//Begin auto tab script

var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len, e) {
var keyCode = (isNN) ? e.which : e.keyCode; 
var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
if(input.value.length >= len && !containsElement(filter,keyCode)) {
input.value = input.value.slice(0, len);
input.form[(getIndex(input)+1) % input.form.length].focus();
}
function containsElement(arr, ele) {
var found = false, index = 0;
while(!found && index < arr.length)
if(arr[index] == ele)
found = true;
else
index++;
return found;
}
function getIndex(input) {
var index = -1, i = 0, found = false;
while (i < input.form.length && index == -1)
if (input.form[i] == input)index = i;
else i++;
return index;
}
return true;
}

//  End auto tab script

// Start numerals only script
	function disableKey(e) 
		{var key; 
			if(window.event) 
	          key = window.event.keyCode;     //IE 
	     	else 
	          key = e.which;     //firefox 
	  		if((key  < 48 || key > 57)) 
	          return false; 
	     	else 
	          return true; 
		} 
// End numerals only script

// email validator
	function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false
		 }

 		 return true					
	}	
// end email validator
function swap_button(image,swap_image){
	image.src=swap_image;
}

function hide_all(){
	if (document.getElementById("popup_div")) {
		document.getElementById("popup_div").style.display="none";
	}
}
function show_cars(){
	document.getElementById("mb_Trucks").style.display="none";
	document.getElementById("mb_Suvs").style.display="none";
	document.getElementById("mb_Hybrids").style.display="none";
	document.getElementById("mb_Cars").style.display="block";
}
function show_trucks(){
	document.getElementById("mb_Cars").style.display="none";
	document.getElementById("mb_Suvs").style.display="none";
	document.getElementById("mb_Hybrids").style.display="none";
	document.getElementById("mb_Trucks").style.display="block";
}
function show_suvs(){
	document.getElementById("mb_Trucks").style.display="none";
	document.getElementById("mb_Cars").style.display="none";
	document.getElementById("mb_Hybrids").style.display="none";
	document.getElementById("mb_Suvs").style.display="block";
}
function show_hybrids(){
	document.getElementById("mb_Trucks").style.display="none";
	document.getElementById("mb_Cars").style.display="none";
	document.getElementById("mb_Suvs").style.display="none";
	document.getElementById("mb_Hybrids").style.display="block";
}
function show_ncars(){
	document.getElementById("mb_Trucks").style.display="none";
	document.getElementById("mb_Suvs").style.display="none";
	document.getElementById("mb_Cars").style.display="block";
}
function show_ntrucks(){
	document.getElementById("mb_Cars").style.display="none";
	document.getElementById("mb_Suvs").style.display="none";
	document.getElementById("mb_Trucks").style.display="block";
}
function show_nsuvs(){
	document.getElementById("mb_Trucks").style.display="none";
	document.getElementById("mb_Cars").style.display="none";
	document.getElementById("mb_Suvs").style.display="block";
}

function swapbox_search() { 
	var NAME = document.getElementById("swap_box"); 
	NAME.className="swap_box_search";
	document.swap_form.Form_Type.value="Search";
	document.getElementById("search_container").style.display ="block";
	document.getElementById("quote_container").style.display ="none";
}
function swapbox_quote() { 
	var NAME = document.getElementById("swap_box");
	NAME.className="swap_box_quote";
	document.swap_form.Form_Type.value="Quote";
	document.getElementById("search_container").style.display ="none";
	document.getElementById("quote_container").style.display ="block";
} 
//Begin auto tab script

var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len, e) {
var keyCode = (isNN) ? e.which : e.keyCode; 
var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
if(input.value.length >= len && !containsElement(filter,keyCode)) {
input.value = input.value.slice(0, len);
input.form[(getIndex(input)+1) % input.form.length].focus();
}
function containsElement(arr, ele) {
var found = false, index = 0;
while(!found && index < arr.length)
if(arr[index] == ele)
found = true;
else
index++;
return found;
}
function getIndex(input) {
var index = -1, i = 0, found = false;
while (i < input.form.length && index == -1)
if (input.form[i] == input)index = i;
else i++;
return index;
}
return true;
}

//  End auto tab script

// Start numerals only script
	function disableKey(e) 
		{var key; 
			if(window.event) 
	          key = window.event.keyCode;     //IE 
	     	else 
	          key = e.which;     //firefox 
	  		if((key  < 48 || key > 57)) 
	          return false; 
	     	else 
	          return true; 
		} 
