﻿function CheckTrungPass()
{
	alert("vao day");
	var txtpass = document.getElementById("txtpass");
	var txtpass1 = document.getElementById("txtpass1");
	
	if (txtpass.value == "")
	{
		alert("Bạn chưa nhập mật khẩu. Vui lòng kiểm tra lại.");
		txtpass.focus();
		return false;
	}
	if (txtpass1.value == "")
	{
		alert("Bạn chưa xác nhận lại mật khẩu. Vui lòng kiểm tra lại.");
		txtpass1.focus();
		return false;
	}
	
	if (txtpass.value != txtpass1.value)
	{
		alert("Bạn nhập mật khẩu không trùng nhau. Vui lòng kiểm tra lại.");
		txtpass1.focus();
		return false;
	}
	return true;
}


function loadsizewin()
{
	var wid = document.body.clientWidth;
	SetWidthWin(wid);	
}

function SetWidthWin(wid)
{
   xmlHttp = GetMSXmlHttp();
   xmlHttp.onreadystatechange = function()
   {
     	if(xmlHttp.readyState == 4)
        {
            var value = xmlHttp.responseText; 
			LoadMenu();
		}
		
   }    
   xmlHttp.open("GET","ajax.php?do=setwidth&wid="+wid+"&times="+Math.random(),true);
   xmlHttp.send(null);
}


function checklogin()
{
   xmlHttp = GetMSXmlHttp();
   xmlHttp.onreadystatechange = function()
   {
     	if(xmlHttp.readyState == 4)
        {
			var value = xmlHttp.responseText; 
           	if (value != "0")
			{
				LoadInforLogin();	
			}					
		}		
   }    
   xmlHttp.open("GET","ajax.php?do=checklogin&times="+Math.random(),true);
   xmlHttp.send(null);
}

function LoadInforLogin()
{
   xmlHttp = GetMSXmlHttp();
   xmlHttp.onreadystatechange = function()
   {
     	if(xmlHttp.readyState == 4)
        {
			var value = xmlHttp.responseText; 
           	var menu = document.getElementById("menucontent");
			menu.innerHTML = value;
						
		}		
   }    
   xmlHttp.open("GET","ajax.php?do=checklogin&times="+Math.random(),true);
   xmlHttp.send(null);
}


function CheckMaXacNhan()
{
	var maxacnhan = document.getElementById("txtmaxacnhan");
	if (maxacnhan.value == "")
	{
		alert("Bạn chưa nhập mã xác nhận. Vui lòng kiểm tra lại.");
		maxacnhan.focus();
	}
	else
	{
		LoadCheckImageCode(maxacnhan.value);
	}
}

function LoadCheckImageCode(imagecode)
{
   xmlHttp = GetMSXmlHttp();
   xmlHttp.onreadystatechange = function()
   {
        if(xmlHttp.readyState == 4)
        {
            var value = xmlHttp.responseText; 
            if(!document.all) value = eval(value+""); 
			if(value == 0) 
            {
                alert("Mã xác nhận chưa trùng khớp . Vui lòng nhập lại");
				var maxacnhan = document.getElementById("txtmaxacnhan");
				maxacnhan.focus();
                return false;
            }
        }
   }    
   xmlHttp.open("GET","ajax.php?do=checkImageCode&imagecode="+imagecode+"&times="+Math.random(),true);
   xmlHttp.send(null);
}

function CheckInFor(lan)
{
	var hoten = document.getElementById("txthoten");
	var diachi = document.getElementById("txtdiachi");
	var email = document.getElementById("txtemail");
	var dienthoai = document.getElementById("txtdienthoai");
	var noidung = document.getElementById("txtnoidung");
	var maxacnhan = document.getElementById("txtmaxacnhan");
	//var tieude = document.getElementById("txtmobile");
	//var fax = document.getElementById("txtfax");
	if (hoten.value == "")
	{
		alert("Bạn chưa nhập họ tên. Vui lòng kiểm tra lại.");
		hoten.focus();
		return false;
	}
	if (diachi.value == "")
	{
		alert("Bạn chưa nhập địa chỉ. Vui lòng kiểm tra lại.");
		diachi.focus();
		return false;
	}
	if (email.value == "")
	{
		alert("Bạn chưa nhập email. Vui lòng kiểm tra lại.");
		email.focus();
		return false;
	}
	else
	{
		if(!emailReg.test(email.value))
        {
            alert("Email không được bỏ trống hoặc email không hợp lệ . \nVui lòng kiểm tra lại");
			email.focus();
            return false;
        }   
	}
	if (dienthoai.value == "")
	{
		alert("Bạn chưa nhập điện thoại. Vui lòng kiểm tra lại.");
		dienthoai.focus();
		return false;
	}
	if (noidung.value == "")
	{
		alert("Bạn chưa nhập nội dung liên hệ. Vui lòng kiểm tra lại.");
		noidung.focus();
		return false;
	}
	if (maxacnhan.value == "")
	{
		alert("Bạn chưa nhập mã xác nhận. Vui lòng kiểm tra lại.");
		maxacnhan.focus();
		return false;
	}
	CheckMaXacNhanToSend(maxacnhan.value, hoten.value, diachi.value, email.value, "", dienthoai.value, "", noidung.value, lan);	
}

function CheckMaXacNhanToSend(maxacnhan, hoten, diachi, email, didong, dienthoai, fax, noidung, lan)
{
   xmlHttp = GetMSXmlHttp();
   xmlHttp.onreadystatechange = function()
   {
        if(xmlHttp.readyState == 4)
        {
            var value = xmlHttp.responseText; 
            if(!document.all) value = eval(value+""); 
			if(value == 0) 
            {
                alert("Mã xác nhận chưa trùng khớp . Vui lòng nhập lại");
				var maxacnhan = document.getElementById("txtmaxacnhan");
				maxacnhan.focus();
                return false;
            }
			else
			{
				SendInFor(hoten, diachi, email, didong, dienthoai, fax, noidung, lan);
			}
        }
   }    
   xmlHttp.open("GET","ajax.php?do=checkImageCode&imagecode="+maxacnhan+"&times="+Math.random(),true);
   xmlHttp.send(null);
}

function ResetinFor()
{
	var hoten = document.getElementById("txthoten");
	hoten.value = "";
	hoten.focus();
	var diachi = document.getElementById("txtdiachi");
	diachi.value = "";
	var email = document.getElementById("txtemail");
	email.value = "";
	var dienthoai = document.getElementById("txtdienthoai");
	dienthoai.value = "";
	var noidung = document.getElementById("txtnoidung");
	noidung.value = "";
	var maxacnhan = document.getElementById("txtmaxacnhan");
	maxacnhan.value = "";
	
}

function SendInFor(hoten, diachi, email, didong, dienthoai, fax, noidung, lan)
{
	 xmlHttp = GetMSXmlHttp();
	 xmlHttp.onreadystatechange = function()
	 {
		   if(xmlHttp.readyState == 4)
		   {
			 	var value = xmlHttp.responseText; 
				
				if (eval(value) == 1)
				{
					alert("Thông tin của quý khách đã được gửi. Chúng tôi sẽ trả lời trong thời gian sớm nhất.");
					ResetinFor();
				}
				else
				{
					alert("Có lỗi xảy ra trong quá trình truyền dữ liệu .Vui lòng kiểm tra lại.")	;
				}
				return;
		   }		   
	 }    
	 xmlHttp.open("GET","ajax.php?do=sendinfo&hoten="+encodeURIComponent(hoten)+"&didong="+didong+"&diachi="+encodeURIComponent(diachi)+"&email="+email+"&dienthoai="+dienthoai+"&fax="+fax+"&noidung="+encodeURIComponent(noidung)+"&times="+Math.random(),true);
	 xmlHttp.send(null);	
}

