var $ = function(i)
{
return document.getElementById(i);
};
var $$=function(node)
{
return document.getElementsByName(node);
};
var pos=-1;
function Offset(e)
//取标签的绝对位置
{
    var t = e.offsetTop;
    var l = e.offsetLeft;
    var w = e.offsetWidth;
    var h = e.offsetHeight;
    while(e=e.offsetParent)
    {
    t+=e.offsetTop;
    l+=e.offsetLeft;
    }
    return {
    top : t-25,
    left : l,
    width : w,
    height : h
    }
}


function DefineRequest() {//初始化、指定处理函数、发送请求的函数
//开始初始化XMLHttpRequest对象
var name=false;
if(window.XMLHttpRequest) { //Mozilla 浏览器
name = new XMLHttpRequest();
if (name.overrideMimeType) {//设置MiME类别
//name.overrideMimeType('text/xml');
}
}
else if (window.ActiveXObject) { // IE浏览器
try {
name = new ActiveXObject("Msxml2.XMLHTTP");
} 
catch (e) {
try {
name = new ActiveXObject("Microsoft.XMLHTTP");
} 
catch (e) {}
}
}
if (!name) { // 异常，创建对象实例失败
window.alert("不能创建XMLHttpRequest对象实例.");
return false;
}
return name;
}

//定义xmlhttp对象
var xmlhttp = new DefineRequest();
var timeid=0;

//插入房源
function insertHouse(url,fun,xml)
{
    xmlhttp = new DefineRequest();
	xmlhttp.open("POST",url,true);
	xmlhttp.setRequestHeader("content-length",xml.length);
	xmlhttp.setRequestHeader("content-type","application/x-www-form-urlencoded");
	xmlhttp.onreadystatechange=function()
	{
		if(xmlhttp.readyState==4)
		{
			if (xmlhttp.status == 200) 
			{
				fun(xmlhttp.responseText);
			}
			else
			{
			    alert("服务器异常或通信延迟，请稍后重新发布");
			    $('tijiao').value="提交";
			}
		}
		else
		{
		    //提示页面正在提交中
            $('tijiao').value="Loading...";
		}
	};
	xmlhttp.send(xml);
}

//遍历出租发布页面控件，生成post的字符串
function getPostXml(obj)
{
    var str = new Array(obj.length);
    var returnstr="";
    for(m=0;m<obj.length;m++)
    {
        if(obj[m].type=="text"||obj[m].type=="select-one"||obj[m].type=="hidden"||obj[m].type=="textarea")
        {
            str[m] = obj[m].name+"="+escape(obj[m].value);
        }
    }
    returnstr = str.join('&')+getCheckedValue('baseinfo_str_baseservice');
    returnstr += getCheckedValue('baseinfo_num_price')+getCheckedValue('baseinfo_str_payinfo');
    returnstr += getCheckedValue('baseinfo_str_fitment');
    returnstr += getCheckedValue('baseinfo_str_privider');
    returnstr = replaceAnd(returnstr);
    return returnstr;
}

function getPostXmlSeek(obj)
{
    var str = new Array(obj.length);
    var returnstr="";
    for(m=0;m<obj.length;m++)
    {
        if(obj[m].type=="text"||obj[m].type=="select-one"||obj[m].type=="hidden"||obj[m].type=="textarea")
        {
            str[m] = obj[m].name+"="+escape(obj[m].value);
        }
    }
    returnstr = str.join('&')+getCheckedValue('baseinfo_str_baseservice');
    returnstr += getCheckedValue('extendinfo_str_psex');
    returnstr += getCheckedValue('baseinfo_str_fitment');
    returnstr = replaceAnd(returnstr);
    return returnstr;
}

function getCheckedValue(objid)
{
    var check="";
    for(n=0;n<$$(objid).length;n++)
    {
        if($$(objid)[n].checked==true)
        {
            check += $$(objid)[n].value+',';
        }
    }
    check = check.substr(0,check.length-1);
    return "&"+objid+"="+escape(check)+"&";
}

function replaceAnd(str)
{
    if(str.indexOf("&&")>0)
    {
        str = str.replace("&&","&");
    }
    else
    {
        return str;
    }
    str = replaceAnd(str);
    return str;
}

