function submitform(){
	document.anpassningsformular.submit();
}

function setCookie(sNameOfCookie, sValue, sCollName, nDays)
{
	// alert('setCookie: ' + sNameOfCookie + ' = ' + sValue);
  // var path = SiteURL;
	var path;
	
	if(!path)
	{
		path = new String(document.location.pathname);
		path = path.substring(0, path.lastIndexOf("/"));
		if(path.indexOf("/") != 0)
			path = "/" + path;
		if(path.substring(path.length -3) == "/sv" || path.substring(path.length -3) == "/fi")
			path = path.substring(0, path.length -3);
	}
	else
	{
		if(path.substring(8).indexOf("/") > -1)
		{
			path = path.substring(path.substring(8).indexOf("/") + 8);
			path = path.substring(0,path.lastIndexOf("/"));
			
		}
	}
	if(!path)
		path = "/";
	var expires = "";
	if(nDays)
	{
		var today = new Date();
		var expire = new Date();
		expire.setTime(today.getTime() + 3600000 * 24 * nDays);
		expires = ";expires=" + expire.toGMTString();
	}
	var sCookie = document.cookie;
	var regEx = null;
	var arr = null;
	
	sNameOfCookie = encodeUTF8(sNameOfCookie);
	sValue = encodeUTF8(sValue);
	if(!sCollName)
	{
		regEx = new RegExp("(^|; )" + sNameOfCookie + "\\=", "ig");
		while ((arr = regEx.exec(sCookie)) != null)
		{
			var sName = arr[0].replace(/; /g, "");
			if(sName.replace(/\=/, "") != sNameOfCookie)
				document.cookie = sName + ";path=" + path + ";expires=Fri, 4 Mar 1980 08:19:41 UTC";
		}
		document.cookie = sNameOfCookie + "=" + sValue + ";path=" + path + expires;
		return;
	}
	
	sCollName = encodeUTF8(sCollName);
	regEx = new RegExp("(^|; )" + sNameOfCookie + "\\=[^;]*", "i");
	arr = regEx.exec(sCookie);
	if(arr == null)
	{
		//alert(sNameOfCookie + "=" + sCollName + "=" + sValue + ";path=" + path + expires);
		document.cookie = sNameOfCookie + "=" + sCollName + "=" + sValue + ";path=" + path + expires;
		return;
	}
	
	var sOldCookieValue = arr[0].substring(arr[0].indexOf("=") + 1);
	
	regEx = new RegExp("(^|&)" + sCollName + "\\=[^&]*(&|$)", "ig");
	sOldCookieValue = sOldCookieValue.replace(regEx, "");
	//alert(sNameOfCookie + "=" + sCollName + "=" + sValue + (sOldCookieValue ? "&" : "") + sOldCookieValue + ";path=" + path + expires);
	document.cookie = sNameOfCookie + "=" + sCollName + "=" + sValue + (sOldCookieValue ? "&" : "") + sOldCookieValue + ";path=" + path + expires;
	regEx = new RegExp("(^|; )" + sNameOfCookie + "\\=", "ig");
	while ((arr = regEx.exec(sCookie)) != null)
	{
		var sName = arr[0].replace(/; /g, "");
		if(sName.replace(/\=/, "") != sNameOfCookie)
			document.cookie = sName + ";path=" + path + ";expires=Fri, 4 Mar 1980 08:19:41 UTC";
	}
}

function getCookie(sName, sCollName) {
	//alert('getCookie');
	sName = encodeUTF8(sName);
	var sCookie = document.cookie;
	var regEx = new RegExp("(^|; )" + sName + "\\=[^;]*", "i");
	var sRet = null;
	var arr = regEx.exec(sCookie);
	if(arr == null)
		return null;
	sRet = arr[0].substring(arr[0].indexOf("=") + 1);
	if(!sCollName)
		return decodeUTF8(sRet);
	sCookie = sRet;
	sCollName = encodeUTF8(sCollName);
	regEx = new RegExp("(^|&)" + sCollName + "\\=[^&]*", "ig");
	sRet = null;
	arr = null;
	while ((arr = regEx.exec(sCookie)) != null)
		sRet = (sRet == null ? "" : sRet + ", ") + arr[0].substring(arr[0].indexOf("=") + 1);
	if(sRet == null)
		return null;
	return decodeUTF8(sRet);
}

function encodeUTF8(sValue) {
	try	{
		return encodeURIComponent(sValue).replace(/\_/g, "%5F").replace(/\-/g, "%2D").replace(/\+/g, "%2B");
	}
	catch(e) {
		//
	}
	return escape(sValue).replace(/\_/g, "%5F").replace(/\-/g, " ").replace(/\+/g, "%2B");
}

function decodeUTF8(sValue) {
	try {
		return decodeURIComponent(sValue.replace(/\+/g, " "));
	}
	catch(e) {
		//isNaN
	}
	return unescape(sValue.replace(/\+/g, " "));
}

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 1; i < radioLength; i++) {  // 0 is the the default and should not be set
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function loadSettings() {
	// alert('loadSettings');
	var textstorlek = (getCookie('textstorlek','')) ? getCookie('textstorlek','') : 0;
	// alert(textstorlek);
	var typsnitt = (getCookie('typsnitt','')) ? getCookie('typsnitt','') : 0;
	var radavstand = (getCookie('radavstand', '')) ? getCookie('radavstand', '') : 0;
	// alert(radavstand);
	var teckenmellanrum = (getCookie('teckenmellanrum','')) ? getCookie('teckenmellanrum','') : 0;
	var ordmellanrum = (getCookie('ordmellanrum','') ) ? getCookie('ordmellanrum','') : 0;
	var bakgrund = (getCookie('bakgrund','')) ? getCookie('bakgrund','') : 0;
	// alert(bakgrund);
	var farg = (getCookie('farg','')) ? getCookie('farg','') : 0 ;
	
	document.anpassningsformular.textstorlek[textstorlek].checked=true;
	document.anpassningsformular.typsnitt[typsnitt].checked=true;
	document.anpassningsformular.radavstand[radavstand].checked=true;
	document.anpassningsformular.teckenmellanrum[teckenmellanrum].checked=true;
	document.anpassningsformular.ordmellanrum[ordmellanrum].checked=true;
	document.anpassningsformular.bakgrund[bakgrund].checked=true;
	document.anpassningsformular.farg[farg].checked=true;
}

function resetValues() {
	// alert('resetValues');
	setCookie('textstorlek','','',30);
	setCookie('typsnitt','','',30);
	setCookie('radavstand','','',30);
	setCookie('teckenmellanrum','','',30);
	setCookie('ordmellanrum','','',30);
	setCookie('bakgrund','','',30);
	setCookie('farg','','',30);
	setCookie('IE_STYLE','','',30);
	setCookie('NS_STYLE','','',30);
	loadSettings();
}

function saveSettings() {
	// alert('saveSettings');
	setCookie('textstorlek',getCheckedValue(document.anpassningsformular.textstorlek),'',30);
	setCookie('typsnitt',getCheckedValue(document.anpassningsformular.typsnitt),'',30);
	setCookie('radavstand',getCheckedValue(document.anpassningsformular.radavstand),'',30);
	setCookie('teckenmellanrum',getCheckedValue(document.anpassningsformular.teckenmellanrum),'',30);
	setCookie('ordmellanrum',getCheckedValue(document.anpassningsformular.ordmellanrum),'',30);
	setCookie('bakgrund',getCheckedValue(document.anpassningsformular.bakgrund),'',30);
	setCookie('farg',getCheckedValue(document.anpassningsformular.farg),'',30);
}
