/*
This is a cross-browser layer library. There are some important
restrictions. Layers should not be nested into other layers.
Putting layers into a table is also not recommended.
Library programmed by Sabah Karaali (Last modified: 06-09-2002)
Following functions are included:
Browser-Function:
 checkBrowser()    Determines browser in use
Layer-Functions:
 getlayer(divname)    Returns object of layer
 getlayerstyle(divname)     " style of layer
 getlayertop(divname)     " top position of layer
 getlayerleft(divname)     " left position of layer
 getlayerheight(divname)     " height of layer
 getlayerwidth(divname)     " width of layer
 setlayertop (divname,pos) Sets  Y position of layer
 setlayerleft (divname,pos)    "  X position of layer
 setpos (divname,posx,posy)    " X & Y position of layer
 setvisible (divname)  Sets Layer visible
 setinvisible (divname)  Sets Layer invisible
Other-Functions:
 getwindowheight ()   Returns height of browser window
 getwindowwidth ()      " width of browser window
*/
////////// BROWSER-FUNCTION: ///////////
  function checkBrowser(){
    this.ver=navigator.appVersion
    this.dom=document.getElementById?1:0
    this.mac=(this.ver.indexOf("Mac")>-1)?1:0;
    this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0;
    this.ie4=(document.all && !this.dom)?1:0;
    this.ns5=(this.dom && parseInt(this.ver) >= 5) ?1:0;
    this.ns4=(document.layers && !this.dom)?1:0;
    this.ie4mac=this.ie4 && navigator.userAgent.indexOf("Mac")>-1
    this.ns4mac=this.ns4 && navigator.appVersion.indexOf("Mac")>-1
    this.ie5mac=this.ie5 && navigator.userAgent.indexOf("Mac")>-1
    this.ie55=(this.ver.indexOf("MSIE 5.5")>-1 && this.dom)?1:0;
    this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom)?1:0;
    this.ns = ( this.ns4 || this.ns5 );
    this.ie = ( this.ie6 || this.ie5 || this.ie4 );
    this.bw=( this.dom ||  this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns5 || this.ie5mac)
    return this;
  }
  bw = new checkBrowser();
  function layerlib_error(s){
  	//uncomment for debugging...
    //alert(s);
  }
