//Universal Window Function Type "yes" or "no" for scrollBar
  function flexWin(aU,aS,aW,aH,aN,aO,aX,aY,aC){
   var wN = aN ? aN : "myWin" + nocacheRandom();
   var oV = aO == "all" ? 1 : 0;
   var oS = "history="+oV+",toolbar="+oV+",location="+oV+",directories="+oV+",status="+oV+",menubar="+oV+",resizable="+oV;
   var wO = aO != "all" ? aO : oS;
   var wW = aW ? aW : 800;wO += ",width=" + wW;
   var wH = aH ? aH : 600;wO += ",height=" + wH;
   var sB = ",scrollbars="+aS;wO+=sB;
   var wX = aX ? aX :(screen.availWidth-wW)/2;wO+=",left="+wX+",screenX="+wX;
   var wY = aY ? aY :((screen.availHeight-wH)/2)-40;wO+=",top="+wY+",screenY="+wY;
   window.open(aU,wN,wO);
   aC ? window.close():"";
  }

//Universal image swapfunction
function rollover(aIN, aIS, aDA){var dA = "";if(document.layers && aDA){for( var i = 0; i < aDA.length; i++ ){dA += 'document.' + aDA[i] + '.';}eval(dA + 'document.' + aIN + '.src ="' + aIS + '";');return true;}else{document[aIN].src = aIS;}}

//function to get starting @ price for family
function getStartingAtPrice(aV){for(i=0; i<models.length; i++){if(models[i].vehicle == aV){if(models[i].msrp == ""){return "";}else{return 'MSRP Starting at $' + models[i].msrp + '<br>(excludes taxes)';}}}}

//function to get starting @ price for  homepage family
function getStartingAtPriceHome(aV){for(i=0; i<models.length; i++){if(models[i].vehicle == aV){if(models[i].msrp == ""){return "";}else{return 'MSRP Starting at $' + models[i].msrp + '**';}}}}

//Universal function to take user to a page in main window
function targetMainWindow(aU){if(window.blur){self.blur();}if (window.opener.closed){window.open(aU,"newWin");}else{window.opener.location = aU;}}

//Universal function for no cache
function nocacheRandom(){var axel = Math.random() + "";var ord = axel * 1000000000000000000;return ord;}

// generate random number within range passed in
function generateRandomNumber( argRange ) {return 1 + Math.round( Math.random() * ( argRange - 1 ) );}

//Universal function to get parameter from url srting
function getParameter(aP){var qS = new String(location.search.substring(1,location.search.length));var p = qS.split("&");var val = "";if(aP){for(i=0;i<p.length;i++){if(p[i].split( "=" )[0] == aP){val = p[i].split( "=" )[1];}}return val;}}

//Universal function to Print Page in all browsers including IE 4
var da = (document.all) ? 1 : 0;var pr = (window.print) ? 1 : 0;var mac = (navigator.userAgent.indexOf("Mac") != -1);

//Code for Flash tracking
function flashTracking(lid, pos){
    trackNamedHit(lid , pos);
    trackHit();
}

//universal popup

var wrapMsg = "";
wrapMsg += 'The contents in the current "Build Your Own" window will be erased   \n';
wrapMsg += 'and a new session will be started. Click OK to continue and restart,\n';
wrapMsg += 'or Cancel to retain the contents of the window.';
var pandeWindow = null;
var universalWindow = null;

// universal popup
function wrap(argApp, argTracking, argFamily, argModel) {

  argApp = argApp.toLowerCase();
  var sizedWin = false;
  
  //if( argApp == "cdl" ) argApp = "dealer";
  
  var launchUrl = "/bridge/index.html?";
  if( argTracking != '' ) launchUrl += argTracking + "&";
  launchUrl += "app=" + argApp + "&family=" + argFamily + "&model=" + argModel;
  
  if( argApp == "dealer" || argApp == "edmunds" || argApp == "fulfillment" || argApp == "gap" || argApp == "incentives" || argApp == "preownedinventory" ) {
    sizedWin = true;
    var winWidth = 618, winHeight = 452;
    if( argApp == "edmunds" || argApp == "gap" || argApp == "preownedinventory" ) {
      var winWidth = 790, winHeight = ( window.screen.availHeight - 130 );
    }
    var options = "resizable,scrollbars,toolbar,"
    options += "width=" + winWidth + ",height=" + winHeight;
    if( window.screen ) {
      var xPos = ( screen.availWidth - winWidth ) / 2;
      var yPos = ( ( screen.availHeight - winHeight ) / 2 ) - 40;
      options += ",left=" + xPos + ",screenX=" + xPos;
      options += ",top=" + yPos + ",screenY=" + yPos;
    }
  }
  if(sizedWin) {
    window.open( launchUrl, "universal", options );
  } else {
    window.location = launchUrl;
  }
}