function CheckInForRegist(lan)
{
	var txtpass = document.getElementById("txtpassxacnhan");
	var hoten = document.getElementById("txthoten");
	var diachi = document.getElementById("txtdiachi");
	var email = document.getElementById("txtemail");
	var dienthoai = document.getElementById("txtdienthoai");
	var maxacnhan = document.getElementById("txtmaxacnhan");
	var matkhau = document.getElementById("txtpass");	
	var txttaikhoannh = document.getElementById("txttaikhoannh");
	
	if (hoten.value == "")
	{
		alert("Bạn chưa nhập họ tên. Vui lòng kiểm tra lại.");
		hoten.focus();
		return false;
	}
	if (diachi.value == "")
	{
		alert("Bạn chưa nhập địa chỉ. Vui lòng kiểm tra lại.");
		diachi.focus();
		return false;
	}
	if (email.value != "")
	{
		if(!emailReg.test(email.value))
        {
            alert("Email không hợp lệ . \nVui lòng kiểm tra lại");
			email.focus();
            return false;
        }  
	}	
	else
	{
		alert("Bạn chưa nhập email đăng ký . \nVui lòng kiểm tra lại");
		email.focus();
		return false;
	}
	if (matkhau.value == "")
	{
		alert("Bạn chưa nhập mật khẩu truy cập. Vui lòng kiểm tra lại.");
		matkhau.focus();
		return false;
	}
	
	
	if (txtpass.value == "")
	{
		alert("Bạn chưa xác nhận lại mật khẩu. Vui lòng kiểm tra lại.");
		txtpass.focus();
		return false;
	}
	
	if (matkhau.value != txtpass.value)
	{
		alert("Bạn nhập mật khẩu không trùng nhau. Vui lòng kiểm tra lại.");
		txtpass.focus();
		return false;
	}
	
	if (dienthoai.value == "")
	{
		alert("Bạn chưa nhập điện thoại. Vui lòng kiểm tra lại.");
		dienthoai.focus();
		return false;
	}	
	
	if (maxacnhan.value == "")
	{
		alert("Bạn chưa nhập mã xác nhận. Vui lòng kiểm tra lại.");
		maxacnhan.focus();
		return false;
	}
	CheckMaXacNhanToRegist(maxacnhan.value);
	
	//AddThanhVien(hoten.value, diachi.value, email.value, matkhau.value , dienthoai.value, txttaikhoannh.value, lan);	
}

function CheckMaXacNhanToRegist(maxacnhan)
{
   xmlHttp = GetMSXmlHttp();
   xmlHttp.onreadystatechange = function()
   {
        if(xmlHttp.readyState == 4)
        {
            var value = xmlHttp.responseText; 
			
            if(!document.all) value = eval(value+""); 
			if(eval(value) == 0) 
            {
                alert("Mã xác nhận chưa trùng khớp . Vui lòng nhập lại");
				var maxacnhan = document.getElementById("txtmaxacnhan");
				maxacnhan.focus();
                return false;
            }
			else
			{
				var frm = document.regist;
				frm.submit();	
			}
        }
   }    
   xmlHttp.open("GET","ajax.php?do=checkImageCode&imagecode="+maxacnhan+"&times="+Math.random(),true);
   xmlHttp.send(null);
}

function AddThanhVien(hoten, diachi, email, matkhau , dienthoai, tknh, lan)
{
	xmlHttp = GetMSXmlHttp();
    xmlHttp.onreadystatechange = function()
    {
        if(xmlHttp.readyState == 4)
        {
            var value = xmlHttp.responseText;
			if (eval(value) == 1)
			{
				alert("Bạn đã đăng ký thành công.\nTài khoản của bạn đã kích hoạt.\nCảm ơn bạn đã sử dụng dịch vụ của chúng tôi !")	;
				document.location.href = "cartdetail.php?l="+lan;
			}
			else
			{
				alert("Có lỗi trong quá trình đăng ký thành viên.\n Vui lòng kiểm tra lại.");	
			}
		}
    }
    xmlHttp.open("GET","ajax.php?do=addthanhviens&hoten="+myEscape(hoten)+"&diachi="+myEscape(diachi)+"&email="+email+"&matkhau="+matkhau+"&dienthoai="+dienthoai+"&taikhoannganhang="+tknh+"&times="+Math.random(),true);
    xmlHttp.send(null);	
}

function CheckTrungTenTruyCap()
{
	var tentruycap = document.getElementById("txtemail");
	if (tentruycap.value == "")
	{
		alert("Bạn chưa nhập tên truy cập. Vui lòng kiểm tra lại.");
		tentruycap.focus();
		return false;
	}
	CheckTrungTaiKhoan(tentruycap.value);
}

function CheckTrungTaiKhoan(tentruycap)
{
   xmlHttp = GetMSXmlHttp();
   xmlHttp.onreadystatechange = function()
   {
        if(xmlHttp.readyState == 4)
        {
            var value = xmlHttp.responseText; 
                       	
			if(eval(value) == 0) 
            {
                alert("Email này đã tồn tại. Vui lòng chọn email khác.");
				var tentruycap = document.getElementById("txtemail");
				tentruycap.focus();
                return false;
            }                          
        }
   }    
   xmlHttp.open("GET","ajaxloaddatadetail.php?do=checktrungtaikhoan&tentk="+tentruycap+"&times="+Math.random(),true);
   xmlHttp.send(null);
}

function ResetinForRegist()
{
	var hoten = document.getElementById("txthoten");
	hoten.value = "";
	hoten.focus();
	var diachi = document.getElementById("txtdiachi");
	diachi.value = "";
	var email = document.getElementById("txtemail");
	email.value = "";
	var dienthoai = document.getElementById("txtdienthoai");
	dienthoai.value = "";
	var txttaikhoannh = document.getElementById("txttaikhoannh");
	txttaikhoannh.value = "";
	var maxacnhan = document.getElementById("txtmaxacnhan");
	maxacnhan.value = "";
	var matkhau = document.getElementById("txtpass");
	matkhau.value = "";
}

function Checkdangnhap()
{
	var tentruycap = document.getElementById("username");
	if (tentruycap.value == "")
	{
		alert("Bạn chưa nhập email truy cập. Vui lòng kiểm tra lại.");
		tentruycap.focus();
		return false;
	}
	else
	{
		if(!emailReg.test(tentruycap.value))
        {
            alert("Email không hợp lệ . \nVui lòng kiểm tra lại");
			tentruycap.focus();
            return false;
        }  	
	}
	var matkhau = document.getElementById("password");	
	if (matkhau.value == "")
	{
		alert("Bạn chưa nhập mật khẩu truy cập. Vui lòng kiểm tra lại.");
		matkhau.focus();
		return false;
	}
	
	LoadDangNhap(tentruycap.value,matkhau.value);
}

function Checkdangnhap1()
{
	
}
function Checkdangnhap_rg(lan)
{
	var tentruycap = document.getElementById("username_rg");
	if (tentruycap.value == "")
	{
		alert("Bạn chưa nhập email truy cập. Vui lòng kiểm tra lại.");
		tentruycap.focus();
		return false;
	}
	else
	{
		if(!emailReg.test(tentruycap.value))
        {
            alert("Email không hợp lệ . \nVui lòng kiểm tra lại");
			tentruycap.focus();
            return false;
        }  	
	}
	var matkhau = document.getElementById("password_rg");	
	if (matkhau.value == "")
	{
		alert("Bạn chưa nhập mật khẩu truy cập. Vui lòng kiểm tra lại.");
		matkhau.focus();
		return false;
	}
	
	LoadDangNhap(tentruycap.value,matkhau.value, lan);
}

