﻿var cStart = "http://fordlabels.webview.biz/webviewhybrid/WindowSticker.aspx?vin=";
var bEnd = "&ref=VL";

var result = document.getElementById('PhotoBox400Contact').parentNode.innerHTML;
var regExp = /[A-Z0-9]{17,17}/g;
result = result.match(regExp);
result = result[0];   

//window.onload = function () {
//    document.getElementById("myiframe").src = cStart + result + bEnd;
//}

$(document).ready(function(){
	document.getElementById("myiframe").src = cStart + result + bEnd;
}) 



//------------------------------Vin Decoder -------------------------------------------------------------------------------

var dBrochure  = "http://www.foxvalleyford.com/onlinevehicle-brochures.aspx"
var modelCode = result.substring(4,7);

// Focus
if (modelCode == "P3E"|| modelCode == "P3F" || modelCode == "P3C" || modelCode == "P3H" || modelCode == "P3G" || modelCode == "P3D") {
dBrochure  = "http://noneedtohaggle.com/Ford%20Brochures/2010Brochures/2010FordFocus.pdf";
var vehicleModel = "focus"
}
// Fusion
if (modelCode == "P0G" || modelCode == "P0H" || modelCode == "P0J" || modelCode == "P0K" || modelCode == "P0C" || modelCode == "P0D") {
dBrochure  = "http://noneedtohaggle.com/Ford%20Brochures/2010Brochures/2010Fusion.pdf";
var vehicleModel = "fusion"
}
// Fusion hybrid
if (modelCode == "P0L") {
dBrochure  = "http://noneedtohaggle.com/Ford%20Brochures/2010Brochures/2010Fusion.pdf";
var vehicleModel = "fusionHybrid"
}

//Mustang
if (modelCode == "P8A" || modelCode == "P8E" || modelCode == "P8C" || modelCode == "P8F") {
dBrochure  = "http://noneedtohaggle.com/Ford%20Brochures/2010Brochures/2010Mustang.pdf";
var vehicleModel = "mustang"
}
// Taurus
if (modelCode == "P2D" || modelCode == "P2E" || modelCode == "P2H" || modelCode == "P2F" || modelCode == "P2J" || modelCode == "P2K") {
dBrochure  = "http://noneedtohaggle.com/Ford%20Brochures/2010Brochures/2010FordTaurusBrochure.pdf";
var vehicleModel = "taurus"
}
// Flex
if (modelCode == "K5B" || modelCode == "K5C" || modelCode == "K6C" || modelCode == "K5D" || modelCode == "K6D" || modelCode == "U9E") {
dBrochure  = "http://noneedtohaggle.com/Ford%20Brochures/2010Brochures/2010FordFlexBrochure.pdf";
var vehicleModel = "flex"
}
// Edge
if (modelCode == "K3G" || modelCode == "K3J" || modelCode == "K3K" || modelCode == "K3A" || modelCode == "K4G" || modelCode == "K4J" || modelCode == "K4K" || modelCode == "K4A") {
dBrochure  = "http://noneedtohaggle.com/Ford%20Brochures/2010Brochures/2010FordEdgeBrochure.pdf";
var vehicleModel = "edge"
}
// Escape
if (modelCode == "U0C" || modelCode == "U9C" || modelCode == "U0D" || modelCode == "U9D" || modelCode == "U0E" || modelCode == "U9E" || modelCode == "U4K" || modelCode == "U5K") {
dBrochure  = "http://noneedtohaggle.com/Ford%20Brochures/2010Brochures/2010EscapeBrochure.pdf";
var vehicleModel = "escape"
}
// Explorer
if (modelCode == "U6D" || modelCode == "U6E" || modelCode == "U6F" || modelCode == "U7D" || modelCode == "U7E" || modelCode == "U7F" || modelCode == "U8D" || modelCode == "U8F") {
dBrochure  = "http://noneedtohaggle.com/Ford%20Brochures/2010Brochures/2010FordExplorerBrochure.pdf";
var vehicleModel = "explorer"
}
// Explorer Sport trac
if (modelCode == "U3B" || modelCode == "U3D" || modelCode == "U5B" || modelCode == "U5D" || modelCode == "U2D") {
dBrochure  = "http://noneedtohaggle.com/Ford%20Brochures/2010Brochures/2010SportTracBrochure.pdf";
var vehicleModel = "sportTrac"
}
// Expedition
if (modelCode == "U1F" || modelCode == "K1F" || modelCode == "U1H" || modelCode == "K1H" || modelCode == "U1K" || modelCode == "K1K" || modelCode == "U1G" || modelCode == "K1G" || modelCode == "U1J" || modelCode == "K1J" || modelCode == "U2A" || modelCode == "K2A") {
dBrochure  = "http://noneedtohaggle.com/Ford%20Brochures/2010Brochures/2010ExpeditionBrochure.pdf";
var vehicleModel = "expedition"
}
// Ranger
if (modelCode == "R1A" || modelCode == "R1E" || modelCode == "R1F" || modelCode == "R4E" || modelCode == "R4F") {
dBrochure  = "http://noneedtohaggle.com/Ford%20Brochures/2010Brochures/RangerBrochure.pdf";
var vehicleModel = "ranger"
}
// Transit Connect
if (modelCode == "S6A" || modelCode == "S7A" || modelCode == "S6B" || modelCode == "S7B" || modelCode == "S7C" || modelCode == "S7D" || modelCode == "S9A" || modelCode == "S9B") {
dBrochure  = "http://noneedtohaggle.com/Ford Brochures/2010Brochures/transitConnect2010Brochure.pdf";
var vehicleModel = "transit"
}
// Ford F-150
if (modelCode == "F0C" || modelCode == "F1C" || modelCode == "F0E" || modelCode == "F1E" || modelCode == "W0C" || modelCode == "W1C" || modelCode == "W0E" || modelCode == "W1E" || modelCode == "XOC" || modelCode == "X1C" || modelCode == "X0E" || modelCode == "X1E") {
dBrochure  = "http://noneedtohaggle.com/Ford Brochures/2010Brochures/2010FordBrochure.pdf";
var vehicleModel = "f150"
}
// Ford Super Duty
if (modelCode == "F2B" || modelCode == "F3A" || modelCode == "F3B" || modelCode == "F3C" || modelCode == "F3D" || modelCode == "F3E" || modelCode == "F3F" || modelCode == "F3G" || modelCode == "F3H" || modelCode == "F4G" || modelCode == "F4H" || modelCode == "F5G" || modelCode == "F5H" || modelCode == "W2A" || modelCode == "W2B" || modelCode == "W3A" || modelCode == "W3B" || modelCode == "W3C" || modelCode == "W3D" || modelCode == "W3E" || modelCode == "W3F" || modelCode == "W3G" || modelCode == "W3H") {
dBrochure  = "http://noneedtohaggle.com/Ford%20Brochures/2010Brochures/Super-DutyBrochure.pdf";
var vehicleModel = "sd"
}


