	var xmlHttp;
	var waitbar = "<center><img src='http://www.satangsoft.net/waitbar.gif' align='absmiddle'><img src='http://www.satangsoft.net/waitbar.gif' align='absmiddle'><br><font color='#3399FF' size='2'>กรุณารอสักครู่...กำลังโหลดข้อมูล... ^_^</font></center>";
	var waittitle = "<center><img src='http://www.satangsoft.net/waitbar.gif' align='absmiddle'></center>";
	var mainurl = "http://www.satangsoft.com/lms3/";
	// 
	window.onerror = function(){ return true;}

	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);        
        }
		
		function doFile(Vr, DIV) {
		    createXMLHttpRequest();
			var divStatus = document.getElementById(DIV);
            xmlHttp.open("GET", "_.php?"+Vr, true);
            xmlHttp.onreadystatechange = function () {
                if (xmlHttp.readyState == 4) {
                    if (xmlHttp.status == 200) {
						divStatus.innerHTML = xmlHttp.responseText;
						document.all[DIV].style.visibility="visible"
                    } else {
                       divStatus.innerHTML = "พบข้อผิดพลาด ไม่สามารถแสดงข้อมูลได้";
                    }
                } else {
						divStatus.innerHTML = waitbar;
				}
            };
            xmlHttp.send(null);
        }
		
		function doUrl(Vr, DIV) {
		    createXMLHttpRequest();
			var divStatus = document.getElementById(DIV);
            xmlHttp.open("GET", "_.php?"+Vr, true);
            xmlHttp.onreadystatechange = function () {
                if (xmlHttp.readyState == 4) {
                    if (xmlHttp.status == 200) {
						divStatus.innerHTML = xmlHttp.responseText;
						fadetoview(DIV);  //FadeIn
                    } else {
                       divStatus.innerHTML = "พบข้อผิดพลาด ไม่สามารถแสดงข้อมูลได้";
                    }
                } 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("&");        
        }
		
//	function hidestatus(){
	//	window.status=''
//		return true
//	}
//	if (document.layers)
//	document.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT)
//	document.onmouseover=hidestatus
//	document.onmouseout=hidestatus
//	document.onclick=hidestatus

// ========== Fade DIV =====================
	function fadetoview(objname){
		var objholder=document.getElementById(objname)
		objholder.filters[0].apply()
		objholder.style.visibility="visible"
		objholder.filters[0].play()
	}

//=========== Show DIV ====================
	function showL(url, ob, width, height){
		doFile(url, ob);
		//p ตำแหน่ง  0=ในตำแหน่งที่เม้าท์ชี้  |  1=กลางจอ
		var winwidth = 0, winheight = 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);
		height =  parseInt(height);
		width =  parseInt(width);
		
		var top = (winheight-height)/2;
		var left = (winwidth-width)/2;
		
		if (width>950){ width=950; }
		if (height>500){ height=500; }
		
		if((left+width)>winwidth){  // ถ้ามีความกว้างเกินกว่าหน้าจอ
			left = left-(((left+width) - winwidth)+30);
		}
		
		if((top+height)>winheight){  // ถ้าสูงเกินหน้าจอ
			top = top-((top+height) - winheight);
		}
		
		//document.all[ob].style.visibility = "visible";
		document.all[ob].style.left = left + "px";
		document.all[ob].style.top = top + "px";
		document.all[ob].style.width = width + "px";
		document.all[ob].style.height = height + "px";
		
//		document.all[ob].style.backgroundColor = "#FFFFFF";
	}
	
	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,'','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,'newwindow','toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width='+winwidth+',height='+winheight);
	}
	
	// Carlendar ===========================================================================
	function goLastMonth(month,year,form,field) 
    { 
        // If the month is January, decrement the year. 
        if(month == 1) 
    { 
    --year; 
    month = 13; 
    }        
        doFile('fls=calendar&month='+(month-1)+'&year='+year+'&field='+field,'pop'); 
    } 
    
    function goNextMonth(month,year,form,field) 
    { 
        // If the month is December, increment the year. 
        if(month == 12) 
    { 
    ++year; 
    month = 0; 
    }    
        doFile('fls=calendar&month='+(month+1)+'&year='+year+'&field='+field,'pop'); 
    } 
    
    function sendToForm(val,field) 
    { 
		eval("document.all." + field + ".value='" + val + "'"); 
        hideL('pop'); 
    } 
	
	// Function สร้างเฉพาะ =====================================================================
	
	function showtitle(txt){
		document.getElementById("tbtitle").innerHTML = "<font color='#FFFFFF' size='2'><b>"+txt+"</b></font>";	
	}
	
	// Function LMS =========================================================================
	function showLMS(theme, id){
		var ob = "lmsshow";
		var ob2 = "lmszone";
		document.getElementById(ob2).innerHTML = '<table width="800" height="550" border="0" cellpadding="0" cellspacing="0"><tr><td height="23"><div align="center"><table width="100%" height="23" border="0" cellpadding="0" cellspacing="0"><tr><td align="left"><a href="http://www.satangsoft.com/lms3/" target="_blank"><img src="'+mainurl+'img/satanglmslogo.gif" border="0" alt="Satangsoft.COM" align="absmiddle" /></a><font color="#FFFFFF" size="2"><b> E-Learning Management System 2008</b></font></td><td width="74"><a href="javascript:onclick=hideLMS();"><img src="'+mainurl+'img/close.gif" border="0" alt="ปิดหน้านี้" align="absmiddle" /></a></td></tr></table></div></td></tr><tr><td height="1" bgcolor="#999999"></td></tr><tr height="526"><td><iframe frameborder="0" marginheight="0" marginwidth="0" style="border:0; height:526px; width:100%" scrolling="no" src="'+mainurl+'index.php?theme='+theme+'&id='+id+'"></iframe></td></tr></table>';
		var winwidth = 0, winheight = 0;
		  if( typeof( window.innerWidth ) == 'number' ) {
			//Non-IE
			winwidth = window.innerWidth;
			winheight = window.innerHeight;
			var docheight = window.innerHeight;
			//alert('Non-IE');
		  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			//IE 6+ in 'standards compliant mode'
			winwidth = document.documentElement.clientWidth;
			winheight = document.documentElement.clientHeight;
			var docheight = document.body.clientHeight;
			//alert('IE 6+ in');
		  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
			//IE 4 compatible
			winwidth = document.body.clientWidth;
			winheight = document.body.clientHeight;
			var docheight = document.body.clientHeight;
			//alert('IE 4 compatible');
		  }

		winwidth =  parseInt(winwidth);
		winheight =  parseInt(winheight);
		docheight =  parseInt(docheight);
		
		if(docheight<550){
			docheight = winheight;
		}
				
		document.all[ob].style.visibility = "visible";
		document.all[ob].style.left = "0px";
		document.all[ob].style.top = "0px";
		document.all[ob].style.width = winwidth + "px";
		document.all[ob].style.height = docheight + "px";
		
		// เปิดไฟล์ LMS
		var top = (winheight-550)/2;
		var left = (winwidth-800)/2;
		fadetoview(ob2);  //FadeIn
		document.all[ob2].style.left = left+"px";
		document.all[ob2].style.top = top+"px";
		document.all[ob2].style.width = "800px";
		document.all[ob2].style.height = "550px";
	}
		
	function hideLMS(){
		document.all['lmsshow'].style.visibility = 'hidden';
		document.all['lmszone'].style.visibility = 'hidden';
	}
	
	document.write('<div id="lmsshow" style="position:absolute; overflow:hidden; filter :alpha(opacity=50); -moz-opacity: .50; z-index:10; background-color:#333333"; visibility:hidden"></div>');
	document.write('<div id="lmszone" style="position:absolute; overflow:hidden; filter:progid:DXImageTransform.Microsoft.Fade(duration=1); z-index:11; visibility:hidden;"></div>');