// V 1.0
//====================== Gestion langue
var currentLng; //langue courante
currentUrl=(document.location+"").toLowerCase() //adresse courante de la page

//recherche _nl _fr _en dans l'adresse
startPosIndexFr=currentUrl.toLowerCase().indexOf("_fr.")
startPosIndexEn=currentUrl.toLowerCase().indexOf("_en.")
startPosIndexNl=currentUrl.toLowerCase().indexOf("_nl.")
startPosIndexIt=currentUrl.toLowerCase().indexOf("_it.")

//trouve la langue courante	
if (startPosIndexFr>0) { currentLng="fr" }
if (startPosIndexEn>0) { currentLng="en" }
if (startPosIndexNl>0) { currentLng="nl" }
if (startPosIndexIt>0) { currentLng="it" }

function swapToLng(f_LngToSwap) {
	//génère le string de la nouvelle adresse	
	newUrl=currentUrl.replace("_"+currentLng.toLowerCase(),"_"+f_LngToSwap)

  //Sauve le choix de langue dans un cookie
	setLngCookie(f_LngToSwap);

//	alert("swapToLng")
//	alert("save : "+f_LngToSwap);
//  alert("newUrl : "+newUrl+" | currentLng : "+currentLng+" | f_LngToSwap : "+f_LngToSwap);

  if (currentUrl=="http://www.viridaxis.com/" || currentUrl=="http://www.viridaxis.com/index.html") {newUrl="http://www.viridaxis.com/home_"+f_LngToSwap+".html"}
  if (currentUrl=="http://www.viridaxis.com/home_nl.html" && f_LngToSwap=="fr") {newUrl="http://www.viridaxis.com/"}
  if (currentUrl=="http://www.viridaxis.com/home_en.html" && f_LngToSwap=="fr") {newUrl="http://www.viridaxis.com/"}

  //Envoie à la nouvelle adresse
  document.location=newUrl
  }

function redirectToLng() {
	var favorite = GetCookie('language');
	//alert("favorite : "+favorite);
	
	if (favorite != null) {
		switch (favorite) {
			case 'fr' : url = 'home_fr.php'; break;
			case 'en' : url = 'home_en.php'; break;
			case 'nl' : url = 'home_nl.html'; break;
			case 'it' : url = 'home_it.php'; break;
		}
		window.location.href = url;
	}
}

function redirectTo(name_p, value_p) { SetCookie (name_p, value_p);	window.location.href = url;	}

//====================== Gestion cookies
var expDays = 30;
var exp = new Date(); 
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

function getCookieVal (offset) {  
var endstr = document.cookie.indexOf (";", offset);  
if (endstr == -1)    
endstr = document.cookie.length;  
return unescape(document.cookie.substring(offset, endstr));
}
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) {  
	var argv = SetCookie.arguments;  
	var argc = SetCookie.arguments.length;  
	var expires = (argc > 2) ? argv[2] : null;  
	var path = (argc > 3) ? argv[3] : null;  
	var domain = (argc > 4) ? argv[4] : null;  
	var secure = (argc > 5) ? argv[5] : false;  
	document.cookie = name + "=" + escape (value) + 
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
	((path == null) ? "" : ("; path=" + path)) +  
	((domain == null) ? "" : ("; domain=" + domain)) +    
	((secure == true) ? "; secure" : "");
}
function DeleteCookie (name) {  
	var exp = new Date();  
	exp.setTime (exp.getTime() - 1);  
	var cval = GetCookie (name);  
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

function setLngCookie(lng_p) { SetCookie('language', lng_p, exp) }
function loadLngInCookie() { GetCookie('language'); }
