function setLokalisierungCookie(value) {
	var a = new Date();
	a = new Date(a.getTime() +1000*60*60*24*700); // Lebensdauer 700 Tage
	document.cookie = 'DolderPCountry='+value+'; expires='+a.toGMTString()+'; path=/'; 
}

function finishLokalisierung() {
	var complete = false;
	
	var myCountrySelectBox = document.getElementById('countrySelect');
	var selectedcountryId = myCountrySelectBox.options[myCountrySelectBox.options.selectedIndex].value;
	
	if (selectedcountryId != null && selectedcountryId != "NONE") {
		complete = true;
	}
	else {
		document.getElementById('selCountry').style.color = "red";
	}
	
	if (complete) {
		// Cookie setzen
		setLokalisierungCookie(selectedcountryId);
		dispatchCountry(selectedcountryId);
	}
}

/*
	Funktion zur Weiterleitung auf die entsprechende URL, je nach Landesauswahl.
*/
function dispatchCountry(cid) {
	switch (cid) {
		case "CH-DE": this.location.href="http://www.dolder.com/de/"; break;
		case "CH-FR": this.location.href="http://www.dolder.com/fr/"; break;
		case "CH-IT": this.location.href="http://www.dolder.com/it/"; break;
		case "CH": this.location.href="http://www.dolder.com/de/"; break;
		case "IT": this.location.href="http://www.dolder.it/"; break;
		case "DE": this.location.href="http://www.dolder.com/de/"; break;
		case "AT": this.location.href="http://www.dolder.com/de/"; break;
		case "CN": this.location.href="http://www.dolder.com/cn/"; break;
		default: this.location.href="http://www.dolder.com"; break;
	}
}

/*
	Funktion zur Pruefung, ob schon ein Lokalisierungscookie gesetzt ist.
	Falls nicht, wird das Lokalisierungspopup angezeigt.
*/
function checkLokalisierungCookie() {
	var lokCookie = getLokCookie('DolderPCountry');
	var popupL = document.getElementById('lokalisierungsLayer');
	
	// wenn Cookies deaktiviert sind, mache nichts
	if (!navigator.cookieEnabled) return;
	
	// Popup anzeigen, wenn Cookie nicht gesetzt
	if (lokCookie.length == 0 && location.href.indexOf("www.dolder.it")==-1) {
		popupL.style.display="block";
		try {
			// Content verbergen, damit selects im IE6 nicht im vordergrund sind		
			document.getElementById('product_finder').style.display="none";
		}
		catch (e) {}
	}
	/*
	 *   Wenn Lokalisierungs-Cookie gesetzt und Startseite (dolder.com) wird aufgerufen, leite auf entsprechende Sprachversion der Startseite weiter.
	 */
	else {
		var c = lokCookie;
		if (document.URL == "http://www.dolder.com/") {
			if ( c == "CH-DE" || c == "CH-FR" || c == "CH-IT" || c == "CH" || c == "IT" || c == "DE" || c == "AT" || c == "CN") {
				dispatchCountry(c);
			}
		}
	}
}

/**
	Lokalisierungs-Cookie aendern, wenn Language-Parameter in URL enthalten
**/
function changeCookie() {
	if (getURLParam("L") == "1") { // DE
		setLokalisierungCookie("DE");
	}
	if (getURLParam("L") == "2") { // FR
		setLokalisierungCookie("CH-FR");
	}
	if (getURLParam("L") == "3") { // IT
		setLokalisierungCookie("IT");
	}
	if (getURLParam("L") == "4") { // CN
		setLokalisierungCookie("CN");
	}
}

/**
	Funktion, zum Auslesen eines GET-Parameters aus der aktuellen URL.
**/
function getURLParam(strParamName) {
	strReturn = "";
	strHref = document.URL;
	if ( strHref.indexOf("?") > -1 ){
		strQueryString = strHref.substr(strHref.indexOf("?"));
		aQueryString = strQueryString.split("&");
		for ( iParam = 0; iParam < aQueryString.length; iParam++ ){
			if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ) {
				aParam = aQueryString[iParam].split("=");
				strReturn = aParam[1];
				break;
			}
		}
	}
	return strReturn;
}

function getLokCookie(mid) {
	var lf = "\n";
	var CookieString = document.cookie;
	var CookieSet = CookieString.split (';');
	var SetSize = CookieSet.length;
	var CookiePieces
	var ReturnValue = "";
	var x = 0;
	for (x = 0; ((x < SetSize) && (ReturnValue == "")); x++) {
		CookiePieces = CookieSet[x].split ('=');
		if (CookiePieces[0].substring (0,1) == ' ') {
		CookiePieces[0] = CookiePieces[0].substring (1, CookiePieces[0].length);
		}
		if (CookiePieces[0] == mid) {
		ReturnValue = CookiePieces[1];
		}
	}
	return ReturnValue;
} 

/*
	Methode, die einen onLoad Event hinzufuegt.
*/
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}