// End numerals only script

// email validator
	function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false
		 }

 		 return true					
	}	
// end email validator

function swap_box_submit(){
	if (document.swap_form.Form_Type.value=="Quote"){
		var themessage = "There was an error in your quote submission:\n ";
		if (document.swap_form.Applicant1_Name.value.length == 0){
			themessage = themessage + "\n- Name cannot be blank!";
		}
		if (document.swap_form.Applicant1_Phone_1_1.value.length != 3 || document.swap_form.Applicant1_Phone_1_2.value.length != 3 || document.swap_form.Applicant1_Phone_1_3.value.length != 4) {
			themessage = themessage + "\n- Phone is invalid!";
		}			
		if (echeck(document.swap_form.Applicant1_Email.value)==false){
			themessage = themessage + "\n- Email is invalid!";
		}
		if (themessage == "There was an error in your quote submission:\n ") {
			document.swap_form.submit();
		}
		else {
			alert(themessage);
   		}
	}
	else{
		document.swap_form.submit();
	}
}

function swap_box_submit_esp(){
	if (document.swap_form.Form_Type.value=="Quote"){
		var themessage = "Había un error en su sumisión de la cotización:\n ";
		if (document.swap_form.Applicant1_Name.value.length == 0){
			themessage = themessage + "\n- ˇEl nombre no puede estar en blanco!";
		}
		if (document.swap_form.Applicant1_Phone_1_1.value.length != 3 || document.swap_form.Applicant1_Phone_1_2.value.length != 3 || document.swap_form.Applicant1_Phone_1_3.value.length != 4) {
			themessage = themessage + "\n- ˇEl teléfono es inválido!";
		}			
		if (echeck(document.swap_form.Applicant1_Email.value)==false){
			themessage = themessage + "\n- ˇEl email es inválido!";
		}
		if (themessage == "Había un error en su sumisión de la cotización:\n ") {
			document.swap_form.submit();
		}
		else {
			alert(themessage);
   		}
	}
	else{
		document.swap_form.submit();
	}
}

function New_Search_Swap(){
	document.getElementById("New_Search_Makes").style.display ="block";
	document.getElementById("New_Search_Models").style.display ="block";
	document.getElementById("Used_Search_Makes").style.display ="none";
	document.getElementById("Used_Search_Models").style.display ="none";
}

function Used_Search_Swap(){
	document.getElementById("New_Search_Makes").style.display ="none";
	document.getElementById("New_Search_Models").style.display ="none";
	document.getElementById("Used_Search_Models").style.display ="block";
	document.getElementById("Used_Search_Makes").style.display ="block";
}

function quick_quote_submit(){
	var themessage = "There was an error in your quote submission:\n ";
	if (document.Quick_Quote.Name.value.length == 0){
		themessage = themessage + "\n- Name cannot be blank!";
	}
	if (echeck(document.Quick_Quote.Email.value)==false){
		themessage = themessage + "\n- Email is invalid!";
	}
	if (document.Quick_Quote.Phone_1.value.length != 3 || document.Quick_Quote.Phone_2.value.length != 3 || document.Quick_Quote.Phone_3.value.length != 4) {
		themessage = themessage + "\n- Phone is invalid!";
	}			
	if (themessage == "There was an error in your quote submission:\n ") {
		document.Quick_Quote.submit();
	}
	else {
		alert(themessage);
  	}
}

function contact_form_submit(){
	var themessage = "There was an error in your contact information:\n ";
	if (document.contact_form.Name.value.length == 0){
		themessage = themessage + "\n- Please enter your name.";
	}
	if (echeck(document.contact_form.Email.value)==false){
		themessage = themessage + "\n- Please enter a valid email address.";
	}
	if (document.contact_form.Comments.value.length == 0){
		themessage = themessage + "\n- Please ask your question.";
	}
	if (themessage == "There was an error in your contact information:\n ") {
		document.contact_form.submit();
	}
	else {
		alert(themessage);
  	}
}