function ReadyGetName(url,province,city,e)
{
    if(e!=38&&e!=40&&e!=37&&e!=39&&e!=13)
    {
        if(timeid!=0)
        {window.clearTimeout(timeid);}

        timeid=window.setTimeout("showPopUp('"+url+"','"+province+"','"+city+"','"+e+"')",500)
    }
//    else if(e==27)//esc的处理
//    {
//        $('baseinfo_str_projname').focus();
//    }
    else if(e==13)//enter的处理
    {
        if($('uUlchildnewcode')==null)return;
        var liobj=$('uUlchildnewcode').getElementsByTagName("li");
        if(liobj==null)return;
        for(n=0;n<liobj.length;n++)
        {
            if(liobj[n].style.background.substr(0,4)=="gray")
            {
                $("bak_projname").value=liobj[n].id;
                bindProjInfo();
                $("bak_projname").value="";
                removeNode();
            }   
        }
    }
    else if(e==38||e==40)
    {
        if($('selectchildnewcode')!=null)
        {
            if($('uUlchildnewcode')!=null)
            {
                $('uUlchildnewcode').focus();
                var liobj=$('uUlchildnewcode').getElementsByTagName("li");
                if(e==40)
                {
                    if(pos<liobj.length)
                    {
                        pos++;
                        if(pos>=liobj.length) pos=0;
                    }
                    if(pos>=liobj.length) pos=0;
                }
                if(e==38)
                {
                    if(pos>=0)
                    {
                        pos--;
                        if(pos<=-1)
                        {
                            pos=liobj.length-1;
                        }
                    }
                    else
                        pos=liobj.length-1;
                }
                for(m=0;m<liobj.length;m++)
                {
                    liobj[m].style.background="white";
                    liobj[m].style.color="black";
                }
                if(0<=pos&&pos<liobj.length)
                {
                    $('selectchildnewcode').scrollTop=(20*(pos-2));
                    liobj[pos].style.background="gray";
                    liobj[pos].style.color="white";
                }
            }
        }
    }
}

function showPopUp(url,province,city,e)
{
    var projname = $("baseinfo_str_projname").value;
    //区县，商圈置可选
    sdistrict($("baseinfo_str_district"),province,city);
    sarea_new($("comarea"),province,city,$("baseinfo_str_district").value);
    $("baseinfo_str_district").onclick=function() {setarea(province,city)};
    xmlhttp = new DefineRequest();
    var dicinf,comarea,district,address,projname;
    var showstr = "<select id='newcode' name='newcode'>";
    xmlhttp.onreadystatechange = function()
    {
        if(xmlhttp.readyState==4)
        {
            if(xmlhttp.status==200)
            {
                dicinf = eval(xmlhttp.responseText);
                //alert(xmlhttp.responseText);
                if(dicinf!=undefined)
                {
                    for(i=0;i<dicinf.length;i++)
                    {
                    var ovl = "[{comarea:\""+dicinf[i].comarea+"\",district:\""+dicinf[i].district+"\",address:\""+dicinf[i].address+"\",projname:\""+dicinf[i].projname+"\"}]";
                    showstr += "<option value='"+ovl+"'>"+dicinf[i].newprojname+"</option>";
                    }
                }
                showstr +="</select>";
                if(dicinf==undefined)
                {
                   removeNode();
                    return;
                }
                $("DivGroup").innerHTML  = showstr;
                loadSelect($("newcode"),e);
            }
        }
    }
    xmlhttp.open("GET",url+"?projname="+escape(projname)+"&time="+new Date().getTime(),true);
    xmlhttp.send(null);
}

function loadSelect(obj,e)
{	
    removeNode();
    var offset=Offset(obj);
    if(obj.selectedIndex>-1)
    {
    //alert("dd");
        obj.style.display="none";
        var iDiv = document.createElement("div");
        iDiv.id="selectof" + obj.name;
        iDiv.style.position = "absolute";
        iDiv.style.width="139px";
        iDiv.style.height=offset.height + "px";
        iDiv.style.top="187px";
        iDiv.style.left= offset.left-83+"px";
        iDiv.style.border="1px solid #3366ff";
        iDiv.style.fontSize="12px";
        iDiv.style.lineHeight=offset.height + "px";
        iDiv.style.textIndent="4px";
        iDiv.style.display="none";
        document.body.appendChild(iDiv);

        iDiv.innerHTML=obj.options[obj.selectedIndex].innerHTML;
    }
    else
        $("DivGroup").innerHTML="";
    if ($("selectchild" + obj.name))
    {
        //判断是否创建过div
        if (childCreate)
        {
            //判断当前的下拉是不是打开状态，如果是打开的就关闭掉。是关闭的就打开。
            $("selectchild" + obj.name).style.display="";
            childCreate=true;
        }
        else
        {
            $("selectchild" + obj.name).style.display="";
            childCreate=true;
        }
    }
    else
    {
        //alert("dd");
        //初始一个div放在上一个div下边，当options的替身。
        var cDiv = document.createElement("div");
        cDiv.id="selectchild" + obj.name;
        cDiv.onmouseover = function(){$('isSelect').value="1";
            };
        cDiv.onmouseout = function(){$('isSelect').value="";
            };
        cDiv.onpropertychange=function(){pos=-1;};
        cDiv.style.textAlign="left";
        cDiv.style.position = "absolute";
        cDiv.style.width="200px";
        if(obj.selectedIndex>-1)
        {
            cDiv.style.height="100px";
        }
        else
            cDiv.style.display="none";
        cDiv.style.overflow="auto";
        cDiv.style.top="187px";
//        var screenw = screen.width;
//        var left = screenw/2-122;
        //alert(left);
        cDiv.style.left= offset.left-83+"px";
        cDiv.style.background="white";
        cDiv.style.border="1px solid silver";
        var uUl = document.createElement("ul");
        uUl.id="uUlchild" + obj.name;
        uUl.style.listStyle="none";
        uUl.style.margin="0";
        uUl.style.padding="0";
        uUl.style.fontSize="12px";
        cDiv.appendChild(uUl);
        document.body.appendChild(cDiv);        
        childCreate=true;
        //隐藏select
        $("baseinfo_str_district").style.display="none";
        $("comarea").style.display="none";
        for (var i=0;i<obj.options.length;i++)
        {
            //将原始的select标签中的options添加到li中
            var lLi=document.createElement("li");
            lLi.id=obj.options[i].value;
            lLi.name="childLi";
            lLi.style.textIndent="4px";
            lLi.style.height="20px";
            lLi.style.lineHeight="20px";
            lLi.style.align="left";
            lLi.innerHTML=obj.options[i].innerHTML;
            uUl.appendChild(lLi);
        }
        var liObj=$("uUlchild" + obj.name).getElementsByTagName("li");
        for (var j=0;j<obj.options.length;j++)
        {
            //为li标签添加鼠标事件
            liObj[j].onmouseover=function(){
                this.style.background="gray";
                this.style.color="white";
                $("bak_projname").value=this.id;};
            liObj[j].onmouseout=function(){
                this.style.background="white";
                this.style.color="black";
                $("bak_projname").value='';};
            liObj[j].onclick=function(){
                //做两件事情，一是将用户选择的保存到原始select标签中
                obj.options.length=0;
                obj.options[0]=new Option(this.innerHTML,this.id);
                //同时我们把下拉的关闭掉。
                $("selectchild" + obj.name).style.display="none";
                childCreate=false;
                iDiv.innerHTML=this.innerHTML;
                bindProjInfo();
                //显示被隐藏的控件
                $("baseinfo_str_district").style.display="";
                $("comarea").style.display="";
                };
        }
    }

    if(obj!=null&&obj.selectedIndex>-1)
    {
       obj.style.display="none";
    }
}