function askWin() {
  var winWidth = 618, winHeight = 452;
  var options = "resizable,scrollbars,toolbar,"
    options += "width=" + winWidth + ",height=" + winHeight;
  if( window.screen ) {
      var xPos = ( screen.availWidth - winWidth ) - 20;
      var yPos = ( ( screen.availHeight - winHeight ) / 2 ) - 40;
      options += ",left=" + xPos + ",screenX=" + xPos;
      options += ",top=" + yPos + ",screenY=" + yPos;
    }
  window.open( "", "askWindow", options );
  return true;
}

var o1=0,o2=0,o3=0,o4=0,o5=0,o6=0,o7=0,o8=0,o9=0, o10=0,o11=0,o12=0;

function vehicleDropOver( i, imgSrc ) { if( navOn ) {showE( "vehicleDrop" + i ); eval( "o" + i + " = 1" );}rollover( "top" + i, imgSrc );}

function vehicleDropOut( i, imgSrc ) { if( navOn ) {eval( "o" + i + " = 0" ); setTimeout( "if( !o" + i + " ) { hideE( 'vehicleDrop" + i + "' ); rollover( 'top" + i + "', '" + imgSrc + "' ); }", 10 );} else {rollover( "top" + i,  imgSrc ); } }

var dropClosed = 1, dropOver = 0;

function shopDrop() {if( shopOn ) { if( dropClosed ) { showE( "shopToolsDrop" ); dropClosed = 0;} else {hideE( "shopToolsDrop" ); dropClosed = 1;} } else { window.location = "/purchase/index.html"; } }

function shopDropOver() { if( shopOn ) {dropOver = 0; setTimeout( "if( !dropOver ) { hideE( 'shopToolsDrop' ); dropClosed = 1; }", 10 ); } }

// img tag creator - need for Route 2003
function imgTag( i, m, map ) {var iTag = '<img src="' + i + '"'; if( m != "" ) iTag += ' border="0" usemap="#' + m  + '"'; iTag += ' />'; if( m != "" ) iTag += map; return iTag;}

//For Dealer Box Navigation
function getDealerList(argZipCode) {
 if( argZipCode.length != 5 && !isNumeric( argZipCode )) {
    alert( "Your ZIP code must be 5 digits and only contain numeric characters." );
 }else {
   alert("YOUR ZIP CODE IS SUPER. Now we give you are dealer list.")
 }
}

function isNumeric( d ) {
  var c;
  for( var i = 0; i < d.length; i++ ) {
    c = d.charAt( i );
    if(! ( c >= "0" && c <= "9" ) ) return false;
  }
  return true;
}

// exit window
function confirmNewWindow(newUrl){ window.open(newUrl, TARGET='_blank'); }

function getMSRP( argVehicle, argModel) {if( argModel != "" ) {for( i=0; i<models.length; i++ ) {if( models[i].vehicle == argVehicle && models[i].model == argModel && models[i].msrp != "" ) {return 'Starting at $' + models[i].msrp + '.00 MSRP (excludes tax)'; // do any additional formatting here.
} }return "Please see your dealer for pricing."; } else { var start; for( i=0; i<models.length; i++ ) {if( models[i].vehicle == argVehicle ) {start = i; break;} }var end;    for( i=models.length-1; i>=0; i-- ) { if( models[i].vehicle == argVehicle ) { end = i; break; } }if (models[i].msrp == ""){ return "Please see your<br>dealer for pricing.";} if( start != end ) { return "Starting at $" + models[start].msrp + ".00 <br>MSRP (excludes tax)";	} else { return "Please see your dealer for pricing."; } } }

function validateZip( argF ) {
	var z = argF.zipcode;
	var re = new RegExp('^[0-9]{5}$');
	
	if( z = z.value )
		if( z.length == 5 )
			if( z.match( re ))
				return true;
	if( z == "Zip Code" || z == "ZIP Code" || !z || z == "" || z.length == 0 )
		return true;
	alert( "Please check your zipcode for accuracy and try again." );
	return false;
}