/*********************************************************************************/
/*********************************************************************************/
/*********************************************************************************/
/*	Filename: mocc_lib_elems.js																		*/
/*	current version: 1.1												*/
/*	date: 2007-09-29													*/
/*	Description: This file contains the necessary functions to handle and modify elements in general		*/
/*						Functionality for specific elements should be placed in specific libraries			*/
/*																											*/
/*	Dependencies: none																		*/
/*	Contributors (chronological order, starting with originating author):									*/
/*					1. Matt Olinger (MO)																	*/
/*					2. Cliff Chambers (CC)																*/
/*																											*/
/*************************************************************************************/
/*	version history:													*/
/*************************************************************************************/
/*	Version 1, created 2007-09-11 with functions: getElem and setElemStyle	(MO)					*/
/*  Version 1.1, updated 2007-09-29 with function: getElemCountByClassName (CC)  				*/
/*  Version 1.2, updated 2007-10-06 with function: insertElem (CC), removeElem (CC)
/*  Version 1.3, updated 2007-10-28 with function: getElemCountByID (MO)
/*																*/
/*********************************************************************************/
/*********************************************************************************/
/*********************************************************************************/


/*********************************************************************************/
/*	FUNCTION getElem	(original source unknown)												*/
/*	Parameters: ob=string specifying ID of the element to be returned					*/
/*																											*/
/*	Returns: handle to the element specified by ID											*/
/*																											*/
/*	Dependencies: none																		*/
/*																											*/
/*********************************************************************************/
function getElem(ob) {
	if (document.getElementById) {		// this is the way the standards work
		elem = document.getElementById(ob);
	}
	else if (document.all) {				// this is the way old msie versions work
		elem = document.all[ob];
	}
	else if (document.layers) {			// this is the way nn4 works
		elem = document.layers[ob];
	}
return elem;
}


/*********************************************************************************/
/*	FUNCTION setElemStyle	(alpha version)																	*/
/*	Parameters: ob=string specifying ID of the element to be modified					*/
/*				str=a string representing the style that is to be applied							*/
/*					e.g. "display: block; border: 1px solid black;"									*/
/*																											*/
/*	Returns: all js commands used to modify the element in full												*/
/*																											*/
/*	Dependencies: mocc_lib_string.js (.trim)																*/
/*																											*/
/*********************************************************************************/
function setElemStyle(ob,str) {
	var singleStr, fullStr='';
	var elem=getElem(ob);
	var attributes=str.split(";");
	for (var i=0;i<attributes.length;i++) {
		var val=attributes[i].replace(/;/g,'');	//global replace of semicolon to null (mostly in case last attribute is only a semicolon
		val=val.trim();
		if (val!='') {
			val=val.replace(/:\s*/g,'="');			//globally remove the colon and any following spaces
			singleStr='elem.style.' + val + '";';	//transfer css language into js (width: 100px -> elem.style.width="100px";)
			eval(singleStr);							//perform the js equivalent fo the css
			fullStr+=singleStr;						//add the newly performed command to the output
		}
	}
return fullStr;		//send the entire list of js commands that was used (only good for debugging purposes)
}

/*********************************************************************************/
/*	FUNCTION isArray																					*/
/*	Parameters: ob=string specifying variable/constant to be checked					*/
/*																											*/
/*	Returns: true if ob is an array, false if ob is not an array												*/
/*																											*/
/*	Dependencies: none																					*/
/*																											*/
/*********************************************************************************/
function isArray(ob) {
   return (ob.constructor.toString().indexOf("Array") != -1)
}


/*********************************************************************************/
/*	FUNCTION getElemCountByID																					*/
/*	Parameters: ob=string specifying class name to be checked					*/
/*																											*/
/*	Returns: count 											*/
/*																											*/
/*	Dependencies: none																					*/
/*																											*/
/*********************************************************************************/


function getElemCountByID(ob) {
	var pgt = new Array();
	var cn=0;
	pgt = document.getElementsByTagName("*");
	for (i=0; i<pgt.length; i++) {
		if (pgt[i].id==ob) {
			cn++;
		}
	}
	return cn;
}


