function isValid() {
	var area=document.searchForm.freeTextSearch.value;
	if (area != "" ) return true;
	else alert ('Du måste ange en ort eller stadsdel!');
 return false;
}


function ShowOrHide(d) {
if(d.length < 1) { return; }
if(document.getElementById(d).style.display == "none") { document.getElementById(d).style.display = "block"; }
else { document.getElementById(d).style.display = "none"; }
}

function Show(d) {
if(d.length < 1) { return; }
document.getElementById(d).style.display = "block"; 
}

function Hide(d) {
if(d.length < 1) { return; }
document.getElementById(d).style.display = "none"; 
}

function calcHeight()
{
	//find the height of the internal page
	var the_height=document.getElementById('mypagewindow').contentWindow.document.getElementById('mp').scrollHeight;
//	the_height = the_height + 13;
	the_height = the_height + 80; // ändrat av PG 081023
	
	document.getElementById('mypagewindow').height=the_height;//change the height of the iframe
}

// Dynamic Iframe loader 
function loadIframe(theURL) {
	
	document.getElementById('min-sida').style.display = "block";
	// IE and Safari
	if(navigator.userAgent.indexOf("MSIE") != -1 )
		window.frames("mypagewindow").location.href = theURL;
	// Safari
	else if(navigator.userAgent.indexOf("Safari") != -1 )
		document.getElementById('mypagewindow').src = theURL;
	//  Firefox
	else if(navigator.userAgent.indexOf("Firefox") != -1 )
		document.getElementById('mypagewindow').contentWindow.location.href = theURL;
	else
		document.getElementById('mypagewindow').location.href = theURL;
	
}

function calcStoreHeight()
{
	//find the height of the internal page
	var the_height=document.getElementById('mystorewindow').contentWindow.document.getElementById('mystore').scrollHeight;
//	var the_height = the_height + document.getElementById('mystorewindow').contentWindow.document.getElementById('a').scrollHeight;
	
//	the_height = the_height + 393;
	the_height = the_height + 10;
	
	document.getElementById('mystorewindow').height=the_height; //change the height of the iframe
}

function loadStoreIframe(theURL) {
	
	document.getElementById('butiken').style.display = "block";
	// IE 
	if(navigator.userAgent.indexOf("MSIE") != -1  )
		window.frames("mystorewindow").location.href = theURL;
	// Safari
	else if(navigator.userAgent.indexOf("Safari") != -1 )
		document.getElementById('mystorewindow').src = theURL;
	// Firefox
	else if(navigator.userAgent.indexOf("Firefox") != -1  )
		document.getElementById('mystorewindow').contentWindow.location.href = theURL;
	// andra..
	else
		document.getElementById('mystorewindow').location.href = theURL;
}

function addSubmitValueInit(level){
	
	var theValuestring;
	
	if(level == 1){
		theValuestring = "Välj kommun";
		document.adFormInit.getDinfoInit.value = theValuestring;
	}
	else if(level == 2)
	{
		theValuestring = document.adFormInit.adMunicipalityIDInit.options[document.adFormInit.adMunicipalityIDInit.selectedIndex].text;
		document.adFormInit.getDinfoInit.value = theValuestring;
	}
	else if(level == 3)
	{
		theValuestring = document.adFormInit.adAreaInit.options[document.adFormInit.adAreaInit.selectedIndex].text;
		document.adFormInit.getDinfoInit.value = theValuestring;
	}
	
}

function addSubmitValue(level){
	
	var theValuestring;
	
	if(level == 1){
		theValuestring = "Välj kommun";
		document.adForm.getDinfo.value = theValuestring;
	}
	else if(level == 2)
	{
		theValuestring = document.adForm.adMunicipalityID.options[document.adForm.adMunicipalityID.selectedIndex].text;
		document.adForm.getDinfo.value = theValuestring;
	}
	else if(level == 3)
	{
		theValuestring = document.adForm.adArea.options[document.adForm.adArea.selectedIndex].text;
		document.adForm.getDinfo.value = theValuestring;
	}
	
}

function activateSubmit()
{
	document.getElementById('getDinfo').disabled=false;
}
function deActivateSubmit()
{
	document.getElementById('getDinfo').disabled=true;
}
function activateSubmitInit()
{
	document.getElementById('getDinfoInit').disabled=false;
}
function deActivateSubmitInit()
{
	document.getElementById('getDinfoInit').disabled=true;
}

var dynamicContent_ajaxObjects = new Array();

