var browserName=navigator.appName;
var browserVersion=parseInt(navigator.appVersion);
var cX=0;
var cY=0;
var pageHeight = (window.innerHeight)?window.innerHeight:((document.documentElement.clientHeight>0)?document.documentElement.clientHeight:document.body.clientHeight);
var pageWidth = (window.innerWidth)?window.innerWidth:((document.documentElement.clientWidth>0)?document.documentElement.clientWidth:document.body.clientWidth);
//Update variables with mouse position
function UpdateCursorPosition(e){ cX = e.pageX; cY = e.pageY;}
function UpdateCursorPositionDocAll(e){
	try {
		cX = event.clientX + document.documentElement.scrollLeft;
		cY = event.clientY + document.documentElement.scrollTop;
	} catch(e) {
		cX = event.clientX;
		cY = event.clientY;
	}
}
if(document.all) { document.onmousemove = UpdateCursorPositionDocAll;} else { document.onmousemove = UpdateCursorPosition; }
function updatePageDimensions() {
	pageHeight = (window.innerHeight)?window.innerHeight:((document.documentElement.clientHeight>0)?document.documentElement.clientHeight:document.body.clientHeight);
	pageWidth = (window.innerWidth)?window.innerWidth:((document.documentElement.clientWidth>0)?document.documentElement.clientWidth:document.body.clientWidth);
}
//Create a cookie
function createCookie(name,value,days) {
	var expires="";
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		expires = "; expires="+date.toGMTString();
	}
	document.cookie = name+"="+value+expires+"; path=/";
}
//Read cookie value
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;}
//Simple validation of search field
function validateSearch (form, inputname) {
	theForm = form;
	theInput = document.getElementById(inputname);
	if (theInput.value.length > 3) {
		theForm.action = theForm.action + '?Search=' + theInput.value;
		theForm.submit();
	}
	return false;}
//Hide input default value
function editInput (what, from, to) {
	if (typeof from == 'undefined') {
		what.value = to;
	} else {
		if(what.value==from) {
			what.value = to;}}}
//Add to or edit text input
function insertText(where, text, replace) {
	var what = document.getElementById(where);
	if (replace) {
		what.value = text;
	} else {
		what.value += text;}}
//Auto-grow textarea
function autoGrow(which,minHeight) {
		var dummy = document.createElement("div");
		var isIE = (browserName=="Microsoft Internet Explorer")? true : false;
		dummy.setAttribute("id","dummy"+which.id);
		dummy.style.width = which.offsetWidth +"px";
		if(!isIE) which.style.overflow = "hidden";
		dummy.style.height = "auto";
		dummy.className = "textAreaDummy";
		dummy.innerHTML = which.value.replace(/\n/g,"<br>.");
		dummy.style.visibility = "hidden";
		var dummyContainer = document.getElementById("dummyContainer"+which.id);
		dummyContainer.appendChild(dummy);
		if(dummy.offsetHeight>60) {
			which.style.height = dummy.offsetHeight + "px";
		} else {
			which.style.height = "60px";
		}
		dummy.innerHTML = "";
		dummyContainer.removeChild(dummy)
	}
//Quick document.getElementById
function o(id) {
	return document.getElementById(id);
}
//Toggle a div's appearance
function toggleDiv(what, to, cookie, days, hidewhen, cssClass, hiddenCssClass) {
	var theDiv = document.getElementById(what);
	if (theDiv.style.display=="none") {
		theDiv.style.display = to;
		if (cookie==1) {
			if(hidewhen!=1) {
				createCookie(what,'1',days);
			} else {
				createCookie(what,'',-1);
			}
		}} else {
		theDiv.style.display = "none";
		if (cookie==1) {
			if(hidewhen!=0) {
				createCookie(what,'0',days);
			} else {
				createCookie(what,'',-1);
			}}}}
