// JavaScript Document

//------------------------------ read existing cookie ------------------------------//
function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}

//------------------------------ create cookie ------------------------------//

function createCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString())+
"; path=/";
}

//------------------------------ erase cookie ------------------------------//
function eraseCookie(name) 
 {
	createCookie(name,'',-1);
}

//------------------------------ when you click on flags ------------------------------//
function gotoLang(_language) {
	createCookie('langCookie',_language,999);
}

//------------------------------ redirect from index page ------------------------------//
function checkCookie()
{
var language=getCookie('langCookie');
	
	if (language == "EN") {
		window.location = "EN/index.html" //redirect to language
	}
	if(language == "FR") {
		window.location = "FR/index.html" //redirect to language
	}
	if(language == "DE") {
		window.location = "DE/index.html" //redirect to language
	}
}

//------------------------------ switch language from inner page ------------------------------//

function generateURL(_redirect) {
	var fullURL = document.location.href;
	var arrayURL = new Array();
    arrayURL = fullURL.split("/");
	var arrayURLlength = arrayURL.length;
	var newPg = arrayURL[arrayURLlength-1];
	window.location = _redirect+newPg;
}

function switchLang(_switchlanguage) {
	var langCode = "../" + _switchlanguage + "/";
	createCookie('langCookie',_switchlanguage,999);
	generateURL(langCode);
}
