//javascript by pom
function Popup(mypage,myname,w, h) {
				var winl = (screen.width - w) / 2;
				var wint = (screen.height - h) / 2;
				winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars=no,fullscreen=no,resizable,toolbar=no,location=no,status=no,menubar=no'
				win = window.open(mypage, myname, winprops)
				if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}
function Popup2(mypage,myname,w, h) {
				var winl = (screen.width - w) / 2;
				var wint = (screen.height - h) / 2;
				winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars=yes,fullscreen=no,resizable,toolbar=no,location=no,status=no,menubar=no'
				win = window.open(mypage, myname, winprops)
				if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}
function New_Win_NoOption2(mypage,myname,w, h) {
				var winl = (screen.width - w) / 2;
				var wint = (screen.height - h) / 2;
				winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars=yes,fullscreen=no,resizable,toolbar=no,location=no,status=no,menubar=no'
				win = window.open(mypage, myname, winprops)
				if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}
function confirmSubmit()
{
var agree=confirm("do you want to delete?");
if (agree)
	return true ;
else
	return false ;
}
function confirmSubmit2()
{
var agree=confirm("Confirm Delete");
if (agree)
	return true ;
else
	return false ;
}
function del_confirm(msg){
document.MM_returnValue=(confirm(unescape(msg)));
}
//---------------->
	function CheckAll(BackendForm,checkboxState) {
		for (a=0; a<BackendForm.elements.length; a++) {
			if (BackendForm.elements[a].id.indexOf("checkbox_") == 0) {
				BackendForm.elements[a].checked = checkboxState ;
			}
		}
	}
	function setColor_when_checked(form,checkboxState){
for(a=0;a<form.elements.length;a++){

}//end for
	}//end function setColor_when..
function chkEmail (input) 
	{
		var str=input.value;
	    var num_as = str.lastIndexOf("@");
		var num_poin = str.lastIndexOf(".");
	    if (num_as == -1 || num_poin ==-1) 
		{
		     return false; 
	    }else
		{
		   return true;
		}
   }
function checkbox_color(obj){
if(obj.checked){
hightLightOn (obj) ;
}else{
hightLightOff (obj) ;
}
}
	/* End checkbox*/
	 function hightLightOn (obj) {
       cRef = obj.style.backgroundColor;
           if (cRef != "#59acff") // สีตอน Mark
           {
                obj.style.backgroundColor = "#D2E9FF";
           }
	 }

	  function hightLightOff (obj) {
       cRef = obj.style.backgroundColor;
           if (cRef != "#59acff")  // สีตอน Mark
           {
                obj.style.backgroundColor = "#FFFFFF";
           }
	 }

	 function hightLightMark (obj) {
		 var  cRef = obj.style.backgroundColor;
		 var  c1 = "#59acff";  // สีตอน Mark
         var c2 = "#FFFFFF";   // สีตอน Mark ออก

			if (cRef == c1){
			    obj.style.backgroundColor = c2;
			}else{
			    obj.style.backgroundColor = c1;
			}
	 }

	 //------------------------------>
function CheckInputNumber(VInput){
var checkOK = ".0123456789";
var checkStr = VInput.value;
var allValid = true;
var allNum = "";
for (i = 0;  i < checkStr.length;  i++)
{
ch = checkStr.charAt(i);
for (j = 0;  j < checkOK.length;  j++)
if (ch == checkOK.charAt(j))
break;

if (j == checkOK.length)
{
allValid = false;
break;
}
if (ch != ",")
allNum += ch;
}
if (!allValid)
{
alert("Please enter only digit characters in field.");
VInput.value="";
VInput.focus();
return (false);
}
	 }
