﻿/*
所在模块：定向广告通用处理
文件功能：定向广告通用处理
作    者：Eagle
时    间：2010-06-17 10:24
*/
//图片广告图片路径
var ImgPath="http://img1.ucar.cn/ucar/uploadpic/SecondHandCar/AD/";
var AjaxDomain = "";

/*根据条件异步得到要加载的广告，填充广告容器
top：         取广告数量
senseType：   广告类型1：图片，2文字 3车源广告
ContainerId:  填充广告容器
MainBrandId:    主品牌ID
SerialId：      车系ID
ProvinceId:     省份ID
CityId：        城市ID
lowPrice：      最低价
highPrice：     最高价
lowYear：       最低车龄
highYear：      最高车龄
AdType：        广告类型：1为经销商广告2为厂商广告
ContainerId：   容器ID
showlocation:   广告显示位置1：车源列表页，2车源详细页
BigContainerId: 上级容器Id：为了控制可见性
*/
function GetADListByAdTypeAndFiter(top,
    senseType,
    MainBrandId,
    SerialId,
    ProvinceId,
    CityId, 
    lowPrice,
    highPrice,
    lowYear,
    highYear,
    AdType,
    ContainerId,
    showlocation,
    BigContainerId)
{
    var url=AjaxDomain+"/ajax/directionalad/ajaxadlist.ashx";
  var pars = "CityId="+CityId
            +"&SerialId="+SerialId
            +"&WSId="+GetWebSiteId()
            +"&Top="+top
            +"&SenseType="+senseType
            +"&ProvinceId="+ProvinceId
            +"&MainBrandId="+MainBrandId
            +"&LowPriceId="+lowPrice
            +"&HighPriceId="+highPrice
            +"&lowYear="+lowYear
            +"&highYear="+highYear
            +"&showlocation=" + showlocation
            +"&adtype="+AdType
            +"&r="+Math.random();
  
  if(senseType==1)
  {
      var myAjax = new Ajax.Request(
                        url,
                        {method: 'get', 
                        parameters: pars, 
                        onSuccess: function callback(request){InitImgAd(request,ContainerId,BigContainerId);},
                        onError: function(){},
	                    evalScripts:true,
	                    asynchronous:true
                        }                        
                        );
   }
   else if(senseType == 2)
   {
      if(AdType==2)  
      {
          var myAjax = new Ajax.Request(
                        url,
                        {method: 'get', 
                        parameters: pars, 
                        onSuccess: function callback(request){InitCarInfoSuperiorTxtBlockAd(request,ContainerId,BigContainerId);},
                        onError: function(){},
	                    evalScripts:true,
	                    asynchronous:true
                        }
                        );
         
      }
      else if(AdType==1)
      {
            var myAjax = new Ajax.Request(
                        url,
                        {method: 'get', 
                        parameters: pars, 
                        onSuccess: function callback(request){OnitDealerTxtAd(request,ContainerId,BigContainerId);},
                        onError: function(){},
	                    evalScripts:true,
	                    asynchronous:true
                        }
                        );
      }
   }
   else if(senseType == 3)
   {
   
         var myAjax = new Ajax.Request(
                        url,
                        {method: 'get', 
                        parameters: pars, 
                        onSuccess: function callback(request){InitCarInfoAd(request,ContainerId,BigContainerId);},
                        onError: function(){},
	                    evalScripts:true,
	                    asynchronous:true
                        }
                        );
      
   }  
}

//根据URL得到网站Id
function GetWebSiteId()
{
      var WSId;
      var paterUrl=document.location.href;  
      paterUrl=paterUrl.substr(paterUrl.indexOf("//")+2);
      paterUrl=paterUrl.substr(0,paterUrl.indexOf("/"));
      paterUrl=paterUrl.toLowerCase();
      if(paterUrl.indexOf("163")>=0)
      {
         WSId=6;//网易
      }
      else if(paterUrl.indexOf("sohu")>=0)
      {
         WSId=2;//搜狐
      }
      else if(paterUrl.indexOf("sina")>=0)
       {
         WSId=1;//新浪
      }
      else if(paterUrl.indexOf("yahoo")>=0)
      {
         WSId=5;//雅虎
      }
      else if(paterUrl.indexOf("qq")>=0)
      {
         WSId=3;//腾讯
      }
      else if(paterUrl.indexOf("bitauto")>=0)
      {
         WSId=4;//易车
      }
      else if(paterUrl.indexOf("tom")>=0)
      {
         WSId=8;//tom
      }
       else if(paterUrl.indexOf("ganji")>=0)
      {
         WSId=9;//赶集
      }
      else
      {
         WSId=7;//Ucar
      }
      return WSId

}


function AdClick(AdId)
{

   var paterUrl=escape(document.location.href);
   var url=AjaxDomain+"/ajax/directionalad/AjaxADClick.ashx";
   var pars = "url="+paterUrl+"&AdId="+AdId;
   var myAjax = new Ajax.Request(
                        url,
                        {method: 'get', parameters: pars, onComplete: function empty(){}}
                        );
                        
                        
 }
