// Place your application-specific JavaScript functions and classes here  
// This file is automatically included by javascript_include_tag :defaults

  function MM_swapImgRestore() { //v3.0
    var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
  }

  function MM_preloadImages() { //v3.0
    var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
      if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
  }

  function MM_findObj(n, d) { //v4.01
    var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
      d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
      if(!(x=d[n])&&d.all) x=d.all[n]; 
      for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
      for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
      if(!x && d.getElementById) x=d.getElementById(n); 
      return x;
  }

  function MM_swapImage() { //v3.0
    var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array;
	for(i=0;i<(a.length-2);i+=3)
      if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x;
	if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];
	}
  }
  
  // Function to display a message box in a TD element within a previously hidden DIV element.
  // Define the DIV element with styles "display:none; position:absolute; z-index:2;"
  // The WIDTH attribute of the TABLE element must also be defined in the html code;
  //   otherwise, the positioning logic in this script may fail.
  // Parameters:
  //    objDiv - the hidden DIV element
  //    objTbl - a table element within the hidden DIV element
  //    objTh  - a TH element within the table
  //    objTd  - a TD element within the table
  //    objClicked - an element over which the message box will be displayed
  //    strHeading - a heading for the message.
  //    strHtmlTxt - the message to be displayed.
  function show_msgbox(objDiv, objTbl, objTh, objTd, objClicked, strHeading, strHtmlTxt) {//v1.0

    // Get the clicked obect's position relative to the top left of the page:
	var x = objClicked.offsetLeft;
	var y = objClicked.offsetTop;

	// Get the dimensions of the browser window:
    var wndWidth = 0;
    var wndHeight = 0;

    if (window.innerWidth)
      wndWidth = window.innerWidth;
    else if (document.documentElement && document.documentElement.clientWidth)
      wndWidth = document.documentElement.clientWidth;
    else if (document.body)
      wndWidth = document.body.clientWidth;

    if(window.innerHeight)
      wndHeight = window.innerHeight;
	else if (document.documentElement && document.documentElement.clientHeight)
      wndHeight = document.documentElement.clientHeight;
    else if (document.body)
      wndHeight = document.body.clientHeight;

    // Get the scroll offsets of the visible portion of the document:
	var scrollLeft = 0;
	var scrollTop = 0;
    if(document.body) {
      scrollLeft = document.body.scrollLeft;
      scrollTop = document.body.scrollTop;
      }
	else {
      scrollLeft = document.childNodes.item(0).scrollLeft;
      scrollTop = document.childNodes.item(0).scrollTop;
	}

    // Adjust the box's horizontal position if necessary based on the predefined width of the table element:
    var w = (objTbl.width*1) + 40;
    if( (x+w)-scrollLeft > wndWidth ) {
	  if( w > wndWidth ) {
	  	x = scrollLeft;
        }
	  else {
        x = wndWidth+scrollLeft-w;
		}
	  }

	// Then display the object in order to measure its height:
    objDiv.style.left=x;
    objDiv.style.top=y;
    objTh.innerHTML=strHeading;
    objTd.innerHTML='<font size=-2>'+(String(strHtmlTxt)).replace(/__%/g,"\"")+'</font>';
    objDiv.style.display='inline';

    // Finally, adjust the vertical position if necessary:	
	var h = objDiv.clientHeight+40;

    if( (y+h)-scrollTop > wndHeight ) {
      if( h > wndHeight ) {
        objDiv.style.top = scrollTop;
	    }
	  else {
        objDiv.style.top = wndHeight+scrollTop-h;
	  	}
	  }
  }
  var bDragging=false;

  // Function to move a DIV element to the new mouse position.
  function move_msg_box(objClicked) {
  	
	if( bDragging == false )
	  return false;

    // Get the clicked obect's position relative to the top left of the page:
    var x = objClicked.offsetLeft;
    var y = objClicked.offsetTop;    
    }

// Function to re-hide a DIV element that was revealed by calling show_msgbox, above. 
 function hide_msgbox(objDiv) {//v1.0
 	objDiv.style.display='none';
}

