// JavaScript Document
function LOGIN()
	  {
	  	var email=frmLogin.txtEmail.value;
		var pass=frmLogin.txtPassword.value;
		if(email=="")
		{
		alert("Please input email");
		frmLogin.txtEmail.focus();
		return false;
		}
		if(pass=="")
		{
		alert("Please input password");
		frmLogin.txtPassword.focus();
		return false;
		}
		
		return true;
	  }
function KTTVH()
	  {
	  	var tieude=form1.txttieude.value;
		var noidung=form1.txtMessage.value;
		if(tieude=="")
		{
		alert("Tiêu Đề Không Để Trống");
		form1.txttieude.focus();
		return false;
		}
		if(noidung=="")
		{
		alert("Nội Dung Không Để Trống");
		form1.txtMessage.focus();
		return false;
		}
		
		return true;
	  }
function KTTK1()
{
	var tukhoa=form1.tk.value;
	var daunhay=/\'/;
	if (daunhay.test(tukhoa)==true)
	{
		alert("Từ khóa không hợp lệ !");
		form1.tk.focus();
		return false
	}
	return true;
}

function KTTK()
{
	var gia1=form2.txtgia1.value;
	var gia2=form2.txtgia2.value;
	var tk1=form2.tk.value;
	var daunhay=/\'/;
	if (daunhay.test(tk1)==true)
	{
		alert("Từ khóa không hợp lệ !");
		form2.tk.focus();
		return false
	}
	if(isNaN(gia1))
	{
		alert("Bạn nhập giá tiền không hợp lệ !");
		form2.txtgia1.focus();
		return false
	}		
	if(isNaN(gia2))
	{
		alert("Bạn nhập giá tiền không hợp lệ !");
		form2.txtgia2.focus();
		return false
	}	
	return true;
}
function KT()
{
	var name=form1.txtname.value
	if(name=="")
	{
		alert("Tên nhóm sản phẩm không được để trống !");
		form1.txtname.focus();
		return false
	}	
	
	return true;
}

function AddProducts()
{
	var tensp=form1.txttensp.value;
	var hinhanh=form1.txtanh.value;
	var tien =form1.txttien.value;
	var nhomsp =form1.nhomsp.value;
	var chitiet=form1.txtdetail.value;
	if(tensp=="")
	{
		alert("Tên sản phẩm không được để trống!");
		form1.txttensp.focus();
		return false
	}
	if(hinhanh=="")
	{
		alert("Ảnh không được để trống!");
		form1.txtanh.focus();
		return false;
	}
	if(nhomsp==0)
	{
		alert("Chưa chọn nhóm sản phẩm!");
		form1.nhomsp.focus();
		return false;
	}
	if(tien=="")
	{
		alert("Tìên không được để trống!");
		form1.txttien.focus();
		return false;
	}
	if(isNaN(tien))
	{
		alert("Tìên không hợp lệ!");
		form1.txttien.focus();
		return false;
	}
	if(chitiet=="")
	{
		alert("Chi tiết sản phẩm không được để trống!");
		form1.txtdetail.focus();
		return false;
	}
	return true
}

function AddNews()
{
	var tieude=form1.txttieude.value;
	var tomtat=form1.txttomtat.value;
	var noidung=form1.txtMessage.value;
	var tacgia=form1.txttacgia.value;	
	if(tieude=="")
	{
		alert("Tiêu đề không được để trống!");
		form1.txttieude.focus();
		return false;
	}
	 var ok=false;	 
	  for (var i=0;i < form1.newhot.length;i++)
	  {
		if (form1.newhot[i].checked)
		{
			ok=true;
			break;
		}
	  }      
		if (!ok)
		{
			alert('Bạn chưa chọn tin nổi bật.');
			form1.newhot[0].focus();
			return false;
		} 
	if(tomtat=="")
	{
		alert("Tóm tắt không được để trống!");
		form1.txttomtat.focus();
		return false;
	}
	if(noidung=="")
	{
		alert("Nội dung không được để trống!");
		form1.txtMessage.focus();
		return false;
	}	
	if(tacgia=="")
	{
		alert("Tác giả không được để trống!");
		form1.txttacgia.focus();
		return false;
	}
	return true;
}