//Enable div with anchor behavior
function divLink(div) {
	var links = div.getElementsByTagName("a");
	if(links!=null) {
		if(links[0].target=="_top")
			top.location = links[0].href;
		else if(links[0].target=="_blank")
			window.open(links[0].href);
		else if(links[0].target==null)
			links[0].onclick();
		else
			document.location = links[0].href;
			
		if(links[0].onclick!=null&&links[0].onclick!="") {
			links[0].onclick();
		}
	}
}
//Switch between two css classes
function switchClass (what, class1, class2, defaultid) {
	var theDiv = document.getElementById(what);
	if(theDiv.className==class1) {
		theDiv.className = class2;
	}
	else if(theDiv.className==class2) {
		theDiv.className = class1;
	}
	else {
		if(defaultid==1) {
			theDiv.className = class1;
		}
		else {
			theDiv.className = class2;
		}
	}
}
//Switch between two images
function switchImage (what, img1, img2,defaultid) {
	var theDiv = document.getElementById(what);
	if(theDiv.src==img1) {
		theDiv.src = img2;
	}
	else if(theDiv.src==img2) {
		theDiv.src = img1;
	}
	else {
		if(defaultid==1) {
			theDiv.src = img1;
		}
		else {
			theDiv.src = img2;
		}
	}
}
//Redirect
function urlRedirect(url) {
	top.location = url;
}
//Toggle div with animation
function tipToggleDiv(which, height) {
	if(isRunning==false) {
		var openDiv = document.getElementById(which);
		if(which!=lastOpen) {
			inter=self.setInterval("openDiv('"+which+"',"+height+")", 1);
			openDiv.style.display='block';
			inter2=self.setInterval("closeDiv('"+lastOpen+"')", 1);
			lastOpen = which;
		} else {
			if(openDiv.style.display=='none') {
				inter=self.setInterval("openDiv('"+which+"',"+height+",'inter')", 1);
				openDiv.style.display='block';
			} else {
				inter2=self.setInterval("closeDiv('"+lastOpen+"')", 1);
			}
		}
	}
}
//Hide div with animation
function closeDiv(divId) {
	var theDiv = document.getElementById(divId);
	if(parseInt(theDiv.style.height,10)>10) {
			isRunning=true;
			theDiv.style.height = parseInt(theDiv.style.height,10)-10 + "px";			
	} else {
		theDiv.style.height = '0px';
		inter2=self.clearInterval(inter2);
		isRunning=false;
		theDiv.style.display='none';
	}
}
var inter;
var interDiv;
var lastOpen=null;
var isRunning = false;
function animateDiv(divId, width, height, evalAfter, evalWhile) {
	var theDiv = document.getElementById(divId);
	if(theDiv!=interDiv||isRunning==false) {
		interDiv = theDiv;
		inter=self.setInterval("runAnimation('"+divId+"',"+width+","+height+",'"+evalAfter+"','"+evalWhile+"')", 1);
	}
}
function runAnimation(divId, width, height, evalAfter,evalWhile) {
	var theDiv = document.getElementById(divId);
	var done=0;
	if(parseInt(theDiv.style.height,10)<height-10&&height!=null) {
		isRunning=true;
		theDiv.style.height = parseInt(theDiv.style.height,10)+10 + "px";
	} else if(parseInt(theDiv.style.height,10)>height+10&&height!=null) {
		isRunning=true;
		theDiv.style.height = parseInt(theDiv.style.height,10)-10 + "px";
	} else {
		done+=1;
		theDiv.style.height = height+'px';
	}
	if(done==1) {
		if(parseInt(theDiv.style.width,10)<width-10&&width!=null) {
			isRunning=true;
			theDiv.style.width = parseInt(theDiv.style.width,10)+10 + "px";
		} else if(parseInt(theDiv.style.width,10)>width+10&&width!=null) {
			isRunning=true;
			theDiv.style.width = parseInt(theDiv.style.width,10)-10 + "px";
		} else {
			done+=1;
			theDiv.style.width = width+'px';
		}
	}
	if(done==2) {
		inter=self.clearInterval(inter);
		if(evalAfter!=null) { eval(evalAfter); }
		isRunning=false;
	}
	if(evalWhile!=null) { eval(evalWhile); }
}
//Show div with animation
function openDiv(divId,height) {
	var theDiv = document.getElementById(divId);
	if(parseInt(theDiv.style.height,10)<height-10) {
			isRunning=true;
			theDiv.style.height = parseInt(theDiv.style.height,10)+10 + "px";
	} else {
		theDiv.style.height = height+'px';
		inter=self.clearInterval(inter);
		isRunning=false;
	}
}
//Swap image src
function swapImg(which, img) {
	which.src = img;}