// Function to open a pop-up web page with contents of /extra/more_info/page/<page_id>
function popup_moreinfo(id) {//v1.0
  window.open("/extra/more_info_page/"+id, "more_info", "width=500,height=500,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes");
}

// Function to open a pop-up web page with contents of passed-in url:
function popup_external(url, width, height) {
  window.open("http://"+url, "_blank", "width="+width+",height="+height+",status=no,toolbar=no,menubar=no,location=no,scrollbars=yes");
}
    
function mark_for_destroy(element) {
  $(element).next('should_destroy').value=1;
  $(element).hide;
}

function displayLayer(which) {
	obj = document.getElementById(which);
	if (obj.style.display == "block") {
    obj.style.display = "none";
    obj.style.visibility = "hidden";
  }
  else {
    obj.style.display = "block";
    obj.style.visibility = "visible";
    document.getElementById("imgLoading").src = "/images/globe64.gif";
    setTimeout('document.images["imgLoading"].src = "/images/globe64.gif"', 200); 
 //   document.getElementById("imgLoading").style.backgroundImage = "/images/sokning_pagar.gif";
  }
}



/************************************************************************************************************
(C) www.dhtmlgoodies.com, November 2005

This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website.	

Terms of use:
You are free to use this script as long as the copyright message is kept intact. However, you may not
redistribute, sell or repost it without our permission.

Thank you!

www.dhtmlgoodies.com
Alf Magne Kalleland

************************************************************************************************************/

var dhtmlgoodies_slideSpeed = 20;	// Higher value = faster
var dhtmlgoodies_timer = 1;	// Lower value = faster

var objectIdToSlideDown = false;
var dhtmlgoodies_activeId = false;
var dhtmlgoodies_slideInProgress = false;
function showHideContent(e,inputId)
{
	if(dhtmlgoodies_slideInProgress)return;
	dhtmlgoodies_slideInProgress = true;
	if(!inputId)inputId = this.id;
	inputId = inputId + '';
	var numericId = inputId.replace(/[^0-9]/g,'');
	var answerDiv = document.getElementById('dhtmlgoodies_a' + numericId);

	objectIdToSlideDown = false;
	
	if(!answerDiv.style.display || answerDiv.style.display=='none'){		
		if(dhtmlgoodies_activeId &&  dhtmlgoodies_activeId!=numericId){			
			objectIdToSlideDown = numericId;
			slideContent(dhtmlgoodies_activeId,(dhtmlgoodies_slideSpeed*-1));
		}else{
			
			answerDiv.style.display='block';
			answerDiv.style.visibility = 'visible';
			
			slideContent(numericId,dhtmlgoodies_slideSpeed);
		}
	}else{
		slideContent(numericId,(dhtmlgoodies_slideSpeed*-1));
		dhtmlgoodies_activeId = false;
	}	
}

function slideContent(inputId,direction)
{
	
	var obj =document.getElementById('dhtmlgoodies_a' + inputId);
	var contentObj = document.getElementById('dhtmlgoodies_ac' + inputId);
	height = obj.clientHeight;
	if(height==0)height = obj.offsetHeight;
	height = height + direction;
	rerunFunction = true;
	if(height>contentObj.offsetHeight){
		height = contentObj.offsetHeight;
		rerunFunction = false;
	}
	if(height<=1){
		height = 1;
		rerunFunction = false;
	}

	obj.style.height = height + 'px';
	var topPos = height - contentObj.offsetHeight;
	if(topPos>0)topPos=0;
	contentObj.style.top = topPos + 'px';
	if(rerunFunction){
		setTimeout('slideContent(' + inputId + ',' + direction + ')',dhtmlgoodies_timer);
	}else{
		if(height<=1){
			obj.style.display='none'; 
			if(objectIdToSlideDown && objectIdToSlideDown!=inputId){
				document.getElementById('dhtmlgoodies_a' + objectIdToSlideDown).style.display='block';
				document.getElementById('dhtmlgoodies_a' + objectIdToSlideDown).style.visibility='visible';
				slideContent(objectIdToSlideDown,dhtmlgoodies_slideSpeed);				
			}else{
				dhtmlgoodies_slideInProgress = false;
			}
		}else{
			dhtmlgoodies_activeId = inputId;
			dhtmlgoodies_slideInProgress = false;
		}
	}
}


