﻿// JScript 文件
var CarList=null;
var UseList=null;
var PriceList=null;

function ShowBrandList(updateElemID)
{
     var url = "../ajaxPage/searchResponse.ashx";
     var pars = (window.location.search=='')?'type=cartype':window.location.search +'&type=cartype';
     $(updateElemID).update('正在生成列表...');
     //loadJS.push(url+pars,"utf-8", function(){InitBrandList(updateElemID)});
     new Ajax.Request(url, {method:"get",parameters:pars, onComplete:function(request){InitBrandList(request,updateElemID)},evalScripts:true,asynchronous:true} ); 
}
function InitBrandList(request,updateElemID)
{
    CarList= eval('['+request.responseText+']');
    var strdiv="";
    if(CarList==null || CarList.length <= 0)
    {
        $(updateElemID).style.display="none";
        return;
    }
    strdiv+="<h2 class=\"mclb_tit1\">按品牌选择</h2>";
    strdiv+="<ul>";
    for(var i=0;i<CarList.length;i++)
    {   strdiv+="<li>";
        strdiv+="<a class=\"mc_cola\" href ='carlist.aspx?pid=" +CarList[i].ProducerId+"&bid=" + CarList[i].BrandId + "&cid="+CarList[i].CarId+"' target=\"_self\">"+CarList[i].name +"</a> (" + CarList[i].carcount+")";
        strdiv+="</li>";
    }   
    strdiv+="</ul>";
    strdiv+="<div class=\"clear\"></div>";
    
    $(updateElemID).update(strdiv);
}

