if(document.all && !document.getElementById) {
    document.getElementById = function(id) {
         return document.all[id];
    }
}

function panicButton() {
  //alert("panix!");
  document.getElementById("maincont").style.display = "none";
  strOriginalTitle = document.title;
  document.title = "Statistiska centralbyrån - SKRIV UT: index för avtalade priser";
  document.getElementById("panic").style.display = "block";
  strOriginalHref = location.href;
  location.href = "#SCB_page45159__print.asp?path=xxxt7838uhy5ytty83iuyuxforden.org/www/cal/printyy33location";
}
function resetPanicAttack() {
  document.getElementById("panic").style.display = "none";
  document.title = strOriginalTitle;
  document.getElementById("maincont").style.display = "block";
  location.href = strOriginalHref;
}


function getNewSubmitForm(){
  var submitForm = document.createElement("FORM");
  document.body.appendChild(submitForm);
  submitForm.method = "GET";
  submitForm.target = "_blank";
  return submitForm;
}
//helper function to add elements to the form
function createNewFormElement(inputForm, elementName, elementValue){
  var newElement = document.createElement("<input name='"+elementName+"' type='hidden'>");
  inputForm.appendChild(newElement);
  newElement.value = elementValue;
  return newElement;
}
//function that creates the form, adds some elements, then submits it
function createFormAndSubmit(){
  var submitForm = getNewSubmitForm();
  createNewFormElement(submitForm, "field1", "somevalue");
  createNewFormElement(submitForm, "field2", "somevalue");
  submitForm.action= "someURL";
  submitForm.submit();
}
function sendToEngine(strURL) {
   senginewin = window.open(strURL,"senginewin");
   if (senginewin.focus) senginewin.focus();
}
function doSearchMore() {
  var f1 = document.searchmoreform;
  var strKeyword = f1.searchmorekeyword.value;
  if (strKeyword == "") return false;
  var strEngine = f1.selectengine.value;
  var submitForm = getNewSubmitForm();

  switch (strEngine){
    case "monster": 
        // Monster - http://jobb.monster.se/jobsearch.asp?q=________&re=0&sort=rv&tm=&cy=SE&vw=b
        sendToEngine("http://jobb.monster.se/jobsearch.asp?q=" + strKeyword + "&re=0&sort=rv&tm=&cy=SE&vw=b");
        break;
    case "dn": 
        // DN Jobb - http://www.jobbmatchning.dn.se/jobs/search_list_jobs.asp?search_type=simple_search&location=2%A3SWE%A3%A3&work_area=&free_text=_______&list_page=0&tc=1175006975066
        sendToEngine("http://www.jobbmatchning.dn.se/jobs/search_list_jobs.asp?search_type=simple_search&location=2%A3SWE%A3%A3&work_area=&free_text=" + strKeyword + "&list_page=0&tc=1175006975066");
        break;
    case "eniro":
        // Eniro - http://jobb.eniro.se/cgi/jobsearch.cgi?q=_____&subid=&region=sverige
		sendToEngine("http://jobb.eniro.se/cgi/jobsearch.cgi?q=" + strKeyword + "&subid=&region=sverige");
		break;
    case "jobbguiden":
		// OLD  JobbGuiden.se - http://www.jobbguiden.se/?page=main&region=1&category=0&keyword=______
		// OLD  sendToEngine("http://www.jobbguiden.se/?page=main&region=1&category=0&keyword=" + strKeyword);
		// JobbGuiden.se - Form GET : http://www.jobbguiden.se/SE/JobSeeker/Jobs/JobResults.aspx
		sendToEngine("http://www.jobbguiden.se/SE/JobSeeker/Jobs/JobResults.aspx?S:sbkw=" + encodeURI(strKeyword));
		break;
    case "jobs":
		// Jobs.se - http://www.jobs.se/Jobs.aspx?Categories=&Regions=&Keywords=_____
		sendToEngine("http://www.jobs.se/Jobs.aspx?Categories=&Regions=&Keywords=" + encodeURI(strKeyword));
		break;
	case "jobbregistret":
		// jobbregistret.se - http://www.jobbregistret.se/annonser
		submitForm.action = "http://www.jobbregistret.se/annonser";
		submitForm.method = "POST";
		createNewFormElement(submitForm, "term", strKeyword);
        	submitForm.submit();
		break;
    case "nyteknik":
        // NYTeknik - http://www.nyteknik.se/jobb/trafflista.aspx?kategori_yrke=&kategori_region=&fritext=_____
		sendToEngine("http://www.nyteknik.se/jobb/trafflista.aspx?kategori_yrke=&kategori_region=&fritext=" + strKeyword);
		break;
    case "lokus":
        // LOKUS - http://www.lokus.se/lokus_jobb.asp?NewUrl=http%3A//WWW.LOKUS.SE/exp_searchJobb.asp?FreeText=_______
		sendToEngine("http://www.lokus.se/lokus_jobb.asp?NewUrl=http%3A//WWW.LOKUS.SE/exp_searchJobb.asp?FreeText=" + strKeyword);
		break;
    case "merajobb":
        // Merajobb.se - http://www.merajobb.se/jobs/search_list_jobs.asp?search_type=simple_search&location=2£SWE££&free_text=_________&work_area=&list_page=0&tc=1175004948592
		sendToEngine("http://www.merajobb.se/jobs/search_list_jobs.asp?search_type=simple_search&location=2£SWE££&free_text=" + strKeyword + "&work_area=&list_page=0&tc=1175004948592");
		break;
    case "kelly":
		// Kelly Services - http://se.livejobs.recruitadvantage.com/job/job_search_result.cfm?cLang=Swedish&frm_loc_id=0&frm_ind_id=0&frm_job_type_id=0&frm_keyword=_________
		sendToEngine("http://se.livejobs.recruitadvantage.com/job/job_search_result.cfm?cLang=Swedish&frm_loc_id=0&frm_ind_id=0&frm_job_type_id=0&frm_keyword=" + encodeURI(strKeyword));
		break;
    case "towork":
		// ToWork.se - http://www.towork.se/lediga-jobb?txt=_____
		sendToEngine("http://www.towork.se/lediga-jobb?txt=" + encodeURI(strKeyword));
		break;
    case "ams":
		// $ej_ok_chars = array("å","ä","ö"); $ok_chars = array("%e5","%e4","%f6"); 
        // Platsbanken - http://platsbanken.ams.se/platsbanken.cgi/go/day=4165/days=30/search=________/words/show#5
        submitForm.action = "http://platsbanken.ams.se/platsbanken.cgi/go/day=4165/days=30/search=" + escape(strKeyword) + "/words/show#5";
        submitForm.submit();
        break;
   case "jobb24":
		// Jobb24.se - http://www.jobb24.se/jobb24/job/fulltime/result
		submitForm.action = "http://www.jobb24.se/jobb24/job/fulltime/result";
		submitForm.method = "POST";
		createNewFormElement(submitForm, "sort", "0");
		createNewFormElement(submitForm, "keyword", strKeyword);
		submitForm.submit();
		break;
    case "jobbexpressen":
		// jobbexpressen - http://www.jobbexpressen.se/annons/resultat/?c=&g=&text=_____
		sendToEngine("http://www.jobbexpressen.se/annons/resultat/?c=&g=&text=" + escape(strKeyword));
		break;	
	case "jobb365":
		// BORTTAGEN! jobb365.se - http://www.jobb365.se/lediga_jobb.php?fritext=___
		sendToEngine("http://www.jobb365.se/lediga_jobb.php?fritext=" + escape(strKeyword));
		break;
	case "offentliga":
		// offentligajobb.se - http://www.offentligajobb.se/public_user/searchres.aspx?RegionStateCode=0&SearchString=___
		sendToEngine("http://www.offentligajobb.se/public_user/searchres.aspx?RegionStateCode=0&SearchString=" + escape(strKeyword));
		break;
	case "volvo":
		// Volvo.com http://lnosvolvoext06.it.volvo.se/volvo/jobpostings.nsf/SearchPostingsAllextnew?SearchView&Query=_________+and+(?)+and+(?)+and+(field+country=sweden)+and+(?)&SearchOrder=4&SearchMax=0
		break;
	case "stepstone":
		// BORTTAGEN! stepstone.se - form submit
		submitForm.action = "http://www.stepstone.se/controllers/searchListingController.cfc?searchtype=freetext&newsearch=1&allowJAPU=1";
		submitForm.method = "POST";
		createNewFormElement(submitForm, "logsearchtype", "freetext search on homepage main frame");
		//createNewFormElement(submitForm, "searchtype", "freetext");
		//createNewFormElement(submitForm, "newsearch", "1");
		createNewFormElement(submitForm, "radioStemming", "yes");
		createNewFormElement(submitForm, "radioOperator", "opor");
		createNewFormElement(submitForm, "chkboxTitle", "no");
		createNewFormElement(submitForm, "relevance", "1");
		createNewFormElement(submitForm, "keyword", strKeyword);
        submitForm.submit();
		break;
    case "":
		alert("Välj en sökmotor i listan!");
		break;
    default :
       alert("Ett fel inträffade! Försök med en annan sökmotor.");
       return false;
  }
}

function findPosition( oElement ) {
  if( typeof( oElement.offsetParent ) != 'undefined' ) {
    for( var posX = 0, posY = 0; oElement; oElement = oElement.offsetParent ) {
      posX += oElement.offsetLeft;
      posY += oElement.offsetTop;
    }
    return [ posX, posY ];
  } else {
    return [ oElement.x, oElement.y ];
  }
}

function focusSearchField() {
	if (document.forms[0]) {
		if (document.forms[0].searchquery) {
			if (document.forms[0].searchquery.value == "") {
				document.forms[0].searchquery.value = " ";
				document.forms[0].searchquery.value = "";
			}
			document.forms[0].searchquery.focus();
		}
	}
}