﻿function IsEmpty(aTextField) {
   if ((aTextField.value.length==0) ||
   (aTextField.value==null)) {
      return true;
   }
   else { return false; }
}	


function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
}

function isValidEmail(str) {
   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}


function ValidateForm(form)
{
   if(IsEmpty(form.name)) 
   { 
      alert('Bạn cần nhập tên bạn !') ;
      form.name.focus(); 
      return false; 
   } 
   
   if(IsEmpty(form.email)) 
   { 
      alert('Bạn cần nhập email !') ;
      form.email.focus(); 
      return false; 
   } 
   
   if (!isValidEmail(form.email.value)) 
   { 
	  alert('Email không hợp lệ !') 
	  form.email.focus(); 
	  return false; 
   } 
 
   if(IsEmpty(form.address)) 
   { 
      alert('Bạn cần nhập địa chỉ !') ;
      form.address.focus(); 
      return false; 
   } 
   
   if(IsEmpty(form.phone)) 
   { 
      alert('Bạn cần nhập điện thoại !') ;
      form.phone.focus(); 
      return false; 
   } 
   
   if (!IsNumeric(form.phone.value)) 
   { 
	  alert('Điện thoại phải là số !') 
	  form.phone.focus(); 
	  return false; 
   } 
   
   if (form.howto[5].checked) {
		if(IsEmpty(form.channel)) {
			alert('Bạn cần nhập nguồn thông tin!') ;
			form.channel.focus(); 
			return false; 
		}
    }   
   
   if(IsEmpty(form.verify)) 
   { 
      alert('Bạn cần nhập mã bảo vệ !') ;
      form.verify.focus(); 
      return false; 
   }  

return true;
 
}


function ValidateForm2(form)
{
   if(IsEmpty(form.name)) 
   { 
	  alert('Bạn cần nhập tên !') ;
	  form.name.focus(); 
	  return false; 
   } 

   
   if(IsEmpty(form.birthday)) 
   { 
      alert('Bạn cần nhập ngày sinh !') ;
      form.birthday.focus(); 
      return false; 
   } 
   
   if(IsEmpty(form.home)) 
   { 
      alert('Bạn cần nhập nơi sinh !') ;
      form.home.focus(); 
      return false; 
   } 
   
 	if(IsEmpty(form.study)) 
   { 
      alert('Bạn cần nhập trình độ học vấn !') ;
      form.study.focus(); 
      return false; 
   }
   
   if(IsEmpty(form.address1)) 
   { 
      alert('Bạn cần nhập hộ khẩu thường trú !') ;
      form.address1.focus(); 
      return false; 
   } 
   
      
    if(IsEmpty(form.address2)) 
   { 
      alert('Bạn cần nhập địa chỉ liên hệ !') ;
      form.address2.focus(); 
      return false; 
   } 
   
   
   if (!IsNumeric(form.phone1.value)) 
   { 
	  alert('Điện thoại phải là số !') 
	  form.phone1.focus(); 
	  return false; 
   } 
   if (!IsNumeric(form.phone2.value)) 
   { 
	  alert('Điện thoại phải là số !') 
	  form.phone2.focus(); 
	  return false; 
   } 
   
   if(IsEmpty(form.email)) 
   { 
      alert('Bạn cần nhập email !') ;
      form.email.focus(); 
      return false; 
   } 
   
   if (!isValidEmail(form.email.value)) 
   { 
	  alert('Email không hợp lệ !') 
	  form.email.focus(); 
	  return false; 
   } 
   
   	
	if (form.howto[5].checked) {
		if(IsEmpty(form.channel)) {
			alert('Bạn cần nhập nguồn thông tin!') ;
			form.channel.focus(); 
			return false; 
		}
    }   
   
   if(IsEmpty(form.verify)) 
   { 
      alert('Bạn cần nhập mã bảo vệ !') ;
      form.verify.focus(); 
      return false; 
   }
   
   if(form.confirm.checked != true) 
   { 
      alert('Bạn phải đồng ý các qui định !') ;
      return false; 
   }
   
   return true;
 
}