function showCopyright() {
	var CopyrightWin = open('', 'Help', 'directories=no,location=no,menubar=no,status=no,titlebar=no,toolbar=no,scrollbars=no,width=400,height=150,resizable=no');
		CopyrightWin.document.writeln('<html><head><title>COPYRIGHT/TRADEMARK INFORMATION</title></head><body onLoad="window.setTimeout(\'window.close()\', 10000)">');
		CopyrightWin.document.writeln('<span style="text-align: center; color: #8A8A8A; font-family: Verdana; font-size: 12pt">');
		CopyrightWin.document.writeln('<b>COPYRIGHT/TRADEMARK INFORMATION</b>');
		CopyrightWin.document.writeln('</span>');
		CopyrightWin.document.writeln('<span style="text-align: center; color: #8A8A8A; font-family: Verdana; font-size: 8pt">');
		CopyrightWin.document.writeln('<p>The Nissan names, logos, product names, feature names, and slogans are trademarks owned by or licensed to Nissan Motor Co. Ltd. and/or Nissan North America, Inc. 2002-2008 Nissan North America, Inc. All rights reserved. Materials contained on this Web site may not be used or reproduced without written permission from Nissan North America, Inc.<BR></p>');
		CopyrightWin.document.writeln('</span></body></html>');
		CopyrightWin.document.close();
		CopyrightWin.focus();
}
function showcase_toy_showcars(){
	var div_1 = document.getElementById("toyota_cars");
	var div_2 = document.getElementById("toyota_trucks");
	div_1.style.display="block";
	div_2.style.display="none";
}
function showcase_toy_showtrucks(){
	var div_1 = document.getElementById("toyota_cars");
	var div_2 = document.getElementById("toyota_trucks");
	div_1.style.display="none";
	div_2.style.display="block";
}
function New_Search_Swap_x(){
	document.getElementById("New_Search_Makes_div").style.display ="block";
	document.getElementById("New_Search_Models_div").style.display ="block";
	document.getElementById("Used_Search_Makes_div").style.display ="none";
	document.getElementById("Used_Search_Models_div").style.display ="none";
}
function Used_Search_Swap_x(){
	document.getElementById("New_Search_Makes_div").style.display ="none";
	document.getElementById("New_Search_Models_div").style.display ="none";
	document.getElementById("Used_Search_Models_div").style.display ="block";
	document.getElementById("Used_Search_Makes_div").style.display ="block";
}
function New_Quote_Swap_x(){
	document.getElementById("New_Quote_Makes_div").style.display ="block";
	document.getElementById("New_Quote_Models_div").style.display ="block";
	document.getElementById("Used_Quote_Makes_div").style.display ="none";
	document.getElementById("Used_Quote_Models_div").style.display ="none";
}

function Used_Quote_Swap_x(){
	document.getElementById("New_Quote_Makes_div").style.display ="none";
	document.getElementById("New_Quote_Models_div").style.display ="none";
	document.getElementById("Used_Quote_Models_div").style.display ="block";
	document.getElementById("Used_Quote_Makes_div").style.display ="block";
}

function quick_quote_x_submit(){
	var themessage = "There was an error in your submission:\n ";
	if (document.quote_form_x.First_Name.value.length == 0){
		themessage = themessage + "\n- First Name cannot be blank.";
	}
	if (document.quote_form_x.Last_Name.value.length == 0){
		themessage = themessage + "\n- Last Name cannot be blank.";
	}
	if (document.quote_form_x.First_Name.value == "First"){
		themessage = themessage + "\n- Please fill in your First Name.";
	}
	if (document.quote_form_x.Last_Name.value == "Last"){
		themessage = themessage + "\n- Please fill in your Last Name";
	}
	if (echeck(document.quote_form_x.Email.value)==false){
		themessage = themessage + "\n- Email is invalid!";
	}
	if (document.quote_form_x.Phone_1.value.length != 3 || document.quote_form_x.Phone_2.value.length != 3 || document.quote_form_x.Phone_3.value.length != 4) {
		themessage = themessage + "\n- Phone is invalid!";
	}
	if (themessage == "There was an error in your submission:\n ") {
		document.quote_form_x.submit();
	}
	else {
		alert(themessage);
  	}
}

