function doModel2(modelName) {
  document.mainform.elements[0].value=modelName;
  document.mainform.submit();
}
function doModel(modelName) {
  document.mainform.elements[3].value="config";
  document.mainform.elements[3].name="target";
  doModel2(modelName);
}



function shouldPopup() {
  if (document.cookie.indexOf("fdSSPopup=1") >= 0) {
    return false;
  }
  setCookie("fdSSPopup","1","/");
  return true;
}
function setCookie(name, value, path ) {
  var newCookie = name + "=" + escape(value) +
      ((path) ? "; path=" + path : "");
  document.cookie = newCookie;
}

// Object for holding the vehicle info, and the array to hold them.
// the array will get populated by the using page.
var vehicleList = new Array();
function VehicleInfo(price,priceMax,priceMin,modelNames,modelImages,qqLinks)
{
  this.price = price;
  this.priceMax = priceMax;
  this.priceMin = priceMin;
  this.modelNames = modelNames;
  this.modelImages = modelImages;
  this.qqLinks = qqLinks;
}
var currentModel = "";
var jsArrowURL;

//This function is used to point to the function, whose image is loaded in the start page, as the default image.
function doNameRolloverRootStart(modelTokenName)
{
    //Check if the model name is not null, then call the function to show the pointer in front of that model, at loading time.
    if (modelTokenName != "" && modelTokenName != null)
    {
        doNameRolloverRoot(modelTokenName);
    }
    return;
}

function doNameRolloverRoot(modelName){
  // do null checks here
  if ( document["modelImg"] == null || document[modelName] == null || vehicleList[modelName] == null ) {
    return;
  }

  document["modelImg"].src = vehicleList[modelName].modelImages;
  document["modelImg"].alt = vehicleList[modelName].modelNames;
  document[modelName].src = jsArrowURL;
  document[modelName].width = 13;
  document[modelName].height = 11;

  if(document[currentModel] != null && currentModel != modelName){
    document[currentModel].src = 'null.gif';
  }
  currentModel = modelName;
  
  var mName = document.getElementById("name");
  var msrp = document.getElementById("price");
  var msrptext = getString('Model~baseMSRP') + vehicleList[modelName].priceMin + " - " + vehicleList[modelName].priceMax;
  if(msrp != null)
    {msrp.innerHTML = msrptext;}
  var mNametext = "20" + modelName.substring(0,2) + " " + vehicleList[modelName].modelNames;
  if(mName != null)
    {mName.innerHTML = mNametext;}
}

function doNameRolloverType(modelName){
  // do null checks here
  if ( document["modelImg"] == null || vehicleList[modelName] == null ) {
    return;
  }

  document["modelImg"].src = vehicleList[modelName].modelImages;
  var mName = document.getElementById("name");
  var msrp = document.getElementById("price");
  var msrptext = getString('Model~baseMSRP') + vehicleList[modelName].priceMin + " - " + vehicleList[modelName].priceMax;
  if(msrp != null)
    {msrp.innerHTML = msrptext;}
  var mNametext = "20" + modelName.substring(0,2) + " " + vehicleList[modelName].modelNames;
  if(mName != null)
    {mName.innerHTML = mNametext;}
  var link = document.getElementById("qqLink");
  if(link != null)
    {link.href = vehicleList[modelName].qqLinks;}
}

function doNameRolloverModel(modelName){
  // do null checks here
  if ( document["modelImg"] == null || vehicleList[modelName] == null ) {
    return;
  }

  document["modelImg"].src = vehicleList[modelName].modelImages;
  var mName = document.getElementById("name");
  var msrp = document.getElementById("price");
  var mNametext = modelName.substring(0,4) + " " + vehicleList[modelName].modelNames;
  var msrptext = getString('Model~baseMSRP') + vehicleList[modelName].price;
  if(msrp != null)
    {msrp.innerHTML = msrptext;}
  if(mName != null)
    {mName.innerHTML = mNametext;}
}

function doNameRolloverTrim(modelName){
  // do null checks here
  if ( document["modelImg"] == null || vehicleList[modelName] == null ) {
    return;
  }

  document["modelImg"].src = vehicleList[modelName].modelImages;
  var msrp = document.getElementById("price");
  var msrptext = getString('Model~baseMSRP') + vehicleList[modelName].price;
  if(msrp != null)
    {msrp.innerHTML = msrptext;}
}

function fetchImage(imageName){
  img = new Image();
  img.src = imageName;
  return img.src;
}

function doProduct(modelName, index) {
    var sZip = captureZipCode();
    if (!validateZip(sZip)) {
            alert(getString('forddirect_js~InvalidZipCode'));
    } else {
        document.mainform.elements[5].value=sZip;       
        document.mainform.elements[4].value=index;
        document.mainform.elements[4].name='selectProduct';
        
        doModel(modelName);
    }
}

//Returns a random number between 1 and number
function rand(number) {
   return Math.ceil(Math.random()*number);
};




