var domain, CookieUpdate;
domain = "jackieturbo.com";
CookieUpdate = "UpdateCheck";
CookieCounter = "Counter";

function SwitchLanguage( language ) {
	var url = window.location.href;
	var newUrl = url;
	var pos = 0;
	var from;
	
	Set_Cookie("SiteLanguage", language, 60, "/");
	
	if( language == "nl" ) {
		from = "en";
	}
	else {
		from = "nl";
	}
	
    pos = url.indexOf( "/" + from + "/" );
    if( pos >= 0 ) {
	  newUrl = url.substring(0,pos) + "/" + language + "/" + url.substring(pos+4);
	}
	else {
	  pos = url.indexOf( "lang=" + from );
	  if( pos >= 0 ) {
		newUrl = url.substring(0,pos) + "lang=" + language + url.substring(pos+7);
	  }
	}
	
	window.location.href = newUrl;
	return false;
}

function replace(string,text,by) {
// Replaces text with by in string
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);

    return newstr;
}

function Get_Cookie(name) {
	var start = document.cookie.indexOf(name+"=");
	var len = start+name.length+1;
	if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
	if (start == -1) return null;
	var end = document.cookie.indexOf(";",len);
	if (end == -1) end = document.cookie.length;
	return unescape(document.cookie.substring(len,end));
}

function Set_Cookie(name,value,expires,path,secure) {
	var today = new Date();
	var zero_date = new Date(0,0,0);
	today.setTime(today.getTime() - zero_date.getTime());

	var todays_date = new Date(today.getYear(),today.getMonth(),today.getDate(),0,0,0);
	var expires_date = new Date(todays_date.getTime() + (expires * 86400000));

	document.cookie = name + "=" +escape(value) +
		( (expires) ? ";expires=" + expires_date.toGMTString() : "") +
	( (path) ? ";path=" + path : "/") + 
	";domain=" + domain +
	( (secure) ? ";secure" : "");
}

function Delete_Cookie(name,path) {
	if (Get_Cookie(name)) document.cookie = name + "=" +
		( (path) ? ";path=" + path : "/") +
		";domain=" + domain +
		";expires=Thu, 01-Jan-70 00:00:01 GMT";
}

var cookie_js_loaded = true;
