function chkField(FormName,FieldName,TxtName){
	if (eval("document."+FormName+"."+FieldName+".value")==""){
		alert("กรุณากรอกรายละเอียดที่ช่อง \""+TxtName+"\" ด้วยครับ");
		eval("document."+FormName+"."+FieldName+".focus()");
		return true;	
	}else{
		return false;
	}
}


function chkField_Email(FormName,FieldName,TxtName){
	
	if (!chkField(FormName,FieldName,TxtName)){

		var a = eval("document."+FormName+"."+FieldName+".value");
		var inValid = false;
		var a_arr  = a.split(",");
			
		for (var i=0;i<a_arr.length;i++){
			if (!isValidEmail(a_arr[i])){
			 	inValid = true;	
			}
		}
			
		if (inValid){
			alert("กรุณากรอกอีเมล์ที่ช่อง \""+TxtName+"\" ให้ถูกต้องด้วยครับ");
			eval("document."+FormName+"."+FieldName+".focus()");
			return true;
		}else return false;
		
		

}else{
		return true;
	}
	
}

function isValidEmail(str) {
	   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}


function chkField_Mobile(FormName,FieldName,TxtName){
	if (!chkField(FormName,FieldName,TxtName)){
		var a = eval("document."+FormName+"."+FieldName+".value");
	   
		if ((!isInteger(a)) || (a.length!=10)){
			alert("กรุณากรอกเบอร์โทร \""+TxtName+"\" ให้ถูกต้องด้วยครับ");
			eval("document."+FormName+"."+FieldName+".focus()");
			return true;
		}else return false;
		
	}else{
		return true;
	}
}

function chkField_CardID(FormName,FieldName,TxtName){
	if (!chkField(FormName,FieldName,TxtName)){
		var a = eval("document."+FormName+"."+FieldName+".value");
	
		if ((!isInteger(a)) || (a.length!=13)){
			alert("กรุณากรอกเลขที่ \""+TxtName+"\" ให้ถูกต้องด้วยครับ");
			eval("document."+FormName+"."+FieldName+".focus()");
			return true;
		}else return false;		

	}else{
			return true;
	}
}



//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


function openPic(pic,w,h){
	var html = " <html>\n<head><title>MagMaReport.Com - Webadmin</title></head>\n<body style=\"margin:0px;\"><img src=\""+pic+"\" width=\""+w+"\" height=\""+h+"\"></body>\n<script language=\"JavaScript1.1\" src=\"http://hits.truehits.in.th/data/q0027969.js\" type=\"text/javascript\"></script></html>";
	picWindow=window.open("","displayPic","toolbar=no,scrollbars=no,resizable=no,width="+w+",height="+h);
	picWindow.document.write(html);
}

function openFullWin(url){
	picWindow=window.open(url,"popup_win");
}


function openWin(url,w,h){
	picWindow=window.open(url,"popup_win","toolbar=no,scrollbars=yes,resizable=yes,width="+w+",height="+h);
}

function lengthEx(){
	var ex_count=1;
	var loop = true;
	while (loop==true){
		var xx= "ex_"+ex_count;
		if (document.getElementById(xx)==null){
			loop=false;
		}else{
			ex_count++;	
		}
	}
	return ex_count-1;
}

function activeEx(name){
	for (var i=1;i<=lengthEx();i++){
		var div = "ex_"+i;
		var menu_ac = "ex_menu"+i+"_ac";
		var menu_inac = "ex_menu"+i+"_inac";
		document.getElementById(menu_ac).style.display="none";
		document.getElementById(menu_inac).style.display="inline";
		document.getElementById(div).style.display="none";
	}
	div = "ex_"+name;
	menu_ac = "ex_menu"+name+"_ac";
	menu_inac = "ex_menu"+name+"_inac";
	document.getElementById(menu_ac).style.display="inline";
	document.getElementById(menu_inac).style.display="none";
	document.getElementById(div).style.display="inline";
}