function xoanhieu()
{
    var checked = false;
	for(i=0;i<document.frmdssanpham.chkxoa.length;i++)
	{
		if(document.frmdssanpham.chkxoa[i].checked)
		{
			checked = true;
			document.frmdssanpham.chkxoa.value = document.frmdssanpham.chkxoa[i].value;
			 if (confirm("Bạn có muốn xóa sản phẩm đã chọn không?"))
	         {
		         document.frmdssanpham.action="XLXoaNhieuSP.asp";
		         document.frmdssanpham.submit();
	         }
			break;
		}
		
	}	
	if(!checked)
	{
		alert('Xin vui lòng chọn sản phẩm mà bạn muốn xóa!');
		return false;
	}
  return true; 
}
///////////
function XoaNhieu_LH()
{
    var checked = false;
	for(i=0;i<document.frmLH.chkxoa.length;i++)
	{
		if(document.frmLH.chkxoa[i].checked)
		{
			checked = true;
			document.frmLH.chkxoa.value = document.frmLH.chkxoa[i].value;
			 if (confirm("Bạn có muốn xóa câu hỏi đã chọn không?"))
	         {
		         document.frmLH.action="XoaNhieu_LH.asp";
		         document.frmLH.submit();
	         }
			break;
		}
		
	}	
	if(!checked)
	{
		alert('Xin vui lòng chọn sản phẩm mà bạn muốn xóa!');
		return false;
	}
  return true; 
}

