// JavaScript Document
var ie45,ns6,ns4,dom,other1;
if (navigator.appName=="Microsoft Internet Explorer") {
  ie45=parseInt(navigator.appVersion)>=4;
} else if (navigator.appName=="Netscape") {
  ns6=parseInt(navigator.appVersion)>=5;
  ns4=parseInt(navigator.appVersion)<5;
} else {
  other1=1>0;
}
dom=ie45 || ns6 || other1;
function doit(id,cha)
{
  el = document.all ? document.all[id] :
    dom ? document.getElementById(id) :
    document.layers[id];
  els = dom ? el.style : el;
	cha_id = document.getElementById(cha);
  if (dom){
    if (els.display == "none")
    {
      els.display = "";
	  cha_id.background = "images/menu_04b.gif";
    }
    else
    {
      els.display = "none";
	  cha_id.background = "images/menu_04a.gif";
	}
  } else if (ns4){
    if (els.display == "show")
    {
      els.display = "hide";
	  cha_id.background = "images/menu_04a.gif";
	}
    else
    {
      els.display = "show";
	  cha_id.background = "images/menu_04b.gif";
	}
  }	
}

function guimail()
{
	if(!isEmpty(document.formDK.Username.value)){
		alert("Vui long nhap vao ten nguoi gui!");
		document.formDK.Username.focus();
		return false;
	}
	return true;
}

function doitAcc(id,cha)
{
	el = document.all ? document.all[id] : dom ? document.getElementById(id) : document.layers[id];
	els = dom ? el.style : el;
	cha_id = document.getElementById(cha);

	if (dom)
	{
		if (els.display == "none")
			els.display = "";
		else
			els.display = "none";
	}
	else if (ns4)
	{
		if (els.display == "show")
			els.display = "hide";
		else
			els.display = "show";
	}
}

function go(X)
{
	if (X != "none")
	{
		self.location= X;
	}
}

function openImage(tenfile)
{
	window.open("largeimage.php?id="+tenfile, "Large", "toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0");
}

function openResult(id)
{
	window.open(id, "Result", "toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1");
}

function openAE(dest)
{
	window.location.href = dest;
	return true;
}

function showTag(name)
{
	if(name.style.display == "none")
		name.style.display = '';
	else
		name.style.display = 'none';
}

function SelectImage(form)
{
	window.open("../library/Image_Select.php?form="+form, "newImage", "top=100,left=100,height=410,width=570,scrollbars=no");
}

function UserImage(form)
{
	var sList = window.open("library/UserImage_Select.php?form="+form, "newImage", "top=100,left=100,height=320,width=400,scrollbars=no");
}

function cpanelSelectImage(form)
{
	var sList = window.open("lib/ImageSelect.php?form="+form, "newImage", "top=100,left=100,height=450,width=570,scrollbars=yes");
}

function cpanelSelectFile(form)
{
	var sList = window.open("panel/lib/FileSelect.php?form="+form, "newImage", "top=100,left=100,height=410,width=570,scrollbars=no");
}

function CheckSerial(f)
{
	if (!isEmpty(document.formDK.Serial.value))
	{
		alert("Vui long nhap so Serial.");
		document.formDK.Serial.focus();
		return false;
	}
	window.open("../functions/CheckSerial.php?form="+f, "Check", "top=350,left=300,height=70,width=350,scrollbars=no");
}

function CheckUser(f)
{
	if (!isEmpty(document.form.Username.value))
	{
		alert("Vui long nhap ten tai khoan.");
		document.form.Username.focus();
		return false;
	}
	window.open("library/CheckUser.php?form="+f, "Check", "top=350,left=300,height=70,width=350,scrollbars=no");
}

function logoClick(id)
{
	window.open("logoClick.php?id="+id, "Logo");
}

function CheckUserAdmin(f)
{
	if (!isEmpty(document.formDK.Username.value))
	{
		alert("Vui long nhap ten tai khoan.");
		document.formDK.Username.focus();
		return false;
	}
	window.open("../functions/CheckUser.php?form="+f, "Check", "top=350,left=300,height=130,width=350,scrollbars=no");
}

function CheckMultiUser(f)
{
	if (!isEmpty(document.formDK.Username.value))
	{
		alert("Vui long nhap ten tai khoan.");
		document.formDK.Username.focus();
		return false;
	}
	window.open("functions/CheckMultiUser.php?form="+f, "Check", "top=350,left=300,height=300,width=350,scrollbars=no");
}


