﻿function isname(name)
{
  if(name=="")
  {
       alert("Bạn chưa nhập tên");
       return false;	  		  
  }
  for (var j=0;j<name.length;j++)
  {
	  if (((name.charat(j)>"A")&&(name.charat(j)<"Z"))
	     ||((name.charat(j)>"a")&&(name.charat(j)<"z"))
		 ||(name.charat(j)==" ")||(name.charat(j)>192))
	  {	 
         alert("Tên không hợp lệ");
	     return false;		 
	  }
  }	  
  return true;
}

function ofemail(email)
{
    var str  = "abcdefghijklmnopqrstuvwxyz@._-";
	for (var j=0;j<str.length;j++)
	  if (str.indexof(email.charat(j))==-1)
	    return false;
   return true;		
}	

function isemail(email)
{
	if (email=="")
	{
		alert("Ban chua nhap email.");
		return false;
	}
	var the_at    = email.indexOf("@");
	var the_dot   = email.indexOf(".");
	var the_space = email.indexOf(" ");
	if ((the_at>1)&&((the_at+1)<the_dot)&&(the_dot<email.length-1)&&(the_space==-1)&&(email.indexof("..")==-1)&&ofmail(email))
       return true;
	alert("Email khong hop le.");
	return false;
}
function do_login(form)
{
  var pass=form.password;
  var email=form.email;
 
  if(email.length<5)
  {
    alert("User name phai lon hon 4 ky tu.");
    return false;    
  }
  if(pass.length<5)
  {
    alert("Password phai lon hon 4 ky tu.");
    return false;    
  }  
  return true;
}

function check_loginform(the_login)
{
//  return (isemail(the_login.email.value) && ispass(the_login.password.value));
}

function check_searchform(str)
{
	if (str.value=='')
	{
		alert("Nhap vo noi dung tim kiem.");
		str.focus;
		return false;
	}
	return true;
}
function check_form(the_form)
{
	var the_email    = the_form.email.value;
	var the_name     = the_form.name.value;
	var the_content  = the_form.content.value;
	
	if (the_name=='')
	{
		alert("Ban chua nhap ho ten");
		the_form.name.focus();
		return false;
	}

    if (the_email=='')
	{
		alert("Ban chu nhap email");
		the_form.email.focus();
		return false;
	}
	if (!isemail(the_email))
	{
	   alert("Email khong hop le");
       the_form.email.focus();
	   return false;
	}   

    if (the_content=='')
	{
	   alert("Ban chua nhap noi dung");
       the_form.content.focus();
	   return false;
	}   
	return true;
}

function check_personalform(the_form)
{
	var the_email    = the_form.email.value;
	var the_name     = the_form.realname.value;
    if (isemail(the_email))	
    {
      the_form.email.focus();
	  return false;
	}  
	if (the_name=='')
	{
		alert("Nhập dầy dủ thông tin bắt buộc.");
		the_form.email.focus();
		return false;
	}
	return true;
}

function checkinstall(control)
{
  if(control.req_db_host.value=="")
  {
    alert("Ban hay dien dia chi server du lieu.");
	control.req_db_host.focus();
    return false;
  } 
  if(control.req_db_name.value=="")
  {
    alert("Ban hay nhap vao ten co so du lieu su dung.");
	control.req_db_name.focus();
    return false;
  } 
  if (isname(control.req_username.value))  return false;  
  if(!isemail(req_email)) return false;
  if((control.password1.value=="")||(control.password1.value!=control.password2.value)) return false;
  return true;
}
function check_order(the_form)
{
	var the_email    = the_form.email.value;
	var the_name     = the_form.name.value;
	var the_content  = the_form.content.value;
	var the_address  = the_form.address.value;
	var the_tell     = the_form.tell.value;
	
	if (the_name.length<10)
	{
		alert("Ho ten phai lon hon 10.");
		the_form.name.focus();
		return false;
	}

    if (the_address.length<15)
	{
		alert("Dia chi phai lon hon 15");
		the_form.address.focus();
		return false;
	}

    if (the_email.length<10)
	{
		alert("Mail phai lon hon 10");
		the_form.email.focus();
		return false;
	}

    if (!isemail(the_email))
	{
	   alert("Email khong hop le");
       the_form.email.focus();
	   return false;
	}   

    if (the_tell.length<5)
	{
		alert("Dien thoai phai lon hon 5 ky tu");
		the_form.address.focus();
		return false;
	}

    if (the_content.length<20)
	{
	   alert("Noi dung phai lon hon 20 ky tu");
       the_form.content.focus();
	   return false;
	}   
	return true;
}
