/*
Allhamdulilah
@Author  :  Masukree Tayakareng
@ Version : 1.00
@ ѲẺͧ Niruth Amnuaysilp (nirutha@gmail.com) Thaidev.com's Webmaster
*/
function  ajax()  // Class ajax
	{
		this._ajaxRequest; 
		this._param;
		this._length;
		this.ajaxdir;
		this.processOnly;
		this.responseText;
		this.show_pleasewait;
		
	this.jaxinit=function()
	{
		this._length=0;
		this._param="";
		this.processOnly=false;
		this.show_pleasewait=true;
	}  //end  jaxinit
	

	this.addvar=function(name,value)
	{	
		if (this._length==0){
			this._param+="?";
		}else{
			this._param+="&";
		}
		this._param+=name;
		this._param+="=";
		this._param+=value;
		this._length=this._length+1;	
	}  // end   addvar	
	
	this.getstring=function()
	{
		return this._param;
	}	 // end  getstring
	
	this.processajax=function(url,place)
	{  
		var  AjaxDir=(this.ajaxdir)?this.ajaxdir:'cvlibs/ajax/';
		var  processOnly=this.processOnly;
		var  Text;	
		this.addvar("temp",Math.random());
		
		xmlhttp=this.newXmlHttp();
		show_pleasewait=this.show_pleasewait;
		
		if(!this.processOnly){
			xmlhttp.onreadystatechange = function(){
				if(xmlhttp.readyState==4){
					 var Text=xmlhttp.responseText;
					
					 document.getElementById(place).innerHTML = Text;
				}else{
					if(show_pleasewait){
				     document.getElementById(place).innerHTML = "<center><img src='"+AjaxDir+"loading.gif'> Please wait...</center>";
					}
				}
			}		
			xmlhttp.open("GET", url+this.getstring(), true);
			xmlhttp.send(null);
		
		}else{
			xmlhttp.open("GET", url+this.getstring(), false);
			xmlhttp.send(null);	
			this.responseText=xmlhttp.responseText;
		}
		

		

	}	// end processajax
		
 this.newXmlHttp=function(){	
	try{
		 return  new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){
			try{
				return new ActiveXObject("Microsoft.XMLHTTP");
			}catch(e){
				return new XMLHttpRequest();
			}
		}

 } // end  newXmlHttp	
		
} //end class	

