

// Global Constants
var COOKIE_LANG = 'FBN-language';
var COOKIE_DUR = '15'; 			//number of days cookie lives till expires.





//Algorithm: If the cookie is not set yet, try to load the default image 
//If cookie is set, try to load the selected image. 
function checkLanguage()
{
	

	var languageCookie = Getcookie(COOKIE_LANG);

	if(!languageCookie) {
			Setcookie(COOKIE_LANG,1,COOKIE_DUR);
			return 'english';
				
	}
	else {
		
		
		if(languageCookie==1){
		return 'english';
		} 
		
		else if(languageCookie==2){
		return 'french';
		}
		
	
			
					
	}
	
}
//This function will open a pop-up window depending on which Chart is currently Selected.
//////////////////////////////////////////////////////////////////////////////////////////////////////////
// STANDARD COOKIE FUNCTIONS 
//////////////////////////////////////////////////////////////////////////////////////////////////////////

function Getexpirydate(nodays)
{
	var UTCstring;
	Today = new Date();
	nomilli=Date.parse(Today);
	Today.setTime(nomilli+nodays*24*60*60*1000);	//computation is done in milliseconds
	UTCstring = Today.toUTCString();
	return UTCstring;
}

//escape method here is used to replace special characters by corresponding HEX values
function Setcookie(name,value,duration)
{
	document.cookie=name+"="+escape(value)+";EXPIRES="+getexpirydate(duration);
	return Getcookie(name); 		//we return getcookie here to be sure cookies are enabled on that computer		
}




//The function is passed one parameter cookiename. This is the cookie we want to retrieve. 
//We use document.cookie to retrieve all the cookie/value pairs set for our domain. The 
//function indexOf(cookiename) finds the position in the string of the first occurrence of 
//the cookiename we are looking for. If the string is not found index1 is set to -1. If it 
//doesn't find it an empty string is returned. If it finds the cookie it searches for the 
//first occurrence of ";" starting from the position of index1.The final line extracts the 
//cookie value as a substring of cookiestring and then uses unescape to translate any hex 
//coded characters back into a readable form
function Getcookie(cookiename)
{	
	var cookiestring=""+document.cookie;
	var index1=cookiestring.indexOf(cookiename);
	if (index1==-1 || cookiename=="") {
		return ""; 
	}		
	var index2=cookiestring.indexOf(';',index1);
	if (index2==-1)	{
		index2=cookiestring.length;
	}	
	return unescape(cookiestring.substring(index1+cookiename.length+1,index2));
}

function redirectLanguage(url,language){
Setcookie(COOKIE_LANG,language,COOKIE_DUR);
document.location=url;
}

