
var isDOM = (document.getElementById ? true : false);
var isIE4 = ((document.all && !isDOM) ? true : false);
var isNS4 = (document.layers ? true : false);

function getRef(id) {
  if (isDOM) return document.getElementById(id);
  if (isIE4) return document.all[id];
  if (isNS4) return document.layers[id];
}


function loadPage(id,nestref,url) {
    // change the 550 value to make the layer wider or smaller
    content_width = 550;
    if (isNS4) {
	var lyr = (nestref)? eval('document.'+nestref+'.document.'+id) : document.layers[id]
	    lyr.load(url,content_width)
    }
    else if(isIE4) parent.content.location = url;
    else if(isDOM) document.getElementById('contentFrame').src = url;
}

function showPage(id) {
    if (isIE4) {
	document.all[id].innerHTML = parent.contentFrame.document.body.innerHTML;
    }
    else if(isDOM) {
	document.getElementById(id).innerHTML = window.frames['contentFrame'].document.getElementById('theBody').innerHTML;
    }
}




function getSty(id) {
  return (isNS4 ? getRef(id) : getRef(id).style);
}

var menuArray = new Array();
for (var i = 0; i<10; i++) menuArray[i]=null;

var numOfMenus = 0;

function registerMenu(menuToAdd) {
   menuArray[numOfMenus] = menuToAdd;
   litNow[numOfMenus] = new Array();
   numOfMenus++;
}

// Hide timeout.
var popTimer = 0;

// Array showing highlighted menu items.
var litNow = new Array();

function popOver(i, menuNum, itemNum) {
  hideAllOtherMenus(i);
  var menu = menuArray[i];
  clearTimeout(popTimer);
  hideAllBut(i, menuNum);
  litNow[i] = getTree(i, menuNum, itemNum);
  changeCol(i, litNow[i], true);
  targetNum = menu[menuNum][itemNum].target;
  if (targetNum > 0) {
    thisX = parseInt(menu[menuNum][0].ref.left) + parseInt(menu[menuNum][itemNum].ref.left);
    thisY = parseInt(menu[menuNum][0].ref.top) + parseInt(menu[menuNum][itemNum].ref.top);
    testH = thisY+parseInt(menu[targetNum][0].ref.height);
    if (parseInt(navigator.appVersion)>3) {
	if (navigator.appName=="Netscape") {
	    winH = window.innerHeight;
	}
	if (navigator.appName.indexOf("Microsoft")!=-1) {
	    winH = document.body.offsetHeight;
	}
    }

    //if (testH>winH) {
	//thisY = thisY - parseInt(menu[targetNum][0].ref.height)+parseInt(menu[menuNum][itemNum].ref.height);
    //}
    with (menu[targetNum][0].ref) {
      left = parseInt(thisX + menu[targetNum][0].x);
      top = parseInt(thisY + menu[targetNum][0].y);
      visibility = 'visible';
    }
  }
}

function hideAllOtherMenus(i) {
  for (var x = 0; x<numOfMenus; x++) {
    if (x!=i) {
      var menu = menuArray[x];
      for (count = 1; count < menu.length; count++)
        menu[count][0].ref.visibility='hidden';
      changeCol(x,litNow[x],false);
    }
  }
}

function popOut(i, menuNum, itemNum) {
 
  var menu = menuArray[i];
  if ((menuNum == 0) && !menu[menuNum][itemNum].target) {
      hideAllBut(i,0);
       showDropDowns();
  }
  else
      popTimer = setTimeout('hideAll();showDropDowns()', 500);
}


function getTree(i, menuNum, itemNum) {
  // Array index is the menu number. The contents are null (if that menu is not a parent)
  // or the item number in that menu that is an ancestor (to light it up).
  var menu = menuArray[i];
  itemArray = new Array(menu.length);
  while(1) {
      itemArray[menuNum] = itemNum;
      // If we've reached the top of the hierarchy, return.
      if (menuNum == 0) return itemArray;
      itemNum = menu[menuNum][0].parentItem;
      menuNum = menu[menuNum][0].parentMenu;
  }
}


// Pass an array and a boolean to specify colour change, true = over colour.
function changeCol(i, changeArray, isOver) {
  var menu = menuArray[i];
  for (menuCount = 0; menuCount < changeArray.length; menuCount++) {
    if (changeArray[menuCount]) {
      newCol = isOver ? menu[menuCount][0].overCol : menu[menuCount][0].backCol;
      // Change the colours of the div/layer background.
      with (menu[menuCount][changeArray[menuCount]].ref) {
      if (isNS4) bgColor = newCol;
        else backgroundColor = newCol;
      }
	}
  }
}


