//check 1
	function loaDing(div){
		    document.getElementById(div).style.display='';
			document.getElementById(div).innerHTML="กำลังทำการตรวจสอบ.. ";
	  }
      function endLoading(){
            
	  }
	  			
					function stateChanged(){ 
				if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
					var response=xmlHttp.responseText ;
					var msg=document.getElementById("msg");
					endLoading();
					msg.innerHTML=response;
				} 
		} 

///// ajax

       var xmlHttp

		function checkUsername(user_login){ 
         
		    if(user_login.length > 0){ 
			     loaDing("msg");
				var url="register/checkiduser.php?id="+user_login;
				 xmlHttp=GetXmlHttpObject(stateChanged);
				 xmlHttp.open("GET", url , true);
				 xmlHttp.send(null);
			}

		} 

function GetXmlHttpObject(handler){ 

					 var objXmlHttp=null;

					if(navigator.userAgent.indexOf("Opera")>=0){
								alert("This example doesn't work in Opera") ;
								return 
					}
					if (navigator.userAgent.indexOf("MSIE")>=0){ 

								var strName="Msxml2.XMLHTTP";

								if(navigator.appVersion.indexOf("MSIE 5.5")>=0){
											strName="Microsoft.XMLHTTP";
								}

								try{ 
											objXmlHttp=new ActiveXObject(strName);
											objXmlHttp.onreadystatechange=handler ;
											return objXmlHttp;
								}catch(e){ 
											alert("Error. Scripting for ActiveX might be disabled") ;
											return ;
								} 

				  } 


				 if (navigator.userAgent.indexOf("Mozilla")>=0){
							objXmlHttp=new XMLHttpRequest();
							objXmlHttp.onload=handler;
							objXmlHttp.onerror=handler ;
							return objXmlHttp;
				 }

		} 



   //// end ajax
//end check 1
//check 2
function isDigit(c){
	    var test = "" + c;
	    if (test == "0" || 
			test == "1" || 
			test == "2" || 
			test == "3" ||
			test == "4" || 
			test == "5" ||
			test == "6" || 
			test == "7" ||
			test == "8" || 
			test == "9")  {
		   return true;	     
		}
	    return false;
 }
function isAllDigits(s){
    var test = "" + s;
    for (var k = 0; k < test.length; k++){
        var c = test.substring(k, k+1);
        if (isDigit(c) == false){
            return false;
          }
   }
    return true;
 }
 
 function check(mode){
      var theform=document.register;
	  
			if(theform.user_firstname.value==""){
				   alert('กรอกชื่อจริงด้วยครับ');
				   theform.user_firstname.focus();
				   return false;
			 }else if(theform.user_lastname.value==""){
				   alert('กรอกนามสกุลด้วยครับ');
				   theform.user_lastname.focus();
				   return false;
			 }
			 
			 
		 if(theform.user_email.value==""){
			   alert('กรอก emailด้วยครับ');
			   theform.user_email.focus();
			   return false;
		 }else if(theform.user_email.value.indexOf("@")==-1){
			   alert('กรอก email ให้ถูกต้องด้วยครับ');
				theform.user_email.focus();
			   return false;
		  }else if(theform.user_email.value.indexOf(".")==-1){
			   alert('กรอก email  ให้ถูกต้องด้วยครับ');
				theform.user_email.focus();
			   return false;
		  }
		  
	 		if(theform.user_mobile.value==""){
				   alert(' กรอก เบอร์โทรศัพท์  ด้วยครับ');
				   theform.user_mobile.focus();
				   return false;
			 }else if(theform.user_mobile.value.length<9){
				   alert('กรอก เบอร์โทรศัพท์  ต้องมากกว่า 9 ตัวครับ');
				   theform.user_mobile.focus();
				   return false;
			 }else if(!isAllDigits(theform.user_mobile.value)){
				   alert(' เบอร์โทรศัพท์  ต้องป็นตัวเลขครับ ');
				   theform.user_mobile.focus();
				   return false;
			 }
			 
			 	 if(mode=="add"){

			 if(theform.user_login.value.length<4){
					alert('ID ต้อง มากกว่า 4 ตัวอักษร');
					theform.user_login.focus();
				   return false;
			  }else if(theform.user_pass.value.length<4){
					alert('password ต้อง มากกว่า 4 ตัวอักษร');
					theform.user_pass.focus();
				   return false;
			  }else if(theform.user_pass.value != theform.re_user_pass.value){
					alert('password กับ ยืนยัน password ไม่เหมือนกัน ');
					theform.user_pass.focus();
				   return false;
			  }
	 }
			

       if(mode=="add")theform.register_button.value=" กำลังทำการสมัครสมาชิก .........กรุณา รอสักครู่";
	   else theform.register_button.value=" กำลังทำการแก้ไข .........กรุณา รอสักครู่";
       theform.register_button.disabled=true;
	   theform.submit();
	   
 }