/**
 * @author jeremy
 * Generalized AJAX stuff - first used for Bianca Sells website
 * Created: 25 September 2008
 * Last Change: 25 September 2008
 */

function AjaxCall() {
	this.filepath = "";
}
AjaxCall.prototype.filepath;

AjaxCall.prototype.run = function() {
	var xmlObj = null;
	
	with (this) {
		file = filepath;
		beforeFunction();
		
		if(window.XMLHttpRequest){
			xmlObj = new XMLHttpRequest();
		} else if(window.ActiveXObject){
		    xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
		} else {
			afterFunction();
		    return;
		}
		
		xmlObj.onreadystatechange = function(){
		    if(xmlObj.readyState == 4){
				successFunction(xmlObj);
				afterFunction();
		    } else {
				failureFunction(xmlObj);
			}
	  	}
		
	    xmlObj.open ('GET', file, true);
	    xmlObj.send ('');
		
	} // end of with
}


AjaxCall.prototype.failureFunction = function(xmlObj) {
	//alert("Call Failed. Ready State: " + xmlObj.readyState);
	return false;
}

// parameters is in the form of a long string containing:
// field_name=encodeURI(field_value)
// with each field separated by an ampersand "&"
AjaxCall.prototype.post_form = function(parameters) {
	var xmlObj = null;
	
	with (this) {
		file = filepath;
		beforeFunction();
		
		if(window.XMLHttpRequest){
			xmlObj = new XMLHttpRequest();
		} else if(window.ActiveXObject){
		    xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
		} else {
			afterFunction();
		    return;
		}
		
		xmlObj.onreadystatechange = function(){
		    if(xmlObj.readyState == 4){
				successFunction(xmlObj);
				afterFunction();
		    }
	  	}
		
	    xmlObj.open ('POST', file, true);
	    xmlObj.send (parameters);
		
	} // end of with
}
