//========================================================================================
// ONRESIZE RELOAD FOR NS
//========================================================================================
function reload_NS()
{
	if (navigator.appName == "Netscape")
	{
		window.location.reload();
	}
}

//========================================================================================
// JAVASCRIPT FOR THE MENU
//========================================================================================
var menus = new Array()
var options = new Array()
var problemMenu = null
var problemForm = null

function getMenus(){return}
function buildSearch(){return}
function buildDescript(){return}
function buildTools(){return}
function buildExplanations() {return}
function getPositions(){return}

function swapOn(imgName) { 
	if (ie4 || ns5) hideOtherMenus("null")
	document [imgName].src= "/imgs/" + imgName + "-_on.gif"; 
}

function swapOff(imgName) { document [imgName].src= "/imgs/" + imgName + ".gif"; }

function init()
{
  //preloadImgs()
  if(is4) buildOptions()
}

function surfto(formname) { 
                        myindex=eval("document." + formname + ".elements[0].selectedIndex"); 
                        location=eval("document." + formname + ".elements[0].options[myindex].value"); 
} 

function clearForm(formname) {
	var elementCount = eval('document.' + formname + '.elements.length');
	var elementType;
	var i;
	for (i = 0; i < elementCount; i++) {
		elementType = (eval("document." + formname + ".elements[i].type"));
		if (elementType == "text" || elementType == "textarea") {
			eval('document.' + formname + '.elements[i].value = ""');
		}
	}
}

function itemOver(whichItem, type, name)
{

var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
if(isMac && isIE)
{}
else
{

	  if(is4 && (type != null))
	  {
	    if(type == 'menu' && menus[whichItem + 'Menu'] && menus[whichItem + 'Menu'].visShow) 
	    {
	     	mask.setVis(true)
	    	showMenu(whichItem + 'Menu')
	    }
	    else
	    {
	      if(window[whichItem + 'Obj']) thisObj = window[whichItem + 'Obj']
	      else return
	      if(type == 'home')
	      {
	        thisImg = ''
	        if (document.images[(whichItem + 'Img')]) thisImg = document.images[(whichItem + 'Img')]
	        thisImg.src="/imgs/" + whichItem + "_on.gif"
	        hMask.setVis(true)
	        thisObj.setVis(true)
	      }
	      if(type == 'home2')
	      {
	        thisImg = ''
	        if (document.images[(whichItem + 'Img')]) thisImg = document.images[(whichItem + 'Img')]
	        thisImg.src="/imgs/" + whichItem + "_on.gif"
	        thisObj.setVis(true)
	      }
	      if((type == 'object') && thisObj && thisObj.setVisibility)
	      {
	        thisObj.setVisibility(true)
	        if(whichItem == 'search')
	        {
	          mask.setVis(true)
	          thisObj.imgMask.setVis(true)
	          searchFormElm.focus()
	        }
	        else 
	        {
	          thisObj[whichItem + 'ImgMask'].setVis(true)
	        }
	      }
	    }
	  }
	  else 
	  {
	    if(whichItem == 'search') return
		if (ie4 || ns5) hideOtherMenus(whichItem)
	    thisImg = ''
	    if (document.images[(whichItem + 'Img')]) thisImg = document.images[(whichItem + 'Img')]
	    else return
	    thisImg.src="/imgs/" + whichItem + "_on.gif"
	  }
}
}



function itemOut(whichItem, type, event, name)
{

var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
if(isMac && isIE)
{}
else
{

	  if(is4 && (type == 'home')) 
	  {
	      if(window[whichItem + 'Obj']) thisObj = window[whichItem + 'Obj']
	      else return
	      hMask.setVis(false)
	      thisObj.setVis(false)
	  }
	  if(is4 && (type == 'home2')) 
	  {
	      if(window[whichItem + 'Obj']) thisObj = window[whichItem + 'Obj']
	      else return
	      thisObj.setVis(false)
	  }
	  if(is4 && (type == 'menu')) { 
	    //if (ie4 || ns5) menus[whichItem + 'Menu'].visHide()
		if (ie4 || ns5) {
			var m = menus[whichItem + 'Menu']
			var x = event.layerX;
			var y = event.layerY;
			//alert("menu: " + m.border.id + "\nx: " + x + "\ny: " + y);
		}
		return
	  }
	  thisImg = document.images[(whichItem + 'Img')]
	  thisImg.src="/imgs/" + whichItem + "Off.gif"
	  return;
		}
}



function goTo(url)
{
  window.location = url
}


function hideOtherMenus(whichMenu)
{
        // hide all other menus.
        for (n in menus) {
                if (n != whichMenu && (menus[n].isVisible())) menus[n].visHide()
        }
}

