
function validataFormContact(){
nam=document.frmcontact.name;
ema=document.frmcontact.email;
cont=document.frmcontact.content;
thongbao="";
setfc="";
if(nam.value=="")
{
	thongbao+="\n- Hãy nhập tên của bạn !";
	if(setfc=="") setfc=nam;
}
if(ema.value=="")
{
	thongbao+="\n- Không được để trống email.";
	if(setfc=="") setfc=ema;
}
if(cont.value=="")
{
	thongbao+="\n- Bạn chưa nhập thông tin liên hệ.";
	if(setfc=="") setfc=cont;
}
if (echeck(ema.value)==false){
	ema.value=""
	thongbao+="\n- Email không hợp lệ";
	if(setfc=="") setfc=ema;
}
if(thongbao!=""){
		alert(thongbao);
		setfc.focus();
		return false;
	}
	else{
		return true;
	}
}

function validataFormCart(){
nam=document.frmcart.name;
ema=document.frmcart.email;
phon=document.frmcart.phone;
thongbao="";
setfc="";
if(nam.value=="")
{
	thongbao+="\n- Hãy nhập tên của bạn !";
	if(setfc=="") setfc=nam;
}
if(ema.value=="")
{
	thongbao+="\n- Không được để trống email.";
	if(setfc=="") setfc=ema;
}
if (echeck(ema.value)==false){
	ema.value=""
	thongbao+="\n- Email không hợp lệ";
	if(setfc=="") setfc=ema;
}
if(phon.value=="")
{
	thongbao+="\n- Bạn chưa nhập số điện thoại.";
	if(setfc=="") setfc=phon;
}

if(thongbao!=""){
		alert(thongbao);
		setfc.focus();
		return false;
	}
	else{
		return true;
	}
}

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false
		 }

 		 return true					
	}