/******************************************************************************
* Copyright 2000 by Mike Hall                                                 *
* Please see http://www.brainjar.com for terms of use.                        *
*                                                                             *
* Code for the site menu.                                                     *
******************************************************************************/

// Determine browser and version. Script works for IE 5.5+ and NS 6.0+

function Browser() {

  var ua, s, i;

  this.isIE    = false;
  this.isNS    = false;
  this.version = null;

  ua = navigator.userAgent;

  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }
}

var browser = new Browser();

// Global variable for tracking the currently active button.

var activeButton = null;

// Capture mouse clicks on the page so any active button can be deactivated.

if (browser.isIE)
  document.onmousedown = pageMousedown;
if (browser.isNS)
  document.addEventListener("mousedown", pageMousedown, true);

function lukdialog() {
    alert("Virker ikke endnu");
//    dialogbox.style.position = "relative";
//    dialogbox.style.visibility = "hidden";
//    boks = document.getElementById(dialogbox);
//    boks.style.visibility = "hidden";
    dialogtitel.style.visibility = "hidden";
    dialogbody.style.visibility = "hidden";
    alert("hhh");
}

function pageMousedown(event) {

  var className;

  // If the object clicked on was not a menu button or item, close any active
  // menu.

  if (browser.isIE)
    className = window.event.srcElement.className;
  if (browser.isNS)
    className = (event.target.className ?
      event.target.className : event.target.parentNode.className);

  if (className != "menuButton"  && className != "menuItem" &&
      className != "menuItemSep" && activeButton &&
      className != "siteMenuForm" && className != "siteMenuInput" &&
      className != "siteMenuSend" && className != "dontHideMenu")
    resetButton(activeButton);
}

function buttonClick(button, menuName) {

  // Blur focus from the link to remove that annoying outline.

  button.blur();

  // Associate the named menu to this button if not already done.

  if (!button.menu)
    button.menu = document.getElementById(menuName);

  // Reset the currently active button, if any.

  if (activeButton && activeButton != button)
    resetButton(activeButton);

  // Toggle the button's state.

  if (button.isDepressed)
    resetButton(button);
  else
    depressButton(button);

  return false;
}

function buttonMouseover(button, menuName) {

  // If any other button menu is active, deactivate it and activate this one.
  // Note: if this button has no menu, leave the active menu alone.

  if (activeButton && activeButton != button) {
    resetButton(activeButton);
    if (menuName)
      buttonClick(button, menuName);
  }
}

function depressButton(button) {

  // Change the button's style class to make it look like it's depressed.

  button.className = "menuButtonActive";

 // For IE, set an explicit width for the first menu item. This causes
  // mouseovers to work for all the items even when cursor is not over
  // the link text.

  if (browser.isIE && !button.menu.firstChild.style.width)
    if (browser.version < 6.0)
      button.menu.firstChild.style.width = button.menu.offsetWidth + "px";
    else
      button.menu.firstChild.style.width = "1em";

  // Position the associated drop down menu under the button and
  // show it. Note that the position must be adjusted according to
  // browser, styling and positioning.

  x = getPageOffsetLeft(button);
  y = getPageOffsetTop(button) + button.offsetHeight;
  if (browser.isNS && browser.version < 6.1) {
    x--;
    y--;
  }
  button.menu.style.left = x + "px";
  button.menu.style.top  = y + "px";

  // viser Select-boxe
  hideSelects('hidden');

  // skjuler bottom divs
  showBottom("hideAll");

  button.menu.style.visibility = "visible";

  // Set button state and let the world know which button is
  // active.

  button.isDepressed = true;
  activeButton = button;
}

function resetButton(button) {

  // Restore the button's style class.

  button.className = "menuButton";

  // Hide the button's menu.

  if (button.menu)
    button.menu.style.visibility = "hidden";

  // skjuler bottom divs
  showBottom('hideAll');

  // viser Select-boxe
  hideSelects('visible');

  // Set button state and clear active menu global.

  button.isDepressed = false;
  activeButton = null;

}

function getPageOffsetLeft(el) {

  // Return the true x coordinate of an element relative to the page.

  return el.offsetLeft + (el.offsetParent ? getPageOffsetLeft(el.offsetParent) : 0);
}

function getPageOffsetTop(el) {

  // Return the true y coordinate of an element relative to the page.

  return el.offsetTop + (el.offsetParent ? getPageOffsetTop(el.offsetParent) : 0);
}

function hideSelects(action) {
  if (browser.isIE) {
    if ( document.getElementById("selectHide1") ) {
      link1 = document.getElementById("selectHide1");
      if ( link1.isVisible == true && action == "hidden" ) {
              link1.style.visibility = "hidden";
      } else if ( link1.isVisible == true && action == "visible" ) {
              link1.style.visibility = "visible";
      }
    }
    if ( document.getElementById("selectHide2") ) {
      link1 = document.getElementById("selectHide2");
      if ( link2.isVisible == true && action == "hidden" ) {
              link2.style.visibility = "hidden";
      } else if ( link2.isVisible == true && action == "visible" ) {
              link2.style.visibility = "visible";
      }
    }
  }
}