function dangky()
{
	var i;
	//Ten tai khoan
	var user=form1.txtuser.value;
	if(user == "")
	{
		alert("Tên tài khoản không được trống ");
		form1.txtuser.focus()
		return false
	}
	if((user.length < 5) || (user.length > 20))
	{
		alert("Tên tài khoản không hợp lệ")
		form1.txtuser.focus()
		return false
	}
	if(user.length == /^(\w)+(\s)/)
	{		
		alert("Tên tài khoản không hợp lệ ");
		form1.txtuser.focus()
		return false;
	}
	//MAT KHAU
	var pass1=form1.txtpass.value;
	var pass2=form1.txtrepass.value;
	if(pass1.length==0)
	{
		alert("Mật khẩu không được trống ");
		form1.txtpass.focus()
		return false
	}
	if((pass1.length < 5) || (pass1.length > 20))
	{
		alert("Mật khẩu không hợp lệ ");
		form1.txtpass.focus()
		return false	
	}
	if(pass1 !=pass2)
	{
		alert("Mật khẩu không hợp lệ ");
		form1.txtpass.focus()
		return false
	}
	//Email
	var re=new RegExp;
	re=/^\w+([\.-]?\w+)*@\w+(-?\w+)*(\.\w{2,3}){1,2}$/;
	var email = form1.txtemail.value;
	var b1 = email.indexOf(",");
	var b2 = email.indexOf("?");
	var b3 = email.indexOf(":");
	var b4 = email.indexOf("#");
	
	/*var a = email.indexOf('@');
	var a2 = email.indexOf('@',a+1);
	var cham = email.indexOf('.');
	var cham2 = email.indexOf('.',cham+1);
	var trong = email.indexOf(" ");
	if((a < 0)||(a2 > 0)||(cham < 0)||(cham2 > 0)||(trong > 0)||(b1 > -1)||(b2 > -1)||(b3 > -1))
	{		
		alert("E-mail không hơp lệ ")
		form1.txtemail.focus()
		return false
	}*/
	
	if((b1 > -1)||(b2 > -1)||(b3 > -1)||(b4 > -1))
	{
		alert("Email không hợp lệ")
		form1.txtemail.focus()
		return false
	}
	if(re.test(email)==false)
	{
		alert("Email không hợp lệ")
		form1.txtemail.focus()
		return false
	}
	
	if(email == "")
	{
		alert("Email không được để trống")
		form1.txtemail.focus()
		return false
	}
	//ho ten
	var name=form1.txtname.value;
	if(name=="")
	{
		alert("Họ tên không được trống");
		form1.txtname.focus()
		return false
	}
	//dia chi
	var add = form1.txtaddress.value;
	if(add == "")
	{
		alert("Địa chỉ không được trống");
		form1.txtaddress.focus()
		return false
	}
	//dien thoai
	var phone = form1.txtphone.value;
	if(phone == "")
	{
		alert("Số điện thoại không được để trống")
		form1.txtphone.focus()
		return false
	}
	if((phone.length <=5) || (phone.length >= 11))
	{
		alert("Số điện thoại không hợp lệ")
		form1.txtphone.focus()
		return false
	}
	if(isNaN(phone))
	{
		alert("Số điện thoại không hợp lệ")
		form1.txtphone.focus()
		return false	
	}
	//CMND
	var CMND = form1.txtcmnd.value;
	if(CMND == "")
	{
		alert("Số CMND không được trống")
		form1.txtcmnd.focus()
		return false
	}
	if(isNaN(CMND))
	{
		alert("Số CMND không hợp lệ")
		form1.txtcmnd.focus()
		return false
	}
	if(CMND.length != 9)
	{
		alert("Số CMND không hợp lệ")
		form1.txtcmnd.focus()
		return false
	}
	return true
}
//-------------------------------------------------------------
function lienhe()
{
	//ho ten
	var name=form2.txtname.value;
	if(name=="")
	{
		alert("Họ tên không được trống");
		form2.txtname.focus()
		return false
	}
	//Email
	var email = form2.txtemail.value;
	var a = email.indexOf('@');
	var a2 = email.indexOf('@',a+1);
	var cham = email.indexOf('.');
	var cham2 = email.indexOf('.',cham+1);
	var trong = email.indexOf(" ");
	var b1 = email.indexOf("/");
	var b2 = email.indexOf("?");
	var b3 = email.indexOf(":");	
	if(email == "")
	{
		alert("Email không được để trống")
		form2.txtemail.focus()
		return false
	}
	if((a < 0)||(a2 > 0)||(cham < 0)||(cham2 > 0)||(trong > 0)||(b1 > -1)||(b2 > -1)||(b3 > -1))
	{		
		alert("E-mail không hơp lệ ")
		form2.txtemail.focus()
		return false
	}		
	var content=form2.txtsub.value;
	if(content == "")
	{
		alert("Bạn chưa nhập nội dung ");
		form2.txtsub.focus();
		return false	
	}	
	return true;	
}
//---------------------------------
function xoacheck()
{
    var checked = false;
	for(i=0;i<document.frmnews.chkdel.length;i++)
	{
		if(document.frmnews.chkdel[i].checked)
		{
			checked = true;
			document.frmnews.chkdel.value = document.frmnews.chkdel[i].value;
			 if (confirm("Bạn muốn xóa các tin tức đã chọn chứ?"))
	         {
		         document.frmnews.action="Del_Check_News.asp";
		         document.frmnews.submit();
	         }
			break;
		}
		
	}	
	if(!checked)
	{
		alert('Xin vui lòng chọn tin tức mà bạn muốn xóa!');
		return false;
	}
  return true; 
}
function KiemTra()
{
    //Kiem Tra ID
	       var ktid=/\'/;
	       var  id = f1.txtid.value;
		    if( id=='' || id.length < 6 )
			{
			    alert('Tên đăng nhập không được trống và lớn hơn 6 ký tự');
			    f1.txtid.focus();
				return false;
			}
			if (ktid.test(id)==true)
			{
				alert("Tên đăng nhập không có ký tự  ' ");
			    f1.txtid.focus();
				return false;
			}
 //Kiem tra mat khau
            var Pass1 = f1.txtpass1.value ;
			var Pass2 = f1.txtpass2.value ;  
		     if(Pass1=='')
		     {
			      alert('Bạn chưa nhập mật khẩu');
			      f1.txtpass1.focus();
		          return false;
		     }
		   var KTPass =/[^\w]/
		     if (KTPass.test(Pass1)== true)
			 {
			    alert('Mật khẩu là các ký tự từ a-z , A-Z , 1-9 ');
				f1.txtpass1.focus();
				return false;
			 } 
		     if (Pass1.length < 6)
			 {
			     alert('Mật khẩu phải nhiều hơn 5 ký tự ');
				 f1.txtpass1.focus();
				 return false;
			 }
		  
		     if(Pass2=='')
		     {
			      alert('Bạn chưa nhập lại mật khẩu');
			      f1.txtpass2.focus();
		          return false;
		     }	
		    if (Pass1 != Pass2)
			{
			      alert('Vui lòng nhập đúng mật khẩu ở trên');
				  f1.txtpass2.focus();
				  return false;
			}		
 //Kiem tra ho ten
        var name=f1.txtname.value;
		    if (name=='')
		    {
		         alert('Bạn chưa nhập họ tên');
			     f1.txtname.focus();
			     return false;
		    } 
  //Kiem tra sinh nhat
        var day=f1.txtday.value;
		var month=f1.txtmonth.value;
		var year=f1.txtyear.value;
		var ktsinhnhat=/[^0-9]/;
		if(day=='')
		{
			alert("Bạn chưa nhập ngày sinh");
			f1.txtday.focus();
			return false;
		}
		 if(month=='')
		{
			alert("Bạn chưa nhập tháng sinh");
			f1.txtmonth.focus();
			return false;
		}
	  	if(month==02)
		{
			if(day>29)
			{
				alert("Ngày không hợp lệ");
				f1.txtday.focus();
				return false;
			}			
		}
		if(month==04 || month==06 || month==09 ||month==11)
		{
			if(day>30)
			{
				alert("Ngày không hợp lệ");
				f1.txtday.focus();
				return false;	
			}			
		}
		if (year=='' )
		{
			alert("Bạn chưa nhập năm sinh");
			f1.txtyear.focus();
			return false;
		}
		if (year >2005 || year <1910)
		{
			alert("Năm không hợp lệ");
			f1.txtyear.focus();
			return false;
		}
  //Kiem tra gioi tinh	
       var ok=false;
		   i=0;
		  for (i;i < f1.sex.length;i++)
		  {
			if (f1.sex[i].checked)
			{
			    ok=true;
			    break;
			}
		  }      
			if (!ok)
			{
				alert('Bạn hãy chọn giới tính');
				f1.sex[0].focus();
				return false;
			} 
  //Kiem tra CMND
      var cmnd=f1.txtcmnd.value
		if (cmnd=='')
		{
			alert("Bạn chưa nhập CMND");
			f1.txtcmnd.focus();
			return false;
		}
		if (cmnd.length != 9)
		{
		   alert("CMND có 9 số");
		   f1.txtcmnd.focus();
		   return false;
		}
		  if (ktsinhnhat.test(cmnd)==true)
		{
			alert("CMND phải là kiểu số");
			f1.txtcmnd.focus();
			return false;
		}
 
 //Kiem tra	dia chi	
        var sonha= f1.txtsonha.value;
		var duong= f1.txtduong.value;
		var phuong= f1.txtphuong.value;
		var quan= f1.txtquan.value;
		var thanhpho= f1.txtthanhpho.value;
	    if(sonha== '')
	      {
		        alert("Bạn chưa nhập số nhà");
		        f1.txtsonha.focus();
		        return false;
	      }
		if(duong== '')
	      {
		        alert("Bạn chưa nhập đường");
		        f1.txtduong.focus();
		        return false;
	      }
		if(phuong== '')
	      {
		        alert("Bạn chưa nhập phường");
		        f1.txtphuong.focus();
		        return false;
	      } 
		 if(thanhpho== '')
	      {
		        alert("Bạn chưa nhập thành phố");
		        f1.txtthanhpho.focus();
		        return false;
	      } 
   //Kiem tra dien thoai di dong
         var mobilephone= f1.txtmobilephone.value;
         var ktphone=/[^0-9]/;
             if (ktphone.test(mobilephone)== true)
	      {
	             alert("Điện thoại phải là kiểu số");
		         f1.txtmobilephone.focus();
		         return false;
	      }	

  //Kiem tra dien thoai
        var phone= f1.txtphone.value;
	       if(phone =='')
	      {
		        alert("Bạn chưa nhập số điện thoại bàn");
		        f1.txtphone.focus();
		        return false;
	      }
	   var ktphone=/[^0-9]/;
	       if (ktphone.test(phone)== true)
	      {
	             alert("Điện thoại phải là kiểu số");
		         f1.txtphone.focus();
		         return false;
	      }	
		  if (phone.length < 6)
		 {
			     alert('Điện thoại bàn phải nhiều hơn 5 ký tự ');
				 f1.txtphone.focus();
				 return false;
		 }  
	 


 //Kiem tra email  
	
	var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i
	var mail=f1.txtemail.value; 
	if(mail=='')	
		  {
			 alert('Bạn chưa nhập Email');
			 f1.txtemail.focus();
			 return false;
		  } 
	if (emailfilter.test(f1.txtemail.value)==false)
	    {
	     alert("Email không hợp lệ ");
	     f1.txtemail.focus();
		 return false;
	    }
return true;		  	      	 				
}
function ktnsp()
{
	var ten=form1.txtname.value;
	if(ten=="")
	{
		alert("Tên Nhóm Sản Phẩm không được để trống !");
		form1.txtname.focus();
		return false;
	}
	return true;
}
function KiemTra_update()
{
  //Kiem tra CMND
      var cmnd=f1.txtcmnd.value
	     var ktcmnd=/[^0-9]/;
	     if (ktcmnd.test(cmnd)==true)
		{
			alert("CMND phải là kiểu số");
			f1.txtcmnd.focus();
			return false;
		}
		if (cmnd.length != 9)
		{
		   alert("CMND có 9 số");
		   f1.txtcmnd.focus();
		   return false;
		}
   //Kiem tra	dia chi	
     	var diachi= f1.txtdiachi.value;
	   	 if(diachi== '')
	      {
		        alert("Bạn chưa nhập thành phố");
		        f1.txtdiachi.focus();
		        return false;
	      } 
		
  //Kiem tra dien thoai di dong
         var mobilephone= f1.txtmobilephone.value;
         var ktphone=/[^0-9]/;
             if (ktphone.test(mobilephone)== true)
	      {
	             alert("Điện thoại phải là kiểu số");
		         f1.txtmobilephone.focus();
		         return false;
	      }	

 //Kiem tra dien thoai ban
        var phone= f1.txtphone.value;
	    var ktphone=/[^0-9]/;
	       if (ktphone.test(phone)== true)
	      {
	             alert("Điện thoại phải là kiểu số");
		         f1.txtphone.focus();
		         return false;
	      }	
		  if (phone.length < 6)
		 {
			     alert('Điện thoại bàn không hợp lệ ');
				 f1.txtphone.focus();
				 return false;
		 }
		 
	 
 //Kiem tra email  
	
	var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i
	var mail=f1.txtemail.value; 
		if (emailfilter.test(f1.txtemail.value)==false)
	    {
	     alert("Email không hợp lệ ");
	     f1.txtemail.focus();
		 return false;
	    }
return true;		  	      	 				
}

