﻿var FilterSearch={action:1,RegName:"",Score:0,StartCity:0,EndCity:0,VehicleTypeID:0,IsCustoms:0,Weight:0,Volume:0,VehicleBrandID:0};
(function(){
    var e6ExponentData=[
        ["总&nbsp;&nbsp;成交&nbsp;&nbsp;量",e6ExpData[0]],
        ["总&nbsp;&nbsp;车辆&nbsp;&nbsp;数",e6ExpData[1]],
        ["总&nbsp;&nbsp;用户&nbsp;&nbsp;数",e6ExpData[2]]
    ];
    var tmp="";
    for(var i=0;i<e6ExponentData.length;i++){
        tmp+="<div><h2>"+e6ExponentData[i][0]+"</h2><p>"+e6ExponentData[i][1]+"</p></div>";
    }
    tmp+="<div><h2>"+e6ExponentData[0][0]+"</h2><p>"+e6ExponentData[0][1]+"</p></div><p style='clear:both;height:10px'>&nbsp;</p>";
    var obj=$("#tipMain").append(tmp).scrollTop(0);
    obj.Instanse=this;
    var as=$("#tips>div:first a");
    var H=$("div:eq(1)",obj).position().top-$("div:eq(0)",obj).position().top;
    var step=2;
    var direct=0;
    var target=0;
    var lastIndex=0;
    var timer;
    var pasue=4000;
    
    function Move(){
        var px=obj.scrollTop();
        if((direct>0&&px+step>=target)||(direct<0&&px-step<=target)){
            obj.scrollTop(target);
            window.clearInterval(timer);
            timer=window.setInterval(NextExponent,pasue);
        }else{
            obj.scrollTop(px+step*direct);
        }
    }
    function NextExponent(){
        var index=lastIndex+1;
        if(e6ExponentData.length==index)index=0;
        obj.Instanse.ShowExponent(index);
    }
    this.ShowExponent=function(index){
        if(lastIndex==index){
            window.clearInterval(timer);
            timer=window.setInterval(NextExponent,pasue);
            return;
        }
        window.clearInterval(timer);
        as.eq(lastIndex).css("backgroundPosition",(-lastIndex*16)+"px -16px");
        as.eq(index).css("backgroundPosition",(-index*16)+"px 0");
        lastIndex=index;
        var px=obj.scrollTop();
        if(px==0&&index==2){
            obj.scrollTop(3*H);
            target=2*H;
            direct=-1;
        }else if(px==3*H&&index==1){
            obj.scrollTop(0);
            target=H;
            direct=1;
        }else if(index==0){
            if(px<2*H){
                target=0;
                direct=-1;
            }else{
                target=3*H;
                direct=1;
            }
        }else{
            target=index*H;
            direct=target>px?1:-1;
        }
        timer=window.setInterval(Move,10);
    };
    as.eq(0).css("backgroundPosition","0 0");
    $("#tips p>a").each(function(i,n){
        $(n).attr("href","javascript:void(0)").click(function(){
            obj.Instanse.ShowExponent(i);
            return false;
        });
    });
    $(function(){obj.Instanse.ShowExponent(0);});
})();