//===========================================================================================================

function resizeFix()  
{
  if(widthCheck != window.innerWidth || heightCheck != window.innerHeight)
  {
    window.location.reload(true)
  }
}

  var elm = ns4 ? document : document.all
function layerObj(id, arg_width, url)
{
  this.x = 0
  this.y = 0
  this.w = arg_width
  this.h = 0
  this.color = null
  this.html = ""
  this.label = ""
  this.arrow = ""
  this.zIndex = 1
  this.id = id
  if(url) this.url = url
//  this.css
//  this.elm
//  this.doc
  this.create = createLayer
  this.create()
  
  this.setPos = setPos
  this.setHtml = setHtml
  this.setSize = setSize
  this.setVis = setVis
  this.setColor = setColor
  this.setArrow = setArrow
  this.setZindex = setZindex
  this.isVisible = isVisible
}

function createLayer()
{
  var lyr
  if (ns4)
  {
    lyr = new Layer(this.w)
    this.css = lyr
    this.doc = lyr.document
    this.elm = lyr
    this.css.visibility = "inherit"
    this.doc.label = this.id
    this.doc.url = this.url
  }
  else if (ns5)
  {
	var node = document.createElement("div");
	node.setAttribute("id", this.id);
	node.style.position   = "absolute";
	node.style.visibility = "hidden";
	document.getElementsByTagName("body").item(0).appendChild(node);
	//lyr = document.getElementById(this.id);
    this.css = node.style
    this.doc = document
    this.elm = node
    this.elm.label = this.id
  }
  else
  {
    var code = "<div id=\""+ this.id + "\" style=\"position:absolute;top:0px;left:0px;width:0px;height:0px;visibility:hidden\"></div>"
    document.body.insertAdjacentHTML("beforeEnd", code)
	lyr = document.all[this.id]

    this.css = lyr.style
    this.doc = document
    this.elm = lyr
    this.elm.label = this.id
  }
}

function setHtml(html)
{
  if (!arguments[1]) this.html = html
  if (ns4)
  {
    if(html.match('img') && !html.match('href'))
    {
      tempHtml = html
      html = '\<a href=\"#\" onClick=\"return false\"\>' + tempHtml + '\<\/a\>'
    }
    this.doc.open()
    this.doc.write(html)
    this.doc.close()
  }
  else
  {
    this.elm.innerHTML = html
  }
}

function setSize(w,h)
{
  this.w = w
  this.h = h
  if (ns4)
  {
    this.css.clip.width = w
    this.css.clip.height = h
  }
  else
  {
    this.css.clip = "rect(0px " + w + "px " + h + "px 0px)"
    this.css.width = w
    this.css.height = h
  }
}

function isVisible()
{
	if (ns4)
	{
		return this.css.visibility == "inherit"
	}
	else
	{
		return this.css.visibility == "visible"
	}
}
function setVis(bool)
{
  if (ns4)
  {
    this.css.visibility = (bool) ? "inherit" : "hide"
  }
  else
  {
    this.css.visibility = (bool) ? "visible" : "hidden"
  }
}

function setColor(color)
{
  this.color = color
  if (ns4) { this.css.bgColor = color }
  else { this.css.backgroundColor = color }
}

function setZindex(zIndex)
{
  this.zIndex = zIndex
  this.css.zIndex = zIndex
}

function setPos(x,y)//position of the on-state image that spawns the menus
{
  this.x = x
  this.y = y

  if (ns4) { 
	this.elm.moveTo(x+1,y) 
  }
  else 
  {
	  if (ie4) {
	    this.css.pixelLeft = x 
	    this.css.pixelTop = y//show over item & menu this #of pixels from top of off item
	  }
	  else
	  {
		this.css.left = x + 1
		this.css.top  = y
	  }
  }
}

function setArrow()
{
this.arrow = ""
+"<img src=\"/imgs/menu_arrow.gif\" width=9 height=19 border=0 hspace=0 vspace=0 align=\"right\">"  
+ this.html
this.setHtml(this.arrow)
}

