var omnitureDebug;
var loadOnFire=0;
var hbxActive=0;
var hbxSet=0;
var anObjectsSet=0;
var baseAtA="http://www.autotrader.co.uk/";
var setChan="cars";
var scChannel;
var setContID="advice";
var userName;
var userId;
var setLoggedIn="no";
var defProps;
var scLocRef=location.href.toLowerCase();
var scReferrer=document.referrer.toLowerCase();
var atAnalytics;

var spn,smlc,sci,shc1,shc2,shc3,shc4,slt,sfv,som;

var cookieEnabled=(navigator.cookieEnabled)? true : false
if (typeof navigator.cookieEnabled=="undefined" && !cookieEnabled){ 
document.cookie="testcookieuser"
cookieEnabled=(document.cookie.indexOf("testcookieuser")!=-1)? true : false
} if (cookieEnabled){function getCookie(name){
var nameEq = name + '=';
var cookieArray = document.cookie.split(';');
for (var i = 0;i < cookieArray.length; i++) {
var cookie = cookieArray[i];
while (cookie.charAt(0) == ' ') {
cookie = cookie.substring(1, cookie.length);
} if (cookie.indexOf(nameEq) == 0) {
return cookie.substring(nameEq.length, cookie.length);
}} return null;
} function getCookieValues(cna,val) {
var cookieName = getCookie(cna);var val=val+"=";
if (cookieName != null && cookieName.length > 0) {
var indexOfV = cookieName.indexOf(val);
if (indexOfV >= 0) {var indexOfNextAmp = cookieName.indexOf('&', indexOfV);
if (indexOfNextAmp >= 0) {return cookieName.substring(indexOfV + val.length, indexOfNextAmp);
}else{return cookieName.substring(indexOfV + val.length, cookieName.length);
}}} return null;
}}

omnitureDebug=(navigator.omnitureDebug)? true : false
if (typeof navigator.omnitureDebug=="undefined" && !omnitureDebug){ 
omnitureDebug=(document.cookie.indexOf("omnitureDebug")!=-1)? true : false
}

function addLoadEvent(func){
var oldonload=window.onload;
if(typeof window.onload!='function'){
window.onload=func;
}else{window.onload=function(){
if(oldonload){oldonload();
}func();
}}}

function createTagJail(){
if(!loadOnFire){document.write('<div id="atAnalytics"><\/div>');
}else{if(typeof document.getElementsByTagName("body")[0] == 'object'){
var bodyStick=document.getElementsByTagName("body")[0];
var createAta=document.createElement('div');
createAta.setAttribute('id','atAnalytics');
bodyStick.appendChild(createAta);
}}atAnalytics=document.getElementById('atAnalytics');
}

function grabJsInc(filename){
if(!loadOnFire){document.write('<scr'+'ipt type="text/ja'+'vascr'+'ipt" src="'+filename+'"><\/scr'+'ipt>');
}else{var getJs=document.createElement('script');
getJs.setAttribute("type","text/javascript");
getJs.type="text/javascript";
getJs.setAttribute("src", filename);
getJs.src=filename;
atAnalytics.appendChild(getJs);
}}

function remChars(str){if(str.charAt(0)=="/"){str=str.substr(1);
}strl=str.length-1;if(str.charAt(strl)=="/"||str.charAt(strl)=="+"){str=str.substring(0,strl);
}return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '').replace(/\s+/g, '_').replace(/\+/g,"_").replace(/\//g,":").replace(/\&amp;/g,"&").toLowerCase();
}

function setOmnitureDebug(){
omDebPageName=s.pageName+" ("+s.hbx_lt+")";
if(omnitureDebug){if(!loadOnFire){
document.write('<div id="omDeb" style="position:absolute;top:0px;right:0px;padding:10px;z-index:9999;font-size:11px;background:transparent url('
+baseAtA+'_images/_structure_images/omniture-debuger.gif) no-repeat fixed top right">'+omDebPageName+'<\/div>');
}else{var omDeb=document.getElementById("omDeb");
if(omDeb!=null){omDeb.innerHTML=omDebPageName;
}else{var debugDiv=document.createElement('div');
debugDiv.id="omDeb";
debugDiv.style.position="absolute";
debugDiv.style.top="0px";
debugDiv.style.right="0px";
debugDiv.style.padding="10px";
debugDiv.style.zIndex="9999";
debugDiv.style.fontSize="11px";
debugDiv.style.background="transparent url('"+baseAtA+"_images/_structure_images/omniture-debuger.gif') no-repeat fixed top right";
debugDiv.innerHTML=omDebPageName;
atAnalytics.appendChild(debugDiv);
}}}}