//------------------------------------Pop out Videos and box JS-------------------------------------------------------------------------

function popVideo(vid, action) {
  // This function accepts a division ID (vid), either a string or the actual
  // object itself.   vid is mandatory.   darken is optional, if it's true
  // the page will be greyed out under the video.
if (action == "close"){
vid = document.getElementById(vid);
vid.style.display='none';
}else{
  vid = document.getElementById(vid);     // Get all the videos on the page.
    // Make the video visible and set the zindex so its on top of everything else
    vid.style.zIndex='100';    
    vid.style.display='block';

    vid.style.left=Math.floor((document.documentElement.clientWidth/2)-(vid.offsetWidth/2))+'px';
}
  return false;
}

//----------------------------------Payment Calculator JS---------------------------------------------------------------------------


function calcLoan() {

var formvals = getFormVal();

var months = formvals[0];

var loan = formvals[2];
var apr = formvals[1];

var mpr = apr / 1200;
var nfactor = 0 - months;
var mofactor = Math.pow((1 + mpr), nfactor);
var bofactor = 1 - mofactor;
var tofactor = mpr / bofactor;

var payment = loan * tofactor;
var reducto = Math.round(payment*100)/100;

document.wcbubba.payment.value = "$"+reducto;

if (amortsub) showAm();

}

function getFormVal(){

          var years = parseInt(document.wcbubba.term.value);
          var loan = parseInt(document.wcbubba.loan.value);
          var apr = parseFloat(document.wcbubba.apr.value);

          if((years <= 0)||(isNaN(years))) years = 1;
          if((apr <= 0)||(isNaN(apr))) apr = .00000001;
          if((loan <= 0)||(isNaN(loan))) loan = 1;

          var mike = new Array(years,apr,loan);

         return mike;
}

//---------------------------------Key Board Short Cuts JS----------------------------------------------------------------------------