function getInfo(whichObject, name)
{
    if(ns4)
    {
      if(document[name].document)
      { 
        whichDiv = document[name]
      }
      else {return}
      whichObject.parentImage = whichDiv
      if(section == 'homePage') 
      {
        whichObject.x = whichDiv.pageX
        if(name == 'home' || name == 'home2') whichObject.y = whichDiv.pageY
        else whichObject.y = whichDiv.pageY + whichObject.img.height
      }
      else 
      {
        whichObject.x = whichDiv.pageX + whichObject.img.width - whichObject.w
        whichObject.y = whichDiv.pageY + whichObject.img.height
      }
      whichObject.parentImage.wVal = whichDiv.document.width
      whichObject.parentImage.hVal = whichDiv.document.height - 12
      whichObject.parentImage.xVal = whichDiv.pageX
      whichObject.parentImage.yVal = whichDiv.pageY
    }
    else
    {

      if(document.all[name])
      {
        whichDiv = document.all[name]
      }
	  else if (document.getElementById(name)) {
		whichDiv = document.getElementById(name)
	  }
      else {return}
      whichObject.parentImage = whichDiv
      if (section == 'homePage')
      {
        whichObject.x = whichDiv.offsetLeft
        if(name == 'home' || name == 'home2') whichObject.y = whichDiv.offsetTop
        else whichObject.y = whichDiv.offsetTop + whichObject.img.height
      }
      else 
      {
        whichObject.x = whichDiv.offsetLeft + whichObject.img.width - whichObject.w
        whichObject.y = whichDiv.offsetTop + whichObject.img.height
      }
      whichObject.parentImage.wVal = whichDiv.offsetWidth
      whichObject.parentImage.hVal = whichDiv.offsetHeight
      whichObject.parentImage.xVal = whichDiv.offsetLeft
      whichObject.parentImage.yVal = whichDiv.offsetTop
    }
}

function buildOptions()
{
  getMenus()
	getPositions()

    for(each in menus)
    {
      thisMenu = menus[each]
      thisMenu.build(thisMenu)
    }
  buildSearch()
  buildTools()
  if(section == 'homePage') buildExplanations()
  
  if(ns4) 
  {
    widthCheck = window.innerWidth
    heightCheck = window.innerHeight
    window.onresize = resizeFix
  }
  else
  {
    widthCheck = document.body.scrollWidth
	heightCheck = document.body.scrollHeight
  }
  buildMask()
}    

var openMenu = null
var openSubMenu = null

function buildMask()
{
  namer='mask'
  mask = new layerObj(namer, widthCheck*2)
  mask.setVis(false)
  mask.w = widthCheck
  mask.h = heightCheck
  mask.setSize(mask.w, mask.h)
  mask.setPos(0, 0)
  mask.setZindex(0)
  mask.elm.onmouseover =
    function()
    {      
        if(problemForm && openMenu)
        {
          for (x in problemForm)
          {
            if (problemMenu && ((openMenu.label == problemMenu[x])))
					elm[problemForm[x]].visibility = 'visible'
          }
        }
        if(openMenu) 
        {
          openMenu.visHide()    
        }
        else
        {
          for (each in menus) menus[each].visHide()
          
        }
        openMenu = null
        if(openSubMenu) openSubMenu.visHide()
        openSubMenu = null
       // if(searchObj) 
       // {
       //   searchObj.setVisibility(false)
       //   searchFormElm.blur()
       // }
        mask.setVis(false)
    }
}


//========================================================================================
var menuCounter=0

function makeMenu()
{  
  var itemArray = new Array()
  for(var i=0; i<arguments.length; i++)
  {
    itemArray[i] = new menuItem(arguments[i])
  }
  return new menu(itemArray)
}

function menuItem()
{
  var itemDesc = arguments[0]  
  this.label = itemDesc[0]
  this.url = null
  this.submenu = null
  if(itemDesc.length == 2)
  {
   if(typeof itemDesc[1] == 'string') 
   {
     this.url = itemDesc[1]
   }
   else
   {
     this.submenu = itemDesc[1]
   }
  }

  if(itemDesc.length == 3)
  {
    this.url = itemDesc[1]
    this.submenu = itemDesc[2]
  }
}

// ::::::::::::::::::::::::::::::: begin : EDITABLE SECTION ::::::::::::::::::::::::::::::: !!!
function menu(arg_items)
{
  this.parent = null
  this.menuItems = arg_items
  this.menuNum = menuCounter++
  this.topPos = 0
  this.leftPos = 0
  this.menuWidth = 150
  this.menuHeight = 20
  this.bgColor = '#ffcc33'
  this.overColor = '#ffe790'
  this.textClass = 'menuLink'
  this.borderWidth = 1
  this.borderColor = '#000000'
// ::::::::::::::::::::::::::::::: end : EDITABLE SECTION :::::::::::::::::::::::::::::::  !!!
  
  this.Imglyr = null
  this.visShow = 
    function() 
    { 
      if(this.Imglyr) this.Imglyr.setVis(true)
      for(x in this.menuItems)
      {
        if(this.menuItems[x].lyr)this.menuItems[x].lyr.setVis(true)
      }
      if(this.border) this.border.setVis(true)
    }
    
  this.visHide = 
    function() 
    { 
      if(this.Imglyr) this.Imglyr.setVis(false)
      for(x in this.menuItems)
      {
        if(this.menuItems[x].lyr)this.menuItems[x].lyr.setVis(false)
      }
      if(this.border) this.border.setVis(false)
    }
  this.build = buildMenus
  this.isVisible = 
	function()
	{
		return this.Imglyr.isVisible()
	}
    
  for (i in this.menuItems)
  {
    if (this.menuItems[i].submenu) 
    {
      this.menuItems[i].submenu.parentMenu = this
      this.menuItems[i].submenu.parentMenuItem = this.menuItems[i]
    }
  }
}

