/****************************************************************
Function: addLoadEvent()
Purpose: used to create onLoad events without having to define
 the event to be loaded within the document's body tag.  Also 
 allows you to apply multiple onload events.
Example Usage:
 addLoadEvent(pageLoadFunction1);
 addLoadEvent(pageLoadFunction2);
 addLoadEvent(pageLoadFunction3);
/***************************************************************/
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

/****************************************************************
Function: insertAfter()
Purpose: since there is no prebuilt insertAfter function like
 like there is an insertBefore, you can use this function to
 add a sibling element after an element within the same parent
 node
Example Usage:
 insertAfter(myNewElement, siblingElementToInsertAfter);
/***************************************************************/
function insertAfter(newElement,targetElement) {
  var parent = targetElement.parentNode;
  if (parent.lastChild == targetElement) {
    parent.appendChild(newElement);
  } else {
    parent.insertBefore(newElement,targetElement.nextSibling);
  }
}
/****************************************************************
Function: makeWindow()
Purpose: creates a new pop up window
Example Usage:
 makeWindow('../pageToLoad.html', '800', '600');
/***************************************************************/
function makeWindow(url, width, height)
{
	var newWindow;
	newWindow = window.open(url,"displaywindow","menubar=no,statusbar=no,scrollbars=yes,titlebar=yes,status=yes,resizable=yes,HEIGHT=" + height + ",WIDTH=" + width + ",left=0,top=0");
	newWindow.self.focus();
}
/****************************************************************
Function: getStyle()
Purpose: used to retrieve a css style of an element even if its
 embedded in a css class (ie: not defined inline)
Example Usage:
 getStyle(document.getElementById("container"), "font-size");
/***************************************************************/
// The regular version
function getStyle(oElm, strCssRule){
	var strValue = "";
	if(document.defaultView && document.defaultView.getComputedStyle){
		strValue = document.defaultView.getComputedStyle(oElm, "").getPropertyValue(strCssRule);
	}
	else if(oElm.currentStyle){
		strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){
			return p1.toUpperCase();
		});
		strValue = eval("oElm.currentStyle." + strCssRule);
	}
	return strValue;
}
// The version if you expect any IE 5.0 users whatsoever
function getStyle(oElm, strCssRule){
	var strValue = "";
	if(document.defaultView && document.defaultView.getComputedStyle){
		strValue = document.defaultView.getComputedStyle(oElm, "").getPropertyValue(strCssRule);
	}
	else if(oElm.currentStyle){
		try{
			strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){
				return p1.toUpperCase();
			});
			strValue = eval("oElm.currentStyle." + strCssRule);
		}
		catch(e){
			// Used to prevent an error in IE 5.0
		}
	}
	return strValue;
}
/****************************************************************
Function: qs()
Purpose: used to retrieve values that appear in URL query string
 using javascript
Example Usage:
 //Declare an array to hold querystring values
 var qsParm = new Array();
 //"input" and "text" refer to: test.htm?input=value&text=value2
 //initializes values
 qsParm['input'] = null;
 qsParm['text'] = null;
 //calls function which sets the values for initiazed
 //values above
 qs();
/***************************************************************/
function qs()
{
	var query = window.location.search.substring(1);
	var parms = query.split('&');
	for (var i=0; i<parms.length; i++)
	{
		var pos = parms[i].indexOf('=');
		if (pos > 0)
		{
			var key = parms[i].substring(0,pos);
			var val = parms[i].substring(pos+1);
			qsParm[key] = val;
		}
	}
}
/****************************************************************
FUNCTION: getElementsByClassName()
PURPOSE: This function makes up for the fact that Javascript has 
no getElementsByClassName function. It returns an array of all 
nodes with the associated class
EXAMPLE USAGE:
 ???
/***************************************************************/
function getElementsByClassName(oElm, strTagName, oClassNames){
	var arrElements = (strTagName == "*" && document.all)? document.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	var arrRegExpClassNames = new Array();
	if(typeof oClassNames == "object"){
		for(var i=0; i<oClassNames.length; i++){
			arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames[i].replace(/\-/g, "\\-") + "(\\s|$)"));
		}
	}
	else{
		arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames.replace(/\-/g, "\\-") + "(\\s|$)"));
	}
	var oElement;
	var bMatchesAll;
	for(var j=0; j<arrElements.length; j++){
		oElement = arrElements[j];
		bMatchesAll = true;
		for(var k=0; k<arrRegExpClassNames.length; k++){
			if(!arrRegExpClassNames[k].test(oElement.className)){
				bMatchesAll = false;
				break;
			}
		}
		if(bMatchesAll){
			arrReturnElements.push(oElement);
		}
	}
	return (arrReturnElements)
}

// If you want to support IE 5 with the getElementsByClassName function you will need to add the following to your js file
Array.prototype.push = ArrayPush;
function ArrayPush(value){
	this[this.length] = value;
}

