// JavaScript Document
function Ajax(){
	this.xmlhttp = null;
	this.failedImgSrc = null;
	
	/********************************************************************************/
	this.initAjax = function(){
		var self = this;
		if (window.XMLHttpRequest)
		{
			try{
				self.xmlhttp = new XMLHttpRequest();
			} catch(e) {
				self.xmlhttp = null;  
			}
		} 
		else if (window.ActiveXObject)
		{
			try{
				self.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e){
				self.xmlhttp = null;
			}
		}
		return (self.xmlhttp!=null);
	};

	/********************************************************************************/
	this.Updater = function(url, method, responding, showPicLoading){
		var self = this;
		if(showPicLoading==undefined) showPicLoading=true;
		if(showPicLoading)
			self.loadRespond(responding, '<img src="images/loading.gif" border="0" align="absmiddle" /> <span class="styLoading">Loading ... </span>');
		if(!self.initAjax()) 
		{
			self.loadRespondFailed(responding);
			return;
		}
		self.xmlhttp.open("GET", url, true);
		self.xmlhttp.onreadystatechange= function() {
			if (self.xmlhttp.readyState==4) {
				if (self.xmlhttp.status==200){
					self.loadRespond(responding, self.xmlhttp.responseText)
				} else self.loadRespondFailed(responding);
			}
		}
		self.xmlhttp.send(null);
	};
	
	/********************************************************************************/
	this.loadRespondFailed = function(responding){
		obj = document.getElementById(responding);
		if(obj==undefined) alert('Object\'s not founded ['+responding+']');
		obj.innerHTML = '<img src="'+(this.failedImgSrc?this.failedImgSrc:'images/load_failed.gif')+'" border="0" align="absmiddle" /> <span class="styLoading">Loading failed !</span>';
	}
	
	/********************************************************************************/
	this.loadRespond = function(responding, responseText){
		obj = document.getElementById(responding);
		if(obj==undefined) {alert('Object\'s not founded ['+responding+']'); return;}
		obj.innerHTML = responseText;
	}
}

