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.user_url.value.match(/^[A-Za-z0-9_-]{3,}$/)){
			   alert(' ล็อกอินต้อง อย่างน้อย 3 ตัวอักษร และต้องเป็น A-Z 0-9 - _ เท่านั้น ');
			   theform.user_url.focus();
			   return false;
	 }else if(theform.user_pass.value.length<4 || theform.user_pass.value.length>32){
            alert('password ต้อง 4 ตัวอักษร - 32 ตัวอักษร');
            theform.user_pass.focus();
           return false;
	  }else if(theform.user_pass.value != theform.re_user_pass.value){
            alert('password กับ ยืนยัน password ไม่เหมือนกัน ');
            theform.re_user_pass.focus();
           return false;
	  }else if(theform.user_nick.value.length<4 || theform.user_nick.value.length>32){
               alert('ชื่อแทนตัว ต้อง 4 ตัวอักษร ถึง 32 ตัวอักษร');
			   theform.user_nick.focus();
			   return false;
	  }else 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;
	  }else if(!theform.user_sex[0].checked && !theform.user_sex[1].checked){
		   alert('เลือกเพศด้วยครับ');
		   theform.user_sex[0].focus();
		   return false;
	 }else if(theform.user_day.value=="0" || theform.user_month.value=="0" || theform.user_year.value=="0"){
		   alert('เลือก วันเกิด ด้วยครับ ');
		   theform.user_day.focus();
		   return false;
	 }else if(theform.user_key.value==""){
		   alert('พิมพ์ตัวอักษรตรวจสอบ จากรูป ด้วยครับ ');
		   theform.user_key.focus();
		   return false;
	 }else if(!theform.user_accept.checked){
		   alert('ยอมรับเงื่อนไขการใช้งานด้วยครับ ');
		   theform.user_accept.focus();
		   return false;
	 }

   theform.submit();
} //function


function checkEdit(){

     var theform=document.register;

	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;
	  }else if(!theform.user_sex[0].checked && !theform.user_sex[1].checked){
		   alert('เลือกเพศด้วยครับ');
		   theform.user_sex[0].focus();
		   return false;
	 }else if(theform.user_day.value=="0" || theform.user_month.value=="0" || theform.user_year.value=="0"){
		   alert('เลือก วันเกิด ด้วยครับ ');
		   theform.user_day.focus();
		   return false;
	 }
   theform.register_button.value=" กำลังทำการแก้ไขข้อมูล .........กรุณา รอสักครู่";
   theform.register_button.disabled=true;
   theform.submit();

} //function


var Dom = YAHOO.util.Dom;
function requestCheck(objname){

	  var obj=Dom.get(objname);

	   if(obj.name=="user_nick"){
		   var value=obj.value;
		   var mode=0;
	   }else if(obj.name=="user_url"){
		   var value=obj.value;
			var mode=1;
	   }else if(obj.name=="user_email"){
		   var value=obj.value;
		   var mode=2;
	   }else if(obj.name=="user_login"){
		   var value=obj.value;
		   var mode=3;
	   }

	   var display_obj=Dom.get(obj.name+"_check");
	   display_obj.style.display="";
	   display_obj.innerHTML="<img src='../images/web/ajax-loader.gif'>";

	   var data = "sid=" + Math.random()+"&mode="+mode+"&name="+value;  

		var handleSuccess = function(o){
			if(o.responseText !== undefined){
					 display_obj.innerHTML=o.responseText;
			}
		}

		var handleFailure = function(o){
			if(o.responseText !== undefined){
				 display_obj.innerHTML="checking error..";
			}
		}

		var callback =
		{
		  success:handleSuccess,
		  failure: handleFailure,
		  argument: { foo:"foo1", bar:"bar1" }
		};

		var request = YAHOO.util.Connect.asyncRequest('POST',"checkuser.php", callback,data);

}
