/**
* HttpRequest Object
*/
function HttpRequest() {
       this.headers = [];
       this.onComplete = false;
       this.onSend = false;
	  
       try {
               this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
       } catch (E) {
               this.xmlhttp = false;
               this.xmlhttp = new XMLHttpRequest();
       }
       this.applyCallback();
	   
}

HttpRequest.prototype.applyCallback = function() {
       var xmlhttp = this.xmlhttp;
       var request = this;
       xmlhttp.onreadystatechange = function() {
               if (xmlhttp.readyState == 2) {
                       if (request.onSend) {
                               request.onSend.call();
                       }
               } else if (xmlhttp.readyState == 4) {
                       if (request.onComplete) {
                       	document.body.style.cursor='auto';
								response = {
                                    status: xmlhttp.status,
                                    text: xmlhttp.responseText,
                                    headers: xmlhttp.responseHeaders
								}
								if (xmlhttp.responseXML != undefined) response.xml = xmlhttp.responseXML;
								request.onComplete.call(null, response);
                       }
               }
       }
}

HttpRequest.prototype.addHeader = function(name, value) {
       this.headers[name] = value;
}

//HttpRequest.prototype.setRequestHeaders = function() {
 //      request.headers.each(function(key){
  //             this.xmlhttp.setRequestHeader(key, request.headers[key]);
   //    });
//}

HttpRequest.prototype.get = function(uri) {
	document.body.style.cursor='wait';
	this.xmlhttp.open("GET", uri, true);
  //  this.setRequestHeaders();
    this.xmlhttp.send(null);
}

HttpRequest.prototype.post = function(uri, data) {
		document.body.style.cursor='wait';
       this.xmlhttp.open("POST", uri, true);
       if (!this.headers['Content-Type']) {
               this.addHeader('Content-Type', 'application/x-www-form-urlencoded');
       }
     //  this.setRequestHeaders();
	 this.xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
       this.xmlhttp.send(data);
}

HttpRequest.prototype.head = function(uri) {
       this.xmlhttp.open("HEAD", uri, true);
       this.setRequestHeaders();
       this.xmlhttp.send(null);
}

function httpEncode(string) {
	if (encodeURIComponent) {
	    string = encodeURIComponent(string);
	} else {
	    string = escape(string);
	}
	string = string.replace("+","%2B").replace("/","%2F");
	return string;
}
