﻿
var ajaxRequest = function(targetObj, u, m, s){
	
	this.targetObject 	= targetObj;
	this.url			= u;
	this.method			= m || "GET";
	this.async			= s || true;
	this.body			= null;
	this.head			= false;
	
	var _this = this;
	
	//------------------------------------------------------------
	try{
		this.request = new XMLHttpRequest();	
	}catch(e){
		try{
			this.request = new ActiceXObject("Msxml2.XMLHTTP");
		}catch(e){
			try{
				this.request = new ActiveXObject("Microsoft.XMLHTTP");
			}catch(e){
				this.request = false;	
			}
		}
	}	
	//------------------------------------------------------------
	
	this.doRequest = function(){		
		this.request.open(this.method, this.url, this.async);
		this.request.onreadystatechange = this.checkState;		
		this.request.send(this.body);		
	}
	
	this.checkState = function(){		
		if(_this.request.readyState<4){
			document.getElementById("waiting").style.display = "block";
		}else{
			if(_this.request.status == 200 || _this.request.status == 304){	
				document.getElementById("waiting").style.display = "none";
				if (_this.request.responseText !='') {
					
					//alert(_this.request.responseText);
					document.getElementById(_this.targetObject).innerHTML = _this.request.responseText;
				}
			}
		}
	}
	
}
