// JavaScript Document
function Inint_AJAX() {
	try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {} //IE
	try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {} //IE
	try { return new XMLHttpRequest(); } catch(e) {} //Native Javascript
	alert("XMLHttpRequest not supported")
	return null
}

function getModule(modules) {
	document.getElementById(modules).innerHTML='<div id="wait">กำลังโหลด...</div>';
	var req = Inint_AJAX();
	var strRand = Math.random();
	queryURL = 'modules/main/'+modules+'.php?rand='+strRand 
	req.open('GET', queryURL, true);
	req.onreadystatechange = function() {
		if (req.readyState==4) {
			if (req.status==200) {
				var data=req.responseText;
				document.getElementById(modules).innerHTML=data;
			}
		}
	};
	req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	req.send(null);
};

function getModules(modules,section) {
	document.getElementById(section).innerHTML='<div id="wait">กำลังโหลด...</div>';
	var req = Inint_AJAX();
	var strRand = Math.random();
	queryURL = 'modules/main/'+modules+'.php?rand='+strRand 
	req.open('GET', queryURL, true);
	req.onreadystatechange = function() {
		if (req.readyState==4) {
			if (req.status==200) {
				var data=req.responseText;
				document.getElementById(section).innerHTML=data;
			}
		}
	};
	req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	req.send(null);
};

function getCallBack(modules,section,time) {
	var countTime=time;
	var codeVal="getCallBackModules('"+modules+"','"+section+"','"+time+"')";
	setTimeout(codeVal,countTime);
}

function getAutoModules(modules,section,time) {
	document.getElementById(section).innerHTML='<div id="wait">กำลังโหลด...</div>';
	var req = Inint_AJAX();
	var strRand = Math.random();
	queryURL = 'modules/mod.'+modules+'.php?rand='+strRand 
	req.open('GET', queryURL, true);
	req.onreadystatechange = function() {
		if (req.readyState==4) {
			if (req.status==200) {
				var data=req.responseText;
				document.getElementById(section).innerHTML=data;
				getCallBack(modules,section,time)
			}
		}
	};
	req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	req.send(null);
};
function getCallBackModules(modules,section,time) {
	var req = Inint_AJAX();
	var strRand = Math.random();
	queryURL = 'modules/mod.'+modules+'.php?rand='+strRand
	req.open('GET', queryURL, true);
	req.onreadystatechange = function() {
		if (req.readyState==4) {
			if (req.status==200) {
				var data=req.responseText;
				document.getElementById(section).innerHTML=data;
				getCallBack(modules,section,time)
			}
		}
	};
	req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	req.send(null);
};

function loadNews(section) {
	var req = Inint_AJAX()
     req.onreadystatechange = function () { 
          if (req.readyState==4) {
               if (req.status==200) {
                    var obj = document.getElementById(section)
                    obj.style.backgroundImage  = "url()"
                    obj.style.height='auto'
                    obj.innerHTML = req.responseText
               } 
          } 
     }
     req.open("POST", "modules/mod.Reader.php", true)
     req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
     req.send("rssURL=http://www.rssthai.com/rss/it.xml")
}

function callBack(modules,section,time) {
	var countTime=time;
	var codeVal="callBackModules('"+modules+"','"+section+"','"+time+"')";
	setTimeout(codeVal,countTime);
}

function autoModules(modules,section,time) {
	document.getElementById(section).innerHTML='<div id="wait">กำลังโหลด...</div>';
	var req = Inint_AJAX();
	var strRand = Math.random();
	queryURL = '../modules/mod.'+modules+'.php?rand='+strRand 
	req.open('GET', queryURL, true);
	req.onreadystatechange = function() {
		if (req.readyState==4) {
			if (req.status==200) {
				var data=req.responseText;
				document.getElementById(section).innerHTML=data;
				callBack(modules,section,time)
			}
		}
	};
	req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	req.send(null);
};
function callBackModules(modules,section,time) {
	var req = Inint_AJAX();
	var strRand = Math.random();
	queryURL = '../modules/mod.'+modules+'.php?rand='+strRand
	req.open('GET', queryURL, true);
	req.onreadystatechange = function() {
		if (req.readyState==4) {
			if (req.status==200) {
				var data=req.responseText;
				document.getElementById(section).innerHTML=data;
				callBack(modules,section,time)
			}
		}
	};
	req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	req.send(null);
};

function module(modules) {
	document.getElementById(modules).innerHTML='<div id="wait">กำลังโหลด...</div>';
	var req = Inint_AJAX();
	var strRand = Math.random();
	queryURL = '../modules/main/'+modules+'.php?rand='+strRand 
	req.open('GET', queryURL, true);
	req.onreadystatechange = function() {
		if (req.readyState==4) {
			if (req.status==200) {
				var data=req.responseText;
				document.getElementById(modules).innerHTML=data;
			}
		}
	};
	req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	req.send(null);
};

function modules(modules,section) {
	document.getElementById(section).innerHTML='<div id="wait">กำลังโหลด...</div>';
	var req = Inint_AJAX();
	var strRand = Math.random();
	queryURL = '../modules/main/'+modules+'.php?rand='+strRand 
	req.open('GET', queryURL, true);
	req.onreadystatechange = function() {
		if (req.readyState==4) {
			if (req.status==200) {
				var data=req.responseText;
				document.getElementById(section).innerHTML=data;
			}
		}
	};
	req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	req.send(null);
};














function displayContent(sID) {
	oObj = document.getElementById(sID);
	if (oObj) {
		oObj.style.display='inherit';
	}
}
function hideContent(sID) {
	oObj = document.getElementById(sID);
	if (oObj) {
		oObj.style.display='none';
	}
}
function getLoginPanel(id){
	for (i=1;i<=2;i++)
	{
		if (id == i)
		{
			displayContent("loginShow"+i);
      		document.getElementById("loginBox"+i).className		 ='loginBox_Active';
		}else{
			hideContent("loginShow"+i);
      		document.getElementById("loginBox"+i).className		 ='loginBox_Inactive';
		}
	}
}

function checkDirectAdmin() {
var inputUsername = document.formDirect.username
var inputPassword = document.formDirect.password

if (inputUsername.value == '') {
	alert('ข้อผิดพลาด : กรุณาระบุชื่อผู้ใช้')
	inputUsername.focus()
	return false
} else
	if (inputPassword.value == '') {
	alert('ข้อผิดพลาด : กรุณาระบุรหัสผ่าน')
	inputPassword.focus()
	return false
} else
	return true
}