/**
 * library.js
 * by Brian Swartzfager
 */

function jsChangeHref(id,href) {
	/*Action usage:  To change the href value of a hyperlink
	id:  the id of the hyperlink
	href:  the new href value */
	//Get object identified by id
	target_object= document.getElementById(id);
	
	target_object.href= href;
	
} //end of function


function jsChangeNodeClass(id,newclass) {
	//Action usage:  Any listener.
	//id:  the id of the page element
	//newclass:  the name of the new class.  Must be in the form of "CSSattribute_value" (examples:  "color_red", "font-weight_bold")
	
	//Get object identified by id
	target_object= document.getElementById(id);
	//Get object's current classes
	old_value= target_object.className;
	
	//Define variable to denote if newclass is replacing an existing class or is being added
	var replacing= 'no';
	
	//split newclass into style and value
	newclass_style= newclass.split("_");
	
	//Split old_value by spaces
	class_array= old_value.split(" ");
	for (var i= 0; i < class_array.length; i++)
		{
			class_data= class_array[i].split("_");
			if (class_data[0]== newclass_style[0])
				{
					replacing= 'yes';
					class_data[1]= newclass_style[1];
					class_array[i]= class_data[0] + "_" + class_data[1];
				}
		}
	
	if (replacing== 'no')
		{
			new_value= old_value + " " + newclass;
		}
	else
		{
			replace_value= '';
			for (var i= 0; i < class_array.length; i++)
				{
					replace_value= replace_value + class_array[i] + " ";
				}
			new_value= replace_value;
		}
		
	//This works in IE and Firefox:  thisitem.className= 'color_green';
	target_object.className= new_value;
	
} //end of function

function jsChangeNodeText(id,text) {

	//Get element
	//alert("in jsChangeNodeText");
	node_element= document.getElementById(id);
	
	//Update the text node within the element, forking depending on browser
	if (typeof node_element.innerText != "undefined")
		{
			//IE browser, so use innerText to update
			node_element.innerText= text;
		}
	else
		{
			//Use childNodes reference
			node_element.childNodes[0].nodeValue= text;
		}
	
}  //end of function