function setarea(province,city)
{
    sarea_new($('comarea'),province,city,$('baseinfo_str_district').value);
}

//移除已经存在的节点
function removeNode()
{
    if($("selectofnewcode")!=null)$("selectofnewcode").parentNode.removeChild($("selectofnewcode"));
    if($("selectchildnewcode")!=null)$("selectchildnewcode").parentNode.removeChild($("selectchildnewcode"));
    if($("uUlchildnewcode")!=null)$("uUlchildnewcode").parentNode.removeChild($("uUlchildnewcode"));
    //显示select
    $("baseinfo_str_district").style.display="";
    $("comarea").style.display="";
}

//将选择的楼盘信息绑定到客户端控件
function bindProjInfo()
{
    $("baseinfo_str_projname").value=eval($("bak_projname").value)[0].projname;//写物业名称
    $("baseinfo_str_address").value=$("baseinfo_str_projname").value+eval($("bak_projname").value)[0].address;//物业地址
    var comarea = eval($("bak_projname").value)[0].comarea;//商圈
    var district = eval($("bak_projname").value)[0].district;//区县
    $("baseinfo_str_district").onclick=null;
    if(comarea!="")
    {
        clear($("comarea"));
        $("comarea").options.add(new Option(comarea,comarea));
    }
    if(district!="")
    {
        clear($("baseinfo_str_district"));
        $("baseinfo_str_district").options.add(new Option(district,district));
    }
}

function OpenPicWin()
	{
		if(!check_empty($("baseinfo_str_Projname"),"请先填写物业或小区名称！"))
		{return;}

	    var projname=$("baseinfo_str_Projname").value;
	    projname=TrimSpace(projname,0);
	    var url = "/newsecond/sale_info/returnnewhousepic.aspx?projname="+projname;
    	
	    picwindow = window.open(url,"nw2","height=500,width=300,resizable=yes,scrollbars=yes,status=yes,toolbar=no,menubar=no,location=no");
	    if(!picwindow.opener)picwindow.opener=self;
	}
	
//判断是否为数字
function checkisnum(o)
{
	var s = document.getElementById(o);
	var reg =/^[0-9]*$/;
	if(!reg.test(trim(s.value)))
	{
		return false;
	}
	else{
		return true;}
}
	
