
/*
* Function to take a standard javascript event object and return the target that triggered the event.
* Pre-Condtion: An javascript event must exist.
* Post-Condition: The target that triggered the event is returned.
*
* @param        e - standard javascript event
* @return		targ - the target that triggered the event.
*/
function getEventCurrentTarget(e){
	var targ
	if (!e) var e = window.event
	if (e.currentTarget) targ = e.currentTarget
	else if (e.srcElement) targ = e.srcElement
	if (targ.nodeType == 3) // defeat Safari bug
		targ = targ.parentNode
	return targ;
}

/*
* Function to take a standard javascript event object and return the physical element that triggered the event.
* Pre-Condtion: An javascript event must exist.
* Post-Condition: The physical element that triggered the event is returned.
*
*
* @param        e - standard javascript event.
* @return		targ - Returns the physical element that triggered the event.
*/
function getEventElement(e){
	var targ
	if (!e) var e = window.event
	if (e.target) targ = e.target
	else if (e.srcElement) targ = e.srcElement
	if (targ.nodeType == 3) // defeat Safari bug
		targ = targ.parentNode
	return targ;
}


/*
* Function to append an option to a select statement.
* Pre-Condition: The select statement must exist.
* Post-Condition: The option is added to the select statement passed to the function.
*
* @param        select - the name of the select statement to be appended.
* @param		option - the option to be appeneded to the select statement.
* @return		select - the select statement with the new option appended.
*/
function appendOptionToSelect(select, option){
	if(browserCheck.ie){
		var num = select.options.length;
		select.options[num] = option;
	}
	else {
		select.appendChild(option);
	}
	return select;
}


/*
* Function that creates an option for a select statement.
* Post-Condition: An option is created with the text and value pair.
* @param        value - a value of a option
* @param		text - the text of the option
* @return		opt - the completed option statement
*/
function getSelectOption(value, text){
	var opt;
	if(browserCheck.ie){
		opt = new Option(text,value);
	}
	else {
		opt = document.createElement("option");
		opt.value = value;
		opt.text = text;
	}
	return opt;
}


/*
* Function to remove all children from a node.
* Pre-Condition: The node is an html element.
* Post-Condition: All children are removed from the node.
*
* @param        node - node to have all children removed from.
* @author       Seisan Consulting   2-16-2006
*/
function removeAllChildren(node){
	if(!node){
		return;
	}

	var len = node.childNodes.length;

	for(var i = 0; i < len; i++){
		try{
			node.removeChild(node.childNodes[i]);
		}
		catch(ex){}
	}

	node.innerHTML = "";

}

/*
* Function to build an html input element.
* Pre-Condition: none
* Post-Condition: An html input element is constructed based on the type, name and value.
*
* @param        type - input type
* @param		name - input name
* @param		value - input value
* @return       input - an html input element
*/
function createInputElement(type, name, value){
	if(browserCheck.ie)
		return document.createElement("<input type=\"" + type + "\" name=\"" + name + "\" value=\"" + value + "\"/>");
	else {
		input = document.createElement("input");
		input.type = type;
		input.name = name;
		input.value = value;
		return input;
	}
}

