<!--
function msg_status(msg) { window.status=(msg); return true;}
function sbar (st) { st.style.backgroundColor = '#C6F8FE'; }
function sbaratom (st) { st.style.backgroundColor = '#C6F8FE';}
function sbaratomII (st) { st.style.backgroundColor = '#C6F8FE'; }
function sbar3 (st) { st.style.backgroundColor = '#C6F8FE'; }
function sbar4 (st) { st.style.backgroundColor = '#C6F8FE'; }
function cbar (st) { st.style.backgroundColor = '#C6F8FE'; }
function cmt_sbar (st) { st.style.backgroundColor = ''; }
function cmt_cbar (st) { st.style.backgroundColor = ''; }
function mail(email) {
	popUpWin = window.open('http://3mail.superboard.com/mail.cgi?tmail='+email,'','width=335,height=345');
	return false;
}

// LTrim(string) : Returns a copy of a string without leading spaces.
function ltrim(str)
{
   var whitespace = new String(" \t\n\r");
   var s = new String(str);
   if (whitespace.indexOf(s.charAt(0)) != -1) {
      var j=0, i = s.length;
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;
      s = s.substring(j, i);
   }
   return s;
   
}

//RTrim(string) : Returns a copy of a string without trailing spaces.
function rtrim(str)
{
   var whitespace = new String(" \t\n\r");
   var s = new String(str);
   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
      var i = s.length - 1;       // Get length of string
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;
      s = s.substring(0, i+1);
   }
   return s;
}

// Trim(string) : Returns a copy of a string without leading or trailing spaces
function trim(str) {
   return rtrim(ltrim(str));
}

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

function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features).focus();
}
<!--
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_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_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 addToFavorite(favTitle){
  if ((navigator.appVersion.indexOf("MSIE") > 0) && (parseInt(navigator.appVersion) >= 4)) {
    window.external.AddFavorite(location.href, unescape(favTitle));
  }
}

/* ajax template */
var EsAJaxhttp = false;
function EsAJax(url) {
  var today=new Date();
  var getdate=today.getTime();
  url=String(url)+String(String(url).indexOf('?')>0 ? "&" : "?")+'ranid='+ String(Math.ceil(Math.random()*getdate));

  var result;
  if (!EsAJaxhttp) {
    if (window.XMLHttpRequest) 
      EsAJaxhttp = new XMLHttpRequest();
    else if (window.ActiveXObject)
      EsAJaxhttp = new ActiveXObject("Microsoft.XMLHTTP");
  }
  EsAJaxhttp.open("GET", url, false);
  EsAJaxhttp.send(null);
  result = EsAJaxhttp.responseText;
//alert('body:' + EsAJaxhttp.responseText);
  return(result);
}
function chk_pid(tmpidno){
	if(tmpidno!=""){
		var tmpresult=EsAJax('../config/pid_check.php?id='+tmpidno);
		if(tmpresult !="1"){
			var conf= confirm('เลขที่บัตรประจำตัวประชาชนไม่ถูกต้อง คุณต้องการจัดเก็บข้อมูลใช่หรือไม่ ?\nกดปุ่ม OK เพื่อจัดเก็บข้อมูล\nกดปุ่ม Cancel เพื่อแก้ไข');
			if(conf){
				return true;
			}else{
				return false;
			}
		}else{
		    return true;
		}
	}
}
//วันที่ช่องเดียวกัน
function thaimonth(val){
		chkval=val.substr(0,1);
		if(chkval=='0'){
			val=val.substr(1,1);
		}
			var month=new Array("","มกราคม ","กุมภาพันธ์ ","มีนาคม ","เมษายน ","พฤษภาคม ","มิถุนายน ",
							"กรกฏาคม ","สิงหาคม ","กันยายน ","ตุลาคม ","พฤศจิกายน ","ธันวาคม ");
			newval=month[val];
			return(newval);
}
function chkdateval(idval,saveval){
			valthis=document.getElementById(idval).value;
			len=document.getElementById(idval).value.length;
			//ครบ 8 ตัว
				if(len==4|| len==6 || len==8 ){
					//ตัวเลขหรือไม่
							if (isNaN(valthis)) {
									alert("กรุณา กรอกข้อมูลเป็นตัวเลข");
									document.getElementById(idval).select();
									document.getElementById(idval).focus();
									return false;
							 }
							 if(len==4){
									date='00';
									WhichMonth='00';
									year=valthis;
							 }else if(len==6){
									date='00';
									WhichMonth=valthis.substr(0,2);
									year=valthis.substr(2,4);							
							 }else{
									date=valthis.substr(0,2);
									WhichMonth=valthis.substr(2,2);
									year=valthis.substr(4,4);
							}							
							//ค่าของวันที่มาก
							if (WhichMonth == "04" || WhichMonth == "06" || WhichMonth == "09" || WhichMonth == "11"){
									DaysInMonth = 30;
							}else if (WhichMonth == "02"){	
									DaysInMonth = 29;
							}else{
									DaysInMonth = 31;
							}
							//วันที่ถูกหรือไม่
							if(date > DaysInMonth){
									alert('วันที่มีค่าระหว่าง 00-'+DaysInMonth);
									document.getElementById(idval).focus();
									return false;									
							}
							//เดือน
							if (WhichMonth >12){
									alert('เดือนมีค่าระหว่าง 00-12');
									document.getElementById(idval).focus();
									return false;
							}

								document.getElementById(saveval).value=year+WhichMonth+date;
									valmonth=thaimonth(WhichMonth);								
									if(date=='00'){
										date='';
									}else{
										if(date.substr(0,1)=='0'){
											date=date.substr(1,1);
										}
										date=date+' ';
									}																
									newval=date+valmonth+year;
									document.getElementById(idval).value=newval;
									return true;
				}else{
								if(len !=""){
										alert("กรอกข้อมูลให้ครบ 8 หรือ 6 หรือ 4 หลัก\n( รูปแบบ : ddmmyyyy, mmyyyy, yyyy)");
										document.getElementById(idval).select();
										return false;
								 }else{
										 document.getElementById(saveval).value='';
										 return false;
								 }
					}
	}
	function changvaldate(idval,saveval){ 
			var valthis=document.getElementById(saveval).value;
			var valsave=document.getElementById(saveval).value;
			var len=document.getElementById(saveval).value.length;

							 if(len==8){							 
									var date=valthis.substr(6,2);
									var WhichMonth=valthis.substr(4,2);
									var year=valthis.substr(0,4);
									document.getElementById(saveval).value=year+WhichMonth+date;
									if(date=='00'){
										date='';
									}
									if(WhichMonth=='00'){
											WhichMonth='';
									}
									document.getElementById(idval).value=date+WhichMonth+year;
									document.getElementById(idval).select();
							}	

							return;
		}


