function ajax() {
	this.url = "" ;
	this.method = "GET" ;
	this.timeout = 60 ;
	this.callback = "" ;
	
	this.Ajax_ID = "Unknown";
	
	var response = "" ;
	var http_request = false ;
	var callback = this.callback ;
	var timeout  = this.timeout ;
	var start_time = new Date() ;
	var end_time = new Date() ;
	var timeout_status = false ;
	var request_status = false ;	
  var Ajax_ID = this.Ajax_Id;
	
	
  this.request = ajaxRequest ;
	this.resultText = getHttpResultText ;
	this.resultXML = getHttpResultXML ;
	
	function ajaxRequest() {
	  AjaxProcess = AjaxProcess + 1;
	  
		timeout  = this.timeout ;
		callback = this.callback ;
		start_time = new Date() ;
		end_time = new Date() ;
		timeout_status = false ;
		request_status = false ;
		
		Ajax_ID = this.Ajax_ID;
    var url = this.url ;
   	var url_post = url ;
		var url_send = null;
				
		if (url.indexOf('?')>0)
		{
			url_post = url.substring(0,url.indexOf('?'));
			url_send = url.substring(url.indexOf('?')+1);
		} else {
			url_post = url ;
			url_send = null ;
		}
	
		http_request = false;
		if (window.XMLHttpRequest) { // Mozilla, Safari,...
			http_request = new XMLHttpRequest();
			if (http_request.overrideMimeType) {
				http_request.overrideMimeType('text/xml');
			}
		} else if (window.ActiveXObject) { // IE
			try {
				http_request = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					http_request = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {}
			}
		}
	
		if (!http_request) {
			alert("Giving up... Cannot create XML HTTP instance");
			AJAX_ProcessFailedHandler(4);
			return false;
		}
		http_request.onreadystatechange = ajaxReady ;
		if ((this.method).toUpperCase() == 'POST')
		{
			http_request.open('POST', url_post, true);
			http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			http_request.setRequestHeader("Content-length", url_send.length);
			http_request.setRequestHeader("Connection", "close");	
			http_request.send(url_send);
		} else {
			http_request.open('GET', url, true);
			http_request.send(url_send);			
		}
		request_status = true ;
		checkTimer();
		
	}
	
	function ajaxReady() {
	 try 
   {
  		if (http_request.readyState == 4) {
  			request_status = false ;
  			if (http_request.status == 200) {
  				if (!timeout_status) {
  				  if (AjaxProcess > 0) AjaxProcess = AjaxProcess - 1;
  				  if (AjaxProcess == 0 ) LoadingStop("PS");  				  
  					ajaxDone() ;  					
  				}
  			} else if (http_request.status == 404) {
  				alert('This service is not found in the server, please contact this site administrator.');
  				AJAX_ProcessFailedHandler(2);
  			} else if (http_request.status == 500) {
  				alert('This service encounter problem, please contact this site administrator.');
  				AJAX_ProcessFailedHandler(3);
  			}
  		}
   }catch(e) {  
   /*   
     var dc = document.getElementById("DC");
     if (dc) dc.innerHTML += "<br>Ajax service with ID : " + Ajax_ID + " was failed to get data.<br>Requesting data from Url :<br>" + Url + "<br><br>";
     alert("Ajax service with ID : " + Ajax_ID + " was failed to get data.\n\nRequesting data from Url :\n" + Url);
    */
     AJAX_ProcessFailedHandler(5);
   }
	}
	
	function checkTimer() {
		end_time = new Date() ;
		var timer = Math.round((end_time.getTime() - start_time.getTime())/1000) ;
		if (timer > timeout) {
			var timeout_display = (timeout_status == false)?true:false;
			timeout_status = true ;
			http_request.abort() ;
			if (timeout_display) {
				alert("Sorry, timeout while connecting please check your internet connection");
				AJAX_ProcessFailedHandler(1);
			}
		}
		if (request_status) {
			setTimeout(checkTimer,1000) ;
		}
	}
	
	function ajaxDone() {
		if (callback) {
			eval(callback);
		}
	}
	
	function getHttpResultText() {
		if (http_request) {
			return http_request.responseText ;
		} else {
			return "" ;	
		}	
	}
	
	function getHttpResultXML() {
		if (http_request) {
			return http_request.responseXML ;
		} else {
			try { //Internet Explorer
				xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
			} catch(e) {
				try { //Firefox, Mozilla, Opera, etc.
					xmlDoc=document.implementation.createDocument("","",null);
				} catch(e) {
					return ;
				}
			}
		}			
	}
	
}