function check_user()
{
	if(!isEmpty(document.formDK.Username.value)){
		alert("Vui long nhap vao ten dang nhap!");
		document.formDK.Username.focus();
		return false;
	}
	if(!isEmpty(document.formDK.Password.value)){
		alert("Vui long nhap vao mat khau dang nhap!");
		document.formDK.Password.focus();
		return false;
	}
	document.formDK.submit();
	
}
function check_user_register()
{
		
	if(!isEmpty(document.formDK.Username.value)){
		alert("Vui long nhap vao ten dang nhap!");
		document.formDK.Username.focus();
		return false;
	}
	if(!isEmpty(document.formDK.Password.value)){
		alert("Vui long nhap vao mat khau dang nhap!");
		document.formDK.Password.focus();
		return false;
	}
	if(!isEmpty(document.formDK.rePassword.value)){
		alert("Vui long nhap lai mat khau!");
		document.formDK.rePassword.focus();
		return false;
	}
	if(document.formDK.Password.value!=document.formDK.rePassword.value){
		alert("Mau khau dang nhap va mat khau xac nhan khong chinh xac!");
		document.formDK.rePassword.focus();
		return false;
	}
	if(!isEmpty(document.formDK.Hoten.value)){
		alert("Vui long Ho va ten!");
		document.formDK.Hoten.focus();
		return false;
	}
	if(!isEmpty(document.formDK.Address.value)){
		alert("Vui long nhap dia chi!");
		document.formDK.Address.focus();
		return false;
	}
	
	if(!isNumber(document.formDK.Telephone.value)){
		alert("Vui long so dien thoai la so!");
		document.formDK.Telephone.focus();
		return false;
	}
	if(!isNumber(document.formDK.Mobile.value)){
		alert("Vui long so di dong la so!");
		document.formDK.Mobile.focus();
		return false;
	}
	if(!isEmpty(document.formDK.IDCardNumber.value)){
		alert("Vui long so cmnd!");
		document.formDK.IDCardNumber.focus();
		return false;
	}
	if(!isNumber(document.formDK.IDCardNumber.value)){
		alert("Vui long so cmnd!");
		document.formDK.IDCardNumber.focus();
		return false;
	}
	if(!isNumber(document.formDK.Fax.value)){
		alert("Vui long so fax la so!");
		document.formDK.Fax.focus();
		return false;
	}
	
	if(!isEmpty(document.formDK.Email.value)){
		alert("Vui long nhap dia chi Email!");
		document.formDK.Email.focus();
		return false;
	}
	if (!isEmail(document.formDK.Email.value))
	{
		  alert("Du lieu khong hop le.\nVui long nhap lai dia chi Email.");
		  document.formDK.Email.focus();
		  return false;
	}
	if(document.formDK.cboProvince.value==0){
		alert("Vui long chon Tinh/TP!");
		document.formDK.cboProvince.focus();
		return false;
	}
	if(document.formDK.cboDistrict.value==0){
		alert("Vui long Quan/Huyen!");
		document.formDK.cboDistrict.focus();
		return false;
	}
	document.formDK.submit();
	
}
function kt_dangtin()
{
	if(!isEmpty(document.formDK.Title.value)){
		alert("Vui long nhap dia chi!");
		document.formDK.Title.focus();
		return false;
	}
	if(!isNumber(document.formDK.Dimension.value)){
		alert("Dien tich phai la so!");
		document.formDK.Dimension.focus();
		return false;
	}
	if(!isEmpty(document.formDK.Dimension.value)){
		alert("Phai nhap dien tich!");
		document.formDK.Dimension.focus();
		return false;
	}

	if(!isNumber(document.formDK.Width.value)){
		alert("Chieu rong phai la so!");
		document.formDK.Width.focus();
		return false;
	}
	if(!isNumber(document.formDK.Height.value)){
		alert("Chieu ngang phai la so!");
		document.formDK.Height.focus();
		return false;
	}
	if(!isNumber(document.formDK.Price.value)){
		alert("Gia phai la so!");
		document.formDK.Price.focus();
		return false;
	}
	if(!isEmpty(document.formDK.Price.value)){
		alert("Phai nhap gia!");
		document.formDK.Price.focus();
		return false;
	}
	if(document.formDK.DVT.value==0){
		alert("Phai chon don vi tinh!");
		document.formDK.DVT.focus();
		return false;
	}
	if(document.formDK.cboDistrict.value==0){
		alert("Phai chon Quan/Huyen!");
		document.formDK.cboDistrict.focus();
		return false;
	}
	if(document.formDK.cboLoainha.value==0){
		alert("Phai chon loai nha!");
		document.formDK.cboLoainha.focus();
		return false;
	}
	if(document.formDK.cboHinhthuc.value==0){
		alert("Phai chon hinh thuc nha!");
		document.formDK.cboHinhthuc.focus();
		return false;
	}
	document.formDK.submit();

}
function kt_dangtin1()
{
	if(!isEmpty(document.formDK.Title.value)){
		alert("Vui long nhap dia chi!");
		document.formDK.Title.focus();
		return false;
	}
	if(!isNumber(document.formDK.Price.value)){
		alert("Gia phai la so!");
		document.formDK.Price.focus();
		return false;
	}
	if(!isEmpty(document.formDK.Price.value)){
		alert("Phai nhap gia!");
		document.formDK.Price.focus();
		return false;
	}
	if(document.formDK.DVT.value==0){
		alert("Phai chon don vi tinh!");
		document.formDK.DVT.focus();
		return false;
	}
	if(document.formDK.cboDistrict.value==0){
		alert("Phai chon Quan/Huyen!");
		document.formDK.cboDistrict.focus();
		return false;
	}
	if(!isNumber(document.formDK.Dimension.value)){
		alert("Dien tich phai la so!");
		document.formDK.Dimension.focus();
		return false;
	}
	if(!isEmpty(document.formDK.Dimension.value)){
		alert("Phai nhap dien tich!");
		document.formDK.Dimension.focus();
		return false;
	}

	if(!isNumber(document.formDK.Width.value)){
		alert("Chieu rong phai la so!");
		document.formDK.Width.focus();
		return false;
	}
	if(!isNumber(document.formDK.Height.value)){
		alert("Chieu ngang phai la so!");
		document.formDK.Height.focus();
		return false;
	}
	if(document.formDK.cboLoainha.value==0){
		alert("Phai chon loai nha!");
		document.formDK.cboLoainha.focus();
		return false;
	}
	if(document.formDK.cboHinhthuc.value==0){
		alert("Phai chon hinh thuc nha!");
		document.formDK.cboHinhthuc.focus();
		return false;
	}
	document.formDK.submit();

}



