function thaiajax(){
	this.xmlhttp;
	this.formElement;
	this.method;
	this.requestFile;
	this.URLString;
	this.innerDivID;
	this.onCompletion = function() { };
	this.onProcess = function() { };
	this.loading = function(v) {
		var v;
		/*
		if(v==1){
			document.getElementById("divLoading").style.visibility = "visible";
		}else{
			document.getElementById("divLoading").style.visibility = "hidden";
		}
		*/
	}; 
	
	this.ConnXmlHttp = function(){
		try{
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){
			try{
				isIE = true;
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}catch(e){
				xmlhttp = false;
			}
		}
	
		if(!xmlhttp && document.createElement){
			xmlhttp = new XMLHttpRequest();
		}
		
		return xmlhttp;
	}
	
	this.getRequestBody = function(myForm) {
		var aParams = new Array();  
			for (var i=0 ; i < myForm.elements.length; i++) {

            	var sParam = encodeURIComponent(myForm.elements[i].name);
				//sParam = myForm.elements[i].name; 
               	sParam += "=";
               //	sParam += encodeURI(myForm.elements[i].value);
			   sParam += this.thai(myForm.elements[i].value);

               	aParams.push(sParam);
           	}     
			//alert(aParams.join("&")); 
           	return aParams.join("&");        
	}
	
	this.loadXMLDoc = function() {
	
		var self = this;
		this.xmlhttp = this.ConnXmlHttp();

		
		if (this.method == "GET") {
			var totalurlstring = this.requestFile + "?" + this.URLString;
			this.xmlhttp.open(this.method, totalurlstring, true);
		}else{
			this.URLString = this.getRequestBody(this.formElement);
			//alert(this.URLString); 
			this.xmlhttp.open(this.method,this.requestFile, true);
		}
		if (this.method == "POST"){
  			try {
				this.xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded')  
//				this.xmlhttp.setRequestHeader('charset', 'tis-620'); 
//				xmlRequest.setRequestHeader("charset", "utf-8")

			} catch (e) {}
		}
		this.xmlhttp.onreadystatechange = function(){
			if(self.xmlhttp.readyState==4&&self.xmlhttp.responseText){
				self.loading(0);
				self.onProcess();
				if (self.xmlhttp.status == 200) {
					self.response = self.xmlhttp.responseText;
					self.onCompletion();
					
				}
			}else{
				self.loading(1);
				self.onProcess();
			}
		}
		this.xmlhttp.send(this.URLString);
	}

	this.Dec2Hex = function(Dec) {
		var hexChars = "0123456789ABCDEF";
		var a = Dec % 16;
		var b = (Dec - a)/16;
		hex = "" + hexChars.charAt(b) + hexChars.charAt(a);
		return hex;
	}

	this.thai = function(s){
		s2='';
		for(var i=0;i<s.length;i++)
		{
			if (s.charCodeAt(i)>3423) {
				n=s.charCodeAt(i)-3424;
				s2+='%'+this.Dec2Hex(n);
			}
			else s2+=s.charAt(i);
		}	// end 
		//alert("s2 = " + s2); 
		return s2; 
	} 
}
