	var xmlHttp;
	var waitbar = "<center><img src='waitbar.gif' align='absmiddle'><img src='waitbar.gif' align='absmiddle'><br><font color='#3399FF' size='2'>Please wait... ^_^</font></center>";
	var waittitle = "<center><img src='waitbar.gif' align='absmiddle'></center>";

	function createXMLHttpRequest() {
	 if (window.ActiveXObject) {
		    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		 } 
			else if (window.XMLHttpRequest) {
			 xmlHttp = new XMLHttpRequest();
			 }
		}

        
        function doForm(DIV) {
		   createXMLHttpRequest();
            var pForm = document.forms[0];
            var pBody = getRequestBody(pForm);       
			var divStatus = document.getElementById(DIV);
			          
            xmlHttp.open("post", pForm.action, true);
            xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            
            xmlHttp.onreadystatechange = function () {
                if (xmlHttp.readyState == 4) {
                    if (xmlHttp.status == 200) {
						fadetoview(DIV);  //FadeIn
						divStatus.innerHTML = xmlHttp.responseText;
                    } else {
                        divStatus.innerHTML = "&nbsp;<p>"+waitbar+"</p>";
                    }
                }            
            };
            xmlHttp.send(pBody);        
        }
		
		// สำหรับสั่งทำงานรอบที่ 1  Fade
		function doFile(Vr, DIV) {
		    createXMLHttpRequest();
			var divStatus = document.getElementById(DIV);
			var ran = Math.random();
			Vr += "&ran="+ran;
            xmlHttp.open("GET", "_.php?"+Vr, true);
            xmlHttp.onreadystatechange = function () {
                if (xmlHttp.readyState == 4) {
                    if (xmlHttp.status == 200) {
						fadetoview(DIV);  //FadeIn
						divStatus.innerHTML = xmlHttp.responseText;
						document.all[DIV].style.visibility="visible"
                    } else {
                       divStatus.innerHTML = "Error Not Display !";
                    }
                } else {
						divStatus.innerHTML = waitbar;
				}
            };
            xmlHttp.send(null);
        }
		
		
		// สั่งทำงานแบบไม่ Fade
		function dozone(Vr, DIV) {
		    createXMLHttpRequest();
			var divStatus = document.getElementById(DIV);
			var ran = Math.random();
			Vr += "&ran="+ran;
            xmlHttp.open("GET", "_.php?"+Vr, true);
            xmlHttp.onreadystatechange = function () {
                if (xmlHttp.readyState == 4) {
                    if (xmlHttp.status == 200) {
						divStatus.innerHTML = xmlHttp.responseText;
                    } else {
                       divStatus.innerHTML = "Error Not Display !";
                    }
                } 
            };
            xmlHttp.send(null);
        }
		
		// DIV กลางจอ
		function doUrl(Vr, DIV,w,h) {
		    createXMLHttpRequest();
			var divStatus = document.getElementById(DIV);
			var ran = Math.random();
			Vr += "&ran="+ran;
            xmlHttp.open("GET", "_.php?"+Vr, true);
			//============================== หาจุดกลางของ DIV
			  //var winwidth = 0, winheight = 0, width=0, height=0;
			  if( typeof( window.innerWidth ) == 'number' ) {
				//Non-IE
				winwidth = window.innerWidth;
				winheight = window.innerHeight;
			  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
				//IE 6+ in 'standards compliant mode'
				winwidth = document.documentElement.clientWidth;
				winheight = document.documentElement.clientHeight;
			  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
				//IE 4 compatible
				winwidth = document.body.clientWidth;
				winheight = document.body.clientHeight;
			  }
			
			winwidth =  parseInt(winwidth);
			winheight =  parseInt(winheight);
			if(w==0){ w = winwidth; } else { w = parseInt(w); }
			if(h==0){ h = winheight; } else { h = parseInt(h); }
			//หาตำแหน่งที่เม้าท์อยู่บนจอ
			var left = document.all.mouseX.value;
		    var top = document.all.mouseY.value;
			top =  parseInt(top);
			left =  parseInt(left);
			//var top = (winheight-h)/2;
			//var left = (winwidth-w)/2;
			
			if (w>950){ w=950; }
			if (h>500){ h=500; }
			
			if((left+w)>winwidth){ 
				left = left-(((left+w) - winwidth)+30);
			}
			
			//if((top+h)>winheight){ 
			//	top = top-((top+h) - winheight);
			//}
			
			top = top-150;
			left = left-(left/2);
			
			document.all[DIV].style.left = left + "px";
		    document.all[DIV].style.top = top + "px";
			document.all[DIV].style.width = w + "px";
			document.all[DIV].style.height = h + "px";
			//==========================================
            xmlHttp.onreadystatechange = function () {
                if (xmlHttp.readyState == 4) {
                    if (xmlHttp.status == 200) {
						divStatus.innerHTML = xmlHttp.responseText;
						fadetoview(DIV);  //FadeIn
                    } else {
                       divStatus.innerHTML = "Error Not Display !";
                    }
                } else {
                        divStatus.innerHTML = "&nbsp;<p>"+waitbar+"</p>";
                } 
            };
            xmlHttp.send(null);
        }
		
        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("&");        
        }
		