function hideAllBut(i, menuNum) {
  var menu = menuArray[i];
  var keepMenus = getTree(i, menuNum, 1);
  for (count = 0; count < menu.length; count++)
    if (!keepMenus[count])
      menu[count][0].ref.visibility = 'hidden';
  changeCol(i, litNow[i], false);
}

function hideAll() {


  for (var i = 0; i< numOfMenus; i++) {
    var menu = menuArray[i];
    var keepMenus = getTree(i, 0, 1);
    for (count = 0; count < menu.length; count++)
      if (!keepMenus[count])
        menu[count][0].ref.visibility = 'hidden';
      changeCol(i, litNow[i], false);
  }

}

// *** MENU CONSTRUCTION FUNCTIONS ***

function Menu(isVert, popInd, x, y, width, overCol, backCol, borderClass, textClass) {
  // True or false - a vertical menu?
  this.isVert = isVert;
  // The popout indicator used (if any) for this menu.
  this.popInd = popInd
  // Position and size settings.
  this.x = x;
  this.y = y;
  this.width = width;
  // Colours of menu and items.
  this.overCol = overCol;
  this.backCol = backCol;
  // The stylesheet class used for item borders and the text within items.
  this.borderClass = borderClass;
  this.textClass = textClass;
  // Parent menu and item numbers, indexed later.
  this.parentMenu = null;
  this.parentItem = null;
  // Reference to the object's style properties (set later).
  this.ref = null;
}

function Item(text, href, frame, length, spacing, target,bgcolor) {
  this.text = text;
  this.href = href;
  this.frame = frame;
  this.length = length;
  this.spacing = spacing;
  this.target = target;

  if (bgcolor!='')
  {
	  this.bgcolor= "bgcolor='"+bgcolor+"'";
  }
  else
  {
		this.bgcolor = "";
  }
  // Reference to the object's style properties (set later).
  this.ref = null;
}

function writeMenus(i)
{
  
  var menu = menuArray[i];
  if (!isDOM && !isIE4 && !isNS4) return;
  
  for (currMenu = 0; currMenu < menu.length; currMenu++) with (menu[currMenu][0]) {
    // Variable for holding HTML for items and positions of next item.
      var str = '', itemX = 0, itemY = 0, menuHeight=0;

    // Remember, items start from 1 in the array (0 is menu object itself, above).
    // Also use properties of each item nested in the other with() for construction.
    for (currItem = 1; currItem < menu[currMenu].length; currItem++) with (menu[currMenu][currItem]) {
      var itemID = i+'menu' + currMenu + 'item' + currItem;
      

      // The width and height of the menu item - dependent on orientation!
      var w = (isVert ? width : length);
      var h = (isVert ? length : width);
      if (isVert) menuHeight+=h;
      if (isDOM || isIE4)
      	{
        str += '<div id="' + itemID + '" style="position: absolute; left: ' + itemX + '; top: ' + itemY + '; width: ' + w + '; height: ' + h + '; visibility: inherit;';
        if (backCol) str += 'background: ' + backCol + '; ';
        str += '" ';
	}
	
	if (isNS4)
	{

        str += '<layer id="' + itemID + '" left="' + itemX + '" top="' + itemY + '" width="' +  w + '" height="' + h + '" visibility="inherit" ';
        if (backCol) str += 'bgcolor="' + backCol + '" ';
	}
	//borderClass="test"
	if (borderClass) str += 'class="' + borderClass + '" ';

      // Add mouseover handlers and finish div/layer.


      if (href=='')
      {
         str += 'onMouseOver="popOver(' +i+',' + currMenu + ',' + currItem + ');hideDropDowns('+i+')" onMouseOut="popOut('+i+',' + currMenu + ',' + currItem + ')">';
      }
      else
      {
      	if (frame)
	      str += 'onClick="window.open(\''+href+'\',\'displayWindow\')" onMouseOver="popOver('+i+','+currMenu+','+currItem + ');hideDropDowns('+i+')" onMouseOut="popOut('+i+',' + currMenu + ',' + currItem + ')">';
	    else
	      str += 'onClick="location.href=\'' + href + '\'" onMouseOver="hideDropDowns('+i+');popOver(' +i+',' + currMenu + ',' + currItem + ')" onMouseOut="popOut('+i+',' + currMenu + ',' + currItem + ')">';
	    
      }

      str += '<table '+bgcolor+' width="' + (w) + '" border="0" cellspacing="0" cellpadding="' + (!isNS4 && borderClass ? 3 : 0) + '"><tr><td align="left" valign="middle" height="' + (h) + '"  width="' + (w-10) + '">';
   
      if (isDOM || !isNS4) str+='<span class="'+textClass+'">'+text+'</span>';
      else str+=text;
      
      if (target > 0) {

        // Set target's parents to this menu item.
        menu[target][0].parentMenu = currMenu;
        menu[target][0].parentItem = currItem;

        // Add a popout indicator.
        //if (popInd) str += '<td class="' + textClass + '" align="right" valign="middle"></td>' + popInd ;

		if (popInd !="") str += '&nbsp;' + popInd +'</td>';
      }
	  str+='</td>';
      str += '</tr></table>' + (isNS4 ? '</layer>' : '</div>');
      if (isVert){
	  itemY += length + spacing;
	  menuHeight+=spacing;
      }
      else itemX += length + spacing;

    }
    
    if (isDOM) {
      var newDiv = document.createElement('div');
      document.getElementsByTagName('body').item(0).appendChild(newDiv);
	  

      newDiv.innerHTML = str;
      ref = newDiv.style;
      ref.position = 'absolute';
      ref.visibility = 'hidden';
      if (isVert) ref.height = menuHeight;
    }

    // Insert a div tag to the end of the BODY with menu HTML in place for IE4.
    if (isIE4) {
	strHTML = '<div id=i+"menu' + currMenu + 'div" ' + 'style="position: absolute; visibility: hidden;';
	if (isVert) strHTML += ' height: '+menuHeight+';';
	strHTML+='>' + str + '</div>';
	document.body.insertAdjacentHTML('beforeEnd', strHTML);
	ref = getSty(i+'menu' + currMenu + 'div');
    }
	
	// In NS4, create a reference to a new layer and write the items to it.
    if (isNS4) {
      ref = new Layer(0);
      ref.document.write(str);
      ref.document.close();
    }

   for (currItem = 1; currItem < menu[currMenu].length; currItem++) {
      itemName = i+'menu' + currMenu + 'item' + currItem;
      if (isDOM || isIE4) menu[currMenu][currItem].ref = getSty(itemName);
      if (isNS4) {
	  menu[currMenu][currItem].ref = ref.document.layers[currItem-1];
      }
    }

  }
  with(menu[0][0]) {
    ref.left = x;
    ref.top = y;
    ref.visibility = 'visible';
  }
}