function kt_change_password()
{
		
	if(!isEmpty(document.formDK.OldPassword.value)){
		alert("Vui long nhap vao Password cu vao!");
		document.formDK.OldPassword.focus();
		return false;
	}
	if(!isEmpty(document.formDK.cmnd.value)){
		alert("Vui long nhap vao so cmnd!");
		document.formDK.cmnd.focus();
		return false;
	}
	if(!isEmpty(document.formDK.Password.value)){
		alert("Vui long nhap lai mat khau!");
		document.formDK.Password.focus();
		return false;
	}
	if(!isEmpty(document.formDK.Retype.value)){
		alert("Vui long nhap lai mat khau!");
		document.formDK.Retype.focus();
		return false;
	}
	if(document.formDK.Password.value!=document.formDK.Retype.value){
		alert("Mau khau dang nhap va mat khau xac nhan khong chinh xac!");
		document.formDK.Retype.focus();
		return false;
	}
	document.formDK.submit();
	
}
function kt_forgot_password()
{
	if (!isEmpty(document.formDK.Email.value))
	{
		  alert("Vui long nhap dia chi Email dang ky!");
		  document.formDK.Email.focus();
		  return false;
	}
	if (!isEmpty(document.formDK.cmnd.value))
	{
		  alert("Vui long nhap so CMND!");
		  document.formDK.cmnd.focus();
		  return false;
	}
	if (!isNumber(document.formDK.cmnd.value))
	{
		  alert("Vui long nhap so CMND phai la so!");
		  document.formDK.cmnd.focus();
		  return false;
	}
	document.formDK.submit();	
}
function SelectFile(form)
{
	window.open("../library/File_Select.php?form="+form, "newFile", "top=100,left=100,height=410,width=570,scrollbars=no");
}

function isEmpty(s)
{
	if(s=="") return false;
	if(s.length==0) return false;
	for(var j=0;j<s.length;j++)
		if(s.charAt(j)!=" ") return true;

	return false;
}

function isNumber(sText)
{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;

   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
}

function isString(sText)
{
   var ValidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-+#@!$%^=.";
   var IsString=true;
   var Char;

   for (i = 0; i < sText.length && IsString == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsString = false;
         }
      }
   return IsString;
}