function LoadDangNhap(tentruycap, matkhau)
{
   xmlHttp = GetMSXmlHttp();
   
   xmlHttp.onreadystatechange = function()
   {
        if(xmlHttp.readyState == 4)
        {
            var value = xmlHttp.responseText; 
			if(_parseInt(value) == "0") 
            {
                alert("Tên truy cập hoặc mật khẩu sai. Vui lòng kiểm tra lại.");
				var tentruycap = document.getElementById("username");
				tentruycap.focus();
                return false;
            }  
			else
			{
				Loadmenuthanhvien(1);
				//window.open(location.reload(true)); //document.location.href = "cartdetail.php";	
			}
        }
   }    
   xmlHttp.open("GET","ajax.php?do=checkdangnhapn&tentruycap="+tentruycap+"&matkhau="+matkhau+"&times="+Math.random(),true);
   xmlHttp.send(null);	
}

function CheckInForRegistEdit(lan)
{
	var hoten = document.getElementById("txthoten");
	var diachi = document.getElementById("txtdiachi");
	//var email = document.getElementById("txtemail");
	var dienthoai = document.getElementById("txtdienthoai");
	var maxacnhan = document.getElementById("txtmaxacnhan");
	var txttaikhoannh = document.getElementById("txttaikhoannh");
		
	if (hoten.value == "")
	{
		alert("Bạn chưa nhập họ tên. Vui lòng kiểm tra lại.");
		hoten.focus();
		return false;
	}
	if (diachi.value == "")
	{
		alert("Bạn chưa nhập địa chỉ. Vui lòng kiểm tra lại.");
		diachi.focus();
		return false;
	}
	
	if (dienthoai.value == "")
	{
		alert("Bạn chưa nhập điện thoại. Vui lòng kiểm tra lại.");
		dienthoai.focus();
		return false;
	}
	

	if (maxacnhan.value == "")
	{
		alert("Bạn chưa nhập mã xác nhận. Vui lòng kiểm tra lại.");
		maxacnhan.focus();
		return false;
	}
	CheckMaXacNhan();
	var frm = document.memberedit;
	frm.submit();
	//EditThanhVien(hoten.value, diachi.value, dienthoai.value, txttaikhoannh.value, lan);	
}

function EditThanhVien(hoten, diachi, dienthoai, taikhoannh, lan)
{
	
	xmlHttp = GetMSXmlHttp();
    xmlHttp.onreadystatechange = function()
    {
        if(xmlHttp.readyState == 4)
        {
            var value = xmlHttp.responseText;
			
			if (eval(value) == 1)
			{
				alert("Thông tin của bạn đã được cập nhật!")	;				
			}
			else if (eval(value) == 0)
			{
				alert("Có lỗi trong quá trình cập nhật dữ liệu.\n Vui lòng kiểm tra lại.");	
			}
			else if (eval(value) == 2)
			{
				alert("Email đăng ký của bạn đã thành viên dược sử dụng.\n Vui lòng kiểm tra lại.");	
			}
		}
    }
    xmlHttp.open("GET","ajax.php?do=editthanhviens&hoten="+myEscape(hoten)+"&diachi="+myEscape(diachi)+"&dienthoai="+dienthoai+"&taikhoannh="+taikhoannh+"&times="+Math.random(),true);
    xmlHttp.send(null);	
}

function ChangePass(lan)
{
	var matkhaucu = document.getElementById("matkhaucu");
	var matkhaumoi = document.getElementById("matkhaumoi");
	var newpass = document.getElementById("newpass");
	
	
	if (matkhaucu.value == "")
	{
		alert("Bạn chưa nhập mật khẩu cũ. Vui lòng kiểm tra lại.");
		matkhaucu.focus();
		return false;
	}
	if (matkhaumoi.value == "")
	{
		alert("Bạn chưa nhập mật khẩu mới. Vui lòng kiểm tra lại.");
		matkhaumoi.focus();
		return false;
	}
	if (newpass.value == "")
	{
		alert("Mật khẩu không hợp lệ . \nVui lòng kiểm tra lại");
		newpass.focus();
		return false;        
	}	
	if (matkhaumoi.value != newpass.value)
	{
		alert("Bạn nhập mật khẩu không trùng nhau. Vui lòng kiểm tra lại.");
		matkhaumoi.focus();
		return false;
	}
	
	xmlHttp = GetMSXmlHttp();
    xmlHttp.onreadystatechange = function()
    {
        if(xmlHttp.readyState == 4)
        {
            var value = xmlHttp.responseText;
			
			if (eval(value) == 1)
			{
				alert("Đã đổi mật khẩu thành công!");
				var obj1 = document.getElementById("infothanhcong");
				var obj2 = document.getElementById("infochange");
				obj2.style.display = 'none';
				obj1.innerHTML = "Đã đổi mật khẩu thành công!";
				obj1.style.display = '';
			}
			else if (eval(value) == -1)
			{
				alert("Bạn nhập mật khẩu cũ không đúng.\n Vui lòng kiểm tra lại.");	
			}
			else
			{
				alert("lỗi trong quá trình cập nhật.\n Vui lòng kiểm thử lại.");	
			}
		}
    }
    xmlHttp.open("GET","ajax.php?do=changepass&matkhaucu="+matkhaucu.value+"&matkhaumoi="+matkhaumoi.value+"&times="+Math.random(),true);
    xmlHttp.send(null);	
}

function CancelEdit(lan)
{
	document.location.href = "memberedit.php?l="+lan;	
}

function Thoat(lan)
{
	xmlHttp = GetMSXmlHttp();
    xmlHttp.onreadystatechange = function()
    {
        if(xmlHttp.readyState == 4)
        {
            var value = xmlHttp.responseText;
			
			if (value == "1")
			{
				document.location.href = "index.php";			
			}			
		}
    }
    xmlHttp.open("GET","ajax.php?do=thoat&times="+Math.random(),true);
    xmlHttp.send(null);	
}

function quayve()
{
	history.back();	
}

//add gio hang phan ca chep nhat
function addtocart(masanpham)
{
   xmlHttp = GetMSXmlHttp();
   xmlHttp.onreadystatechange = function()
   {
        if(xmlHttp.readyState == 4)
        {
            var value = xmlHttp.responseText;   
			if (value == "0")
			{
				alert("Vui lòng đăng nhập thành viên trước khi sử dụng chức năng này hoặc Đăng ký thành viên. \nChân thành cám ơn.")	
				document.location.href = "regist.php";	
			}
			else
			{
			   xmlHttp1 = GetMSXmlHttp();
			   xmlHttp1.onreadystatechange = function()
			   {
					if(xmlHttp1.readyState == 4)
					{
						var value = xmlHttp1.responseText;  
												       
					   if(value == 1)
							alert("Sản phẩm này không tồn tại . Vui lòng xem lại");
						else if(value == 2)
						{
							alert("Sản phẩm bạn chọn đã được thêm vào giỏ hàng.");
							loadSoLuongSanPhamTrongGio(1);
							//document.location.href = "cartdetail.php";	
						}
						else if(value == 3)
						{
							alert("Sản phẩm bạn chọn đã tồn tại trong giỏ hàng rồi.\nVui lòng chọn sản phẩm khác.");	 			
						}
					}
			   }    
			   xmlHttp1.open("GET","ajax.php?do=insertItemIntoCart&masp="+masanpham+"&times="+Math.random(),true);
			   xmlHttp1.send(null);
			}
		
        }
   }    
   xmlHttp.open("GET","ajax.php?do=kiemtradangnhap&times="+Math.random(),true);
   xmlHttp.send(null);
  }
  
  //add gio hang phan thuoc tri ca
