var isNav4, isIE4, isMac
var insideWindowWidth
var range = ""
var styleObj = ""
var layerObjCache = new Array()
var layerNameCache = new Array()
var useTop = true;

if (navigator.appVersion.charAt(0) >= "4") {
	if (navigator.appName == "Netscape") {
		isNav4 = true
		insideWindowWidth = window.innerWidth
	} else {
		isIE4 = true
		range = "all."
		styleObj = ".style"
	}
}

isMac = (navigator.userAgent.indexOf("mac")!=-1)  || (navigator.userAgent.indexOf("Mac")!=-1);

//!! AAL getObject return a reference to the style, this returns the base object
function getObjectRef(objName)
{
  var obj;

  if (isNav4)
  {
    obj = findObjectNav(objName);
    return obj;
  } 
  
  if (isIE4)
  {
    obj = eval("document.all."+objName)
    return obj;
  }

  return null
}

//!! AAl Added
function getObjectHeight(objName)
{
  obj = getObjectRef(objName);
  if (isNav4)
    return obj.clip.height;
  
  if (isIE4)
    return obj.scrollHeight;

  return null
}

//!! AAL Added
function getObjectWidth(objName)
{
  obj = getObjectRef(objName);

  if (isNav4)
    return obj.clip.width;
 
  if (isIE4)
    return obj.scrollWidth;

  return null
}

//AAL Added, *UNTESTED*
function getPageX(objName)
{
  var offset
  if (isNav4)
  {
    obj = findObjectNav(objName)
    return obj.pageX
  } 
  
  if (isIE4)
  {
    obj = eval("document.all."+objName)
    offset = 0
    while (obj != null)
    {
//      showProps(obj,obj.id)
      offset += obj.offsetLeft
      obj = obj.offsetParent;
    }
    return offset
  }

  return null
}

function getPageY(objName)
{
  var offset
  if (isNav4)
  {
    obj = findObjectNav(objName)
    return obj.pageY
  } 
  
  if (isIE4)
  {
    obj = eval("document.all."+objName)
    offset = 0
    while (obj != null)
    {
//      showProps(obj,obj.id)
      offset += obj.offsetTop
      obj = obj.offsetParent;
    }
    return offset
  }

  return null
}

function findObjectIE(obj)
{
  return eval("document.all."+obj+".style")
}

function checkObjectCache(layerName)
{
  var i
  for (i=0; i<layerNameCache.length;i++)
  {
    if (layerNameCache[i] == layerName)
     return layerObjCache[i]
  }
  return null
}

function addObjectCache(layerName,obj)
{
  var idx
  idx = layerNameCache.length;
  layerNameCache[idx] = layerName
  layerObjCache[idx] = obj
}

function findObjectPrim(theLayer,layerObj)
{
  var doc
  var i
  var aLayer
  if (theLayer == null)
     doc = document
  else
     doc = theLayer.document

  for (i=0; i<doc.layers.length;i++)
  {
     aLayer = doc.layers[i]
     if (aLayer.name == layerObj)
       return aLayer
     else
     {
       layerObjFind = findObjectPrim(aLayer,layerObj)
       if (layerObjFind != null)
         return layerObjFind
     }
         
  }
  return null
}

function findObjectNav(obj)
{
  var theObj

  //first check the object cache
  theObj = checkObjectCache(obj)
  if (theObj != null)
    return theObj

  theObj = findObjectPrim(null,obj)

  if (theObj != null)
    addObjectCache(obj,theObj)
  return theObj
}


function findObject(obj)
{
  if (isIE4)
    return findObjectIE(obj)
 
  if (isNav4)
   return findObjectNav(obj)
 
  return null;

}

function getWindowWidth(winobj)
{
  if (isIE4)
    return winobj.document.body.clientWidth
  
  if (isNav4)
    return winobj.innerWidth
}

function getLinkText(linkobj)
{
  if (isIE4)
    return linkobj.innerText
    
  if (isNav4)
    return linkobj.text
}

function getApplet(layerName,appletName) {
  if (isIE4)
   return document.applets[appletName]

  if (isNav4) {
   lay = getObject(layerName)
   return lay.document.applets[appletName]
  }

  return null
}

// Convert object name string or object reference
// into a valid object reference
function getObject(obj) {
	var theObj
	if (typeof obj == "string") {
		theObj = findObject(obj)
//		theObj = eval("document." + range + obj + styleObj)
	} else {
		theObj = obj
	}
	return theObj
}

// Positioning an object at a specific pixel coordinate
function shiftTo(obj, x, y) {
	var theObj = getObject(obj)
        if (isNav4) {
		theObj.moveTo(x,y)
	} else {
		theObj.pixelLeft = x
		theObj.pixelTop = y
	}
}

