﻿function fun_lienket(obj)
{	
	var index=obj.selectedIndex;
	var url=obj.options[index].value;
	if (index!=0)
	{
		//document.open(url);
		window.open(url);
	}
}

function LoadDataHome()
{
	/*var ajtt = document.getElementById("ajaxtintucmoi");
    ajtt.style.display = "";
	var ajda = document.getElementById("ajaxthongtinbdsmoi");
    ajda.style.display = "";
	var ajck = document.getElementById("ajaxthongtinchungkhoan");
    ajck.style.display = "";
	var ajqc = document.getElementById("ajaxquangcao");
    ajqc.style.display = "";
	var ajxd = document.getElementById("ajaxduanxaydung");
    ajxd.style.display = "";
	var ajsgd = document.getElementById("ajaxsangiaodich");
    ajsgd.style.display = "";
	var ajbdsnb = document.getElementById("ajaxbatdongsannoibat");
    ajbdsnb.style.display = "";
	var ajlk = document.getElementById("ajaxlienket");
    ajlk.style.display = "";
	var ajtk = document.getElementById("ajaxthongke");
    ajtk.style.display = "";*/
	
	//LoadHelp();
	Loadmenumember();
	LoadTinTucMoi();
	LoadWebLienKet();
	LoadDuAnXayDungMoi();
	LoadDataTinTuc()
	
}

function LoadHelp()
{
	var chatyh = document.getElementById("chatyahoo");	
	var str = "<a href=\"ymsgr:sendIM?nthong20042003\"><img src=\"images/yahoo.jpg\" width=\"139\" height=\"34\" alt=\"Click here go to Yahoo! Messenger \" border=\"0\"></a><br><br><img src=\"images/Skype.jpg\" width=\"139\" height=\"22\" />";
	chatyh.innerHTML = str;
}

function LoadWebLienKet()
{
	
	xmlHttp = GetMSXmlHttp();
    xmlHttp.onreadystatechange = function()
    {
        if(xmlHttp.readyState == 4)
        {
            var value = xmlHttp.responseText;
			//var ajaxlk = document.getElementById("ajaxlienket");
            //ajaxlk.style.display = "none";
            var ajlk = document.getElementById("lienket");
			ajlk.innerHTML = value;
			LoadThongKe();
        }
    }
    xmlHttp.open("GET","ajaxpro.php?do=loadweblienket&times="+Math.random(),true);
    xmlHttp.send(null);
}

function LoadThongKe()
{
	
	xmlHttp = GetMSXmlHttp();
    xmlHttp.onreadystatechange = function()
    {
        if(xmlHttp.readyState == 4)
        {
            var value = xmlHttp.responseText;
			
			//var ajaxtk = document.getElementById("ajaxthongke");
            //ajaxtk.style.display = "none";
            var ajtk = document.getElementById("thongke");
			ajtk.innerHTML = value;		
			LoadDuAnXayDungMoi();
        }
    }
    xmlHttp.open("GET","ajaxpro.php?do=loadthongke&times="+Math.random(),true);
    xmlHttp.send(null);
}

function LoadTinTucMoi()
{
	xmlHttp = GetMSXmlHttp();
    xmlHttp.onreadystatechange = function()
    {
        if(xmlHttp.readyState == 4)
        {
            var value = xmlHttp.responseText;
            //var ajax = document.getElementById("ajaxtintucmoi");
            //ajax.style.display = "none";
            var ajtintucmoi = document.getElementById("tintucmoi");
			ajtintucmoi.innerHTML = value;
			Loadthongtinbdsmoi();
        }
    }
    xmlHttp.open("GET","ajaxpro.php?do=loadtintucmoi&times="+Math.random(),true);
    xmlHttp.send(null);
}

function Loadthongtinbdsmoi()
{
	xmlHttp = GetMSXmlHttp();
    xmlHttp.onreadystatechange = function()
    {
        if(xmlHttp.readyState == 4)
        {
            var value = xmlHttp.responseText;
            //var ajaxda= document.getElementById("ajaxthongtinbdsmoi");
            //ajaxda.style.display = "none";
            var ajdamoi = document.getElementById("thongtinbdsmoi");
			ajdamoi.innerHTML = value;
			LoadThongTinChungKhoanMoi();
        }
    }
    xmlHttp.open("GET","ajaxpro.php?do=loadthongtinbdsmoi&times="+Math.random(),true);
    xmlHttp.send(null);
}

function LoadThongTinChungKhoanMoi()
{
	xmlHttp = GetMSXmlHttp();
    xmlHttp.onreadystatechange = function()
    {
        if(xmlHttp.readyState == 4)
        {
            var value = xmlHttp.responseText;
            //var ajaxttck= document.getElementById("ajaxthongtinchungkhoan");
            //ajaxttck.style.display = "none";
            var ajttck = document.getElementById("thongtinchungkhoan");
			ajttck.innerHTML = value;		
			LoadQuamqCao();
        }
    }
    xmlHttp.open("GET","ajaxpro.php?do=loadthongtinchungkhoanmoi&times="+Math.random(),true);
    xmlHttp.send(null);
}