////////// LAYER-FUNCTIONS: ///////////
  // Returns object of layer
  function getlayer(divname) {
    if(bw.dom) return document.getElementById(divname);
    if(bw.ie4) return document.all[divname];
    if(bw.ns4) return window.document[divname];
    return null;
  }
  // Returns style of layer
  function getlayerstyle(divname) {
    var tmpObj = getlayer(divname);
    if (tmpObj) {
      if(bw.dom || bw.ie4) {
        return tmpObj.style;
      }
      if(bw.ns4) {
        return tmpObj;
      }
    }
    return null;
  }
  // Returns top position of layer
  function getlayertop(divname) {
    if(bw.dom) {
      var tmpObj = getlayerstyle(divname);
      if(tmpObj) {
        if(bw.ns5) {
          return parseInt(tmpObj.top);
        } else {
          return tmpObj.posTop;
        }
      }
    }
    if(bw.ie4) {
      var tmpObj = getlayer(divname);
      if(tmpObj) {
        return tmpObj.posTop;
      }
    }
    if(bw.ns4) {
      var tmpObj = getlayer(divname);
      if(tmpObj) {
        return tmpObj.top;
      }
    }
    return null;
  }
  // Returns left position of layer
  function getlayerleft(divname) {
    if(bw.dom) {
      var tmpObj = getlayerstyle(divname);
      if(tmpObj) {
        if(bw.ns5) {
          return parseInt(tmpObj.left);
        } else {
          return tmpObj.posLeft;
        }
      }
    }
    if(bw.ie4) {
      var tmpObj = getlayer(divname);
      if(tmpObj) {
        return tmpObj.posLeft;
      }
    }
    if(bw.ns4) {
      var tmpObj = getlayer(divname);
      if(tmpObj) {
        return tmpObj.left;
      }
    }
    return null;
  }
  // Returns height of layer
  function getlayerheight(divname) {
    if(bw.dom || bw.ie4) {
      var tmpObj = getlayer(divname);
      if(tmpObj) {
        return tmpObj.offsetHeight;
      }
    }
    if(bw.ns4) {
    var tmpObj = getlayer(divname)
      if(tmpObj) {
        return tmpObj.document.height;
      }
    }
    return 0;
  }
  // Returns width of layer
  function getlayerwidth(divname) {
    if(bw.dom || bw.ie4) {
      if(getlayer(divname)) {
      var tmpObj = getlayer(divname);
      return tmpObj.offsetWidth;
      }
    }
    if(bw.ns4) {
      var tmpObj = getlayer(divname);
      if(tmpObj) {
        return tmpObj.document.width;
      }
    }
    return 0;
  }
  // Sets Y position of layer
  function setlayertop (divname,pos) {
    var obj = getlayer(divname);
    if (obj){
      if(bw.dom && bw.ns5) obj.style.top = pos;
      if(bw.dom && !bw.ns5) obj.style.posTop = pos;
      if(bw.ie4) obj.posTop=pos;
      if(bw.ns4) obj.pageY=pos;
    } else {
      layerlib_error("setlayertop: Cannot find '"+divname+"'. obj"+obj+".");
    }
  }
  // Sets X position of layer
  function setlayerleft (divname,pos) {
    var obj = getlayer(divname);
    if (obj) {
      if(bw.dom && bw.ns5) obj.style.left = pos;
      if(bw.dom && !bw.ns5) obj.style.posLeft = pos;
      if(bw.ie4) obj.posLeft=pos;
      if(bw.ns4) obj.pageX=pos;
    } else {
      layerlib_error("setlayerleft: Cannot find '"+divname+"'. obj"+obj+".");
    }
  }
  // Sets X,Y position of layer
  function setpos (divname, posx,posy) {
    setlayerleft (divname,posx);
    setlayertop (divname,posy);
  }
  // Sets Layer visible
  function setvisible (divname) {
    var tmpObj = getlayerstyle(divname);
    if(tmpObj) {
      tmpObj.visibility="visible";
      //alert("setvisible  '"+divname+"'.visibility="+tmpObj.visibility)
    } else {
      //alert("setvisible Cannot find '"+divname+"'.")
      layerlib_error("setvisible: Cannot find '"+divname+"'.");
    }
  }
  // Sets Layer invisible
  function setinvisible (divname) {
    var tmpObj = getlayerstyle(divname);
    if(tmpObj) {
      tmpObj.visibility="hidden";
    } else {
      //alert("setinvisible Cannot find '"+divname+"'.")
      layerlib_error("setinvisible: Cannot find '"+divname+"'.");
    }
  }
////////// OTHER-FUNCTIONS: ///////////
//Returns height of browser window
  function getwindowheight () {
    if(bw.dom) {
      windowheight= document.body.offsetHeight;
      if( bw.ns5) windowheight= window.innerHeight;
    }
    if(bw.ie4) windowheight= document.body.offsetHeight;
    if(bw.ns4) windowheight= window.innerHeight;
    return windowheight;
  }
  //Returns width of browser window
  function getwindowwidth () {
    if(bw.dom) {
      windowwidth= document.body.offsetWidth;
      if( bw.ns5) windowwidth= window.innerWidth;
    }
    if(bw.ie4) windowwidth= document.body.offsetWidth;
    if(bw.ns4) windowwidth= window.innerWidth;
    return windowwidth;
  }
  // not tested!!
  function setTextOfLayer(divname,newText) {
    var obj = getlayer(divname);
    if (obj) {
      if (bw.ns) {
        //alert("ns "+divname);
        //obj.document.open();
        obj.document.write(newText);
        obj.document.close();
      } else {
        //alert("ie")
        obj.innerHTML = newText;
      }
    } else {
      //alert("setvisible Cannot find '"+divname+"'.")
      layerlib_error("setTextOfLayer: Cannot find '"+divname+"'.");
    }
  }  