//验证frm_info_input.aspx,成功则提交数据
function check_input(housetype,houseid)
    {
        if($('tijiao').value!='提交' && $('tijiao').value!=' 提交 ') return false;
        var obj = document.form1.elements;
        if(!checkAttr(obj)) return false;
        if($("comarea").value=="其它"&&trim($("comarea_other").value)==""){alert("请提供商圈信息！");$("comarea_other").focus();return false;}
        else if($("comarea").value=="其它"){$("baseinfo_str_comarea").value=$("comarea_other").value;}
        else $("baseinfo_str_comarea").value=$("comarea").value;
        $("baseinfo_str_address").value=$("baseinfo_str_address").value;
        //if(!check_checked(document.getElementsByName("baseinfo_str_privider"),"请选择信息来源！")){$("baseinfo_str_privider").focus();return false;}
	    if(!check_checked(document.getElementsByName("baseinfo_str_baseservice"),"请选择配套设施！")){$("baseinfo_str_baseservice").focus();return false;}
	    if(trim($("telephone2").value)==''&&trim($("baseinfo_str_mobilecode").value)==''){alert('请输联系电话或手机号！');$("telephone2").focus();return false;}
	    if(trim($("telephone2").value)!=""){if(!checkisnum("telephone2"))
	        {
	            alert("电话号码必须是数字");
	            return false;
	        }}
	    if($("telephone2").value.substr(0,1)=="1"){alert('您输入的电话号码有误');$("telephone2").focus();return false;}
	    if(trim($("telephone1").value)!=""&&$("telephone1").value.indexOf('013')==0){alert('区号不能以013开头');return false;}
	    if(trim($("telephone1").value)!=""&&$("telephone1").value.indexOf('0')!=0){alert('区号必须以0开头');return false;}
	    if($("telephone2").value!="")
	    {
	        $("baseinfo_str_telephone").value = $("telephone1").value+"-"+$("telephone2").value+"-"+$("telephone3").value;
	    }
	    //
	    if($("baseinfo_str_mobilecode").value!="")
	    {
	        if(!checkisnum("baseinfo_str_mobilecode"))
	        {
	            alert("手机号码必须是数字");
	            return false;
	        }
	        if($("baseinfo_str_mobilecode").value.length != 11 && $("baseinfo_str_mobilecode").value.length!= 13)
	        {
	            alert("手机位数不正确");
	            return false;
	        }
	    }
	    //for(j=1;j<=5;j++){if($("extendinfo_str_Img"+j+"Url").value!=""&&trim($("extendinfo_str_Img"+j+"Name").value)==""){alert("图片没有全部命名！");$("extendinfo_str_Img"+j+"Name").focus();return false;}}
	    //楼层
	    if(parseInt($('baseinfo_num_floor').value)>parseInt($('baseinfo_num_totlefloor').value)){alert("楼层数不能大于总楼层数");$('baseinfo_num_floor').focus();return false;}
	    
	    //面积
	    if(parseFloat($('baseinfo_num_buildingarea').value)<parseFloat($('baseinfo_num_livingarea').value)){alert("使用面积不能大于建筑面积");$('baseinfo_num_buildingarea').focus();return false;}
	    if(parseFloat($('baseinfo_num_buildingarea').value)<=0){alert("建筑面积必须大于零");$('baseinfo_num_buildingarea').focus();return false;}  ///
	    if($('baseinfo_num_livingarea').value!='' && parseFloat($('baseinfo_num_livingarea').value)<=0){alert("使用面积必须大于零");$('baseinfo_num_livingarea').focus();return false;}  ///
	    if(parseFloat($('baseinfo_num_buildingarea').value)>9999.99){alert("建筑面积不能大于9999.99");$('baseinfo_num_buildingarea').focus();return false;}  ///
	    if($('baseinfo_num_livingarea').value!='' && parseFloat($('baseinfo_num_livingarea').value)>9999.99){alert("使用面积不能大于9999.99");$('baseinfo_num_livingarea').focus();return false;}  ///
	    
	    //售价
	    if(parseFloat($('baseinfo_num_price').value)==0){alert('售价必须大于零');$('baseinfo_num_price').focus();return false;}
	    if(parseFloat($('baseinfo_num_price').value)>9999.99){alert('售价不能大于一个亿');$('baseinfo_num_price').focus();return false;}
	    
	    if($("baseinfo_str_description").value.length>200){alert("备注超出了200字符的限制！");$("baseinfo_str_description").focus();return false;}
	    if($("check_zj").checked==true&&$("baseinfo_str_description").value.length<190){$("baseinfo_str_description").value+="(中介勿扰)";}
	    insertHouse("/newsecond/sale_info/frm_info_save.aspx?houseid="+houseid,
	    function(r){
	        $('iframe_window').src='/newsecond/sale_info/input_success.aspx?housetype='+housetype+'&type='+r+'&isedit='+houseid;
	    },getPostXml(obj));
 }
 
 //验证求购发布页，并提交数据
 function check_input_seek(housetype,houseid)
{
    if($('tijiao').value!='提交' && $('tijiao').value!=' 提交 ') return false;
	var obj = document.form1.elements;
    if(!checkAttr(obj)) return false;
	if($('auto').checked)
	{
	    $('baseinfo_str_comarea').value="";//先清空原来的值，防止反复提交时，字段超长
		for(i=0;i<$('comarea_choose').options.length;i++)
		{
			$('baseinfo_str_comarea').value+=$('comarea_choose').options[i].value+',';
		}
		$('baseinfo_str_comarea').value=$('baseinfo_str_comarea').value.substr(0,$('baseinfo_str_comarea').value.length-1);
		if($('baseinfo_str_comarea').value==''){alert("请提供期望区域！");$('auto').focus();return false;}
		$('baseinfo_str_address').value=$('baseinfo_str_comarea').value;
	}
	else if($('man').checked)
	{
		if(trim($('area').value)==''){alert("请提供期望区域！");$('man').focus();return false;}
		$('baseinfo_str_address').value=$('area').value;
	}
	
	//价格
	if(parseFloat($('baseinfo_str_price').value)==0){alert('价格必须大于零');$('baseinfo_str_price').focus();return false;}
	if(parseFloat($('baseinfo_str_price').value)>9999.99){alert('价格不能大于一个亿');$('baseinfo_str_price').focus();return false;}
	//期望面积
	if(parseFloat($('baseinfo_str_buildingarea').value)<=0){alert("期望面积必须大于零");$('baseinfo_str_buildingarea').focus();return false;}  ///
	if(parseFloat($('baseinfo_str_buildingarea').value)>9999.99){alert("期望面积不能大于9999.99");$('baseinfo_str_buildingarea').focus();return false;}  ///
	
	if(trim($("telephone2").value)==''&&trim($("baseinfo_str_mobilecode").value)==''){alert('请输联系电话或手机号！');$("telephone2").focus();return false;}
	if($("telephone2").value.substr(0,1)=="1"){alert('您输入的电话号码有误');$("telephone2").focus();return false;}
	if(trim($("telephone2").value)!=""){if(!checkisnum("telephone2"))
	        {
	            alert("电话号码必须是数字");
	            return false;
	        }}
	if(trim($("telephone1").value)!=""&&$("telephone1").value.indexOf('013')==0){alert('区号不能以013开头');return false;}
	if(trim($("telephone1").value)!=""&&$("telephone1").value.indexOf('0')!=0){alert('区号必须以0开头');return false;}
	if($("telephone2").value!="")
	{
	    $("baseinfo_str_telephone").value = $("telephone1").value+"-"+$("telephone2").value+"-"+$("telephone3").value;
	}
	if($('baseinfo_str_description').length>=200){alert('备注不能超过200个字符');$('baseinfo_str_description').focus();return false;}
	if($('chzj').checked&&$("baseinfo_str_description").value.length<210){$('baseinfo_str_description').value+='（中介勿扰）'; }
	insertHouse("/newsecond/sale_info/frm_info_save.aspx?houseid="+houseid,
	    function(r){
	        $('iframe_window').src='/newsecond/sale_info/input_success.aspx?housetype='+housetype+'&type='+r+'&r='+Math.random();
	    },getPostXmlSeek(obj));
}

