//获取楼盘信息的地址
var G_HTML_TRAN_PATH = G_ROOT_PATH + "es/";
var _PageLoadObj = new Array();
//参数说明：0 - 对象id，1 - xml文件路径，2 - 样式表文件路径，3 - 已读取标识位，4 - 重读时间间隔（0表示无需更新，单位秒）
//			，5 - 更新静态文件时间（0表示无需更新），6 - 更新文件网址，7读取后重读对象id
var xmlurl1 = G_ROOT_PATH + "tempxml/es/xiaoqulist.xml";
var xslurl1 = G_ROOT_PATH + "agentsys/xml/EditXiaoQuSelect.xsl";
var xslmakeurl1 = G_ROOT_PATH + "Web/LoadDbToXml.aspx?pid=web_getdistrictinfobycityid&csnum=1&cn1=cityid&cv1=" + G_CITY_SHORT_NAME;
var GetDataSuccess = null;
var MaxTime = 0;
initaddobj("es_price", "", "../xml/MingciPreview.xsl", "0", "0", "0", "", "", "");
initaddobj("competeRankings", '', "../xml/JJPreview.xsl", "0", "0", "0", "", "", "");
initaddobj("xiaoquselect",xmlurl1,xslurl1,"0","0","72000",xslmakeurl1,"","0","");
initaddobj("div_square", "../../Web/LoadDbToXml.aspx?pid=manage_h_squarebyareainfo&csnum=1&cn1=aravalue&cv1=", "../xml/bankuai.xsl", "0", "0", "0", "", "", "");
initaddobj("assignuserid","","../xml/EsManageAssignUseridSelect.xsl","0","0","0","","","0","");
initaddobj("buslines","","../Xml/BuslinesCollectFromMapBar.xsl","0","0","0","","","0","GetDataFromHidden('buslines');");
initaddobj("education","","../Xml/EducationCollectFromMapBar.xsl","0","0","0","","","0","GetDataFromHidden('education');");
initaddobj("business","","../Xml/BusinessCollectFromMapBar.xsl","0","0","0","","","0","GetDataFromHidden('business');");
initaddobj("hospital","","../Xml/HospitalCollectFromMapBar.xsl","0","0","0","","","0","GetDataFromHidden('hospital');");
initaddobj("bank","","../Xml/BankCollectFromMapBar.xsl","0","0","0","","","0","GetDataFromHidden('bank');");
initaddobj("hidd_nid_span","","../xml/EsManageIsHavePoint.xsl","0","0","0","","","0","");

function init()
{
	readXmlToObjById("xiaoquselect");
}

var xmlurl2 = G_ROOT_PATH + "Web/LoadDbToXml.aspx?pid=web_getdistrictinfobylpid&csnum=2&cn1=cityid&cv1=" + G_CITY_SHORT_NAME;
var xslurl2 = G_ROOT_PATH + "agentsys/xml/GetXiaoQuInfo.xsl";

initaddobj("getonexiaoquinfo","",xslurl2,"0","0","0","","","0","setxiaoquinfo();");


function doaddrkeyup(obj)
{

	if (document.getElementById("select_xiaoqu"))
	{
		var coll = document.getElementById("select_xiaoqu").options;
		if (obj.value == '') {
			coll[0].selected = true;
			return;
		}

		var i = 1;
		for (; i < coll.length; i++) {
			if (coll[i].text.indexOf(obj.value) == 0) {
				coll[i].selected = true;
				break;
			}
		}
		if (i == coll.length) {
			coll[0].selected = true;
		}
	}
}

function doaddrblur(obj)
{
	if (document.getElementById("select_xiaoqu"))
	{
		var sOptionText = '';
		if (document.getElementById("select_xiaoqu").selectedIndex > 0) {
			sOptionText = document.getElementById("select_xiaoqu").options(document.getElementById("select_xiaoqu").selectedIndex).innerText;
		}
		
		if (document.activeElement == document.getElementById("select_xiaoqu")) {
			obj.value = sOptionText;
			return;
		}

		if (document.getElementById("select_xiaoqu").selectedIndex > 0 && obj.value != sOptionText) {
			if (confirm('选择 [' + sOptionText + '] 吗？')) {
				document.getElementById("select_xiaoqu").fireEvent('onchange');
			}
			else {
				document.getElementById("select_xiaoqu").selectedIndex = 0;
			}
		}
		else {
			document.getElementById("select_xiaoqu").fireEvent('onchange');
		}
	}
}