function isEmail(s)
{
	if(s=="") return true;
	if(s.indexOf(" ")>0) return false;	//email co khoang trang
	if(s.indexOf("@")==-1) return false;	//email khong co dau @
	if(s.indexOf(".")==-1) return false;	//email khong co dau '.'
	if(s.indexOf("..")!=-1) return false;	//email co 2 dau '..' lien tiep
	if(s.indexOf("@")!=s.lastIndexOf("@")) return false;	//email co 2 dau '@'
	if(s.lastIndexOf(".")==s.length-1) return false;	//email co dau '.' cuoi chuoi
	var str="0123456789abcdefghijklmnopqrstuvwxyz+-*&^$#`~=@._";	//email khong thuoc cac ky tu trong str
	for(var j=0;j<s.length;j++)
		if(str.indexOf(s.charAt(j))==-1) return false;
		
	return true;
}

function isLeapYear(nam)
{
	return ((nam % 4 == 0) && (nam % 100 != 0)) || (nam % 400 == 0);
}

function isDate(ngay,thang,nam)
{
	if(ngay=="" || thang=="" || nam=="") return false;
	var songay;
	switch (Number(thang))
	{
		case 1:
		case 3:
		case 5:
		case 7:
		case 8:
		case 10:
		case 12:
			songay=31;
			break;
		case 4:
		case 6:
		case 9:
		case 11:
			songay=30;
			break;
		case 2:
			if (isLeapYear(nam))
				songay=29;
			else
				songay=28;
			break;
	}
	if(ngay > songay) return false;
	return true;
}

function docheckone()
{
	var alen=document.frmList.elements.length;
	var isChecked=true;

	alen=(alen>5)?document.frmList.chkid.length:0;
	if (alen>0)
	{
   		for(var i=0;i<alen;i++)
			if(document.frmList.chkid[i].checked==false)
				isChecked=false;
	}else
	{
			if(document.frmList.chkid.checked==false)
				isChecked=false;
	}				
	document.frmList.chkall.checked=isChecked;
}

function docheck(status,from_)
{

	var alen=document.frmList.elements.length;
	alen=(alen>5)?document.frmList.chkid.length:0;
	if (alen>0)
	{
		for(var i=0;i<alen;i++)
			document.frmList.chkid[i].checked=status;
	}else
	{
		document.frmList.chkid.checked=status;
	}
	if(from_>0)
		document.frmList.chkall.checked=status;
}

function checkInput(chon)
{
	var alen=document.frmList.elements.length;
	var isChecked=false;
	if(chon==0)
	{
		alen=(alen>5)?document.frmList.chkid.length:0;
		if (alen>0)
		{
   			for(var i=0;i<alen;i++)
				if(document.frmList.chkid[i].checked==true)
					isChecked=true;
		}else
		{
			if(document.frmList.chkid.checked==true)
				isChecked=true;
		}
		if (!isChecked)
			alert("Xin vui long chon it nhat 1 mau tin.");
		else
			calculatechon();

		return isChecked;
	}
	else
	{
		calculateAll();
		document.frmList.submit();
	}
} 

function calculatechon()
{			
	var strchon="";
	var alen=document.frmList.elements.length;	
					
	alen=(alen>5)?document.frmList.chkid.length:0;
	if (alen>0)
	{
   		for(var i=0;i<alen;i++)
			if(document.frmList.chkid[i].checked==true)
				strchon+=document.frmList.chkid[i].value+",";
	}
	else
	{
		if(document.frmList.chkid.checked==true)
			strchon=document.frmList.chkid.value;
	}
	document.frmList.chkids.value=strchon;
}

function checkAll(checkname, exby)
{
	for (i = 0; i < checkname.length; i++)
		checkname[i].checked = exby.checked? true:false;
}
function calculateAll()
{
	var strActive="";
	var strUnActive="";
	var checkname = document.frmList.chkActive
	
	for (i = 0; i < checkname.length; i++)
		if(checkname[i].checked==true)
			strActive+=checkname[i].value+",";
	document.frmList.chkact.value=strActive;

	for (i = 0; i < checkname.length; i++)
		if(checkname[i].checked==false)
			strUnActive+=checkname[i].value+",";
	document.frmList.chkunact.value=strUnActive;
}