/**
 * http://www.openjs.com/scripts/events/keyboard_shortcuts/
 * Version : 1.00.A
 * By Binny V A
 * License : BSD
 */
function shortcut(shortcut,callback,opt) {
	//Provide a set of default options
	var default_options = {
		'type':'keydown',
		'propagate':false,
		'target':document
	}
	if(!opt) opt = default_options;
	else {
		for(var dfo in default_options) {
			if(typeof opt[dfo] == 'undefined') opt[dfo] = default_options[dfo];
		}
	}

	var ele = opt.target
	if(typeof opt.target == 'string') ele = document.getElementById(opt.target);
	var ths = this;

	//The function to be called at keypress
	var func = function(e) {
		e = e || window.event;

		//Find Which key is pressed
		if (e.keyCode) code = e.keyCode;
		else if (e.which) code = e.which;
		var character = String.fromCharCode(code).toLowerCase();
		
		var keys = shortcut.toLowerCase().split("+");
		//Key Pressed - counts the number of valid keypresses - if it is same as the number of keys, the shortcut function is invoked
		var kp = 0;
		
		//Work around for stupid Shift key bug created by using lowercase - as a result the shift+num combination was broken
		var shift_nums = {
			"`":"~",
			"1":"!",
			"2":"@",
			"3":"#",
			"4":"$",
			"5":"%",
			"6":"^",
			"7":"&",
			"8":"*",
			"9":"(",
			"0":")",
			"-":"_",
			"=":"+",
			";":":",
			"'":"\"",
			",":"<",
			".":">",
			"/":"?",
			"\\":"|"
		}
		//Special Keys - and their codes
		var special_keys = {
			'esc':27,
			'escape':27,
			'tab':9,
			'space':32,
			'return':13,
			'enter':13,
			'backspace':8,

			'scrolllock':145,
			'scroll_lock':145,
			'scroll':145,
			'capslock':20,
			'caps_lock':20,
			'caps':20,
			'numlock':144,
			'num_lock':144,
			'num':144,
			
			'pause':19,
			'break':19,
			
			'insert':45,
			'home':36,
			'delete':46,
			'end':35,
			
			'pageup':33,
			'page_up':33,
			'pu':33,

			'pagedown':34,
			'page_down':34,
			'pd':34,

			'left':37,
			'up':38,
			'right':39,
			'down':40,

			'f1':112,
			'f2':113,
			'f3':114,
			'f4':115,
			'f5':116,
			'f6':117,
			'f7':118,
			'f8':119,
			'f9':120,
			'f10':121,
			'f11':122,
			'f12':123
		}


		for(var i=0; k=keys[i],i<keys.length; i++) {
			//Modifiers
			if(k == 'ctrl' || k == 'control') {
				if(e.ctrlKey) kp++;

			} else if(k ==  'shift') {
				if(e.shiftKey) kp++;

			} else if(k == 'alt') {
					if(e.altKey) kp++;

			} else if(k.length > 1) { //If it is a special key
				if(special_keys[k] == code) kp++;

			} else { //The special keys did not match
				if(character == k) kp++;
				else {
					if(shift_nums[character] && e.shiftKey) { //Stupid Shift key bug created by using lowercase
						character = shift_nums[character]; 
						if(character == k) kp++;
					}
				}
			}
		}

		if(kp == keys.length) {
			callback(e);

			if(!opt['propagate']) { //Stop the event
				//e.cancelBubble is supported by IE - this will kill the bubbling process.
				e.cancelBubble = true;
				e.returnValue = false;

				//e.stopPropagation works only in Firefox.
				if (e.stopPropagation) {
					e.stopPropagation();
					e.preventDefault();
				}
				return false;
			}
		}
	}

	//Attach the function with the event	
	if(ele.addEventListener) ele.addEventListener(opt['type'], func, false);
	else if(ele.attachEvent) ele.attachEvent('on'+opt['type'], func);
	else ele['on'+opt['type']] = func;
	
}

var w1 = "http://fordlabels.webview.biz/webviewhybrid/WindowSticker.aspx?vin=";
var w2 = "&ref=VL"

var i1 = "https://www.d2d.dealerconnection.com/Common/Server/Utility/invoice_main.asp?pacode=01545&vl=F4508&vin=";
var i2 = "&n=Fox Valley Ford Inc&p=(630) 907-3100&A=0"

var v1 = "https://w2k3.ci.dealerconnection.com/smartvincent/home/default.asp?DCPVIN="
var v2 = "&referrer=vehiclelocator&DCPLanguage=E"