function LoadQuamqCao()
{
	xmlHttp = GetMSXmlHttp();
    xmlHttp.onreadystatechange = function()
    {
        if(xmlHttp.readyState == 4)
        {
            var value = xmlHttp.responseText;
            //var ajaxqc= document.getElementById("ajaxquangcao");
            //ajaxqc.style.display = "none";
            var ajqc = document.getElementById("quangcao");
			ajqc.innerHTML = value;	
			LoadWebLienKet();
        }
    }
    xmlHttp.open("GET","ajaxpro.php?do=loadthongtinquangcao&times="+Math.random(),true);
    xmlHttp.send(null);
}

function LoadDuAnXayDungMoi()
{
	
	xmlHttp = GetMSXmlHttp();
    xmlHttp.onreadystatechange = function()
    {
        if(xmlHttp.readyState == 4)
        {
            var value = xmlHttp.responseText;
			//var ajaxdaxd = document.getElementById("ajaxduanxaydung");
            //ajaxdaxd.style.display = "none";
            var ajdaxd = document.getElementById("duanxaydung");
			ajdaxd.innerHTML = value;		
			LoadSanGiaoDich();
        }
    }
    xmlHttp.open("GET","ajaxpro.php?do=loadduanxaydungmoi&times="+Math.random(),true);
    xmlHttp.send(null);
}

function LoadSanGiaoDich()
{
	xmlHttp = GetMSXmlHttp();
    xmlHttp.onreadystatechange = function()
    {
        if(xmlHttp.readyState == 4)
        {
            var value = xmlHttp.responseText;
            //var ajaxsgd= document.getElementById("ajaxsangiaodich");
            //ajaxsgd.style.display = "none";
            var ajsgd = document.getElementById("sangiaodich");
			ajsgd.innerHTML = value;
			LoadItemFirstShow();	
        }
    }
    xmlHttp.open("GET","ajaxpro.php?do=loadsangiaodich&times="+Math.random(),true);
    xmlHttp.send(null);	
}

function LoadItemFirstShow()
{
	xmlHttp = GetMSXmlHttp();
    xmlHttp.onreadystatechange = function()
    {
        if(xmlHttp.readyState == 4)
        {
            var value = xmlHttp.responseText;            
			LoadChiTietSanGiaoDich(_parseInt(value));	
        }
    }
    xmlHttp.open("GET","ajaxpro.php?do=loaditemfirstshow&times="+Math.random(),true);
    xmlHttp.send(null);
}

function LoadChiTietSanGiaoDich(maloairao)
{
	xmlHttp = GetMSXmlHttp();
    xmlHttp.onreadystatechange = function()
    {
        if(xmlHttp.readyState == 4)
        {
            var value = xmlHttp.responseText;
			//var ajaxctsgd = document.getElementById("ajaxchitietsangiaodich");
            //ajaxctsgd.style.display = "none";
            var ajctsgd = document.getElementById("chitietsangiaodich");
			ajctsgd.innerHTML = value;		
			LoadBatDongSanNoiBat();	
        }
    }
    xmlHttp.open("GET","ajaxpro.php?do=loadchitietsangiaodich&maloairao=" + maloairao + "&times="+Math.random(),true);
    xmlHttp.send(null);
	
}

function LoadBatDongSanNoiBat()
{
	
	xmlHttp = GetMSXmlHttp();
    xmlHttp.onreadystatechange = function()
    {
        if(xmlHttp.readyState == 4)
        {
            var value = xmlHttp.responseText;
			//var ajaxbdsnb = document.getElementById("ajaxbatdongsannoibat");
            //ajaxbdsnb.style.display = "none";
            var ajbdsnb = document.getElementById("batdongsannoibat");
			ajbdsnb.innerHTML = value;					
        }
    }
    xmlHttp.open("GET","ajaxpro.php?do=loadbatdongsannoibat&times="+Math.random(),true);
    xmlHttp.send(null);
}

//Load so luong bds cua mot tin rao

function LoadChiTietSoLuongBDS_TinRao(odivtinrao ,otsdivrao,omatinrao)
{
	var i = 0;
	for (i = 0; i < otsdivrao; i++)
	{
		var otinrao = document.getElementById("tinrao_" + i);	
		if (i < otsdivrao -1)
		{
			otinrao.style.background = "url(images/bg_canban1.gif) no-repeat";				
		}
		else
		{
			otinrao.style.background = "url(images/bg_canmua1.gif) no-repeat";	
		}
		
	}
	
	var otinrao = document.getElementById("tinrao_" + odivtinrao);	
	if (odivtinrao == otsdivrao -1)
	{
		otinrao.style.background = "url(images/bg_canmua.gif) no-repeat";	
	}
	else
		otinrao.style.background = "url(images/bg_canthue.gif) no-repeat";
		
	LoadChiTietSanGiaoDichCuaTinRao(_parseInt(omatinrao));	
	//var ajaxctsgd = document.getElementById("ajaxchitietsangiaodich");
    //ajaxctsgd.style.display = "";	
}


