
/* ***************************************************** */
/*  hideElement(Object)		                              */
/*  sets display:none for object specified by param1     */
/* ***************************************************** */
function hideElement(oElem) {
	displayElement(oElem, 'none');
}



/* ***************************************************** */
/*  hideElementById(String)                              */
/*  sets display:none for object specified by param1     */
/* ***************************************************** */
function hideElementById(elemId) {
	displayElementById(elemId, 'none');
}



/* ***************************************************** */
/*  displayElement(Object, String)                       */
/*  sets display for object specified by param1          */
/*               to display state specified by param2    */
/* ***************************************************** */
function displayElement(oElem, displayState) {

	if (!displayState)
		displayState = 'block';

	if (document.getElementById) // DOM3 = IE5, NS6 
		oElem.style.display = displayState;  // show/hide 
	else 
		if (document.layers) // Netscape 4 
			document.layers[oElem].display = displayState; 
	else // IE 4 
			document.all.hideShow.oElem.display = displayState; 
}



/* ***************************************************** */
/*  displayElementById(String, String)                   */
/*  sets display for object specified by ID in param1    */
/* ***************************************************** */
function displayElementById(elemId, displayState) {
	var oElem;
	if ((oElem = document.getElementById(elemId)))
		displayElement(oElem, displayState);
}




/* ***************************************************** */
/*  displayByTagAndClassName(String, String)             */
/*  sets display:none for objects having the following:  */
/*      tag - specified by param1                        */
/*      style class - specified by param2                */
/*      display attribute - specified by param 3 (opt)   */
/* ***************************************************** */
function displayByTagAndClassName(tag,cName,displayType) {
	var divs = document.getElementsByTagName(tag); 
	for (var i=0; i<divs.length; i++) { 
		if (divs[i].className.match(cName)) {
			if (!displayType) { displayType = 'block' }
			displayElement(divs[i], displayType);
		}
	}
}


/* ***************************************************** */
/*  hideByTagAndClassName(String, String)                */
/*  sets display:none for objects having the following:  */
/*      tag - specified by param1                        */
/*      style class - specified by param2                */
/* ***************************************************** */
function hideByTagAndClassName(tag,cName) {
	var divs = document.getElementsByTagName(tag); 
	for (var i=0; i<divs.length; i++){ 
		if (divs[i].className.match(cName))
			hideElement(divs[i]);
	}
}



/* ***************************************************** */
/*  hideByTagAndId(String, String)                       */
/*  sets display:none for objects having the following:  */
/*      tag - specified by param1                        */
/*      id - specified by param2                         */
/* ***************************************************** */
function hideByTagAndId(tag,idName) {
	var divs = document.getElementsByTagName(tag); 
	for (var i=0; i<divs.length; i++){ 
		if (divs[i].id.match(idName))
			hideElement(divs[i]);
	}
}



/* ***************************************************** */
/*  isAncestor(Object, Object)                           */
/*  returns true if param1 is ancestor of param 2        */
/* ***************************************************** */
function isAncestor(oAncestor,oChild) {
	if (oChild == oAncestor)
		return true;
	else if (oChild != document) {
		if (oChild.parentNode) {
			return isAncestor(oAncestor,oChild.parentNode);
		}
	}
	else
		return false;
}



/* ***************************************************** */
/*  getFirstChildByTag(Object, String)                    */
/*  returns first child of param1                        */
/*  where tag matches param2                             */
/* ***************************************************** */
function getFirstChildByTag(oParent,tag) {
	var elements = document.getElementsByTagName(tag); 
	for(var i=0; i<elements.length; i++) {
		if(isAncestor(oParent,elements[i]))
			return elements[i];
	}
	return null;
}


/* ***************************************************** */
/*  getDecendentByClass(Object, String)                  */
/*  returns first decendent of param1                    */
/*  where class matches param2                           */
/* ***************************************************** */
function getDecendentByClass(oParent,cName) {
	var r;
	
	if (oParent.className == cName)
		return oParent;
	
	if (!(oParent.childNodes))
		return null;
				
	for (var i=0; i<oParent.childNodes.length; i++) {
		r = getDecendentByClass(oParent.childNodes[i],cName);
		if (r != null)
			return r;
	}

	return null;
}



/* ***************************************************** */
/*  isAncestorDisplayed(child,state)                     */
/*  returns true if child is decended from an object     */
/*  that has a specified display state                   */
/* ***************************************************** */
function isAncestorDisplayed(oElem,displayState) {
	if (oElem == document)
		return false;
	else if (oElem.tagName == 'HTML') /* old version of IE throw an error looking for currentStyle on the HTML object */
		return false;
		
	if (oElem.currentStyle) {	/* check for in-line style -- IE */
		if (oElem.currentStyle.display == displayState)
			return true;
	}
	else if (window.getComputedStyle) { /* check for in-line style -- non-IE browsers */
		if (document.defaultView.getComputedStyle(oElem,null).getPropertyValue('display') == displayState)
			return true;
	}
	else if (oElem.style) {
		if (oElem.style.display == displayState)
			return true;
	}
	return isAncestorDisplayed(oElem.parentNode,displayState);
}



/* ***************************************************** */
/*  isDecendent(Object, Object)                          */
/*  returns true if param1 is decended from param 2      */
/* ***************************************************** */
function isDecendent(oChild,oParent) {
	for (var i=0; i<oParent.childNodes.length; i++) {
		if (oParent.childNodes[i] == oChild)
			return true;
		else
			return isChild(oChild,oParent.childNodes[i]);
	}
	return null;
}




/* ***************************************************** */
/*  getCurrentFormObj(Object, String)                    */
/*  returns form object if within displayed container    */
/* ***************************************************** */
function getCurrentFormObj(oForm,inputName) {
	for (var i=0; i<oForm.elements.length; i++) {
		if (!isAncestorDisplayed(oForm.elements[i],'none')) {
			if (oForm.elements[i].name == inputName)
				return oForm.elements[i];
		}
	}
	return null;
}



/* ***************************************************** */
/*  getFormByName(string)                                */
/*  returns form object if name matches param1           */
/* ***************************************************** */
function getFormByName(formName) {
	for (var i=0; i<document.forms.length; i++) {
		if (formName == document.forms[i].name)
			return document.forms[i];
	}
	return null;
}



/* ***************************************************** */
/*  resetPageForms([string])                             */
/*  resets all form values for all page forms            */
/*  optional: param1 specifies single form reset by name */
/* ***************************************************** */
function resetPageForms(formName) {
	var forms = document.getElementsByTagName('form');
	for(var i=0; i<forms.length; i++) {
		if (!formName || (formName && (formName == forms[i].name)))
			forms[i].reset();
	}
}



/* ****************************************************************** */
/* ****************************************************************** */