function doonchangeselectxiaoqu(obj)
{
	if (obj.value != '') { 
	    lpid = obj.value;
		SetPageLoadObjById("getonexiaoquinfo",1,xmlurl2 + "&cn2=lpid&cv2=" + obj.value);
		readXmlToObjById("getonexiaoquinfo");
//		alert(document.all("ddl_areainfo").value);
//		document.getElementById("ddl_areainfo").fireEvent('onchange');
	}
}



function setxiaoquinfo()
{
	if (document.getElementById("xiaoqu_lp_name"))
	{
		if (document.getElementById("txt_addrinfo"))
		{
			document.getElementById("txt_addrinfo").value = document.getElementById("xiaoqu_lp_name").value;
			document.getElementById("addrinfo").value = document.getElementById("txt_addrinfo").value;
		}		
	}

	if (document.getElementById("xiaoqu_lp_address"))
	{
		if (document.getElementById("txt_addressinfo"))
		{
			document.getElementById("txt_addressinfo").value = document.getElementById("xiaoqu_lp_address").value;
		}		
	}



	if (document.getElementById("xiaoqu_areaname"))
	{
		var qu = document.getElementById("xiaoqu_areaname").value;
		var qulist = document.getElementById("ddl_areainfo").options;	  
		for(var i=0;i<qulist.length;i++)
		{		
			if(qulist[i].value == qu){qulist[i].selected=true;}
		}
	}


	if (document.getElementById("xiaoqu_lp_starttime"))
	{
		var nf = document.getElementById("xiaoqu_lp_starttime").value;
		var nflist = document.getElementById("ddl_buildyear").options;	  
		if (4 < nf.length)
		{
			var nflist = document.getElementById("ddl_buildyear").options;	  
			for(var i=0;i<qulist.length;i++)
			{		
				if(nflist[i].value == nf.substring(0,4)){nflist[i].selected=true;}   
			}
		}
	}
	
}