function ShowDetail(id){
    window.open("/summary/"+id);
}
function DoSearch(){
    var req=$.postJSON("AjaxData.ashx",FilterSearch,function(json){
        var body=$("#PublistVehicleList>tbody");
        var temp="";
        for(var i=0;i<json.length;i++){
            if((i&1)==0)
                temp+="<tr>";
            else
                temp+="<tr class=\"tr1\">";
            temp+="<td abbr=\""+json[i][0]+"\">"+json[i][1]+"</td>";
            temp+="<td abbr=\""+json[i][2]+"\">"+json[i][3]+"</td>";
            temp+="<td>"+json[i][4]+"</td>";
            temp+="<td>"+json[i][5]+"</td>";
            temp+="<td>"+json[i][6]+"</td>";
            temp+="<td>"+json[i][7]+"</td>";
            temp+="<td>"+json[i][8]+"</td>";
            temp+="<td>"+json[i][9]+"</td>";
            temp+="<td>"+json[i][10]+"</td>";
            temp+="<td>"+json[i][11]+"</td>";
            temp+="<td class=\"operate\" abbr=\""+json[i][12]+"\"></td>";
            temp+="</tr>";
        }
        body.html(temp);
        if (json.length<=3) {
            $("#NoSearchCountRow").show();
        }else{
            $("#NoSearchCountRow").hide();
        }
        var dt=new Date(req.getResponseHeader("date"));
        BindFreeData(dt);
    });
}
function BindFreeData(dt){
    var today=new RegExp("^"+(dt.getMonth()+1)+"月"+(dt.getDate())+"日(.*)$","g");
    var yesterday=new RegExp("^"+(dt.getMonth()+1)+"月"+(dt.getDate()-1)+"日(.*)$","g");
    $("#PublistVehicleList>tbody>tr").each(function(i,n){
        var tds=$("td",n);
        var regname=tds.eq(0);
        var id=regname.attr("abbr");
        
        var attention=parseInt(tds.eq(10).attr("abbr"));
        if(!isNaN(attention)&&attention>0)
            regname.html("<a href=\"/detail/"+id+"\" target=\"_blank\">"+regname.html()+"</a> <img src='/images/fire.gif' width='10' height='10' title='"+attention+"人关注' alt='"+attention+"人关注'>");
        else
            regname.html("<a href=\"/detail/"+id+"\" target=\"_blank\">"+regname.html()+"</a>");

        tds.eq(10).html("<a href=\"/detail/"+id+"\" target=\"_blank\" class=\"detail\">详情</a>");
        
        // 诚信度处理
        var score=tds.eq(1);
        var s=parseInt(score.html());
        if(isNaN(s)||s<0||s>100)s=1;
        score.html("<a href=\"/free.aspx?s1="+s+"\" target=\"_blank\">"+s+" "+GetStarHtml(score.attr("abbr"))+"</a>").find("span").css("cursor","pointer");

        // 起始城市处理
        var scity=tds.eq(2);
        scity.html(ConvertCity(scity.html(),{showtitle:true,url:"/free/{0}' target='_blank"}));
        // 终止城市处理
        var ecity=tds.eq(3);
        var cityhtml=ecity.html();
        ecity.html(ConvertCity(cityhtml,{showtitle:true,url:"/free/0/{0}' target='_blank",size:1,sep:'/'}));
        if(cityhtml.split(",").length>1){
            var menu=$("<div class=\"pop-up\" style=\"position:absolute;z-index:200;display:none\"><div class=\"top\"></div><div class=\"center\">"+ConvertCity(cityhtml,{showtitle:true,url:"/free.aspx?s3={0}' target='_blank"})+"</div><div class=\"bottom\"></div></div>");
            ecity.append(menu)
            .mousemove(function(e){
                var offset = ecity.offset();
                menu.css("left",offset.left+ecity.innerWidth()-5)
                .css("top",offset.top)
                .stop(true,true).show();
            }).mouseout(function(){
                menu.fadeOut();
            });
        }
        //车辆类型
        var type=tds.eq(4);
        var typeid=parseInt(type.html());
        var typeindex;
        if(999==typeid)typeindex=0;else typeindex=typeid;
        type.html("<a href=\"/free/0/0/"+typeid+"\" target=\"_blank\" class=\"VTypeImg\" title=\""+VehicleType[typeindex]+"\" style=\"background-position:0 -"+typeindex*25+"px\"></a>");
        //海关
        var customs=tds.eq(5);
        var b=(customs.html()=="True"||customs.html()=="1");
        customs.html("<a href=\"/free.aspx?s5="+(b?"1":"2")+"\" target=\"blank\">"+(b?"是":"否")+"</a>");
        //载重
        var weight=tds.eq(6);
        weight.html("<a href=\"/free.aspx?s6="+Math.floor(weight.html())+"\" target=\"_blank\">"+weight.html()+"吨</a>");
        //体积
        var volume=tds.eq(7);
        volume.html("<a href=\"/free.aspx?s7="+Math.floor(volume.html())+"\" target=\"_blank\">"+volume.html()+"m<sup>3</sup></a>");
        //品牌
        var brand=tds.eq(8);
        var brandid=parseInt(brand.html());
        var brandindex;
        if(999==brandid)brandindex=0;else brandindex=brandid;
        brand.html("<a href=\"/free.aspx?s8="+brandid+"\" target=\"_blank\" class=\"VBrandImg\" title=\""+VehicleBrand[brandindex]+"\" style=\"background-position:0 -"+brandindex*25+"px\"></a>");
        //时间
        var time=tds.eq(9);
        time.html(time.html().replace(/^\d{4}-(\d{1,2})-(\d{1,2}) (\d{1,2}:\d{1,2}):\d{1,2}$/g,"$1月$2日 $3").replace(today,"今$1").replace(yesterday,"昨$1"));
    });
}