function setObjectSCT(){
grabJsInc(baseAtA+'common/s_code.js');
}

function scPageViewVars(cpn,cmlc){
cpn=remChars(cpn);cmlc=remChars(cmlc);
var chcpn = ":"+cpn; 
if(cmlc.indexOf(chcpn)!=-1) chcpn = "";
s.pageName=cmlc+chcpn;
if(!window.channel){if(scLocRef.indexOf('bike')!=-1) setChan="bikes";
if(scLocRef.indexOf('vans')!=-1 || scLocRef.indexOf('comm')!=-1 && scLocRef.indexOf('common')==-1) setChan="vans";
if(scLocRef.indexOf('plant')!=-1 || scLocRef.indexOf('agri')!=-1) setChan="plant";
if(scLocRef.indexOf('trucks')!=-1) setChan="trucks";
if(scLocRef.indexOf('cara')!=-1) setChan="caravans";
}else{scChannel=channel;
}if(!scChannel) scChannel=setChan;
if(!s.channel) s.channel=scChannel;
var atVersion="at2";
if(!window.at2&&typeof WebAnalyticsService!="function")atVersion="at1";
s.prop31=atVersion+":"+s.pageName;
if(cmlc.indexOf(":")!=-1){defProps=s.pageName.split(":");
if(defProps[1]) s.prop1=defProps[0]+":"+defProps[1];
if(defProps[2]) s.prop2=s.prop1+":"+defProps[2];
if(defProps[3]) s.prop3=s.prop2+":"+defProps[3];
if(defProps[4]) {var prop4Build=s.prop3+":"+defProps[4];
if(defProps[5]) prop4Build=prop4Build+":"+defProps[5];
if(defProps[6]) prop4Build=prop4Build+":"+defProps[6];
if(defProps[7]) prop4Build=prop4Build+":"+defProps[7];
if(defProps[8]) prop4Build=prop4Build+":"+defProps[8];
s.prop4=prop4Build;
}}else{s.prop1=s.pageName;
}if(scLocRef.indexOf("editorial")!=-1) setContID="editorial";
if(scLocRef.indexOf("sell.auto")!=-1) setContID="sell";
if(scLocRef.indexOf("registration.auto")!=-1) setContID="registration";
if(scLocRef.indexOf("search.auto")!=-1 || scLocRef.indexOf("es-staging.auto")!=-1 || scLocRef.indexOf("mapping.auto")!=-1){setContID="search";
s.pageURL=scLocRef.replace(location.search.toLowerCase(),'');
if(window.eSfreshSearch=="1") s.events=s.apl(s.events,"event1",",",1);
if(window.eSkeywords) if(eSkeywords.length>0){s.prop8=eSkeywords.toLowerCase();
}if(window.eStotalAdverts) s.prop12=eStotalAdverts;
if(window.eSpostcodeDistance) s.prop14=eSpostcodeDistance;
if(window.eSpostcode) s.prop15=eSpostcode.replace(/\ /g,"").toLowerCase();
if(window.eSmake) s.prop16=eSmake.toLowerCase();
if(window.eSmodel) s.prop17=eSmodel.toLowerCase();
if(window.eSminPrice) s.prop18=eSminPrice;
if(window.eSmaxPrice) s.prop19=eSmaxPrice;
if(window.eSmaxMileage) s.prop20=eSmaxMileage;
if(window.eSmaxYear) s.prop21=eSmaxYear;
if(window.eSformType) s.prop22=eSformType;
if(window.eSsort) s.prop23=eSsort.toLowerCase();
if(window.eSsellerType) s.prop24=eSsellerType.toLowerCase();
if(s.prop15) s.events=s.apl(s.events,"event12",",",1);
if(window.eSadvertImageCount>="1") s.prop39=eSadvertImageCount;
if(scLocRef.indexOf("advertid")!=-1){window.eSadvertId=s.getQueryParam('advertId');
}if(window.eSadvertId&&s.pageName.indexOf("image")==-1) s.events=s.apl(s.events,"event7",",",1);
}s.prop5=setContID;s.hier1=cmlc.replace(/\:/g,",");
if(window.document.title) s.prop6=document.title.toLowerCase();
s.prop7=s.hier1.substring(s.hier1.lastIndexOf(","),"-1");
var scripts = document.getElementsByTagName("script");for(var i=0; i<scripts.length; i++){
var ads=scripts[i].src;if(ads.indexOf("acptr.auto")==7 || ads.indexOf("ads.auto")==7 || ads.indexOf("www.google")==7){s.events=s.apl(s.events,"event4",",",0);
}else if(window.pageNum){s.events=s.apl(s.events,"event4",",",1);
}}if(scReferrer!=null && typeof scReferrer =='string' && scReferrer.length > 0 && (scReferrer.indexOf("search.auto")!=-1 || scReferrer.indexOf("es-staging.auto")!=-1 || scReferrer.indexOf("mapping.auto")!=-1)){
if(scReferrer!=null && scReferrer.indexOf("?")!=-1){scReferrer=scReferrer.split("?");s.referrer=scReferrer[0];
}}var userNewsletter,userMake,userModel,userThirdParty,userInsRenewal,userState,userPostCode,userDOB;
if (window.omPage) {if (omPage.indexOf("registration,confirmation")!=-1){s.events=s.apl(s.events,"event3",",",1);
if (!s.prop43 && window.regTitle != null && window.regTitle != 'null') s.prop43 = regTitle.toLowerCase();
if (regNewsletter != null && regNewsletter != '0') userNewsletter = "1";
if (regMake != null && regMake != 'null') userMake = regMake.toLowerCase();
if (regModel != null && regModel != 'null') userModel = regModel.toLowerCase();
if (regThirdParty != null && regThirdParty != '0') userThirdParty = "1";
if (regInsRenewal != null && regInsRenewal != 'null') userInsRenewal = regInsRenewal.toLowerCase();
if (regState != null && regState != 'null') userState=regState.toLowerCase();
if (regPostCode != null && regPostCode != 'null') userPostCode=regPostCode.replace(/\+/g,"").replace(/\ /g,"").toLowerCase();
if (regDOB != null && regDOB != 'null') userDOB = regDOB.replace(/\"/g,'');
}}if (cookieEnabled){var userName = getCookieValues("user","FN");
userId = getCookieValues("userid","ID");
if (userName != null && userName != 'null') {setLoggedIn="yes";
if (userId != null && userId != 'null') userId = getCookieValues("user","ID");
userMake = getCookieValues("user","CMAKE");
userModel = getCookieValues("user","CMODEL");
userThirdParty = getCookieValues("user","TP");
userInsRenewal = getCookieValues("user","INS");
userState = getCookieValues("user","COUNTY");
userPostCode = getCookieValues("user","PC").replace(/\" "/g,"_");
userDOB = getCookieValues("user","DOB");
if (!s.prop45 && userMake != null && userMake != 'null') s.prop45 = userMake.toLowerCase();
if (!s.prop46 && userModel != null && userModel != 'null') s.prop46 = userModel.toLowerCase();
if (!s.prop47 && userThirdParty != null && userThirdParty != '0') s.prop47 = "yes";
if (!s.prop44 && userInsRenewal != null && userInsRenewal != 'null') s.prop44 = userInsRenewal.toLowerCase();
if (!s.state && userState != null && userState != 'null') s.state=userState.toLowerCase();
if (!s.zip && userPostCode != null && userPostCode != 'null') s.zip=userPostCode.replace(/\+/g,"").replace(/\ /g,"").toLowerCase();
if (!s.prop41 && userDOB != null && userDOB != 'null') s.prop41 = userDOB.replace(/\"/g,'');
}} if (!s.prop29) s.prop29=setLoggedIn;
if (!s.prop30 && userId != null && userId != 'null') s.prop30=userId;
if(scLocRef.indexOf("sell")!=-1){if(scLocRef.indexOf("trade.")!=-1 
|| scLocRef.indexOf("trade/")!=-1 || s.getQueryParam('trade')=="true") {olaSetType="trade";
} else {if(scLocRef.indexOf("private.")!=-1) olaSetType="private";
}if(scLocRef.indexOf("packageid")!=-1) s.prop48=s.getQueryParam('packageId').toLowerCase();
if(scLocRef.indexOf("adtype")!=-1) s.prop49=s.getQueryParam('adtype').toLowerCase();
if(window.olaSetType) s.prop32=olaSetType;
if(scLocRef.indexOf("platform=")!=-1) {var tempVar=s.getValOnce(s.getQueryParam('platform'),'s_atplatform',30);
if(tempVar) s.campaign=s.getQueryParam('platform').toLowerCase();
}if(scLocRef.indexOf("cid=")!=-1) {var tempVar=s.getValOnce(s.getQueryParam('cid'),'s_atcid',30);
if(tempVar) s.campaign=s.getQueryParam('cid').toLowerCase();
}}}

function startSiteCat(cpn,cmlc,clt){
if(clt!=null) s.hbx_lt=clt;
scPageViewVars(cpn,cmlc);
s_code=void(s.t());s.getImgLength();
if(s_code){return s_code;
}if(navigator.appVersion.indexOf('MSIE')>=0){return unescape('%3C')+'\!-'+'-';}
}

function startMetrics(){
if(typeof document.getElementsByTagName("body")[0] == 'object'){
createTagJail();
setObjectSCT();
anObjectsSet=1;
}}

startMetrics();

function IEContentLoaded(w,fn){
var d=w.document,done=false,
init=function(){if(!done){done=true;fn();
}};(function(){try{d.documentElement.doScroll('left');
}catch(e){setTimeout(arguments.callee, 0);return;
}init();})();d.onreadystatechange=function(){
if(d.readyState=='complete'){
d.onreadystatechange=null;
init();
}};}

function doTagCalls(gpn,gmlc,gci,ghc1,ghc2,ghc3,ghc4,glt,gfv,gom){
startSiteCat(gpn,gmlc,glt);
}

function doHBX(atpn,atmlc,atci,athc1,athc2,athc3,athc4,atlt,atfv,atom){ 
if(!hbxSet){if(typeof atpn =='string' && atpn.length > 0){spn=atpn;}else{spn=document.title;}
if(typeof atmlc =='string' && atmlc.length > 0){smlc=atmlc;}else{smlc="/cars";}
if(typeof atci =='string' && atci.length > 0){sci=atci;}else{sci="";}
if(typeof athc1 =='string' && athc1.length > 0){shc1=athc1;}else{shc1="";}
if(typeof athc2 =='string' && athc2.length > 0){shc2=athc2;}else{shc2="";}
if(typeof athc3 =='string' && athc3.length > 0) {shc3=athc3;}else{shc3="";}
if(typeof athc4 =='string' && athc4.length > 0){shc4=athc4;}else{shc4="";}
if(typeof atlt =='string' && atlt.length > 0){slt=atlt;}else{slt="auto";}
if(typeof(atfv)!='undefined'&&typeof atfv!='string'){
if(parseInt(atfv)!=parseFloat(atfv)){atfv=atfv.toString();
}}if(typeof atfv =='string' && atfv.length > 0){sfv=atfv;}else{sfv="n";}
if(typeof atom =='string' && atom.length > 0){som=atom;}else{som="";}
}if(typeof document.getElementsByTagName("body")[0] == 'object'){
if(anObjectsSet){hbxSet=hbxSet+1;
if(!hbxActive&&hbxSet==1){
doTagCalls(spn,smlc,sci,shc1,shc2,shc3,shc4,slt,sfv,som);
hbxActive=1;
}}}
}

function startHbLegacy(){
_hbLink=function(a,b){
trackClick(remChars(a),remChars(b));
};_hbPageView=function(a,b){
scPageViewVars(a,b);
void(s.t());s.getImgLength();
setOmnitureDebug();
};}

function checkHBX(){
if((!hbxActive)||(typeof callDefaultHBXfunction!='string')){
doHBX(spn,smlc,sci,shc1,shc2,shc3,shc4,slt,sfv,som);
}}

addLoadEvent(function(){loadOnFire=1;
if(!hbxActive&&!anObjectsSet){
var browserIsIE=/MSIE /i.test(navigator.userAgent);
if (browserIsIE){IEContentLoaded(window, startMetrics);
}else{startMetrics();
}}setTimeout("checkHBX();setOmnitureDebug();",500);
startHbLegacy();
});

trackClick=function(){
if(trackClick.arguments[0]!=undefined){var lid=trackClick.arguments[0];
var lpos=trackClick.arguments[1];var desc=trackClick.arguments[2];
var eve=trackClick.arguments[3];var anc=trackClick.arguments[4];
var s=s_gi(s_account);s.events="None";
s.prop33="";s.prop34="";s.prop35="";s.prop36="";s.prop37="";
s.linkTrackVars="events,prop33,prop34,prop35,prop36,prop37";
if(!eve){var eve="event20";}s.linkTrackEvents=eve;s.events=eve;
if(s.pageName)s.prop33=s.pageName;
s.prop34=lid;s.prop35=s.prop33+","+s.prop34;
if(lpos){s.prop36=lpos;s.prop37=s.prop34+","+s.prop36;
}if(!anc){anc=new Object();anc.href="http://www.dummyhref.com";}
void(s.tl(anc,"o",desc));s.events="";
s.prop33="";s.prop34="";s.prop35="";s.prop36="";s.prop37="";
}};