//检查页面元素的自定义属性
function checkAttr(obj)
{
    for(i=0;i<obj.length;i++)
    {
        try
        {
            if(obj[i].getAttribute("need")!=null&&trim(obj[i].value)=="")
            {
                alert(obj[i].getAttribute("need"));
                obj[i].focus();
                return false;
            }
            if(obj[i].getAttribute("strtype")!=null&&!checkType(obj[i].value))
            {
                alert(obj[i].getAttribute("strtype"));
                obj[i].focus();
                return false;
            }
            if(obj[i].getAttribute("num")!=null&&trim(obj[i].value)!=""&&!checkisnumber(obj[i].id))
            {
                alert(obj[i].getAttribute("num"));
                obj[i].focus();
                return false;
            }
            if(obj[i].getAttribute("float")!=null&&!checkisfloat(obj[i].id))
            {
                alert(obj[i].getAttribute("float"));
                obj[i].focus();
                return false;
            }
            if(obj[i].getAttribute("email")!=null&&obj[i].value!=""&&!checkEmail(obj[i].value))
            {
                alert(obj[i].getAttribute("email"));
                obj[i].focus();
                return false;
            }
        }
        catch(e)
        {return false;}
    }
    return true;
}

//查询电话
function checkTel()
{
    var obj = document.getElementById('tel');
    if(obj.value=='查询是否中介' || obj.value=='')
    {
        alert("请输入要查询的电话或手机");
        return false;
    }
    else
    {
        if(!checkisnumber('tel'))
        {
           alert("电话或手机必须为数字");
           return false;
        }
        var a="mobile";
        if (!Mobile(obj.value))
        {
		   a = "telephone"; 
	    }
	    alert(a);
        //$('iframe_window').src='/newsecond/sale_info/getHackerRecord.aspx?mobile=13810810587&r='+Math.random();
        $('iframe_window').src='/newsecond/sale_info/getHackerRecord.aspx?'+a+'='+obj.value+'&r='+Math.random();
    }
}

