
		function do_img_refresh(thevar){
		var rndval=new Date().getTime();
		var c = document.getElementById(thevar);
		 c.innerHTML = "<img src='image.php?a="+rndval+"'  border='0'  alt=''  width='60' height='15' />";
		}


        var url = 'captcheck.php?code=';
        var captchaOK = 2;  // 2 - not yet checked, 1 - correct, 0 - failed
        
        function getHTTPObject()
        {
        try {
        req = new XMLHttpRequest();
          } catch (err1)
          {
          try {
          req = new ActiveXObject("Msxml12.XMLHTTP");
          } catch (err2)
          {
          try {
            req = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (err3)
            {
				req = false;
            }
          }
	}
        return req;
	}
        
        var http = getHTTPObject(); // We create the HTTP Object        
        
        function handleHttpResponse() {
        if (http.readyState == 4) {
            captchaOK = http.responseText;
            if(captchaOK != 1) {
              alert('Bạn đã nhập không đúng Mã an toàn! Vui lòng nhập lại. \nThe entered code was not correct. Please try again');
              document.myform.fm_verify.value='';
              document.myform.fm_verify.focus();
              return false;
              }
              document.myform.submit();
           }
        }

        function checkcode(thecode) {
        http.open("GET", url+ escape(thecode), true);
		/*alert("captcheck.php?code="+escape(thecode));*/
        http.onreadystatechange = handleHttpResponse;
        http.send(null);
        }
        
	function validateEmail(elementValue){  
		var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;  
		return emailPattern.test(elementValue);  
	}  

function checkform() {
// First the normal form validation

	  if (document.myform.ten.value == "") {
		alert( "Vui lòng nhập họ tên.\nPlease enter yourname." );
		document.myform.ten.focus();
		return false ;
	  }
	if (document.myform.diachi.value == "") {
		alert( "Vui lòng nhập địa chỉ.\nPlease enter your address." );
		document.myform.diachi.focus();
		
		return false ;
	}

	if (document.myform.email.value == "") {
		alert( "Vui lòng nhập email.\nPlease enter your email address." );
		document.myform.email.focus();
		
		return false ;
	}
	if (!validateEmail(document.myform.email.value)){
		alert( "Vui lòng nhập đúng email.\nPlease enter correct your email address." );
		document.myform.email.focus();
		
		return false;

	}
/*	if (document.myform.tenmien.value == "") {
		alert( "Vui lòng nhập tên miền.\nPlease enter your domain name." );
		document.myform.tenmien.focus();
		
		return false ;
	}
*/
	if(document.myform.fm_verify.value=='') {
	  alert('Vui lòng nhập Mã an toàn, được hiển thị bên cạnh. \n Please enter the string from the displayed image');
	  document.myform.fm_verify.value='';
	  document.myform.fm_verify.focus();
	  return false;
	  }
	  // Now the Ajax CAPTCHA validation
	  checkcode(document.myform.fm_verify.value);
	  return false;
}      

function checkformcontact() {
	// First the normal form validation
	  if (document.myform.yourname.value == "") {
		alert( "Vui lòng nhập họ tên(Please enter yourname)." );
		document.myform.yourname.values='';
		document.myform.yourname.focus();
		return false ;
	  }
	  if (!IsNumeric(document.myform.yourphone.value)||document.myform.yourphone.value == "") {
		alert( "Vui lòng nhập số điện thoại(Please enter  your phone)." );
		document.myform.yourphone.values='';
		document.myform.yourphone.focus();
		return false ;
	  }
	 
	if (document.myform.youremail.value == "") {
		alert( "Vui lòng nhập email.\nPlease enter your email address." );
		document.myform.youremail.values='';
		document.myform.youremail.focus();
		
		return false ;
	}
	if (!validateEmail(document.myform.youremail.value)){
		alert( "Vui lòng nhập đúng email.\nPlease enter correct your email address." );
		document.myform.youremail.focus();
		return false;
	}
	if(document.myform.tieude_adv.value =="")
	{
		alert();
		document.myform.tieude_adv.focus();
		return false;
	}
	if (document.myform.yourinfo.value == "") {
		alert( "Vui lòng nhập từ khóa bạn muốn sử dụng(Please enter  info)." );
		document.myform.yourinfo.focus();
		return false ;
	}

	if(document.myform.fm_verify.value=='') {
	  alert('Vui lòng nhập Mã an toàn, được hiển thị bên cạnh. \n Please enter the string from the displayed image');
	  document.myform.fm_verify.value='';
	  document.myform.fm_verify.focus();
	  return false;
	}

	// Now the Ajax CAPTCHA validation
	checkcode(document.myform.fm_verify.value);
	return false;
}      




