﻿  //遍历所有选中的项
var str=null;
$("#erjidiming").ready(function(){
    $("strong").each(function(){
        if($(this).text()!="不限")
        {
        if(str==null)
    	    str=$(this).text();
        else
    	    str+="+"+$(this).text();
        }    
    });

if(str!=null)
{
   $("#curCondition").html("<li><a href='rent.aspx?condition="+GetUrlParam('condition')+"'>"+str+"</a></li>");
}
});
//document.getElementById("condition").value=a;

function GetUrlParam(paramName )
{
   var url = document.URL; //URL参数
   var oRegex = new RegExp( '[\?&]' + paramName + '=([^&]+)', 'i' ) ;
    //var oMatch = oRegex.exec( window.top.location.search ) ; //获取当前窗口的URL
    var oMatch = oRegex.exec( url ) ;
    if ( oMatch && oMatch.length > 1 )
        return oMatch[1] ;  //返回值
    else
        return '' ;
}
//删除一条选房条件
function delIt(o)
{
    o.parentNode.parentNode.removeChild(o.parentNode);
    $.ajax({
        type: "POST",   //访问WebService使用Post方式请求
        contentType: "application/json", //WebService 会返回Json类型
        url: "rent.aspx/del_xftj", //调用WebService的地址和方法名称组合 ---- WsURL/方法名
        data: "{id:"+o.name+"}",         //这里是要传递的参数，格式为 data: "{paraName:paraValue}",下面将会看到      
        dataType: 'json',
        success:function(result){
            if(result.d==1)
            {
                alert("删除成功！");
            }
            else{
                alert("网络延迟...");
            }
            
        }
    });
}

//保存条件
 function saveCondition()
    {
      if($('li',$('#saved')).length>=4)
      {
        alert("您只能保存四条信息！");
        return false;
      }
      if(document.getElementById("curCondition").firstChild!=null)
      {
      var content=document.getElementById("curCondition").firstChild.firstChild.href;
      var flag=false;
        $('a',$('#saved')).each(function(i,ele){
        if(content==ele.href)
        {
           alert("该条件已经保存！");
           flag=true;
        }
        });
      }
      if(!flag)
      {
          
       // <li><a href='rent.aspx?condition=111200_233_2'>海淀区+中关村+100万-200万</a><span><a href="javascript:delIt(this)">ｘ</a></span></li>
           var li=document.createElement("li");
           var html="<a href='rent.aspx?condition="+GetUrlParam('condition')+"'>"+str+"</a>&nbsp;&nbsp;&nbsp;<a onclick='delIt(this)' title='删除该条件' href='javascript:;'>×</a>";
           li.innerHTML=html;
           if(str!=null)
           {
               document.getElementById("saved").appendChild(li);
                   $.ajax({
                type: "post",   //访问WebService使用Post方式请求
                contentType: "application/json", //WebService 会返回Json类型
                url: "rent.aspx/add_xftj", //调用WebService的地址和方法名称组合 ---- WsURL/方法名
                data: "{condition:'"+str+"',conditionLink:'"+GetUrlParam('condition')+"'}",         //这里是要传递的参数，格式为 data: "{paraName:paraValue}",下面将会看到      
                dataType: 'json',
                error:function(msg){aa(msg)},
                success:function(result){
                    if(result.d==1)
                    {
                        alert("添加成功!");
                    }
                    else if(result.d==-2)
                    {
                        alert("您是经纪人，没有添加选房条件的权限！");
                    }
                    else
                    {
                        alert("请先登录....")
                    }
                
                }
            });
           }
       }
    }
             
$(document).ready(function(){
    $.ajax({
        type:"post",
        contentType:"application/json",
        url:"sale.aspx/getAdvertisment",
        data:"{'condition':'租房'}",
        dataType: 'json',
        success:function(result)
        {
            if(result.d!=null)
            {
                  $("#advertisement").html("");
                $(result.d).each(function(i,e){
                    var src=e.Adv_url;
                    var link=e.adv_title;
                    var width=e.adv_wide;
                    var height=e.adv_height;
                    $("#advertisement").append("<li><a href='"+link+"' target='_blank'><img width='"+width+"px' height='"+height+"px' src='FileUpload/AdvImg/"+src+"' /></a></li>");
                });
            }
        },
        error:function(msg){alert(msg);}
    });
}); 