//举报电话
function jbSubmit()
{
    if($('jbChk').checked)
    {
        if(document.getElementById('mobile').value=='查询中介手机'&&document.getElementById('telephone').value=='查询中介电话')
        {
            document.getElementById('showinfo1').innerHTML="<font style=\"color:red\">请输入要举报的电话或手机</font>";
            return false;
        }
        else
        {
            var a="";
            if(document.getElementById('telephone').value!='查询中介电话')
            {
                if(!checkisnumber('telephone')||(document.getElementById('telephone').value.length!=7&&document.getElementById('telephone').value.length!=8))
                {
                    a="电话";
                }
            }
            if(document.getElementById('mobile').value!='查询中介手机')
            {
                if(!checkisnumber('mobile')||document.getElementById('mobile').value.length!=11)
                {
                    if(a=="") a="手机";
                    else a+=",手机";
                }
            }
            
            if(a!="")
            {
                document.getElementById('showinfo1').innerHTML="<font style=\"color:red\">请输入正确的"+a+"</font>";
                return false;
            }
            else
                document.getElementById('showinfo1').innerHTML="";
        }
        $('iframe_window').src='/newsecond/sale_info/getHackerRecord.aspx?jbdh='+$('telephone').value+'&jbsj='+$('mobile').value+'&r='+Math.random();
//        outDiv();
    }
    else
    {
        document.getElementById('showinfo1').innerHTML="<font style=\"color:red\">请先选中选择框</font>";
    }
}

//查看联系方式
function seeContact(houseid,businesstype,agentcode,furl)
{
    $('iframe_window').src='/newsecond/sale_info/showalert.aspx?houseid='+houseid+"&businesstype="+businesstype+"&agentcode="+agentcode+"&furl="+furl+"&r="+Math.random();
//    outDiv();
}

//手机付费
function mobilePay(sendtxt)
{
    $('iframe_window').src='/newsecond/sale_info/showalert.aspx?sendtxt='+sendtxt+"&r="+Math.random();
//    outDiv();
}

function outDiv()
{
    $('iframe_window').width=window.screen.width+"px";
    $('iframe_window').height=window.screen.height+"px";
    $('overlay').style.height=window.screen.height+"px";
    $('overlay').style.display="block";
    showOrHideSelect("hidden");
    document.documentElement.style.height=window.screen.height+"px";
    document.documentElement.scrollTop = 0;
    document.documentElement.style.overflow="hidden";
    document.documentElement.style.overflowY="hidden";
    $('div_windowfull').style.display='block';
    $('div_windowfull').style.height=window.screen.height+"px";
}
  
    function stateChangeIE(_frame)
    {
    if(_frame.src=="")return;
     outDiv();
     if($('btnwy')!=undefined) $('btnwy').value='物业相关图片';
//     var loader = document.getElementById("overlay");
//        loader.innerHTML      = "";    
//        loader.style.display = "none";  
//        _frame.style.display = "block";   
 
     }   
     
    function stateChangeFirefox(_frame)
    {
    if(_frame.src=="")return;
     outDiv();
if($('btnwy')!=undefined) $('btnwy').value='物业相关图片';
//     var loader = document.getElementById("overlay");
//        loader.innerHTML      = "";    
//        loader.style.display = "none";  
//        _frame.style.display = "block";   
    }
    
    function sdb_input(houseid,qq,msn,idcard,hcard,fun)
{
//先判断用户录入的信息是否规范
if(trim($('txt_hcard').value)=='') {alert('请输入房产证号！');return;}
if(trim($('txt_msn').value)!=''&&!checkEmail($('txt_msn').value)){alert("请输入正确的msn！");return;}
if(trim($('txt_idcard').value)==''||($('txt_idcard').value.length!=15&&$('txt_idcard').value.length!=18)) {alert('请输入15位或18位的身份证号！');return;}

    if($('btnok').value!="确定") return;
    xmlhttp = new DefineRequest();
	xmlhttp.open("Get","/newsecond/sale_info/sdbinput.aspx?houseid="+houseid+"&qq="+qq+"&msn="+msn+"&idcard="+idcard+"&hcard="+hcard,true);
	xmlhttp.onreadystatechange=function()
	{
		if(xmlhttp.readyState==4)
		{
			if (xmlhttp.status == 200) 
			{
				if(xmlhttp.responseText=="1")
				{ alert("录入成功！");
				    $('btnok').value="确定";
				}
				else
				{
				alert(xmlhttp.responseText);
				}
			}
			else
			{
			    alert("服务器异常或通信延迟，请稍后重新提交");
			}
			$('btnok').value="确定";
		}
		else
		{
		    //提示页面正在提交中
            $('btnok').value="Loading...";
		}
	};
	xmlhttp.send();
}

//var loginWindowCode = '<table width=\"100%\" border=\"0\" cellspacing=\"10\"><tr><td width=\"75%\">用户名：<input id=\"username\" name=\"username\" type=\"text\" size=\"16\" /></td><td rowspan=\"2\"><img src=\"http://img.soufun.com/secondhouse/image/button_login.gif\" alt=\"\" onclick=\"submitLogin()\" style="cursor:pointer;"></td></tr><tr><td>密　码：<input id=\"userpwd\" name=\"userpwd\" type="password" style=\"font-family:宋体;\"  size=\"16\" /></td></tr><tr><td colspan=\"2\" class=\"orange\"><span class=\"grayt\">尚未注册为搜房用户？</span> <a href=\"/loginnew1.aspx\" target=\"_blank\" >免费注册>></a></td></tr></table>';
function showError(value)
{
    var obj = $('errormsg');
    obj.innerHTML = value;
    obj.style.display = '';
}

