function getPosition(elm)
{
   var pos = new Object();
   pos.x = 0;
   pos.y = 0;
   if (elm.offsetParent)
   {
      while (elm.offsetParent)
      {
         pos.x += elm.offsetLeft;
         pos.y += elm.offsetTop;
         elm = elm.offsetParent;
      }
   }
   else
   {
      if (elm.x)
      {
         pos.x = elm.x;
         pos.y = elm.y;
      }
   }
   return pos;
}

   
   function checkBrowser(){
      btype = "browser not detected: \n"+navigator.appVersion;
      if(navigator.appVersion.indexOf("Safari") >= 0){
         btype = "Safari";
      } else if (navigator.appVersion.indexOf("MSIE") >= 0 && navigator.appVersion.indexOf("Macintosh") >= 0){
         btype = "Macexplorer";
      } else if (navigator.appVersion.indexOf("5.0 (Macintosh; en-US)") >=0 && navigator.appName.indexOf("Netscape") >= 0){
         btype = "Firerfox";	
      } else if (navigator.appVersion.indexOf("MSIE") >= 0 && navigator.appVersion.indexOf("Windows") >= 0){
         btype = "PCexplorer";
      }

      return btype;
   }

   function layout(){
      var winWidth = window.innerWidth;
      if (winWidth == null)
         winWidth = document.body.clientWidth;
      var winHeight = window.innerHeight;
      if (winHeight == null)
         winHeight = document.body.clientHeight;

      var mainDiv = document.getElementById("maincontainer");
      var leftMargin = (winWidth - 950) / 2;
      mainDiv.style.marginLeft = leftMargin + "px";

      var leftDiv = document.getElementById("sideburnsleft");
      var bodyDiv = document.getElementById("bodycontainer");
      var rightDiv = document.getElementById("sideburnsright");

      var bodyPos = getPosition(bodyDiv);
      var bodyHeight = bodyDiv.clientHeight;

      bodyPos = getPosition(bodyDiv);
      bodyHeight = bodyDiv.clientHeight;

      var cornLeft = document.getElementById("cornleft");
      var cornRight = document.getElementById("cornright");
      var cornRightImage = document.getElementById("cornrightimg");

      var maxCornWidth = Math.floor((document.body.clientWidth - bodyDiv.clientWidth) / 2);

      cornLeft.style.display = "block";
      cornLeft.style.left = bodyPos.x - 188 + "px";
      //if (document.body.className != "template_forside")
      //   cornLeft.src = "/system/modules/no.klapp.norgesmollene.mollerens/resources/grafikk/melaks_left_underside.png";

      cornRight.getElementsByTagName("IMG")[0].style.display = "block";
      cornRight.style.width = maxCornWidth + "px";
      cornRight.style.left = bodyPos.x + 904 + "px";

      var footer = document.getElementById("footer");
      var bodyPaddingBottom = parseInt(bodyDiv.style.paddingBottom, 10);
      if (isNaN(bodyPaddingBottom))
         bodyPaddingBottom = 0;
      bodyHeight -= bodyPaddingBottom;
      footer.style.left = bodyPos.x + 30 + "px";
      var mainHeight = bodyPos.y + bodyHeight;
      if (winHeight > mainHeight + 50)
      {
         bodyDiv.style.paddingBottom = winHeight - bodyPos.y - bodyHeight + "px";
         footer.style.top = winHeight - 90 + "px";
      }
      else
      {
         bodyDiv.style.paddingBottom = "88px";
         footer.style.top = bodyPos.y + bodyHeight + 10 + "px";
      }
      bodyPaddingBottom = parseInt(bodyDiv.style.paddingBottom, 10);
      //alert(bodyPaddingBottom);
      leftDiv.style.display = "block";
      leftDiv.style.left = bodyPos.x - 16 + "px";
      leftDiv.style.top = bodyPos.y + "px";
      leftDiv.style.height = bodyHeight + bodyPaddingBottom + "px";

      rightDiv.style.display = "block";
      rightDiv.style.left = bodyPos.x + 904 + "px";
      rightDiv.style.top = bodyPos.y + "px";
      rightDiv.style.height = bodyHeight + bodyPaddingBottom + "px";

      // Vise footer
      footer.style.visibility = "visible";


      return;
   }

   function layoutXXX(){
      var winWidth = window.innerWidth;
      if (winWidth == null)
         winWidth = document.body.clientWidth;
      var winHeight = window.innerHeight;
      if (winHeight == null)
         winHeight = document.body.clientHeight;

      var mainDiv = document.getElementById("maincontainer");
      var leftMargin = (winWidth - 950) / 2;
      mainDiv.style.marginLeft = leftMargin + "px";

      var leftDiv = document.getElementById("sideburnsleft");
      var bodyDiv = document.getElementById("bodycontainer");
      var rightDiv = document.getElementById("sideburnsright");

      var bodyPos = getPosition(bodyDiv);
      var bodyHeight = bodyDiv.clientHeight;

      bodyPos = getPosition(bodyDiv);
      bodyHeight = bodyDiv.clientHeight;

      var cornLeft = document.getElementById("cornleft");
      var cornRight = document.getElementById("cornright");
      var cornRightImage = document.getElementById("cornrightimg");

      var maxCornWidth = Math.floor((document.body.clientWidth - bodyDiv.clientWidth) / 2);

      cornLeft.style.display = "block";
      cornLeft.style.left = bodyPos.x - 188 + "px";

      cornRight.getElementsByTagName("IMG")[0].style.display = "block";
      cornRight.style.width = maxCornWidth + "px";
      cornRight.style.left = bodyPos.x + 909 + "px";

      var footer = document.getElementById("footer");
      var bodyPaddingBottom = parseInt(bodyDiv.style.paddingBottom, 10);
      if (isNaN(bodyPaddingBottom))
         bodyPaddingBottom = 0;
      bodyHeight -= bodyPaddingBottom;
      footer.style.left = bodyPos.x + 30 + "px";
      var winHeight = window.innerHeight;
      if (winHeight == null)
         winHeight = document.body.clientHeight;
      var mainHeight = bodyPos.y + bodyHeight;
      if (winHeight > mainHeight + 50)
      {
         bodyDiv.style.paddingBottom = winHeight - bodyPos.y - bodyHeight + "px";
         footer.style.top = winHeight - 58 + "px";
      }
      else
      {
         bodyDiv.style.paddingBottom = "70px";
         footer.style.top = bodyPos.y + bodyHeight + 20 + "px";
      }
      bodyPaddingBottom = parseInt(bodyDiv.style.paddingBottom, 10);
      //alert(bodyPaddingBottom);
      leftDiv.style.display = "block";
      leftDiv.style.left = bodyPos.x - 16 + "px";
      leftDiv.style.top =  "0px";
      leftDiv.style.height = bodyPos.y + bodyHeight + bodyPaddingBottom + "px";

      rightDiv.style.display = "block";
      rightDiv.style.left = bodyPos.x + 903 + "px";
      rightDiv.style.top = "0px";
      rightDiv.style.height = bodyPos.y + bodyHeight + bodyPaddingBottom + "px";


      return;
   }


