function createCookie(name,value,days) {
	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=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	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) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}


function gotoRedirect(siteRef) {
	//the siteRef is the country directory that the cookie is set to.
	window.location.href='http://www.unistik3.com' + siteRef;
	}
	
function checkForRedirect() {
	// If we've got a Unistik3 cookie, the user has previously selected a location
	// so redirect them there.
	unistik3Cookie = readCookie("unistik3");
	//alert(unistik3Cookie);
	
	if (unistik3Cookie != null) {
		gotoRedirect(unistik3Cookie);
	}
}

function setCountry(country) {
	unistik3Cookie = createCookie("unistik3",country,30);
}

$(document).ready(function(){
	
		
	$("#country_list").find("a").click(function(){
		if ($(this).attr("id") != "de") {
			setCountry("/" + $(this).attr("id") + "/");
		}
	});
   
   $("#change_country").find("a").click(function(){
		eraseCookie("unistik3");
	});
   
});