// ========== Fade DIV =====================
	function fadetoview(objname){
		var objholder=document.getElementById(objname)
		objholder.filters[0].apply()
		objholder.style.visibility="visible"
		objholder.filters[0].play()
	}

	function hideL(ob){
		document.all[ob].style.visibility = 'hidden';
	}
	
	function popwin(Fls, w, h , sc, res){
		var winwidth = screen.width;
		var winheight = screen.height;
		winwidth =  parseInt(winwidth);
		winheight =  parseInt(winheight);
		h =  parseInt(h);
		w =  parseInt(w);
		var top = (winheight-h)/2;
		var left = (winwidth-w)/2;
		
		window.open(Fls,'nwin','top='+top+', left='+left+', width='+w+', height='+h+', scrollbars='+sc+', resizable='+res);
	}
	
	function fullwin(Fls){
		var winwidth = screen.width;
		var winheight = screen.height;
		winwidth =  parseInt(winwidth);
		winheight =  parseInt(winheight)-27;		
		window.open(Fls,'','top=0, left=0, width='+winwidth+', height='+winheight+', scrollbars=no, resizable=no');
	}
	
	function newwindow(Fls){
		var winwidth = screen.width;
		var winheight = screen.height;
		window.open(Fls,'','toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width='+winwidth+',height='+winheight);
	}
	
	function copyit(theField) {
		var tempval=eval("document.all."+theField)
		tempval.focus()
		tempval.select()
		therange=tempval.createTextRange()
		therange.execCommand("Copy")
	}
	
	function check(V,a) {
		for (i = 0; i < a; i++) {
			var tempval=eval("document.all."+V+i)
			tempval.checked = true;
		}
	}
	
	function uncheck(V,a) {
		for (i = 0; i < a; i++) {
			var tempval=eval("document.all."+V+i)
			tempval.checked = false;
		}
	}
	
	function confirmDelete(delUrl) {
	  if (confirm("คุณต้องการลบ รายการนี้ เดี๋ยวนี้หรือไม่ ?")) {
		document.location = delUrl;
	  }
	}
	
	function confirmDel(delUrl,DIV) {  //สำหรับ AJAX
	  if (confirm("คุณต้องการลบ รายการนี้ เดี๋ยวนี้หรือไม่ ?")) {
		dozone(delUrl,DIV);
	  }
	}
	
	function delRent(delUrl) {
	  if (confirm("คุณต้องการลบ รายการนี้ เดี๋ยวนี้หรือไม่ ?")) {
		window.open(delUrl,'xData','');
	  }
	}
	
	function viewFlash(movieUrl,w,h,id,bgColor,fVars,win)
	{
		var jsFlash="<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0' width='"+w+"' height='"+h+"' id='"+id+"' align='middle'>"+
				"<param name='allowScriptAccess' value='always' />"+
				"<param name='movie' value='"+movieUrl+"' />"+
				"<param name='quality' value='high' />"+
				"<param name='FlashVars' value='"+fVars+"'/>"+
				"<param name='bgcolor' value='"+bgColor+"' />"+
				"<param name='wMode' value='"+win+"' />"+
				"<embed src='"+movieUrl+"?"+fVars+"' width='"+w+"' height='"+h+"' type='application/x-shockwave-flash' quality='high' bgcolor='#FFFFFF' allowScriptAccess='always' name='PLAYNC_FLASH_GAME' pluginspage='http://www.macromedia.com/go/getflashplayer' align='middle' /></object>";
		document.write(jsFlash);
	}