function LoadChiTietSanGiaoDichCuaTinRao(maloairao)
{
	xmlHttp = GetMSXmlHttp();
    xmlHttp.onreadystatechange = function()
    {
        if(xmlHttp.readyState == 4)
        {
            var value = xmlHttp.responseText;
			//var ajaxctsgd = document.getElementById("ajaxchitietsangiaodich");
            //ajaxctsgd.style.display = "none";
            var ajctsgd = document.getElementById("chitietsangiaodich");
			ajctsgd.innerHTML = value;					
        }
    }
    xmlHttp.open("GET","ajaxpro.php?do=loadchitietsangiaodich&maloairao=" + maloairao + "&times="+Math.random(),true);
    xmlHttp.send(null);
	
}

//Load chi tiet bat dong san cua quy mo bat dong san

function Loadchitietbatdongsancuaquymo(maquymo,maloaibds,maloairao)
{
	alert("vao day");
}


//Cac function cho muc tin tuc

function LoadDataTinTuc()
{
	var ajtt = document.getElementById("ajaxtintucmoi");
    ajtt.style.display = "";
	var ajda = document.getElementById("ajaxthongtinbdsmoi");
    ajda.style.display = "";
	var ajck = document.getElementById("ajaxthongtinchungkhoan");
    ajck.style.display = "";
	var ajqc = document.getElementById("ajaxquangcao");
    ajqc.style.display = "";
	var ajlk = document.getElementById("ajaxlienket");
    ajlk.style.display = "";
	var ajtk = document.getElementById("ajaxthongke");
    ajtk.style.display = "";
	
	LoadHelp();
	Loadmenumember();
	LoadTinTucMoi();
	
}

//Tin tuc

function LoadCacTinKhac(newid)
{
	xmlHttp = GetMSXmlHttp();
    xmlHttp.onreadystatechange = function()
    {
        if(xmlHttp.readyState == 4)
        {
            var value = xmlHttp.responseText;
			var cactinkhac = document.getElementById("cactinkhac");
			cactinkhac.innerHTML = value;					
        }
    }
    xmlHttp.open("GET","ajaxloaddatadetail.php?do=loadcactinkhac&nid="+newid+"&times="+Math.random(),true);
    xmlHttp.send(null);
}

function loadnewdetail(matin, tablename, feildid, fieldcontent)
{
	xmlHttp = GetMSXmlHttp();
    xmlHttp.onreadystatechange = function()
    {
        if(xmlHttp.readyState == 4)
        {
            var value = xmlHttp.responseText;
			var newdetail = document.getElementById("newdetail");
			newdetail.innerHTML = value;					
        }
    }
    xmlHttp.open("GET","ajaxloaddatadetail.php?do=loaddetailnew&nid="+matin+"&tabName="+tablename+"&feildid="+feildid+"&fieldcontent="+fieldcontent+"&times="+Math.random(),true);
    xmlHttp.send(null);
}

function LoadOtherPage(itrang, isorecordtrentrang, table, keytable,fieldcontent)
{
	xmlHttp = GetMSXmlHttp();
    xmlHttp.onreadystatechange = function()
    {
        if(xmlHttp.readyState == 4)
        {
            var value = xmlHttp.responseText;
			var cactinkhac = document.getElementById("cactinkhac");
			cactinkhac.innerHTML = value;	
			Setfocuspage(itrang, isorecordtrentrang, table, keytable); 
        }
    }
    xmlHttp.open("GET","ajaxloaddatadetail.php?do=loadotherpage&p="+itrang+"&nrec="+isorecordtrentrang+"&table="+table+"&keyid="+keytable+"&fieldcontent="+fieldcontent+"&times="+Math.random(),true);
    xmlHttp.send(null);
}

function Setfocuspage(itrang, isorecordtrentrang, table, keytable)
{
	xmlHttp = GetMSXmlHttp();
    xmlHttp.onreadystatechange = function()
    {
        if(xmlHttp.readyState == 4)
        {
            var value = xmlHttp.responseText;
			var phantrang = document.getElementById("phantrang");
			phantrang.innerHTML = value;	
		}
    }
    xmlHttp.open("GET","ajaxloaddatadetail.php?do=loadsetfocuspage&p="+itrang+"&nrec="+isorecordtrentrang+"&table="+table+"&keyid="+keytable+"&times="+Math.random(),true);
    xmlHttp.send(null);	
}