//onchange listbox
function remove_district()
{
	if(formDK.cboProvince[formDK.cboProvince.selectedIndex].value == "" || (formDK.cboProvince[formDK.cboProvince.selectedIndex].value != "" && formDK.cboDistrict.value == ""))
	{
		for(s=formDK.cboDistrict.length-1;s >= 0;s--)
			formDK.cboDistrict.remove(s);	
	}
}

function display_district()
{
	for(s=formDK.cboDistrict.length-1;s >= 0;s--)
		formDK.cboDistrict.remove(s);	

	if(formDK.cboProvince[formDK.cboProvince.selectedIndex].value != "")
	{
		for (i=0;i<formDK.slthidden_district.length;i++)
		{
			if (formDK.cboProvince[formDK.cboProvince.selectedIndex].value == formDK.slthidden_district[i].value)
			{
				var strTemp = new String(formDK.slthidden_district[i].text);
				vaTemp = strTemp.split("~");

				NewOptItem = new Option(vaTemp[1],vaTemp[0]);
				j = formDK.cboDistrict.length;			  				
				formDK.cboDistrict.options[j] = NewOptItem;
				NewOptItem = null;
			}
		}
	}
}

function display_street()
{
	for(s=formDK.cboStreet.length-1;s >= 0;s--)
		formDK.cboStreet.remove(s);	

	if(formDK.cboDistrict[formDK.cboDistrict.selectedIndex].value != "")
	{
		for (i=0;i<formDK.slthidden_street.length;i++)
		{
			if (formDK.cboDistrict[formDK.cboDistrict.selectedIndex].value == formDK.slthidden_street[i].value)
			{
				var strTemp = new String(formDK.slthidden_street[i].text);
				vaTemp = strTemp.split("~");

				NewOptItem = new Option(vaTemp[1],vaTemp[0]);
				j = formDK.cboStreet.length;			  				
				formDK.cboStreet.options[j] = NewOptItem;
				NewOptItem = null;
			}
		}
	}
}

function display_fromto_street()
{
	for(s=formDK.cboFromToStreet.length-1;s >= 0;s--)
		formDK.cboFromToStreet.remove(s);	

	if(formDK.cboStreet[formDK.cboStreet.selectedIndex].value != "")
	{
		for (i=0;i<formDK.slthidden_fromto_street.length;i++)
		{
			if (formDK.cboStreet[formDK.cboStreet.selectedIndex].value == formDK.slthidden_fromto_street[i].value)
			{
				var strTemp = new String(formDK.slthidden_fromto_street[i].text);
				vaTemp = strTemp.split("~");

				NewOptItem = new Option(vaTemp[1],vaTemp[0]);
				j = formDK.cboFromToStreet.length;			  				
				formDK.cboFromToStreet.options[j] = NewOptItem;
				NewOptItem = null;
			}
		}
	}
}

function display_district_province()
{
 for(s=formDK.cboDistrict01.length-1;s >= 0;s--)
  	formDK.cboDistrict01.remove(s);
	
  	if(formDK.cboProvince01[formDK.cboProvince01.selectedIndex].value != ""){
  		for (i=0;i<formDK.slthidden_district01.length;i++){
  			if (formDK.cboProvince01[formDK.cboProvince01.selectedIndex].value == 
				formDK.slthidden_district01[i].value){
  				var strTemp = new String(formDK.slthidden_district01[i].text);
  				vaTemp = strTemp.split("~");

  				NewOptItem = new Option(vaTemp[1],vaTemp[0]);
  				j = formDK.cboDistrict01.length;			  				
				formDK.cboDistrict01.options[j] = NewOptItem;
  				NewOptItem = null;
  			}
  		}
 	}				
}

function display_details()
{
 for(s=formDK.cboRelativeNews.length-1;s >= 0;s--)
  	formDK.cboRelativeNews.remove(s);
	
  	if(formDK.cboSubCategory[formDK.cboSubCategory.selectedIndex].value != ""){
  		for (i=0;i<formDK.slthidden_district.length;i++){
  			if (formDK.cboSubCategory[formDK.cboSubCategory.selectedIndex].value == 
				formDK.slthidden_district[i].value){
  				var strTemp = new String(formDK.slthidden_district[i].text);
  				vaTemp = strTemp.split("~");

  				NewOptItem = new Option(vaTemp[1],vaTemp[0]);
  				j = formDK.cboRelativeNews.length;			  				
				formDK.cboRelativeNews.options[j] = NewOptItem;
  				NewOptItem = null;
  			}
  		}
 	}				
}