var inputValue = null;
var queryString = null;

function inputFocus(evt)
{
   var target = evt.target;
   if (target == null)
      target = evt.srcElement;
   if (target != null)
   {
      inputValue = target.value;
      target.value = "";
   }
}
 
function inputBlur(evt)
{
   //alert("blur - " + inputValue);
   var target = evt.target;
   if (target == null)
      target = evt.srcElement;
   if (target != null && inputValue != null)
   {
      queryString = target.value;
      target.value = inputValue;
      window.setTimeout("queryString = null;", 100); // Gi klikk i div-en en sjanse
   }
   target.style.display = "none";
}

function inputSearchCheckSubmit(evt, baseUrl)
{
   var target = evt.target;
   if (target == null)
      target = evt.srcElement;
   var input = target;
   if (target.tagName != "INPUT")
   {
      input = target.getElementsByTagName("INPUT")[0];
      if (inputValue == null)
         inputValue = input.value;
      input.style.display = "block";
 
      target.style.cursor = "pointer";
      if (queryString == null)
         input.focus();
      else
         window.location = baseUrl + "?query=" + queryString;
   }
   else
   if (evt.keyCode == 13)
   {
      window.location = baseUrl + "?query=" + target.value;
   }
}

function escramble_webmaster()
{
   var a,b,c,d,e
   a='<a href=\"mai' 
   b='webmaster'  
   c='\">'  
   a+='lto:'  
   b+='@'  
   e='</a>'  
   b+='mollerens'  
   b+='.'  
   b+='no'  
   d='webmaster'
   document.write(a+b+c+d+e)
}

