function createCookie(name,value,days,path){
	// alert("setting cookie: name["+name+"]value["+value+"]days["+days+"]path["+path+"]");
	if (!path) {
		path="";
	}
	
	if(days){
		var date=new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = ";expires="+date.toGMTString();
	}else
		var expires="";
	createMenuCookie('webkinzMenuCookie',value,365);
	document.cookie=name+"="+value+expires+";path=/;domain=webkinz.com";
	if (document.getElementById('countriesBar'))
    {
        checkMenuCookie();
    }
	//redirect!
	relocate(value, 'create');
}
function readCookie(name){
	var nameEQ=name+"=";
	var value;
	var ca=document.cookie.split(';');
	for(var i=0;i<ca.length;i++) {
		var c=ca[i];
		while(c.charAt(0)==' ')
			c=c.substring(1,c.length);
		if(c.indexOf(nameEQ)==0)
			value=c.substring(nameEQ.length,c.length);
	}
	//alert("getting cookie: value["+value+"]");
	if ((name == 'webkinzLocaleCookie') && (value == undefined)){
		//value ='us_en';
	}
	return value;
}
function checkCookie(){
	if (document.cookie.indexOf('webkinzLocaleCookie')==-1){
		//No cookie found so create one.
//		createCookie('webkinzLocaleCookie','us_en',365);
		relocate('us_en', 'check');
	}else{
		//Cookie found so get value ...
		value = readCookie('webkinzLocaleCookie');
		//redirect!
		relocate(value, 'check');
	}
}

//inline, block or none, ner 701108cs
function relocate(value, from){

	//if (this.is_Flash == false)	{
	//    if (value == 'us_en' || value == '') {
	//        window.location="/index.html";
	//    } else {
	//	    window.location="/"+value+"/index.html";
	//	}
	//	return false;
	//}
    
	var currentPathname = window.location.pathname;
	var pathSplit = currentPathname.split('/');
	//alert("path name: " +currentPathname + "       pathSplit: "+pathSplit + "          pathSplit[pathSplit.length-2] = "+pathSplit[pathSplit.length-2]);
	
	if(pathSplit.length > 2 && pathSplit[pathSplit.length-2] == value){
		// reference to bumoper page
		if (pathSplit[pathSplit.length-1] == "country_disclaimer.html") {
			if (value != 'us_en' & value != '') {
                var newPathname="/"+value+"/";	
                window.location=newPathname;
            }
            if ((value == 'us_en' || value == '') && from == 'create') {
                var newPathname="/";
                window.location=newPathname;
            } 
		}
		
	} else {
            if (value != 'us_en' && value != '') {
		        var newPathname="/"+value+"/";
                window.location=newPathname;
            }
            if ((value == 'us_en' || value == '') && from == 'create') {
                var newPathname="/";
                window.location=newPathname;
            }
	}
}


// natalia roque, cookie for show up the countries menu
function createMenuCookie(name,value,days,path){
	if (!path) {
		path="";
	}
	if(days){
		var date=new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = ";expires="+date.toGMTString();
	}else
		var expires="";
	document.cookie=name+"="+value+expires+";path=/;domain=webkinz.com";

}
function readMenuCookie(name){
	var nameEQ=name+"=";
	var value;
	var ca=document.cookie.split(';');
	for(var i=0;i<ca.length;i++) {
		var c=ca[i];
		while(c.charAt(0)==' ')
			c=c.substring(1,c.length);
		if(c.indexOf(nameEQ)==0)
			value=c.substring(nameEQ.length,c.length);
	}
	//alert("getting cookie: value["+value+"]");
	//if ((name == 'webkinzMenuCookie') && (value == undefined)){
	//	value ='us_en';
	//}
	
	return value;
}
function checkMenuCookie(){
	if (document.cookie.indexOf('webkinzMenuCookie')==-1){
		//No cookie found so create one.
		//createMenuCookie('webkinzMenuCookie','us_en',365);
		document.getElementById('countriesBar').style.display = 'block';
		document.getElementById('countries').style.display = 'block';
		return false;
	}else{
		//Cookie found so get value ...
		value = readMenuCookie('webkinzMenuCookie');
		document.getElementById('countriesBar').style.display = 'none';
		document.getElementById('countries').style.display = 'none';
		return true;
	}
}

