
function Ajax(){
	this.callback = function(){

		if (current_ajax_request.httpRequest.readyState == 4) {
//			alert(current_ajax_request.httpRequest.status);
		 	if (current_ajax_request.httpRequest.status == 200) {
		//		alert(current_ajax_request.callbackSuccess);
       			current_ajax_request.callbackSuccess(current_ajax_request.httpRequest.responseText);
		 	 
			    // perfect!
			} else {
			 
       			current_ajax_request.callbackFail(current_ajax_request.httpRequest.responseText);
       		
			}
		} else {
		    // still not ready
		}
	}
	
	this.callbackFail_default = function(response){
		alert("Could not update information");
	}
	this.doRequest = function(callback, data, type, url){
	 	this.callbackSuccess = callback;
  	 	window.current_ajax_request = this;
		this.httpRequest.onreadystatechange = this.callback;
     // alert(url);
		this.httpRequest.open(type, url, true);
	    this.httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		return this.httpRequest.send(data);
	}

	this.httpRequest = null;
	this.callbackSuccess = null;
	this.callbackFail = this.callbackFail_default;
	
	if (window.XMLHttpRequest) { // Mozilla, Safari, ...
	    this.httpRequest = new XMLHttpRequest();
        if (this.httpRequest.overrideMimeType) {
            this.httpRequest.overrideMimeType('text/xml');
            // See note below about this line
        }
	} else if (window.ActiveXObject) { // IE
            try {
                this.httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
                } 
                catch (e) {
                   try {
                        this.httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
                       } 
                     catch (e) {}
               }
    }
	if (!this.httpRequest) {
		alert('Giving up :( Cannot create an XMLHTTP instance');
        return false;
    }
	
}

function make_ajax_call(url, data, type, callback){
	ajax = new Ajax();
	return ajax.doRequest(callback, data, type, url);
}

function addtab(){
	make_ajax_call('graph_content.php', data, "POST", printtabdata);
}
