var xml;
function loaddulieu(giatri,tenham)
{
	if(giatri=='')
		return;
	xml=phuongthuc();
	if (xml==null)
	{
		alert ("Browser does not support HTTP Request !");
		return;
	}
	dulieu="diachi="+giatri+"&sid="+Math.random();
	xml.onreadystatechange=tenham;
	xml.open("POST","/ajax.php",true);
	xml.send(dulieu);
}
function phuongthuc()
{ 
	var giatri=null;
	if (window.XMLHttpRequest)
	{
		giatri=new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{
		giatri=new ActiveXObject("Microsoft.XMLHTTP");
	}
	return giatri;
}
function kiemtra_dangnhap()
{
	tb_dangnhap=document.getElementById('thongbao_dangnhap');
	tb_dangnhap.innerHTML="";
	email=document.form_dangnhap.email.value;
	password=document.form_dangnhap.password.value;
	if(email=='')
		tb_dangnhap.innerHTML="<img src='/images/loi.gif'> Quý Khách chưa nhập Email !";
	else if(password=='')
		tb_dangnhap.innerHTML="<img src='/images/loi.gif'> Quý Khách chưa nhập mật khẩu !";
	else if(email.indexOf("@")==-1 || email.indexOf(".")==-1)
		tb_dangnhap.innerHTML="<img src='/images/loi.gif'> Email của Quý Khách không hợp lệ !";
	else if(password.length<6)
		tb_dangnhap.innerHTML="<img src='/images/loi.gif'> Mật khẩu của Quý Khách nhỏ hơn 6 ký tự !";
	else
		loaddulieu(email+'##'+password+'##log_in',dangnhap);
}
function dangnhap()
{
	tb_dangnhap=document.getElementById('thongbao_dangnhap');
	tb_dangnhap.innerHTML="<img src='/images/loading_small.gif'>";
	document.form_dangnhap.email.disabled=true;
	document.form_dangnhap.password.disabled=true;
	document.form_dangnhap.submit_.disabled=true;
	if(xml.readyState==4 || xml.readyState=="complete")
	{
		document.form_dangnhap.email.disabled=false;
		document.form_dangnhap.password.disabled=false;
		document.form_dangnhap.submit_.disabled=false;
		if(xml.responseText=='thanhcong')
		{
			document.getElementById('div_dangnhap').className='body_dangnhap cangiua';
			document.getElementById('div_dangnhap').innerHTML='Đăng nhập thành công !<br>Xin vui lòng đợi trong giây lát';
			window.location=window.location;
			window.location.reload();
		}
		else			
			tb_dangnhap.innerHTML="<img src='/images/loi.gif'> "+xml.responseText;
	}
}
function dangxuat()
{
	document.getElementById('div_dadangnhap').className='body_dangnhap cangiua';
	document.getElementById('div_dadangnhap').innerHTML='Đang đăng xuất. . . <br>Xin vui lòng đợi trong giây lát';
	if(xml.readyState==4 || xml.readyState=="complete")
	{
		if(xml.responseText!='thanhcong')
			alert('Có lỗi xảy ra ! Không thể đăng xuất.');
		window.location=window.location;
		window.location.reload();
	}
}
function hienbang(lenh)
{
	div_tb=document.getElementById('div_thongbao');
	if(lenh=='bat')
	{
		div_tb.innerHTML="<img src='/images/loading.gif'><br>Đang thực hiện . . .";
		rong=200;
		//cachtren=(screen.height/2)-190;
		//cachtrai=screen.width/2-(rong/2);	
		cachtren=document.body.scrollTop+(window.document.body.clientHeight/2);
		cachtrai=(window.document.body.clientWidth/2)-(rong/2);
		div_tb.style.marginTop=cachtren+'px';
		div_tb.style.marginLeft=cachtrai+'px';
		div_tb.style.width=rong+'px';
		div_tb.className='thongbao';
	}
	else
		div_tb.className='tat';
}
function hienbang1(lenh)
{
	if(lenh=='bat')
	{		
		document.getElementById('tieude_bangcapnhat').innerHTML='';
		document.getElementById('noidung_bangcapnhat').innerHTML="<img src='/images/loading.gif'><br>Đang thực hiện . . .";
		rong=200;
		cachtren=document.body.scrollTop+(window.document.body.clientHeight/2)-150;
		cachtrai=(window.document.body.clientWidth/2)-(rong/2);				
		document.getElementById('bangcapnhat').style.marginTop=cachtren+'px';
		document.getElementById('bangcapnhat').style.marginLeft=cachtrai+'px';
		document.getElementById('bangcapnhat').style.width=rong+'px';
		document.getElementById('bangcapnhat').className='bang_thongbao';
	}
	else
		document.getElementById('bangcapnhat').className='tat';
}
function set_active(menu_id,type)
{
	menu_active=document.getElementById("menu_"+menu_id);
	menu_dangactive=document.getElementById("menu_"+temp_menu);
	if(type==1)
	{
		menu_active.className='hientai';
		if(menu_id!=temp_menu)
			menu_dangactive.className='';
	}
	else
	{
		menu_active.className='';
		menu_dangactive.className='hientai';
	}
}
function tenduongdan(ten)
{
	document.getElementById('ten_duongdan').innerHTML=ten;
}
function doitrang_thongbaors(trang)
{
	loaddulieu(trang+'##doitrang_tb_rs',doithongbao_rs);
}
function doithongbao_rs()
{
	hienbang('bat');
	if(xml.readyState==4 || xml.readyState=="complete")
	{
		hienbang('tat');
		document.getElementById('tb_rs').innerHTML=xml.responseText;
		window.location="#tb_moi";
	}
}
function bat_tienich(ten_id)
{
	document.getElementById('gioithieu').className='tat';
	document.getElementById('rsm').className='tat';
	document.getElementById('rsu').className='tat';
	document.getElementById(ten_id).className='bat';
}
function bat_tienich_mg(ten_id)
{
	document.getElementById('mg_manager').className='tat';
	document.getElementById('mg_toolbar').className='tat';
	document.getElementById('mg_filebox').className='tat';
	document.getElementById(ten_id).className='candeu cao7px';
}
function mo_faq(ten_id)
{
	id_faq=document.getElementById('_'+ten_id).className;
	if(id_faq=='tat')
		document.getElementById('_'+ten_id).className='cachtrenduoi7px';
	else
		document.getElementById('_'+ten_id).className='tat';
}
function kt_doimatkhau()
{
	tbdoimatkhau=document.getElementById('tb_doimatkhau');
	tbdoimatkhau.innerHTML="";
	mk_cu=document.form_doimatkhau.matkhaucu.value;
	mk_moi=document.form_doimatkhau.matkhaumoi.value;
	mk_moi2=document.form_doimatkhau.matkhaumoi2.value;
	if(mk_cu=='')
		tbdoimatkhau.innerHTML="<img src='/images/loi.gif'> Quý Khách chưa nhập mật khẩu cũ !";
	else if(mk_cu.length<6)
		tbdoimatkhau.innerHTML="<img src='/images/loi.gif'> Mật khẩu cũ của Quý Khách nhỏ hơn 6 ký tự !";
	else if(mk_moi=='')
		tbdoimatkhau.innerHTML="<img src='/images/loi.gif'> Quý Khách chưa nhập mật khẩu mới !";
	else if(mk_moi2=='')
		tbdoimatkhau.innerHTML="<img src='/images/loi.gif'> Quý Khách chưa nhập lại mật khẩu mới !";
	else if(mk_moi2!=mk_moi)
		tbdoimatkhau.innerHTML="<img src='/images/loi.gif'> Mật khẩu mới không trùng nhau !";
	else if(mk_moi.length<6)
		tbdoimatkhau.innerHTML="<img src='/images/loi.gif'> Mật khẩu mới của Quý Khách nhỏ hơn 6 ký tự !";
	else if(mk_moi2==mk_cu)
		tbdoimatkhau.innerHTML="<img src='/images/loi.gif'> Mật khẩu và mật khẩu cũ giống nhau !";
	else
		loaddulieu(mk_cu+'##'+mk_moi+'##'+mk_moi2+'##doimatkhau',doimatkhau);
}
function doimatkhau()
{
	tbdoimatkhau=document.getElementById('tb_doimatkhau');
	tbdoimatkhau.innerHTML="<img src='/images/loading_small.gif'>";
	document.form_doimatkhau.matkhaucu.disabled=true;
	document.form_doimatkhau.matkhaumoi.disabled=true;
	document.form_doimatkhau.matkhaumoi2.disabled=true;
	document.form_doimatkhau.submit_.disabled=true;
	if(xml.readyState==4 || xml.readyState=="complete")
	{
		document.form_doimatkhau.matkhaucu.disabled=false;
		document.form_doimatkhau.matkhaumoi.disabled=false;
		document.form_doimatkhau.matkhaumoi2.disabled=false;	
		document.form_doimatkhau.submit_.disabled=false;
		if(xml.responseText=='thanhcong')
			document.getElementById('div_doimatkhau').innerHTML="Xin chúc mừng ! Bạn đã đổi mật khẩu thành công.";
		else			
			tbdoimatkhau.innerHTML="<img src='/images/loi.gif'> "+xml.responseText;
	}
}
function kt_doittcn()
{
	tbdoittcn=document.getElementById('tb_doittcn');
	tbdoittcn.innerHTML="";
	ho_ten=document.form_doittcn.hovaten.value;
	dia_chi=document.form_doittcn.diachi.value;
	so_dt=document.form_doittcn.sodienthoai.value;
	if(ho_ten=='')
		tbdoittcn.innerHTML="<img src='/images/loi.gif'> Quý Khách chưa nhập họ và tên !";
	else if(dia_chi=='')
		tbdoittcn.innerHTML="<img src='/images/loi.gif'> Quý Khách chưa nhập địa chỉ !";
	else if(so_dt=='')
		tbdoittcn.innerHTML="<img src='/images/loi.gif'> Quý Khách chưa nhập số điện thoại !";
	else if(so_dt.length<7)
		tbdoittcn.innerHTML="<img src='/images/loi.gif'> Số điện thoại của Quý Khách nhỏ hơn 7 ký tự !";
	else
		loaddulieu(ho_ten+'##'+dia_chi+'##'+so_dt+'##doittcn',doittcn);
}
function doittcn()
{
	tbdoittcn=document.getElementById('tb_doittcn');
	tbdoittcn.innerHTML="<img src='/images/loading_small.gif'>";
	document.form_doittcn.hovaten.disabled=true;
	document.form_doittcn.diachi.disabled=true;
	document.form_doittcn.sodienthoai.disabled=true;
	document.form_doittcn.submit_.disabled=true;
	if(xml.readyState==4 || xml.readyState=="complete")
	{
		document.form_doittcn.hovaten.disabled=false;
		document.form_doittcn.diachi.disabled=false;
		document.form_doittcn.sodienthoai.disabled=false;
		document.form_doittcn.submit_.disabled=false;
		if(xml.responseText=='thanhcong')
			document.getElementById('div_doittcn').innerHTML="Xin chúc mừng ! Bạn đã đổi thông tin cá nhân thành công.";
		else			
			tbdoittcn.innerHTML="<img src='/images/loi.gif'> "+xml.responseText;
	}
}
function kt_doiemail()
{
	email_moi=document.form_doiemail.email_moi.value;
	if(email_moi=='')
		document.getElementById('tb_doiemail').innerHTML="<img src='/images/loi.gif'> Quý Khách chưa nhập email mới !";
	else if(email_moi.indexOf("@")==-1 || email_moi.indexOf(".")==-1)
		document.getElementById('tb_doiemail').innerHTML="<img src='/images/loi.gif'> Email của Quý Khách không hợp lệ !";
	else
			loaddulieu(email_moi+'##doiemail',doiemail);	
}
function doiemail()
{
	tbdoiemail=document.getElementById('tb_doiemail');
	tbdoiemail.innerHTML="<img src='/images/loading_small.gif'>";
	document.form_doiemail.email_moi.disabled=true;
	document.form_doiemail.submit_.disabled=true;
	if(xml.readyState==4 || xml.readyState=="complete")
	{
		document.form_doiemail.email_moi.disabled=false;
		document.form_doiemail.submit_.disabled=false;
		if(xml.responseText=='thanhcong')
			document.getElementById('div_doiemail').innerHTML="Xin chúc mừng ! Bạn đã đổi Email thành công.";
		else			
			tbdoiemail.innerHTML="<img src='/images/loi.gif'> "+xml.responseText;
	}
}
function kt_lienhe()
{
	tblienhe=document.getElementById('tb_lienhe');
	tblienhe.innerHTML="";
	oj_hovaten=document.form_lienhe.hovaten.value;
	oj_diachi=document.form_lienhe.diachi.value;
	oj_sodienthoai=document.form_lienhe.sodienthoai.value;
	oj_email=document.form_lienhe.email.value;
	oj_tieude=document.form_lienhe.tieude.value;
	oj_noidung=document.form_lienhe.noidung.value;
	oj_tuxung=document.form_lienhe.tuxung.value;
	if(oj_hovaten=='')
		tblienhe.innerHTML="<img src='/images/loi.gif'> Quý Khách chưa nhập họ và tên !";
	else if(oj_email=='')
		tblienhe.innerHTML="<img src='/images/loi.gif'> Quý Khách chưa nhập Email !";
	else if(oj_email.indexOf("@")==-1 || oj_email.indexOf(".")==-1)
		tblienhe.innerHTML="<img src='/images/loi.gif'> Email của Quý Khách không hợp lệ !";
	else if(oj_tieude=='')
		tblienhe.innerHTML="<img src='/images/loi.gif'> Quý Khách chưa nhập tiêu đề !";
	else if(oj_noidung=='')
		tblienhe.innerHTML="<img src='/images/loi.gif'> Quý Khách chưa nhập nội dung!";
	else
		loaddulieu(oj_hovaten+'##'+oj_diachi+'##'+oj_sodienthoai+'##'+oj_email+'##'+oj_tieude+'##'+oj_noidung+'##'+oj_tuxung+'##lienhe_gopy',lienhe);
}
function lienhe()
{
	tblienhe=document.getElementById('tb_lienhe');
	tblienhe.innerHTML="<img src='/images/loading_small.gif'>";
	document.form_lienhe.hovaten.disabled=true;
	document.form_lienhe.diachi.disabled=true;
	document.form_lienhe.sodienthoai.disabled=true;
	document.form_lienhe.email.disabled=true;
	document.form_lienhe.tieude.disabled=true;
	document.form_lienhe.noidung.disabled=true;
	document.form_lienhe.submit_.disabled=true;
	document.form_lienhe.tuxung.disabled=true;
	if(xml.readyState==4 || xml.readyState=="complete")
	{
		document.form_lienhe.hovaten.disabled=false;
		document.form_lienhe.diachi.disabled=false;
		document.form_lienhe.sodienthoai.disabled=false;
		document.form_lienhe.email.disabled=false;
		document.form_lienhe.tieude.disabled=false;
		document.form_lienhe.noidung.disabled=false;
		document.form_lienhe.submit_.disabled=false;
		document.form_lienhe.tuxung.disabled=false;
		if(xml.responseText=='thanhcong')
		{
			document.form_lienhe.reset();
			document.getElementById('div_lienhe').innerHTML="Truong An đã nhận được góp ý của Quý Khách. Chúng tôi sẽ trả lời Quý Khách sau ít phút. Xin cảm ơn !";
		}
		else			
			tblienhe.innerHTML="<img src='/images/loi.gif'> "+xml.responseText;
	}
}
function xoa_dathang(idsp)
{
	kt=confirm('Quý Khách có chắc chắn muốn bỏ sản phẩm này ra khỏi giỏ hàng ?');
	if(kt)
	{
		document.form_giohang.xoadathang.value=idsp;
		document.form_giohang.submit();
	}
}
function dathang()
{
	document.form_giohang.lenh.value='add_dathang';
	document.form_giohang.submit();
}
function phidichvu()
{
	if(document.form_giohang.cachthanhtoan.value==1)
	{
		document.getElementById('phidichvu').innerHTML='0 VNĐ';
		document.getElementById('tong_cong').innerHTML='<strong>'+tachso(document.form_giohang.tc.value)+' VNĐ</strong>';
	}
	else
	{
		document.getElementById('phidichvu').innerHTML='10.000 VNĐ';
		document.getElementById('tong_cong').innerHTML='<strong>'+tachso(parseInt(document.form_giohang.tc.value)+10000)+' VNĐ</strong>';
	}
}
function tachso(so)
{
	so = so+'';
	if(so=='' || so==0)
		return 0;
	dodai=so.length;
	sodu=0;
	if(dodai%3==0)
		sodoan=dodai/3;
	else
	{
		sodoan=Math.floor(dodai/3)+1;
		sodu=dodai%3;
	}
	somoi="";
	if(sodu!=0)
	{
		somoi=so.substr(0,sodu);
		vongchay=sodoan-1;
	}
	else
		vongchay=sodoan;
	for(i=0;i<vongchay;i++)
	{
		if(somoi=="")
			somoi=so.substr(sodu+i*3,3);
		else
			somoi=somoi+'.'+so.substr(sodu+i*3,3);
	}
	return somoi;
}
function hiengiaodich()
{
	hienbang1('bat');
	if(xml.readyState==4 || xml.readyState=="complete")
	{
		document.getElementById('noidung_bangcapnhat').innerHTML=xml.responseText;
	}
}
function chung()
{
	hienbang1('bat');
	if(xml.readyState==4 || xml.readyState=="complete")
	{
		if(xml.responseText=='thanhcong')
		{
			window.location=window.location;
			window.location.reload();
		}
		else
			document.getElementById('noidung_bangcapnhat').innerHTML=xml.responseText;
	}
}
function kt_dangky()
{
	tbdangky=document.getElementById('tb_dangky');
	tbdangky.innerHTML="";
	oj_hovaten=document.form_dangky.hovaten;
	oj_diachi=document.form_dangky.diachi;
	oj_sodienthoai=document.form_dangky.sodienthoai;
	oj_email=document.form_dangky.email;
	oj_matkhau1=document.form_dangky.matkhau1;
	oj_matkhau2=document.form_dangky.matkhau2;
	/*if(oj_hovaten.value=="")
	{
		tbdangky.innerHTML="<img src='/images/loi.gif'> Quý Khách chưa nhập họ và tên !";
		oj_hovaten.focus();
		return false;
	}
	else if(oj_diachi.value=="")
	{
		tbdangky.innerHTML="<img src='/images/loi.gif'> Quý Khách chưa nhập địa chỉ !";
		oj_diachi.focus();
		return false;
	}
	else if(oj_sodienthoai.value=="")
	{
		tbdangky.innerHTML="<img src='/images/loi.gif'> Quý Khách chưa nhập số điện thoại !";
		oj_sodienthoai.focus();
		return false;
	}
	else if(oj_sodienthoai.value.length<7)
	{
		tbdangky.innerHTML="<img src='/images/loi.gif'> Số điện thoại của Quý Khách phải lớn hơn 7 số !";
		oj_sodienthoai.focus();
		return false;
	}
	else if(document.form_dangky.ngaysinh.value=="---" || document.form_dangky.thangsinh.value=="---" || document.form_dangky.namsinh.value=="---")
	{
		tbdangky.innerHTML="<img src='/images/loi.gif'> Quý Khách chưa nhập đầy đủ ngày sinh !";
		return false;
	}
	else if(oj_email.value=="")
	{
		tbdangky.innerHTML="<img src='/images/loi.gif'> Quý Khách chưa nhập email !";
		oj_email.focus();
		return false;
	}
	else if(oj_email.value.indexOf("@")==-1 || oj_email.value.indexOf(".")==-1)
	{
		tbdangky.innerHTML="<img src='/images/loi.gif'> Email không hợp lệ !";
		oj_email.focus();
		return false;
	}
	else if(oj_matkhau1.value=="")
	{
		tbdangky.innerHTML="<img src='/images/loi.gif'> Quý Khách chưa nhập mật khẩu !";
		oj_matkhau1.focus();
		return false;
	}
	else if(oj_matkhau1.value.length<6)
	{
		tbdangky.innerHTML="<img src='/images/loi.gif'> Mật khẩu của Quý Khách phải từ 6 kí tự trở lên !";
		oj_matkhau1.focus();
		return false;
	}
	else if(oj_matkhau2.value=="")
	{
		tbdangky.innerHTML="<img src='/images/loi.gif'> Quý Khách chưa nhập lại mật khẩu !";
		oj_matkhau2.focus();
		return false;
	}
	else if(oj_matkhau2.value!=oj_matkhau1.value)
	{
		tbdangky.innerHTML="<img src='/images/loi.gif'> 2 mật khẩu không trùng nhau !";
		return false;
	}
	else*/
	if(document.form_dangky.dongy.checked==false)
	{
		tbdangky.innerHTML="<img src='/images/loi.gif'> Quý Khách chưa đồng ý với các điểu khoản dịch vụ !";
		return false;
	}
	loaddulieu(oj_hovaten.value+'##'+oj_diachi.value+'##'+oj_sodienthoai.value+'##'+document.form_dangky.ngaysinh.value+'##'+document.form_dangky.thangsinh.value+'##'+document.form_dangky.namsinh.value+'##'+oj_email.value+'##'+oj_matkhau1.value+'##'+oj_matkhau2.value+'##dangky',dangkymuahang);
}
function dangkymuahang()
{
	document.getElementById('tb_dangky').innerHTML="<img src='/images/loading_small.gif'>";
	document.form_dangky.hovaten.disabled=true;
	document.form_dangky.diachi.disabled=true;
	document.form_dangky.sodienthoai.disabled=true;
	document.form_dangky.email.disabled=true;
	document.form_dangky.matkhau1.disabled=true;
	document.form_dangky.matkhau2.disabled=true;
	document.form_dangky.ngaysinh.disabled=true;
	document.form_dangky.thangsinh.disabled=true;
	document.form_dangky.namsinh.disabled=true;
	document.form_dangky.submit_.disabled=true;
	if(xml.readyState==4 || xml.readyState=="complete")
	{
		document.form_dangky.hovaten.disabled=false;
		document.form_dangky.diachi.disabled=false;
		document.form_dangky.sodienthoai.disabled=false;
		document.form_dangky.email.disabled=false;
		document.form_dangky.matkhau1.disabled=false;
		document.form_dangky.matkhau2.disabled=false;
		document.form_dangky.ngaysinh.disabled=false;
		document.form_dangky.thangsinh.disabled=false;
		document.form_dangky.namsinh.disabled=false;
		document.form_dangky.submit_.disabled=false;
		if(xml.responseText=='thanhcong')
		{
			document.getElementById('div_dangky').className='cangiua';
			document.getElementById('div_dangky').innerHTML='Quý Khách đã đăng ký đặt hàng thành công !<br>Xin vui lòng đợi trong giây lát.';
			if(location.href.indexOf("Gio-Hang")==-1)
			{
				window.location=window.location;
				window.location.reload();
			}
			else
				window.location="/TrangChu/Quan-Ly-Giao-Dich.tac";
		}
		else if(xml.responseText.indexOf("##")!=-1)
		{
			mang=xml.responseText.split('##');
			document.getElementById('div_dangky').className='cangiua';
			document.getElementById('div_dangky').innerHTML='Kích hoạt IDM thành công !<br>Xin vui lòng đợi trong giây lát.';
			window.location="/TrangChu/San-Pham/IDM/Chi-Tiet/"+mang[1]+".tac";
		}
		else
			document.getElementById('tb_dangky').innerHTML=xml.responseText;
	}
}
function bat_capnhat()
{
	document.getElementById('thongbao_capnhat').innerHTML=' (Nhấn "Cập nhật giỏ hàng" để hiện phần Đăng ký) ';
	document.getElementById('div_dangky').className='tat';
}
function kt_quenmatkhau()
{
	email=document.form_quenmatkhau.email.value;
	if(email=='' || email.indexOf("@")==-1 || email.indexOf(".")==-1)
	{
		document.getElementById('tb_quenmatkhau').innerHTML="<img src='/images/loi.gif'> Email của Quý Khách không hợp lệ !";
		document.form_quenmatkhau.email.focus();
	}
	else
		loaddulieu(email+'##laylaimatkhau',quenmatkhau)
}
function quenmatkhau()
{
	document.getElementById('tb_quenmatkhau').innerHTML="<img src='/images/loading_small.gif'>";
	document.form_quenmatkhau.email.disabled=true;
	document.form_quenmatkhau.submit_.disabled=true;
	if(xml.readyState==4 || xml.readyState=="complete")
	{
		document.form_quenmatkhau.email.disabled=false;
		document.form_quenmatkhau.submit_.disabled=false;
		if(xml.responseText=='thanhcong')
			document.getElementById('div_quenmatkhau').innerHTML='Trường An đã gửi 1 liên kết để lấy lại mật khẩu qua Email của Quý Khách.<br />Quý Khách vui lòng kiểm tra email để biết thêm chi tiết.';
		else
			document.getElementById('tb_quenmatkhau').innerHTML="<img src='/images/loi.gif'> "+xml.responseText;
	}
}
function kt_doimk_moi()
{
	mk=document.form_quenmatkhau.matkhau.value;
	mk2=document.form_quenmatkhau.matkhau2.value;
	id_tv=document.form_quenmatkhau.id.value;
	makh=document.form_quenmatkhau.makichhoat.value;
	if(mk=='')
	{
		document.getElementById('tb_quenmatkhau').innerHTML="<img src='/images/loi.gif'> Quý Khách chưa nhập mật khẩu ! !";
		document.form_quenmatkhau.matkhau.focus();
	}
	else if(mk2=='')
	{
		document.getElementById('tb_quenmatkhau').innerHTML="<img src='/images/loi.gif'> Quý Khách chưa nhập mật khẩu 2 !";
		document.form_quenmatkhau.matkhau2.focus();
	}
	else if(mk.length<6)
	{
		document.getElementById('tb_quenmatkhau').innerHTML="<img src='/images/loi.gif'> Mật khẩu phải từ 6 ký tự trở lên !";
		document.form_quenmatkhau.matkhau.focus();
	}
	else if(mk!=mk2)
		document.getElementById('tb_quenmatkhau').innerHTML="<img src='/images/loi.gif'> 2 mật khẩu không trùng nhau !";
	else
		loaddulieu(id_tv+'##'+makh+'##'+mk+'##'+mk2+'##doi_mk_quen',doi_mk_quen);
}
function doi_mk_quen()
{
	document.getElementById('tb_quenmatkhau').innerHTML="<img src='/images/loading_small.gif'>";
	document.form_quenmatkhau.matkhau.disabled=true;
	document.form_quenmatkhau.matkhau2.disabled=true;
	document.form_quenmatkhau.submit_.disabled=true;
	if(xml.readyState==4 || xml.readyState=="complete")
	{
		document.form_quenmatkhau.matkhau.disabled=false;
		document.form_quenmatkhau.matkhau2.disabled=false;
		document.form_quenmatkhau.submit_.disabled=false;
		if(xml.responseText=='thanhcong')
			document.getElementById('div_quenmatkhau').innerHTML='Xin chúc mừng ! Quý Khách đã thay đổi mật khẩu thành công !';
		else
			document.getElementById('tb_quenmatkhau').innerHTML="<img src='/images/loi.gif'> "+xml.responseText;
	}
}
function res_mg()
{
	hienbang1('bat');
	document.getElementById('noidung_bangcapnhat').innerHTML="<img src='/images/kinh_lup_mega.jpg' />";
}
function kt_kichhoat()
{
	tbmakichhoat=document.getElementById('tb_makichhoat');
	ma1=document.form_kichhoat.mkh1.value;
	ma2=document.form_kichhoat.mkh2.value;
	cachmua=document.form_kichhoat.cachdangky.value;
	if(ma1=='' || ma2=='')
	{
		tbmakichhoat.innerHTML="<img src='/images/loi.gif'> Quý Khách chưa nhập mã kích hoạt !";
		document.form_kichhoat.mkh1.focus();
	}
	else if(ma1.length<5)
	{
		tbmakichhoat.innerHTML="<img src='/images/loi.gif'> Mã kích hoạt chưa đủ !";
		document.form_kichhoat.mkh1.focus();
	}
	else if(ma2=='')
	{
		tbmakichhoat.innerHTML="<img src='/images/loi.gif'> Quý Khách chưa nhập mã kích hoạt !";
		document.form_kichhoat.mkh2.focus();
	}
	else if(ma2.length<5)
	{
		tbmakichhoat.innerHTML="<img src='/images/loi.gif'> Mã kích hoạt chưa đủ !";
		document.form_kichhoat.mkh2.focus();
	}
	else if(ma2==ma1)
	{
		tbmakichhoat.innerHTML="<img src='/images/loi.gif'> Mã không hợp lệ !";
	}
	else
		loaddulieu(ma1+'##'+ma2+'##'+cachmua+'##kichhoat_idm',kh_idm);
}
function kh_idm()
{
	document.getElementById('tb_makichhoat').innerHTML="<img src='/images/loading_small.gif'>";
	document.form_kichhoat.mkh1.disabled=true;
	document.form_kichhoat.mkh2.disabled=true;
	document.form_kichhoat.cachdangky.disabled=true;
	document.form_kichhoat.submit_.disabled=true;
	if(xml.readyState==4 || xml.readyState=="complete")
	{
		document.getElementById('tb_makichhoat').innerHTML="&nbsp;";
		document.form_kichhoat.mkh1.disabled=false;
		document.form_kichhoat.mkh2.disabled=false;
		document.form_kichhoat.cachdangky.disabled=false;
		document.form_kichhoat.submit_.disabled=false;
		mang=xml.responseText.split('####');
		if(mang[0]=='thanhcong')
		{
			document.getElementById('tb_makichhoat').innerHTML="Chấp nhận mã kích hoạt ! <br />Vui lòng chờ trong giây lát";
			document.getElementById('td_makichhoat').innerHTML=document.form_kichhoat.mkh1.value+'-'+document.form_kichhoat.mkh2.value;
			if(document.form_kichhoat.cachdangky.value==1)
				document.getElementById('td_cachmua').innerHTML='Đăng ký mới';
			else
				document.getElementById('td_cachmua').innerHTML='Lấy lại serial';
			document.getElementById('td_submit').innerHTML='&nbsp;';
			window.location="/TrangChu/San-Pham/IDM/Chi-Tiet/"+mang[1]+".tac";
		}
		else if(mang[0]=='error')
			document.getElementById('tb_makichhoat').innerHTML="<img src='/images/loi.gif'> "+mang[1];
		else
		{
			document.getElementById('tb_makichhoat').innerHTML="Chấp nhận mã kích hoạt ! ";
			document.getElementById('td_makichhoat').innerHTML=document.form_kichhoat.mkh1.value+'-'+document.form_kichhoat.mkh2.value;
			document.getElementById('td_cachmua').innerHTML='Đăng ký mới';
			document.getElementById('td_submit').innerHTML='&nbsp;';
			document.getElementById('div_dk').innerHTML=mang[1];
		}
	}
}