/*  Ajax  */
var xmlhttp

function Inint_AJAX () {
  var xmlhttp = false;
  try {
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  } catch(e) {
    try {
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    } catch(e) {
      xmlhttp = false;
    }
  }

  if(!xmlhttp && document.createElement){
    xmlhttp = new XMLHttpRequest();
  }
  return xmlhttp;
}

function startCallback() {
  if (xmlhttp.readyState == 4) {
    if (xmlhttp.status == 200) { 
      document.getElementById("time").innerHTML=xmlhttp.responseText; //รับค่ากลับมา
      
      delete xmlhttp;
      setTimeout("doStart()", 1000);
    }
  }
}

function doStart() {
  xmlhttp = Inint_AJAX();
  var url = "time.php";
  xmlhttp.open("GET", url, true);
  xmlhttp.onreadystatechange = startCallback;
  xmlhttp.send(null);
}
/* End Ajax */

/* Open new Windows */
function newwin(URLStr,width, height)
{
	  var popUpWin=0;
	  var left = (screen.width/2) - width/2;
	  var top = (screen.height/2) - height/2;
	  if(popUpWin)
	  {
		  if(!popUpWin.closed) popUpWin.close();
	   }
	   popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menub ar=no,scrollbar=no,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}
/* Begin of auto size for pupop ------------------------------------------------------- */
function resize(img)
{
	  foto1= new Image();
	  foto1.src=(img);
	  Controlla(img);
}
function Controlla(img)
{
	  if((foto1.width!=0)&&(foto1.height!=0))
	  {
			viewFoto(img);
	  }
	  else
	  {
			funzione="Controlla('"+img+"')";
			intervallo=setTimeout(funzione,20);
	  }
}
function viewFoto(img)
{
	  var finestra=0;
	  var largh=foto1.width+20;
	  var altez=foto1.height+20;	 
	  var left=(screen. largh/2)-largh/2;
	  var top=(screen.altez/2)-altez/2;
	  var stringa="toolbar=no,location=no,directories=no,status=no,menub ar=no,scrollbar=no,resizable=yes,copyhistory=yes,width="+largh+",height="+altez+"left="+left+", top="+top+",screenX="+left+",screenY="+top+"";
	  finestra=open(img,"",stringa);
}
/* end of auto size for pupop ------------------------------------------------------- */

function checkAll(field)
{
  for(i = 0; i < field.elements.length; i++)
     field[i].checked = true ;
}

function uncheckAll(field)
{
 for(i = 0; i < field.elements.length; i++)
    field[i].checked = false ;
}

function Confirm(link,text) 
{
  if (confirm(text))
     window.location=link
}

  function delConfirm(obj){
	var status=false;
	for(var i=0 ; i < obj.elements.length ; i++ ){
		if(obj[i].type=='checkbox'){
			if(obj[i].checked==true){
				status=true;
			}
		}
	}
	if(status==false){
		alert('กรุณาเลือกข้อมูลที่ต้องการลบ.');
		return false;
	}else{
		if(confirm('คุณต้องการลบรายการข้อมูล นี้หรือไม่ ?')){
			return true;
		}else{
			return false;
		}
	}
}

/*Jump Menu  */
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

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_jumpMenuGo(selName,targ,restore){ //v3.0
  var selObj = MM_findObj(selName); if (selObj) MM_jumpMenu(targ,selObj,restore);
}
//-->
/* การแสดง Submenu */
function getposOffset(overlay, offsettype){
  var totaloffset = (offsettype == "left")? overlay.offsetLeft : overlay.offsetTop
  var parentEl = overlay.offsetParent
  while (parentEl != null) {
    totaloffset = (offsettype == "left")? totaloffset + parentEl.offsetLeft : totaloffset + parentEl.offsetTop
    parentEl = parentEl.offsetParent
  }
  return totaloffset
}

var menutimedelay = 0
var menudisplay = ""

function menuoverlay(curobj, subobjstr) {
  if (document.getElementById) {
    if (menudisplay != "" & menudisplay != subobjstr) document.getElementById(menudisplay).style.visibility = "hidden"
    menudisplay = subobjstr
    var subobj = document.getElementById(subobjstr)
    subobj.style.visibility = "visible"
    var xpos = getposOffset(curobj, "left")
    var ypos = getposOffset(curobj, "top")
     /* คำนวณตำแหน่งของเมนูตรงกับด้านล่าง-ซ้าย */
    subobj.style.left = xpos + (-10) + "px"
    subobj.style.top = ypos + curobj.offsetHeight + 4 + "px"
    return false
  }
}
function menudelayHide(lyr) {
  menutimedelay = setTimeout('document.getElementById("'+lyr+'").style.visibility="hidden"', 250)
}
function menuMouseover(lyr) {
  if (menutimedelay > 0) clearTimeout(menutimedelay)
}
function menuHide(lyr) {
  document.getElementById(lyr).style.visibility = "hidden"
}
// End Submenu --->

/* แสดง การคลิก เปิด/ปิด ซ่อนตาราง----------------------*/
function toggle(obj,obj2) {
	var el = document.getElementById(obj);
	var el2 = document.getElementById(obj2);
	if ( el.style.display != 'none' ) {
		el.style.display = 'none';
	}
	else {
		el.style.display = '';
		el2.style.display = 'none';
	}
}
/* end การคลิก เปิด/ปิด ซ่อนตาราง -----------------------*/

// JavaScript Document popup
	function popup(URLStr,width,height)
	{
			  var popUpWin=0;
			  var left = (screen.width/2) - width/2;
			  var top = (screen.height/2) - height/2;
			
				  if(popUpWin)
					  {
						if(!popUpWin.closed) popUpWin.close();
					  }
			  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
			  popUpWin.focus();return false;
	}
	function RELOAD(xtime)
	{
	   window.opener.location.reload();
	   setTimeout("self.close()",xtime);
	}

	/* function close windows auto */
	function AUTO_CLOSE(xtime)
	{
	   setTimeout("self.close()",xtime);
	}

