// common.js - Generic library.
// Author: Alex Aalto
// Date: 2005/05/16
// Requirements: Written to work with client side Javascript 1.3 or better.

var submitClicked = false;
function oneClickSubmit() {
  if(!submitClicked) {
    submitClicked = true;
    setStyleOnId('submitBack','submitBackGrey');
    setStyleOnId('submitNext','submitNextGrey');
    setStyleOnId('submitLogin','submitLoginGrey');
    return true;
  } else {
    //alert("You can't do that!");
    return false;
  }
}

function showhide(id,display) {
  document.getElementById(id).style.display=display;
}

function showhideObj(obj,display) {
  obj.style.display=display;
}

function setStyleOnId(id,style) {
  if(document.getElementById(id)) {
    document.getElementById(id).className=style;
  }
}

function ToggleDisplayState(obj,legendObj,objstate) {
  if(objstate=="block") {
    objstate="none";
    legendObj.className="closed";
  } else {
    objstate="block";
    legendObj.className="opened";
  }
  showhideObj(obj,objstate);
  return objstate;
}

function setVisibility(obj, state) {
  obj.style.visibility = state;
}

function getObjOffsetLeft(el) {
  var ol=el.offsetLeft;
  while ((el=el.offsetParent) != null) { ol += el.offsetLeft; }
  return ol;
}
function getObjOffsetTop(el) {
  var ot=el.offsetTop;
  while((el=el.offsetParent) != null) { ot += el.offsetTop; }
  return ot;
}
function moveObject(obj,x,y) {
  obj.style.left = x+"px";
  obj.style.top = y+"px";
}
function getBrowserHeight() {
  var myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myHeight = document.body.clientHeight;
  }
  return myHeight;
}
function getBrowserWidth() {
  var myWidth = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
  }
  return myWidth;
}
function getBrowserScroll() {
  var scroll = document.body.scrollTop;
  if (scroll == 0) {
    if (window.pageYOffset) {
        scroll = window.pageYOffset;
    } else {
        scroll = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
    }
  }
  return scroll;
}
function findPosX(obj) {
  var curleft = 0;
  if (obj.offsetParent) {
    while (obj.offsetParent) {
      curleft += obj.offsetLeft
      obj = obj.offsetParent;
    }
  } else if (obj.x) {
    curleft += obj.x;
  }
  return curleft;
}
function findPosY(obj) {
  var curtop = 0;
  if (obj.offsetParent) {
    while (obj.offsetParent) {
      curtop += obj.offsetTop
      obj = obj.offsetParent;
    }
  } else if (obj.y) {
    curtop += obj.y;
  }
  return curtop;
}
function getIndexBySelectValue(select,value) {
  for(var i=0;i<select.options.length;i++) {
    if(select.options[i].text==value) { return i; }
  }
  return 0;
}
function gotoURL(url) {
  location = url;
}