function ShowUseYearList(updateElemID)
{
    var url = "../ajaxPage/searchResponse.ashx";
    var pars = (window.location.search=='')?'type=useyear':window.location.search +'&type=useyear';
    $(updateElemID).update('正在生成列表...');
    new Ajax.Request(url, {method:"get",parameters:pars, onComplete:function(response){InitUseYearList(response,updateElemID)},evalScripts:true,asynchronous:true} ); 
}
function InitUseYearList(request,updateElemID)
{
    UseList= eval('['+request.responseText+']');
    if(UseList==null)
    {
        return;
    }
    var strdiv="";
    for(var i=0;i<UseList.length;i++)
    {
        strdiv+="<li>";
        strdiv+="<a class=\"mc_cola\" href ='carlist.aspx?ca=" +UseList[i].ca+"' target=\"_self\">"+UseList[i].name +"</a> (" + UseList[i].carcount+")";
        strdiv+="</li>";
    }
    $(updateElemID).update(strdiv);
}
function ShowCarpriceList(updateElemID)
{
    var url = "../ajaxPage/searchResponse.ashx";
    var pars = (window.location.search=='')?'type=price':window.location.search +'&type=price';
    $(updateElemID).update('正在生成列表...');
    new Ajax.Request(url, {method:"get",parameters:pars, onComplete:function(response){InitpriceList(response,updateElemID)},evalScripts:true,asynchronous:true});
}
function InitpriceList(request,updateElemID)
{
    PriceList= eval('['+request.responseText+']');
    if(PriceList == null)
    {
        return;
    }
    var strdiv="";
    for(var i=0;i<PriceList.length;i++)
    {
        strdiv+="<li>";
        strdiv+="<a class=\"mc_cola\"  href ='carlist.aspx?lp=" +PriceList[i].lp + "&hp" + PriceList[i].hp +"' target=\"_self\">"+PriceList[i].name +"</a> (" + PriceList[i].carcount+")";
        strdiv+="</li>";
    }
    $(updateElemID).update(strdiv);
}
var _Ucar_ResponseSearch = 
{
   attachEvent:function(o,name,fun){
		return document.all ? o.attachEvent(name,fun) : o.addEventListener(name.substr(2),fun,false);
	},
	
    DynamicLoadJavaScript:  function()
    {
       ShowBrandList('divBrand');
       ShowCarpriceList('divPrice');
       ShowUseYearList('divUseYear');
    },
    
    AppendHTML: function() 
    {
        this.attachEvent(window,"onload",InniteCarList);
        this.attachEvent(window,"onload",this.DynamicLoadJavaScript);
    }
}
//_Ucar_ResponseSearch.AppendHTML();
function SelectChangeCarList(__parameter,id)
{
    window.location.href = DecodeUrlParameters(__parameter,$(id).value);
}
function SearcheCarList(__parameter,_value)
{
    location.href = DecodeUrlParameters(__parameter,_value);
}
function DecodeUrlParameters(_key,_value)
{
     var _Parameter= {pid:'0',bid:'0',pvid:'0',ctid:'0',order:'0',pagecount:'15',ca:'-1',pc:'0'};
     for(var i in _Parameter)
     {
       _Parameter[i]= DecodeUrlParameter(i);
     }
     _Parameter[_key] = _value;
     if(_key== 'pid')
     {
        _Parameter['bid']=0;
        
     }
     
     else if(_key == "pvid")
     {
         _Parameter['ctid']=0;
     }
     var _parapart ='';
     for(var a in _Parameter)
     {
        _parapart += a + "=" + _Parameter[a] + "&";
     }
    var __oriurlparts = document.location.href.split('?');
    var __pathpart = __oriurlparts[0];
    return __pathpart+"?"+_parapart.substring(0 ,_parapart.length -1 );
}
function InniteCarList()
{
    var order = GetIntValue(DecodeUrlParameter('order'));
   
    var pid= GetIntValue(DecodeUrlParameter('pid'));
    var bid= GetIntValue(DecodeUrlParameter('bid'));
    
    var pvid= GetIntValue(DecodeUrlParameter('pvid'));
    var ctid= GetIntValue(DecodeUrlParameter('ctid'));
    
    var pc= GetIntValue(DecodeUrlParameter('pc'));
    var ca= GetIntValue(DecodeUrlParameter('ca'));
    
    var pagecount= GetIntValue(DecodeUrlParameter('pagecount'));
    if(pid > 0)
    {
       $('selbrand').disabled=false;
    }

    if(pvid>0)
    {
        $('selcity').disabled=false;
    } 

    $('ddlCarAge').value = DecodeUrlParameter('ca')?ca:'-1';

    $('ddlPrice').value = DecodeUrlParameter('pc')?pc:'-1';
    $('ddlorder').value = order;
    if(order == 0)
    {
        $('imgtime').src = 'http://img2.ucar.cn/ucar/image/ucar/ucar2009/buycar/timedown.gif';
        //$('imgpub').src='http://img2.ucar.cn/ucar/image/ucar/ucar2009/buycar/mclb_down.gif'; 
    }else if(order == 1)
    {
        $('imgprice').src = 'http://img2.ucar.cn/ucar/image/ucar/ucar2009/buycar/priceup.gif';
        $('imgtime').src=$('imgtime').src.replace(".gif",'b.gif').replace('bb','b'); 
        //$('imgsellprice').src='http://img2.ucar.cn/ucar/image/ucar/ucar2009/buycar/mclb_up.gif'; 
    }
    else if(order == 2)
    {
        $('imgprice').src = 'http://img2.ucar.cn/ucar/image/ucar/ucar2009/buycar/pricedown.gif';
        $('imgtime').src=$('imgtime').src.replace(".gif",'b.gif').replace('bb','b'); 
        //$('imgsellprice').src='http://img2.ucar.cn/ucar/image/ucar/ucar2009/buycar/mclb_down.gif'; 
    }
    else if(order == 3)
    {
        $('imgtime').src = 'http://img2.ucar.cn/ucar/image/ucar/ucar2009/buycar/timeup.gif';
        $('imgprice').src=$('imgprice').src.replace(".gif",'b.gif').replace('bb','b');  
        //$('imgpub').src='http://img2.ucar.cn/ucar/image/ucar/ucar2009/buycar/mclb_up.gif'; 
    }
    else if(order == 4)
    {
        $('imgtime').src = 'http://img2.ucar.cn/ucar/image/ucar/ucar2009/buycar/timedown.gif';
        $('imgprice').src=$('imgprice').src.replace(".gif",'b.gif').replace('bb','b');  
        //$('imgpub').src='http://img2.ucar.cn/ucar/image/ucar/ucar2009/buycar/mclb_down.gif'; 
    }

    if(pagecount == 30)
    {
         $('hf30').className = "mclb_ytcz";
         $('hf15').className = "";
    }
    else
    {
         $('hf15').className = "mclb_ytcz";
         $('hf30').className = "";
    }
    $('selprov')[0].innerHTML='全国';
    $('selcity')[0].innerHTML='城市';
}
function HistorySearchView()
{
    var strDiv ="";
    var cookievalue = eval('['+GetCookie('LastSearchView')+']');

    if(cookievalue == null)
    {
        return;
    }
    for(var i=0;i<cookievalue.length;i++)
    {
       strDiv +="<li>";
       strDiv +="<a href=\"" +cookievalue[i].href + "\" title='" +cookievalue[i].title +"' target=\"_blank\">";
       strDiv += cookievalue[i].title;
       strDiv +="</a>"
       strDiv+="</li>";
    }
    $('divHistory').update(strDiv);
}

