//Universal image swap function
function swapImg(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 getMSRP(argVehicle, argModel) {

    if( argModel!="") {
        for( i=0; i<models.length; i++ ) {
            if( models[i].vehicle == argVehicle && models[i].model == argModel && models[i].msrp != "" ) {

                if (models[i].is_reveal)
                    return "Pricing Available Later This Year";

                return 'MSRP* starting at: $' + models[i].msrp; // do any additional formatting here.
            }
        }
        return "Please see your dealer for pricing.";
    } else {
        var start=null, end=null, i=0;

        for( i=0; i<models.length; i++ ) {
            if( models[i].vehicle == argVehicle ) {
                if (start==null) {
                    start = i;
                } else {
                    end = i;
                }
            }
        }
        if (models[start].is_reveal)
            return "Pricing Available Later This Year";

        if (models[start].msrp == ""){
            return "Pricing available soon.";
        }
        if( start != end ) {
            return "MSRP* starting at: $" + models[start].msrp;
        } else {
            return "Pricing available soon.";
        }
    }
}

//function to get msrp ONLY for model
function getMSRPonly(aMI){for( i=0; i<models.length; i++ ){if(models[i].id == aMI){return  models[i].msrp;}}return "";}

//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;}}}}

//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 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 on sites prior to 3.7.05
function flashTracking(lid, pos, argPN){
  var curPN = hbx.pn +"+-+"+argPN;
  var newPN = curPN.replace(/\s/g,"+");
  if (argPN){
    _hbSet('n',newPN);
  }
  trackNamedHit(lid, pos);
}

// Flash link tracking code
function flashLinkTracking(argPN, argMLC, argLid, argLpos, argHEC){
  // Sets current page name.  if argPN has a value it will be added to hbx.pn which is set in the .html page.
  var curPN = (argPN=="")?hbx.pn:hbx.pn + "+-+" + argPN;
  // variables curPN | argLid | newLpos - allow only alphanumeric, spaces, "+" and hypens and then it strips out spaces and makes them "+".
  var newPN = curPN.replace(/[^a-zA-Z0-9,\s,+,-]/g,'').replace(/\s+/g,"+");
  var newLid = argLid.replace(/[^a-zA-Z0-9,\s,+,-]/g,'').replace(/\s+/g,"+");
  var newLpos = argLpos.replace(/[^a-zA-Z0-9,\s,+,-]/g,'').replace(/\s+/g,"+");
  var newMLC = (argMLC=="" || argMLC=="undefined")?hbx.mlc:argMLC;

  // Gateway variables are being set for WSS and then sent
    _hbSet('n', newPN);
    _hbSet('vcon', newMLC);
    _hbSet('lid', newLid);
    _hbSet('lpos', newLpos);
    _hbSet('hec', argHEC);
    _hbSend();
}

// Flash page view tracking
function flashPageTracking(argPN, argMLC, argGP){
  // Sets current page name.
  var curPN = hbx.pn +"+-+" + argPN;
 // curPN - allows only alphanumeric, spaces, "+" and hypens and then it strips out spaces and makes them "+".
  var newPN = curPN.replace(/[^a-zA-Z0-9,\s,+,-]/g,'').replace(/\s+/g,"+");
  var stem = location.protocol + '\/\/' + location.host + '\/' + argPN.toLowerCase();
  var newGP = argGP.toLowerCase();
  var newMLC = (argMLC=="" || argMLC=="undefined")?hbx.mlc:argMLC;

    // Gateway variables are being set for WSS and then sent
    _hbSet('n', newPN);
    _hbSet('vcon', newMLC);
   // custom variables
    _hbSet('cv.c21', stem);
    _hbSet('cv.c22', hbx.hc22);
  // The page is set as a goal page if "y" is passed to argGP
  if (newGP == "y"){
    _hbSet('gp','LAST');
    _hbSet('gn',argPN);
  }
  _hbSend();
}

//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;

function askWin(f) {
    if( f ) {
        f.target = "_self";
        if( f.ask.value == "Type question or keyword"   || 
		    f.ask.value == "Type a question or keyword" ||
		    f.ask.value == "Enter question or keyword"  || 
			f.ask.value == "Enter a question or keyword"   )
		{
			f.ask.value = ""; 
		} 
        if( f.ask.value.replace(/^\s+|\s+$/g,'') == "" ) {
            alert( "You must type a keyword in the space provided and then click \"Go\" to begin your search." );
            return false;
        } else {
            flashLinkTracking('', '', 'Search+Success', 'Search+Validation', 1);
            return true;
        }
    }
}

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 == "Enter Zip" || z == "Enter ZIP" || !z || z == "" || z.length == 0 )
		return true;
	alert( "Please check your zipcode for accuracy and try again." );
	return false;
}