function getPositions()
{
  for(each in menus)
  {
    thisMenu = menus[each]
    thisMenu.label = each
    if(ns4)
    {
      thisMenu.parentImage = document[each]
      thisMenu.leftPos = document[each].pageX + thisMenu.menuWidth-35//fine
      thisMenu.topPos = document[each].pageY + thisMenu.menuHeight-19//perfect
    }
    if(ie4)
    {
      thisMenu.parentImage = document.getElementById(each)
      thisMenu.leftPos = document.getElementById(each).offsetLeft+115//perfect
      thisMenu.topPos = document.getElementById(each).offsetTop + thisMenu.menuHeight-19//fine
    }
	if(ns5)
	{
      thisMenu.parentImage = document.getElementById(each)
      thisMenu.leftPos = document.getElementById(each).offsetLeft+114//perfect
      thisMenu.topPos = document.getElementById(each).offsetTop + thisMenu.menuHeight-19//fine
	}
    for(i in menus[each].menuItems)
    {
      if(thisMenu.menuItems[i].submenu)
      {
        thisSubMenu = thisMenu.menuItems[i].submenu
        thisSubMenu.leftPos = thisMenu.leftPos + thisMenu.menuWidth+1
        thisSubMenu.topPos = thisMenu.topPos + (i * (thisMenu.menuHeight+1))
      }
    }
  }
}

