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;
}

if(navigator.appName == "Microsoft Internet Explorer" && readCookie("divbox") != null){
	
	var tmp1 = document.getElementById('country').innerHTML
	document.getElementById('country').outerHTML =  '<select class="OptionSelect_Orderstep1" id="country" name="country" onchange="ConfirmChange()">'+tmp1+'</select>'
								 
	var tmp2 = document.getElementById('lcountry').innerHTML										 
	document.getElementById('lcountry').outerHTML = '<SELECT class="OptionSelect_Orderstep1" xstyle="width:91%" id="lcountry" name="lcountry" onchange="ConfirmChange()">'+tmp2+'</SELECT>'

	

}
if(navigator.appName != "Microsoft Internet Explorer"){

	var attr = document.createAttribute('onchange');
			
	attr.nodeValue = "ConfirmChange()";
	document.getElementById('country').setAttributeNode(attr);
	
	var attr2 = document.createAttribute('onchange');
			
	attr2.nodeValue = "ConfirmChange()";
	document.getElementById('lcountry').setAttributeNode(attr2);



}


//alert(readCookie("divbox"))
var val = ""
if (readCookie("divbox") == "DKK"){
	val = "2397"
}
else if (readCookie("divbox") == "23"){
	val = "2540"
}
else if (readCookie("divbox") == "18"){
	val = "2497"
}
else if (readCookie("divbox") == "1"){
	val = "2436"
}
else if (readCookie("divbox") == "11"){
	val = "2413"
}
else if (readCookie("divbox") == "2"){
	val = "2573"
}
else if (readCookie("divbox") == "3"){
	val = "2574"
}
else if (readCookie("divbox") == "4"){
	val = "2419"
}
else if (readCookie("divbox") == "5"){
	val = "2575"
}
else if (readCookie("divbox") == "6"){
	val = "2355"
}
else if (readCookie("divbox") == "7"){
	val = "2373"
}
else if (readCookie("divbox") == "8"){
	val = "2578"
}
else if (readCookie("divbox") == "9"){
	val = "2407"
}
else if (readCookie("divbox") == "10"){
	val = "2576"
}
else if (readCookie("divbox") == "12"){
	val = "2434"
}
else if (readCookie("divbox") == "13"){
	val = "2443"
}
else if (readCookie("divbox") == "14"){
	val = "2445"
}
else if (readCookie("divbox") == "15"){
	val = "2454"
}
else if (readCookie("divbox") == "16"){
	val = "2460"
}
else if (readCookie("divbox") == "17"){
	val = "2466"
}
else if (readCookie("divbox") == "19"){
	val = "2508"
}
else if (readCookie("divbox") == "20"){
	val = "2513"
}
else if (readCookie("divbox") == "21"){
	val = "2514"
}
else if (readCookie("divbox") == "22"){
	val = "2528"
}
else if (readCookie("divbox") == "24"){
	val = "2546"
}
else if (readCookie("divbox") == "25"){
	val = "2551"
}
else if (readCookie("divbox") == "26"){
	val = "2556"
}
else if (readCookie("divbox") == "27"){
	val = "2557"
}
else {
	val = readCookie("divbox")
}
var ChossenCountry
var allPageTags = new Array(); 
var allPageTags=document.getElementsByTagName("option");

var CheckProfilCountry = new Array()
var count = 0
for (i=0; i<allPageTags.length; i++) 
{ 
	if (allPageTags[i].selected == true) 
	{ 
		allPageTags[i].selected = false
		CheckProfilCountry[count] = allPageTags[i].value
		count++
	}
}

//alert("cookie val = "+val+"\nprofil val = "+CheckProfilCountry[0])
var LoggedIn = false
var allPageTags2 = new Array(); 
var allPageTags2 = document.getElementsByTagName("b");

function SetCur2(CountryID){
	if (CountryID == "2412" || CountryID == "2577"){
		var expires = new Date();
		expires.setTime(expires.getTime()+(1000*60*20));
		document.cookie = "CheckReload=1; expires="+expires.toGMTString()+"; path=/";
		ChangeCurrency("USD")
	}
	else if(CountryID == "2397"){
		var expires = new Date();
		expires.setTime(expires.getTime()+(1000*60*20));
		document.cookie = "CheckReload=1; expires="+expires.toGMTString()+"; path=/";
		ChangeCurrency("DKK")
	}
	else{
	var expires = new Date();
		expires.setTime(expires.getTime()+(1000*60*20));
		document.cookie = "CheckReload=1; expires="+expires.toGMTString()+"; path=/";
		ChangeCurrency("EURO")
	}
}


for (i=0; i<allPageTags2.length; i++) 
{ 
	if (allPageTags2[i].innerHTML == "You are logged in") 
	{ 
		if(CheckProfilCountry[0] != val){
			val = CheckProfilCountry[0]
			if(readCookie("CheckReload") != 1){
				SetCur2(val)
			}
			else{
				alert("Please note that the country and currency will now be changed to match the country you have stated in your profile.")
				var expires = new Date();
				expires.setTime(expires.getTime()+(1000*60*20));
				document.cookie = "CheckReload=0; expires="+expires.toGMTString()+"; path=/";
				document.cookie = "divbox="+val+"; expires="+expires.toGMTString()+"; path=/";
			}
		}
		LoggedIn = true
	}
}

//SetCur(val)


for (i=0; i<allPageTags.length; i++) 
{ 
	if (allPageTags[i].value == val) 
	{ 
		allPageTags[i].selected = true
		ChossenCountry = allPageTags[i].innerHTML
	}
}

function setCorrectCountry(){
	for (i=0; i<allPageTags.length; i++) 
	{ 
		if (allPageTags[i].value == val) 
		{ 
			allPageTags[i].selected = true
			ChossenCountry = allPageTags[i].innerHTML
		}
	}
}
//document.getElementById('country').onclick = "alert('asas')"


function DoChange(){
	var expires = new Date();
	expires.setTime(expires.getTime()-1);
	document.cookie = "divbox=; expires="+expires.toGMTString()+"; path=/";
	Loc = location.href
	location.href = Loc
}


//alert(document.getElementById('country').innerHTML)

function ConfirmChange(){
	if(LoggedIn == false){
		var where_to= confirm("You have chosen "+ChossenCountry+". If you wish to change country here, the currency will change as well.\nDo you wish to continue?");
		if (where_to== true){
		   DoChange()
		} else {
			setCorrectCountry();
		}
	}
	else{
		alert("You can't change your country when your profile has been loaded.")
	}
}