function addtocart_thuoctrica(masanpham)
{
   xmlHttp = GetMSXmlHttp();
   xmlHttp.onreadystatechange = function()
   {
        if(xmlHttp.readyState == 4)
        {
            var value = xmlHttp.responseText;   
			if (value == "0")
			{
				alert("Vui lòng đăng nhập thành viên trước khi sử dụng chức năng này hoặc Đăng ký thành viên. \nChân thành cám ơn.")	
				document.location.href = "regist.php";	
			}
			else
			{
			   xmlHttp1 = GetMSXmlHttp();
			   xmlHttp1.onreadystatechange = function()
			   {
					if(xmlHttp1.readyState == 4)
					{
						var value = xmlHttp1.responseText;  
												       
					   if(value == 1)
							alert("Sản phẩm này không tồn tại . Vui lòng xem lại");
						else if(value == 2)
						{
							alert("Sản phẩm bạn chọn đã được thêm vào giỏ hàng.");
							loadSoLuongSanPhamTrongGio(1);
							//document.location.href = "cartdetail.php";	
						}
						else if(value == 3)
						{
							alert("Sản phẩm bạn chọn đã tồn tại trong giỏ hàng rồi.\nVui lòng chọn sản phẩm khác.");	 			
						}
					}
			   }    
			   xmlHttp1.open("GET","ajax.php?do=insertItemIntoCart_thuoctrica&magoithuoc="+masanpham+"&times="+Math.random(),true);
			   xmlHttp1.send(null);
			}
		
        }
   }    
   xmlHttp.open("GET","ajax.php?do=kiemtradangnhap&times="+Math.random(),true);
   xmlHttp.send(null);
  }

	//add gio hang phan cac san pham dieu kien ve nuoc, sach , tap chi, thuc an, dung cu
function addtocart_other(masanpham)
{
   xmlHttp = GetMSXmlHttp();
   xmlHttp.onreadystatechange = function()
   {
        if(xmlHttp.readyState == 4)
        {
            var value = xmlHttp.responseText;   
			if (value == "0")
			{
				alert("Vui lòng đăng nhập thành viên trước khi sử dụng chức năng này hoặc Đăng ký thành viên. \nChân thành cám ơn.")	
				document.location.href = "regist.php";	
			}
			else
			{
			   xmlHttp1 = GetMSXmlHttp();
			   xmlHttp1.onreadystatechange = function()
			   {
					if(xmlHttp1.readyState == 4)
					{
						var value = xmlHttp1.responseText;  
												       
					   if(value == 1)
							alert("Sản phẩm này không tồn tại . Vui lòng xem lại");
						else if(value == 2)
						{
							alert("Sản phẩm bạn chọn đã được thêm vào giỏ hàng.");
							loadSoLuongSanPhamTrongGio(1);
							//document.location.href = "cartdetail.php";	
						}
						else if(value == 3)
						{
							alert("Sản phẩm bạn chọn đã tồn tại trong giỏ hàng rồi.\nVui lòng chọn sản phẩm khác.");	 			
						}
					}
			   }    
			   xmlHttp1.open("GET","ajax.php?do=insertItemIntoCart_other&masp="+masanpham+"&times="+Math.random(),true);
			   xmlHttp1.send(null);
			}
		
        }
   }    
   xmlHttp.open("GET","ajax.php?do=kiemtradangnhap&times="+Math.random(),true);
   xmlHttp.send(null);
  }
  
  //add gio hang phan cac san pham bo sung: cac san pham them tu phan admin
function addtocart_bosung(masanpham)
{
   xmlHttp = GetMSXmlHttp();
   xmlHttp.onreadystatechange = function()
   {
        if(xmlHttp.readyState == 4)
        {
            var value = xmlHttp.responseText;   
			if (value == "0")
			{
				alert("Vui lòng đăng nhập thành viên trước khi sử dụng chức năng này hoặc Đăng ký thành viên. \nChân thành cám ơn.")	
				document.location.href = "regist.php";	
			}
			else
			{
			   xmlHttp1 = GetMSXmlHttp();
			   xmlHttp1.onreadystatechange = function()
			   {
					if(xmlHttp1.readyState == 4)
					{
						var value = xmlHttp1.responseText;  
												       
					   if(value == 1)
							alert("Sản phẩm này không tồn tại . Vui lòng xem lại");
						else if(value == 2)
						{
							alert("Sản phẩm bạn chọn đã được thêm vào giỏ hàng.");
							loadSoLuongSanPhamTrongGio(1);
							//document.location.href = "cartdetail.php";	
						}
						else if(value == 3)
						{
							alert("Sản phẩm bạn chọn đã tồn tại trong giỏ hàng rồi.\nVui lòng chọn sản phẩm khác.");	 			
						}
					}
			   }    
			   xmlHttp1.open("GET","ajax.php?do=insertItemIntoCart_bosung&masp="+masanpham+"&times="+Math.random(),true);
			   xmlHttp1.send(null);
			}
		
        }
   }    
   xmlHttp.open("GET","ajax.php?do=kiemtradangnhap&times="+Math.random(),true);
   xmlHttp.send(null);
  }

//=============================
function loadSoLuongSanPhamTrongGio(lan)
{
   xmlHttp = GetMSXmlHttp();
   xmlHttp.onreadystatechange = function()
   {
        if(xmlHttp.readyState == 4)
        {
            var value = xmlHttp.responseText;   			
			try
            {
                var sl = document.getElementById("slgiohang");
                sl.innerHTML = value;				
            }
            catch(exception)
            {
            } 
			LoadTongTienGioHang(lan);
        }
   }    
   xmlHttp.open("GET","ajax.php?do=getItemFromCart&times="+Math.random(),true);
   xmlHttp.send(null);
}

//=============================
function LoadTongTienGioHang(lan)
{
   xmlHttp = GetMSXmlHttp();
   xmlHttp.onreadystatechange = function()
   {
        if(xmlHttp.readyState == 4)
        {
            var value = xmlHttp.responseText; 
			try
            {
                var tt = document.getElementById("TongTienGioHang");
                tt.innerHTML = value;				
            }
            catch(exception)
            {
            }           
        }
   }    
   xmlHttp.open("GET","ajax.php?do=getTotalmoneyFromCart&l="+lan+"&times="+Math.random(),true);
   xmlHttp.send(null);
}

function CheckSoLuongTonKho(masp)
{
	   var soluong = document.getElementById("txtamount_" + masp);
	   xmlHttp = GetMSXmlHttp();
	   xmlHttp.onreadystatechange = function()
	   {
			if(xmlHttp.readyState == 4)
			{
				var value = xmlHttp.responseText; 
				alert(value);
				var arrval = value.split("@");
				if (eval(arrval[0]) == 1)	//Ton kho con du so luong dat hang
				{
					loadthanhtien(masp);	
				}
				else		//Ton kho khong du so luong de dat hang
				{
					alert("Xin lỗi quý khách, hiện tại số lượng tồn kho của sản phẩm là " + arrval[1] + "\n\nkhông đủ số lượng quý khách yêu cầu. Vui lòng chọn lại.");
					var soluong = document.getElementById("txtamount_" + masp);	
					soluong.value = arrval[1];
					loadthanhtien(masp);	
				}
			}
	   }    
	   xmlHttp.open("GET","ajax.php?do=checktonkho&masp="+masp+"&sldathang="+soluong.value+"&times="+Math.random(),true);
	   xmlHttp.send(null);
}


//Load thanh tien ca chep nhat
function loadthanhtien(masp)
{
	/*var soluong = document.getElementById("txtamount_" + masp);	
	var gia = document.getElementById("price_" + masp);	
	var igia = _parseFloat(gia.value);
	var isl = _parseInt(soluong.value);
	var thanhtien = igia * isl;
	var ott = document.getElementById("thanhtien_" + masp);	
	ott.innerHTML = formatCurrency(thanhtien) + " USD";*/
}

