var SaveVersion="8";var ddVehCnt=0;var DnD_PanelView_MAX=12;var DnD_DOver=false;var DnD_InsertPos=0;$.extend($.support,{touch:"ontouchend" in document});$.fn.addTouch=function(){if(!$.support.touch){return}this.each(function(i,el){el.removeEventListener("touchstart",TouchToMouseHandler,false);el.removeEventListener("touchmove",TouchToMouseHandler,false);el.removeEventListener("touchend",TouchToMouseHandler,false);el.removeEventListener("touchcancel",TouchToMouseHandler,false);el.addEventListener("touchstart",TouchToMouseHandler,false);el.addEventListener("touchmove",TouchToMouseHandler,false);el.addEventListener("touchend",TouchToMouseHandler,false);el.addEventListener("touchcancel",TouchToMouseHandler,false)})};function TouchToMouseHandler(event){var type="";var simulatedEvent;switch(event.type){case"touchstart":type="mousedown";break;case"touchmove":type="mousemove";break;case"touchend":case"touchcancel":type="mouseup";break;default:return}simulatedEvent=document.createEvent("MouseEvent");simulatedEvent.initMouseEvent(type,true,true,window,1,event.changedTouches[0].screenX,event.changedTouches[0].screenY,event.changedTouches[0].clientX,event.changedTouches[0].clientY,false,false,false,false,0,null);event.changedTouches[0].target.dispatchEvent(simulatedEvent);if(type=="mousemove"){event.preventDefault()}}function DnD_MakeDraggables(Selector){if(Selector==null){Selector=".dnd_range, .dnd_individual"}var jqObj=$(Selector).draggable({scope:"dnd",helper:"clone",opacity:0.5,zIndex:1000,start:function(e,ui){DnD_DragStart(e,ui,this)},drag:function(e,ui){DnD_Drag(e,ui,this)}}).addTouch();function DnD_DragStart(e,ui,pThis){var ObjW=$(pThis).width();var ObjH=$(pThis).height();$(ui.helper).width(ObjW);$(ui.helper).height(ObjH)}function DnD_Drag(e,ui,pThis){var ObjH=$(pThis).outerHeight(true)/2;DnD_InsertPos=DnD_DropBoxGaps(DnD_DOver,ui.offset.top+ObjH)}}function DnD_YourCarMakeDroppables(Selector){if((Selector==null)){Selector=".dnd_yourcardropbox:visible"}$(Selector).droppable({scope:"dnd",tolerance:"pointer",drop:function(e,ui){DnD_YourCarDrop(e,ui,this)}})}function DnD_YourCarDrop(e,ui,pThis){var Obj=DnD_GetInformation(ui.draggable);if(Obj==null){return}if(Obj.Class=="dnd_cmpcont_r"){alert("You cannot drop a range of vehicles into your car.");return}YourCarDnD(Obj.DB,Obj.VehID)}function DnD_CompareMakeDroppables(){$(".dnd_comparedropbox").droppable({scope:"dnd",tolerance:"pointer",deactivate:function(e,ui){DnD_HoverOut(e,ui,this)},over:function(e,ui){DnD_HoverOver(e,ui,this)},out:function(e,ui){DnD_HoverOut(e,ui,this)},drop:function(e,ui){DnD_CompareDrop(e,ui,this)}})}function DnD_HoverOver(e,ui,pThis){$("#leftCompare").css({border:"1px dashed #444444"});DnD_DOver=true}function DnD_HoverOut(e,ui,pThis){$("#leftCompare").css({border:"1px solid #ffffff"});DnD_DOver=false;DnD_DropBoxNoGaps()}function DnD_CompareDrop(e,ui,pThis){$("#leftCompare").css({border:"1px solid #ffffff"});DnD_HoverOut(e,ui,pThis);var Obj=DnD_GetInformation(ui.draggable);if(Obj==null){return}var Description=Obj.Txt;if((Obj.TxtEx!=null)&&(Obj.TxtEx!="")){Description=Description+"<br/>"+Obj.TxtEx}DnD_CompareAddTo(Obj.Class,Obj.DB,Obj.VehID,Obj.PicID,Description,DnD_InsertPos)}function DnD_CompareAddTo(dClass,DB,VehID,PicID,Description,InsertPos){if(DB.toUpperCase()!="CAR"){alert("You can only add cars to the compare list.");return}if(dClass=="dnd_cmpcont_r"){alert("You cannot add a range of vehicles to the compare list.");return}if(DnD_Exists(DB,VehID)){alert("The vehicle is already in the compare list.");return}DnD_Compare_DropMarkup(dClass,DB,VehID,PicID,Description,"",InsertPos);DnD_Compare_Save()}function DnD_CompareRestore(){if(DnD_GetVehiclesCount().Total){return}Cookie.GetID(function(){ddVehCnt=0;DnD_EmptyList();var c,i;var Obj=DnD_Compare_GetDnDList();if(Obj==null){return}i=Obj.Individual.DB.length-1;for(c=0;c<Obj.Individual.DB.length;c++,i--){DnD_Compare_DropMarkup("dnd_cmpcont_i",Obj.Individual.DB[i],Obj.Individual.VehID[i],Obj.Individual.PicID[i],Obj.Individual.Description[i])}})}function DnD_CompareDelete(pThis){$(pThis).parent().remove();if(!DnD_GetVehiclesCount().Total){DnD_EmptyList()}DnD_Compare_Save();DnD_SetDropPanelHeight()}function DnD_EmptyList(){$(".dnd_comparedropbox").html("<h2>Compare</h2><label>Drag vehicles here to compare<br/>&nbsp;<br/>&nbsp;<br/>&nbsp;<br/>&nbsp;</label>");DnD_HideView()}function DnD_GetVehiclesCount(){var r,i;r=0;i=$(".dnd_comparedropbox:visible>.dnd_cmpcont_i").length;return{"r":r,"i":i,"Total":r+i}}function DnD_Exists(DB,VehID){var i,Obj;var jqObj=$(".dnd_comparedropbox:visible .dndiset");for(i=0;i<jqObj.length;i++){Obj=DnD_GetInformation(jqObj[i]);if(Obj==null){continue}if((Obj.DB==DB)&&(Obj.VehID==VehID)){return true}}return false}function DnD_CompareRun(Group){var n;var Text,Html;var Obj;var Count=DnD_GetVehiclesCount();if(Group<2){n=Count.r}else{n=Count.i}if(!n){alert("You have no vehicles to compare\n"+"Please drop some vehicles onto the compare panel");return}if(Group&1){SetHash("CompareWalkUp?Group="+Group+"&Vehs="+n)}else{SetHash("Compare?Group="+Group+"&Vehs="+n)}}function DnD_Compare_DropMarkup(dClass,DB,VehID,PicID,ModTxt,DerTxt,InsertPos){var ddVehCount=ddVehCnt++;var Html,Href;DerTxt="";var jqObj=$("#leftCompare:visible ."+dClass);if(jqObj.length>=DnD_PanelView_MAX){$(jqObj[DnD_PanelView_MAX-1]).remove()}$('#leftCompare:visible>label:contains("Drag")').css("display","none");DnD_ShowView();if(dClass=="dnd_cmpcont_r"){}else{Href="\"javascript:SetHash('VehicleDetails?DB="+DB+"&ID="+VehID+"')\"";Html='<div class="'+dClass+'" onmouseover="DnD_vehIN('+ddVehCount+')" onmouseout="DnD_vehOUT('+ddVehCount+')">'+'<div class="dndSpacer">&nbsp;</div>'+'<div class="dndiset" style="display:none">'+"{"+'"Selected":"'+0+'",'+'"DB":"'+DB+'",'+'"VehID":"'+VehID+'",'+'"PicID":"'+PicID+'",'+'"Txt":"'+ModTxt+'",'+'"TxtEx":"'+DerTxt+'"'+"}"+"</div>"+'<div id="ddVeh'+ddVehCount+'" class="dnd_delbutton" style="visibility:hidden" onclick="DnD_CompareDelete(this)"></div>'+'<a class="DnDRctSpA0" href='+Href+">"+'<img src="GetImage.aspx?DB='+DB+"&ID="+PicID+'&Width=60&Height=45" alt="Cap Image" title="'+DerTxt+'"style="visibility:hidden"/>'+"</a>"+'<a class="DnDRctSpA1" href='+Href+">"+ModTxt+"<br/> "+DerTxt+"</a>"+"&nbsp;"+"</div>";if((InsertPos==null)||(InsertPos==0)){$("#leftCompare:visible label").after(Html)}else{jqObj=$("#leftCompare:visible ."+dClass);if(InsertPos>=jqObj.length){$(jqObj).eq(jqObj.length-1).after(Html)}else{$(jqObj).eq(InsertPos).before(Html)}}}$("#leftCompare:visible img").load(function(){$(this).css("opacity","0.01");$(this).css("visibility","visible");$(this).animate({opacity:1},1000)});DnD_SetDropPanelHeight();DnD_DropBoxNoGapsNow()}function DnD_vehIN(o){$("#ddVeh"+o).css("visibility","visible")}function DnD_vehOUT(o){$("#ddVeh"+o).css("visibility","hidden")}function DnD_ShowView(){Html="<span>"+'<a href="javascript:DnD_CompareRun(2)">view</a>'+"</span>"+"Compare";$("#leftCompare h2").html(Html)}function DnD_HideView(){Html="<span>"+'<a href="javascript:DnD_CompareRun(2)" style="display:none">view</a>'+"</span>"+"Compare";$("#leftCompare h2").html(Html)}function DnD_GetInformation(jqObj){var Class,InfoDiv,jqTemp,Obj;jqTemp=$(jqObj).find(".dndiset,.dndrset");if(jqTemp.length){jqObj=jqTemp}if($(jqObj).hasClass("dndrset")){Class="dnd_cmpcont_r"}if($(jqObj).hasClass("dndiset")){Class="dnd_cmpcont_i"}if(Class==null){return null}try{InfoDiv=$(jqObj).text();InfoDiv=InfoDiv.replace(/['#?&;]/gi," ");Obj=eval("("+InfoDiv+")");Obj.Class=Class;if((Obj.Description==null)&&(Obj.Txt!=null)){Obj.Description=Obj.Txt}if((Obj.Txt==null)&&(Obj.Description!=null)){Obj.Txt=Obj.Description}if((Obj.TxtEx==null)){Obj.TxtEx=""}if(Obj.Selected==null){Obj.Selected=0}}catch(err){return null}return Obj}function DnD_Compare_Save(){var jqObj=$(".dnd_comparedropbox:visible .dndiset");var i=0,r=0,Obj;var CompareData="";var r_sel="0",i_sel="0";for(i=0;i<jqObj.length;i++){Obj=DnD_GetInformation(jqObj[i]);if(Obj==null){continue}if(Obj.Selected!="0"){i_sel=i}CompareData+=Token.Encode(Obj.DB)+"&"+Obj.VehID+"&"+Obj.PicID+"&"+Obj.Description+"&"}if(i||r){CompareData=SaveVersion+"&"+i_sel+"&"+r_sel+"&"+i+"&"+r+"&"+CompareData}Cookie.GetID(function(){Cookie.Save("CAP_WEB_CD",CompareData,365)})}function DnD_Compare_GetDnDList(){var Obj={"Version":"0","Individual":{"Selected":0,"DB":[],"VehID":[],"PicID":[],"Description":[]},"Range":{"Selected":0,"DB":[],"VehID":[],"PicID":[],"Description":[]}};var i,i_sel,r_sel,i_count=0,r_count=0,c=0;var arr=Cookie.Load("CAP_WEB_CD");if(arr==""){return null}arr=arr.split("&");if(arr.length<9){return null}Obj.Version=arr[c++];Obj.Individual.Selected=arr[c++];Obj.Range.Selected=arr[c++];i_count=arr[c++];r_count=arr[c++];if(Obj.Version!=SaveVersion){return null}for(i=0;i<i_count;i++){Obj.Individual.DB[i]=Token.Decode(arr[c++]);Obj.Individual.VehID[i]=arr[c++];Obj.Individual.PicID[i]=arr[c++];Obj.Individual.Description[i]=arr[c++]}return Obj}function DnD_SetDropPanelHeight(){var jqObj,i,h=0;jqObj=$("#leftCompare:visible>*:visible");for(i=0;i<jqObj.length;i++){h+=$(jqObj[i]).outerHeight(true)}jqObj=$("#leftCompare:visible .dnd_cmpcont_i");if(jqObj.length<DnD_PanelView_MAX){h+=140}$("#leftCompare:visible").css({height:h+"px"})}function DnD_DropBoxGaps(DOver,DY){var jqObj,i,y,h;if(!DOver){DnD_DropBoxNoGaps();return 0}jqObj=$("#leftCompare:visible .dnd_cmpcont_i");var InsertPos=jqObj.length;for(i=0;i<jqObj.length;i++){y=$(jqObj[i]).offset().top;h=$(jqObj[i]).outerHeight(true)/2;if((DY>=y)&&(DY<(y+h))){InsertPos=i;break}y+=h;if((DY>=y)&&(DY<(y+h))){InsertPos=i+1;break}}if(InsertPos>=jqObj.length){if(!jqObj.length){InsertPos=0}else{y=$(jqObj[0]).offset().top;if(DY<y){InsertPos=0}}}for(i=0;i<jqObj.length;i++){if(InsertPos==i){$(jqObj[i]).find(".dndSpacer").stop(true).animate({height:"40px"},{duration:"fast"})}else{$(jqObj[i]).find(".dndSpacer").stop(true).animate({height:0},{duration:"slow"})}}return InsertPos}function DnD_DropBoxNoGaps(){$("#leftCompare:visible .dndSpacer").stop(true).animate({height:0},{duration:"fast"})}function DnD_DropBoxNoGapsNow(){$("#leftCompare:visible .dndSpacer").stop(true).css({height:0})};