function display_items()
{
 for(s=formDK.cboItem.length-1;s >= 0;s--)
  	formDK.cboItem.remove(s);
	
  	if(formDK.cboProduct[formDK.cboProduct.selectedIndex].value != ""){
  		for (i=0;i<formDK.slthidden_district.length;i++){
  			if (formDK.cboProduct[formDK.cboProduct.selectedIndex].value == 
				formDK.slthidden_district[i].value){
  				var strTemp = new String(formDK.slthidden_district[i].text);
  				vaTemp = strTemp.split("~");

  				NewOptItem = new Option(vaTemp[1],vaTemp[0]);
  				j = formDK.cboItem.length;			  				
				formDK.cboItem.options[j] = NewOptItem;
  				NewOptItem = null;
  			}
  		}
 	}				
}

function display_nhadat()
{
 for(s=formDK.cboNhadat.length-1;s >= 0;s--)
  	formDK.cboNhadat.remove(s);
	
  	if(formDK.cboLoainha[formDK.cboLoainha.selectedIndex].value != ""){
  		for (i=0;i<formDK.slthidden_nhadat.length;i++){
  			if (formDK.cboLoainha[formDK.cboLoainha.selectedIndex].value == 
				formDK.slthidden_nhadat[i].value){
  				var strTemp = new String(formDK.slthidden_nhadat[i].text);
  				vaTemp = strTemp.split("~");

  				NewOptItem = new Option(vaTemp[1],vaTemp[0]);
  				j = formDK.cboNhadat.length;			  				
				formDK.cboNhadat.options[j] = NewOptItem;
  				NewOptItem = null;
  			}
  		}
 	}				
}

function display_district_nhadat()
{
 for(s=formDK.cboNhadat.length-1;s >= 0;s--)
  	formDK.cboNhadat.remove(s);
	
  	if(formDK.cboDistrict01[formDK.cboDistrict01.selectedIndex].value != ""){
  		for (i=0;i<formDK.slthidden_nhadat.length;i++){
  			if (formDK.cboDistrict01[formDK.cboDistrict01.selectedIndex].value == 
				formDK.slthidden_nhadat[i].value){
  				var strTemp = new String(formDK.slthidden_nhadat[i].text);
  				vaTemp = strTemp.split("~");

  				NewOptItem = new Option(vaTemp[1],vaTemp[0]);
  				j = formDK.cboNhadat.length;			  				
				formDK.cboNhadat.options[j] = NewOptItem;
  				NewOptItem = null;
  			}
  		}
 	}				
}

function display_customer()
{
 for(s=formDK.cboCustomer.length-1;s >= 0;s--)
  	formDK.cboCustomer.remove(s);
	
  	if(formDK.cboDistrict[formDK.cboDistrict.selectedIndex].value != ""){
  		for (i=0;i<formDK.slthidden_customer.length;i++){
  			if (formDK.cboDistrict[formDK.cboDistrict.selectedIndex].value == 
				formDK.slthidden_customer[i].value){
  				var strTemp = new String(formDK.slthidden_customer[i].text);
  				vaTemp = strTemp.split("~");

  				NewOptItem = new Option(vaTemp[1],vaTemp[0]);
  				j = formDK.cboCustomer.length;			  				
				formDK.cboCustomer.options[j] = NewOptItem;
  				NewOptItem = null;
  			}
  		}
 	}				
}

function display_customer_district()
{
 for(s=formDK.cboCustomer.length-1;s >= 0;s--)
  	formDK.cboCustomer.remove(s);
	
  	if(formDK.cboDistrict01[formDK.cboDistrict01.selectedIndex].value != ""){
  		for (i=0;i<formDK.slthidden_customer.length;i++){
  			if (formDK.cboDistrict01[formDK.cboDistrict01.selectedIndex].value == 
				formDK.slthidden_customer[i].value){
  				var strTemp = new String(formDK.slthidden_customer[i].text);
  				vaTemp = strTemp.split("~");

  				NewOptItem = new Option(vaTemp[1],vaTemp[0]);
  				j = formDK.cboCustomer.length;			  				
				formDK.cboCustomer.options[j] = NewOptItem;
  				NewOptItem = null;
  			}
  		}
 	}				
}

