/******************************************************************************
 * Pre-notes:
 *   Use Ctrl + F to search for the following items...
 *   - udating -
 *       A portion of code which is undergoing an update.
 *   - removing -
 *       A portion of code which is presently being decommissioned and
 *         removed.      
 ******************************************************************************/

/*********************** Create some global variables.  ***********************/
var ns4;
var op5;
var op6;
var agt;
var mac;
var ie; 
var mac_ie;
/*************************** Create some functions. ***************************/
/*
 sniffBrowsers() - updating -
   This function checks for JavaScript features available in the browser and
     sets to global variables.
*/
function sniffBrowsers() {
	ns4    = document.layers;
	op5    = (navigator.userAgent.indexOf("Opera 5")!=-1)
           || (navigator.userAgent.indexOf("Opera/5")!=-1);
	op6    = (navigator.userAgent.indexOf("Opera 6")!=-1)
           || (navigator.userAgent.indexOf("Opera/6")!=-1);
	agt    = navigator.userAgent.toLowerCase();
	mac    = (agt.indexOf("mac")!=-1);
	ie     = (agt.indexOf("msie") != -1); 
	mac_ie = mac && ie;
}
/*
 getStyleObject()
   A function that returns style property of an object if it exists, otherwise
     it returns false (meaning that it could not find the style property).
*/
function getStyleObject(objectId, doc) {
    if(document.getElementById && document.getElementById(objectId)) {
	return document.getElementById(objectId).style;
    } else if (document.all && document.all(objectId)) {
	return document.all(objectId).style;
    } else if (document.layers && document.layers[objectId]) {
		return getObjNN4(document,objectId);
    } else {
	return false;
    }
} 
/*
 changeObjectVisibility()
   Self-explanitory function. Changes the visiblity of an object and then
     returns a boolean value based whether or not it was able to change the
     visiblity of the object.
*/
function changeObjectVisibility(objectId, newVisibility) {
    var styleObject = getStyleObject(objectId, document);
    if(styleObject) {
	styleObject.visibility = newVisibility;
	return true;
    } else {
	return false;
    }
} 
/*
 getObjNN4() - updating -
   An old function that still has a little bit of life left in it. Originally
     intended for use on Netscape Navigator versions 4 and up, this function
     simply returns a reference to an object by searching through the layers
     property.
*/
function getObjNN4(obj,name)
{
	var x = obj.layers;
	var foundLayer;
	for (var i=0;i<x.length;i++)
	{
		if (x[i].id == name)
		 	foundLayer = x[i];
		else if (x[i].layers.length)
			var tmp = getObjNN4(x[i],name);
		if (tmp) foundLayer = tmp;
	}
	return foundLayer;
}
/*
 getElementHeight()
   A makeshift function to represent getting an element's height the same way
     you can get an element by its ID. It locates an element and returns the
     value of its height.
*/
function getElementHeight(Elem) {
	if (ns4) {
		var elem = getObjNN4(document, Elem);
		return elem.clip.height;
	} else {
		var elem;
		if(document.getElementById) {
			var elem = document.getElementById(Elem);
		} else if (document.all){
			var elem = document.all[Elem];
		}
		if (op5) {
			xPos = elem.style.pixelHeight;
		} else {
			xPos = elem.offsetHeight;
		}
		return xPos;
	} 
}
/*
  getElementWidth()
    Another makeshift function whose purpose is self-explanitory.
*/
function getElementWidth(Elem) {
	if (ns4) {
		var elem = getObjNN4(document, Elem);
		return elem.clip.width;
	} else {
		var elem;
		if(document.getElementById) {
			var elem = document.getElementById(Elem);
		} else if (document.all){
			var elem = document.all[Elem];
		}
		if (op5) {
			xPos = elem.style.pixelWidth;
		} else {
			xPos = elem.offsetWidth;
		}
		return xPos;
	}
}
/*
 getElementLeft()
   This function tries to obtain and return the leftmost location of an
     element. (Positioned elements are always assumed to be in pixels.)
*/
function getElementLeft(Elem) {
	if (ns4) {
		var elem = getObjNN4(document, Elem);
		return elem.pageX;
	} else {
		var elem;
		if(document.getElementById) {
			var elem = document.getElementById(Elem);
		} else if (document.all){
			var elem = document.all[Elem];
		}
		xPos = elem.offsetLeft;
		tempEl = elem.offsetParent;
  		while (tempEl != null) {
  			xPos += tempEl.offsetLeft;
	  		tempEl = tempEl.offsetParent;
  		}
		return xPos;
	}
}
/*
 getElementTop()
   The same type of functionality as getElementLeft(), but instead returns the
     topmost location of an element.
*/
function getElementTop(Elem) {
	if (ns4) {
		var elem = getObjNN4(document, Elem);
		return elem.pageY;
	} else {
		if(document.getElementById) {	
			var elem = document.getElementById(Elem);
		} else if (document.all) {
			var elem = document.all[Elem];
		}
		yPos = elem.offsetTop;
		tempEl = elem.offsetParent;
		while (tempEl != null) {
  			yPos += tempEl.offsetTop;
	  		tempEl = tempEl.offsetParent;
  		}
		return yPos;
	}
}
/*
 moveXY()
   This function moves an object on both its X and Y coordinates if it can.
*/
function moveXY(myObject, x, y) {
	obj = getStyleObject(myObject)
	if (ns4) {
		obj.top = y;
 		obj.left = x;
	} else {
		if (op5) {
			obj.pixelTop = y;
 			obj.pixelLeft = x;
		} else {
			obj.top = y + 'px';
 			obj.left = x + 'px';
		}	
	}
}
/*
 changeClass()
   Changes the class of an element.
*/
function changeClass(Elem, myClass) {
	var elem;
	if(document.getElementById) {
		var elem = document.getElementById(Elem);
	} else if (document.all){
		var elem = document.all[Elem];
	}
	if (op5 || op6) elem.style.className = myClass;
	else elem.className = myClass;
}