function LoadOtherPageThongTin(itrang, type,tablename, fieldid, fieldcontent, isorecordtrentrang)
{
	xmlHttp = GetMSXmlHttp();
    xmlHttp.onreadystatechange = function()
    {
        if(xmlHttp.readyState == 4)
        {
            var value = xmlHttp.responseText;
			var cactinkhac = document.getElementById("cactinkhac");
			cactinkhac.innerHTML = value;	
			//SetfocuspageThongTin(itrang, isorecordtrentrang, tablename, fieldid, fieldcontent, type); 
        }
    }
    xmlHttp.open("GET","ajaxloaddatadetail.php?do=loadotherpagethongtin&p="+itrang+"&nrec="+isorecordtrentrang+"&table="+table+"&keyid="+keytable+"&fieldcontent="+fieldcontent+"&itype="+type+"&times="+Math.random(),true);
    xmlHttp.send(null);
}


function SetfocuspageThongTin(itrang, isorecordtrentrang, tablename, fieldid, fieldcontent, type)
{
	xmlHttp = GetMSXmlHttp();
    xmlHttp.onreadystatechange = function()
    {
        if(xmlHttp.readyState == 4)
        {
            var value = xmlHttp.responseText;
			var phantrang = document.getElementById("phantrang");
			phantrang.innerHTML = value;	
		}
    }
    xmlHttp.open("GET","ajaxloaddatadetail.php?do=loadsetfocuspagethongtin&p="+itrang+"&nrec="+isorecordtrentrang+"&table="+tablename+"&keyid="+fieldid+"&fieldcontent="+fieldcontent+"&itype="+type+"&times="+Math.random(),true);
    xmlHttp.send(null);	
}

function LoadOtherPageDauGiaBDS(itrang, isorecordtrentrang, table, keytable)
{
	xmlHttp = GetMSXmlHttp();
    xmlHttp.onreadystatechange = function()
    {
        if(xmlHttp.readyState == 4)
        {
            var value = xmlHttp.responseText;
			var cactinkhac = document.getElementById("cactinkhac");
			cactinkhac.innerHTML = value;	
			Setfocuspagedaugiabds(itrang, isorecordtrentrang, table, keytable); 
        }
    }
    xmlHttp.open("GET","ajaxloaddatadetail.php?do=loadotherpagedaugiabds&p="+itrang+"&nrec="+isorecordtrentrang+"&table="+table+"&keyid="+keytable+"&times="+Math.random(),true);
    xmlHttp.send(null);
}

function Setfocuspagedaugiabds(itrang, isorecordtrentrang, table, keytable)
{
	xmlHttp = GetMSXmlHttp();
    xmlHttp.onreadystatechange = function()
    {
        if(xmlHttp.readyState == 4)
        {
            var value = xmlHttp.responseText;
			var phantrang = document.getElementById("phantrang");
			phantrang.innerHTML = value;	
		}
    }
    xmlHttp.open("GET","ajaxloaddatadetail.php?do=loadsetfocuspagedaugiabds&p="+itrang+"&nrec="+isorecordtrentrang+"&table="+table+"&keyid="+keytable+"&times="+Math.random(),true);
    xmlHttp.send(null);	
}

function LoadOtherPageTaiLieu(itrang, isorecordtrentrang, table, keytable)
{
	xmlHttp = GetMSXmlHttp();
    xmlHttp.onreadystatechange = function()
    {
        if(xmlHttp.readyState == 4)
        {
            var value = xmlHttp.responseText;
			var cactinkhac = document.getElementById("cactinkhac");
			cactinkhac.innerHTML = value;	
			Setfocuspagetailieu(itrang, isorecordtrentrang, table, keytable); 
        }
    }
    xmlHttp.open("GET","ajaxloaddatadetail.php?do=loadotherpagetailieu&p="+itrang+"&nrec="+isorecordtrentrang+"&table="+table+"&keyid="+keytable+"&times="+Math.random(),true);
    xmlHttp.send(null);
}

function Setfocuspagetailieu(itrang, isorecordtrentrang, table, keytable)
{
	xmlHttp = GetMSXmlHttp();
    xmlHttp.onreadystatechange = function()
    {
        if(xmlHttp.readyState == 4)
        {
            var value = xmlHttp.responseText;
			var phantrang = document.getElementById("phantrang");
			phantrang.innerHTML = value;	
		}
    }
    xmlHttp.open("GET","ajaxloaddatadetail.php?do=loadsetfocuspagetailieu&p="+itrang+"&nrec="+isorecordtrentrang+"&table="+table+"&keyid="+keytable+"&times="+Math.random(),true);
    xmlHttp.send(null);	
}

function LoadOtherPageDichVu(itrang, isorecordtrentrang, table)
{
	xmlHttp = GetMSXmlHttp();
    xmlHttp.onreadystatechange = function()
    {
        if(xmlHttp.readyState == 4)
        {
            var value = xmlHttp.responseText;
			var cactinkhac = document.getElementById("cactinkhac");
			cactinkhac.innerHTML = value;	
			Setfocuspagedichvu(itrang, isorecordtrentrang, table); 
        }
    }
    xmlHttp.open("GET","ajaxloaddatadetail.php?do=loadotherpagedichvu&p="+itrang+"&nrec="+isorecordtrentrang+"&table="+table+"&times="+Math.random(),true);
    xmlHttp.send(null);
}


