///  Usage: 
///     var oAjaxReq = new AjaxRequest;
///     oAjaxReq.postAjaxRequest( 
///       (required string) "/process.aspx",
///       (required string) "firstname=John&lastname=Smith",
///       (optional string) callbackFunction
///     );

function AjaxRequest() {

    var pCallBack = "callBack";

	this.post = function (url, postArgs, callBack) {
	    // Do CR, LF, and CRLF replacement with spaces
	    postArgs = postArgs.replace(/\r\n/g, " ");
	    postArgs = postArgs.replace(/\r/g, " ");
	    postArgs = postArgs.replace(/\n/g, " ");
	    postArgs = postArgs.replace(/\t/g, "    ");
	    //  Set up the variables
	    this.contentType = "application/x-www-form-urlencoded";
	
	    //  Process the callback function
	    pCallBack = (callBack == undefined ? "callBack" : callBack);
	    
	    //  Branch for native XMLHttpRequest object
	    if (window.XMLHttpRequest) {
	        req = new XMLHttpRequest();
	        req.onreadystatechange = this.processReqChange;
	        req.open("POST", url, true);
	        req.setRequestHeader('Content-Type', this.contentType);
	        req.send(postArgs);
	        
	    //  Branch for IE/Windows ActiveX version
	    } else if (window.ActiveXObject) {
	        try {
	            req = new ActiveXObject("Msxml2.XMLHTTP");
	        } catch(excep) {
	            req = new ActiveXObject("Microsoft.XMLHTTP");
	        }
	        if (req) {
	            req.onreadystatechange = this.processReqChange;
	            req.open("POST", url, true);
	            req.setRequestHeader('Content-Type', this.contentType);
	            req.send(postArgs);
	        }
	    }
	};

    this.processReqChange = function () {
	
	    //  Only if req shows "complete"
	    if (req.readyState == 4) {
	    
	        //  Call the callback function
	        parent[ pCallBack ]( req.responseText );
	     
	    }
	};
}