function display_card_subcategory()
{
 for(s=formDK.cboCard_SubCategory.length-1;s >= 0;s--)
  	formDK.cboCard_SubCategory.remove(s);
	
  	if(formDK.cboCard_Category[formDK.cboCard_Category.selectedIndex].value != ""){
  		for (i=0;i<formDK.slthidden_subcategory.length;i++){
  			if (formDK.cboCard_Category[formDK.cboCard_Category.selectedIndex].value == 
				formDK.slthidden_subcategory[i].value){
  				var strTemp = new String(formDK.slthidden_subcategory[i].text);
  				vaTemp = strTemp.split("~");

  				NewOptItem = new Option(vaTemp[1],vaTemp[0]);
  				j = formDK.cboCard_SubCategory.length;			  				
				formDK.cboCard_SubCategory.options[j] = NewOptItem;
  				NewOptItem = null;
  			}
  		}
 	}				
}

function ktlogin()
{
	if (!isEmpty(document.formDK.User.value))
	{
		alert("Vui long nhap ten dang nhap.");
		document.formDK.User.focus();
		return false;
	}
	if (!isEmpty(document.formDK.Password.value))
	{
		alert("Vui long nhap vao mat khau.");
		document.formDK.Password.focus();
		return false;
	}
	document.formDK.submit();
	return true;
	/*
	if(document.login.ID.value.length<6 || document.login.Pass.value.length<6)
	{
		alert("Ten dang nhap va Password\n - Toi thieu phai la 6 ky tu tro len.\n - Toi da la 20 ky tu.\n - Phai bao gom ca chu cai [A-Z] va chu so [0-9].\n - Khong chua cac ky tu dac biet.");
		document.login.ID.focus();
		return false;
	}

	if(isNumber(document.login.Pass.value) || isString(document.login.Pass.value))
	{
		alert("Ten dang nhap va Password\n - Toi thieu phai la 6 ky tu tro len.\n - Toi da la 20 ky tu.\n - Phai bao gom ca chu cai [A-Z] va chu so [0-9].\n - Khong chua cac ky tu dac biet.");
		document.login.Pass.focus();
		return false;
	}
*/
	
}
function ktChangeMoney()
{
	if (!isEmpty(document.frmList.US.value))
	{
		alert("Vui long nhap ten tai khoan.");
		document.frmList.US.focus();
		return false;
	}
	if (!isEmpty(document.frmList.money.value))
	{
		alert("Vui long nhap so tien.");
		document.frmList.money.focus();
		return false;
	}
	if(!isNumber(document.frmList.money.value))
	{
		alert("Tien phai la so.");
		document.frmList.money.focus();
		return false;
	}
	if(document.frmList.User.value == document.frmList.US.value)
	{
		alert("Nguoi goi va nguoi nhan khong the trung nhau.");
		document.frmList.US.focus();
		return false;
	}
	if( parseInt(document.frmList.TotalMoney.value) < parseInt(document.frmList.money.value))
	{
		alert("Tien trong tai khoan khong du.");
		document.frmList.money.focus();
		return false;
	}
	document.frmList.submit();
}
function CheckChangeUser(f)
{
	if (!isEmpty(document.frmList.US.value))
	{
		alert("Vui long nhap ten tai khoan.");
		document.frmList.US.focus();
		return false;
	}
	window.open("functions/CheckUser.php?form="+f, "Check", "top=350,left=300,height=100,width=350,scrollbars=no");
}