function getMunicipalityList(sel)
{
	var adRegionID = sel.options[sel.selectedIndex].value;
	document.getElementById('adMunicipalityID').options.length = 0;	// Empty municipality select box
	document.getElementById('adMunicipalityID').options[0] = new Option('Välj Kommun','');
	document.getElementById('adArea').options.length = 0;	// Empty area select box
	document.getElementById('adArea').options[0] = new Option('Välj kommun först','');
	document.getElementById('adRegion').value = sel.options[sel.selectedIndex].text;

	
	if(adRegionID.length > 0){
	var ajaxIndex = dynamicContent_ajaxObjects.length;
	dynamicContent_ajaxObjects[ajaxIndex] = new sack();
	dynamicContent_ajaxObjects[ajaxIndex].requestFile = '/cgi-bin/setbox?adRegionID='+adRegionID;
	dynamicContent_ajaxObjects[ajaxIndex].onCompletion = function () {createMunicipalityList(dynamicContent_ajaxObjects[ajaxIndex])};	
	dynamicContent_ajaxObjects[ajaxIndex].runAJAX();
	}
}

function getMunicipalityListInit(sel)
{
	var adRegionID = sel.options[sel.selectedIndex].value;
	document.getElementById('adMunicipalityIDInit').options.length = 0;	// Empty municipality select box
	document.getElementById('adMunicipalityIDInit').options[0] = new Option('Välj Kommun','');
	document.getElementById('adAreaInit').options.length = 0;	// Empty area select box
	document.getElementById('adAreaInit').options[0] = new Option('Välj kommun först','');
	document.getElementById('adRegionInit').value = sel.options[sel.selectedIndex].text;

	
	if(adRegionID.length > 0){
	var ajaxIndex = dynamicContent_ajaxObjects.length;
	dynamicContent_ajaxObjects[ajaxIndex] = new sack();
	dynamicContent_ajaxObjects[ajaxIndex].requestFile = '/cgi-bin/setbox?adRegionID='+adRegionID;
	dynamicContent_ajaxObjects[ajaxIndex].onCompletion = function () {createMunicipalityListInit(dynamicContent_ajaxObjects[ajaxIndex])};	
	dynamicContent_ajaxObjects[ajaxIndex].runAJAX();
	}
}

function createMunicipalityList(ajaxObj)
{
	var obj = document.getElementById('adMunicipalityID');
	eval(ajaxObj.response);
}

function createMunicipalityListInit(ajaxObj)
{
	var obj = document.getElementById('adMunicipalityIDInit');
	eval(ajaxObj.response);
}

function getAreaList(sel)
{	
	var adMunicipalityID = sel.options[sel.selectedIndex].value;
	document.getElementById('adArea').options.length = 0;	// Empty city select box
	document.getElementById('adArea').options[0] = new Option('Välj område','');
	document.getElementById('adMunicipality').value = sel.options[sel.selectedIndex].text;

	if(adMunicipalityID.length>0){
	var ajaxIndex = dynamicContent_ajaxObjects.length;
	dynamicContent_ajaxObjects[ajaxIndex] = new sack();
	dynamicContent_ajaxObjects[ajaxIndex].requestFile = '/cgi-bin/setbox?adMunicipalityID='+adMunicipalityID;	
	dynamicContent_ajaxObjects[ajaxIndex].onCompletion = function () {createAreaList(dynamicContent_ajaxObjects[ajaxIndex])};	
	dynamicContent_ajaxObjects[ajaxIndex].runAJAX();		
	
	}
}

function getAreaListInit(sel)
{	
	var adMunicipalityID = sel.options[sel.selectedIndex].value;
	document.getElementById('adAreaInit').options.length = 0;	// Empty city select box
	document.getElementById('adAreaInit').options[0] = new Option('Välj område','');
	document.getElementById('adMunicipalityInit').value = sel.options[sel.selectedIndex].text;

	if(adMunicipalityID.length>0){
	var ajaxIndex = dynamicContent_ajaxObjects.length;
	dynamicContent_ajaxObjects[ajaxIndex] = new sack();
	dynamicContent_ajaxObjects[ajaxIndex].requestFile = '/cgi-bin/setbox?adMunicipalityID='+adMunicipalityID;	
	dynamicContent_ajaxObjects[ajaxIndex].onCompletion = function () {createAreaListInit(dynamicContent_ajaxObjects[ajaxIndex])};	
	dynamicContent_ajaxObjects[ajaxIndex].runAJAX();		
	
	}
}

function createAreaList(ajaxObj)
{
	var obj = document.getElementById('adArea');
	eval(ajaxObj.response);	
}

function createAreaListInit(ajaxObj)
{
	var obj = document.getElementById('adAreaInit');
	eval(ajaxObj.response);	
}

function switchBgImg(divId, filename)
{
	document.getElementById(divId).style.background = "url(../image/vinjets/" + filename + ")";
	document.getElementById(divId).style.backgroundRepeat = "no-repeat"; 
}
