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(){
     		var theform=document.register;

			 if(theform.firstname.value==""){
				   alert('กรอกชื่อจริงด้วยครับ');
				   theform.firstname.focus();
				   return false;
			 }else if(theform.lastname.value==""){
				   alert('กรอกนามสกุลด้วยครับ');
				   theform.lastname.focus();
				   return false;
			 }else if(!theform.sex[0].checked && !theform.sex[1].checked){
				   alert('เลือกเพศด้วยครับ');
				   theform.sex[0].focus();
				   return false;
			 }else if(theform.bday.value=="0" || theform.bmonth.value=="0" || theform.byear.value=="0"){
				   alert('เลือก วันเกิด ด้วยครับ ');
				   theform.bday.focus();
				   return false;
			 }else if(theform.address.value==""){
				   alert('กรอก ที่อยู่ ด้วยครับ');
				   theform.address.focus();
				   return false;
			 }else if(theform.amphur.value==""){
				   alert('กรอก อำเภอ ด้วยครับ');
				   theform.amphur.focus();
				   return false;			
			 }else if(theform.province.value==""){
				   alert('เลือกจังหวัด  ด้วยครับ');
				   theform.province.focus();
				   return false;
			 }else if(theform.zipcode.value==""){
				   alert(' กรอก รหัสไปรษณีย์  ด้วยครับ');
				   theform.zipcode.focus();
				   return false;
			 }else if(theform.zipcode.value.length!=5){
				   alert('กรอก รหัสไปรษณีย์  5 ตัวครับ');
				   theform.zipcode.focus();
				   return false;
			 }else if(!isAllDigits(theform.zipcode.value)){
				   alert('รหัสไปรษณีย์  ต้องป็นตัวเลขครับ ');
				   theform.zipcode.focus();
				   return false;
			 }else if(theform.loginname.value.length<4){
					alert('username ต้อง มากกว่า 4 ตัวอักษร');
					theform.loginname.focus();
				   return false;
			  }else if(theform.password.value.length<4){
					alert('password ต้อง มากกว่า 4 ตัวอักษร');
					theform.password.focus();
				   return false;
			  }else if(theform.password.value != theform.re_password.value){
					alert('password กับ ยืนยัน password ไม่เหมือนกัน ');
					theform.password.focus();
				   return false;
			  }else if(theform.nickname.value==""){
					alert(' กรอกชื่อเล่นด้วยครับ ');
					theform.nickname.focus();
				   return false;
			  }else if(theform.nickname.value.length<4){
					alert(' ชื่อเล่น 4-32 ตัวอักษรครับ ');
					theform.nickname.focus();
				   return false;
			  }else if(theform.email.value==""){
				   alert('กรอก email ด้วยครับ');
				   theform.email.focus();
				   return false;
			 }else if(theform.email.value.indexOf("@")==-1){
				   alert('กรอก email ให้ถูกต้องด้วยครับ');
					theform.email.focus();
				   return false;
			  }else if(theform.email.value.indexOf(".")==-1){
				   alert('กรอก email  ให้ถูกต้องด้วยครับ');
					theform.email.focus();
				   return false;
			  }else if(theform.security_code.value==""){
					alert('กรอก รหัสความปลอดภัยด้วยครับ ');
					theform.security_code.focus();
				   return false;
			  }
	 

	  theform.submit();


} //function





	  function loaDing(div){
		    document.getElementById(div).style.display='';
			document.getElementById(div).innerHTML="กำลังทำการตรวจสอบ.. ";
	  }
  
	  function loaDingImg(div){
		    document.getElementById(div).style.display='';
			document.getElementById(div).innerHTML="กำลังโหลดรูป signup ley.. ";
	 }

      function endLoading(){
            
	  }

      function endLoadingImg(div){
             document.getElementById(div).style.display='none';
	  }



       ///// ajax

       var xmlHttp

		function checkUsername(user_login){ 
         
		    if(user_login.length > 0){ 
			     loaDing("msg");
				var url="checkuser.php?action=user&name="+user_login;
				 xmlHttp=GetXmlHttpObject(stateChanged);
				 xmlHttp.open("GET", url , true);
				 xmlHttp.send(null);
			}

		} 



		function checkEmail(email){ 
		    if(email.length > 0){ 
			     loaDing("msgemail");
				var url="checkuser.php?action=email&name="+email;
				 xmlHttp=GetXmlHttpObject(stateChanged1);
				 xmlHttp.open("GET", url , true);
				 xmlHttp.send(null);
			}

		} 
  


		function stateChanged(){ 
				if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
					var response=xmlHttp.responseText ;
					var msg=document.getElementById("msg");
					endLoading();
					msg.innerHTML=response;
				} 
		} 


		function stateChanged1(){ 
				if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
					var response=xmlHttp.responseText ;
					var msg=document.getElementById("msgemail");
					endLoading();
					msg.innerHTML=response;
				} 
		} 



		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

