﻿//------------------------------------------------------------------------
function validEmail(obj) {
	var s = obj.value;
	for (var i=0; i<s.length; i++)
		if (s.charAt(i)==" "){
			return false;
		}
	var elem, elem1;
	elem=s.split("@");
	if (elem.length!=2)	return false;

	if (elem[0].length==0 || elem[1].length==0)return false;

	if (elem[1].indexOf(".")==-1)	return false;

	elem1=elem[1].split(".");
	for (var i=0; i<elem1.length; i++)
		if (elem1[i].length==0)return false;
	return true;
}
//------------------------------------------------------------------------
function testSpaceBar(obj){
	if(obj.value=="")return false;
	else{		
		var s = obj.value;
		var temp = s.split(" ");
		var str = "";
		for(var i=0; i<temp.length; i++)str=str + temp[i];
		if(str==""){
			obj.value = str.substring(0,str.length);
			return false;
		}
	}//else
	return true;
}
//------------------------------------------------------------------------
function validDate(obj) {
	var s = obj.value;
	var unicode;
	for(var i=0;i<s.length; i++){
		unicode = s.charCodeAt(i);
		if(unicode<48 || unicode>57)
			if (unicode!=47)return false;
	}
	if(s.indexOf("/")==-1)return false;

	var elem=s.split("/");
	if(s.length!=0 && (elem[1].length==0 || eval(elem[1])<1 || eval(elem[1])>12))return false;

	var DaysPerMonth;
	switch(eval(elem[1])){
		case 4:
		case 6:
		case 9:
		case 11:{
			DaysPerMonth=30;
			break;}
		case 2:{ 
			if((elem[2]%4 == 0) && ((elem[2]%100 != 0) || (elem[2]%400 == 0)))
				DaysPerMonth=29
			else
				DaysPerMonth=28
			break;
		}
		default:
			DaysPerMonth=31
	}
	if(s.length!=0 && (elem[0].length==0 || eval(elem[0])<1 || eval(elem[0])>eval(DaysPerMonth)))return false;
	if(s.length!=0 && (elem[2].length==0 || eval(elem[2])<1900 || eval(elem[2])>3000))return false;
	return true;
}
//------------------------------------------------------------------------
function isNumber(obj) {
	var s = obj.value;
	s = s.toString();
	if (s.length == 0)
		return false;
	for (var n = 0; n < s.length; n++)
		if (s.substring(n, n+1) < "0" || s.substring(n, n+1) > "9")
			return false;

	return true;
}
//------------------------------------------------------------------------
function isNumberF(obj){
	var sText = obj.value;
	var ValidChars = ".0123456789";
	var Char;
	for (i = 0; i < sText.length; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         return false;
         }
      }
 	return true;
}
//------------------------------------------------------------------------------------------
function validCheckBox(obj){
	var isChecked = false;
	for(var i=0; i<obj.length; i++)
		if (obj[i].checked==true)isChecked = true;
	if(isChecked==false)return false;
	else return true;
}
//------------------------------------------------------------------------------------------
function MM_openBrWindow(theURL,winName,features) { //v2.0
	var mywindow = window.open(theURL,winName,features);
	if (window.focus) {mywindow.focus()}
	return false;
}
//------------------------------------------------------------------------------------------
function ShowHideMenu(divmenu, divicon)
{
    if(!divmenu) return;
    divmenu = document.getElementById(divmenu);
    divicon = document.getElementById(divicon);
    if(!divmenu) return;
    if(divmenu.style.display == "none")
    {
        divmenu.style.display = "";
        divicon.style.backgroundImage = "url('/images/bullet-red-open.gif')";
    }
    else
    {
        divmenu.style.display = "none";
        divicon.style.backgroundImage = "url('/images/bullet-red.gif')";
    }
}
//------------------------------------------------------------------------------------------
function ShowHideMenuSub(divmenu, divicon)
{
    if(!divmenu) return;
    divmenu = document.getElementById(divmenu);
    divicon = document.getElementById(divicon);
    if(!divmenu) return;
    if(divmenu.style.display == "none")
    {
        divmenu.style.display = "";
        divicon.style.backgroundImage = "url('/images/bullet-red-sub-open.gif')";
    }
    else
    {
        divmenu.style.display = "none";
        divicon.style.backgroundImage = "url('/images/bullet-red-sub.gif')";
    }
}
//------------------------------------------------------------------------------------------
function hidestatus()
{
	window.status='';
	return true
}
//------------------------------------------------------------------------------------------
function openform(textbox,textboxsm,smstyle)
{
	newwin=window.open("fupload.asp?textbox="+textbox+"&textboxsm="+textboxsm+"&smstyle="+smstyle, "upload", "toolbar=no,location=no,directories=no,status=no, menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=450,height=100")
}
//------------------------------------------------------------------------------------------
function lopenform(textbox,textboxsm)
{
	newwin=window.open("lupload.asp?textbox="+textbox+"&textboxsm="+textboxsm, "upload", "toolbar=no,location=no,directories=no,status=no, menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=450,height=100")
}
//------------------------------------------------------------------------------------------
function getfilename(textbox,strFilename,textboxsm,strSMFilename){
	textbox = document.getElementById(textbox);
	textboxsm = document.getElementById(textboxsm);
	if(!textbox) return;
	textbox.value = strFilename;
	if(!textboxsm) return;
	textboxsm.value = strSMFilename;
}
//------------------------------------------------------------------------
function checkAll(checkname, exby) {
  for (i = 0; i < checkname.length; i++)
  checkname[i].checked = exby.checked? true:false
}
//------------------------------------------------------------------------
function ShowHideOpt(divmenu)
{
    if(!divmenu) return;
    divmenu = document.getElementById(divmenu);
    if(divmenu.style.display == "none")
    {
        divmenu.style.display = "";
    }
    else
    {
        divmenu.style.display = "none";
    }
}
//------------------------------------------------------------------------
function setStar(si)
{
	for (i=1; i<=si; i++) 
      {
      	  stari = document.getElementById("s"+i);
      	  stari.src = "/images/staron.png";
      }
	for (i=10; i>si; i--) 
      {
      	  stari = document.getElementById("s"+i);
      	  stari.src = "/images/staroff.png";
      }
}
//------------------------------------------------------------------------
function setStari(si)
{
	document.vote.star.value = si;
}
//------------------------------------------------------------------------
function resetStar()
{
    	si = document.vote.star.value;
		for (i=1; i<=si; i++) 
	      {
	      	  stari = document.getElementById("s"+i);
	      	  stari.src = "/images/staron.png";
	      }
		for (i=10; i>si; i--) 
	      {
	      	  stari = document.getElementById("s"+i);
	      	  stari.src = "/images/staroff.png";
	      }
}
//------------------------------------------------------------------------
function ssetStar(si)
{
	for (i=1; i<=si; i++) 
      {
      	  stari = document.getElementById("ss"+i);
      	  stari.src = "/images/staron.png";
      }
	for (i=10; i>si; i--) 
      {
      	  stari = document.getElementById("ss"+i);
      	  stari.src = "/images/staroff.png";
      }
}
//------------------------------------------------------------------------
function ssetStari(si)
{
	document.svote.sstar.value = si;
}
//------------------------------------------------------------------------
function sresetStar()
{
    	si = document.svote.sstar.value;
		for (i=1; i<=si; i++) 
	      {
	      	  stari = document.getElementById("ss"+i);
	      	  stari.src = "/images/staron.png";
	      }
		for (i=10; i>si; i--) 
	      {
	      	  stari = document.getElementById("ss"+i);
	      	  stari.src = "/images/staroff.png";
	      }
}
//-------------------------------------------------------------------------------------------
function doComment(){
	if(!testSpaceBar(document.postcmd.tieude)){
		alert("Vui lòng nhập tiêu đề nhận xét.");
		document.postcmd.tieude.focus();
		return false;
	}
	if(!testSpaceBar(document.postcmd.noidung)){
		alert("Vui lòng nhập nội dung đánh giá.");
		document.postcmd.noidung.focus();
		return false;
	}
	if(!validEmail(document.postcmd.email)){
		alert("Vui lòng nhập email của bạn.");
		document.postcmd.email.focus();
		return false;
	}
}
//-------------------------------------------------------------------------------------------
function logIn(){
	var login = document.login;
	if(!validEmail(login.emaillogin)){
		alert("Vui lòng nhập email đăng nhập.");
		login.emaillogin.focus();
		return false;
	}
	if(!testSpaceBar(login.passwordlogin)){
		alert("Vui lòng nhập mật khẩu.");
		login.passwordlogin.focus();
		return false;
	}
}
//-------------------------------------------------------------------------------------------
function getPass(){
	var login = document.getpass;
	if(!validEmail(login.emaillogin)){
		alert("Vui lòng nhập email đăng nhập.");
		login.emaillogin.focus();
		return false;
	}
}
//-------------------------------------------------------------------------------------------
function doReg(){
	var register = document.register;
	if(!validEmail(register.email)){
		alert("Vui lòng nhập email đăng nhập.");
		register.email.focus();
		return false;
	}
	if(!testSpaceBar(register.password)){
		alert("Vui lòng nhập mật khẩu.");
		register.password.focus();
		return false;
	}
	if(!testSpaceBar(register.hoten)){
		alert("Vui lòng cho biết tên của quý khách.");
		register.hoten.focus();
		return false;
	}
	if(!testSpaceBar(register.diachi)){
		alert("Vui lòng cho biết địa chỉ liên hệ.");
		register.diachi.focus();
		return false;
	}
	if(!testSpaceBar(register.dienthoai)){
		alert("Vui lòng cho biết số điện thoại liên hệ.");
		register.dienthoai.focus();
		return false;
	}
}
//-------------------------------------------------------------------------------------------
function doRegSend(){
	var sendto = document.sendto;
	if(!testSpaceBar(sendto.hoten)){
		alert("Vui lòng cho biết tên của người nhận.");
		sendto.hoten.focus();
		return false;
	}
	if(!testSpaceBar(sendto.diachi)){
		alert("Vui lòng cho biết địa chỉ giao hàng.");
		sendto.diachi.focus();
		return false;
	}
	if(!testSpaceBar(sendto.dienthoai)){
		alert("Vui lòng cho biết số điện thoại liên hệ.");
		sendto.dienthoai.focus();
		return false;
	}
}
//-------------------------------------------------------------------------------------------
function goLink(obj){
	var url = obj.options[obj.selectedIndex].value;
	window.open(url);
}
//-------------------------------------------------------------------------------------------
function goVote(){
	var frm=document.voteweb;
	if(!validCheckBox(frm.bid)){
		alert("Vui lòng chọn 1 kết quả.");
		frm.bid.focus();
		return false;
	}
	var w = window.open('about:blank','Popup_Window','toolbar=no,location=no,directories=no,status=no,menubar=no,sc rollbars=no,resizable=no,copyhistory=no,width=400,height=260,t op=20,left=100');
	frm.target = 'Popup_Window';
	return true;
}