//Load thanh tien thuoc tri ca
function loadthanhtienttc(masp)
{
	/*var soluong = document.getElementById("txtamountttc_" + masp);	
	var gia = document.getElementById("pricettc_" + masp);	
	var igia = _parseFloat(gia.value);
	var isl = _parseInt(soluong.value);
	var thanhtien = igia * isl;
	var ott = document.getElementById("thanhtienttc_" + masp);	
	ott.innerHTML = formatCurrency(thanhtien) + " USD";*/
}

//Load thanh tien cac san pham khac
function loadthanhtienother(masp)
{
	alert("fdsgf fgds");
	/*var soluong = document.getElementById("txtamountother_" + masp);	
	var gia = document.getElementById("priceother_" + masp);	
	var igia = _parseFloat(gia.value);
	var isl = _parseInt(soluong.value);
	var thanhtien = igia * isl;
	var ott = document.getElementById("thanhtienother_" + masp);	
	ott.innerHTML = formatCurrency(thanhtien) + " USD";*/
}

//Load thanh tien cac san pham bo sung
function loadthanhtienbosung(masp)
{
	/*var soluong = document.getElementById("txtamountbosung_" + masp);	
	var gia = document.getElementById("pricebosung_" + masp);	
	var igia = _parseFloat(gia.value);
	var isl = _parseInt(soluong.value);
	var thanhtien = igia * isl;
	var ott = document.getElementById("thanhtienbosung_" + masp);	
	ott.innerHTML = formatCurrency(thanhtien) + " USD";*/
}



function tieptucchonhang(lan)
{
	history.back();
	//document.location. href = "index.php?l="+lan;	
}

//Xoa item gio hang ca chep nhat
function DelCart(lan)
{
	var listsp = document.getElementsByName("chkdel[]");	
	var slistid = "";
	for(var i = 0; i < listsp.length; i++)
	{
		if (listsp[i].checked)
			slistid = slistid + listsp[i].value + ",";
	}
		
	if (slistid == "") return;	
	if (confirm("Bạn có chắc chắn muốn xoá sản phẩm này không?")==true)
	{
		
		xmlHttp = GetMSXmlHttp();
		xmlHttp.onreadystatechange = function()
		{
			 if(xmlHttp.readyState == 4)
			 {
				 var value = xmlHttp.responseText;
				 if (value == "1")
				 	document.location.href = "cartdetail.php?l="+lan;
			 }
		}    
	   xmlHttp.open("GET","ajax.php?do=delcart&listid=" + slistid + "&times="+Math.random(),true);
	   xmlHttp.send(null);
	}	
}

//Xoa item gio hang thuoc tri ca
function DelCartttc()
{
	var listsp = document.getElementsByName("chkdelttc[]");	
	var slistid = "";
	for(var i = 0; i < listsp.length; i++)
	{
		if (listsp[i].checked)
			slistid = slistid + listsp[i].value + ",";
	}
		
	if (slistid == "") return;	
	if (confirm("Bạn có chắc chắn muốn xoá sản phẩm này không?")==true)
	{
		
		xmlHttp = GetMSXmlHttp();
		xmlHttp.onreadystatechange = function()
		{
			 if(xmlHttp.readyState == 4)
			 {
				 var value = xmlHttp.responseText;
				 if (value == "1")
				 	document.location.href = "cartdetail.php";
			 }
		}    
	   xmlHttp.open("GET","ajax.php?do=delcartttc&listid=" + slistid + "&times="+Math.random(),true);
	   xmlHttp.send(null);
	}	
}

//Xoa item gio hang san pham khac
function DelCartother()
{
	var listsp = document.getElementsByName("chkdelother[]");	
	var slistid = "";
	for(var i = 0; i < listsp.length; i++)
	{
		if (listsp[i].checked)
			slistid = slistid + listsp[i].value + ",";
	}
		
	if (slistid == "") return;	
	if (confirm("Bạn có chắc chắn muốn xoá sản phẩm này không?")==true)
	{
		
		xmlHttp = GetMSXmlHttp();
		xmlHttp.onreadystatechange = function()
		{
			 if(xmlHttp.readyState == 4)
			 {
				 var value = xmlHttp.responseText;
				 if (value == "1")
				 	document.location.href = "cartdetail.php";
			 }
		}    
	   xmlHttp.open("GET","ajax.php?do=delcartother&listid=" + slistid + "&times="+Math.random(),true);
	   xmlHttp.send(null);
	}	
}


//Xoa item gio hang san pham bo sung
function DelCartbosung()
{
	var listsp = document.getElementsByName("chkdelbosung[]");	
	var slistid = "";
	for(var i = 0; i < listsp.length; i++)
	{
		if (listsp[i].checked)
			slistid = slistid + listsp[i].value + ",";
	}
		
	if (slistid == "") return;	
	if (confirm("Bạn có chắc chắn muốn xoá sản phẩm này không?")==true)
	{
		
		xmlHttp = GetMSXmlHttp();
		xmlHttp.onreadystatechange = function()
		{
			 if(xmlHttp.readyState == 4)
			 {
				 var value = xmlHttp.responseText;
				 if (value == "1")
				 	document.location.href = "cartdetail.php";
			 }
		}    
	   xmlHttp.open("GET","ajax.php?do=delcartbosung&listid=" + slistid + "&times="+Math.random(),true);
	   xmlHttp.send(null);
	}	
}

//Cap nhat gio hang ca chep nhat
function capnhatgiohang(lan)
{
	getlistsanpham(lan);
}

function getlistsanpham(lan)
{
   xmlHttp = GetMSXmlHttp();
   xmlHttp.onreadystatechange = function()
   {
        if(xmlHttp.readyState == 4)
        {
            var value = xmlHttp.responseText;     
			capnhatsoluong(value, lan);
        }
   }    
   xmlHttp.open("GET","ajax.php?do=getlistitem&times="+Math.random(),true);
   xmlHttp.send(null);
}

//Cap nhat so luong dat hang cua tungmat hang

function capnhatsoluong(listid, lan)
{
	var arrid = listid.split(',');
	var ssoluong = "";
	for(var i = 0; i < arrid.length; i++)
	{
		var soluong = document.getElementById("txtamount_" + arrid[i]);	
		ssoluong = ssoluong + soluong.value + ",";
	}
	setsoluong(listid, ssoluong, lan);
}

function setsoluong(listid, ssoluong, lan)
{
	xmlHttp = GetMSXmlHttp();
   xmlHttp.onreadystatechange = function()
   {
        if(xmlHttp.readyState == 4)
        {
            var value = xmlHttp.responseText;     
			document.location.href = "cartdetail.php?l="+lan;
        }
   }    
   xmlHttp.open("GET","ajax.php?do=setsoluongchogiohang&listsp="+ listid + "&ssoluong="+ ssoluong + "&times="+Math.random(),true);
   xmlHttp.send(null);	
}
//====================== Ket thuc cap nhat gio hang ca chep nhat =================

//Cap nhat gio hang thuoc tri ca
function capnhatgiohangttc()
{
	getlistsanphamttc();
}

function getlistsanphamttc()
{
   xmlHttp = GetMSXmlHttp();
   xmlHttp.onreadystatechange = function()
   {
        if(xmlHttp.readyState == 4)
        {
            var value = xmlHttp.responseText;     
			capnhatsoluongttc(value);
        }
   }    
   xmlHttp.open("GET","ajax.php?do=getlistitemttc&times="+Math.random(),true);
   xmlHttp.send(null);
}

//Cap nhat so luong dat hang cua tungmat hang

