/*
Developer: Steve Curry
Developed on: November: 5, 2007
Purpose: This javascript contains general JS functions which 
are required through the website.
Mostly file contains form validation rules.
version 1.6
*/

/* Preloading of images for the build/research page tabs */
var rules=new Array();
if (document.images)
{
	img0 = new Image(10,20);
	img1 = new Image(10,20);
	img2 = new Image(10,20);
	img3 = new Image(10,20);
	img4 = new Image(10,20);
	img5 = new Image(10,20);
	img6 = new Image(10,20);
	img7 = new Image(10,20);
	img8 = new Image(10,20);
	img0.src = "VF/images/research/tabconsumerinfo_i.gif";
	img1.src = "VF/images/research/tabconsumerinfo_a.gif";
	img2.src = "VF/images/research/tabtechnicalspec_i.gif";
	img3.src = "VF/images/research/tabtechnicalspec_a.gif";
	img4.src = "VF/images/research/tabstandardoptions_i.gif";
	img5.src = "VF/images/research/tabstandardoptions_a.gif";
	img6.src = "VF/images/research/colors_a.gif";
	img7.src = "VF/images/research/options_a.gif";
	img8.src = "VF/images/research/quote_a.gif";
}

/* function used to enable/disabled research/build page tabs */
function enableDisable(activeTab, activeImage)
{
	document.getElementById("colors").style.display = "none";	
	document.getElementById("options").style.display = "none";	
	document.getElementById("quote").style.display = "none";	
	
	document.getElementById("consumerInfo").style.display = "none";	
	document.getElementById("technicalSpec").style.display = "none";		
	document.getElementById("standardOptions").style.display = "none";	

	document.images["colorsTab"].src = "VF/images/research/colors.gif";
	document.images["optionsTab"].src = "VF/images/research/options.gif";
	document.images["quoteTab"].src = "VF/images/research/quote.gif";
	
	document.images["consumerInfoTab"].src = "VF/images/research/tabconsumerinfo_i.gif";
	document.images["technicalSpecTab"].src = "VF/images/research/tabtechnicalspec_i.gif";
	document.images["standardOptionsTab"].src = "VF/images/research/tabstandardoptions_i.gif";

	document.getElementById(activeTab).style.display = "";	
	document.getElementById(activeTab + 'Tab').src = activeImage;	
}

function enableDisable2(activeTab, activeImage)
{
	document.getElementById("consumerInfo").style.display = "none";	
	document.getElementById("technicalSpec").style.display = "none";		
	document.getElementById("standardOptions").style.display = "none";	

	document.images["consumerInfoTab"].src = "VF/images/research/tabconsumerinfo_i.gif";
	document.images["technicalSpecTab"].src = "VF/images/research/tabtechnicalspec_i.gif";
	document.images["standardOptionsTab"].src = "VF/images/research/tabstandardoptions_i.gif";

	document.getElementById(activeTab).style.display = "";	
	document.getElementById(activeTab + 'Tab').src = activeImage;	
}

/* Form validation rules */
function CheckFormValues()
{
	
	rules[0]='txtFullName|required|Please enter Full Name!';
	rules[1]='txtFullName|alphabeticspace|Full Name must contain valid characters';
	rules[2]='txtEmailAddr|required|Please enter Email Address!';
	rules[3]='txtEmailAddr|email|Please enter valid Email Address';
	rules[4]='txtDayPhone|required|Please enter Day Phone!';
	rules[5]='txtDayPhone:Day Phone|keypress|0123456789';
	return performCheck('infoForm', rules, 'classic');
}