/*********************************************************************************/
/*	FUNCTION getElemCountByClassName																					*/
/*	Parameters: ob=string specifying class name to be checked					*/
/*																											*/
/*	Returns: count 											*/
/*																											*/
/*	Dependencies: none																					*/
/*																											*/
/*********************************************************************************/


function getElemCountByClassName(ob) {
	var pgt = new Array();
	var cn=0;
	pgt = document.getElementsByTagName("*");
	for (i=0; i<pgt.length; i++) {
		if (pgt[i].className==ob) {
			cn++;
		}
	}
	return cn;
}


/*********************************************************************************/
/*	FUNCTION insertElem																					*/
/*	Parameters: parent = parent element					*/
/*  			child = element to be added inside of parent
/*				txt = text to be assigned to the child element
/*				childattrib = array of attributes that are assigned to the child element
/*																											*/
/*	Returns: nothing 											*/
/*																											*/
/*	Dependencies: none																					*/
/*																											*/
/*********************************************************************************/


function insertElem(parent,child,txt,childattrib) {
	var elem = document.createElement(child);
	var elemtxt = document.createTextNode(txt);
	//if (parent=="document") var parentelem = document.getChildNodes().item(0).getChildNodes().item(1); //get body element
	if (parent=="document") var parentelem = document.body; //get body element
	else var parentelem = getElem(parent);

	for (i=0; i < childattrib.length; i++) {
		var tribs = childattrib[i].split(",")
		if (tribs[0]=="class") {
			elem.className=tribs[1];
		} else {
			//elem.setAttribute(tribs[0].replace("|",","),tribs[1].replace("|",","));	
			 elem.setAttribute(tribs[0].replace(/\|/g,","),tribs[1].replace(/\|/g,","));
		}
		
	}
	parentelem.appendChild(elem);
	elem.appendChild(elemtxt);
}



/*********************************************************************************/
/*	FUNCTION removeElem																					*/
/*	Parameters: parent = parent element					*/
/*  			child = element to be removed inside of parent
/*																											*/
/*	Returns:  											*/
/*																											*/
/*	Dependencies: none																					*/
/*																											*/
/*********************************************************************************/
function removeElem(child) {
    childelem = getElem(child);
	if (childelem != null)
	    childelem.parentNode.removeChild(childelem);
	var bt = determineBrowser(); //start iFrame workaround on IE6
	if (bt == 'IE') {
	    if (document.getElementsByTagName('iFrame').length > 0) {
	        document.getElementById("gdframe").style.display = "none";
			document.body.removeChild(GiFrame);
	        GiFrame = null;
	    }
	}// end iFrame workaround on IE6
    	
}

/*********************************************************************************/
/*	FUNCTION shadeBody																				*/
/*	Parameters: none					*/
/*																											*/
/*	Returns:  											*/
/*																											*/
/*	Dependencies: none																					*/
/*																											*/
/*********************************************************************************/
var scrollshadecall;
function shadeBody(top,left) {
	if (top==undefined) var top=0;
	if (left==undefined) var left=0;

	if (getElemCountByID('overlay')==0) {
		var objBody = document.getElementsByTagName("body").item(0);
		var objOverlay = document.createElement("div");
		objOverlay.setAttribute('id','overlay');
		objBody.insertBefore(objOverlay, objBody.firstChild);
		setElemStyle('overlay','top: ' + top + 'px; left: ' + left + 'px;');
		scrollshadecall=setInterval('scrollShade('+top+','+left+')',10);
	}
}

/*********************************************************************************/
/*	FUNCTION unshadeBody																				*/
/*	Parameters: none					*/
/*																											*/
/*	Returns:  											*/
/*																											*/
/*	Dependencies: none																					*/
/*																											*/
/*********************************************************************************/
function unshadeBody() {
	var d = getElem('overlay');
	d.parentNode.removeChild( d );
	clearInterval(scrollshadecall);
}

/*********************************************************************************/
/*	FUNCTION scrollShade																				*/
/*	Parameters: none					*/
/*																											*/
/*	Returns:  											*/
/*																											*/
/*	Dependencies: none																					*/
/*																											*/
/*********************************************************************************/
function scrollShade(top,left) {
	scroll(top,left);
}


function toggleTableRowVisible(id) {
	var elem=getElem(id);
	if (elem.style.display=='none'){
		elem.style.display = '';
	} else {
		elem.style.display = 'none';
	}
}