function initDropMenu() {
	// Testa ifall webbläsaren klarar av DOM-metoderna som används, samt se till så att menyn hittas i HTML-koden.
	if(!document.getElementById) return false;
	if(!document.getElementsByTagName) return false;
	if(!document.getElementById("dropdownnav")) return false;
	
	// Hitta alla länkar i menyn.
	var dropdownnav = document.getElementById("dropdownnav");
	var menuLinks = dropdownnav.getElementsByTagName("a");
	
	// Loopa igenom alla länkar
	for(i=0;i<menuLinks.length;i++) {
		// Kolla ifall länkarna är i en submeny.
		if(menuLinks[i].parentNode.parentNode.className != 'dropsubMenu') {
			// Är länkarna inte i en submeny, gör så att inget händer när man klicker på dem.
			menuLinks[i].onclick = function() {
				return false;
			}
			// Bind funktionen för att visa submenyn till li-elementet som är ovanför länken i DOM-strukturen.
			menuLinks[i].parentNode.onmouseover = function() {
				this.getElementsByTagName("ul")[0].style.display = 'block';
			}
			// Bind funktionen för att gömma submenyn till li-elementet som är ovanför länken i DOM-strukturen.
			menuLinks[i].parentNode.onmouseout = function() {
				this.getElementsByTagName("ul")[0].style.display = 'none';
			}
		}
	}
}

// Kör funktionen som initierar menyn när sidan har laddats.



function initShowHideDivs()
{
	var divs = document.getElementsByTagName('DIV');
	var divCounter = 1;
	for(var no=0;no<divs.length;no++){
		if(divs[no].className=='dhtmlgoodies_question'){
			divs[no].onclick = showHideContent;
			divs[no].id = 'dhtmlgoodies_q'+divCounter;
			var answer = divs[no].nextSibling;
			while(answer && answer.tagName!='DIV'){
				answer = answer.nextSibling;
			}
			answer.id = 'dhtmlgoodies_a'+divCounter;	
			contentDiv = answer.getElementsByTagName('DIV')[0];
			contentDiv.style.top = 0 - contentDiv.offsetHeight + 'px'; 	
			contentDiv.className='dhtmlgoodies_answer_content';
			contentDiv.id = 'dhtmlgoodies_ac' + divCounter;
			answer.style.display='none';
			answer.style.height='1px';
			divCounter++;
		}		
	}	
}


/*

CUSTOM FORM ELEMENTS

Created by Ryan Fait
www.ryanfait.com

The only thing you need to change in this file is the following
variables: checkboxHeight, radioHeight and selectWidth.

Replace the first two numbers with the height of the checkbox and
radio button. The actual height of both the checkbox and radio
images should be 4 times the height of these two variables. The
selectWidth value should be the width of your select list image.

You may need to adjust your images a bit if there is a slight
vertical movement during the different stages of the button
activation.

Visit http://ryanfait.com/ for more information.

*/

var checkboxHeight = "25";
var radioHeight = "25";
var selectWidth = "190";

/* No need to change anything after this */

document.write('<style type="text/css">input.styled { display: none; } select.styled { position: relative; width: ' + selectWidth + 'px; opacity: 0; filter: alpha(opacity=0); z-index: 5; }</style>');

