// JavaScript Document

ns4 = (document.layers)? true:false
ie4 = (document.all)? true:false
ns6 = (!document.all && document.getElementById) ? true : false


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function  roll(section,color) {
	if (document.all)
		eval(section).style.color= color;
}

function  rollClass(section,cls) {
	if (document.all){	
		eval(section).className=cls;
	}
}
function MM_checkPlugin(plgIn, theURL, altURL, autoGo) { //v4.0
	var ok=false; 
	document.MM_returnValue = false;
	with (navigator) 
  		if (appName.indexOf('Microsoft')==-1 || (plugins && plugins.length)) {
			ok=(plugins && plugins[plgIn]);
		} 
		else if (appVersion.indexOf('3.1')==-1) { //not Netscape or Win3.1
			if (plgIn.indexOf("Flash")!=-1 && window.MM_flash!=null) 
				ok=window.MM_flash;
			else if (plgIn.indexOf("Director")!=-1 && window.MM_dir!=null) 
				ok=window.MM_dir;
			else ok=autoGo; 
		}
	if (!ok) theURL=altURL; 
	if (theURL) window.open(theURL,'','width=600,height=160');
}
function printpage() { print(document); }

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


function  rollClass2(obj,cls) {
	if (obj.className){	
		obj.className=cls;
	}
}

function langue(){
 var url = document.URL;
 if (url.indexOf('/en/') == -1)
 {
  window.location = url.replace('/fr/','/en/');
  setFastCookie("YoplaitLangIso", "en", 1000);
 }
 else
 {
  window.location = url.replace('/en/','/fr/');
  setFastCookie("YoplaitLangIso", "fr", 1000);
 }
}

function redirigeLang()
{
		var url = document.URL;
		if (GetCookie("YoplaitLangIso") != null && url.indexOf("/" + GetCookie("YoplaitLangIso") + "/")  == -1)
		{
			if (GetCookie("YoplaitLangIso") == "en")
			{
				window.location = url.replace('/fr/','/en/');
			}
			else
			{
				window.location = url.replace('/en/','/fr/');
			}		
		}	
		else if (GetCookie("YoplaitLangIso") == null && url.indexOf("/fr/")  == -1)
			window.location = url.replace('/en/','/fr/');
}

//"Internal" function to return the decoded value of a cookie 
function getCookieVal (offset) { 
	var endstr = document.cookie.indexOf (";", offset); 
	if (endstr == -1) 
		endstr = document.cookie.length; 
	return unescape(document.cookie.substring(offset, endstr)); 
}  

//Function to return the decoded value of a cookie written by ASP
function getASPCookieVal (cookVal, subCookieName) { 
	var subCookies = cookVal.split("&");	
	for (i = 0; i < subCookies.length; i++)
	{
		var subCookie = subCookies[i].split("=");
		if (subCookie[0] == subCookieName)
		{			
			return subCookie[1];
		}
	}
	return "";
} 

//To correct the Mac date problem.
function FixCookieDate (date) { 
	var base = new Date(0); 
	var skew = base.getTime(); // dawn of (Unix) time - should be 0 
	if (skew > 0) // Except on the Mac - ahead of its time 
		date.setTime (date.getTime() - skew); 
}  

function GetCookie (name) { 
	var arg = name + "="; 
	var alen = arg.length; 
	var clen = document.cookie.length; 
	var i = 0; 
	while (i < clen) { 
		var j = i + alen; 
		if (document.cookie.substring(i, j) == arg) 
			return getCookieVal (j); 
		i = document.cookie.indexOf(" ", i) + 1; 
		if (i == 0) 
			break; 
	} 
	return null; 
}  

function SetCookie (name,value,expires,path,domain,secure) { 
	document.cookie = name + "=" + escape (value) + 
	((expires) ? "; expires=" + expires.toGMTString() : "") + 
	((path) ? "; path=" + path : "") + 
	((domain) ? "; domain=" + domain : "") + 
	((secure) ? "; secure" : ""); 
}  

function DeleteCookie (name,path,domain) { 
	if (GetCookie(name)) { 
		document.cookie = name + "=" + 
		((path) ? "; path=" + path : "") + 
		((domain) ? "; domain=" + domain : "") + 
		"; expires=Thu, 01-Jan-70 00:00:01 GMT"; 
	} 
}  

//name: name of cookie
//value: value of cookie
//expires: number of day before it expires
function setFastCookie(name, value, expires)
{
	var thisDate = new Date()
	thisDate.setDate(thisDate.getDate() + expires)
	FixCookieDate(thisDate)
	SetCookie (name,value,thisDate,"/")
}


function RedirectVoid(newURL) 
{
	window.location = newURL
}


function PopupCenter(pageURL, title, w, h, params) 
{
	var left = (screen.width/2)-(w/2);
	var top = (screen.height/2)-(h/2);
	var targetWin = window.open (pageURL, title, params + ', width='+w+', height='+h+', top='+top+', left='+left);
} 