﻿ // JScript 文件
 // 创建日期 2007年1月7日
 // 文件描述 车源详细页
  // 创建人 王加锋
  // 需要同时依赖 prototype1.5.1.js
  //写入读取Cookie
    function SetCookie(cookieName, cookieData) {
    var expires = new Date ();
    expires.setTime(expires.getTime() + 31 * (24 * 60 * 60 * 1000));
    if(GetCookie(cookieName) != null)
        document.cookie = cookieName + "=" + cookieData + ','+  escape(GetCookie(cookieName) ) + "; expires=" + expires.toGMTString();
    else
       document.cookie = cookieName + "=" + escape(cookieData) + "; expires=" + expires.toGMTString();
    }
    //删除Cookie
    function DelCookie(name)
    {
    var exp = new Date();
    exp.setTime (exp.getTime() - 1);
    var cval = GetCookie (name);
    document.cookie = name + "=" + cval + "; expires="+ exp.toGMTString();
    }
    //读取Cookie
    function GetCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
    }
  //同品牌车型
  function ShowSameTypeCar(ucarId)
  {
      var url="AjaxPage/SameBrandCar.aspx?ucarId="+ucarId;
      new Ajax.Request(url, {method:"get",onComplete:updatetotalBrand,evalScripts:true,asynchronous:true} ); 
  }
  //同价位车型
  function ShowSamePriceCar(ucarId)
  {
      var url="AjaxPage/SamePriceCar.aspx?ucarId="+ucarId;
      new Ajax.Request(url, {method:"get",onComplete:updatePrice,evalScripts:true,asynchronous:true} );
  }
   //经销商其他车源
  function ShowVonderAccountCarList(tva_id)
  {
      var url="AjaxPage/VonderAccountCarList.aspx?tva_id="+tva_id;
      new Ajax.Request(url, {method:"get",onComplete:updateOtherCarList,evalScripts:true,asynchronous:true} ); 
  }
  //Bitauto接口
  function BitautoInterface(ucarId)
  {
      var url="AjaxPage/InterFaceCarinfo.aspx?ucarid="+ucarId + "&type=bitauto";
      new Ajax.Request(url, {method:"get",onComplete:updateBitautoInterface,evalScripts:true,asynchronous:true} ); 
  }
   //BAA接口
  function BaaInterface(ucarId)
  {
      var url="AjaxPage/InterFaceCarinfo.aspx?ucarid="+ucarId + "&type=baa";
      new Ajax.Request(url, {method:"get",onComplete:updatebaaInterface,evalScripts:true,asynchronous:true} ); 
  }
  function updatePrice(request)
  {
    $("dvsamePrice").update(request.responseText);
  }
  function updatetotalBrand(request)
  {
    $("dvCarSameList").update(request.responseText);
  }
  function updateOtherCarList(request)
  {
    $("dvOtherCarList").update(request.responseText);
  }
   function updateBitautoInterface(request)
  {
    $("spBitauto").update(request.responseText);
  }
  function updatebaaInterface(request)
  {
    var index=request.responseText.indexOf("/");
    $("spcount").update('(' + request.responseText.substring(0,index) + '条)');
     $("spdetails").update(request.responseText.substring(index+1,request.responseText.length));
  }
  function AnsyCallMethod(ucarId)
  {
    ShowSameTypeCar(ucarId);
    ShowSamePriceCar(ucarId);
    BitautoInterface(ucarId);
    BaaInterface(ucarId);
  }

function CheckVoteMessage()
{
     var ContentText= $F('txtVote'); 
     
     if(ContentText.strip()=="输入虚假信息" || ContentText.strip()=="")
     {
        alert("- 请输入举报内容！");
     　 return false;
     } 
     else if(!CheckLength(ContentText,200))
     {
        alert(" -举报内容最多为100个汉字！");
     　  return false;
     } 
     return true;
}

function saet(o)
{
	var x=y=0;
	do{
      x+=o.offsetLeft;
	  y+=o.offsetTop;
	}
	while (o=o.offsetParent);
	return {"x":x,"y":y};
}

function opendiv(thisObj,openAId,numx,numy)
{	

    var x=saet(thisObj).x;
	var y=saet(thisObj).y;
	
	var newx = x + numx;
	var newy = y + numy; 
	
     $(openAId).style.display="block";
      $(openAId).style.top=newy+"px";
	$(openAId).style.left=newx+"px";
}

function ReplyDisplay(thisObj,openAId,keyid,values)
{ 
    opendiv(thisObj,openAId,-640,-340);
    $(keyid).value=values;
}
//ThisObj是DIV的ID ，Width是DIV的宽，Percent是图片最大宽；

