HM_DOM = (document.getElementById) ? true : false;
HM_NS4 = (document.layers) ? true : false;
HM_IE = (document.all) ? true : false;
HM_IE4 = HM_IE && !HM_DOM;
HM_Mac = (navigator.appVersion.indexOf("Mac") != -1);
HM_IE4M = HM_IE4 && HM_Mac;

//4.1

HM_Opera = (navigator.userAgent.indexOf("Opera")!=-1);
HM_Konqueror = (navigator.userAgent.indexOf("Konqueror")!=-1);

// Added following custom browser detect
// Duleepa Wijayawardhana, Dec 17 2001

var HMBio_Agent = navigator.userAgent.toLowerCase();
HMBio_NS6 = (!document.all && document.getElementById) ? true : false;
HMBio_IE5M = (HMBio_Agent.indexOf("msie 5.")!=-1) && HM_Mac;
HMBio_IE4D = (HMBio_Agent.indexOf("msie 4.")!=-1) && !HM_Mac && !HM_Opera;

// End Custom browser detect

HM_IsMenu = !HM_Opera && !HM_Konqueror && !HM_IE4M && (HM_DOM || HM_NS4 || HM_IE4);
// To add Konqueror support:
// HM_IsMenu = !HM_Opera && !HM_IE4M && (HM_DOM || HM_NS4 || HM_IE4 || HM_Konqueror);

HM_BrowserString = HM_NS4 ? "NS4" : HM_DOM ? "DOM" : "IE4";

//-----------------------------------------------------------------------------
// Layer utilities.
//-----------------------------------------------------------------------------

function getLayer(name) {
	  if (HM_NS4) 
	    return findLayer(name, document);
	  if (HMBio_NS6) 
		return document.getElementById(name); 
	  if (HM_IE)
	  	return eval('document.all.' + name); 
  return null;
}

function findLayer(name, doc) {

  var i, layer;

  for (i = 0; i < doc.layers.length; i++) {
    layer = doc.layers[i];
    if (layer.name == name)
      return layer;
    if (layer.document.layers.length > 0) {
      layer = findLayer(name, layer.document);
      if (layer != null)
        return layer;
    }
  }

  return null;
}

//-----------------------------------------------------------------------------
// Layer visibility.
//-----------------------------------------------------------------------------

function hideLayer(layer) {
	  if (HM_NS4) 
	    layer.visibility = "hide";
	  if (HM_IE || HMBio_NS6) 
	    layer.style.visibility = "hidden";
}

function showLayer(layer) {
	  if (HM_NS4) 
	    layer.visibility = "show";
	  if (HM_IE || HMBio_NS6) 
	  	layer.style.visibility = "visible";
}

//-----------------------------------------------------------------------------
// Layer positioning.
//-----------------------------------------------------------------------------

function moveLayerTo(layer, x, y) {
		if (HM_NS4) 
		    layer.moveTo(x, y);
		if (HM_IE || HMBio_NS6) { 
		    layer.style.left = x;
		    layer.style.top = y;
	   }
}

function moveToShow(name, x, y) { // NOTE - function uses getLayer() to retreive layer object
	moveLayerTo(getLayer(name), x, y);
	showLayer(getLayer(name));
	eval(name + "vis = 1"); // sets a visibility flag to 1
}

function moveToHide(name, x, y) { // NOTE - function uses getLayer() to retreive layer object
	moveLayerTo(getLayer(name), x, y);
	hideLayer(getLayer(name));
	eval(name + "vis = 0"); // sets a visibility flag to 0
}


function moveLayerBy(layer, dx, dy) {

  if (HM_NS4)
    layer.moveBy(dx, dy);
  if (HMBio_NS6) {
  	var xlocation = parseInt(layer.style.left);
		var ylocation = parseInt(layer.style.top);
		xlocation += dx;
		ylocation += dy;
	  layer.style.left = xlocation;
		layer.style.top = ylocation;
  }    
  if (HM_IE) {
    layer.style.pixelLeft += dx;
    layer.style.pixelTop  += dy;
  }
}

function getLeft(layer) {

  if (HM_NS4)
    return(layer.left);
  if (HMBio_NS6)
  	return(parseInt(layer.style.left));
  if (HM_IE)
    return(layer.style.pixelLeft);
  return(-1);
}

function getTop(layer) {

  if (HM_NS4)
    return(layer.top);
  if (HMBio_NS6)
  	return(parseInt(layer.style.top));
  if (HM_IE)
    return(layer.style.pixelTop);
  return(-1);
}

function setWidth(layer, w) {
	if (!HM_Opera && (HM_IE || HMBio_NS6)) {
		layer.style.width = w;
	}
}

function setHeight(layer, h) {
	if (!HM_Opera && (HM_IE || HMBio_NS6)) {
		layer.style.height = h;
	}
}
/******************************************************************************
* End Layer functions                                                         *
******************************************************************************/

//////////////////////////
// Element Positioning and Offsets
/////////////////////////

// Obtain X coordinate of imageName
function findX(imageName) {
	var objImg
	objImg = document.images[imageName]
	if (HM_NS4){		
		if (document.images[imageName]) { // Test for image in document object
			return eval(objImg).x
		} else { // Fix for Netscape 4 div bug - find image in document.layers object instead (will NOT work for nested divs)			
			for (a = 0; a < document.layers.length; a++) {
				if (document.layers[a].document.images[imageName]) {
					xtotal = document.layers[a].left + document.layers[a].document.images[imageName].x;
					return xtotal;
				}
			}
		}
	} else {
		return getXPosition(objImg);
	}
}

// Called by findX()
function getXPosition(imgElem) {
	xPos = eval(imgElem).offsetLeft;
	tempEl = eval(imgElem).offsetParent;
  	while (tempEl != null) {
  		xPos += tempEl.offsetLeft;
  		tempEl = tempEl.offsetParent;
  	}
	return xPos;
}		

// Obtain Y coordinate of imageName
function findY(imageName) {
	var objImg
	objImg = document.images[imageName]
	if (HM_NS4){		
		if (document.images[imageName]) { // Test for image in document object
			return eval(objImg).y
		} else { // Fix for Netscape 4 div bug - find image in document.layers object instead (will NOT work for nested divs)			
			for (a = 0; a < document.layers.length; a++) {
				if (document.layers[a].document.images[imageName]) {
					ytotal = document.layers[a].top + document.layers[a].document.images[imageName].y;
					return ytotal;
				}
			}			
		}
		
	} else {
		return getYPosition(objImg);
	}
}

// Called by findY()
function getYPosition(imgElem) {
	yPos = eval(imgElem).offsetTop;
	tempEl = eval(imgElem).offsetParent;
  	while (tempEl != null) {
  		yPos += tempEl.offsetTop;
  		tempEl = tempEl.offsetParent;
  	}
	return yPos;
}

//////////////////////////
// End Element Positioning and Offsets
/////////////////////////

// Functions needed to be updated to new detection and browser support:
function getWindowWidth() {
  if (HM_NS4 || HMBio_NS6 || HM_Opera)
	return(window.innerWidth);
  if (HM_IE)
	return(document.body.clientWidth);
  return(-1);
}

function getWindowHeight() {
  if (HM_NS4 || HMBio_NS6 || HM_Opera)
	return(window.innerHeight);
  if (HM_IE)
	return(document.body.clientHeight);
  return(-1);
}