(function(){
    //开始初始化
    var links=$("#PublistVehicleList th a").attr("href","javascript:void(0)");
    links.eq(0).bindNameSelect(function(value){
        FilterSearch.RegName = value;
        if(value!="")$(this).attr("title","车辆属地："+value).attr("class",$.config.thclass);
        else $(this).removeAttr("title").removeAttr("class");
        DoSearch();
    });
    links.eq(1).bindScoreSelect(function(score){
        if(score==1)score=0;
        FilterSearch.Score = score;
        if(score>1)$(this).attr("title","诚信度：大于等于"+score/2+"星").attr("class",$.config.thclass);
        else $(this).removeAttr("title").removeAttr("class");
        DoSearch();
    });
    links.eq(2).bindCitySelect(function(cityid){
        FilterSearch.StartCity = cityid;
        if(cityid>0)$(this).attr("title","出发地："+GetFullCity(cityid)).attr("class",$.config.thclass);
        else $(this).removeAttr("title").removeAttr("class");
        DoSearch();
    });
    links.eq(3).bindCitySelect(function(cityid) {
        FilterSearch.EndCity = cityid;
        if(cityid>0)$(this).attr("title","目的地："+GetFullCity(cityid)).attr("class",$.config.thclass);
        else $(this).removeAttr("title").removeAttr("class");
        DoSearch();
    });
    links.eq(4).bindTypeSelect(function(typeid){
        FilterSearch.VehicleTypeID = typeid;
        if(typeid>0)$(this).attr("title","车辆类型："+VehicleType[(typeid==999?0:typeid)]).attr("class",$.config.thclass);
        else $(this).removeAttr("title").removeAttr("class");
        DoSearch();
    });
    links.eq(5).bindCustomSelect(function(customid){
        FilterSearch.IsCustoms = customid;
        if(customid>0)$(this).attr("title","海关监管车："+(customid==1?"是":"否")).attr("class",$.config.thclass);
        else $(this).removeAttr("title").removeAttr("class");
        DoSearch();
    });
    links.eq(6).bindWeightSelect(function(value){
        FilterSearch.Weight = value;
        if(value>0)$(this).attr("title","载重：大于等于"+value+"吨").attr("class",$.config.thclass);
        else $(this).removeAttr("title").removeAttr("class");
        DoSearch();
    });
    links.eq(7).bindVolumeSelect(function(value){
        FilterSearch.Volume = value;
        if(value>0)$(this).attr("title","体积：大于等于"+value+"立方米").attr("class",$.config.thclass);
        else $(this).removeAttr("title").removeAttr("class");
        DoSearch();
    });
    links.eq(8).bindBrandSelect({align:'right'},function(brandid){
        FilterSearch.VehicleBrandID = brandid;
        if(brandid>0)$(this).attr("title","车辆品牌："+VehicleBrand[(brandid==999?0:brandid)]).attr("class",$.config.thclass);
        else $(this).removeAttr("title").removeAttr("class");
        DoSearch();
    });
    var headlink=$("#cyInfo>div a");
    headlink.eq(0).click(function(){
        FilterSearch={action:1,RegName:"",Score:0,StartCity:0,EndCity:0,VehicleTypeID:0,IsCustoms:0,Weight:0,Volume:0,VehicleBrandID:0};
        $("#PublistVehicleList th a").removeAttr("title").removeData("value").removeAttr("class");
        DoSearch();
    });
    headlink.eq(1).click(function(){
        var frm=$("#hideForm");
        var i=-1;
        for(var v in FilterSearch){
            if(i==-1){i++;continue;}
            if(FilterSearch[v])frm.append("<input type=\"hidden\" name=\"s"+i+"\" value=\""+FilterSearch[v]+"\" />");
            i++;
        }
        frm.submit();
        return false;
    });
    $(function(){
        swfobject.embedSWF("/swf/E656ChinaMap.swf", "ChinaMap", "656", "548", "9.0.0", "/swf/expressInstall.swf",null,{allowFullScreen:false,menu:false,wmode:"opaque"},{tabindex:"-1"},function(e){
            if(!e.success){
                $("#loadingmap").remove();
                $("#indexTip").show();
            }
            $("#ChinaMap").mouseup(function(){
                var win=$(window);
                var doc=$(document);
                if(win.height()<=548||(736-win.height()<=doc.scrollTop()&&doc.scrollTop()<=188))return;
                var dest=Math.floor(188-(win.height()-548)/2);
                var lastd=1000;
                setTimeout(function(){
                    if(doc.scrollTop()!=dest){
                        var d=Math.max(Math.ceil(Math.abs(dest-doc.scrollTop())/10),1);
                        if(lastd>=d){
                            lastd=d;
                            d=dest>doc.scrollTop()?d:-d;
                            doc.scrollTop(doc.scrollTop()+d);
                            setTimeout(arguments.callee,20);
                        }
                    }
                },20);
            });
        });
        DoSearch();
    });
})();
