//function SondageOutput(section_name, sous_section) 
//{
//   if (section_name && sous_section)
//   {
//     popupWin2("Sondage", "/sondage/includes/"+section_name+"/"+sous_section+"/"+sous_section+".html", 780, 600);
//   }
//}

function afficheResultats(link, format, width, height) 
{
	if (format == 'popup')
	{
		if (width == null) {
			width = 780;
		}

		if (height == null) {
			height = 600;
		}

		popupWin2("Resultat", link, width, height);
	}
	else 
	{
		top.location = (link);
	}
}

//////////////////////
/*	participerSondage
/	Permet de participer ŕ un sondage
/	Appel le script de participation en lui envoyant les infos nécessaires
/
/	IN:
/		sondageForm: Le formulaire de la question sondage
/
/	OUT:
/		AUCUN
*/
/////////////////////////////////////////////////
function participerSondage(sondageForm, format, width, height) {

	var id_question = sondageForm.id_question.value;
	var url_result  = sondageForm.url_result.value;
	var url_merci   = sondageForm.url_merci.value;

	var choixItem;
	var choixList = sondageForm.reponse;
	for (var i = 0; i < choixList.length; i++) {
		if (choixList[i].checked) {
			choixItem = choixList[i].value
		}
	}

	var link = "http://scripts.canoe.ca/sondage/repondre_sondage.cgi?id_question="+escape(id_question)+"&url_result="+escape(url_result)+"&url_merci="+escape(url_merci)+"&reponse="+escape(choixItem);

	if (format == 'popup') {
		if (width == null) {
			width = 780;
		}

		if (height == null) {
			height = 600;
		}

		popupWin2("Resultat", link, width, height);
	} 
	else {
		top.location = (link);
	}
}


function popupWin2(popupName,url,popupWidth,popupHeight)
{
   win = window.open(url, popupName,"width=" + popupWidth + ",height=" + popupHeight + ",resizable=yes,scrollbars=yes,toolbar=no,status=no,location=no,directories=no");
   //bug de NN4 quand focus trop vite, attend 0,25 sec
   setTimeout('win.focus();',250);
   //win.location.reload(true);
   //return win;
}


function responseIsEmpty(nomCookie, form, lang, id_question)
{
   var radioLenth = form.reponse;
   var value = false;

   for(var i=0; i< radioLenth.length; i++)
   {
      if(radioLenth[i].checked)
      {
         value = true;
      }
   }
   if(!value)
      if (lang == 'E')
         alert("You didn't vote!");
	  else
         alert("Vous avez omis de voter!");
   else
      value = getCookie(nomCookie, lang, id_question);

   return value;
}


function readCookie (cookieName)
{
    if(document.cookie)
    {
       index = document.cookie.indexOf(cookieName)
       if (index != -1)
       {
           cookieStart = (document.cookie.indexOf("=", index) + 1)
           cookieStop = document.cookie.indexOf(";", index)
           if (cookieStop == -1)
           {
              cookieStop = document.cookie.length
           }

                   return unescape(document.cookie.substring(cookieStart, cookieStop));
       }
    }
    return null;
}

function getCookie(cookieName, lang, id_question)
{
        var presentDay = new Date();

        var count = readCookie (cookieName)

        incCookie(cookieName, count);

        if (count == presentDay.getDate())
        {
           if (lang == 'E')
			   alert('Only one vote per question is permitted. Thanks for participating.')
           else
              alert('Une seule participation par question est permise. Merci d\'avoir particip\351 au sondage.')
           return false
        }
        else
        {
			//document.location  = "http://scripts.canoe.ca/sondage/resultat_sondage.cgi?id_question="+id_question;
			return true
        }
}
    

function incCookie(cookieName, count)
{
   var windowprops = "width=400,height=370,location=no,toolbar=no,menubar=no,scrollbars=no,resizable=yes";

   var presentDay = new Date();


    if (count)
      {
        count = presentDay.getDate();

      }
    else
    {
       count =  presentDay.getDate();
    }
/*
 *  document.cookie=cookieName + "=" + escape(count) + "; expires=Monday, 01-JAN-2001 11:11:00 GMT"
 */

/*  Pour les tests. */
    document.cookie=cookieName + "=" + escape(count) + "; expires=Tuesday, 01-JAN-2100 08:00:00 GMT"
}
