function viewResult(pro_id, option)
{
  Win = window.open('votes.asp?vote_id='+pro_id+'&option='+option,'view','width=330,height=340,top=null,left=null,alwaysRaised=no,status=no,resizable=no,scrollbars=no,toolbar=0,directories=0,menubar=0,location=0,copyhistory=0');
  Win.focus();
}

function explorer(id,b) 
{
	var i = 0;
	var found = false;
	var len = b.length;
	
	if (len > 1){
		while ((i < len) && !found)
		{
			if ((b[i].style.display == '') && (i != id))
			{			
				b[i].style.display = 'none';
				found = true;
			}
			else i++;
		}
		if (b[id].style.display =='')
			b[id].style.display = 'none';
		else b[id].style.display = '';
	}
	else{
		if (b.style.display =='')
			b.style.display = 'none';
		else b.style.display = '';
	}
}
function toUnicode(str1)
{
  var code, str2 , j=0;
  var len
  while(j<2)
   {
	len=str1.length
	str2=''
	for(var i=0;i<len;i++) 
	 {
      code=str1.charCodeAt(i);
      if(code<128) continue;
      str2 +=str1.substring(0,i) + '&#' + code + ';'
      str1=str1.substring(i+1,str1.length)
      len=str1.length
      i=0
     }
    str1=str2+str1
    j++;
   }
  return str1;
}


function isEmpty(str)

{

	if (str != "")

		while (str.charAt(0) == " ")

			str = str.substr(1, str.length);

	return (str == "")? true : false;

}



function Trim(str)

{

	if (str != "")

		while (str.charAt(0) == " ")

			str = str.substr(1, str.length);

	return str;

}



function inputNumber(number)

{

	var pattern = "0123456789";

	

	if (len != 0)

	{

		var index = 0;

		var len = number.value.length;

		

		while ((index < len) && (len != 0))

			if (pattern.indexOf(number.value.charAt(index)) == -1)

			{

				if (index == len-1)

					number.value = number.value.substring(0, len-1);

				else if (index == 0)

					 	number.value = number.value.substring(1, len);

					 else number.value = number.value.substring(0, index)+number.value.substring(index+1, len);

				index = 0;

				len = number.value.length;

			}

			else index++;

	}

}



function inputPhoneFax(number)

{

	var pattern = "0123456789 -().";

	

	if (len != 0)

	{

		var index = 0;

		var len = number.value.length;

		

		while ((index < len) && (len != 0))

			if (pattern.indexOf(number.value.charAt(index)) == -1)

			{

				if (index == len-1)

					number.value = number.value.substring(0, len-1);

				else if (index == 0)

					 	number.value = number.value.substring(1, len);

					 else number.value = number.value.substring(0, index)+number.value.substring(index+1, len);

				index = 0;

				len = number.value.length;

			}

			else index++;

	}

}



function inputPrice(number)

{

	var pattern = "0123456789,.";

	

	if (len != 0)

	{

		var index = 0;

		var len = number.value.length;

		

		while ((index < len) && (len != 0))

			if (pattern.indexOf(number.value.charAt(index)) == -1)

			{

				if (index == len-1)

					number.value = number.value.substring(0, len-1);

				else if (index == 0)

					 	number.value = number.value.substring(1, len);

					 else number.value = number.value.substring(0, index)+number.value.substring(index+1, len);

				index = 0;

				len = number.value.length;

			}

			else index++;

	}

}

function doCheck(check, state, n)

{

	if (n == 1)

		check.checked = state;

	else

	{

		for (var i = 0; i < n; i++)

			check[i].checked = state;

	}

}



function isDelete(frm, n)
{

	var flag = false;



	if (n == 1)

		flag = frm.checkbox.checked;

	else

	{	

		var i = 0;		

		

		while ((i < n) && (!flag))

		{

			if (frm.checkbox[i].checked)

				flag = true;

			else i++;	

		}

	}	

	if(!flag)

	{
		alert("Xin vui long chon muc muon xoa!");
		return;
	}

	frm.submit();

}



function isEdit(frm, n)