var Custom = {
	init: function() {
		var inputs = document.getElementsByTagName("input"), span = Array(), textnode, option, active;
		for(a = 0; a < inputs.length; a++) {
			if((inputs[a].type == "checkbox" || inputs[a].type == "radio") && inputs[a].className == "styled") {
				span[a] = document.createElement("span");
				span[a].className = inputs[a].type;

				if(inputs[a].checked == true) {
					if(inputs[a].type == "checkbox") {
						position = "0 -" + (checkboxHeight*2) + "px";
						span[a].style.backgroundPosition = position;
					} else {
						position = "0 -" + (radioHeight*2) + "px";
						span[a].style.backgroundPosition = position;
					}
				}
				inputs[a].parentNode.insertBefore(span[a], inputs[a]);
				inputs[a].onchange = Custom.clear;
				span[a].onmousedown = Custom.pushed;
				span[a].onmouseup = Custom.check;
				document.onmouseup = Custom.clear;
			}
		}
		inputs = document.getElementsByTagName("select");
		for(a = 0; a < inputs.length; a++) {
			if(inputs[a].className == "styled") {
				option = inputs[a].getElementsByTagName("option");
				active = option[0].childNodes[0].nodeValue;
				textnode = document.createTextNode(active);
				for(b = 0; b < option.length; b++) {
					if(option[b].selected == true) {
						textnode = document.createTextNode(option[b].childNodes[0].nodeValue);
					}
				}
				span[a] = document.createElement("span");
				span[a].className = "select";
				span[a].id = "select" + inputs[a].name;
				span[a].appendChild(textnode);
				inputs[a].parentNode.insertBefore(span[a], inputs[a]);
				inputs[a].onchange = Custom.choose;
			}
		}
	},
	pushed: function() {
		element = this.nextSibling;
		if(element.checked == true && element.type == "checkbox") {
			this.style.backgroundPosition = "0 -" + checkboxHeight*3 + "px";
		} else if(element.checked == true && element.type == "radio") {
			this.style.backgroundPosition = "0 -" + radioHeight*3 + "px";
		} else if(element.checked != true && element.type == "checkbox") {
			this.style.backgroundPosition = "0 -" + checkboxHeight + "px";
		} else {
			this.style.backgroundPosition = "0 -" + radioHeight + "px";
		}
	},
	check: function() {
		element = this.nextSibling;
		if(element.checked == true && element.type == "checkbox") {
			this.style.backgroundPosition = "0 0";
			element.checked = false;
		} else {
			if(element.type == "checkbox") {
				this.style.backgroundPosition = "0 -" + checkboxHeight*2 + "px";
			} else {
				this.style.backgroundPosition = "0 -" + radioHeight*2 + "px";
				group = this.nextSibling.name;
				inputs = document.getElementsByTagName("input");
				for(a = 0; a < inputs.length; a++) {
					if(inputs[a].name == group && inputs[a] != this.nextSibling) {
						inputs[a].previousSibling.style.backgroundPosition = "0 0";
					}
				}
			}
			element.checked = true;
		}
	},
	clear: function() {
		inputs = document.getElementsByTagName("input");
		for(var b = 0; b < inputs.length; b++) {
			if(inputs[b].type == "checkbox" && inputs[b].checked == true && inputs[b].className == "styled") {
				inputs[b].previousSibling.style.backgroundPosition = "0 -" + checkboxHeight*2 + "px";
			} else if(inputs[b].type == "checkbox" && inputs[b].className == "styled") {
				inputs[b].previousSibling.style.backgroundPosition = "0 0";
			} else if(inputs[b].type == "radio" && inputs[b].checked == true && inputs[b].className == "styled") {
				inputs[b].previousSibling.style.backgroundPosition = "0 -" + radioHeight*2 + "px";
			} else if(inputs[b].type == "radio" && inputs[b].className == "styled") {
				inputs[b].previousSibling.style.backgroundPosition = "0 0";
			}
		}
	},
	choose: function() {
		option = this.getElementsByTagName("option");
		for(d = 0; d < option.length; d++) {
			if(option[d].selected == true) {
				document.getElementById("select" + this.name).childNodes[0].nodeValue = option[d].childNodes[0].nodeValue;
			}
		}
	}
}



window.onload = function(){
initDropMenu();
initShowHideDivs();
Custom.init();
}
