
/// the ungraceful and only way to include a .js file 
//document.write('<script language="javascript" type="text/javascript" src="javascript/test.js">');

/*
ajUtils class

supports sends (sendAndReceive still in testing)


*/
//define class
function ajUtils(){


/*
////abort call
var xhReq = createXMLHttpRequest();
   xhReq.open("get", "infiniteLoop.phtml", true); // Server stuck in a loop.
   *** var requestTimer = setTimeout(function() {
       xhReq.abort();
       // Handle timeout situation, e.g. Retry or inform user.
     }, MAXIMUM_WAITING_TIME); ***
   xhReq.onreadystatechange = function() {
     if (xhReq.readyState != 4)  { return; }
     ** clearTimeout(requestTimer); **
     if (xhReq.status != 200)  {
       // Handle error, e.g. Display error message on page
       return;
     }
     var serverResponse = xhReq.responseText;
     ...
   };

*/

 
	
	this.xmlhttpSend = xmlhttpSend;
	function xmlhttpSend(strURL, getPost) {
		if (typeof getPost == 'undefined' ) var getPost = 'POST';
			var xmlHttpReq = false;
			var self = this;
		
			// Mozilla/Safari
			if (window.XMLHttpRequest) {
				self.xmlHttpReq = new XMLHttpRequest();
			}	
			// IE
			else if (window.ActiveXObject) {
				self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
			}	
	
			self.xmlHttpReq.open(getPost, strURL, false);
			self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			self.xmlHttpReq.onreadystatechange = function() {
	    }
		self.xmlHttpReq.send(strURL);
	}


	this.xmlhttpSendAndRecieve = xmlhttpSendAndRecieve;
	function xmlhttpSendAndRecieve(strURL, responseFunction, getPost, postVars) {
		if (typeof getPost == 'undefined' ) var getPost = 'POST';
		if (typeof postVars == 'undefined' ) var postVars = '';
		var xmlHttpReq = false;	
	    var self = this;
	    // Mozilla/Safari
	    if (window.XMLHttpRequest) {
			self.xmlHttpReq = new XMLHttpRequest();
	    }
	    // IE
	    else if (window.ActiveXObject) {
			self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	    }
	
	    self.xmlHttpReq.open(getPost, strURL, true);
	    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	
	   self.xmlHttpReq.onreadystatechange = function() {
			if (self.xmlHttpReq.readyState == 4) {
				document.body.style.cursor='default';
				responseFunction(self.xmlHttpReq.responseText);
			} else {
				document.body.style.cursor='wait';
			}
	    }
		if (getPost == "GET" || getPost == "get" || getPost == "Get"){
			self.xmlHttpReq.send(strURL);
		}else if (getPost == "POST" || getPost == "post" || getPost == "Post"){
			self.xmlHttpReq.send(postVars); // eg: postVars = 'arg1=val1&arg2=val2&arg3=val3';
		}
	}
	
}


//// add onloadEvent

//// this function is necessary to add onload events where existing events exist.
//// if you are not sure of other burried window.onload(s) then you can safely use this function instead of calling
//// window.onload directly, which may overwrite the possible existing onload function.  
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

