//  Script to insert a vevo logo into a Cobalt Vehicle listing page
//  Written by Jamie Ahmed
//  © 2007 Dealer Specialties

var VIN = "";

function JSONscriptRequest(fullUrl) {
    this.fullUrl = fullUrl; 
    // Keep IE from caching requests
    this.noCacheIE = '&noCacheIE=' + (new Date()).getTime();
    // Get the DOM location to put the script tag
    this.headLoc = document.getElementsByTagName("head").item(0);
    // Generate a unique script tag id
    this.scriptId = 'scriptId' + JSONscriptRequest.scriptCounter++;
}

// Static script ID counter
JSONscriptRequest.scriptCounter = 1;

// buildScriptTag method
JSONscriptRequest.prototype.buildScriptTag = function () {

    // Create the script tag
    this.scriptObj = document.createElement("script");
    
    // Add script object attributes
    this.scriptObj.setAttribute("type", "text/javascript");
    this.scriptObj.setAttribute("src", this.fullUrl + this.noCacheIE);
    this.scriptObj.setAttribute("id", this.scriptId);
}
 
// removeScriptTag method
JSONscriptRequest.prototype.removeScriptTag = function () {
    // Destroy the script tag
    this.headLoc.removeChild(this.scriptObj);  
}

// addScriptTag method
JSONscriptRequest.prototype.addScriptTag = function () {
    // Create the script tag
    this.headLoc.appendChild(this.scriptObj);
}

// Inserts the logo/link
function checkvevo(data)
{
    if(data.hasvevo.value==1)
    {
        var theDiv = document.getElementById('callsToAction');

        //var lastrow = theDiv.childNodes.length;

        //var cell = row.insertCell(0);
        theDiv.innerHTML+="<center><div><a href=\"javascript: void 0;\" onclick=\"javascript:window.open('http://videos.vehicledata.com/vevo.cfm?vin="+VIN+"&dataPartner=1691','vevowin','directories=no,status=no,location=no,menubar=no,toolbar=no,resizable=no,scrollbars=no,height=270,width=320');if(window.vevowin)window.focus();\"><img src=\"http://gaimgs.getauto.com/imgs/design/ag/gabandit/algraphics/lexusvevo.gif\" border=\"0\" /></a></div></center>";
    }
}

// Initialization function
function initvevo()
{
if(navigator.appName.lastIndexOf("Explorer") != -1)
{
VIN = document.getElementById('VINCNT').childNodes[0].childNodes[0].childNodes[0].childNodes[1].innerHTML; //.innerHTML.replace(' ','').replace('&nbsp;','');
}
else if(navigator.appName.lastIndexOf("Netscape") != -1)
{
VIN = document.getElementById('VINCNT').childNodes[1].childNodes[0].childNodes[0].childNodes[3].innerHTML;//.innerHTML.replace(' ','').replace('&nbsp;','');
}
var obj=new JSONscriptRequest('http://www.getauto.com/checkvevo.php?vin='+VIN);
obj.buildScriptTag();
obj.addScriptTag();
}

// Event handler
window.onload=function(){ init(); initvevo(); };