// JavaScript Document
function validate_text(field,alerttxt)
{
with (field)
  {
  //var mark = parseInt(value);
  if (value==null || value=="")
    {
    alert(alerttxt);return false;
    }
  else
    {
    return true;
    }
  }
}
function validate_select(field,alerttxt)
{
with (field)
  {
  if (value==null||value=="" || value==-1)
    {
    alert(alerttxt);return false;
    }
  else
    {
    return true;
    }
  }
}
function validate_check(field)
{
with (field)
  {
  if (checked==false)
    {
    return false;
    }
  else
    {
    return true;
    }
  }
}
function validate_radio(field)
{
with (field)
  {
  if (value >=1 && value <=5)
    {
    return true;
    }
  else
    {
    return false;
    }
  }
}

function validate_email(field,alerttxt)
{
with (field)
  {
  apos=value.indexOf("@");
  dotpos=value.lastIndexOf(".");
  if (apos<1||dotpos-apos<2)
    {alert(alerttxt);return false;}
  else {return true;}
  }
}

function validate(thisform)
{
with (thisform)
  {
  	if (validate_text(Ten,"Name is not empty")==false)
  	{
  		Ten.focus();return false;
  	}	
	if (validate_email(Email,"Not a valid e-mail address!")==false)
	{
		Email.focus();return false;
	}	
	if (validate_text(Dienthoai,"Phone is not empty")==false)
  	{
  		Dienthoai.focus();return false;
  	}	
	if (validate_text(Diachi,"Address is not empty")==false)
  	{
  		Diachi.focus();return false;
  	}	
	
	
  }
  
}

function validate_register(thisform)
{
with (thisform)
  {
  	if (validate_text(username,"Username không được bỏ trống")==false)
  	{
  		username.focus();return false;
  	}	
	if (validate_text(password,"password không được bỏ trống")==false)
  	{
  		password.focus();return false;
  	}	
	if (thisform.password.value!=thisform.repassword.value)
  	{
		alert('Password và nhập lại password không giống nhau');
  		password.focus();return false;
  	}	
	if (validate_email(Email,"Không đúng định dạng địa chỉ email")==false)
	{
		Email.focus();return false;
	}	
	if (validate_text(holot,"Họ Chữ Lót không được bỏ trống")==false)
  	{
  		Ten.focus();return false;
  	}
	if (validate_text(Ten,"Name không được bỏ trống")==false)
  	{
  		Ten.focus();return false;
  	}		
	
  }
  
}

function validate_entry(thisform)
{
with (thisform)
  {
  	if (validate_text(title,"Tiêu Đề không được bỏ trống")==false)
  	{
  		title.focus();return false;
  	}	
	if (validate_text(comment,"Nôi dung không được bỏ trống")==false)
  	{
  		comment.focus();return false;
  	}	
	
  }
  
}