//Preload menu images for faster hover effects
function loadMenu() {
var bilder = new Array(
			'/images/layout/menu/topmenu_restaurang.jpg',
			'/images/layout/menu/topmenu_restaurang_over.jpg',
			'/images/layout/menu/topmenu_klubb.jpg',
			'/images/layout/menu/topmenu_klubb_over.jpg',
			'/images/layout/menu/topmenu_konsert.jpg',
			'/images/layout/menu/topmenu_konsert_over.jpg',
			'/images/layout/menu/topmenu_shopping.jpg',
			'/images/layout/menu/topmenu_shopping_over.jpg',
			'/images/layout/menu/topmenu_kultur.jpg',
			'/images/layout/menu/topmenu_kultur_over.jpg',
			'/images/layout/menu/topmenu_scen.jpg',
			'/images/layout/menu/topmenu_scen_over.jpg',
			'/images/layout/menu/topmenu_falken.jpg',
			'/images/layout/menu/topmenu_falken_over.jpg',
			'/images/layout/menu/topmenu_turist.jpg',
			'/images/layout/menu/topmenu_turist_over.jpg'
			);
			var temp = new Array();
			for(i=0; i<bilder.length; i++){
			temp[i] = new Image();
			temp[i].src = bilder[i];}}
//Open new window
function openWindow(url, width, height, title) {
	var egenskaper="toolbar=no,location=no,directories=no,menubar=no,scrollbars=yes,resizable=no,status=no,titlebar=no,location=no";
	egenskaper+=",width="+width;
	egenskaper+=",height="+height;
	egenskaper+=",left="+(screen.width  - width) / 2;
	egenskaper+=",top="+(screen.height - height) / 2;
	if(!title) {
	unik=new Date();
	unik=unik.getSeconds()+"_"+unik.getMinutes()+"_"+unik.getHours();
	} else { unik = title; }
	window.open(url,unik,egenskaper);}
//Hover stars
function starHover(id, rating, eventtype, startext) {
		for(var i=1; i<=5;i++) {
			if(i<=rating) {
				document.getElementById('star_'+id+'_'+i).src= '/images/icons/star_active_'+eventtype+'.png';
			} else {
				document.getElementById('star_'+id+'_'+i).src= '/images/icons/star_passive_'+eventtype+'.png';
			}
		}
	document.getElementById('startext'+id).innerHTML = startext;}