function Setfocuspagedichvu(itrang, isorecordtrentrang, table)
{
	xmlHttp = GetMSXmlHttp();
    xmlHttp.onreadystatechange = function()
    {
        if(xmlHttp.readyState == 4)
        {
            var value = xmlHttp.responseText;
			var phantrang = document.getElementById("phantrang");
			phantrang.innerHTML = value;	
		}
    }
    xmlHttp.open("GET","ajaxloaddatadetail.php?do=loadsetfocuspagedichvu&p="+itrang+"&nrec="+isorecordtrentrang+"&table="+table+"&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","ajaxloaddatadetail.php?do=checkImageCode&imagecode="+imagecode+"&times="+Math.random(),true);
   xmlHttp.send(null);
}

function CheckInFor()
{
	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 didong = 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;
	}
	SendInFor(hoten.value, diachi.value, email.value, didong.value, dienthoai.value, fax.value, noidung.value);
}

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 = "";
	var didong = document.getElementById("txtmobile");
	didong.value = "";
	var fax = document.getElementById("txtfax");
	fax.value = "";
}

function SendInFor(hoten, diachi, email, didong, dienthoai, fax, noidung)
{
	xmlHttp = GetMSXmlHttp();
	 xmlHttp.onreadystatechange = function()
	 {
		   if(xmlHttp.readyState == 4)
		   {
			 	var value = xmlHttp.responseText; 
				if (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.")	;
					ResetInfo;
				}
				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","ajaxpro.php?do=sendinfo&hoten="+hoten+"&didong="+didong+"&diachi="+diachi+"&email="+email+"&dienthoai="+dienthoai+"&fax="+fax+"&noidung="+noidung+"&times="+Math.random(),true);
	 xmlHttp.send(null);	
}

//===========================================
function loadCheckMaThanhPham(mavt,tenvt,dvt,mota)
{
    xmlHttp = GetMSXmlHttp();
    xmlHttp.onreadystatechange = function()
    {
        if(xmlHttp.readyState == 4)
        {
            var value = xmlHttp.responseText;
            if(!document.all) value = eval(value+"");
            var ajax = document.getElementById("ajaxvattu");
            ajax.style.display = "none";
            var mavt = document.getElementsByName("mavt")[0];
            if(value == 0)
            {
                alert("Lỗi xảy ra trong quá trình truyền dữ liệu");
                ajax.style.display = "none";
                return false;            
            }
            else if(value == 1)
            {
                alert("Mã vật tư này đã sử dụng rồi . Vui lòng chọn mã vật tư khác");
                ajax.style.display = "none";
                mavt.focus();
                return;
            }
            else if(value == 2)
            {
                alert("Thêm mới thành phẩm thành công.")                             
                mavt.focus();
            }
        }
    }
    xmlHttp.open("GET","ajax.aspx?do=checkmatpandinsert&mavt="+mavt+"&tenvt="+tenvt+"&dvt="+dvt+"&mota="+mota+"&times="+Math.random(),true);
    xmlHttp.send(null);
}

function LoadOtherPageItemBDS(itrang, sorctrentrang, loairao, loaibds, quymobds)
{
	xmlHttp = GetMSXmlHttp();
    xmlHttp.onreadystatechange = function()
    {
        if(xmlHttp.readyState == 4)
        {
            var value = xmlHttp.responseText;
			var cactinkhac = document.getElementById("cactinkhac");
			cactinkhac.innerHTML = value;	
			Setfocuspagebds(itrang, sorctrentrang, loairao, loaibds, quymobds); 
        }
    }
    xmlHttp.open("GET","ajaxloaddatadetail.php?do=loadotherpageitembds&p="+itrang+"&nrec="+sorctrentrang+"&loairao="+loairao+"&loaibds="+loaibds+"&quymobds="+quymobds+"&times="+Math.random(),true);
    xmlHttp.send(null);
}

function Setfocuspagebds(itrang, sorctrentrang, loairao, loaibds, quymobds)
{
	xmlHttp = GetMSXmlHttp();
    xmlHttp.onreadystatechange = function()
    {
        if(xmlHttp.readyState == 4)
        {
            var value = xmlHttp.responseText;
			var phantrang = document.getElementById("phantrang");
			phantrang.innerHTML = value;	
		}
    }
    xmlHttp.open("GET","ajaxloaddatadetail.php?do=setfocuspagebds&p="+itrang+"&nrec="+sorctrentrang+"&loairao="+loairao+"&loaibds="+loaibds+"&quymobds="+quymobds+"&times="+Math.random(),true);
    xmlHttp.send(null);	
}

function Loadchitietbatdongsancuaquymo(maquymo,maloaibds, maloairao)
{
	document.location.href = "property.php?lrid=" + maloairao + "&lbdsid=" + maloaibds + "&qmid="+ maquymo;	
}


function CheckInForRegist()
{
	var hoten = document.getElementById("txthoten");
	var diachi = document.getElementById("txtdiachi");
	var email = document.getElementById("txtemail");
	var dienthoai = document.getElementById("txtdienthoai");
	var tentruycap = document.getElementById("txttentruycap");
	var maxacnhan = document.getElementById("txtmaxacnhan");
	var matkhau = document.getElementById("txtpass");	
	var txtwebsite = document.getElementById("txtwebsite");
	
	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;
        }  
	}	
	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 (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;
	}
	
	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 (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;
	}
	AddThanhVien(hoten.value, diachi.value, email.value, txtwebsite.value, dienthoai.value, tentruycap.value, matkhau.value);	
}