function capnhatsoluongttc(listid)
{
	var arrid = listid.split(',');
	var ssoluong = "";
	for(var i = 0; i < arrid.length; i++)
	{
		var soluong = document.getElementById("txtamountttc_" + arrid[i]);	
		ssoluong = ssoluong + soluong.value + ",";
	}
	setsoluongttc(listid, ssoluong);
}

function setsoluongttc(listid, ssoluong)
{
	xmlHttp = GetMSXmlHttp();
   xmlHttp.onreadystatechange = function()
   {
        if(xmlHttp.readyState == 4)
        {
            var value = xmlHttp.responseText;     
			document.location.href = "cartdetail.php";
        }
   }    
   xmlHttp.open("GET","ajax.php?do=setsoluongchogiohangttc&listsp="+ listid + "&ssoluong="+ ssoluong + "&times="+Math.random(),true);
   xmlHttp.send(null);	
}
//====================== Ket thuc cap nhat gio hang thuoc tri ca =================

//Cap nhat gio hang cac san pham khac
function capnhatgiohangother()
{
	getlistsanphamother();
}

function getlistsanphamother()
{
   xmlHttp = GetMSXmlHttp();
   xmlHttp.onreadystatechange = function()
   {
        if(xmlHttp.readyState == 4)
        {
            var value = xmlHttp.responseText;     
			capnhatsoluongother(value);
        }
   }    
   xmlHttp.open("GET","ajax.php?do=getlistitemother&times="+Math.random(),true);
   xmlHttp.send(null);
}

//Cap nhat so luong dat hang cua tungmat hang

function capnhatsoluongother(listid)
{
	var arrid = listid.split(',');
	var ssoluong = "";
	for(var i = 0; i < arrid.length; i++)
	{
		var soluong = document.getElementById("txtamountother_" + arrid[i]);	
		ssoluong = ssoluong + soluong.value + ",";
	}
	setsoluongother(listid, ssoluong);
}

function setsoluongother(listid, ssoluong)
{
   xmlHttp = GetMSXmlHttp();
   xmlHttp.onreadystatechange = function()
   {
        if(xmlHttp.readyState == 4)
        {
            var value = xmlHttp.responseText;     
			document.location.href = "cartdetail.php";
        }
   }    
   xmlHttp.open("GET","ajax.php?do=setsoluongchogiohangother&listsp="+ listid + "&ssoluong="+ ssoluong + "&times="+Math.random(),true);
   xmlHttp.send(null);	
}
//====================== Ket thuc cap nhat gio hang cac san pham khac =================

//Cap nhat gio hang cac san pham bo sung
function capnhatgiohangbosung()
{
	getlistsanphambosung();
}

function getlistsanphambosung()
{
   xmlHttp = GetMSXmlHttp();
   xmlHttp.onreadystatechange = function()
   {
        if(xmlHttp.readyState == 4)
        {
            var value = xmlHttp.responseText;     
			capnhatsoluongbosung(value);
        }
   }    
   xmlHttp.open("GET","ajax.php?do=getlistitembosung&times="+Math.random(),true);
   xmlHttp.send(null);
}

//Cap nhat so luong dat hang cua tungmat hang

function capnhatsoluongbosung(listid)
{
	var arrid = listid.split(',');
	var ssoluong = "";
	for(var i = 0; i < arrid.length; i++)
	{
		var soluong = document.getElementById("txtamountbosung_" + arrid[i]);	
		ssoluong = ssoluong + soluong.value + ",";
	}
	setsoluongbosung(listid, ssoluong);
}

function setsoluongbosung(listid, ssoluong)
{
	xmlHttp = GetMSXmlHttp();
   xmlHttp.onreadystatechange = function()
   {
        if(xmlHttp.readyState == 4)
        {
            var value = xmlHttp.responseText;     
			document.location.href = "cartdetail.php";
        }
   }    
   xmlHttp.open("GET","ajax.php?do=setsoluongchogiohangbosung&listsp="+ listid + "&ssoluong="+ ssoluong + "&times="+Math.random(),true);
   xmlHttp.send(null);	
}
//====================== Ket thuc cap nhat gio hang cac san pham bo sung =================

function dathang(listid)
{
	/*alert(listid);
	var arr = listid.split(',');
	alert(arr);
	if (arr.length > 0)
	{
		for (var i = 0; i < arr.length; i++)
		{
			var obj = document.getElementById("txtamountother_" + arr[i]);
			if (eval(obj.value) < 30)
			{
				alert("Số lượng đặt hàng phải lớn hơn 30. Vui lòng kiểm tra lại");
				obj.focus();
				return false;
			}
		}
	}*/
	kiemtradangnhap();	
}

function kiemtradangnhap()
{
	
	xmlHttp = GetMSXmlHttp();
   xmlHttp.onreadystatechange = function()
   {
        if(xmlHttp.readyState == 4)
        {
            var value = xmlHttp.responseText;   
			
			if (value == "0")
			{
				alert("Vui lòng đăng nhập thành viên trước khi sử dụng chức năng này.\nChân thành cảm ơn.")	
			}
			else
			{
				var obj = document.getElementById("thongtinthanhtoan");	
				obj.style.display = "";		
			}
		
        }
   }    
   xmlHttp.open("GET","ajax.php?do=kiemtradangnhap&times="+Math.random(),true);
   xmlHttp.send(null);	
}

function SendOrder(lan)
{
	var hinhthucthanhtoan = document.getElementById("hinhthucthanhtoan");		
	/*if (txtdiachi.value == "")
	{
		alert("Địa chỉ giao hàng không thể trống. Vui lòng kiểm tra lại.")	;
		return false;
	}*/

	var yeucaukhac = document.getElementById("txtyeucaukhac");	
	var frm = document.cartdetail;
	alert(frm);
	frm.submit();
	
	//Luudonhang(hinhthucthanhtoan.value, yeucaukhac.value, lan);
}

function Luudonhang(hinhthucthanhtoan, yeucaukhac, lan)
{
	xmlHttp = GetMSXmlHttp();
   xmlHttp.onreadystatechange = function()
   {
        if(xmlHttp.readyState == 4)
        {
            var value = xmlHttp.responseText;     
		 	if (value == "1")
			{
				alert("Đã gửi đơn hàng thành công.\nChúng tôi sẽ liên hệ với bạn trong thời gian sớm nhất.\nCảm ơn bạn đã sử dụng dịch vụ của chúng tôi.")
				document.location.href = "shopinghistory.php?l=" + lan;
			}
			else
			{
				alert("Có lỗi xảy ra trong quá trình gửi đơn hàng. Vui lòng xem lại.");	
			}			
        }
   }    
   xmlHttp.open("GET","ajax.php?do=luudonhang&hinhthucthanhtoan="+ encodeURIComponent(hinhthucthanhtoan) + "&yeucaukhac="+ encodeURIComponent(yeucaukhac) + "&times="+Math.random(),true);
   xmlHttp.send(null);	
}

function CancelOrder()
{
	var obj = document.getElementById("thongtinthanhtoan");	
	obj.style.display = "none";
}


function Loadmenu()
{
   xmlHttp = GetMSXmlHttp();
   xmlHttp.onreadystatechange = function()
   {
    	if(xmlHttp.readyState == 4)
        {
			var value = xmlHttp.responseText;		
			var menu = document.getElementById("menu");
			menu.innerHTML = value;			
		}
   }    
   xmlHttp.open("GET","ajax.php?do=loadmenu&times="+Math.random(),true);
   xmlHttp.send(null);	
}



function LoadSub(subid, listcate)
{
	HiddenSub(listcate);
	var menusub = document.getElementById(subid);
	menusub.style.display = '';
}



