<!--
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.0
  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 && document.getElementById) x=document.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];}
}

var exit=true;
function bye()
{
if (exit)
window.open('exit.html','JavaScriptIt','toolbar= 0,location= 0,directories= 0,status= 0,menubar= 0,scrollbars= 0,resizable= 0,copyhistory= 0,width=240,height=140'); 
}

      function Sm1() {
        document.form1.submit();
       }
      function Sm2() {
        document.form2.submit();
       }      
      function Sm3() {
        document.form3.submit();
       }
       
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function openPopup(page,w,h){
	//win = window.open(page,"newwin","toolbar=no,localtion=no,directories=no,status=no,menubar=no,scrollbar=no,resizeable=no,copyhistory=no,width="+w+",height=h");
	win = window.open(page,"newwin","toolbar=no,localtion=no,directories=no,status=no,menubar=no,resizeable=no,copyhistory=no,width="+w+",height="+h);
}
function openPopup2(page){
	//win = window.open(page,"newwin","toolbar=no,localtion=no,directories=no,status=no,menubar=no,scrollbar=no,resizeable=no,copyhistory=no,width="+w+",height=h");
	win = window.open(page,"newwin","toolbar=no,localtion=no,directories=no,status=no,menubar=no,resizeable=no,copyhistory=no");
}
// Removes leading whitespaces
function LTrim( value ) {
	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}

// Removes ending whitespaces
function RTrim( value ) {
	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}

// Removes leading and ending whitespaces
function Trim( value ) {
	
	return LTrim(RTrim(value));
	
}

function MouseOver(_TR)
{
		_TR.className  = 'HightLight' ;	
}
function MouseOut(_TR,style)
{
	_TR.className  = style ;		
}
function Redir(url){
	window.location = url;
}
//doubleflg = True check with digit
function IsNumeric(strString,flg)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789.";
   if(flg == -1){ // chck with digit and
   		strValidChars = "0123456789.";	
   }else if(flg == 0){
   		strValidChars = "0123456789";
   }else if(flg == 1){
   		strValidChars = "123456789";
   }
   
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
	
   return blnResult;
   }
function CheckNumericControl(){
	var i,_var,errors='' ;
	var args= arguments ;
	for(i=0;i<args.length-1;i+=2){
		_var = MM_findObj(args[i]) ;
		if((!_var.readOnly && !_var.disabled) && !IsNumeric(Trim(_var.value),args[i+1])){
			errors +=  _var.id +'\n'  ;
			if(_var.className =="textbox")	 _var.className = "Error" ;
		}else{
			if(_var.className =="Error")	 _var.className = "textbox" ;
		}
	}
	if(errors != ""){
		alert('Invalid :\n'+errors) ;
		return false ;
	}
	return true ;
}
//INPUT arguments field(name), numberric style
function CheckLengthControl(ctrl){
	var _var,errors='' ;
	_var = MM_findObj(ctrl) ;
	if(_var.readOnly || _var.disabled || Trim(_var.value) == "") return true ;
	if(Trim(_var.value).length != _var.maxLength ){
		errors +=  _var.id +'\n'  ;
	}
	if(errors != ""){
		alert('Invalid :\n'+errors) ;
		return false ;
	}
	return true ;
}
function CheckTextValidation(){
	var i,_var,errors='' ;
	var args= arguments ;
	for(i=0;i<args.length;i++){
		_var = MM_findObj(args[i]) ;
		if((!_var.readOnly && !_var.disabled) && Trim(_var.value) ==""){
			errors +=  _var.id +'\n'  ;
			
		}
	}
	if(errors != ""){
		alert('กรุณาระบุ:\n'+errors) ;
		return false ;
	}
	return true ;
}
function CheckTextValidation2(){
	var i,_var,errors='' ;
	var args= arguments ;
	for(i=0;i<args.length;i++){
		_var = MM_findObj(args[i]) ;
		if(_var.type=="text"){
			if(!_var.disabled && Trim(_var.value) ==""){
				errors +=  _var.id +'\n'  ;
				if(_var.className =="textbox")	 _var.className = "Error" ;
			}else{
				//set to default
				if(_var.className =="Error")	 _var.className = "textbox" ;
			}
		}else if(_var.type=="select-one" && _var.selectedIndex<0){
			errors +=  _var.id +'\n'  ;
		}
	}
	if(errors != ""){
		alert('กรุณาระบุ:\n'+errors) ;
		return false ;
	}
	return true ;
}

function CheckPasswordIsMatch(p1,p2){
	var _p1 = MM_findObj(p1) ;
	var _p2 = MM_findObj(p2)  ;
	if(_p1.disabled || _p2.disabled || _p1.value == _p2.value){
		
		return true ;
	}
	else{
		
		alert('Password missmatch') ;
		
		return false ;
	}
}	
function Goback() {
    history.go(-1);
}	
function disableEnterKey(){
	if(event.keyCode == 13)
	{
	event.keyCode=9; //return the tab key
	event.cancelBubble = true;
	}
}
function expandit(hideobj){
	var _folder = MM_findObj(hideobj) ;
	if (_folder.style.display=="none")
		_folder.style.display='' ;
	else
		_folder.style.display='none' ;	
}
function EmailValidation(e_ctrl) {
		var ctrl = MM_findObj(e_ctrl) ;
		var str = ctrl.value ;
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail")
		    return false
		 }

 		 return true					
	}
function EmailValidation2(str) {
		
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail "+str)
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail "+str)
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr || str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail "+str)
		    return false
		}
		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot ||
		 str.indexOf(dot,(lat+2))==-1 || str.indexOf(" ")!=-1	
		 ){
		    alert("Invalid E-mail "+str)
		    return false
		 }

		
		
		

 		 return true					
	}
function CheckSendMail(){
	var _chkManager = MM_findObj('chkManager') ;
	var _chkStaff = MM_findObj('chkStaff') ;
	var _chkEmployee = MM_findObj('chkEmployee') ;
	var _var = MM_findObj('txtspecify') ;
	if(!_chkManager.checked && !_chkStaff.checked && !_chkEmployee.checked && Trim(_var.value) =="" )
	{
		alert('Please select group or entry specify e-mail') ;
		return false ;
	}
	//splite email
	var aryEmail = _var.value.split(';');
	var i = 0 ;
	for(i=0;i<aryEmail.length;i++){
		if(Trim(aryEmail[i]) != "" && !EmailValidation2(Trim(aryEmail[i])) ){
			return false ;
		}
		
	}
	return true ;
}
//-->