function AddThanhVien(hoten, diachi, email, txtwebsite, dienthoai, tentruycap, matkhau)
{
	xmlHttp = GetMSXmlHttp();
    xmlHttp.onreadystatechange = function()
    {
        if(xmlHttp.readyState == 4)
        {
            var value = xmlHttp.responseText;
			
			if (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 = "home.php";
			}
			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","ajaxloaddatadetail.php?do=addthanhviens&hoten="+myEscape(hoten)+"&diachi="+myEscape(diachi)+"&email="+email+"&txtwebsite="+txtwebsite+"&dienthoai="+dienthoai+"&tentruycap="+tentruycap+"&matkhau="+matkhau+"&times="+Math.random(),true);
    xmlHttp.send(null);	
}

function CheckTrungTenTruyCap()
{
	var tentruycap = document.getElementById("txttentruycap");
	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(value == "0") 
            {
                alert("Tên tài khoản này tồn tại. Vui lòng chọn tài khoản khác.");
				var tentruycap = document.getElementById("txttentruycap");
				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 txtwebsite = document.getElementById("txtwebsite");
	txtwebsite.value = "";
	var maxacnhan = document.getElementById("txtmaxacnhan");
	maxacnhan.value = "";
	var tentruycap = document.getElementById("txttentruycap");
	tentruycap.value = "";
	var matkhau = document.getElementById("txtpass");
	matkhau.value = "";
}

function Checkdangnhap()
{
	var tentruycap = document.getElementById("tentruycap");
	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;
	}
	var matkhau = document.getElementById("matkhau");	
	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;
	}
	var rememberpass = document.getElementById("rememberpass");	
	LoadDangNhap(tentruycap.value,matkhau.value, rememberpass.value);
}

function LoadDangNhap(tentruycap, matkhau, rememberpass)
{
   xmlHttp = GetMSXmlHttp();
   xmlHttp.onreadystatechange = function()
   {
        if(xmlHttp.readyState == 4)
        {
            var value = xmlHttp.responseText; 
                       	
			if(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("tentruycap");
				tentruycap.focus();
                return false;
            }  
			else
			{
				document.location.href = "propertylist.php";	
			}
        }
   }    
   xmlHttp.open("GET","ajaxloaddatadetail.php?do=checkdangnhapn&tentruycap="+tentruycap+"&matkhau="+matkhau+"&rememberpass="+rememberpass+"&times="+Math.random(),true);
   xmlHttp.send(null);	
}

function Loadmenuthanhvien()
{
   xmlHttp = GetMSXmlHttp();
   xmlHttp.onreadystatechange = function()
   {
        if(xmlHttp.readyState == 4)
        {
            var value = xmlHttp.responseText;  			
			var member = document.getElementById("member");	
			member.innerHTML = value;
			LoadDataTinTuc();						
        }
   }    
   xmlHttp.open("GET","ajaxloaddatadetail.php?do=loadmenumember&times="+Math.random(),true);
   xmlHttp.send(null);	
}

function Loadmenumember()
{
   xmlHttp = GetMSXmlHttp();
   xmlHttp.onreadystatechange = function()
   {
        if(xmlHttp.readyState == 4)
        {
            var value = xmlHttp.responseText;  	
			if (value != "")
			{
				var member = document.getElementById("member");	
				member.innerHTML = value;
			}
			//LoadTinTucMoi();
        }
   }    
   xmlHttp.open("GET","ajaxloaddatadetail.php?do=loadmenumember&times="+Math.random(),true);
   xmlHttp.send(null);	
   //LoadTinTucMoi();
}

function XoaTin(keyid,tablename,fieldid,page)
{
	if (confirm("Bạn có muốn xóa tin này không?")==true)
	{
		DeleteRecord(keyid,tablename,fieldid,page);
	}
}

function DeleteRecord(keyid,tablename,fieldid, page)
{
	xmlHttp = GetMSXmlHttp();
    xmlHttp.onreadystatechange = function()
    {
		if(xmlHttp.readyState == 4)
		{
			var value = xmlHttp.responseText;                        	
			if (value == "0")
			{
				alert("Xóa không thành công. Vui lòng kiểm tra lại!")	
			}
			else
			{
				alert("Đã xóa dữ liệu thành công!")	;
				document.location.href = page;
			}
		}
    }    
    xmlHttp.open("GET","ajaxloaddatadetail.php?do=deleterecord&marc="+keyid+"&tablename="+tablename+"&fieldid="+fieldid+"&times="+Math.random(),true);
    xmlHttp.send(null);	
}

function Loadquymobds()
{
	var loaibds = document.getElementById("x_maloaibds");
	xmlHttp = GetMSXmlHttp();
    xmlHttp.onreadystatechange = function()
    {
		if(xmlHttp.readyState == 4)
		{
			var value = xmlHttp.responseText;                        	
			var quymo = document.getElementById("quymo");	
			quymo.innerHTML = value;			
		}
    }    
    xmlHttp.open("GET","ajaxloaddatadetail.php?do=loadquymobds&maloai="+loaibds.value+"&times="+Math.random(),true);
    xmlHttp.send(null);	
}

function Loadquanhuyen()
{
	var tinh = document.getElementById("x_tinh");
	xmlHttp = GetMSXmlHttp();
    xmlHttp.onreadystatechange = function()
    {
		if(xmlHttp.readyState == 4)
		{
			var value = xmlHttp.responseText;                        	
			var quanhuyen = document.getElementById("quanhuyen");	
			quanhuyen.innerHTML = value;			
		}
    }    
    xmlHttp.open("GET","ajaxloaddatadetail.php?do=loadquanhuyens&matinh="+tinh.value+"&times="+Math.random(),true);
    xmlHttp.send(null);	
} 

function LoadOtherPageDichVuMember(mathanhvien, itrang, isorecordtrentrang, table)
{
	xmlHttp = GetMSXmlHttp();
    xmlHttp.onreadystatechange = function()
    {
        if(xmlHttp.readyState == 4)
        {
            var value = xmlHttp.responseText;
			var cactinkhac = document.getElementById("cactinkhac");
			cactinkhac.innerHTML = value;	
			SetfocuspagedichvuMember(mathanhvien,itrang, isorecordtrentrang, table); 
        }
    }
    xmlHttp.open("GET","ajaxloaddatadetail.php?do=loadotherpagedichvuthanhvien&mathanhvien="+mathanhvien+"&p="+itrang+"&nrec="+isorecordtrentrang+"&table="+table+"&times="+Math.random(),true);
    xmlHttp.send(null);
}


function SetfocuspagedichvuMember(mathanhvien, itrang, isorecordtrentrang, table)
{
	xmlHttp = GetMSXmlHttp();
    xmlHttp.onreadystatechange = function()
    {
        if(xmlHttp.readyState == 4)
        {
            var value = xmlHttp.responseText;
			var phantrang = document.getElementById("phantrang");
			phantrang.innerHTML = value;	
		}
    }
    xmlHttp.open("GET","ajaxloaddatadetail.php?do=loadsetfocuspagedichvumeber&mathanhvien="+mathanhvien+"&p="+itrang+"&nrec="+isorecordtrentrang+"&table="+table+"&times="+Math.random(),true);
    xmlHttp.send(null);	
}


function CheckInForRegistEdit()
{
	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 txtwebsite = document.getElementById("txtwebsite");
	var mathanhvien = document.getElementById("mathanhvien");
	
	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;
        }  
	}	
	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;
	}
	EditThanhVien(hoten.value, diachi.value, email.value, txtwebsite.value, dienthoai.value, mathanhvien.value);	
}

