﻿function gmobj(o){
	if(document.getElementById){
		m=document.getElementById(o);
	}
	else if(document.all){
		m=document.all[o];
	}else if(document.layers){
		m=document[o];
	}
	return m;
}

function iif(iEx1,r1,r2){
	if(iEx1)return r1;
	else return r2;
}
function isEmail(s)
{   
  if (s=="") return false;
  if(s.indexOf(" ")>0) return false;
  if(s.indexOf("@")==-1) return false;
  if (s.indexOf(".")==-1) return false;
  if (s.indexOf("..")!=-1) return false;
  if (s.indexOf("@")!=s.lastIndexOf("@")) return false;
  if (s.lastIndexOf(".")==s.length-1) return false;
  var str="abcdefghikjlmnopqrstuvwxyz-@._1234567890"; 
  for(var j=0;j<s.length;j++)
	if(str.indexOf(s.charAt(j))==-1)
		return false;
   return true;
}
function checkSendPass(form_)
{
	if((form_.txtusername.value=="")||(form_.txtemail.value==""))
	{
		alert("Nhập đủ thông tin trong dấu (*)  ");
		return false;
	}

	if(!isEmail(form_.txtemail.value))
	{
		alert("Email không đúng định dạng");
		return false;
	}
}
function checkFormEditAccount(form_)
{
	var str_err='Nhập đầy đủ thông tin đánh dấu (*) \n';
	var flag=true;
	if(form_.txtpass.value=="")
	{
		str_err=str_err+'Mật khẩu \n';
		flag=false;
	}
	if(form_.txtrepass.value=="")
	{
		str_err=str_err+'Nhập lại Mật khẩu \n';
		flag=false;
	}
	if(form_.txtemail.value=="")
	{
		str_err=str_err+'Email \n';
		flag=false;
	}
	if(form_.txtphone.value=="")
	{
		str_err=str_err+'Số điện thoại \n';
		flag=false;
	}
	if ((form_.txtpass.value)!=(form_.txtrepass.value)) 
	{ 
		str_err=str_err+'Mật khẩu không giống nhau \n';
		flag=false;
	}
	if(!isEmail(form_.txtemail.value))
	{
		str_err=str_err+'Email không đúng định dạng \n';
		flag=false;
	}

	if(!flag)
	{
		alert(str_err);
		return false;
	}
	return true;
}


function checkThanhToan()
{
var str_err='Bạn vui lòng điền đầy đủ thông tin bên dưới \n';
var flag=true;
	if (document.frmkh.txtname.value=="")
	{
		str_err=str_err+'Họ tên người đặt hàng \n';
		flag=false;
	}
	
	if (document.frmkh.txtaddress.value=="")
	{
		str_err=str_err+'Địa chỉ người đặt hàng\n';
		flag=false;
	}
	
	if (document.frmkh.txtphone.value=="")
	{
		str_err=str_err+'Điện thoại người đặt hàng \n';
		flag=false;
	}
	if (document.frmkh.txtemail.value=="")
	{
		str_err=str_err+'Email người đặt hàng \n';
		flag=false;
	}
	
	  if(document.frmkh.txtnameother.value=="")
	   {
	    str_err=str_err+'Tên người nhận hàng \n';
		flag=false;
		}
	  if(document.frmkh.txtphoneother.value=="")
	   {
	    str_err=str_err+'Số điện thoại người nhận hàng \n';
		flag=false;
		}
		  if(document.frmkh.txtaddressother.value=="")
	   {
	    str_err=str_err+'Địa chỉ người nhận hàng \n';
		flag=false;
		}	
		if(!isEmail(document.frmkh.txtemail.value))
		{
			alert("Email không đúng định dạng");
			return false;
		}
	if(!flag)
	{
		alert(str_err);
		return false;
	}
	return true;
}

function checkFormUpProduct(form_)
{
	if(form_.productName.value=="")
	{
		alert("Nhập tên sản phẩm");
		return false;
	}		
}
function DeleteConfirm(url)
{
	if(confirm('Bạn có thực sự muốn xóa không ?'))
	{
		location.href=url;
	}	
}

function checkFormPhanHoi(form_)
{
	var str_err='Bạn vui lòng điền đầy đủ thông tin bên dưới \n';
	var flag=true;
	if (form_.fname.value=="" || form_.fname.value=="Tên của bạn" )
	{
		str_err=str_err+'Tên của bạn \n';
		flag=false;
	}
	if (form_.uemail.value=="" || form_.uemail.value=="Email của bạn")
	{
		str_err=str_err+'Email của bạn \n';
		flag=false;
	}
	if (form_.scontent.value=="" || form_.scontent.value=="Bạn nên gõ Tiếng Việt có dấu")
	{
		str_err=str_err+'Nội dung góp ý \n';
		flag=false;
	}	
	if (!isEmail(form_.uemail.value))
	{
		str_err=str_err+'Email phải đúng định dạng \n';
		flag=false;
	}
			if(!flag)
	{
	alert(str_err);
	return false;
	}
	return true;
}
function clearvalues(obj)
{
	obj.value='';
}
