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);
  	}
}
