// JavaScript Document


function cookieState(url)
{
	//first look for forms on the page

	if( document.forms[0] )
	{

		if( document.forms[0].name = 'remember' ) 		//if there are forms check is the form is called  'remember'

		{ 
			if( document.forms[0].remember.checked )
			{
				setCookie('country', url, 365);
			//	setCookie('countryName', getQueryStringVarFromUrl(url, 'cn'), 365);
			//	setCookie('countryName', getCountryName('cn'), 365);

				var Index = document.getElementById("countrySelector").selectedIndex;
				var Id = document.getElementById("countrySelector").options[Index].id;
				
				setCookie('countryName', Id, 365);

				window.location = url;
				
				
			}
			else
			{
				window.location = url;
			}
			
		}
		
	}
	else
	{
				window.location = url;
	}

			//End Cookie conditions 
	
}

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


function eraseCookie(name) {
	createCookie(name,"",-1);
}


//function not necessary, removed the query from the url
/*function getQueryStringVarFromUrl(url,variable)
{
  var query = url;
  var vars = query.split("?");
  if (vars.length == 0)
  {
	return "";
  } else {
  
	  for (var i=0;i<vars.length;i++)
	  {
		var aryPair = vars[i].split("=");
		if (aryPair[0] == variable)
		{
		  return aryPair[1];
		}
	  }
   }   
}
*/


//function in case the id in the option value contains a cn variable
/*
function getCountryName(variable)
{
var Index = document.getElementById("countrySelector").selectedIndex;
var Id = document.getElementById("countrySelector").options[Index].id;

var vars = Id.split("|");



if(vars.length == 0){
return "";
} else {
	
	for(var i=0; i<vars.length;i++){
	
	
	var aryPair = vars[i].split("=");
		if (aryPair[0] == variable)
		{
		  return aryPair[1];
		}	
	}
	
	
	
	}

}
*/

