/////////////////////////////////////////////////////////////////////////////
//选择区域的新方法
var dis_str="";
var topdis="";
var dis_type="";
var dis_num=0;
var diswin=GetTopWin().top.district;
//type为0 表示区域可以多选 为 2表示用于查询使用 为 1 用于录入房源（必须到第三级） 3表示不能到第三级 （增加区域）
function showDistrict(id,obje,type){
	dis_type=type;
	if(id==""||id==0){
		id=diswin.FirstId;
	}
    obj_=obje;
	table = document.getElementById("tablepage");
	table.innerHTML="请稍候 ...";
	var temp="";
	temp+="<table border='0' cellspacing='0' cellpadding='0'>";
	temp+="<tr onclick='javascript:CloseDivId()'><td width='9' height='15' align=left colspan=2><img src='/images/div1.jpg' border=0 ></img></td>";
	temp+="    <td height='9' align='right' bgcolor='white'><a href='javascript:CloseDivId()'><img src='/images/close2.gif' border=0 wifth=14 height=14></img></a></td>";
	temp+="    <td width='9' colspan='2' align='right'><img src='/images/div2.jpg' border=0 ></img></td></tr>";
	temp+="<tr><td height='1' colspan='5' bgcolor='4E5B6C'></td></tr>";
	temp+="<tr>";
	temp+="    <td width='1' bgcolor='4E5B6C'></td>";
	temp+="    <td width='8' class=ajtd></td>";
	temp+="    <td class=ajtd>";
	//插入内容开始
	temp+="<table border=0 cellspacing=1 cellpadding=0  align=center>";
	var t="";
	var name="";
	var str="";
	var i=0;
	//////////////////////////////////
	if(type==0){
	//这里显示 已经选中的区域
		temp+="<tr><td colspan=3 nowrap  align=left>";
		temp+="<div id='disdis' nowrap>";
		topdis=obje.value;
		temp+=showdis(topdis);	
		temp+="</div>";
		temp+="</td></tr>";
	}
	///////////////////////////////////
	temp+="<tr><td colspan=3 nowrap align=left>拼音或汉字查找区域:<input class=myinput size=10 id=dis_spell onKeyUp=spell(this)></td></tr>";
	temp+="<tr><td colspan=3 nowrap align=left><a href='javascript:GoDis(\""+diswin.FirstId+"\",\""+diswin.cityName+"\")'>"+diswin.cityName+"</a>";
	temp+="<span id=distitle>";
	temp+=Distitle(id);
	temp+="</span></td></tr>";
	temp+="<tr><td colspan=3 nowrap  align=left>";
	temp+="<div id=dis2>";
    i=0;
	dis_str=diswin.getStr(id,"");
	if(dis_type==2){
		dis_str+="^无^$";
	}
	temp+=showdis2(dis_str);
	temp+="</div>";
	temp+="</td></tr>";
    temp+="</table>";
//插入内容结束
	temp+="    </td>";
	temp+="    <td width='8' class=ajtd></td>";
	temp+="    <td width='1' bgcolor='4E5B6C'></td></tr>";
	temp+="<tr class=ajtd>";
	temp+="    <td width='9' colspan=2></td>";
	temp+="    <td height='8' ></td>";
	temp+="    <td width='9' colspan=2></td>";
	temp+="</tr>";
	temp+="<tr bgcolor='4E5B6C'>";
	temp+="    <td width='9' colspan=2></td>";
	temp+="    <td height='1' ></td>";
	temp+="    <td width='9' colspan=2></td>";
	temp+="</tr>";
	temp+="</table>";
	table.innerHTML=temp;
	displayLayer();
}
function tomcheck(obj,name){
	if(obj.checked){
		topdis+=name+" ";
	}
	else{
		topdis=topdis.replace(name+" ","");
	}
	document.getElementById("disdis").innerHTML=showdis(topdis);
}
function topcheck(obj,name){
	topdis=topdis.replace(name+" ","");
	document.getElementById("dis2").innerHTML=showdis2(dis_str);
	document.getElementById("disdis").innerHTML=showdis(topdis);
}
//已经选中的区域显示
function showdis(pro,type){
	var temp="";
	var t="";
	var name="";
	var i=0;
	obj_.value=pro;
	temp+="<table border=0 cellspacing=1 cellpadding=0  align=center align=left>";
    while(pro.indexOf(" ")>0){
		t=pro.substring(0,pro.indexOf(" "));
		name=t;
        pro=pro.replace(t+" ","");
        if(i%3==0){
			temp+="<tr>";
        }
        temp+="<td nowrap align=left><input type=checkbox value=1 checked onclick=topcheck(this,\""+name+"\")>&nbsp;"+name+"&nbsp;&nbsp;</td>";
        i++;
		if(i%3==0){
            temp+="</tr>";
        }
     }
     while(i%3!=0){
        temp+="<td nowrap>&nbsp;</td>";
        i++;
        if(i%3==0){
            temp+="</tr>";
        }
     }
	 temp+="</table>";
	 return temp;
}
//按照区域架构显示区域
function showdis2(str){
	var temp="";
	var t="";
	var name="";
	var id="";
	var i=0;
	temp+="<table border=0 cellspacing=1 cellpadding=0  align=center align=left>";
    while(str.indexOf("$")>0){
		t=str.substring(0,str.indexOf("$"));
        id=t.substring(0,t.indexOf("^"));
        t=t.substring(t.indexOf("^")+1);
		name=t.substring(0,t.indexOf("^"));
        str=str.replace(id+"^"+name+"^"+"$","");
        if(i%3==0){
			temp+="<tr>";
        }
		if(dis_type==0){
			temp+="<td nowrap>&nbsp;<input type=checkbox name=pro value=1 onclick=tomcheck(this,\""+name+"\") "+(topdis.indexOf(name+" ")>=0?"checked":"")+">&nbsp;<a href='javascript:GoDis(\""+id+"\",\""+name+"\")'>"+name+"</a>"; //<font color=red>选中</font>
        }
		else{
			temp+="<td nowrap>&nbsp;<a href='javascript:GoDis(\""+id+"\",\""+name+"\")'>"+name+"</a>";
		}
        temp+="&nbsp;&nbsp;</td>";
        i++;
        if(i%3==0){
            temp+="</tr>";
        }
		if(i==99){
			break;
		}
     }
	 if(i==99){
		temp+="<tr><td nowrap colspan=3>&nbsp;&nbsp;<font color=red>本页只显示100条数据,如无选择,请输入更详细内容！</font></td></tr>";
	 }
     while(i%3!=0){
        temp+="<td nowrap>&nbsp;</td>";
        i++;
        if(i%3==0){
            temp+="</tr>";
        }
     }	
	 temp+="</table>";
	 return temp;
}
function Distitle(id){
	var temp="";
	var name="";
	var upid=id;
	dis_num=0;
	while(upid!=diswin.FirstId){
		//得到上级部门ID
		upid=diswin.getUpDisId(upid);
		if(upid==diswin.FirstId){break;}
		name=diswin.getDisNmae(upid);
		temp="-<a href='javascript:GoDis(\""+upid+"\",\""+name+"\")'>"+name+"</a>"+temp;
		dis_num++;
	}
	if(id!=diswin.FirstId){
		name=diswin.getDisNmae(id);
		temp+="-<a href='javascript:GoDis(\""+id+"\",\""+name+"\")'>"+name+"</a>";	
	}
	return temp;
}
function spell(obj){
	dis_str=diswin.getStr("",obj.value);
	document.getElementById("dis2").innerHTML=showdis2(dis_str);
}
function GoDis(id,name){
	if(id==""){
		obj_.value="";
		form1.disid.value="";
		CloseDivId();
		return;
	}
	dis_str=diswin.getStr(id,"");
	if(dis_type==2){
		dis_str+="^无^$";
	}
	document.getElementById("dis2").innerHTML=showdis2(dis_str);
	document.getElementById("distitle").innerHTML=Distitle(id);
	if(dis_type==2){
		obj_.value=name;
	}
	if(dis_type==3&&dis_num<=1){
		obj_.value=name;
		form1.disid.value=id;
		if(dis_num==1){
			CloseDivId();
		}
		return;
	}
	if(dis_type!=0&&dis_num==2){
		if(dis_type==3){
			alert("不能选择到第三级小区！");
			return;
		}
		obj_.value=name;
		form1.disid.value=id;
		CloseDivId();
	}
}
//根据区域ID获取区域的全名
function getDisNameall(id){
	var temp="";
	var name="";
	var upid=id;
	while(upid!=diswin.FirstId){
		//得到上级部门ID
		upid=diswin.getUpDisId(upid);
		if(upid==diswin.FirstId){break;}
		name=diswin.getDisNmae(upid);
		temp="-"+name+temp;
	}
	if(id!=diswin.FirstId){
		name=diswin.getDisNmae(id);
		temp+="-"+name;	
	}
	return temp+"-";
}
/////////////////////////////////////////////////////////////////////////////