function buildMenus(thisMenu)
{
    if(this.borderWidth && this.borderColor)
    {
        this.border = new layerObj('menu' + this.menuNum + 'border', this.menuWidth+(this.borderWidth*2))
        this.border.w = this.menuWidth+(this.borderWidth*2)
        this.border.h = ((this.menuHeight+1)*this.menuItems.length)+(this.borderWidth)
        this.border.setSize(this.border.w, this.border.h)
        this.border.setVis(false)
        this.border.setColor(this.borderColor)
        this.border.setPos(this.leftPos-this.borderWidth, (this.topPos - this.borderWidth))
        this.border.setZindex(2)
	}
  
  for(i in this.menuItems)
  {
    this.menuItem = this.menuItems[i]
    this.menuItem.ident = 'menu' + thisMenu.menuNum + 'item' + i
    itemId = this.menuItem.ident
    this.menuItem.menu = thisMenu
    this.menuItem.lyr = new layerObj(itemId, thisMenu.menuWidth, this.menuItem.url)
    this.menuItem.lyr.setSize(thisMenu.menuWidth, thisMenu.menuHeight)
    this.menuItem.lyr.setVis(false)
    this.menuItem.lyr.setColor(thisMenu.bgColor)
    if(!this.menuItem.url) this.menuItem.url = '#'
    this.menuItem.lyr.setHtml('<a href=\"' + this.menuItem.url + '\" class=\'' + thisMenu.textClass + '\' name=\"' + this.menuItem.ident + 'Link' + '\">' + this.menuItem.label + '</a>')
    this.menuItem.lyr.setPos(thisMenu.leftPos, (thisMenu.topPos + ((thisMenu.menuHeight+1)*i)))
    this.menuItem.lyr.elm.label = this.menuItem.ident
    this.menuItem.lyr.elm.menu = thisMenu
    this.menuItem.lyr.elm.menuItem = this.menuItem
    this.menuItem.lyr.setZindex(3)
    this.menuItem.lyr.css.paddingLeft=5
    this.menuItem.lyr.css.paddingTop=3

    if(this.menuItem.submenu) 
    {
      this.menuItem.lyr.setArrow()
      this.menuItem.submenu.build(this.menuItem.submenu)
      this.menuItem.lyr.elm.subMenu = this.menuItem.submenu
      this.menuItem.lyr.elm.onmouseover = function() 
      { 
        if(openSubMenu && (this.subMenu != openSubMenu)) 
        {
          openSubMenu.visHide()
          openSubMenu = null
        }
        this.subMenu.visShow()
        openSubMenu = this.subMenu
        this.menuItem.lyr.setColor(this.menu.overColor)
      }
    }
    else
    {
      this.menuItem.lyr.elm.onmouseover = 
      function()
      {
        this.menuItem.lyr.setColor(this.menu.overColor)
        if(openSubMenu && (this.menu != openSubMenu)) 
        {
          openSubMenu.visHide()
          openSubMenu = null
        }
      }

    }
    
	if (ns4 || ie4)
    this.menuItem.lyr.elm.onmouseout = 
		function()
    	{        
		  this.menuItem.lyr.setColor(this.menu.bgColor)
    	}
	else
    this.menuItem.lyr.elm.onmouseout = 
      function(event)
      {        
        this.menuItem.lyr.setColor(this.menu.bgColor)

		if (event.target == this) {
			var px = event.pageX;
			var py = event.pageY;
			var ml = this.menu.border.x + 2;
			var mr = ml + this.menu.border.w;
			var mt = this.menu.border.y;
			var mb = mt + this.menu.border.h;
			if(px < ml || px > mr) { this.menu.visHide(); return; }
			if(py < mt || py > mb) { this.menu.visHide(); return; }
		}
      }
	 
    if(ns4) this.menuItem.lyr.elm.captureEvents(Event.CLICK)
    this.menuItem.lyr.elm.onclick = 
      function()
      {
        if(this.menuItem.url) goTo(this.menuItem.url)
      }
    
  }
  
  if(!thisMenu.parentMenu) 
  {
    nameSplit = thisMenu.label.split("Menu")
    itemId= thisMenu.menuNum + 'menuImageMask'
    thisMenu.Imglyr = new layerObj(itemId, (document.images[nameSplit[0] + 'Img'].width+8), thisMenu.url)
    thisMenu.Imglyr.setSize((document.images[nameSplit[0] + 'Img'].width+10), (document.images[nameSplit[0] + 'Img'].height+0))
    thisMenu.Imglyr.setVis(false)
    if(ns4) thisMenu.Imglyr.setPos((thisMenu.parentImage.pageX), (thisMenu.parentImage.pageY))
    else thisMenu.Imglyr.setPos((thisMenu.parentImage.offsetLeft), (thisMenu.parentImage.offsetTop))
    imgName = nameSplit[0] + '_on.gif'
    if(this.url == null) this.url = '#'
// ::::::::::::::::::::::::::::::: begin : EDITED :::::::::::::::::::::::::::::::  !!!
		if (category =="home")
		{
    		thisMenu.Imglyr.setHtml('\<a href=\"' + this.url + '\" onMouseOver="return"><img src=\"images\/' + imgName + '\" border=0 name=\"' + thisMenu.label + 'OverGif\"\></a>')
		}
		else
		{
// LEM 10/17/03: Changed img src tag to get images from relative folder, not off of root.
			thisMenu.Imglyr.setHtml('\<a href=\"' + this.url + '\" onMouseOver="return"><img src=\"../images\/' + imgName + '\" border=0 name=\"' + thisMenu.label + 'OverGif\"\></a>')
		}
// ::::::::::::::::::::::::::::::: end : EDITED ::::::::::::::::::::::::::::::: !!!
    thisMenu.Imglyr.setZindex(1)
    thisMenu.Imglyr.elm.parentMenu = thisMenu
    thisMenu.Imglyr.elm.url = thisMenu.url
    if(ns4) thisMenu.Imglyr.elm.captureEvents(Event.CLICK)
    thisMenu.Imglyr.elm.onclick = 
      function()
      {
        goTo(this.url)
      }
    thisMenu.Imglyr.elm.onmouseover = 
    function()
    {
        if(openMenu != this.parentMenu)
        {
          for(each in menus)
          {
            menus[each].visHide()
          }
          openMenu = null
        }
        if(openMenu == null) openMenu = this.parentMenu
        if(mask.css.visibility == 'hidden' || mask.css.visibility == 'hide') mask.setVis(true)
        if(openSubMenu) openSubMenu.visHide()
    }

  }
}    

function showMenu(whichMenu)
{
  if(menus[whichMenu]) 
  {
    if(ns4) elm = document
	else if(ns5) elm = document.getElementById
    else elm = document.all

	if (ie4 || ns5) hideOtherMenus(whichMenu)

    if(problemForm != null)
    {
      for (x in problemForm)
      {
        if (problemMenu && ((whichMenu == problemMenu[x]))) elm[problemForm[x]].visibility = 'hidden'
      }
    }
    openMenu = menus[whichMenu]
    menus[whichMenu].visShow()
  }
}