function HiddenSub(listcate)
{
	var arrcate = listcate.split(",");
	for (var i = 0; i < arrcate.length - 1; i++)
	{		//alert(arrcate[i]);
		var menu = document.getElementById("td" + arrcate[i]);
		menu.style.display = 'none';
	}	
}

function LoadChiTietSanPham(masanpham, lan)
{
   xmlHttp = GetMSXmlHttp();
   xmlHttp.onreadystatechange = function()
   {
    	if(xmlHttp.readyState == 4)
        {
			var value = xmlHttp.responseText;		
			var detailpro = document.getElementById("detailpro");
			detailpro.innerHTML = value;			
		}
   }    
   xmlHttp.open("GET","ajax.php?do=loadchitietsanpham&masanpham="+masanpham+"&lan="+lan+"&times="+Math.random(),true);
   xmlHttp.send(null);		
}

function SearchProduct(lan)
{
	var txtSrc = document.getElementById("txtSearch");
	var nhomsp = document.getElementById("txtnhom");
	document.location.href = "productsearch.php?cid="+ nhomsp.value+ "&txtSrc="+txtSrc.value+"&l="+lan;
}


function Loadmenuthanhvien(lan)
{
   xmlHttp = GetMSXmlHttp();
   xmlHttp.onreadystatechange = function()
   {
    	if(xmlHttp.readyState == 4)
        {
			var value = xmlHttp.responseText;	
			var arrval = value.split('!');
			if (arrval.length > 1)
			{
				if (eval(arrval[0]) != 0)
				{
					var userinfor = document.getElementById("userinfor");
					userinfor.innerHTML = arrval[1];			
				}
			}
		}
   }    
   xmlHttp.open("GET","ajax.php?do=loadmenuthanhvien&lan="+lan+"&times="+Math.random(),true);
   xmlHttp.send(null);	
}

function LoadChiTietDonHang(madonhang,lan)
{
   xmlHttp = GetMSXmlHttp();
   xmlHttp.onreadystatechange = function()
   {
    	if(xmlHttp.readyState == 4)
        {
			var value = xmlHttp.responseText;
			var infor = document.getElementById("Chitietdonhang_" + madonhang);
			infor.style.display = "";
			infor.innerHTML = value;						
		}
   }    
   xmlHttp.open("GET","ajax.php?do=loadchitietdonhang&madonhang=" + madonhang + "&lan="+lan+"&times="+Math.random(),true);
   xmlHttp.send(null);	
}

function SearchTen()
{
	var ten = document.getElementById("txtten");
	var laigiong = document.getElementById("txtlaigiong");
	var gioitinh = document.getElementById("gioitinh");	
	document.location.href = "cachepnhat.php?ten=" + ten.value + "&lg=" + laigiong.value + "&sex=" + gioitinh.value;
}

function SearchMaSo()
{
	var code = document.getElementById("txtmaso");
	document.location.href = "cachepnhat.php?code=" + code.value;
}

function CloseChitiet(madonhang)
{
	var infor = document.getElementById("Chitietdonhang_" + madonhang);
	infor.style.display = "none";	
}

var offsetfromcursorX=12 //Customize x offset of tooltip
var offsetfromcursorY=10 //Customize y offset of tooltip

var offsetdivfrompointerX=10 //Customize x offset of tooltip DIV relative to pointer image
var offsetdivfrompointerY=10 //Customize y offset of tooltip DIV relative to pointer image. Tip: Set it to (height_of_pointer_image-1).

document.write('<div id="dhtmltooltip"></div>') //write out tooltip DIV
document.write('<img id="dhtmlpointer" style = "display:none" src="../image/logojs.gif">') //write out pointer image

var ie=document.all
var ns6=document.getElementById && !document.all
var enabletip=false
if (ie||ns6)
var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : ""

var pointerobj=document.all? document.all["dhtmlpointer"] : document.getElementById? document.getElementById("dhtmlpointer") : ""