/* Function used to calculate prices
for the build page accessories.
*/
function maniPrice(chkbox, price)
{
	var opt;
	opt = document.getElementById("OptionDiv").innerHTML;
	opt = opt.replace("$", "");
	opt = opt.replace(",", "");
	if(opt == "")
		opt = 0;

	var tot;
	tot = document.getElementById("TotalDiv").innerHTML;
	tot = tot.replace("$", "");
	tot = tot.replace(",", "");
	if(tot == "")
		tot = 0;

	if(chkbox.checked == true)
	{
		document.getElementById("OptionDiv").innerHTML = formatCurrency(parseFloat(opt) + parseFloat(price)) 
		document.getElementById("optionMsrpPrice").value = formatCurrency(parseFloat(opt) + parseFloat(price)) 
		document.getElementById("TotalDiv").innerHTML = formatCurrency(parseFloat(tot) + parseFloat(price)) 
		document.getElementById("totalMsrpPrice").value = formatCurrency(parseFloat(tot) + parseFloat(price)) 
	}
	else
	{
		document.getElementById("OptionDiv").innerHTML = formatCurrency(parseFloat(opt) - parseFloat(price)) 
		document.getElementById("optionMsrpPrice").value = formatCurrency(parseFloat(opt) - parseFloat(price)) 
		document.getElementById("TotalDiv").innerHTML = formatCurrency(parseFloat(tot) - parseFloat(price)) 
		document.getElementById("totalMsrpPrice").value = formatCurrency(parseFloat(tot) - parseFloat(price)) 
	}
}

/* Function used to format numbers into 
currency format. This function is being used
in maniPrice() function
*/
function formatCurrency(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + '$' + num + '.' + cents);
}

/* Function used to change the mainImage
of the rearch/build page */
function changeImg(bigPic, nodeName)
{
	if(document.getElementById("exteriorColor").value == "")
	{
		document.getElementById("MainImg").src = bigPic;
		document.getElementById("ExtColorNameDiv").innerHTML = nodeName;
		document.getElementById("IntColorDiv").innerHTML = "";
		document.getElementById("IntColorDiv").innerHTML = arr[nodeName];
	}
}

/* Function used to change the text of interior color 
color name on hovering the interior color swatch. 
Function called in build your vehicle page.
*/
function changeInnerTxt(txt)
{
	if(document.getElementById("interiorColor").value == "")
	{
		document.getElementById("IntColorNameDiv").innerHTML = txt;
	}
}

/* Function used to change the text of exterior color 
color name on hovering the exterior color swatch. 
Function called in build your vehicle page.
*/
function innerMOut()
{
	if(document.getElementById("exteriorColor").value == "")
		document.getElementById("IntColorNameDiv").innerHTML = "";
}

function clearInnerDiv()
{
	if(document.getElementById("exteriorColor").value == "")
		document.getElementById("IntColorDiv").innerHTML = "";
}

/* Function used to change the mainImage and interior
image swatches based upon the exterior swatch
selection*/
function setExtColor(txt, bigPic)
{
	if(document.getElementById("exteriorColor").value != "" && document.getElementById("exteriorColor").value != "")
	{		
		document.getElementById("IntColorDiv").innerHTML = "";
		document.getElementById("IntColorDiv").innerHTML = arr[txt];
	}
	
	document.getElementById("MainImg").src = bigPic;
	document.getElementById("ExtColorNameDiv").innerHTML = txt;
	document.getElementById("exteriorColor").value = txt;
	document.getElementById("interiorColor").value = "";
}

/* Setting the value of hidden text box 
based upon the interior swatch selection. */
function setIntColor(txt)
{
	document.getElementById("interiorColor").value = txt;
}

/* Load a popup window for eBrochure page. */
function loadPrintPopup()
{
	window.open("NewVehiclePrintPreview.aspx","newWin","width=730, height=500, top=100, left=200, scrollbars=1, menubar=0,resizable=0");	
}

/* Validation rules for contact us page */
function CheckContactUs()
{
	rules[0]='txtName|required|Please enter Name!';
	rules[1]='txtName|alphabeticspace|Name must contain valid characters';
	rules[2]='txtEmail|required|Please enter Email !';
	rules[3]='txtEmail|email|Please enter valid Email ';
	rules[4]='txtComments|required|Please enter Comments!';
	return performCheck('infoForm', rules, 'classic');
	
}