var popOldWidth = window.innerWidth;
nsResizeHandler = new Function('if (popOldWidth != window.innerWidth) location.reload()');

// This is a quick snippet that captures all clicks on the document and hides the menus
// every time you click. Use if you want.

if (isNS4) document.captureEvents(Event.CLICK);
document.onclick = clickHandle;

function clickHandle(evt)
{
 if (isNS4) document.routeEvent(evt);
 hideAll();
}

function buildMenus() {

 if (document.all("quicklinks"))
 {
	  document.all("quicklinks").style.visibility="hidden";
 } 




 for (var i = 0; i<numOfMenus; i++) {
      writeMenus(i);
  }

try
{
	 for (M = 0; M < BottomBit.length; M++)
		 {
		  document.all("EmptyBit").innerHTML = document.all("EmptyBit").innerHTML + BottomBit[M];
		 }
	document.all("EmptyBit").innerHTML = document.all("EmptyBit").innerHTML;
}
catch(err){}

}

function hideDropDowns(i) 
{
  
  if(i>0) 
    return;
    if (document.all)
     {
     if (document.all('SearchDrop1') != null)
	    document.all('SearchDrop1').style.visibility = "hidden";
     if (document.all('SearchDrop2') != null)
	    document.all('SearchDrop2').style.visibility = "hidden";
     if (document.all('FAQDropDown1') != null)
	    document.all('FAQDropDown1').style.visibility = "hidden";
	 if (document.all('ProductList') != null)
	    document.all('ProductList').style.visibility = "hidden";
     }
     else if(isNS4) {
	//if(document.ids.FAQDropDown1 != undefined){
	//	document.ids.FAQDropDown1.display = "none";
	//	document.layers['FAQDropDown1'].visibility = "hide";
	//}
     }
}

function showDropDowns() { 
  if(document.all) {
	if (document.all('SearchDrop1') != null)
		document.all('SearchDrop1').style.visibility = "visible";
	if (document.all('SearchDrop2')!= null)
		document.all('SearchDrop2').style.visibility = "visible";
	if (document.all('FAQDropDown1') != null)
		document.all('FAQDropDown1').style.visibility = "visible";
	if (document.all('ProductList') != null)
		document.all('ProductList').style.visibility = "visible";
  }
  
  else if(isNS4) {
	//if(document.ids.FAQDropDown1 != undefined){
	//	document.layers['FAQDropDown1'].visibility = "show";
	//}
  }
}

















                      