function MM_CheckFlashVersion(reqVerStr,msg)
{
   with (navigator)
   {
      var isIE  = (appVersion.indexOf("MSIE") != -1 && userAgent.indexOf("Opera") == -1);
      var isWin = (appVersion.toLowerCase().indexOf("win") != -1);
      if (!isIE || !isWin)
      {  
         var flashVer = -1;
         if (plugins && plugins.length > 0)
         {
            var desc = plugins["Shockwave Flash"] ? plugins["Shockwave Flash"].description : "";
            desc = plugins["Shockwave Flash 2.0"] ? plugins["Shockwave Flash 2.0"].description : desc;
            if (desc == "") 
               flashVer = -1;
            else
            {
               var descArr = desc.split(" ");
               var tempArrMajor = descArr[2].split(".");
               var verMajor = tempArrMajor[0];
               var tempArrMinor = (descArr[3] != "") ? descArr[3].split("r") : descArr[4].split("r");
               var verMinor = (tempArrMinor[1] > 0) ? tempArrMinor[1] : 0;
               flashVer =  parseFloat(verMajor + "." + verMinor);
            }
         }
         // WebTV has Flash Player 4 or lower -- too low for video
         else 
         if (userAgent.toLowerCase().indexOf("webtv") != -1) 
            flashVer = 4.0;

         var verArr = reqVerStr.split(",");
         var reqVer = parseFloat(verArr[0] + "." + verArr[2]);
  
         if (flashVer < reqVer)
         {
            if (confirm(msg))
               window.location = "http://www.macromedia.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash";
         }
      }
   } 
}
function intToTwoDigitString(i)
{
   var s = "" + i;
   if (s.length < 2)
      s = "0" + s;
   else
   if (s.length > 2)
      s = s.substring(2);
   return s;
}
var inputBackup = null;
var activeLabel = null;
function clearInput(field)
{
   inputBackup = field.value;
   field.value = "";
}
function restoreInput(field)
{
   if (field.className == "required" || field.className == "requiredOk")
      field.className = field.value == "" ? "required" : "requiredOk";
   if (field.value == "")
      field.value = inputBackup
}
function getDateDDMMYY()
{
   var date = new Date();
   return intToTwoDigitString(date.getDate()) + "." + 
          intToTwoDigitString(date.getMonth() + 1) + "." +
          intToTwoDigitString(date.getFullYear());
}

      function handleClickInSelect(evt)
      {
         var target = evt.target;
         if (evt.target == null)
            target = evt.srcElement;
         if (target.nodeType == 3)  // Safari bug
            target = target.parentNode;
         var pos = getPosition(target);
         var list = document.getElementById("selectList");
         list.style.left = pos.x + "px";
         list.style.top = pos.y + target.clientHeight + "px";
         list.style.display = "block";
         if (evt.stopPropagation)
            evt.stopPropagation();
         else
            evt.cancelBubble = true;
      }
      function selectListItem(value)
      {
         document.getElementById("henvendelse").value = value;
      }
      function submitForm()
      {
         document.getElementById("kontaktskjema").submit();
      }
      function resetForm()
      {
         document.getElementById("kontaktskjema").reset();
      }
      function markOption(evt)
      {
         var target = evt.target;
         if (evt.target == null)
            target = evt.srcElement;
         if (target.nodeType == 3)  // Safari bug
            target = target.parentNode;
         target.style.backgroundColor = "#B1B1B1";
      }
      function unmarkOption(evt)
      {
         var target = evt.target;
         if (evt.target == null)
            target = evt.srcElement;
         if (target.nodeType == 3)  // Safari bug
            target = target.parentNode;
         target.style.backgroundColor = "#CECECE";
      }


function submitForm()
{
   document.getElementById('emailform').submit();
}

function resetForm()
{
   document.getElementById('emailform').reset();
}

function showhide(id){ 
if (document.getElementById){ 
obj = document.getElementById(id); 
if (obj.style.display == "none"){ 
obj.style.display = ""; 
} else { 
obj.style.display = "none"; 
} 
} 
} 