// Moving an object by x and/or y pixels
function shiftBy(obj, deltaX, deltaY) {
	var theObj = getObject(obj)
	if (isNav4) {
		theObj.moveBy(deltaX, deltaY)
	} else {
		theObj.pixelLeft += deltaX
		theObj.pixelTop += deltaY
	}
}

// Setting the z-order of an object
function setZIndex(obj, zOrder) {
	var theObj = getObject(obj)
	theObj.zIndex = zOrder
}

// Setting the background color of an object
function setBGColor(obj, color) {
	var theObj = getObject(obj)
	if (isNav4) {
		theObj.bgColor = color
	} else {
		theObj.backgroundColor = color
	}
}

// Setting the visibility of an object to visible
function show(obj) {
	var theObj = getObject(obj)
	theObj.visibility = "visible"
        return false
}

function showScroll(obj,objRef) {
  var theObj = getObject(obj)
  var top = getObjectTop(obj)
  theObj.visibility = "visible"
  off = getPageY(obj)
  if (objRef != null)
    off -= getPageY(objRef)
  window.scroll(0,off)
//  window.alert("pageY="+off)

  //window.alert(document.all.sec2.offsetTop)
//  showProps(document.all.sec2,sec2)
//  window.alert(theObj.pageY)
//  window.scroll(0,theObj.pageY)
  return false
}

// Setting the visibility of an object to hidden
function hide(obj) {
	var theObj = getObject(obj)
	theObj.visibility = "hidden"
        return false
}

// !! AAL Added - getObjectLeft wasn't returning the right value so I wrote this
// Retrieving the x coordinate of a positionable object relative to its parent
function getOffsetLeft(obj)  {
	var theObj = getObjectRef(obj)
	if (isNav4) {
		return theObj.left
	} else {
		return theObj.offsetLeft
	}
}

// !! AAL Added - getObjectTop wasn't returning the right value so I wrote this
// Retrieving the y coordinate of a positionable object relative to its parent
function getOffsetTop(obj)  {
	var theObj = getObjectRef(obj)
	if (isNav4) {
		return theObj.top
	} else {
		return theObj.offsetTop
	}
}

// Retrieving the x coordinate of a positionable object
function getObjectLeft(obj)  {
	var theObj = getObject(obj)
	if (isNav4) {
		return theObj.left
	} else {
		return theObj.pixelLeft
	}
}

// Retrieving the y coordinate of a positionable object
function getObjectTop(obj)  {
	var theObj = getObject(obj)
	if (isNav4) {
		return theObj.top
	} else {
		return theObj.pixelTop
	}
}

function showProps(o, objName) {
        var win
        win = window.open("",objName,"width=300,height=300,resizable,scrollbars")
        win.document.open();
        win.document.write("<HTML>");
        win.document.write("<XMP>")
	var result = ""
	count = 0
	for (var i in o) {
		result = objName + "." + i + "=" + o[i] + "\n"
                win.document.write(result)
/*
		count++
		if (count == 25) {
			alert(result)
			result = ""
			count = 0
		}
*/
	}
//	alert(result)
        win.document.write("</XMP>")
        win.document.close()
}


function makePopupWindow(winVar,winName,winURL)
{
  return makePopupWindowSize(winVar,winName,winURL,380,300)
}

function closePopup(winVar)
{
  if (winVar && ! winVar.closed)
   winVar.close()
}

function makePopupWindowSize(winVar,winName,winURL,width,height)
{
  var newWin = winVar

  if (!winVar || winVar.closed)
  {
    newWin = top.window.open(winURL,winName,"resizable=yes,height="+height+",width="+width+",scrollbars=yes")
  }
  else
  {
    newWin.resizeTo(width,height)
    newWin.focus()
  }
  return newWin
}

function makePopupWindowPos(winVar,winName,winURL,width,height,x,y)
{
  var newWin = winVar

  if (!winVar || winVar.closed)
  {
    if (useTop)
      newWin = top.window.open(winURL,winName,"resizable=yes,height="+height+",width="+width+",scrollbars=yes"+",left="+x+",top="+y)
    else
      newWin = window.open(winURL,winName,"resizable=yes,height="+height+",width="+width+",scrollbars=yes"+",left="+x+",top="+y)      
  }
  else
  {
    if (winURL != newWin.document.location)
      newWin.document.location = winURL
    newWin.moveTo(x,y)
    //! AAL commented out since this is not the same size as originally created window.  Will figure out later
    //newWin.resizeTo(width,height)
    newWin.focus()
  }
  return newWin
}