// fucnion แสดง mouse over ของ Table
<!--
function msg_status(msg) { window.status=(msg); return true;}
function sbar (st) { st.style.backgroundColor = '#CCCCCC'; }
function sbaratom (st) { st.style.backgroundColor = '#00FF99';}
function sbaratomII (st) { st.style.backgroundColor = '#CCCCCC'; }
function sbar3 (st) { st.style.backgroundColor = '#CCCCCC'; }
function sbar4 (st) { st.style.backgroundColor = '#CCCCCC'; }
function cbar (st) { st.style.backgroundColor = ''; }
function cmt_sbar (st) { st.style.backgroundColor = ''; }
function cmt_cbar (st) { st.style.backgroundColor = ''; }

// LTrim(string) : Returns a copy of a string without leading spaces.
function ltrim(str)
{
   var whitespace = new String(" \t\n\r");
   var s = new String(str);
   if (whitespace.indexOf(s.charAt(0)) != -1) {
      var j=0, i = s.length;
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;
      s = s.substring(j, i);
   }
   return s;
   
}

//RTrim(string) : Returns a copy of a string without trailing spaces.
function rtrim(str)
{
   var whitespace = new String(" \t\n\r");
   var s = new String(str);
   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
      var i = s.length - 1;       // Get length of string
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;
      s = s.substring(0, i+1);
   }
   return s;
}

// Trim(string) : Returns a copy of a string without leading or trailing spaces
function trim(str) {
   return rtrim(ltrim(str));
}

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

function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features).focus();
}
<!--
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_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_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 addToFavorite(favTitle){
  if ((navigator.appVersion.indexOf("MSIE") > 0) && (parseInt(navigator.appVersion) >= 4)) {
    window.external.AddFavorite(location.href, unescape(favTitle));
  }
}
var popUpWin=0;
function popUpWindow(URLStr, left, top, width, height)
{
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menub ar=no,scrollbars=yes,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

 function clearform(){
 for (var i = 0; i < document.forms[0].elements.length; i++) {
    			if(document.forms[0].elements[i].type == 'text'||document.forms[0].elements[i].type == 'textarea'){
				document.forms[0].elements[i].value='';
					
			}
	}
}
 function countChar(input,len) {
                if(input.value.length > len){
                input.value= input.value.substring(0,len)   
                  //alert('????????????? '+len+' ????????'); 
                  return false;
                }
} 