//获取楼盘信息的地址 end
function findfromlib(obj)
			{
				var fileid = obj.id;
				var strwhere ="";
				var layout1 = document.getElementById("ddl_houselayout1").value;
				var layout2 = document.getElementById("ddl_houselayout2").value;
				var layout3 = document.getElementById("ddl_houselayout3").value;
				var layout4 = document.getElementById("ddl_houselayout4").value;

				var lab_lpid = lpid;
				strwhere +=  "&layout1=" + layout1;
				strwhere +=  "&layout2=" + layout2;
				strwhere +=  "&layout3=" + layout3;
				strwhere +=  "&lab_lpid=" + lab_lpid;
				strwhere +=  "&houseid=" + houseid;
				nowpicid = fileid;
				if ("_filelayout" == fileid)
				{
					window.open('EsManagePic.aspx?typeid=layout'+strwhere,'','');
				}
				else
				{
					window.open('EsManagePic.aspx?typeid=photo'+strwhere,'','');
				}
			}
			function delpic(picname)
			{
				if(picname == "pic2")
				{
					alert("您现在要删除房源默认图片，删除后请重新上传一张房源默认图片");
				}
				if(confirm("您确定要删除此图片吗？"))
				{
					delUrl = "../../Web/LoadDbToXml.aspx?pid=manage_h_delpicbyhouseid&csnum=3&cn1=houseid&cv1=" + houseid +  "&cn2=picid&cv2=" + picname.replace("pic","") + "&cn3=type&cv3=1";
					DelPicDataFromDB(delUrl);
					document.all(picname).innerHTML = "";
					if(picname == "pic2")
					{
						document.all('housepic2').value = "";;
					}
				}
			}
		    function dellaypic(picname)
			{
				if(confirm("您确定要删除此图片吗？"))
				{
					delUrl = "../../Web/LoadDbToXml.aspx?pid=manage_h_delpicbyhouseid&csnum=3&cn1=houseid&cv1=" + houseid + "&cn2=picid&cv2=" + picname.replace("pic","") + "&cn3=type&cv3=1";
					DelPicDataFromDB(delUrl);
					document.all("lab_h_viewlaypic").innerHTML = "";
					document.all("btn_del").style.display = "none";
				}
			}
			function DelPicDataFromDB(delUrl)
			{
				XMLHttp.sendReq('GET', delUrl , '', NoDo,"","");
			}
			function NoDo(vara1,vara2)
			{
				
			}
			function ShowNopassDiv(obj,objdiv)
		    {
		        var ttop  = obj.offsetTop; 
				var tleft = obj.offsetLeft;
				var theight =obj.offsetHeight;
				var elem = obj;
				while (obj = obj.offsetParent)
				{
					ttop+=obj.offsetTop; 
					tleft+=obj.offsetLeft;
				}
				var parm = document.getElementById(objdiv);	
				parm.style.visibility = "visible";
				parm.style.display = "";
				parm.style.top = ttop+theight;
				parm.style.left = tleft;
				return false;
		    }
		    function displaydiv(obj)
		    {
				obj.style.display = "none";
		    }
		    function DisplayBlock(area)
		    {
				document.all("hidd_square").value = "";
				if(area == "")
				{
					document.all("div_square").innerHTML = "请首先选择区域";
				}
				else
				{
					SetPageLoadObjById("div_square",1,"../../Web/LoadDbToXml.aspx?pid=manage_h_squarebyareainfo&csnum=1&cn1=aravalue&cv1=" + area);
					readXmlToObjById("div_square");
				}
		    }
		    function OutValue(square)
		    {
				document.all("hidd_square").value = square;
		    }
		    function DisplayDept(rType,deptid)
		    {
				if(rType == "rb_assignbyhand")
				{
					if(deptid.length == 10)
					{
						document.all("assigndeptid").style.display = "";
					}
					else if(deptid.length == 20)
					{
						DisplayUserid(deptid);
					}
				}
				else if(rType == "rb_autoassign" || rType == "rb_unassign")
				{
					document.all("assigndeptid").style.display = "none";
					document.all("ddl_dept").selectedIndex = 0;
					document.all("assignuserid").innerHTML = "";
					document.all("assigntouserid").value = "";
				}
		    }
		    function DisplayUserid(deptid)
		    {
				document.all("assigntouserid").value = "";
				if(deptid == "")
				{
					document.all("assignuserid").innerHTML = "";
					document.all("assigntouserid").value = "";
					return;
				}
				document.all("assignuserid").innerHTML = "正在加载部门人员，请稍候...";
				var xslmakeurl1 = "../../Web/LoadDbToXml.aspx?pid=manage_u_getuseridbydeptid&csnum=2&cn1=type&cv1=1&cn2=deptid&cv2=" + deptid;
				SetPageLoadObjById("assignuserid",1,xslmakeurl1);
				readXmlToObjById("assignuserid");
				
		    }
		    function OutUserid(userid)
		    {
				document.all("assigntouserid").value = userid;
		    }
			function YinCangDiv(obj)
			{	
				document.all(obj).style.display = "none";		
			}
						//获取基础设施
			function setroomsettingvalue()
			{ 
			    var objlist = document.all("vallist");
			    var i=0;
				var str = "";
			    var pobj = document.getElementById("txt_roomsetting");
                if(objlist)
                {
                    if(objlist.length)
                    {
                        for(i=0; i <= objlist.length-1; i++)
                        {
                            var v1 = objlist[i].value;
							if (objlist[i].checked)  
							{
								if ( "" == str)
								{
									str += objlist[i].value; 
								}
								else
								{
									str += "、" + objlist[i].value; 
								}
							}
                        }
                    }
                    else
                    {
                        var v1 = objlist.value;
						if (objlist.checked)
						{
							if ( "" == str)
							{
								str += objlist.value; 
							}
							else
							{
								str += "、" + objlist.value; 
							}
						}
                    }
                }
                pobj.value = str;
                document.getElementById("resetdiv").style.display = "none";
		    }