function quick_quote_z_submit(){
	var themessage = "There was an error in your submission:\n ";
	if (document.quote_form_x.First_Name.value.length == 0){
		themessage = themessage + "\n- First Name cannot be blank.";
	}
	if (document.quote_form_x.Last_Name.value.length == 0){
		themessage = themessage + "\n- Last Name cannot be blank.";
	}
	if (echeck(document.quote_form_x.Email.value)==false){
		themessage = themessage + "\n- Email is invalid!";
	}
	if (document.quote_form_x.Phone.value.length == 0){
		themessage = themessage + "\n- Phone cannot be blank.";
	}
	if (themessage == "There was an error in your submission:\n ") {
		document.quote_form_x.submit();
	}
	else {
		alert(themessage);
  	}
}
	$.fn.hoverIntent = function(f,g) {
		var cfg = {
			sensitivity: 7,
			interval: 100,
			timeout: 0
		};
		cfg = $.extend(cfg, g ? { over: f, out: g } : f );
		var cX, cY, pX, pY;
		var track = function(ev) {
			cX = ev.pageX;
			cY = ev.pageY;
		};
		var compare = function(ev,ob) {
			ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
			if ( ( Math.abs(pX-cX) + Math.abs(pY-cY) ) < cfg.sensitivity ) {
				$(ob).unbind("mousemove",track);
				ob.hoverIntent_s = 1;
				return cfg.over.apply(ob,[ev]);
			} else {
				pX = cX; pY = cY;
				ob.hoverIntent_t = setTimeout( function(){compare(ev, ob);} , cfg.interval );
			}
		};
		var delay = function(ev,ob) {
			ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
			ob.hoverIntent_s = 0;
			return cfg.out.apply(ob,[ev]);
		};
		var handleHover = function(e) {
			var p = (e.type == "mouseover" ? e.fromElement : e.toElement) || e.relatedTarget;
			while ( p && p != this ) { try { p = p.parentNode; } catch(e) { p = this; } }
			if ( p == this ) { return false; }
			var ev = jQuery.extend({},e);
			var ob = this;
			if (ob.hoverIntent_t) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); }
			if (e.type == "mouseover") {
				pX = ev.pageX; pY = ev.pageY;
				$(ob).bind("mousemove",track);
				if (ob.hoverIntent_s != 1) { ob.hoverIntent_t = setTimeout( function(){compare(ev,ob);} , cfg.interval );}
			} else {
				$(ob).unbind("mousemove",track);
				if (ob.hoverIntent_s == 1) { ob.hoverIntent_t = setTimeout( function(){delay(ev,ob);} , cfg.timeout );}
			}
		};
		return this.mouseover(handleHover).mouseout(handleHover);
	};


/*
 * Superfish v1.4.8 - jQuery menu widget
 * Copyright (c) 2008 Joel Birch
 *
 * Dual licensed under the MIT and GPL licenses:
 * 	http://www.opensource.org/licenses/mit-license.php
 * 	http://www.gnu.org/licenses/gpl.html
 *
 * CHANGELOG: http://users.tpg.com.au/j_birch/plugins/superfish/changelog.txt
 */

