var head = new Array();
var menu = new Array();

for(i=1; i<=20; i++) {
	head[i] = 0;
	menu[i] = 0; 
}

var pageLeft
var pageTop

var layerRef
var layerPostfix
var styleSwitch
var bgColor

var imagePreloaderCount
var imagePreloaderArray

var wincounter = 0;
window.focus();

function PopUp(url,winname,w,h) {
	var winparams = "top=50,left=50,width="+w+",height="+h+",copyhistory=no,directories=no,topmargin=0,leftmargin=0,rightmargin=0,menubar=no,location=no,resizable=yes, scrollbars=yes";
	wnd = window.open(url, winname, winparams); 
	wnd.focus();
	return false;
}

function isNetscape6(){
  if(document.getElementById)return true
  return false
}

function isNetscape(){
  if(document.layers)return true
  return false
}

function isIE(){
  if(document.all)return true
  return false
}

function isMSIE(){
  return isIE()
}

function isExplorer(){
  return isIE()
}

function getScrollX(){
 if(isNetscape()||isNetscape6()){
  return window.pageXOffset
 }
 if(isExplorer()){
  return document.body.scrollLeft
 }
}

function getScrollY(){
 if(isNetscape()||isNetscape6()){
  return window.pageYOffset
 }
 if(isExplorer()){
  return document.body.scrollTop
 }
}

function getDocumentWidth(){
 if(isExplorer()){
  return document.body.clientWidth
 }
 if(isNetscape()){
  return window.innerWidth-16
 }
 if(isNetscape6()){
  return window.outerWidth-34
 }
}

function getDocumentHeight(){
  return document.height
}

function getWindowWidth(){
 if(isNetscape()){
  return window.innerWidth
 }
 if(isNetscape6()){
  return window.outerWidth
 }
 if(isExplorer()){
  return document.body.clientWidth
 }
}

function getWindowHeight(){
 if(isNetscape()){
  return window.innerHeight
 }
 if(isNetscape6()){
  return window.outerHeight
 }
 if(isExplorer()){
  return document.body.clientHeight
 }
}

function findLayer(where, what){ // only for Netscape 4.*
    var i,l
    for(i=0;i<eval(where+".length");i++){
      l=findLayer(where+"["+i+"].document.layers",what)
      if(l!="")return l
    }
    return ""
}

function getLayer(layerName){
  if(isExplorer()){
    if(eval("document.all[\""+layerName+"\"]"))return "document.all[\""+layerName+"\"]"
    return ""
  }
  if(isNetscape6()){
    if(document.getElementById(layerName))return "document.getElementById('"+layerName+"')"
    return ""
  }
  if(isNetscape()){
    if(document.layers[layerName])return "document.layers[\""+layerName+"\"]"
    return findLayer("document.layers",layerName)
  }
}

function setLayerProperty(layerName,property,value){
  if(isLayerExist(layerName)){
    eval(getLayer(layerName)+styleSwitch+"."+property+"=\""+value+"\"")
  }
}

function getLayerProperty(layerName,property){
  if(isLayerExist(layerName)){
    return eval(getLayer(layerName)+styleSwitch+"."+property)
  }
}

function isLayerExist(layerName){
  return getLayer(layerName)!=""
}

function isLayerExists(layerName){
  return isLayerExist(layerName)
}

function getLayerWidth(layerName){
  if(isLayerExist(layerName)){
   if(isNetscape()){
    return eval(getLayer(layerName)+".document.width")
   }
   if(isNetscape6()){
    return eval(getLayer(layerName)+".offsetWidth")
   }
   if(isExplorer()){
    return parseInt(eval(getLayer(layerName)+".scrollWidth"))
   }
  }
}

function getLayerHeight(layerName){
  if(isLayerExist(layerName)){
   if(isNetscape()){
    return eval(getLayer(layerName)+".document.height")
   }
   if(isNetscape6()){
    return eval(getLayer(layerName)+".offsetHeight")
   }
   if(isExplorer()){
    return parseInt(eval(getLayer(layerName)+".scrollHeight"))
   }
  }
}

function getLayerLeft(layerName){
  if(isLayerExist(layerName)){
   if(isNetscape6()){
    return document.getElementById(layerName).offsetLeft-pageLeft
   }else{
    return parseInt(getLayerProperty(layerName,"left"))-pageLeft
   }
  }
  return 0
}

function getLayerTop(layerName){
  if(isLayerExist(layerName)){
   if(isNetscape6()){
    return document.getElementById(layerName).offsetTop-pageTop
   }else{
    return parseInt(getLayerProperty(layerName,"top"))-pageTop
   }
  }
  return 0
}

function getLayerZindex(layerName){
  if(isLayerExist(layerName)){
    return parseInt(getLayerProperty(layerName,".z-index"))
  }
  return 0
}

function getLayerZ(layerName){
  return getLayerZindex(layerName)
}

function isLayerVisible(layerName){
  if(isLayerExist(layerName)){
    if(getLayerProperty(layerName,"visibility").charAt(0)=="h"){
      return false
    }else{
      return true
    }
  }
}