function WriteSearchHistory()
{
   var title= $('sptitle').innerHTML;
   var link= window.location.href;
   if(title == null || title == '')
   {
        return;
   }

   var cookieList = GetCookie('LastSearchView');
   var cookievalue = '{href:\''+window.location.href+'\',title:\''+title+'\'}';

   if(cookieList == null)
   {
        SetCookie('LastSearchView',cookievalue);
   }
   else
   {
        var temp=null;
        temp=cookievalue;
        var oldcookievalue = eval('['+GetCookie('LastSearchView')+']');
        var count=0;
        for(var i=0;i<oldcookievalue.length;i++)
        {
            if((eval('['+cookievalue+']')[0].title != oldcookievalue[i].title) && count < 4)
            {
                temp+=","+'{title:\''+oldcookievalue[i].title+'\',href:\''+oldcookievalue[i].href+'\'}';
                count++;
            }
        }
       
        DelCookie('LastSearchView');
        SetCookie('LastSearchView',temp);
   }
}
function GetIsHigh(id)
{
    if($(id).parentNode.className == 'bg2')
    {
        return 'mclb_lb2';
    }
    else
    {
        return 'bg1 mclb_lb3 ';
    }
}
var _Ucar_SaleCarList = 
{
   attachEvent:function(o,name,fun){
		return document.all ? o.attachEvent(name,fun) : o.addEventListener(name.substr(2),fun,false);
	},
	
    AppendHTML: function() 
    {
        WriteSearchHistory();
        HistorySearchView();
        //this.attachEvent(window,"onload",function(){HistorySearchView()});
        //this.attachEvent(window,"onload",function(){WriteSearchHistory()});
    }
}

function priceImgClick(id)
{
    if($(id).src == 'http://img2.ucar.cn/ucar/image/ucar/ucar2009/buycar/pricedownb.gif')
    {
        SearcheCarList('order','2');
    }
    else if($(id).src == 'http://img2.ucar.cn/ucar/image/ucar/ucar2009/buycar/priceupb.gif')
    {
        SearcheCarList('order','1');
    }
    else if($(id).src == 'http://img2.ucar.cn/ucar/image/ucar/ucar2009/buycar/priceup.gif')
    {
        SearcheCarList('order','2');
    }
    else if($(id).src == 'http://img2.ucar.cn/ucar/image/ucar/ucar2009/buycar/pricedown.gif')
    {
        SearcheCarList('order','1');
    }
}
function timeImgClick(id)
{
    if($(id).src == 'http://img2.ucar.cn/ucar/image/ucar/ucar2009/buycar/timedownb.gif')
    {
        SearcheCarList('order','4');
    }
    else if($(id).src == 'http://img2.ucar.cn/ucar/image/ucar/ucar2009/buycar/timeupb.gif')
    {
        SearcheCarList('order','3');
    }
    else if($(id).src == 'http://img2.ucar.cn/ucar/image/ucar/ucar2009/buycar/timeup.gif')
    {
        SearcheCarList('order','4');
    }
    else if($(id).src == 'http://img2.ucar.cn/ucar/image/ucar/ucar2009/buycar/timedown.gif')
    {
        SearcheCarList('order','3');
    }
}