//地图相关部分
			function gotomapbar(url)
			{    
				var action ="";
				var mapwin;
				var mapbarpointhouseurl = "";
				var mapbarpointediturl = "";
				var totalorice = 0;

				if(document.getElementById("ddl_countexpress").value == "元/月")
				{
					totalorice = parseFloat(document.getElementById("txt_inputprice").value) * parseFloat(document.getElementById("txt_inputprice").value);
					totalorice = totalorice/10000;
				}
				else
				{
					totalorice = parseFloat(document.getElementById("txt_inputprice").value);
				}
				//获取地图标点的相关参数 begin
				mapbarpointhouseurl +=  "&name=" + document.getElementById("txt_addrinfo").value;
				mapbarpointhouseurl +=  "&infoid=" + infoid;
				mapbarpointhouseurl +=  "&city=" + city;
				mapbarpointhouseurl +=  "&type=" + "二手房";
				mapbarpointhouseurl +=  "&house=" + document.getElementById("ddl_housetype").value;
				mapbarpointhouseurl +=  "&price=" + totalorice;
				mapbarpointhouseurl +=  "&limit=" + "1";
				mapbarpointhouseurl +=  "&addr="  + document.getElementById("ddl_areainfo").value; // + hib.Addressinfo;  //目前不显示详细地址
				mapbarpointhouseurl +=  "&tel=" ;
				mapbarpointhouseurl +=  "&mapurl=" + RootPath + ROOT_PATH + "agentsys/map/showmapinfo.aspx?infoid=" + infoid;
				
				mapbarpointaddurl = ROOT_PATH + "agentsys/map/mapbarpoint.aspx" + "?T=0" + mapbarpointhouseurl;
				mapbarpointediturl = ROOT_PATH + "agentsys/map/mapbarpoint.aspx" + "?T=1" + mapbarpointhouseurl;
				
				//获取地图标点的相关参数 end
				var mapwin = window.open(mapbarpointediturl,'mapedit','width=640,height=480,status=no,toolbar=no,title=no');
				mapwin.focus();
				action = "add";
			}
			function HasPoints()
			{
				window.opener = null;
				var	__src="GetDataFromMapbar.aspx?lbackxml=yes&url=http://club.mapbar.com/center/client/share/hasPoi.jsp?U=goufangMap&infoid=" + infoid;
				XMLHttp.sendReq('GET', __src , '', GetData,'','');
				window.opener = null;
			}

			function GetNearby(type,nid,divid)
			{
				var url = "http://club.mapbar.com/center/client/dlfc/api/nearby.jsp?nid=" + nid + "&poitype=" + type + "&RowNumber=1000";
				var	__url="GetDataFromMapbar.aspx?lbackxml=yes&url=" + url;
				SetPageLoadObjById(divid,1,__url);
				readXmlToObjById(divid);
			}
			//将hidden input 里面的值放到TextBox中
			function GetDataFromHidden(divid)
			{
				document.all("txt_" + divid).value = document.all("_" + divid).value;
			}
			function checkmapbar()
			{
				GetDataSuccess = setInterval(Timer,1000);
				var h_addrinfo = document.getElementById("txt_addrinfo");
				var h_inputprice = document.getElementById("txt_inputprice");
				var h_housetype = document.getElementById("ddl_housetype");
				if(h_addrinfo.value == "")
				{
					alert("请添写地址，方便别人通过电子地图知道房屋地址");
					h_addrinfo.focus();
					return false;
				}
				else if(h_inputprice.value == "")
				{   
					alert("请添写房屋售价，方便别人通过电子地图知道房屋售价");
					h_inputprice.focus();
					return false;
				}
				else if(h_housetype.value == "")
				{
					alert("请添写房屋类型，方便别人通过电子地图知道房屋类型");
					h_housetype.focus();
					return false;
				}
				else
				{
				    gotomapbar();
				}
				if(document.all('btn_mapbar').value == "电子地图未标点")
				{
					HasPoints();
				}
				else if(document.all('btn_mapbar').value == "电子地图已标点")
				{
					document.all("tiqu").style.display = "";
					document.all("tiqu").value = "重新提取公交路线等数据";
				}
			}
			function Timer()
			{
				MaxTime += 1;
				if(MaxTime > 150)
				{
					GetDataSuccess = null;
				}
			}
