﻿var lastHash="<[Nohash]>";
var isIE = (browserName=="Microsoft Internet Explorer")? true : false;
var hIframe=null;
var showLoading = true;
if(isIE) {
	hIframe = document.createElement('iframe');
	hIframe.setAttribute("id","hIframe");
	hIframe.setAttribute("name","hIframe");
	hIframe.setAttribute("height","100");
	hIframe.setAttribute("width","100");
	hIframe.setAttribute("src","/iefix.asp?"+location.hash.replace("#",""));
	hIframe.setAttribute("style","display: none; position: absolute; top:0px; left: 0px;");
}
function firefoxFix(theText) {
	var re = new RegExp("[^a-z|^0-9|^-|^=|^&|^#]", "g");
	if(theText.match(re)!=null) {
		var matches = theText.match(re).toString().split(",");
		for(var i = 0; i<matches.length;i++) {
			theText = theText.replace(matches[i],escape(matches[i]));
		}
	}
	return theText;
}
function checkAll(parentId, check) {
	var inputs=document.getElementById(parentId).getElementsByTagName("input");
	for (var i=0; i<inputs.length;i++) { if(inputs[i].type=="checkbox") { inputs[i].checked=check; } }
	validateStep(parentId);
}
function validateStep(stepId) {
	var inputs=o(stepId).getElementsByTagName("input");
	var btnNext = o("btnNext");
	if(btnNext==null) btnNext = o("btnNext"+stepId);
	if(btnNext==null) return false;
	var btnNextContainer = o("btnNextContainer");
	var checked = 0;
	var checkboxOnly = true;
	for (var i=0; i<inputs.length;i++) { if(inputs[i].type=="checkbox"&&inputs[i].checked) { checked += 1; } else if(inputs[i].type!="checkbox"){ checkboxOnly=false; break; } }
	if (checked>0||!checkboxOnly) {
		if(btnNext.tagName!="IMG") {
			btnNext.innerHTML="Gå vidare";
			btnNext.title="Gå vidare";
			btnNextContainer.style.width="75px";
		} else {
			btnNext.src = btnNext.src.replace("nochoice","go");
			btnNext.alt = "Gå vidare";
			btnNext.title = "Gå vidare";
		}
	} else {
		if(btnNext.tagName!="IMG") {
			btnNext.innerHTML="Spelar ingen roll";
			btnNext.title="Spelar ingen roll";
			btnNextContainer.style.width="120px";
		} else {
			btnNext.src = btnNext.src.replace("go","nochoice");
			btnNext.alt = "Spelar ingen roll";
			btnNext.title = "Spelar ingen roll";
		}
	}
}
function validateParent(parentId, isParent) {
	if(!isParent) {
		var inputs=document.getElementById("filterParent"+parentId).getElementsByTagName("input");
		var parent=document.getElementById("filterGenre"+parentId);
		for (var i=0; i < inputs.length;i++) { if(!inputs[i].checked) { parent.checked=false; return false; } }
		parent.checked = true;
		return true;
	} else {
		var inputs=document.getElementById("filterParent"+parentId).getElementsByTagName("input");
		var parent=document.getElementById("filterGenre"+parentId);
		if(inputs!=null) {
			for (var i=0; i < inputs.length;i++) { inputs[i].checked = parent.checked; }
		}
	}
}
function toggleParent(parentId, toggleBit) {
	var child = document.getElementById("filterParent"+parentId);
	var pImg = document.getElementById("parentImg"+parentId);
	if(child.style.display=="none"&&toggleBit!=2) {
		Effect.toggle(child.id, "blind", { duration: 0.2 });
		//child.style.display="block";
		pImg.src = "/images/icons/smallminus.gif";
	} else if(toggleBit!=1) {
		//child.style.display="none";
		Effect.toggle(child.id, "blind", { duration: 0.2 });
		pImg.src = "/images/icons/smallplus.gif";
	}
}
function replaceInHash(word, value) {
	var strHash = location.hash;
	word = "&" + word + "=";
	var indWord = strHash.indexOf(word);
	if(indWord==-1) indWord = strHash.indexOf(word.substring(1));
	if(indWord!=-1) {
		var indAmp = strHash.substring(indWord+1).indexOf('&')+1;
		strHash = strHash.substring(0,indWord) + ((indWord!=1)? word : word.substring(1)) + value + ((indAmp!=0)? strHash.substring(indWord+indAmp): "");
	} else {
		strHash += word+value;
	}
	location.hash = strHash;
}
	
function createHash () {
		var theForm = document.getElementById('locationForm');
		var strHash='';
		if(theForm!=null) {
			var inputs = theForm.getElementsByTagName('input');
			for(var i=0;i<inputs.length;i++) {
				if(((inputs[i].type == 'checkbox'||inputs[i].type == 'radio')&&inputs[i].checked)||inputs[i].type=='hidden') {
					strHash+= '&' + inputs[i].name + '=' + inputs[i].value;
				}
			}
		}
	strHash = (strHash.substring(0,1)=='&')? strHash.substring(1,strHash.length) : strHash;
	location.hash = strHash;
	loadUrl();
}
function loadUrl()	{
	if(lastHash==location.hash) {
		return;
	}
	lastHash = location.hash;
	if(pageTracker)
		pageTracker._trackPageview("/falken/?" + location.hash.replace("#",""));
	if(isIE) { hIframe.setAttribute("src","/iefix.asp?" + location.hash.replace("#","")); }
	initState(location.hash);
}
function initState(strHash) {
	getLocations(firefoxFix(strHash));
}
function getLocations(strHash) {
  commonAjax('/getlocations'+((strHash.indexOf('test')>-1)? '2' : '')+'.wu?'+strHash.replace('#',''),'ajaxContent',(showLoading)?'loaderContent':null,"showLoading = true; updateColor(); if(o('last-step-placer')!=null) { Effect.ScrollTo('last-step-placer'); } if(o('btnNext')!=null) { o('btnNext').style.display='inline'; } if(o('NoScriptSubmit')!=null) { o('NoScriptSubmit').style.display='none'; }");
}
function updateColor() {
	if(o("falken-type-background")) {
		var color = o("falken-type-background").className.substring(o("falken-type-background").className.indexOf(" ")+1);
		o("falken-upper-background").className = "falken-background " + color;
		o("falken-upper-header").className = "header20 " + color;
		o("falken-upper-button").src = "/images/layout/borders/header20_" + color + "_button.gif";
	}
}
window.onload = function() {
if(isIE) {
	document.body.appendChild(hIframe);
	document.getElementById("hIframe").style.display = "none";
	hIframe.setAttribute("src","/iefix.asp?"+location.hash.replace("#",""));
}
loadUrl();
setInterval(loadUrl, 100);
}