function setLoginBar(values)
{
    var obj = document.getElementById('loginBar');
    if(obj)
    {
        var str = '';
        switch(values.result)
        {
            case '100':
                str = '欢迎您，<a href="' + values.url1 + '" target="_blank" class="bold red">' + values.username +'</a> <a href="javascript:;" onclick="submitLogout()">退出</a>';
                break;
            default:
                str = '<a href=\"http://esf.' + jsShortDomain + '/loginnew1.aspx\" title=\"登录\" target=\"_blank\">登录</a>  <a href=\"http://esf.' + jsShortDomain + '/loginnew1.aspx\" title=\"免费注册\" target=\"_blank\">免费注册</a>';
                break;
        }
        obj.innerHTML = str;
    }
}

function setLoginWindow(values,obj)
{
    var str = '';
    if(obj)
    {
    switch(values.result)
    {
        case '100':
            str = '<table width=\"100%\" border=\"0\" cellspacing=\"10\">';
            str += '<tr><td colspan=\"2\" style=\"padding-top:20px;text-align:center;\"><strong class=\"name\">' + values.username + ' 您好！</strong><span class=\"grayt\"><a href=\"javascript:;\" onclick=\"submitLogout()\">[安全退出]</a></span></td></tr>';
            if(values.isagtuser == 0)
                str += '<tr><td colspan=\"2\" class=\"orange\" style=\"text-align:center;\"><a href=\"' + values.url1 + '\" target=\"_blank\">进入个人用户管理中心</a></td></tr>';
            else if(values.isagtuser == 1)
                str += '<tr><td colspan=\"2\" class=\"orange\" style=\"text-align:center;\"><a href=\"' + values.url1 + '\" target=\"_blank\" >管理我的店铺</a>&nbsp; |&nbsp; <a href=\"' + values.url2 + '\" target=\"_blank\" >查看我的店铺</a></td></tr>';
            str += '</table>';
            break;
        case '000':
        case '001':
        case '002':
        case '003':
            str = '<table width="100%" border="0" cellspacing="7">';
            str += '<tr><td colspan="2" class="red" id="errormsg">' + values.errormsg + '</td></tr>';
        case '004':
            if(values.result == '004')
            {
                str = '<table width="100%" border="0" cellspacing="7">';
                str += '<tr><td colspan="2" class="red" id="errormsg" style="display:none;"></td></tr>';
            }
            str += '<tr><td width="75%">用户名：<input id="username" name="username" type="text" size="16" /></td><td rowspan="2"><img src="http://img.soufun.com/secondhouse/image/button_login.gif" onclick="submitLogin()" style="cursor:pointer;"></td></tr>';
            str += '<tr><td>密　码：<input id=\"userpwd\" name=\"userpwd\" type=\"password\" style=\"font-family:宋体;\" size=\"16\" /></td></tr>';
            str += '<tr><td colspan="2" class="orange"><span class="grayt">尚未注册为搜房用户？</span> <a href="http://esf.' + jsShortDomain + '/loginnew1.aspx" target="_blank" >免费注册>></a></td></tr>';
            str += '</table>';
            break;
        default:
            str = '';
            break;
    }
    obj.innerHTML = str;
    }
}

function initLoginWindow()
{
	xmlhttp = new DefineRequest();
	xmlhttp.open('Get','/newsecond/include/DefaultUserLogin.aspx?method=init');
	var contentObj = $('loginWindow');
	xmlhttp.onreadystatechange = function()
	{
		if(xmlhttp.readyState == 4)
		{
			if(xmlhttp.status == 200)
			{
				var Json = eval("("+xmlhttp.responseText+")");
				setLoginWindow(Json,contentObj);
				setLoginBar(Json);
				setEvent();			
			}
			else
			{
				alert('服务器异常或通讯延迟，请稍后再试');
			}
		}
	}
	xmlhttp.send(null);
}

function submitLogin()
{
    var uname = $('username').value;
    if(uname.length == 0)
    { showError('请输入您的用户名'); return; }
    var upwd = $('userpwd').value;
    if(upwd.length == 0)
    { showError('请输入您的密码'); return; }
    xmlhttp = new DefineRequest();
	xmlhttp.open('Get','/newsecond/include/DefaultUserLogin.aspx?method=login&name=' + uname + '&pwd=' + upwd);
	var contentObj = $('loginWindow');
	contentObj.innerHTML = '<center style=\"width:100%; margin-top:45px;\"><img src=\"http://img.soufun.com/secondhouse/image/8-0.gif\" alt=\"\" width=\"200\"/></center>';
	xmlhttp.onreadystatechange = function()
	{
		if(xmlhttp.readyState == 4)
		{
			if(xmlhttp.status == 200)
			{
				var Json = eval("("+xmlhttp.responseText+")");
				setLoginWindow(Json,contentObj);
				setLoginBar(Json);
				setEvent();
			}
			else
			{
				alert('服务器异常或通讯延迟，请稍后再试');
			}
		}
	}
	xmlhttp.send(null);
}

