/*
 * Wrapper object for making XMLHttpRequests
 */
 
// Global constants
var HTTP_METHOD_GET = "GET";
var HTTP_METHOD_POST = "POST";

 
 function AjaxWrapper() {
	this.request = function(httpMethod, url, callBackMethod) {
	this.httpRequest = this.buildXMLHttpRequest();
	this.httpRequest.onreadystatechange = callBackMethod;
	this.httpRequest.open(httpMethod, url, true);
	this.httpRequest.send(url);

	}
	
	this.getRequestObj = function() {
		return this.httpRequest;
	}
	
	this.buildXMLHttpRequest = function() {
		if(window.XMLHttpRequest) {
			return new XMLHttpRequest();
		}
		else if(window.ActiveXObject) {
			var msxmls = new Array(
				"Msxml2.XMLHTTP.5.0",
				"Msxml2.XMLHTTP.4.0",
				"Msxml2.XMLHTTP.3.0",
				"Msxml2.XMLHTTP",
				"Microsoft.XMLHTTP");
			for(var idx=0; idx<msxmls.length; idx++) {
				try {
					return new ActiveXObject(msxmls[idx]);
				} catch (e) {
					// Trying the next object
				}
			}
		}
		throw new Error("Failed to instantiate XMLHttpRequest");
	}
	
	this.getResponseText = function() {
		return this.httpRequest.responseText;
	}
	
	this.getResponseXml = function() {
		return this.httpRequest.responseXML;
	}
	
	
	this.get = function(url, callBackMethod) {
		this.request(HTTP_METHOD_GET, url, callBackMethod);
	}
	
	this.post = function(url, callBackMethod) {
		this.request(HTTP_METHOD_POST, url, callBackMethod);
	}
	
	this.isProcessed = function() {
		if ( this.httpRequest.readyState == 4 && this.httpRequest.status == 200) {
			return true;
		}
		return false;
	}	
 } 