{

	var flag = false;



	if (n == 1)

		flag = frm.checkbox.checked;

	else

	{	

		var i = 0;		

		

		while ((i < n) && (!flag))

		{

			if (frm.checkbox[i].checked)

				flag = true;

			else i++;	

		}

	}	

	if(!flag)

	{

		alert("Xin vui long chon muc muon sua!");

		return;

	}

	frm.submit();

}



function isEmail(email)

{

	if (email == "")

		return false;

	if (email.indexOf(" ") > 0)	

		return false;

	if (email.indexOf("@") == -1)	

		return false;

	if (email.indexOf(".") == -1)	

		return false;

	if (email.indexOf("..") != -1)	

		return false;

	if (email.indexOf("@") != email.lastIndexOf("@"))		

		return false;

		

	var len = email.length;

	

	if (email.lastIndexOf(".") == len-1)

		return false;

	

	var str = "0123456789abcdefghikjlmnopqrstuvwxyz-@._";

	

	for (var index = 0; index < len; index++)

		if (str.indexOf(email.charAt(index)) == -1)

			return false;

			

	var indexDot = 	email.indexOf(".");

	var indexAcsign = email.indexOf("@");

	

	if ((indexDot == indexAcsign-1) || (indexDot-1 == indexAcsign))

		return false;

					

	return true;

}



function chkConfirm(pwd, confirmpwd)

{

	if (pwd.value == "")

	{

		alert("Please choose a password.");

		pwd.focus();

		return false;

	}

	

	if (pwd.value.length < 6)

	{

		alert("Your new password must be at least 6 character.");

		pwd.focus();

		return false;

	}

	

	if ((confirmpwd.value == "") || (pwd.value != confirmpwd.value))

	{

		alert("Your password entries did not math.");

		confirmpwd.focus();

		return false;

	}	

	return true;

}



function chkcommonInfo(name, address, city, zip, country, phone, fax, email, isUser)

{

	if (isEmpty(name.value))

	{

		alert("Please enter your name!");

		name.focus();

		return false;

	}

	

	if (isEmpty(address.value))

	{

		alert("Please enter address!");

		address.focus();

		return false;

	}

	

	if (isEmpty(city.value))

	{

		alert("Please enter city!");

		city.focus();

		return false;

	}

	

	if (isEmpty(zip.value))

	{

		alert("Please enter zip/postal!");

		zip.focus();

		return false;

	}

	

	if (country.selectedIndex == 0)

	{

		alert("Please choose a country!");

		return false;

	}	

	

	if (isUser)

	{

		if (phone.value.length < 7)

		{

			alert("Invalid phone number, please try again");

			phone.focus();

			return false;

		}

		if (!isEmail(email.value))

		{

			alert("Invalid e-mail address, please try again");

			email.focus();

			return false;

		}		

	}

	else

	{

		if ((phone.value != "") && (phone.value.length < 7))

		{

			alert("Invalid phone number, please try again");

			phone.focus();

			return false;

		}

		if ((email.value != "") && (!isEmail(email.value)))

		{

			alert("Invalid e-mail address, please try again");

			email.focus();

			return false;

		}		

	}

	if ((fax.value != "") && (fax.value.length < 7))

	{

		alert("Invalid fax number, please try again");

		fax.focus();

		return false;

	}

	return true;

}



function chkCusInfo(frm, isChk, submitType)

{

	if (!chkcommonInfo(frm.customer, frm.address, frm.city, frm.zip, frm.country, frm.phone, frm.fax, frm.email, true))

	{

		if (submitType)

			return false;

		return;	

	}

	if (isChk)

	{

		if (submitType)

			return chkConfirm(frm.password, frm.confirmpassword);

		if (!chkConfirm(frm.password, frm.confirmpassword))

			return;

	}

	if (submitType)

		return true;

	frm.submit();	

}



function chkUserInfo(frm)

{

	if (!chkcommonInfo(frm.name, frm.address, frm.city, frm.zip, frm.country, frm.phone, frm.fax, frm.email, false))

	return;

	if (isEmpty(frm.username.value))

	{

		alert("Invalid user, please try again");

		frm.username.focus();

		return;

	}

	if (!chkConfirm(frm.password, frm.confirmpassword))

		return;

	frm.submit();	

}