function ietruebody()
{
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function ddrivetip(thetext, thewidth, thecolor)
{
	if (ns6||ie)
	{		
		if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px"
		if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor
		tipobj.innerHTML=thetext
		enabletip=true
		return false
	}
}

/*function ddrivetip(prodi, lan, thewidth, thecolor)
{
	xmlHttp = GetMSXmlHttp();
    xmlHttp.onreadystatechange = function()
    {
    	if(xmlHttp.readyState == 4)
        {
			var valuetip = xmlHttp.responseText;		
			if (ns6||ie)
			{
				
				if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px"
				if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor
				tipobj.innerHTML=valuetip
				enabletip=true
				return false
			}	
		}
    }    
    xmlHttp.open("GET","ajax.php?do=loadmotasanpham&masanpham="+prodi+"&lan=" + lan + "&times="+Math.random(),true);
    xmlHttp.send(null);	
}*/

function positiontip(e)
{
	if (enabletip)
	{
		var nondefaultpos=false
		var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
		var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
		//Find out how close the mouse is to the corner of the window
		var winwidth=ie&&!window.opera? ietruebody().clientWidth : window.innerWidth-20
		var winheight=ie&&!window.opera? ietruebody().clientHeight : window.innerHeight-20

		var rightedge=ie&&!window.opera? winwidth-event.clientX-offsetfromcursorX : winwidth-e.clientX-offsetfromcursorX
		var bottomedge=ie&&!window.opera? winheight-event.clientY-offsetfromcursorY : winheight-e.clientY-offsetfromcursorY

		var leftedge=(offsetfromcursorX<0)? offsetfromcursorX*(-1) : -1000

		//if the horizontal distance isn't enough to accomodate the width of the context menu
		if (rightedge<tipobj.offsetWidth)
		{
			//move the horizontal position of the menu to the left by it's width
			tipobj.style.left=curX-tipobj.offsetWidth+"px"
			nondefaultpos=true
		}
		else if (curX<leftedge)
			tipobj.style.left="5px"
		else
		{
			//position the horizontal position of the menu where the mouse is positioned
			tipobj.style.left=curX+offsetfromcursorX-offsetdivfrompointerX+"px"
			pointerobj.style.left=curX+offsetfromcursorX+"px"
		}

		//same concept with the vertical position
		if (bottomedge<tipobj.offsetHeight)
		{
			tipobj.style.top=curY-tipobj.offsetHeight-offsetfromcursorY+"px"
			nondefaultpos=true
		}
		else
		{
			tipobj.style.top=curY+offsetfromcursorY+offsetdivfrompointerY+"px"
			pointerobj.style.top=curY+offsetfromcursorY+"px"
		}
			tipobj.style.visibility="visible"
		if (!nondefaultpos)
			pointerobj.style.visibility="visible"
		else
			pointerobj.style.visibility="hidden"
	}
}

function hideddrivetip()
{
	if (ns6||ie)
	{
		enabletip=false
		tipobj.style.visibility="hidden"
		pointerobj.style.visibility="hidden"
		tipobj.style.left="-1000px"
		tipobj.style.backgroundColor=''
		tipobj.style.width=''
	}

}

function LostPass()
{
	var email = document.getElementById("txtemail");
	if (email.value != "")
	{
		if(!emailReg.test(email.value))
        {
            alert("Email không hợp lệ . \nVui lòng kiểm tra lại");
			email.focus();
            return false;
        }  
	}	
	else
	{
		alert("Bạn chưa nhập địa chỉ email. \nVui lòng kiểm tra lại");
		email.focus();
		return false;
	}
	
   xmlHttp = GetMSXmlHttp();
   xmlHttp.onreadystatechange = function()
   {
    	if(xmlHttp.readyState == 4)
        {
			var value = xmlHttp.responseText;
			if (eval(value) == 1)
			{
				var obj = document.getElementById("infolost");
				obj.style.display = 'none';
				var obj1 = document.getElementById("info");
				obj1.style.display = '';
				obj1.innerHTML = "Bạn vui lòng đợi trong giây lát. Chúng tôi đang gửi mật khẩu mới qua email của bạn.<br>Bạn vui lòng check email để xem thêm thông tin.";
			}
			else
			{
				alert("Email bạn nhập không tồn tại trong hệ thống. Vui lòng nhập email khác.");
				email.focus();
			}
		}
   }    
   xmlHttp.open("GET","ajax.php?do=lostpass&email=" + email.value + "&times="+Math.random(),true);
   xmlHttp.send(null);	
}

function ShowTraLoi(macauhoi)
{
	xmlHttp = GetMSXmlHttp();
    xmlHttp.onreadystatechange = function()
    {
    	if(xmlHttp.readyState == 4)
        {
			var value = xmlHttp.responseText;		
			var arrval = value.split("^");
			if (eval(arrval[0]) != 0)
			{
				var obj1 = document.getElementById("traloi_" + arrval[0]);
				if (obj1.style.display == '')	
					obj1.style.display = 'none';

			}
			var obj = document.getElementById("traloi_" + macauhoi);
			obj.style.display = '';	
			//obj.innerHTML = "<span class = Font_Black>" + arrval[1] + </span>;
		}
    }    
    xmlHttp.open("GET","ajax.php?do=loadtraloi&mahoidap="+ macauhoi + "&times="+Math.random(),true);
    xmlHttp.send(null);	
}


function CheckSoLuongDat(oid)
{
	var obj = document.getElementById("txtamountother_" + oid);
	if (eval(obj.value) < 30)
	{
		alert("Số lượng đặt hàng phải lớn hơn 30. Vui lòng kiểm tra lại");
		obj.focus();
		return false;
	}
}
document.onmousemove=positiontip

function SetDiemQua(sodiem)
{
	var obj = document.getElementById("diemchatluong");	
	obj.value = sodiem;
	
}

function SetDiemService(sodiem)
{
	var obj = document.getElementById("diemdichvu");	
	obj.value = sodiem;	
}



function VoteComment(proid)
{
	var obj = document.getElementById("txtcomment");
	if (obj.value == "")
	{
		alert("Bạn chưa nhập ý kiến đánh giá của mình. Vui lòng kiểm tra lại.")	;
		obj.focus();
		return;
	}
	else
	{
		insertcomment(proid, obj.value);	
	}
}

function insertcomment(proid, commnet)
{
	xmlHttp = GetMSXmlHttp();
    xmlHttp.onreadystatechange = function()
    {
    	if(xmlHttp.readyState == 4)
        {
			var value = xmlHttp.responseText;	
			
			if (eval(value) == 0)
			{
				alert("Vui lòng đăng nhập thành viên trước khi sử dụng chức năng này.");
				return;
			}
			if (eval(value) == 1)
			{
				alert("Có lỗi xảy ra khi lưu ý kiến đánh giá. Vui lòng thử lại.");
				return;
			}
			if (eval(value) == 2)
			{
				alert("Ý kiến đánh giá của bạn đã được ghi nhận. Cảm ơn quý khách");
				
			}
			
		}
    }    
    xmlHttp.open("GET","ajax.php?do=setcomment&proid="+ proid + "&comment=" +encodeURIComponent(commnet)+  "&times="+Math.random(),true);
    xmlHttp.send(null);	
}


function VoteQuality(proid)
{
	var obj = document.getElementById("diemchatluong");
	if (obj.value == "0")
	{
		alert("Bạn chưa nhập số điểm đánh giá của mình. Vui lòng kiểm tra lại.")	;
		return;
	}
	else
	{
		insertdanhgiachatluong(proid, obj.value);	
	}
}

function insertdanhgiachatluong(proid, sodiemcl, sodiemdv, comment, tyid)
{
	xmlHttp = GetMSXmlHttp();
    xmlHttp.onreadystatechange = function()
    {
    	if(xmlHttp.readyState == 4)
        {
			var value = xmlHttp.responseText;
			//alert(value);
			if (eval(value) == 0)
			{
				alert("Vui lòng đăng nhập thành viên trước khi sử dụng chức năng này.");
				return;
			}
			if (eval(value) == 1)
			{
				alert("Có lỗi xảy ra khi lưu ý kiến đánh giá. Vui lòng thử lại.");
				return;
			}
			if (eval(value) == 2)
			{
				alert("Ý kiến đánh giá của bạn đã được ghi nhận. Cảm ơn quý khách");
				document.location.href = "productview.php?proid="+ proid + "&ty="+ tyid;
				/*var obj2 = document.getElementById("txtcomment");
				obj2.value = "";
				var obj1 = document.getElementByID("diemchatluong");
				obj1.value = "0";
				var obj3 = document.getElementByID("diemdichvu");
				obj3.value = "0";*/
				
			}
			if (eval(value) == 3)
			{
				alert("Ý kiến đánh giá của bạn đã tồn tại. Cảm ơn bạn đã nhiệt tình ủng hộ sản phẩm của chúng tôi.");				
			}
		}
    }    
    xmlHttp.open("GET","ajax.php?do=setdiemchatluong&proid="+ proid + "&diemcl=" +sodiemcl+"&diemdv="+ sodiemdv +"&comment="+encodeURIComponent(comment)+ "&times="+Math.random(),true);
    xmlHttp.send(null);	
}


function VoteService(proid)
{
	var obj = document.getElementById("diemdichvu");
	if (obj.value == "0")
	{
		alert("Bạn chưa nhập số điểm đánh giá của mình. Vui lòng kiểm tra lại.")	;
		return;
	}
	else
	{
		insertdanhgiadichvu(proid, obj.value);	
	}
}

function insertdanhgiadichvu(proid, sodiem)
{
	xmlHttp = GetMSXmlHttp();
    xmlHttp.onreadystatechange = function()
    {
    	if(xmlHttp.readyState == 4)
        {
			var value = xmlHttp.responseText;	
			
			if (eval(value) == 0)
			{
				alert("Vui lòng đăng nhập thành viên trước khi sử dụng chức năng này.");
				return;
			}
			if (eval(value) == 1)
			{
				alert("Có lỗi xảy ra khi lưu ý kiến đánh giá. Vui lòng thử lại.");
				return;
			}
			if (eval(value) == 2)
			{
				//alert("Ý kiến đánh giá của bạn đã được ghi nhận. Cảm ơn quý khách");
				
			}
			
		}
    }    
    xmlHttp.open("GET","ajax.php?do=setdiemdichvut&proid="+ proid + "&diem=" +sodiem+  "&times="+Math.random(),true);
    xmlHttp.send(null);
}

function ActionDanhGia(proid, tyid)
{
	var obj = document.getElementById("diemdichvu");
	if (obj.value == "0")
	{
		alert("Bạn chưa nhập số điểm đánh giá dịch vụ của sản phẩm. Vui lòng kiểm tra lại.")	;
		return;
	}
	
	var obj1 = document.getElementById("diemchatluong");
	if (obj1.value == "0")
	{
		alert("Bạn chưa nhập số điểm đánh giá chất lượng của sản phẩm. Vui lòng kiểm tra lại.")	;
		return;
	}
	
	var obj2 = document.getElementById("txtcomment");
	if (obj2.value == "")
	{
		alert("Bạn chưa nhập ý kiến đánh giá của mình. Vui lòng kiểm tra lại.")	;
		obj2.focus();
		return;
	}
	
	insertdanhgiachatluong(proid, obj1.value, obj.value, obj2.value, tyid);	
//	insertdanhgiadichvu(proid, obj1.value);	
	//insertcomment(proid, obj2.value);
}
