/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  *
  * Title : 		Javascript actions for all pages
  * Author : 		Ryan Campbell
  * URL : 		http://particletree.com
  *
  * Description :	Includes functions and classes used by every page - listed below:
  *				- 	addEvent
  *				-	cAjax
  *				-	right() and left()
  *				-	getAction
  *
  * Created : 	8/18/2005
  * Modified : 	8/22/2005
  *
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
 
/*
  * Summary:	Attaches an event to the object passed in
  *			Script written by Christian Heilmann at http://www.onlinetools.org/articles/unobtrusivejavascript/chapter4.html
  * Parameters: 	Object to attach event to | type of event to attach | function call
  * Return: 		Boolean indicating success or failure
  */
function addEvent(obj, evType, fn){ 
	if (obj.addEventListener){ 
		obj.addEventListener(evType, fn, false); 
		return true; 
	} 
	else if (obj.attachEvent){ 
		var r = obj.attachEvent("on"+evType, fn); 
		return r; 
	}
	else { 
		return false; 
	} 
}

/*
  * Summary:	Object to handle Ajax Requests
  *			Process return based on calling object constructor
  *			WARNING: This class is for testing and is not complete
  */
function cAjax() {

	if (window.XMLHttpRequest) {
		this.req = new XMLHttpRequest();
	}
	else {
		this.req = new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	this.loadXMLDoc = function(url, data) {
		this.req.onreadystatechange = this.processReqChange;
		this.req.open("GET", url, true);
		this.req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
		this.req.send(data);
	}
	
	this.ajaxString = function(nodeID, bFirst) {
		if(bFirst) {
			return nodeID + "=" + escape(document.getElementById(nodeID).value);
		}
		else {
			return "&" + nodeID + "=" + escape(document.getElementById(nodeID).value);
		}
	}
}

/*
  * Summary:	Find out what function to process based on classname
  */
 function getAction(name) {
	allNames = name.split(" ");
	for(x = 0; x < allNames.length; x++) {
		if(left(allNames[x], 4) == "func") {
			return right(allNames[x], allNames[x].length - 4);
		}
	}
 }

/*
  * Summary:	Copy of vbscripts left function
  *			 http://www.devx.com/tips/Tip/15222
  */
function left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}

/*
  * Summary:	Copy of vbscripts right function
  *			 http://www.devx.com/tips/Tip/15222
  */
function right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