function openImageNews(vLink,vHeight,vWidth){
		
		
	var sLink = (typeof(vLink.href) == 'undefined') ? vLink : vLink.href;	
	if (sLink == '')
	{
		return false;
	}
	//vHeight=vLink.href.height
	//vWidth=vLink.href.width
	var winDef = 'status=no,resizable=no,scrollbars=no,toolbar=no,location=no,fullscreen=no,titlebar=yes,height='.concat(vHeight).concat(',').concat('width=').concat(vWidth).concat(',');
	winDef = winDef.concat('top=').concat((screen.height - vHeight)/2).concat(',');
	winDef = winDef.concat('left=').concat((screen.width - vWidth)/2);
	newwin = open('', '_blank', winDef);

	newwin.document.writeln('<title>gameon.com</title><body topmargin="0" leftmargin="0" marginheight="0" marginwidth="0"><p align="center">');
	newwin.document.writeln('<a href="" onClick="window.close(); return false;"><img src="', sLink, '" alt="', 'Dong lai', '" border=0></a>');
	newwin.document.writeln('</p></body>');

	if (typeof(vLink.href) != 'undefined')
	{
		return false;
	}
}

	  function KientraHD()
{         
         
         //Kiem Tra Name
	       var ktname=/\'/;
		   var ktname1=/[\0-9]/;
	       var  name = f1.txtname.value;
		    if( name=='')
			{
			    alert('Bạn chưa nhập họ tên người nhận');
			    f1.txtname.focus();
				return false;
			}
			if (ktname.test(name)==true)
			{
				alert("Tên người nhận không có ký tự  ' ");
			    f1.txtname.focus();
				return false;
			}
			if (ktname1.test(name)==true)
			{
				alert("Tên người nhận không hợp lệ ");
			    f1.txtname.focus();
				return false;
			}
			//Kiem tra Dia chi
			var  address = f1.txtaddress.value;
		    if( address=='')
			{
			    alert('Bạn chưa nhập địa chỉ người nhận');
			    f1.txtaddress.focus();
				return false;
			}
			//Kiem tra dien thoai
           var phone= f1.txtphone.value;
	       if(phone =='')
	       {
		        alert("Bạn chưa nhập số điện thoại người nhận");
		        f1.txtphone.focus();
		        return false;
	       }
	       var ktphone=/[^0-9]/;
	       if (ktphone.test(phone)== true)
	       {
	             alert("Điện thoại phải là kiểu số");
		         f1.txtphone.focus();
		         return false;
	       }	
		   if (phone.length < 6 || phone.length >10)
		   {
			     alert('Số điện thoại không hợp lệ');
				 f1.txtphone.focus();
				 return false;
		   } 		   
		//Kiem tra selected
	      var PTTT=f1.thanhtoan.value;
		     if (PTTT==0)
			 {
			  alert('Bạn chưa chọn hình thức thanh toán');
			  f1.thanhtoan.focus();
			  return false;
			 }

		//Kiem tra ngay nhan
		var date= new Date();
		var ngay=date.getDate();
		var thang=date.getMonth()+1;
		var nam=date.getYear();
		var gio=date.getHours();
		var phut=date.getMinutes();
		var day=f1.txtday.value;
		var month=f1.txtmonth.value;
		var year=f1.txtyear.value;
		var hours=f1.txtgio.value;
		var minutes=f1.txtphut.value
		if(day=='')
		{
			alert("Bạn chưa nhập ngày nhận hàng");
			f1.txtday.focus();
			return false;
		}
		 if(month=='')
		{
			alert("Bạn chưa nhập tháng nhận hàng");
			f1.txtmonth.focus();
			return false;
		}
	  	if(month==02)
		{
			if(day>29)
			{
				alert("Ngày không hợp lệ");
				f1.txtday.focus();
				return false;
			}			
		}
		if(month==04 || month==06 || month==09 ||month==11)
		{
			if(day>30)
			{
				alert("Ngày không hợp lệ");
				f1.txtday.focus();
				return false;	
			}			
		}
		if (year=='' )
		{
			alert("Bạn chưa nhập năm nhận hàng");
			f1.txtyear.focus();
			return false;
		}
		 if(year>nam)
		{
		    alert("Xin lỗi! Chúng tôi chỉ giao hoa vào năm hiện tại");
			f1.txtyear.focus();
			return false;
			
		}
		 if(thang>month)
		{
			alert("Tháng nhận không hợp lệ");
			f1.txtmonth.focus();
			return false;
		} 
		 if(thang==month)
		{
		     if(ngay>day)
			 {
				alert("Ngày nhận không hợp lệ");
				f1.txtday.focus();
				return false;
			}
			
		}	
	//Kiem tra gio nhan
	    if (hours=='' )
		{
			alert("Bạn chưa nhập giờ nhận hàng");
			f1.txtgio.focus();
			return false;
		}
		 if(21<=hours||hours<=5)
		{
			alert("Xin lỗi! Chúng tôi không thể giao hoa vào giờ trên ");
			f1.txtgio.focus();
			return false;
		}
		 if(thang==month)
		{
			if(ngay==day && 15<=gio)
			 {
				alert("Xin lỗi! Chúng tôi chỉ có thể giao hàng vào ngày mai");
				return false;
				
			}
		}	
			
return true;			
}