(function () { /* * Api 0.1 Prerelease - The Dealer.com API * Copyright (C) 2007 Dealer.com * * October 2007 * Randy Morey, Web Developer */ /* TODO: * Implement Api.urlParams * Implement cross-browser debugging * Rewrite the if-block in Api.get as a series of inner functions, one for each case * Comment the Api.get function */ var Api = { version: '0.1 Prerelease', settings: { /** * Toggles debug mode: Api messages are logged to the console. * @type Boolean */ debug: true, /** * Toggles deploy mode: Api calls are made live instead of local. * @type Boolean */ deploy: true } }; // Assign Api global scope window.Api = Api; /** * Logs a message to the console in supported browsers. * In unsupported browsers, does nothing. * @param {String} msg Message to be logged */ Api.debug = !Api.settings.debug ? function () {} : function (msg) { if (typeof console != 'undefined') { console.log('[api] ' + msg); } }; /** * Extends an object with one or more additional objects. * If only one argument is passed, Api.extend extends Api itself. * @param {Object} Object to extend * @param {Object} Object with which to extend former */ Api.extend = function() { var target = arguments[0] || {}, a = 1, al = arguments.length, deep = false; var prop; if (al == 1) { target = this; a = 0; } for (; a < al; a++) { if ((prop = arguments[a]) !== null) { for (var i in prop) { if (target == prop[i]) { continue; } if (deep && (typeof prop[i] == 'object') && target[i]) { Api.extend( target[i], prop[i]); } else if (prop[i] !== undefined) { target[i] = prop[i]; } } } } return target; }; /** * Gets a script or style sheet cross-domain. * @param {String} type type of file to get (style or script) * @param {String} url url of file to get * @param {Object} params object consisting of key/value pairs to be converted into url parameteres * @param {Function} callback called upon successful completetion of file get */ Api.load = function (type, url, params, success) { type = type || 'script'; url = url || ''; params = params || {}; success = success || function () {}; var el = document.createElement(type == 'script' ? type : 'link'); var head = document.getElementsByTagName('head')[0]; var loaded = false; if (type == 'script') { el.src = url + Api.urlParams(params); el.type = 'text/javascript'; el.onload = el.onreadystatechange = function () { if (!loaded && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete')) { loaded = true; Api.debug('Api.get() - done loading ' + type + ': ' + url); if (navigator.appVersion.indexOf('MSIE ' + (arguments[0] || '')) == -1) { head.removeChild(el); } success(); } }; } else if (type == 'stylesheet') { el.href = url + Api.urlParams(params); el.type = 'text/css'; el.rel = type; } head.appendChild(el); Api.debug('Api.get() - loading ' + type + ': ' + url); }; Api.get = function( id ) { return document.getElementById(id) } /** * Loads a style sheet. * @param {String} url path to style sheet */ Api.getStyle = function (url) { Api.load('stylesheet', url); }; /** * Loads a script cross-domain. * @param {String} src path to script file (may be cross-domain) * @param {Function} success called after successful script load */ Api.getScript = function (url, success) { Api.load('script', url, {}, success); }; /** * Converts an object consisting of key/value pairs to a URL parameter list. * {foo: 'bar', world: 'hello'} becomes '?foo=bar&world=hello' * @param {String} type type of file to get (style or script) * @return {String} string representation of object, in url paramaeter format */ Api.urlParams = function (obj) { return ''; }; })();(function () { /** * apicall.js 1.5 - The Dealer.com Cross-Domain Data Getter * Copyright (C)2007 Dealer.com * * October 2007 **/ var USED_INVENTORY = window.USED_INVENTORY = 1; var NEW_INVENTORY = window.NEW_INVENTORY = 2; var ApiCall = window.ApiCall = function(settings) { return this instanceof ApiCall ? this.initialize(settings) : new ApiCall(settings); }; ApiCall.prototype = { initialize: function (settings) { this.params = []; this.params.index = []; Api.extend(this,settings); this.url = Api.settings.deploy ? 'http://apis.dealer.com/services/' : 'http://localhost:7070/services/'; Api.debug("url: " + this.url ); }, version: '1.5', url: '', reseller: '', accountId: '', service: '', operation: '', version: 'v1', output: 'json', callback: '', param: function(key, value) { this.params.index.push(key); this.params[key] = value; }, execute: function() { Api.debug('ApiCall.execute() - API call for service: ' + this.service); Api.getScript(this.toUrl()); }, toUrl: function() { var request = [ this.url, this.service, '/', this.version, '/', this.operation, '?reseller=', this.reseller, '&accountId=', this.accountId ].join(''); var thisUrl = request; if (this.callback != '') { thisUrl += '&callback=' + this.callback; } if (this.output != 'json') { thisUrl += '&output=' + this.output; } for (var i = 0; i < this.params.index.length; i++) thisUrl += '&' + this.params.index[i] + '=' + this.params[ this.params.index[i] ]; return thisUrl; } }; ApiCall.prototype.addParam = ApiCall.prototype.param; })();var SiSTeR = {}; (function(){ CarFlixWindow = { version: '1.5', autoplay: true, initialized: false, domain: "$base", imagePath: "", windowWidth: 560, windowHeight: 375, window: null, height: null, reseller: "", accountId: "", sessionId: "", branding:" vcl", deploy: true, vehicleDetailsPage: '', currentVehicleData: null, target: null, floatable: true, canSubmit: false, drag : { ie: document.all, nn6: (document.getElementById && !document.all), isdrag: false, x: 0, y: 0, tx: 0, ty: 0, dobj: null, movemouse: function(e) { if (DDC.CarFlixWindow.drag.isdrag) { DDC.CarFlixWindow.drag.dobj.style.left = DDC.CarFlixWindow.drag.nn6 ? (DDC.CarFlixWindow.drag.tx + e.clientX - DDC.CarFlixWindow.drag.x)+"px" : DDC.CarFlixWindow.drag.tx + event.clientX - DDC.CarFlixWindow.drag.x; DDC.CarFlixWindow.drag.dobj.style.top = DDC.CarFlixWindow.drag.nn6 ? (DDC.CarFlixWindow.drag.ty + e.clientY - DDC.CarFlixWindow.drag.y)+"px" : DDC.CarFlixWindow.drag.ty + event.clientY - DDC.CarFlixWindow.drag.y; if( (parseFloat(DDC.CarFlixWindow.drag.dobj.style.left) < 0) || (parseFloat(DDC.CarFlixWindow.drag.dobj.style.top) < 60) ) { DDC.CarFlixWindow.drag.isdrag = false; if( parseFloat(DDC.CarFlixWindow.drag.dobj.style.left) < 0 ) { DDC.CarFlixWindow.drag.dobj.style.left = DDC.CarFlixWindow.drag.nn6 ? "0px":0; } else { DDC.CarFlixWindow.drag.dobj.style.top = DDC.CarFlixWindow.drag.nn6 ? "60px":60; } } return false; } }, selectmouse: function(e) { var fobj = DDC.CarFlixWindow.drag.nn6 ? e.target : event.srcElement; var topelement = DDC.CarFlixWindow.drag.nn6 ? "HTML" : "BODY"; while (fobj.tagName != topelement && fobj.className != "dragme") { fobj = DDC.CarFlixWindow.drag.nn6 ? fobj.parentNode : fobj.parentElement; } if (fobj.className=="dragme") { DDC.CarFlixWindow.drag.isdrag = true; DDC.CarFlixWindow.drag.dobj = fobj; DDC.CarFlixWindow.drag.tx = parseInt(DDC.CarFlixWindow.drag.dobj.style.left+0); DDC.CarFlixWindow.drag.ty = parseInt(DDC.CarFlixWindow.drag.dobj.style.top+0); DDC.CarFlixWindow.drag.x = DDC.CarFlixWindow.drag.nn6 ? e.clientX : event.clientX; DDC.CarFlixWindow.drag.y = DDC.CarFlixWindow.drag.nn6 ? e.clientY : event.clientY; document.onmousemove = DDC.CarFlixWindow.drag.movemouse; return false; } } }, init: function (settings) { if( settings.deploy != undefined ) { Api.settings.deploy = settings.deploy; } Api.extend(this,settings); if( this.vehicleDetailsPage == '' ) { this.vehicleDetailsPage = "http://"+ this.accountId + ".vip.videocarlot.tv/used-inventory/vehicle-details.htm?vehicleId="; } Api.getStyle( this.domain + '/toolkit/carflix/css/window.css' ); this.imagePath = this.domain+"/toolkit/carflix/img"; //set country flag for units of measurement if (this.locale) { this.countryCode = this.locale.split('_')[1]; } SiSTeR.Config = { autoplay: this.autoplay, displaylogo: false, pubid: "3DF" } var carflix = document.createElement('div'); carflix.setAttribute('id', 'carFlixWindow'); carflix.className = "dragme"; carflix.style.position = 'absolute'; carflix.style.display = 'none'; carflix.style.width = this.windowWidth+'px'; carflix.style.height = this.windowHeight+'px'; carflix.style.top = '200px'; carflix.style.left = '200px'; this.window = carflix; // begin generated content from /carflix/window-layout.vm carflix.innerHTML = '
' + '
' + '' + '
' + '' + '' + '
' + '
' + 'Vehicle Options' + 'Similar Vehicles' + 'Test Drive' + 'View Details ' + '
' + '
' + '
Loading...
' + '
' + '
' + '' + '' + '' + '' + '' + '' + '
Request More Information
' + '
First Name
' + '
Last Name
' + '
Email
' + '
Phone
' + '
Comments
' + '
' + '
' + '
' + '' + '' + '' + '
' + '' + '
' + 'Call Us Now: ' + '' + '© SiSTeR Technology   ' + 'logo' + '' + '
' + '' + ' '; // end generated content this.window = carflix; Api.debug( "deploy: " + Api.settings.deploy ); }, open: function( vehicleId, event ) { if( Api.get("carFlixWindow") == null ) { if( this.target != null ) { this.window.style.position = "relative"; this.window.style.top = '0px'; this.window.style.left = '0px'; Api.get(this.target).appendChild( this.window ); if(Api.get("close")) Api.get("close").style.visibility = "hidden"; } else { document.body.appendChild(this.window); } this.height = this.window.offsetHeight; if( this.floatable ) { document.getElementById("handle").onmousedown = DDC.CarFlixWindow.drag.selectmouse; document.getElementById("handle").onmouseup = function(){DDC.CarFlixWindow.drag.isdrag = false;} } } if( this.floatable ) this.position(event); this.toggle("main","contact"); this.load( vehicleId ); if (typeof document.body.style.maxHeight === "undefined") { if(document.getElementById("smartbrowseForm")) document.getElementById("smartbrowseForm").style.display = "none"; if(document.getElementById("sortbyForm")) document.getElementById("sortbyForm").style.display = "none"; }; }, show: function() { this.window.style.display = "block"; }, close: function( ) { this.window.style.display = "none"; this.canSubmit = false; this.clear(); if (typeof document.body.style.maxHeight === "undefined") { if(document.getElementById("smartbrowseForm")) document.getElementById("smartbrowseForm").style.display = "none"; if(document.getElementById("sortbyForm")) document.getElementById("sortbyForm").style.display = "none"; }; }, openDetailsPage: function() { var url = this.vehicleDetailsPage + this.currentVehicleData.id; if(this.branding.indexOf("vcl") == -1) { document.location = url; } else { window.open(url,'detailsWindow','width=780,height=600,menubar=0,resizable=0,status=0,scrollbars=1,location=1'); } }, clear: function( ) { Api.get("wrapper").innerHTML = ""; Api.get("specsInner").innerHTML = ""; Api.get("similarInner").innerHTML = ""; Api.get("vehicleInfo").innerHTML = " Loading...."; Api.get("phoneInner").innerHTML = ""; }, load: function(vehicleId) { //TODO: start loading graphic this.clear(); Api.debug( this.reseller + " - " + this.accountId ); var call = ApiCall({ reseller: this.reseller, accountId: this.accoundId, service: 'carflix', operation: 'window', callback: 'DDC.CarFlixWindow.refresh' }); call.addParam('vehicleId', vehicleId); call.addParam('cache', false); call.execute(); }, refresh: function( data ) { this.currentVehicleData = data; Api.get("wrapper").innerHTML = '
'; SiSTeR.Players.load(SiSTeR.Config.pubid); // load up options for( var i=0; i < data.options.length; i++ ) Api.get("specsInner").innerHTML += ' '+data.options[i]+'
'; for( var i=0; i < data.similar.length; i++ ) { if(data.similar[i]) {//for IE var sim = [ '
', '', '', data.similar[i].year, " ", data.similar[i].make, " ", data.similar[i].model, " ", data.similar[i].trim, ' ', DDC.CarFlixWindow.checkMileage(data.similar[i].mileage, "
"), '

', DDC.CarFlixWindow.checkPrice(data.similar[i].price), '
' ].join(''); } Api.debug( sim ); Api.get("similarInner").innerHTML += sim; } //update items for branding if( this.branding.indexOf("vcl") == -1 ) { Api.get("cffooter").innerHTML = ""; } var vehicleInfo = [ ' ', data.year, ' ', data.make, ' ', data.model, ' ', data.trim ].join(''); //truncate vehicleInfo to always fit on one line var truncateLength = null; if (DDC.CarFlixWindow.checkPrice(data.price) == 'Please Call for Price') { truncateLength = 30; } else { truncateLength = 45; } if(vehicleInfo.length > truncateLength) vehicleInfo = vehicleInfo.substring(0,(truncateLength - 1)) + "... "; var info = [ vehicleInfo, DDC.CarFlixWindow.checkMileage(data.mileage, " "), ' - ', DDC.CarFlixWindow.checkPrice(data.price) ].join(''); Api.debug( data.year ); Api.get("vehicleInfo").innerHTML = info; Api.get("phoneInner").innerHTML = data.account.phone; Api.get("contactFrmAccountId").value = data.account.id; Api.get("contactFrmVehicleId").value = data.id; Api.get("testdriveFrmAccountId").value = data.account.id; Api.get("testdriveFrmVehicleId").value = data.id; //TODO: hide loading graphic this.show(); }, position: function(event) { //get scroll top var yScrolltop; if (self.pageYOffset) { yScrolltop = self.pageYOffset; } else if (document.documentElement && document.documentElement.scrollTop){ // Explorer 6 Strict yScrolltop = document.documentElement.scrollTop; } else if (document.body) {// all other Explorers yScrolltop = document.body.scrollTop; } var windowW = parseFloat(this.window.style.width)/2; var windowH = parseFloat(this.window.style.height)/2; var calcW, calcH; if (window.innerWidth && window.innerHeight) { calcW = window.innerWidth/2 - windowW + 'px'; calcH = window.innerHeight/2 - windowH + yScrolltop + 'px'; } else if (document.documentElement && document.documentElement.clientWidth) { calcW = document.documentElement.clientWidth/2 - windowW + 'px'; calcH = document.documentElement.clientHeight/2 - windowH + yScrolltop + 'px'; } else if(document.body.clientHeight && document.body.clientWidth) { calcW = document.body.clientWidth/2 - windowW + 'px'; calcH = document.body.clientHeight/2 - windowH + yScrolltop + 'px'; } else { return false; } //if(yScrolltop == 0) calcH = (calcH.indexOf("px")!=-1)?((event.clientY-windowH)+"px"):(event.clientY - windowH); //console.log(event.clientY); calcH = (calcH.indexOf("px")!=-1)?((event.clientY-windowH+yScrolltop)+"px"):(event.clientY - windowH + yScrolltop); this.window.style.top = calcH; this.window.style.left = calcW; }, currentTab: "contact", currentSection: "main", toggle: function( section, tab ) { Api.get(DDC.CarFlixWindow.currentSection).style.display = "none"; Api.get(section).style.display = "block"; DDC.CarFlixWindow.currentSection = section; if( tab != '' ) { Api.get(DDC.CarFlixWindow.currentTab).style.display = "none"; Api.get(tab).style.display = "block"; DDC.CarFlixWindow.currentTab = tab; } }, checkPrice: function( s ) { Api.debug( "checkPrice - s:" + s ); if( s == undefined || s == "" || s == "$0.00" || s == "0.0") { return 'Please Call for Price'; //was Please Call } else { s = s.split(".")[0]; return s.replace(/(\d+)(\d{3})/,'$$$1'+','+'$2'); } }, checkMileage: function( s, prepend ) { Api.debug( "checkMileage - s:" + s ); if( s == undefined || s == "" || s == "0" ) { return ''; } else { var unitOfMeasurement = ''; if (this.countryCode != "US" ) { //if we end up doing this often, we could create a DDC.util object to reuse this kind of logic unitOfMeasurement = "km"; } else { unitOfMeasurement = "miles"; } return prepend + s.replace(/(\d+)(\d{3})/,'$1'+','+'$2') + " " + unitOfMeasurement; } }, submitSuccessful : function(obj) { DDC.CarFlixWindow.toggle("main","confirmation"); } }; window.DDC = window.DDC || {}; window.DDC.CarFlixWindow = CarFlixWindow; })();