$.chug.util={isDisplayable:function(a){if(a&&a!=undefined&&a!=""&&a!=null){return true}else{if(a===0){return true}else{return false}}},printField:function(d,f,e,g){var a;if(f==false){a=true}if(this.isDisplayable(d)){var c;if(e&&e!=null){if(a&&(e=="img"||e=="href"||e=="text")){return d}if(e=="img"){$(f).attr("src",d).show()}else{if(e=="href"){$(f).attr("href",d).show()}else{if(e=="text"){$(f).val(d).show()}else{if(e=="dollars"){c=this.formatDollars(d)}else{if(e=="miles"){if(typeof(d)=="number"){c=this.addCommas(d)+" "+$.chug.constants.miles}else{c=d}}else{if(e=="shortMiles"){if(typeof(d)=="number"){c=this.addCommas(d)+" "+$.chug.constants.shortMiles}else{c=d}}else{if(e=="milesNoLabel"){if(typeof(d)=="number"){c=this.addCommas(d)+" "+$.chug.constants.milesNoLabel}else{c=d}}else{if(e=="years"){var b;if(parseInt(d)==1){b="year"}else{b="years"}c=d+" "+b}else{if(e=="months"){var b;if(parseInt(d)==1){b="month"}else{b="months"}c=d+" "+b}else{c=d}}}}}}if(a){return c}else{$(f).html(c).show()}}}}}else{c=d;if(a){return c}else{$(f).html(c).show()}}}else{if(g&&g==true){if(a){return $.chug.constants.notReported}else{$(f).html($.chug.constants.notReported).show()}}else{if(a){return null}else{$(f).hide()}}}return null},formatField:function(a,c,b,d){return this.printField(a,c,b,d,true)},currentUserId:function(){return $.chug.util._cookieValue("user")},_cookieValue:function(b){var d=document.cookie.split(";");var a=d.length;for(var c=0;c<a;c++){var e=d[c].replace(/^\s+/,"").split("=");if(e[0]==b){return e[1]}}return null},formatDollars:function(a){return("$"+this.addCommas(parseInt(a)))},addCommas:function(b){b+="";x=b.split(".");x1=x[0];x2=x.length>1?"."+x[1]:"";var a=/(\d+)(\d{3})/;while(a.test(x1)){x1=x1.replace(a,"$1,$2")}return x1+x2},modifyThousandsToUseK:function(b){b+="";x=b.split(".");x1=x[0];x2=x.length>1?"."+x[1]:"";var a=/(\d+)(\d{3})/;while(a.test(x1)){x1=x1.replace(a,"$1k")}return x1+x2},hasBlackBookOptions:function(a){if(a.blackBookUsedData!=undefined&&a.blackBookUsedData.length>0&&a.blackBookUsedData[0].options!=undefined&&a.blackBookUsedData[0].options.length>0){return true}else{return false}},hasBlackBookMileageRanges:function(a){if(a.blackBookUsedData!=undefined&&a.blackBookUsedData.length>0&&a.blackBookUsedData[0].mileageRanges!=undefined&&a.blackBookUsedData[0].mileageRanges.length>0){return true}else{return false}},trim:function(a){return a.replace(/^\s*/,"").replace(/\s*$/,"")},centerOverlay:function(e,f){if($(f).css("display")=="block"){var d=$(e).height();var a=$(e).width();var h=$(f).height();var c=$(f).width();var b=0;var g=0;if(a>c){b=(a-c)/2}if(d>h){g=(d-h)/2}$(f).css("left",b);$(f).css("top",g)}},getCurrentYear:function(){var a=new Date();return(a.getFullYear())},isCurrentYear:function(a){return(a>=$.chug.constants.newModelYear)},displayPrice:function(a){return((a>0)?"$"+this.addCommas(a):"Price: N/A")},displayMiles:function(a,c,b){if(!b){b=true}var d="";var e=this.isCurrentYear(c);if(a<100&&e){d="New"}else{switch(a){case 0:case null:if(!b){d=0}else{d=$.chug.constants.notReported}break;default:if(!b){d=a}else{d=this.addCommas(a)+" mi"}break}}return d},formatMakeModelTrim:function(a,g,d){var b=a+" "+g;if(this.isDisplayable(d)){b+=" "+d}var c=b.toLowerCase();var h=b.split(" ");var j=c.split(" ");for(var f=0;f<j.length;f++){for(var e=1;e+f<j.length;e++){if(j[f]==j[f+e]){j.splice(f+e,1);h.splice(f+e,1)}}}return h.join(" ")},strip:function(a,b){var c=b.replace(a,"");return c},isValueInArray:function(a,b){var d=false;a.sort();for(var c=0;c<a.length;c++){if(a[c]==b){d=true;break}}return d},readdValueToArray:function(c,a){var b=$.inArray(a,c);if(b>=0){c.splice(b,1)}if(a){c.push(a)}return c},getChugURL:function(){var a=window.location.protocol+"//"+window.location.host;return a},getHistoricalTotalCars:function(d){var f=0;var h=true;var a=null;var c=null;var k;var j;var l;var m;var g;var b;for(var e=0;e<d.length;e++){b=d[e];if(h==true){h=false;f=b.totalCars;k=2000+b.day.substr(0,2)*1;j=b.day.substr(2,2)*1;l=b.day.substr(4,2)*1;a=new Date(k,j,l)}else{k=2000+b.day.substr(0,2)*1;j=b.day.substr(2,2)*1;l=b.day.substr(4,2)*1;c=new Date(k,j,l);m=a.getTime()-c.getTime();g=(((m/1000)/60)/60)/24;if(g<=30){f=b.totalCars}else{return f}}}return f},showCarSavedModalDialog:function(){$("#car-saved-popup").jqmShow();$.chug.util.centerOverlay($(window),$("#car-saved-popup"));setTimeout("$('#car-saved-popup').jqmHide()",6000)},showViewCarfaxReportModalDialog:function(){$("#view-carfax-report-popup").jqmShow();$.chug.util.centerOverlay($(window),$("#view-carfax-report-popup"))},showPriceReportModalDialog:function(){$("#view-price-report-popup").jqmShow();$.chug.util.centerOverlay($(window),$("#view-price-report-popup"))},showOptionPkgsReportModalDialog:function(){$("#view-option-pkgs-report-popup").jqmShow();$.chug.util.centerOverlay($(window),$("#view-option-pkgs-report-popup"))},trackEvent:function(b,c,a){try{_gaq.push(["_trackEvent",b,c,a,0,true])}catch(d){}},trackPageview:function(a){try{if(!a){return}_gaq.push(["_trackPageview",a])}catch(b){}},getUserPrefs:function(){var a=this;if(typeof chugUserPrefs!=undefined&&$.cookies!=undefined&&$.cookies.get("chugUserPrefsData")!=null){chugUserPrefs=$.cookies.get("chugUserPrefsData")}else{a.initializeUserPrefsCookie()}},initializeUserPrefsCookie:function(){chugUserPrefs=new Object;chugUserPrefs.resultsActiveTab=1;chugUserPrefs.resultsTabsHidden=true;chugUserPrefs.indexActiveTab=0;chugUserPrefs.yourCarsActiveTab=0;chugUserPrefs.showResultsInterstitial=true;chugUserPrefs.resultView="listmap";chugUserPrefs.resultsLastSearch="";chugUserPrefs.resultsLastHash="";$.cookies.set("chugUserPrefsData",chugUserPrefs,{expiresAt:$.chug.util.yearFromNow()})},setUserPref:function(a,c){var b=this;chugUserPrefs[a]=c;b.updateUserPrefsCookie()},updateUserPrefsCookie:function(){$.cookies.set("chugUserPrefsData",chugUserPrefs,{expiresAt:$.chug.util.yearFromNow()})},setUserId:function(a){$.cookies.set("user",a,{expiresAt:$.chug.util.yearFromNow()})},getUserId:function(){return $.cookies.get("user")},yearFromNow:function(){var a=new Date();return a.getFullYear()+1+"-"+a.getMonth()+1+"-"+a.getDate()},convertMicrosecondsToDays:function(a){return Math.ceil((((a/1000)/60)/60)/24)},checkToUpgradeBrowser:function(){$.reject({reject:{msie5:true,msie6:true},browserInfo:{firefox:{text:"Firefox 3.5+",url:"http://www.mozilla.com/firefox/"},safari:{text:"Safari 5+",url:"http://www.apple.com/safari/download/"},opera:{text:"Opera",url:"http://www.opera.com/download/",allow:{all:false}},chrome:{text:"Chrome 5+",url:"http://www.google.com/chrome/"},msie:{text:"Internet Explorer 7+",url:"http://www.microsoft.com/windows/Internet-explorer/"},gcf:{text:"Google Chrome Frame",url:"http://code.google.com/chrome/chromeframe/",allow:{all:false,msie:false}}}})},makeInitCaps:function(a){a=a.toLowerCase();a=a.substr(0,1).toUpperCase()+a.substring(1,a.length);var c=0;var b=0;while((b=a.indexOf(" ",c))&&(b!=-1)){a=a.substring(0,b+1)+a.substr(b+1,1).toUpperCase()+a.substring(b+2,a.length);c=b+1}return a},trackCarAction:function(b,a,c,d){$.chug.json.incrementCarAction($.chug.util.currentUserId(),a,c,d,b)},htmlEscape:function(a){return(""+a).split("&").join("&amp;").split("<").join("&lt;").split(">").join("&gt;").split('"').join("&#34;").split("'").join("&#39;")}};
