//  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 tbl = document.getElementById('vinRow').parentNode;

        var lastrow = tbl.rows.length;
        var row = tbl.insertRow(lastrow);

        var cell = row.insertCell(0);
        cell.innerHTML="<br/><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>";
    }
}

// Initialization function
function initvevo()
{
// var VIN = document.getElementById('vinValue').innerHTML.replace(' ','').replace('&nbsp;','');
VIN = vinParam.replace('&vin=','');
var obj=new JSONscriptRequest('http://www.getauto.com/checkvevo.php?vin='+VIN);
obj.buildScriptTag();
obj.addScriptTag();
}

// Event handler
window.onload=function(){ init(); initvevo(); };