$.fn.superfish = function(op){

		var sf = $.fn.superfish,
			c = sf.c,
			$arrow = $(['<span class="',c.arrowClass,'"> &#187;</span>'].join('')),
			over = function(){
				var $$ = $(this), menu = getMenu($$);
				clearTimeout(menu.sfTimer);
				$$.showSuperfishUl().siblings().hideSuperfishUl();
			},
			out = function(){
				var $$ = $(this), menu = getMenu($$), o = sf.op;
				clearTimeout(menu.sfTimer);
				menu.sfTimer=setTimeout(function(){
					o.retainPath=($.inArray($$[0],o.$path)>-1);
					$$.hideSuperfishUl();
					if (o.$path.length && $$.parents(['li.',o.hoverClass].join('')).length<1){over.call(o.$path);}
				},o.delay);	
			},
			getMenu = function($menu){
				var menu = $menu.parents(['ul.',c.menuClass,':first'].join(''))[0];
				sf.op = sf.o[menu.serial];
				return menu;
			},
			addArrow = function($a){ $a.addClass(c.anchorClass).append($arrow.clone()); };
			
		return this.each(function() {
			var s = this.serial = sf.o.length;
			var o = $.extend({},sf.defaults,op);
			o.$path = $('li.'+o.pathClass,this).slice(0,o.pathLevels).each(function(){
				$(this).addClass([o.hoverClass,c.bcClass].join(' '))
					.filter('li:has(ul)').removeClass(o.pathClass);
			});
			sf.o[s] = sf.op = o;
			
			$('li:has(ul)',this)[($.fn.hoverIntent && !o.disableHI) ? 'hoverIntent' : 'hover'](over,out).each(function() {
				if (o.autoArrows) addArrow( $('>a:first-child',this) );
			})
			.not('.'+c.bcClass)
				.hideSuperfishUl();
			
			var $a = $('a',this);
			$a.each(function(i){
				var $li = $a.eq(i).parents('li');
				$a.eq(i).focus(function(){over.call($li);}).blur(function(){out.call($li);});
			});
			o.onInit.call(this);
			
		}).each(function() {
			var menuClasses = [c.menuClass];
			if (sf.op.dropShadows  && !($.browser.msie && $.browser.version < 7)) menuClasses.push(c.shadowClass);
			$(this).addClass(menuClasses.join(' '));
		});
	};

	var sf = $.fn.superfish;
	sf.o = [];
	sf.op = {};
	sf.IE7fix = function(){
		var o = sf.op;
		if ($.browser.msie && $.browser.version > 6 && o.dropShadows && o.animation.opacity!=undefined)
			this.toggleClass(sf.c.shadowClass+'-off');
		};
	sf.c = {
		bcClass     : 'sf-breadcrumb',
		menuClass   : 'sf-js-enabled',
		anchorClass : 'sf-with-ul',
		arrowClass  : 'sf-sub-indicator',
		shadowClass : 'sf-shadow'
	};
	sf.defaults = {
		hoverClass	: 'sfHover',
		pathClass	: 'overideThisToUse',
		pathLevels	: 1,
		delay		: 800,
		animation	: {opacity:'show'},
		speed		: 'normal',
		autoArrows	: true,
		dropShadows : true,
		disableHI	: false,		// true disables hoverIntent detection
		onInit		: function(){}, // callback functions
		onBeforeShow: function(){},
		onShow		: function(){},
		onHide		: function(){}
	};
	$.fn.extend({
		hideSuperfishUl : function(){
			var o = sf.op,
				not = (o.retainPath===true) ? o.$path : '';
			o.retainPath = false;
			var $ul = $(['li.',o.hoverClass].join(''),this).add(this).not(not).removeClass(o.hoverClass)
					.find('>ul').hide().css('visibility','hidden');
			o.onHide.call($ul);
			return this;
		},
		showSuperfishUl : function(){
			var o = sf.op,
				sh = sf.c.shadowClass+'-off',
				$ul = this.addClass(o.hoverClass)
					.find('>ul:hidden').css('visibility','visible');
			sf.IE7fix.call($ul);
			o.onBeforeShow.call($ul);
			$ul.animate(o.animation,o.speed,function(){ sf.IE7fix.call($ul); o.onShow.call($ul); });
			return this;
		}
	});
/* Copyright (c) 2006 Brandon Aaron (http://brandonaaron.net)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) 
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 *
 * $LastChangedDate: 2007-06-19 20:25:28 -0500 (Tue, 19 Jun 2007) $
 * $Rev: 2111 $
 *
 * Version 2.1
 */
(function($){$.fn.bgIframe=$.fn.bgiframe=function(s){if($.browser.msie&&parseInt($.browser.version)<=6){s=$.extend({top:'auto',left:'auto',width:'auto',height:'auto',opacity:true,src:'javascript:false;'},s||{});var prop=function(n){return n&&n.constructor==Number?n+'px':n;},html='<iframe class="bgiframe"frameborder="0"tabindex="-1"src="'+s.src+'"'+'style="display:block;position:absolute;z-index:-1;'+(s.opacity!==false?'filter:Alpha(Opacity=\'0\');':'')+'top:'+(s.top=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderTopWidth)||0)*-1)+\'px\')':prop(s.top))+';'+'left:'+(s.left=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderLeftWidth)||0)*-1)+\'px\')':prop(s.left))+';'+'width:'+(s.width=='auto'?'expression(this.parentNode.offsetWidth+\'px\')':prop(s.width))+';'+'height:'+(s.height=='auto'?'expression(this.parentNode.offsetHeight+\'px\')':prop(s.height))+';'+'"/>';return this.each(function(){if($('> iframe.bgiframe',this).length==0)this.insertBefore(document.createElement(html),this.firstChild);});}return this;};if(!$.browser.version)$.browser.version=navigator.userAgent.toLowerCase().match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/)[1];})(jQuery);