function readXmlToObjByIdEsAdd(objid)
{ 
	for(i=0;i<_PageLoadObj.length;i++)
	{
	tmpobj = _PageLoadObj[i];
	if (objid == tmpobj[0])
	{
		readXmlToObjByNoEsAdd(i);
	}
	}
}
function readXmlToObjByNoEsAdd(objno)
{ 
	var url = _PageLoadObj[objno][1];
	var xslfile = _PageLoadObj[objno][2];
	if(xslfile == "")
	{
	XMLHttp.sendReq('GET', url , '', GetData,objno,'');
	}
	else
	{
	XMLHttp.sendReq('GET', xslfile , '', Transxmlxsl,objno,url);
	}
}
function GetData(getxmlobj,noth1,noth2)
{
	var TorF = getxmlobj.responseTEXT;
	if(TorF.indexOf("True") != -1)
	{
		document.all("btn_mapbar").value = "电子地图已标点";
		if(document.getElementById("txt_buslines").value != "" || document.getElementById("txt_education").value != "" ||document.getElementById("txt_business").value != "" ||document.getElementById("txt_hospital").value != "" ||document.getElementById("txt_bank").value != "" )
		{
			if(!confirm("你之前填写的交通、教育、商业、银行、医疗等信息将被覆盖！"))
			{
				return;
			}
		}
		var url = "http://club.mapbar.com/center/client/dlfc/api/getDetail.jsp?infoid=" + infoid;
		var __url = "GetDataFromMapbar.aspx?lbackxml=yes&url=" + url;
		SetPageLoadObjById("hidd_nid_span",1,__url);
		readXmlToObjByIdEsAdd("hidd_nid_span");
	}
	else
	{
		if(MaxTime >= 150)
		{
			document.all("tiqu").style.display = "";
			return;
		}
		else
		{
			HasPoints();
		}
//		alert("请首先标点地图");
	}

}
function Transxmlxsl(getxslobj,objno,url) {
	_PageLoadObjXsl[objno] = getxslobj.responseXML;
	CheckXslVar(_PageLoadObjXsl[objno]);
	XMLHttp.sendReq('GET', url , '', OnLoadResultXmlEsAdd,objno,'true');  //true 表示用xml方式获取
}
function OnLoadResultXmlEsAdd(getxmlobj,objno,xslfile) {
	var htmlCode = "";
	var xml ;
	if(null == getxmlobj)	//错误时，返回空
	{
	return;
	}
	xml = getxmlobj.responseXML;
	var xsl = _PageLoadObjXsl[objno];
	try
	{
		htmlCode = xml.transformNode(xsl);
	}
	catch(e)
	{
		window.status += objno + "_OnLoadResultXml_" + e.message;
	}
	if (objno < _PageLoadObj.length)
	{
	var divid = _PageLoadObj[objno][0];
	echo(divid,htmlCode);
	_PageLoadObj[objno][3] = 1;}
	var nid = document.all("hidd_nid").value;
	if(nid != "")
	{
//		if(confirm("你之前填写的交通、教育、商业、银行、医疗等信息将被覆盖！"))
//		{
			//拼装Hidden input
			GetNearby("G",nid,"buslines");
			//教 育 A 
			GetNearby("A",nid,"education");
			//商 业 5
			GetNearby("5",nid,"business");
			//医 疗 D
			GetNearby("D",nid,"hospital");
			//银 行 8
			GetNearby("8",nid,"bank");
//		}
	}
	else
	{
		alert("系统错误，请刷新此页面");
	}
}