// JavaScript Document
function loadFunc(){
	
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function logoutData(){//logOut Function
	if(window.confirm("คุณต้องการออกจากระบบ ?")){
		location.href="../thm/logout.php";
	}
}
//-------------Ajax Core------------------------------------------------------
function GetXmlHttpObject(){
	var xmlHttp=null;
	try{
 		// Firefox, Opera 8.0+, Safari
 		xmlHttp=new XMLHttpRequest();
 	}catch (e){
 		//Internet Explorer
 		try {
  			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  		}catch (e){
  			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  		}
 	}
	
	return xmlHttp;
	
}
//------------------------------------------------------------------------------
function isNumber(string1){
	if(parseInt(string1,10)){
		return false;
	}else{
		return true;
	}
}
	
function IsNumeric(sText){
	var ValidChars = "0123456789";
	var IsNumber=true;
	var Char;
	 
	for (i = 0; i < sText.length && IsNumber == true; i++){ 
	      Char = sText.charAt(i); 
	      if (ValidChars.indexOf(Char) == -1){
	         IsNumber = false;
	      }
	}
	return IsNumber;
	   
}

function disableEnterKey(e){
     var key;      
     if(window.event)
          key = window.event.keyCode; //IE
     else
          key = e.which; //firefox      

     return (key != 13);
}

var CHkey=1;
var timeout=10000;
var setTO="";

function openCH(id){
	//if(CHkey==1){
		$("#apGm"+id).fadeIn("slow");
		closeCH2(id);
		CHkey=2;
		if(setTO!=""){
		window.clearTimeout(setTO);
		}
		timeCH();
	/*}else{
		$("#mnDiv").fadeOut("slow");
		CHkey=1;
		if(setTO!=""){
			window.clearTimeout(setTO);
		}
	}*/
}

function timeCH(){
	if(CHkey==2){
		setTO=window.setTimeout(closeCH, timeout);	
	}
}

function closeCH(){
	$("#apGm1").fadeOut("slow");
	$("#apGm2").fadeOut("slow");
	$("#apGm3").fadeOut("slow");
	$("#apGm4").fadeOut("slow");
	$("#apGm5").fadeOut("slow");
	$("#apGm7").fadeOut("slow");
	$("#apGm8").fadeOut("slow");
	CHkey=1;
}

function closeCH2(id){
	if(id!=1){
		$("#apGm1").fadeOut("slow");
	}
	if(id!=2){
		$("#apGm2").fadeOut("slow");
	}
	if(id!=3){
		$("#apGm3").fadeOut("slow");
	}
	if(id!=4){
		$("#apGm4").fadeOut("slow");
	}
	if(id!=5){
		$("#apGm5").fadeOut("slow");
	}
	if(id!=7){
		$("#apGm7").fadeOut("slow");
	}
	if(id!=8){
		$("#apGm8").fadeOut("slow");
	}
	CHkey=1;
}

//-------------------------------------------------------------------------------------
function prevCalendar(){//Prev Calendar
	var year=parseInt(document.liveFrom.year.value);
	var month=parseInt(document.liveFrom.month.value);
	if(month==1){
		month=12;
		document.liveFrom.month.value=month;
		year-=1;
		document.liveFrom.year.value=year;
	
	}else if(month<=12){
		month-=1;
		document.liveFrom.month.value=month;
	}
	
	xmlcal=GetXmlHttpObject();
	if (xmlcal==null){
 		alert ("Browser does not support HTTP Request");
 		return;
 	}
	
	var url="../thm/cld.php";
	url=url+"?year="+year+"&month="+month;
	url=url+"&ev=pv&cnm=1&sid="+Math.random();
	//alert(url);
	xmlcal.onreadystatechange=function(){
		if(xmlcal.readyState==4 || xmlcal.readyState=="complete"){
			//alert(xmlUser.responseText);
			document.getElementById("cldBox").innerHTML=xmlcal.responseText;
 		}
	};
	xmlcal.open("GET",url,true);
	xmlcal.send(null);
}

function nextCalendar(){//Prev Calendar
	var year=parseInt(document.liveFrom.year.value);
	var month=parseInt(document.liveFrom.month.value);
	if(month<12){
		month+=1;
		document.liveFrom.month.value=month;
	}else if(month==12){
		month=1;
		document.liveFrom.month.value=month;
		year+=1;
		document.liveFrom.year.value=year;
	}
	
	xmlcal=GetXmlHttpObject();
	if (xmlcal==null){
 		alert ("Browser does not support HTTP Request");
 		return;
 	}
	
	var url="../thm/cld.php";
	url=url+"?year="+year+"&month="+month;
	url=url+"&ev=pv&cnm=1&sid="+Math.random();
	//alert(url);
	xmlcal.onreadystatechange=function(){
		if(xmlcal.readyState==4 || xmlcal.readyState=="complete"){
			//alert(xmlUser.responseText);
			document.getElementById("cldBox").innerHTML=xmlcal.responseText;
 		}
	};
	xmlcal.open("GET",url,true);
	xmlcal.send(null);
}

function setDay(day){
	document.liveFrom.submit();
}

function prevEvCalendar(){//Prev Calendar
	var year=parseInt(document.liveFrom.year.value);
	var month=parseInt(document.liveFrom.month.value);
	var gId=parseInt(document.liveFrom.gId.value);
	if(month==1){
		month=12;
		document.liveFrom.month.value=month;
		year-=1;
		document.liveFrom.year.value=year;
	
	}else if(month<=12){
		month-=1;
		document.liveFrom.month.value=month;
	}
	
	xmlcal=GetXmlHttpObject();
	if (xmlcal==null){
 		alert ("Browser does not support HTTP Request");
 		return;
 	}
	
	var url="../thm/evcld.php";
	url=url+"?year="+year+"&month="+month+"&gId="+gId;
	url=url+"&ev=pv&cnm=1&sid="+Math.random();
	//alert(url);
	xmlcal.onreadystatechange=function(){
		if(xmlcal.readyState==4 || xmlcal.readyState=="complete"){
			//alert(xmlUser.responseText);
			document.getElementById("evlBox").innerHTML=xmlcal.responseText;
 		}
	};
	xmlcal.open("GET",url,true);
	xmlcal.send(null);
}

function nextEvCalendar(){//Prev Calendar
	var year=parseInt(document.liveFrom.year.value);
	var month=parseInt(document.liveFrom.month.value);
	var gId=parseInt(document.liveFrom.gId.value);
	if(month<12){
		month+=1;
		document.liveFrom.month.value=month;
	}else if(month==12){
		month=1;
		document.liveFrom.month.value=month;
		year+=1;
		document.liveFrom.year.value=year;
	}
	
	xmlcal=GetXmlHttpObject();
	if (xmlcal==null){
 		alert ("Browser does not support HTTP Request");
 		return;
 	}
	
	var url="../thm/evcld.php";
	url=url+"?year="+year+"&month="+month+"&gId="+gId;
	url=url+"&ev=pv&cnm=1&sid="+Math.random();
	//alert(url);
	xmlcal.onreadystatechange=function(){
		if(xmlcal.readyState==4 || xmlcal.readyState=="complete"){
			//alert(xmlUser.responseText);
			document.getElementById("evlBox").innerHTML=xmlcal.responseText;
 		}
	};
	xmlcal.open("GET",url,true);
	xmlcal.send(null);
}