function CheckInputNumber2(VInput){
var checkOK = "0123456789";
var checkStr = VInput.value;
var allValid = true;
var allNum = "";
for (i = 0;  i < checkStr.length;  i++)
{
ch = checkStr.charAt(i);
for (j = 0;  j < checkOK.length;  j++)
if (ch == checkOK.charAt(j))
break;

if (j == checkOK.length)
{
allValid = false;
break;
}
if (ch != ",")
allNum += ch;
}
if (!allValid)
{
alert("Please enter only number characters in field.");
VInput.value="";
VInput.focus();
return (false);
}
	 }
	function ChangAll(id){
var checkall;
checkall=document.getElementById(id+'_All').value;
for(i=1;i<12;i++){
	document.getElementById(id+'_'+i).value=checkall;

	 }
	 }
	 //-------------------->

	 ///------------------>
	 function setAll(id,value){
var checkall=document.getElementById(id+'_All').value
if(value!=checkall){
document.getElementById(id+'_All').value='';
}//endif
if(
		( document.getElementById(id+'_1').value==document.getElementById(id+'_2').value)&&
			 ( document.getElementById(id+'_1').value==document.getElementById(id+'_3').value)&&
			 ( document.getElementById(id+'_1').value==document.getElementById(id+'_4').value)&&
			 ( document.getElementById(id+'_1').value==document.getElementById(id+'_5').value)&&
			 ( document.getElementById(id+'_1').value==document.getElementById(id+'_6').value)&&
			 ( document.getElementById(id+'_1').value==document.getElementById(id+'_7').value)&&
			 ( document.getElementById(id+'_1').value==document.getElementById(id+'_8').value)&&
			 ( document.getElementById(id+'_1').value==document.getElementById(id+'_9').value)&&
			 ( document.getElementById(id+'_1').value==document.getElementById(id+'_10').value)&&
			 (document.getElementById(id+'_1').value==document.getElementById(id+'_11').value)
	){
				document.getElementById(id+'_All').value=document.getElementById(id+'_1').value;
		 }
	 }//end setAll

	
function checkEmail(email){
if (!(/[0-9a-zA-Z_\.\-]+@[0-9a-zA-Z_\.\-]+.[a-zA-Z]+/ig).test(email.value)){
alert( "Try to check Email format" );
email.value='';
email.focus();
return false; 
}else{return true;}
}
function validateEmail(strEmail) {
	var objRegExp  = /(^[a-z]([a-z_\.0-9]*)@([a-z_\.0-9]*)([.][a-z]{3})$)|(^[a-z]([a-z_\.0-9]*)@([a-z_\.0-9]*)([.][a-z]{2})$)/i;
	return objRegExp.test(strEmail);
}

function  validateNum(strNum) {
  var objRegExp  =   /^[1-9][0-9]{1,2}$|^[1-9][0-9]{1,2}[.][0-9]{1,2}$/i;
  return objRegExp.test(strNum);
}

function  validateIDCard(strNum) {
  var objRegExp  =   /^[0-9]{13}$/i;
  return objRegExp.test(strNum);
}
function CheckBoxAll(obj,checkboxState) {
	 str = obj.id.split("_")
	for (a=0; a<document.forms['backend_form'].elements.length; a++) {
			if (document.forms['backend_form'].elements[a].id.indexOf(str[0]) == 0 && document.forms['backend_form'].elements[a].id!=str[0]+'_BF') {
				document.forms['backend_form'].elements[a].checked = checkboxState ;
				
			}
		}
	}
	function unCheckAllByObj(obj,checkboxState){
     str=obj.id.split("_");
	for(i=1;i<8;i++){
			if((document.getElementById(str[0]+'_1').checked==checkboxState) &&
				(document.getElementById(str[0]+'_2').checked==checkboxState) &&
				(document.getElementById(str[0]+'_3').checked==checkboxState) &&
				(document.getElementById(str[0]+'_4').checked==checkboxState) &&
				(document.getElementById(str[0]+'_5').checked==checkboxState) &&
				(document.getElementById(str[0]+'_6').checked==checkboxState) &&
				(document.getElementById(str[0]+'_7').checked==checkboxState)
				){
            document.getElementById(str[0]+'_All').checked=checkboxState;
			}else{ document.getElementById(str[0]+'_All').checked=false;}
	}
	}