function resizeDesign() {
  if( window.innerHeight ) {
    var y = window.innerHeight;
    var x = window.innerWidth;
  } else if (window.document.documentElement.clientHeight) {
    var y = document.documentElement.clientHeight;
    var x = document.documentElement.clientWidth;
  } else {
    var y = window.document.body.clientHeight;
    var x = window.document.body.clientWidth;
  }

  var ySoeg = y - 101;
  if ( document.getElementById("bottomSoeg") ) {document.getElementById("bottomSoeg").style.top  = ySoeg + "px";}
  var xSoeg = (x - 752) / 2;
  if ( document.getElementById("bottomSoeg") ) {document.getElementById("bottomSoeg").style.left  = xSoeg + "px";}
  var ySoeg = y - 191;
  if ( document.getElementById("bottomRSS") ) {document.getElementById("bottomRSS").style.top  = ySoeg + "px";}
  var xSoeg = (x - 752) / 2;
  if ( document.getElementById("bottomRSS") ) {document.getElementById("bottomRSS").style.left  = xSoeg + "px";}
  var ySoeg = y - 226;
  if ( document.getElementById("bottomMail") ) {document.getElementById("bottomMail").style.top  = ySoeg + "px";}
  var xSoeg = (x - 752) / 2;
  if ( document.getElementById("bottomMail") ) {document.getElementById("bottomMail").style.left  = xSoeg + "px";}
  var yBottom = y - 20;
  if ( document.getElementById("bottomMenuBG") ) {document.getElementById("bottomMenuBG").style.top  = yBottom + "px";}

  if ( document.getElementById("dialogOverlay") ) {document.getElementById("dialogOverlay").style.height  = y + "px";}
  if ( document.getElementById("dialogOverlay") ) {document.getElementById("dialogOverlay").style.width  = x + "px";}

  y = y - 90;
  if ( document.getElementById("pagediv") ) {document.getElementById("pagediv").style.height  = y + "px";}
}

function showBottom(what) {
  if ( document.getElementById(what) ) {
    if ( activeButton ) {resetButton(activeButton);}
    link = document.getElementById(what);
    if ( link.isExpanded == true ) {
      link.style.visibility = "hidden";
      link.isExpanded = false ;
    } else {
      if ( document.getElementById("bottomRSS") ) { document.getElementById("bottomRSS").style.visibility = "hidden"; }
      if ( document.getElementById("bottomRSS") ) { document.getElementById("bottomRSS").isExpanded = false ; }
      if ( document.getElementById("bottomSoeg") ) { document.getElementById("bottomSoeg").style.visibility = "hidden"; }
      if ( document.getElementById("bottomSoeg") ) { document.getElementById("bottomSoeg").isExpanded = false ; }
      if ( document.getElementById("bottomMail") ) { document.getElementById("bottomMail").style.visibility = "hidden"; }
      if ( document.getElementById("bottomMail") ) { document.getElementById("bottomMail").isExpanded = false ; }
      link.style.visibility = "visible";
      link.isExpanded = true ;
    }
  } else {
      if ( document.getElementById("bottomRSS") ) { document.getElementById("bottomRSS").style.visibility = "hidden"; }
      if ( document.getElementById("bottomRSS") ) { document.getElementById("bottomRSS").isExpanded = false ; }
      if ( document.getElementById("bottomSoeg") ) { document.getElementById("bottomSoeg").style.visibility = "hidden"; }
      if ( document.getElementById("bottomSoeg") ) { document.getElementById("bottomSoeg").isExpanded = false ; }
      if ( document.getElementById("bottomMail") ) { document.getElementById("bottomMail").style.visibility = "hidden"; }
      if ( document.getElementById("bottomMail") ) { document.getElementById("bottomMail").isExpanded = false ; }
  }
}

function showReply(id) {
  var textname = "replyText"+id;
  link = document.getElementById(textname);

  if ( link.isExpanded == true ) {
    link.style.position ="relative";
    link.style.visibility = "hidden";
    link.style.overflow ="hidden";
    link.style.height ="0px";
    link.isExpanded = false ;
  } else {
    link.style.position ="relative";
    link.style.visibility = "visible";
    link.style.overflow ="visible";
    link.style.height ="auto";
    link.isExpanded = true ;
  }
}

function functionBoxShow(what) {
  if ( document.getElementById(what) ) {
    if ( document.getElementById("functionBox_sektioner") ) { document.getElementById("functionBox_sektioner").style.visibility = "hidden"; }
    if ( document.getElementById("functionBox_login") ) { document.getElementById("functionBox_login").style.visibility = "hidden"; }
    if ( document.getElementById("functionBox_soeg") ) { document.getElementById("functionBox_soeg").style.visibility = "hidden"; }
    if ( document.getElementById("functionBox_postliste") ) { document.getElementById("functionBox_postliste").style.visibility = "hidden"; }
    if ( document.getElementById("functionBox_rss") ) { document.getElementById("functionBox_rss").style.visibility = "hidden"; }

    if ( document.getElementById("selectHide1") ) {
      link1 = document.getElementById("selectHide1");
      link1.isVisible = false ;
      link1.style.visibility = "hidden";
      if ( what == "functionBox_soeg" ) {
        link1.isVisible = true;
        link1.style.visibility = "visible";
      }
    }
    if ( document.getElementById("selectHide2") ) {
      link2 = document.getElementById("selectHide2");
      link2.isVisible = false ;
      link2.style.visibility = "hidden";
      if ( what == "functionBox_rss" ) {
        link2.isVisible = true;
        link2.style.visibility = "visible";
      }
    }

    document.getElementById(what).style.visibility = "visible";
  }
}

function dialogClose(){
    if ( document.getElementById("dialogOverlay") ) { document.getElementById("dialogOverlay").style.visibility = "hidden"; }
    if ( document.getElementById("dialogBox") ) { document.getElementById("dialogBox").style.visibility = "hidden"; }
    hideSelects("visible");
}

if ( document.getElementById("functionBox_soeg") ) {
  functionBoxShow("functionBox_soeg");
}