function ImgWidth(ThisObj,Width,Percent)
{
	var ImgObj=$(ThisObj).getElementsByTagName("img");
	for(i=0;i<ImgObj.length;i++)
	{
		if(ImgObj[i].clientWidth>Width)
		{
			ImgObj[i].style.width=Percent+"px";
		}
	}
}
//参数解析
function DecodeUrlParameter(__key)
{
    var parapart = document.location.search;
    parapart = parapart.replace(/^\?+/, '').replace(/#+$/, '');
    if (parapart.length <= 0){
        return '';
    }
    var arrparas = parapart.split('&');
    var ___iterator_;
    for (___iterator_ = 0; ___iterator_ < arrparas.length; ++___iterator_)
    {
        var urlparacomp = arrparas[___iterator_].split('=');
        if (urlparacomp[0] == __key){
            if (urlparacomp[1]){
                return urlparacomp[1];
            }else{
                return '';
            }
        }
        else{
            continue;
        }
    }
    return '';
}
function HistoryView()
{
    var strDiv ="";
    var cookievalue = eval('['+GetCookie('LastView')+']');

    if(cookievalue == null)
    {
        return;
    }
    for(var i=0;i<cookievalue.length;i++)
    {
        if(cookievalue[i])
        {
            strDiv+="<li><a href='" +cookievalue[i].href+ "' targer=\"_self\" class=\"mc_cola\"><img src='"+cookievalue[i].img + "\' width=\'80px\' height=\'60px\'/></a>";
            strDiv+="<p style=\"height:20px;overflow:hidden;\"><a href='" +cookievalue[i].href  + "' targer=\"_self\" class=\"mc_cola\">" + cookievalue[i].year + "年 "  + unescape(cookievalue[i].brandName) + "</a></p>";
            strDiv+="<p class=\"cola\" style=\"height:20px;overflow:hidden;\"><span style='color:#000'>" + unescape(cookievalue[i].cararea) + ' </span>' + unescape(cookievalue[i].price) + "</p>";
            strDiv+="</li>";
        }
    }
    $('divHistory').update(strDiv);
}

function WriteHistory()
{
   var year=null;
   var brandName=null;
   var img=null;
   var price=null;
   var carinfo= $('spcarBasic').innerHTML;
   var carprice= $('spPrice').innerHTML;
   var _year =  $('lblbuycardata').innerHTML;
   var price = carprice.substring(carprice.indexOf('：')+1,carprice.length -  carprice.indexOf(':')-2);
   var img = $('ucNewCarPicInfor_img0').src.replace('_middle','_smaller');
   var cararea = '';
   var infoList = carinfo.split(' ');
   if(infoList[1] != null)
   {
        cararea = infoList[1].substring(0, infoList[1].indexOf(']'));
   }
   brandName = infoList[2];
   year= _year.substring(2,4);
   
   var cookieList = GetCookie('LastView');
   var cookievalue = '{year:\''+year+'\',href:\''+window.location.href+'\',img:\''+img+'\',cararea:\''+escape(cararea)+'\',brandName:\''+escape(brandName)+'\',price:\''+escape(price)+'\'}';
   
   if(cookieList == null)
   {
        SetCookie('LastView',cookievalue);
   }
   else
   {
        var temp=null;
        temp=cookievalue;
        var oldcookievalue = eval('['+GetCookie('LastView')+']');
        var count=1;
        for(var i=0;i<oldcookievalue.length;i++)
        {
            if(oldcookievalue[i])
            {
                if((eval('['+cookievalue+']')[0].href != oldcookievalue[i].href) && count < 4)
                {
                    temp+=","+'{year:\''+oldcookievalue[i].year+'\',href:\''+oldcookievalue[i].href+'\',img:\''+oldcookievalue[i].img+'\',cararea:\''+oldcookievalue[i].cararea+'\',brandName:\''+oldcookievalue[i].brandName+'\',price:\''+oldcookievalue[i].price+'\'}';
                    count++;
                }
            }
        }
        DelCookie('LastView');
        SetCookie('LastView',temp);
   }
}

var _Ucar_SaleCarinfo = 
{
   attachEvent:function(o,name,fun){
		return document.all ? o.attachEvent(name,fun) : o.addEventListener(name.substr(2),fun,false);
	},
	
    AppendHTML: function() 
    {
        this.attachEvent(window,"onload",function(){AnsyCallMethod($('hfUcarid').value)});
        this.attachEvent(window,"onload",function(){HistoryView()});
        this.attachEvent(window,"onload",function(){WriteHistory()});
    }
}
_Ucar_SaleCarinfo.AppendHTML();
var _carInfoiTimeoutID=null;
function copy_code() 
{
   var carinfo= $('spcarBasic').innerHTML;
   var _year =  $('lblbuycardata').innerHTML;
   var infoList = carinfo.split(' ');
   var brandName = infoList[2];
   var year= _year.substring(0,4);;
    copyText=year +"年" + " 二手"+ brandName + ' ' + window.location.href;
    if (window.clipboardData) 
    {
        window.clipboardData.setData("Text", copyText)
    } 
    else 
    {
        var flashcopier = 'flashcopier';
        if(!document.getElementById(flashcopier)) 
        {
          var divholder = document.createElement('div');
          divholder.id = flashcopier;
          document.body.appendChild(divholder);
        }
        document.getElementById(flashcopier).innerHTML = '';
        var divinfo = '<embed src="../js/clipboard.swf" FlashVars="clipboard='+encodeURIComponent(copyText)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
        document.getElementById(flashcopier).innerHTML = divinfo;
    }

   document.getElementById("tjhy").style.display="block";
   _carInfoiTimeoutID = window.setTimeout("know('tjhy')", 3000);
}
function know(id)
{
     document.getElementById(id).style.display="none";
     window.clearTimeout(_carInfoiTimeoutID)  
}
function carcollect()
{
   var carinfo= $('spcarBasic').innerHTML;
   var _year =  $('lblbuycardata').innerHTML;
   var infoList = carinfo.split(' ');
   var year= _year.substring(0,4);;
   var copyText=year +"年 " + infoList[2] +' ' + infoList[3];
      var carid=$F("hfUcarid");
    CheckUserUserLogIn(function (){collect(1,escape(copyText),carid,ShouCang)});
}
function ShouCang(request)
{
    var result = request.responseText;
    $('scxx').style.display='block';
    if(result == 'false')
    {
     $('pshowInfo').update('您已收藏过此信息');
    }
    else
    {
     $('pshowInfo').update('该信息成功收藏至个人中心');
    }
    _carInfoiTimeoutID = window.setTimeout("know('scxx')", 3000);
}