function EditThanhVien(hoten, diachi, email, txtwebsite, dienthoai,mathanhvien)
{
	xmlHttp = GetMSXmlHttp();
    xmlHttp.onreadystatechange = function()
    {
        if(xmlHttp.readyState == 4)
        {
            var value = xmlHttp.responseText;
			
			if (value == "1")
			{
				alert("Thông tin của bạn đã được cập nhật!")	;				
			}
			else
			{
				alert("Có lỗi trong quá trình cập nhật dữ liệu.\n Vui lòng kiểm tra lại.");	
			}
		}
    }
    xmlHttp.open("GET","ajaxloaddatadetail.php?do=editthanhviens&hoten="+myEscape(hoten)+"&diachi="+myEscape(diachi)+"&email="+email+"&txtwebsite="+txtwebsite+"&dienthoai="+dienthoai+"&mathanhvien="+mathanhvien+"&times="+Math.random(),true);
    xmlHttp.send(null);	
}

function ChangePass()
{
	var passold = document.getElementById("passold");
	var mathanhvien = document.getElementById("mathanhvien");
	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 (value == "1")
			{
				alert("Đã đổi mật khẩu thành công!")	;				
			}
			else if (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","ajaxloaddatadetail.php?do=changepass&mathanhvien="+mathanhvien.value+"&passold="+passold.value+"&matkhaucu="+matkhaucu.value+"&matkhaumoi="+matkhaumoi.value+"&times="+Math.random(),true);
    xmlHttp.send(null);	
}

function Thoat()
{
	xmlHttp = GetMSXmlHttp();
    xmlHttp.onreadystatechange = function()
    {
        if(xmlHttp.readyState == 4)
        {
            var value = xmlHttp.responseText;
			
			if (value == "1")
			{
				document.location.href = "home.php";			
			}			
		}
    }
    xmlHttp.open("GET","ajaxloaddatadetail.php?do=thoat&times="+Math.random(),true);
    xmlHttp.send(null);	
}

function loadloairao()
{
	xmlHttp = GetMSXmlHttp();
	xmlHttp.onreadystatechange = function()
    {
        if(xmlHttp.readyState == 4)
        {
            var value = xmlHttp.responseText;
			var loairao = document.getElementById("loairao");	
			loairao.innerHTML = value;
			LoadTinhHuyen();			
		}
    }
    xmlHttp.open("GET","ajaxpro.php?do=loadloairao&times="+Math.random(),true);
    xmlHttp.send(null);		
}

function LoadTinhHuyen()
{
	xmlHttp = GetMSXmlHttp();
    xmlHttp.onreadystatechange = function()
    {
        if(xmlHttp.readyState == 4)
        {
            var value = xmlHttp.responseText;
			var quanhuyen = document.getElementById("quanhuyen");	
			quanhuyen.innerHTML = value;
			LoadDataHome();
		}
    }
    xmlHttp.open("GET","ajaxpro.php?do=loadtinhhuyen&times="+Math.random(),true);
    xmlHttp.send(null);	
}

function Loadquanhuyensearch()
{
	var matinh = document.getElementById("x_tinh");		
	xmlHttp = GetMSXmlHttp();
    xmlHttp.onreadystatechange = function()
    {
        if(xmlHttp.readyState == 4)
        {
            var value = xmlHttp.responseText;
			var listquan = document.getElementById("listquan");	
			listquan.innerHTML = value;			
		}
    }
    xmlHttp.open("GET","ajaxpro.php?do=Loadquanhuyensearch&matinh="+matinh.value+"&times="+Math.random(),true);
    xmlHttp.send(null);	
}


function setloairao(loairao)
{
	var maloairao = document.getElementById("maloairao");	
	maloairao.innerHTML = "<input type = hidden id = marao value = " +  loairao + ">";		
}


function LoadSearch()
{
	var mahuyen = document.getElementById("x_mahuyen");	
	var gia = document.getElementById("gia");	
	var marao = document.getElementById("marao");	
	var matiente = document.getElementById("x_matiente");	
	var dientich = document.getElementById("dientich");	
	document.location.href = "searchresult.php?loairao="+marao.value+"&hid="+mahuyen.value+"&pri="+gia.value+"&dientich="+dientich.value+"&matiente="+matiente.value;
}

function LoadOtherPageItemSrcBDS(itrang, sorctrentrang, strwhere)
{
	xmlHttp = GetMSXmlHttp();
    xmlHttp.onreadystatechange = function()
    {
        if(xmlHttp.readyState == 4)
        {
            var value = xmlHttp.responseText;
			var cactinkhac = document.getElementById("cactinkhac");
			cactinkhac.innerHTML = value;	
			SetfocuspageSrcBDS(itrang, sorctrentrang, strwhere); 
        }
    }
    xmlHttp.open("GET","ajaxloaddatadetail.php?do=loadotherpagesrc&p="+itrang+"&nrec="+sorctrentrang+"&swhere="+strwhere+"&times="+Math.random(),true);
    xmlHttp.send(null);	
}

function SetfocuspageSrcBDS(itrang, sorctrentrang, strwhere)
{
	xmlHttp = GetMSXmlHttp();
    xmlHttp.onreadystatechange = function()
    {
        if(xmlHttp.readyState == 4)
        {
            var value = xmlHttp.responseText;
			var phantrang = document.getElementById("phantrang");
			phantrang.innerHTML = value;	
		}
    }
    xmlHttp.open("GET","ajaxloaddatadetail.php?do=setfocuspagesrcbds&p="+itrang+"&nrec="+sorctrentrang+"&swhere="+strwhere+"&times="+Math.random(),true);
    xmlHttp.send(null);	
}

function quayve()
{
	history.back();	
}

function Checkdangtinbds()
{
   xmlHttp = GetMSXmlHttp();
   xmlHttp.onreadystatechange = function()
   {
        if(xmlHttp.readyState == 4)
        {
            var value = xmlHttp.responseText; 
                       	
			if(value == "0") 
            {
                alert("Bạn chưa đăng nhập thành viên hoặc bạn chưa phải là thành viên của AN Nghiệp Phát. Vui lòng kiểm tra lại.");
				var tentruycap = document.getElementById("tentruycap");
				tentruycap.focus();
                return false;
            }  
			else
			{
				document.location.href = "propertyadd.php";	
			}
        }
   }    
   xmlHttp.open("GET","ajaxloaddatadetail.php?do=checkdangtin&times="+Math.random(),true);
   xmlHttp.send(null);		
}