function user_editnow()
{
	if(document.formDK.pass.value=="") {
		alert("Vui long nhap  password !");
		document.formDK.pass.focus();
		return false;
	}
	if(document.formDK.pass1.value=="") {
		alert("Vui long nhap mat khau xac nhan!");
		document.formDK.pass1.focus();
		return false;
	}
	if(document.formDK.pass.value!=document.formDK.pass1.value) {
		alert("Mat khau va mat khau xac nhan ko dung!");
		document.formDK.pass1.focus();
		return false;
	}
	if(document.formDK.name.value=="") {
		alert("Vui long nhap ho ten vao!");
		document.formDK.name.focus();
		return false;
	}
	if(document.formDK.address.value=="") {
		alert("Vui long nhap dia chi!");
		document.formDK.address.focus();
		return false;
	}
	
	if(!isNumber(document.formDK.phone.value)){
		alert("Vui long so dien thoai la so!");
		document.formDK.phone.focus();
		return false;
	}
	if(!isNumber(document.formDK.fax.value)){
		alert("Vui long so fax la so!");
		document.formDK.fax.focus();
		return false;
	}
	if(document.formDK.email.value==0){
		alert("Vui long nhap vao dia chi email!");
		document.formDK.email.focus();
		return false;
	}
	if(!isEmail(document.formDK.email.value)){
		alert("Vui long nhap lai dia chi email!");
		document.formDK.email.focus();
		return false;
	}
	

	document.formDK.submit();

}
function checkAllFields(ref)
{
var chkAll = document.getElementById('checkAll');
var checks = document.getElementsByName('delAnn[]');
var removeHidden = document.getElementById('removeChecked');
var boxLength = checks.length;
var allChecked = false;
var totalChecked = 0;

if ( ref == 1 )
{
	if ( chkAll.checked == true )
	{
		for ( i=0; i < boxLength; i++ )
		checks[i].checked = true;
	}
	else
	{
		for ( i=0; i < boxLength; i++ )
			checks[i].checked = false;
			
	}
}
else
{
	
	for ( i=0; i < boxLength; i++ )
	{
		if ( checks[i].checked == true )
		{
			allChecked = true;

			continue;
		}
		else
		{
			allChecked = false;
			break;
		}
	}
	if ( allChecked == true )
		chkAll.checked = true;
	else
		chkAll.checked = false;
}
for ( j=0; j < boxLength; j++ )
{
	if ( checks[j].checked == true )
		totalChecked++;
}
removeHidden.value = totalChecked;

}
function openTraloi()
{
	if(!Count_check()) return false;
	else
	{
	frmList.action="Account.php?content=2";
	frmList.submit();
	}
}

function openchuyentiep()
{
	if(!Count_check()) return false;
	else
	{
	frmList.action="account.php?_ax=11";
	frmList.submit();
	}
}

function Count_check()
{
var chkAll = document.getElementById('checkAll');
var checks = document.getElementsByName('delAnn[]');
var removeHidden = document.getElementById('removeChecked');
var boxLength = checks.length;
var allChecked = false;
var totalChecked = 0;

for ( j=0; j < boxLength; j++ )
{
	if ( checks[j].checked == true )
		totalChecked++;
}
if(totalChecked>=2 | totalChecked<=0) 
	{
		alert("Ban vui long chon mot tin nhan");
		return false;
	}else{
		return true;
	}
}

function exchange()
	{
		if (!isEmpty(document.formDK.Username.value))
		{
			  alert("Vui long nhap ten tai khoan nguoi nhan.");
			  document.formDK.Username.focus();
			  return false;
		}
		if (!isEmpty(document.formDK.Cash.value))
		{
			  alert("Vui long nhap vao so tien can chuyen.");
			  document.formDK.Cash.focus();
			  return false;
		}
		if (!isNumber(document.formDK.Cash.value))
		{
        	  alert("Du lieu khong hop le.\nVui long chi nhap so tu 0 den 9.");
	          document.formDK.Cash.focus();
    	      return false;
	    }
	document.formDK.submit();
}
function Daxem()
{
	if(!One_Check()) return false;
	frmList.option.value="2";
	frmList.submit();
}
function chuaxem() {
	if(!One_Check()) return false;
	frmList.option.value="3";
	frmList.submit();
}
function One_Check()
{
	var chkAll = document.getElementById('checkAll');
	var checks = document.getElementsByName('delAnn[]');
	var removeHidden = document.getElementById('removeChecked');
	var boxLength = checks.length;
	var allChecked = false;
	var totalChecked = 0;
	for ( j=0; j < boxLength; j++ )
	{
		if ( checks[j].checked == true )
			totalChecked++;
	}
	if(totalChecked<=0) 
	{
		alert("Ban vui long chon mot tin nhan");
		return false;
	}else{
		return true;
	}
}
function Delete_Check() {
	if(!One_Check()) return false;
	frmList.submit();

}
function display_Msg(msg){
	var chkAll = document.getElementById('checkAll');
	var checks = document.getElementsByName('delAnn[]');
	var removeHidden = document.getElementById('removeChecked');
	var boxLength = checks.length;
	var allChecked = false;
	var totalChecked = 0;
	for ( j=0; j < boxLength; j++ )
	{
		if ( checks[j].checked == true )
			totalChecked++;
	}
	if(totalChecked<=0) 
	{
		alert(msg);
		return false;
	}else{
		var subTemp = document.getElementById("cart");
		var id="";
		for(i=0; i < boxLength; i++){
			if(checks[i].checked){
				if(id == ""){
				 id += checks[i].value;
				}else{
					id += ","+checks[i].value;
				}
			}
		}
		subTemp.action="ShoppingCart.php?action=delete&id="+id;
		subTemp.submit();
	}
}