function moveLayer(layerName,newx,newy){
  if(isLayerExist(layerName)){
    setLayerProperty(layerName,"left",newx+pageLeft)
    setLayerProperty(layerName,"top",newy+pageTop)
  }
}
function moveLayerX(layerName,newx){
  if(isLayerExist(layerName)){
    setLayerProperty(layerName,"left",newx+pageLeft)
  }
}
function moveLayerY(layerName,newy){
  if(isLayerExist(layerName)){
    setLayerProperty(layerName,"top",newy+pageTop)
  }
}
function moveLayerZ(layerName,newz){
  if(isLayerExist(layerName)){
    setLayerProperty(layerName,"zIndex",newz)
  }
}

function showLayer(layerName){
  if(isLayerExist(layerName)){
    setLayerProperty(layerName,"visibility","visible")
  }
}
function hideLayer(layerName){
  if(isLayerExist(layerName)){
    setLayerProperty(layerName,"visibility","hidden")
  }
}

function clipLayer(layerName, top, right, bottom, left){
  if(isExplorer()||isNetscape6()){
    setLayerProperty(layerName,"clip","rect("+top+"px "+right+"px "+bottom+"px "+left+"px)")
  }

  if(isNetscape()){
    setLayerProperty(layerName,"clip.top",top)
    setLayerProperty(layerName,"clip.right",right)
    setLayerProperty(layerName,"clip.bottom",bottom)
    setLayerProperty(layerName,"clip.left",left)
  }
}

function scrollLayer(layerName,windowLeft,windowTop,windowWidth,windowHeight,scrollX,scrollY){

  if(!isLayerExist(layerName))return
  if(scrollX<0)scrollX=0
  if(scrollY<0)scrollY=0
  if(scrollX>getLayerWidth(layerName)-windowWidth)scrollY=getLayerWidth(layerName)-windowWidth
  if(scrollY>getLayerHeight(layerName)-windowHeight)scrollY=getLayerHeight(layerName)-windowHeight

  var top=0
  var right=windowWidth
  var bottom=windowHeight
  var left=0

  left=left+scrollX
  right=right+scrollX

  top=top+scrollY
  bottom=bottom+scrollY

  moveLayer(layerName, windowLeft-scrollX, windowTop-scrollY)
  clipLayer(layerName, top, right, bottom, left)
}

function scrollLayerOffset(layerName,windowLeft,windowTop,windowWidth,windowHeight,scrollX,scrollY){
  scrollX=getLayerLeft(layerName)-windowLeft+scrollX
  scrollY=getLayerTop(layerName)-windowTop+scrollY
  scrollLayer(layerName,windowLeft,windowTop,windowWidth,windowHeight,scrollX,scrollY)
}

function scrollLayerPercentage(layerName,windowLeft,windowTop,windowWidth,windowHeight,scrollX,scrollY){
  scrollX=(getLayerWidth(layerName)-windowWidth)*scrollX/100
  scrollY=(getLayerHeight(layerName)-windowHeight)*scrollY/100
  scrollLayer(layerName,windowLeft,windowTop,windowWidth,windowHeight,scrollX,scrollY)
}

function writeToLayer(layerName, str){
  if(isLayerExist(layerName)){
    if(isNetscape()){
      var area=document.layers[layerName].document
      area.open()
      area.write(str)
      area.close()
    }
    if(isNetscape6()){
      document.getElementById(layerName).firstChild.nodeValue=str
    }
    if(isExplorer()){
      document.all[layerName].innerHTML=str
    }
  }
}

function addToLayer(layerName, str){
  if(isLayerExist(layerName)){
    if(isNetscape()){
      var area=document.layers[layerName].document
      area.write(str)
    }
    if(isNetscape6()){
      document.getElementById(layerName).firstChild.nodeValue+=str
    }
    if(isExplorer()){
      document.all[layerName].innerHTML+=str
    }
  }
}

function setImage(layerName,imageName,imageFile){
 if(isNetscape6()){
  document.getElementById(imageName).src=imageFile
 }else{
  if(isLayerExist(layerName)){
   eval(getLayer(layerName)+'.document.images["'+imageName+'"].src="'+imageFile+'"')
  }
 }
}

function isImageExist(layerName,imageName){
 if(isNetscape6()){
  return (document.getElementById(imageName))?true:false
 }else{
  if(isLayerExist(layerName)){
   return (eval(getLayer(layerName)+'.document.images["'+imageName+'"]'))?true:false
  }
 }
}

function getImage(layerName,imageName){
 if(isNetscape6()){
  return document.getElementById(imageName).src
 }else{
  if(isLayerExist(layerName)){
   return eval(getLayer(layerName)+'.document.images["'+imageName+'"].src')
  }
 }
}

function setBgColor(layerName,color){
 if(isLayerExist(layerName)){
  setLayerProperty(layerName,bgColor,color)
 }
}

function preloadImage(imageFile){
  imagePreloaderArray[imagePreloaderCount]=new Image()
  imagePreloaderArray[imagePreloaderCount++].src=imageFile
}

function initKLayers(){
  pageLeft=0
  pageTop=0
  imagePreloaderCount=0
  imagePreloaderArray=new Array()

  if(isNetscape()){
    layerRef="document.layers["
    layerPostfix="]"
    styleSwitch=""
    bgColor="bgColor"
  }
  
  if(isExplorer()){
    layerRef="document.all["
    layerPostfix="]"
    styleSwitch=".style"
    bgColor="backgroundColor"
  }

  if(isNetscape6()){
    layerRef="document.getElementById("
    layerPostfix=")"
    styleSwitch=".style"
    bgColor="bgColor"
  }
}

function initLayers(){
  initKLayers()
}

initKLayers()