function submitLogout()
{
    xmlhttp = new DefineRequest();
	xmlhttp.open('Get','/newsecond/include/DefaultUserLogin.aspx?method=logout');
	var contentObj = $('loginWindow');
	if(contentObj) contentObj.innerHTML = '<center style=\"width:100%; margin-top:45px;\"><img src=\"http://img.soufun.com/secondhouse/image/8-0.gif\" alt=\"\" width=\"200\"/></center>';
	xmlhttp.onreadystatechange = function()
	{
		if(xmlhttp.readyState == 4)
		{
			if(xmlhttp.status == 200)
			{
				var Json = {"result":"004"}
			    setLoginWindow(Json,contentObj);
			    setLoginBar(Json);
			    setagtDetailMsgWindow(Json);
			    setEvent();	
			    
			    //经纪人flash
			    try{
			    if(ReloadAgentLogin)
                {
                   ReloadAgentLogin();
                }}catch(e){return;}
			}
			else
			{
				alert('服务器异常或通讯延迟，请稍后再试');
			}
		}
	}
	xmlhttp.send(null);
}

function setEvent()
{
    var input1 = $('username');
    if(input1)
    {
        input1.onkeydown = function(ev)
        {
            ev = ev || window.event;
            if(ev.keyCode == 13)
                submitLogin();
        }
    }
    var input2 = $('userpwd');
    if(input2)
    {
        input2.onkeydown = function(ev)
        {
            ev = ev || window.event;
            if(ev.keyCode == 13)
                submitLogin();
        }
    }
}

function setagtDetailMsgWindow(values)
{
    var obj = $('msgLogin');
    var str = '';
    if(obj)
    {
        if(values.result == '100')
            str = '登录名：<input type="text" name="name" value="' + values.username + '" /> <a href="javascript:;" onclick="submitLogout()">退出</a>';
        else
        {
            str = '登录名：<input type="text" name="name" id="name" value="匿名用户" /> <span id="mm" style="display:none;">密码：<input type="password" name="pwd" id="pwd" /> <input type="button" id="btlogin" onclick="agtDetailMsgLogin()" value="登录"/></span> <a href="/loginnew1.aspx" target="_blank">注册</a> <input name="checkbox" id="checkbox" type="checkbox" checked="checked"  value="1" style="width:20px;" onclick="nmChecked()" />(匿名发表)无需注册';
            if(values.result != '004') alert(values.errormsg);   
        }
        obj.innerHTML = str;
        if(values.result == '100' && document.forms['forms1'] && document.forms['forms1'].name)
            document.forms['forms1'].name.disabled = 'disabled'; 
    }  
}

function nmChecked()
{
    if(document.forms['forms1'].checkbox.checked)
    { $('btlogin').disabled = 'disabled';document.forms['forms1'].name.value = '匿名用户';$('mm').style.display = 'none';}
    else
    { $('btlogin').disabled = '';document.forms['forms1'].name.value = '';$('mm').style.display = '';}
}

function agtDetailMsgInit()
{
    if($('msgLogin')){
    xmlhttp = new DefineRequest();
	xmlhttp.open('Get','/newsecond/include/DefaultUserLogin.aspx?method=init');
	xmlhttp.onreadystatechange = function()
	{
		if(xmlhttp.readyState == 4)
		{
			if(xmlhttp.status == 200)
			{
				var Json = eval("("+xmlhttp.responseText+")");
				setagtDetailMsgWindow(Json);
				setLoginBar(Json);	
			}
			else
			{
				alert('服务器异常或通讯延迟，请稍后再试');
			}
		}
	}
	xmlhttp.send(null);}
}

function agtDetailMsgLogin()
{
    var uname = $('name').value;
    if(uname.length == 0)
    {alert('用户名为空');return;}
    var upwd = $('pwd').value;
    if(upwd.length == 0)
    {alert('密码为空');return;}
    xmlhttp.open('Get','/newsecond/include/DefaultUserLogin.aspx?method=login&name=' + uname + '&pwd=' + upwd);
    xmlhttp.onreadystatechange = function()
	{
		if(xmlhttp.readyState == 4)
		{
			if(xmlhttp.status == 200)
			{
				var Json = eval("("+xmlhttp.responseText+")");
				setagtDetailMsgWindow(Json);
				setLoginBar(Json);
			}
			else
			{
				alert('服务器异常或通讯延迟，请稍后再试');
			}
		}
	}
	xmlhttp.send(null);
}