//Common AJAX function
function commonAjax(url, targetDiv, loadingDiv, evalAfter) {
	var http_request = false;
	var loader = loadingDiv? document.getElementById(loadingDiv) : null;
	var target = targetDiv? document.getElementById(targetDiv) : null;
	if(loader!=null) { loader.innerHTML = "<img src=\"/images/icons/loading.gif\" alt=\"Laddar...\">"; }
	if (window.XMLHttpRequest) { 
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType("text/xml");
		}
	} else if (window.ActiveXObject) {
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	if (!http_request) {
		alert("Ett fel uppstod vid anropet.");
		return false;
	}
	http_request.request;
	http_request.onreadystatechange = function() { alertCommonAjaxContent(http_request, target, loader, evalAfter); };
	http_request.open("GET", url+((url.indexOf("?")>-1)?"&rnd=":"?rnd=")+Math.random(), true);
	http_request.send(null);
}
//Common AJAX POST function
function commonAjaxPost(url, postData, targetDiv, loadingDiv, evalAfter) {  
	var http_request = false;
	var loader = loadingDiv? document.getElementById(loadingDiv) : null;
	var target = targetDiv? document.getElementById(targetDiv) : null;
	if(loader!=null) { loader.innerHTML = "<img src=\"/images/icons/loading.gif\" alt=\"Laddar...\">"; }
	if (window.XMLHttpRequest) {
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/html');
		}
	} else if (window.ActiveXObject) {
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
		try {
			http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	if (!http_request) {
		alert('Ett fel uppstod.');
		return false;
	}
	http_request.onreadystatechange = function() { alertCommonAjaxContent(http_request, target, loader, evalAfter) };
	http_request.open('POST', url, true);
	http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http_request.setRequestHeader("Content-length", postData.length);
	http_request.setRequestHeader("Connection", "close");
	http_request.send(postData);
}
//Common AJAX response function
function alertCommonAjaxContent(http_request, target, loader, evalAfter) {
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			if(loader!=null) { loader.innerHTML = ""; }
			if(target!=null) { target.innerHTML = http_request.responseText; }
			if(evalAfter!=null) {
				if((typeof evalAfter).toLowerCase() == "string")
					eval(evalAfter);
				else if((typeof evalAfter).toLowerCase() == "function")
					evalAfter(http_request, target, loader);
			}
		} else {
			target.innerHTML = "";
		}
	}
}
function getAjaxPostData(form) {
	var children = form.childNodes;
	var postData = "";
	for(var i = 0; i < children.length; i++) {
		if(children[i].childNodes!=null) { postData += getAjaxPostData(children[i]) }
		if(children[i].tagName=="INPUT"||children[i].tagName=="TEXTAREA"||children[i].tagName=="SELECT") {
			if(children[i].tagName=="INPUT") {
				if(children[i].type=="checkbox"||children[i].type=="radio") {
					if(children[i].checked) { postData+="&"+children[i].name+"="+convertAjaxPostData(children[i].value); }
				} else if(children[i].type!="button"&&children[i].type!="submit") {
					postData+="&"+children[i].name+"="+convertAjaxPostData(children[i].value);
				}
			} else if(children[i].tagName=="SELECT") {
				postData+="&"+children[i].name+"="+convertAjaxPostData(children[i].options[children[i].selectedIndex].value);
			} else {
				postData+="&"+children[i].name+"="+convertAjaxPostData(children[i].value);
			}
		}
	}
	return postData;
}
function convertAjaxPostData(str) {
	str=str.replace(/ /gi, '+');
	str=str.replace(/%/g, '%25');
	str=str.replace(/\//g,"%2F");
	str=str.replace(/\?/g,"%3F");
	str=str.replace(/=/g,"%3D");
	str=str.replace(/&/g,"%26");
	str=str.replace(/@/g,"%40");
	return str;
}
//Change body background src
function swapBodyBackground (src, isImage, save) {
		if(isImage==1) {
			document.body.style.backgroundImage = 'url(\'/images/layout/backgrounds/'+src+'\')';
		} else {
			document.body.style.backgroundImage = 'none';
			document.body.style.backgroundColor = src;
		}
		if(save==1) {
			createCookie('backgroundSRC',src,100);
			createCookie('backgroundIsImage',isImage,100);}}
//Show tip container
function showTip(tipStr, minWidth, maxWidth, dynWidth, imgSrc, showImg) {
	if(tipStr.length>1) {
		var tipInner = document.getElementById("tipInner");
		var tipMain = document.getElementById("tipMain");
		var tipMiddleBarUpper = document.getElementById("tipMiddleBarUpper");
		var tipMiddleBarLower = document.getElementById("tipMiddleBarLower");
		if(tipMain!=null) {
			if(maxWidth==null) { maxWidth = 220; }
			if(minWidth==null) { minWidth = 220; }
			if(dynWidth==null) { dynWidth = true; }
			tipInner.innerHTML = tipStr;
			if(tipStr.length>(maxWidth/5.5)&&dynWidth==true) {
				tipMain.style.width = maxWidth+"px";
				tipInner.style.width = (maxWidth-20)+"px";
			} else {
				tipMain.style.width = minWidth + "px";
				tipInner.style.width = (minWidth-20) + "px";
			}
			tipMiddleBarLower.style.width = tipInner.style.width;
			tipMiddleBarUpper.style.width = tipInner.style.width;
			tipMain.style.left = cX+5+"px";
			tipMain.style.top = cY+"px";
			tipMain.style.display = "inline";
		}
	}
}
//Hide tip container
function hideTip() {
	var tipMain = document.getElementById("tipMain");
	if(tipMain!=null) {
		tipMain.style.display="none";
	}
}
function tipLostFocus() {
	var tipMain = document.getElementById("tipMain");
	if(isOver(tipMain,cX,cY)) {
		return false;
	}
	hideTip();
}
//IE sucks
function get_offset(dir, elm) { var offset = elm["offset" + dir]; while(elm = elm.offsetParent) { offset += elm["offset" + dir]; } return offset; }
//Offset
function getLeft(element) {
	var left = (element.offsetLeft != 0) ? element.offsetLeft : get_offset("Left", element);
	return left;
}
function getTop(element) {
	var top = (element.offsetTop != 0) ? element.offsetTop : get_offset("Top", element);
	return top;
}
//Get element bounderies
function getBounderies(element) {
	var bounderies = []
		bounderies["x1"] = getLeft(element);
		bounderies["y1"] = getTop(element);
		bounderies["x2"] = bounderies["x1"] + element.offsetWidth;
		bounderies["y2"] = bounderies["y1"] + element.offsetHeight;
	return bounderies;	
}
//Position is over object?
function isOver(element,x,y) {
	var bounderies = getBounderies(element);
	if(x>bounderies["x1"]&&x<bounderies["x2"]&&y>bounderies["y1"]&&y<bounderies["y2"]) {
		return true;
	} else {
		return false;
	}
}
//Open "popup"
function setPopupDimensions() {
	updatePageDimensions();
	var popup = document.getElementById("popupWindow");
	popup.style.top = ((pageHeight/2)-(parseInt(popup.style.height,10)/2)-24+document.documentElement.scrollTop)+"px";
	popup.style.left = ((pageWidth/2)-(parseInt(popup.style.width,10)/2)-25+document.documentElement.scrollLeft)+"px";
}
function browsePopup(url, width) {
	var popup = document.getElementById("popupWindow");
	if(popup.style.display != "none") closePopup;
	var popupContent = document.getElementById("popupWindowContent");
	
	popupContent.style.visibility = "hidden";
	if(popup.offsetHeight==0) {
		popup.style.width = "200px";
		popup.style.height = "200px";
	//	popupContent.style.height = "170px";
		setPopupDimensions();
	}
	if(width!=null) popupContent.style.width = width+"px";
	popup.style.display = "inline";
	//var evalAfter = "animateDiv(\"popupWindow\",document.getElementById(\"popupWindowContent\").offsetWidth, document.getElementById(\"popupWindowContent\").offsetHeight,\"showPopupContent();\", \"setPopupDimensions();\")";
	var evalAfter = "var widthP = ($(\"popupWindowContent\").offsetWidth/$(\"popupWindow\").offsetWidth)*100; var heightP = ($(\"popupWindowContent\").offsetHeight/$(\"popupWindow\").offsetHeight)*100; new Effect.Parallel([new Effect.Scale(\"popupWindow\", widthP , { scaleY : false, scaleContent : false, sync: true }), new Effect.Scale(\"popupWindow\", heightP , { scaleX : false, scaleContent : false, sync: true }) ], { duration: 0.8, beforeUpdate : setPopupDimensions, afterFinish : showPopupContent });"

	commonAjax(url,"popupWindowContent","popupWindowContentLoader",evalAfter);
}
function showPopupContent() {
	document.getElementById("popupWindowContent").style.visibility="visible";
}
function closePopup () {
	var popup = document.getElementById("popupWindow");
	popup.style.display = "none";
}

//Set cookie with browser window height
createCookie('screenHeight',pageHeight,1);