//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// PongPan AJAX 1.1 (Get and Post Method) 																												//
// Create date 19 July 2006																																//
// Last update 31 July 2006 : Add startRequestIframe() function for fix startRequestPost() can't send file object
// Author Pongpan Pattanapison																															//
//------------------------------------------------------------------------------------------------------------------------------------------------------//
// Public Function (Function for End User)																												//
// - startRequest(divname,getstr) is java script Ajax Function. This function send data to server by GET Method (query string)							//
//       |- divname is Dinamic content id (id Tag of HTML) to change by Ajax 																			//
//       |- getstr is Server side script (file and qurey string)																						//
// 																																						//
// - startRequestPost(divname,actionTxt,divOK,textOK) is javascript Ajax Function. This function send data to server by Post (All Data in forms[0])		//
//       |- divname is Dinamic content id (id Tag of HTML) to change by Ajax 																			//
//       |- actionTxt is Server side script file destination to post data (HTML Form Action). (With this function You can change form action on fly)	//
//       |- divOK is id of HTML Tag for change content in Server send back "OK" 																		//
//       |- textOK is Text Meaasge for show when Server side process Complete (Server send back "OK")													//
// - startRequestIframe(divname,srcfile,fwidth,fheight) is javascript for add iframe. This function use for send file obj								//
//		 |- divname is Dinamic content id (id Tag of HTML) to change by Ajax																			//
//		 |- srcfile is source file put in iframe																										//
//		 |- fwidth is  width of iframe																													//
//		 |- fheight is height of iframe																													//
//																																						//
//------------------------------------------------------------------------------------------------------------------------------------------------------//
//																																						//
// LAO TELECOM Copy Right.
//																																						//
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    var xmlHttp;

	function createXMLHttpRequest() {
	     if (window.ActiveXObject) {
		    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		 } 
		else if (window.XMLHttpRequest) {
			 xmlHttp = new XMLHttpRequest();
		 }
	}
	
// GET AJAX	
	function startRequest(divname,getstr) {
		//document.getElementById(divname).innerHTML = "<font color='#666666'>Loading Data....</font>";
		document.getElementById(divname).innerHTML = "<div align='center'>Loading&nbsp;<img src=wait.gif width='90' height='12' /></div>";
	    createXMLHttpRequest();
        //var sText = document.getElementById(para1).value;
        xmlHttp.open("get", getstr, true);
        xmlHttp.onreadystatechange = function () {
           if (xmlHttp.readyState == 4) {
               if (xmlHttp.status == 200) {
                   displayInfo(xmlHttp.responseText,divname);
               } else {
                   displayInfo("error" + xmlHttp.statusText,divname); 
               }
           }            
        };
       xmlHttp.send(null);
    }
        
    function displayInfo(resultText,divname) {
       document.getElementById(divname).innerHTML = resultText;
			 
    }
// End Get
// POST AJAX
     function startRequestPost(divname,actionTxt,divOK,textOK) {
		 //document.getElementById(divname).innerHTML = "<font color='#666666'>Post Data....</font>";
		 document.getElementById(divname).innerHTML = "<div align='center'>Post Data&nbsp;<img src=wait.gif width='90' height='12' /></div>";
		   createXMLHttpRequest();
            var pForm = document.forms[0];
            var pBody = getRequestBody(pForm);                
            xmlHttp.open("post", actionTxt, true);
            xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            
            xmlHttp.onreadystatechange = function () {
                if (xmlHttp.readyState == 4) {
					if (xmlHttp.status == 200) {
						if (xmlHttp.responseText == 'OK') {
							displayInfo(textOK,divOK);
						} else {
	                   		displayInfo(xmlHttp.responseText,divname);
						}
    	           } else {
        	           displayInfo("error" + xmlHttp.statusText,divname); 
            	   }
                }            
            };
            xmlHttp.send(pBody);        
        }
        
        function getRequestBody(pForm) {
            var nParams = new Array();
            
            for (var i=0 ; i < pForm.elements.length; i++) {
                var pParam = encodeURIComponent(pForm.elements[i].name);
                pParam += "=";
                pParam += encodeURIComponent(pForm.elements[i].value);
                nParams.push(pParam);
            } 
            
            return nParams.join("&");        
        }
		
//end POST
// Iframe
     function startRequestIframe(divname,srcfile,fwidth,fheight) {
		 document.getElementById(divname).innerHTML = "<iframe src=" + srcfile + " name='ppiframe' width="+ fwidth +" height="+ fheight +" scrolling='no'></iframe>";
        }		
//end Iframe

