/* 
	activates an alternate stylesheet based on title
*/

function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

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;
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);

/*
============================================
*/

// remove?
function goLink(linkValue) {
  window.location.href = linkValue;
}


// remove?
function disBox(theAction)
{
  if (theAction == 1)
  {
		document.forms[0].from.disabled=true;
		document.forms[0].tom.disabled=true;
		document.forms[0].lakemedel.disabled=false;
		//document.forms[0].subst.disabled=false;
		document.forms[0].area.disabled=true;		
		//document.forms[0].sokradio.disabled=true;
  }
  else
  {
		document.forms[0].from.disabled=false;
		document.forms[0].tom.disabled=false;
		document.forms[0].lakemedel.disabled=false;
		//document.forms[0].subst.disabled=false;
		document.forms[0].area.disabled=false;						
		//document.forms[0].sokradio.disabled=false;
  }
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

//remove?
function openPackleafet(targ){ 
  eval(targ);
}

// remove
function CheckSearchField() 
{
  bSokOK=true;
 	search = trimString(document.forms[0].searchtext.value);
//	if (document.forms[0].searchtext.value.length<=1)  
  if (search.length<=1)  
	   if (document.forms[0].from.value=="????-mm-dd" || document.forms[0].from.value.length==0 || document.forms[0].from.value=="????-mm-dd") 
	   	  if (document.forms[0].tom.value=="????-mm-dd" || document.forms[0].tom.value.length==0 || document.forms[0].tom.value=="????-mm-dd")   
	      	 if (document.forms[0].area.value==null || document.forms[0].area.value=="all" || document.forms[0].area.value.length==0 ) 
			 	if ((document.forms[0].sokradio.value!="global") || (search.length<=1  &&  document.forms[0].sokradio.value=="global"))
           bSokOK=false;

  if(bSokOK)
  {
		document.forms[0].submit();
    return true;
  }
  else
  {
    alert("Ange minst 2 tecken.");
		document.forms[0].searchtext.focus();
  }
}

function trimString(sData){
  sData = sData.replace(/^\s*/, "").replace(/\s*$/, "");
  return sData;
}

//<!-- ITSIP PDF Print function -->
function MM_openPDFWindow(theURL,winName,features)
{
    if (pluginlist.indexOf("Acrobat Reader")!=-1)
    {
        window.open(theURL,winName,features);
    }
    /* See [Bug 2647] Adobe Reader 8.1 kan inte öppna skriv ut-fuktionen på Fass.se.
    else
    {
        acrFeatures = 'scrollbars=yes,resizable=yes,width=520, height=120';
        window.open('download_acrobat.jsp','AcrobatRequired',acrFeatures);
    }
    */

}

function MM_openDownloadWindow(theURL)
{
    window.open(theURL);
    self.close();
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

/*
	Search box
*/

function clearSearch() { 
	forms['searchform'].reset();
}
  
function clearInput(textname, textvalue) {  
    //Rensa alla 
    clearSearch();
    
    if(textname == 'searchtext1') {
      this.searchtext1.value = textvalue;
    }
    else if(textname == 'searchtext2') {
      this.searchtext2.value = textvalue;
    }
    else if(textname == 'searchtext3') {
      this.searchtext3.value = textvalue;
    }
    else if(textname == 'searchtext4') {
      this.searchtext4.value = textvalue;
    }
    else if(textname == 'searchtext5') {
      this.searchtext5.value = textvalue;
    } 
    else if(textname == 'searchtext6') {
      this.searchtext6.value = textvalue;
    }
    else if(textname == 'searchtext7') {
      this.searchtext7.value = textvalue;
    }
    else if(textname == 'searchtext8') {
      this.searchtext8.value = textvalue;
    }
    else if(textname == 'searchtext9') {
      this.searchtext9.value = textvalue;
    }
    else if(textname == 'searchtext10') {
      this.searchtext10.value = textvalue;
    }
    else if(textname == 'searchtext12') {
      this.searchtext12.value = textvalue;
    }
    else {
      alert("Inget s&ouml;kf&auml;lt ifyllt.");
      return;
    }

    //Submit form
	document.forms['searchform'].submit();
}

function reloadSetClickable(clickable)
{
    url = document.location.href;
    
    if(url.indexOf("clickable")>-1)
    {
        url = url.replace(/clickable=0/,"clickable="+clickable);
        url = url.replace(/clickable=1/,"clickable="+clickable);
        location.replace(url);
    }
    else
    {
        if(url.indexOf("?")>-1)
        {
            location.replace(url+"&clickable="+clickable);
        }
        else{
            location.replace(url+"?clickable="+clickable);
        }
    }
}
function setExpanded(id,h4,h4S,show)
{
 // id of products to show or hide
 // h4  to show/hide
 // h4S to show/hide
  if ( show=='true'){
       document.getElementById(id).style.display = 'block';
       document.getElementById(h4).style.display = 'block';
       document.getElementById(h4S).style.display = 'none';
      }
   if ( show=='false'){
   
       document.getElementById(id).style.display = 'none';
       document.getElementById(h4).style.display = 'block';
       document.getElementById(h4S).style.display = 'none';
      }
      
}

/**
 * Set the autocomplete property for an input field.
 * The property needs to be set with javascript in order for the site to validate. This is because
 * the property "autocomplete" is not valid according to w3c.
 *
 * @param inputElement The input element to append the property to.
 * @param value Either "on" or "off".
 */
function setAutocomplete(inputElement, value) { 
    if (!document.getElementById) {
	return false;
    } 

    var matchedElement = document.getElementById(inputElement); 
    matchedElement.setAttribute("autocomplete", value); 

    // Many browsers fill in the attributes anyway
    matchedElement.value = "";
} 
