var configId = "";		// set when an existing configuration has been requested
var configName = "";
var configExt = "";
var configInt = "";
var configOptpkg = "";
var configApxpkg = "";
var configAcc = "";
var conftype="";
var blank_img = "/images/spacer.gif"
										
var isDealer = 0;
var totalDealerAcc = 0;

var configuratorImagesPath = "/images/configurator/";
var size_extcd = 4;
var size_intcd = 4;
var size_apxpkgcd = 2;
var size_acccd = 5;

var model_cd = "";
var model_year = "";

var sel_ext = "";
var sel_int = "";
var sel_optpkg = "";
var sel_apxpkg = "";
var sel_acc = "";

var base_price = 0;
var totalprice = 0;
var optpkgprice = 0;
var apxpkgprice = 0;
var accprice = 0;

var language = "EN";

var optpkgLayerName = "ScrollWindow0Content";
var accLayerName = "ScrollWindow1Content";

var base_package = "";

// Special pkg sfx combo display
var intPkgSfxDisplay = null;
var extPkgSfxDisplay = null;

var popup_credit_app_host = "";

function showUnavailableAlertBox() {
	alert(unavailable_alert);
}

// //////////////////////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////////////////
// Making "Save vehicle"/"Estimate Payments" visible ONLY when Ineterio/Exterior/Option 
// sections are selected
// //////////////////////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////
function verifySelection(){	
	//alert('me'+sel_ext+' '+sel_int+' '+sel_optpkg);
      //when all values selected, make div visible
	if(sel_ext != "" && sel_int!="" && sel_optpkg!=""){
		var thelayer = document.getElementById('saveVehicle');
		thelayer.style.visibility = "visible";
		thelayer.style.display = "block";
	}
}

function hideVisibility(){
	var thelayer = document.getElementById('saveVehicle');
	thelayer.style.visibility = "hidden";
	thelayer.style.display = "block";
}
		
// //////////////////////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////////////////
// Over functions called when user rolls over an item on the page
// //////////////////////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////////////////
function msExteriorOver( color, colorLang, interLang ){
	if( howManyReady < 2 ) 
		return;

	// only process if color is available and not yet selected by user
	if(all_exterior_state[color] == "av" && color != sel_ext){
		resetAll();			// set all items to available

		// set exterior colors unavailabilty based on already selected items
		setExteriorUnAvailability(sel_int, sel_optpkg);

		setInteriorUnAvailability(color, sel_optpkg);		// sets interior colors unavailabilty based on exterior color user is rolling over and other selected choices
		setOptPkgUnAvailability(color, sel_int);			// sets option packages unavailability based on exterior color user is rolling over and other selected choices
		setApxPkgUnAvailability(color, sel_int, sel_optpkg, sel_acc);		// sets apx packages unavailability based on exterior color user is rolling over and other selected choices
		setAccessoryUnAvailability(color, sel_int, sel_optpkg, sel_apxpkg);		// sets accessories unavailability based on exterior color user is rolling over and other selected choices

		displayAll();					// display all items based on availability
		setSelectedChoices( colorLang, interLang );			// displays all selected choices
			
		// do rollovers
		document['exclr_' + color].src = (getConfiguratorType() == "adstudio") ? blank_img : configuratorImagesPath + model_cd + "/" + "exclr_" + model_cd + model_year + "_" + color + "_on.gif";
		replaceContent('extname_layer', "<font style=\"font-size: 7pt;\">" + exterior_color[ color ] + "</font>", "Verdana, Arial, Helvetica, sans-serif", "8pt");
	}
}

function msInteriorOver( color,  colorLang, interLang  ){
	if( howManyReady < 2 )
		return;
	
	// only process if color is available and not yet selected by user
	if(all_interior_state[color] == "av" && color != sel_int){
		resetAll();			// set all items to available

		// set interior colors unavailabilty based on already selected items
		setInteriorUnAvailability(sel_ext, sel_optpkg);

		setExteriorUnAvailability(color, sel_optpkg);	// sets exterior colors unavailabilty based on interior color user is rolling over and other selected choices
		setOptPkgUnAvailability(sel_ext, color);		// sets option packages unavailability based on interior color user is rolling over and other selected choices
		setApxPkgUnAvailability(sel_ext, color, sel_optpkg, sel_acc);	// sets apx packages unavailability based on interior color user is rolling over and other selected choices
		setAccessoryUnAvailability(sel_ext, color, sel_optpkg, sel_apxpkg);	// sets accessories unavailability based on interior color user is rolling over and other selected choices

		displayAll();					// display all items based on availability
		setSelectedChoices( colorLang, interLang );			// displays all selected choices

		// do rollovers
		document['inclr_' + color].src = (getConfiguratorType() == "adstudio") ? blank_img : configuratorImagesPath + model_cd + "/" + "inclr_" + model_cd + model_year + "_" + color + "_on.gif";
//		document['in_vehicle'].src = configuratorImagesPath + "incar_" + model_cd + model_year + "_" + color + ".jpg";
		replaceContent('intname_layer', "<font style=\"font-size: 7pt;\">" + interior_color[ color ] + "</font>", "Verdana, Arial, Helvetica, sans-serif", "8pt");
	}
}

function msOptPkgOver( optpkg , colorLang, interLang ){
	if( howManyReady < 2 )
		return
	
	// only process if optpkg is available and not yet selected by user
	if(optpkg == "baseoptpkg" || ( all_packages_state[optpkg] == "av" && optpkg != sel_optpkg )){
		if(optpkg == "baseoptpkg")
			optpkg = "";

		resetAll();			// set all items to available
			
		// set option packages unavailabilty based on already selected items
		setOptPkgUnAvailability(sel_ext, sel_int);
			
		setExteriorUnAvailability(sel_int, optpkg);	// sets exterior colors unavailabilty based on option package user is rolling over and other selected choices
		setInteriorUnAvailability(sel_ext, optpkg);	// sets interior colors unavailabilty based on option package user is rolling over and other selected choices
		setApxPkgUnAvailability(sel_ext, sel_int, optpkg, sel_acc);		// sets apx packages unavailability based on option package user is rolling over and other selected choices
		setAccessoryUnAvailability(sel_ext, sel_int, optpkg, sel_apxpkg);	// sets accessories unavailability based on option package user is rolling over and other selected choices

		displayAll();					// display all items based on availability
		setSelectedChoices( colorLang, interLang );			// displays all selected choices
	}
}

function msApxPkgOver( apxpkg,  colorLang, interLang  ){
	if(all_apxs_state[apxpkg] == "av" && apxpkg != sel_apxpkg){
		// only check accessories because apxs do not affect any
		// above combinations (exterior, interior, option packages)
		
		resetAccessoryAvailability();
		setAccessoryUnAvailability(sel_ext, sel_int, sel_optpkg, apxpkg);
		displayAccessoryAvailability();
		setSelectedChoices( colorLang, interLang );
	}
}
		
function msAccessoryOver( acc, colorLang, interLang  ){
	if(all_accessories_state[acc] == "av" && sel_acc.indexOf( acc ) == -1){
		// only check apxs because accessories do not affect any
		// above combinations (exterior, interior, option packages).
		
		resetApxPkgAvailability();
		setApxPkgUnAvailability(sel_ext, sel_int, sel_optpkg, sel_acc + acc);
		displayApxPkgAvailability();
		setSelectedChoices( colorLang, interLang );
	}
}
	
// //////////////////////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////////////////
// Out functions called when user rolls out an item on the page
// //////////////////////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////////////////
function msExteriorOut( color,  colorLang, interLang  ){
	if( howManyReady < 2 )
		return;
	
	resetAll();							// set all items to available
	setAll();							// set items availability based on user selections
	displayAll();						// display all items based on availability
	setSelectedChoices( colorLang, interLang );				// displays all selected choices
		
	// if no exterior color has yet been selected, change exterior
	// vehicle image & name to their default values
	if(sel_ext == ""){
		document['ex_vehicle'].src = configuratorImagesPath + model_cd + "/" + "excar_" + model_cd + model_year + "_default.jpg";
		replaceContent('extname_layer', "", "Verdana, Arial, Helvetica, sans-serif", "8pt");
	}
}

function msInteriorOut( color_swatch,  colorLang, interLang  ){
	if( howManyReady < 2 )
		return;
	
	resetAll();							// set all items to available
	setAll();							// set items availability based on user selections
	displayAll();						// display all items based on availability
	setSelectedChoices( colorLang, interLang );				// displays all selected choices
		
	// if no interior color has yet been selected, change interior
	// vehicle image & name to their default values
	if(sel_int == ""){
		document['in_vehicle'].src = configuratorImagesPath + model_cd + "/" + "incar_" + model_cd + model_year + "_default.jpg";
		replaceContent('intname_layer', "", "Verdana, Arial, Helvetica, sans-serif", "8pt");
	}
}

function msOptPkgOut( optpkg, colorLang, interLang  ){
	if( howManyReady < 2 )
		return;
	
	resetAll();							// set all items to available
	setAll();							// set items availability based on user selections
	displayAll();						// display all items based on availability
	setSelectedChoices( colorLang, interLang );				// displays all selected choices
}

function msApxPkgOut( apxpkg, colorLang, interLang  ){
	resetAccessoryAvailability();
	setAccessoryUnAvailability(sel_ext, sel_int, sel_optpkg, sel_apxpkg);
	displayAccessoryAvailability();
	setSelectedChoices( colorLang, interLang );
}

function msAccessoryOut( acc, colorLang, interLang  ){
	resetApxPkgAvailability();
	setApxPkgUnAvailability(sel_ext, sel_int, sel_optpkg, sel_acc);
	displayApxPkgAvailability();
	setSelectedChoices( colorLang, interLang );
}
	
// //////////////////////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////////////////
// Click functions called when user clicks on an item on the page
// //////////////////////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////////////////
function displayInteriorSpecialPic() {
	if (sel_int != "") {
		if (intPkgSfxDisplay != null) {
			for (var i=0;i<intPkgSfxDisplay.length;i++) {
				if (intPkgSfxDisplay[i] == sel_optpkg) {
					document['in_vehicle'].src = configuratorImagesPath + model_cd + "/" + "incar_" + model_cd + model_year + "_" + sel_int + "_" + sel_optpkg + ".jpg";
					return;
				}
				//alert( "incar_" + model_cd + model_year + "_" + sel_int + "_" + sel_optpkg + ".jpg" );
			}
		}
		document['in_vehicle'].src = configuratorImagesPath + model_cd + "/" + "incar_" + model_cd + model_year + "_" + sel_int + ".jpg";
	}	
}

function displayExteriorSpecialPic() {
	if (sel_ext != "") {
		if (extPkgSfxDisplay != null) {
			for (var i=0;i<extPkgSfxDisplay.length;i++) {
				if (extPkgSfxDisplay[i] == sel_optpkg) {
					document['ex_vehicle'].src = configuratorImagesPath + model_cd + "/" + "excar_" + model_cd + model_year + "_" + sel_ext + "_" + sel_optpkg + ".jpg";
					return;
				}//alert( "incar_" + model_cd + model_year + "_" + sel_int + "_" + sel_optpkg + ".jpg" );
			}
		}
		document['ex_vehicle'].src = configuratorImagesPath + model_cd + "/" + "excar_" + model_cd + model_year + "_" + sel_ext + ".jpg";
	}	
}

function msExteriorClick( color ){
	// only process if color is available and not yet selected by user
	if(all_exterior_state[color] == "av" && color != sel_ext){
		if(sel_ext != "")
			document['exclr_' + sel_ext].src = (getConfiguratorType() == "adstudio") ? blank_img : configuratorImagesPath + model_cd + "/" + "exclr_" + model_cd + model_year + "_" + sel_ext + "_off.gif";

		sel_ext = color;
		document['exclr_' + sel_ext].src = (getConfiguratorType() == "adstudio") ? blank_img : configuratorImagesPath + model_cd + "/" + "exclr_" + model_cd + model_year + "_" + sel_ext + "_on.gif";
		//document['ex_vehicle'].src = configuratorImagesPath + "excar_" + model_cd + model_year + "_" + sel_ext + ".jpg";

		displayExteriorSpecialPic();
		
//		setConfigurationUpdated();

		//turn on the exterior larger image button
		turnOnExtLargerButton();
	}
	else if( all_exterior_state[color] == "na" )
		showUnavailableAlertBox();

	deselectIllegalAccessories();
	deselectIllegalApxPkg();
}
	
function msInteriorClick( color ){
	// only process if color is available and not yet selected by user
	if(all_interior_state[color] == "av" && color != sel_int){
		if(sel_int != "")
			document['inclr_' + sel_int].src = (getConfiguratorType() == "adstudio") ? blank_img : configuratorImagesPath + model_cd + "/" + "inclr_" + model_cd + model_year + "_" + sel_int + "_off.gif";

		sel_int = color;
		document['inclr_' + sel_int].src = (getConfiguratorType() == "adstudio") ? blank_img : configuratorImagesPath + model_cd + "/" + "inclr_" + model_cd + model_year + "_" + sel_int + "_on.gif";
		//document['in_vehicle'].src = configuratorImagesPath + "incar_" + model_cd + model_year + "_" + sel_int + ".jpg";
		
		displayInteriorSpecialPic();

//		setConfigurationUpdated();

		//turn on the interior larger image button
		turnOnIntLargerButton()
	}
	else if( all_interior_state[color] == "na" )
		showUnavailableAlertBox();
	
	deselectIllegalAccessories();
	deselectIllegalApxPkg();
}

function msOptPkgClick( optpkg ){
	var docObj = getDocumentObject( optpkgLayerName );

	if( optpkg == "baseoptpkg" ){
//		docObj['optpkg_rb_baseoptpkg'].src = configuratorImagesPath + "radiobutton_on.gif";
		
		if(sel_optpkg != ""){
			// if user has already selected an option package before, deselect it
			// and deduct the price from the total
			docObj['optpkg_rb_' + sel_optpkg].src = configuratorImagesPath + "radiobutton_off.gif";
			optpkgprice = optpkgprice - packages_price[ sel_optpkg ];
			refreshPrices();
			
//			setConfigurationUpdated();
		}
		
		sel_optpkg = "";
		
		msOptPkgOut('baseoptpkg');
	}
	// only process if optpkg is available and not yet selected by user
/*	ILO - MODIFIED TO ALLOW SELECTION OF THE 1ST PACKAGE WHEN INITIALLY ENTER THE PAGE 
//	else if(all_packages_state[optpkg] == "av" && optpkg != sel_optpkg){
*/
	else if(all_packages_state[optpkg] == "av" && (optpkg != sel_optpkg || (optpkg == "" && sel_optpkg==""))){
//		docObj['optpkg_rb_baseoptpkg'].src = configuratorImagesPath + "radiobutton_off.gif";
		
		if(sel_optpkg != ""){
			// if user has already selected an option package before, deselect it
			// and deduct the price from the total
			docObj['optpkg_rb_' + sel_optpkg].src = configuratorImagesPath + "radiobutton_off.gif";
			optpkgprice = optpkgprice - packages_price[ sel_optpkg ];
		}

		// set new selected option package and add price to total
		sel_optpkg = optpkg;
		optpkgprice = optpkgprice + packages_price[ sel_optpkg ];
		refreshPrices();
		docObj['optpkg_rb_' + sel_optpkg].src = configuratorImagesPath + "radiobutton_on.gif";
		
		displayInteriorSpecialPic();
		displayExteriorSpecialPic();
		
//		setConfigurationUpdated();
	}
	else if( all_packages_state[optpkg] == "na" )
		showUnavailableAlertBox();	
	
	deselectIllegalAccessories();
	deselectIllegalApxPkg();
	
	// //////////////////////////////////////////////////
	// code added for the ad studio
	// //////////////////////////////////////////////////
	if(getConfiguratorType() == "adstudio"){
		autoSelectColors();
	}
}

function msApxPkgClick( apxpkg ){
	var docObj = getDocumentObject( accLayerName );

	// only process if apx package is available
	if(all_apxs_state[apxpkg] == "av" && apxpkg != sel_apxpkg){
		if(sel_apxpkg != ""){
			// if sel_apxpkg is not empty, deselect current apx and subtract price
			docObj['apxpkg_rb_' + sel_apxpkg].src = configuratorImagesPath + "radiobutton_off.gif";
			apxpkgprice = apxpkgprice - apxs_price[ sel_apxpkg ];
		}
		
		// set new selected apxpkg to sel_apxpkg and adjust price
		sel_apxpkg = apxpkg;
		apxpkgprice = apxpkgprice + apxs_price[ sel_apxpkg ];
		refreshPrices();
		
//		setConfigurationUpdated();
		
		docObj['apxpkg_rb_' + sel_apxpkg].src = configuratorImagesPath + "radiobutton_on.gif";
	}
	else if( all_apxs_state[apxpkg] == "na" )
		showUnavailableAlertBox();

	deselectIllegalAccessories();
	deselectIllegalApxPkg();
}

function msAccessoryClick( acc ){
	// This method has been modified to support duplicate accessories.
	// The original method is commented out below.

	var docObj = getDocumentObject( accLayerName );

	if( isDuplicateAcsyById( acc ) ){
		if( isDuplicateAcsyByIdAvailable( acc ) ){
			var master_acsy = getMasterAccessoryId( acc );
			var first_avail_acsy = getFirstAvailableDuplicateAcsyByName( duplicate_id_to_name[acc] );

//			alert("is duplicate:" + sel_acc);
//			alert("first_avail_acsy:" + first_avail_acsy);
//			-- will
			
			// acc (accessory) is being selected, add it to sel_acc
			if( sel_acc.indexOf( first_avail_acsy) == -1 ){
				accprice = accprice + accessories_price[ first_avail_acsy ];
				refreshPrices();

				docObj['acc_chk_' + master_acsy].src = configuratorImagesPath + "checkbox_on.gif";
				sel_acc += first_avail_acsy;
			}
			// accessory is being deselected, remove it from sel_acc
			else{
				accprice = accprice - accessories_price[ first_avail_acsy ];
				refreshPrices();

				docObj['acc_chk_' + master_acsy].src = configuratorImagesPath + "checkbox_off.gif";
				sel_acc = removeAccessory(sel_acc, first_avail_acsy);
			}
			
		}
		else
			showUnavailableAlertBox();
	}
	
	
	else{
		// only process if acc (accessory) is available
		if(all_accessories_state[acc] == "av"){
			// acc (accessory) is being selected, add it to sel_acc
			if(sel_acc.indexOf(acc) == -1){
				accprice = accprice + accessories_price[acc];
				refreshPrices();

				docObj['acc_chk_' + acc].src = configuratorImagesPath + "checkbox_on.gif";
				sel_acc += acc;
			}
			// accessory is being deselected, remove it from sel_acc
			else{
				accprice = accprice - accessories_price[acc];
				refreshPrices();

				docObj['acc_chk_' + acc].src = configuratorImagesPath + "checkbox_off.gif";
				sel_acc = removeAccessory(sel_acc, acc);
			}
		}
		else if( all_accessories_state[acc] == "na" )
			showUnavailableAlertBox();
	}
	
	deselectIllegalAccessories();
	deselectIllegalApxPkg();
}

/*function msAccessoryClick( acc ){
	var docObj = getDocumentObject( accLayerName );

	// only process if acc (accessory) is available
	if(all_accessories_state[acc] == "av"){
		// acc (accessory) is being selected, add it to sel_acc
		if(sel_acc.indexOf(acc) == -1){
			accprice = accprice + accessories_price[acc];
			
			setConfigurationUpdated();
			
			refreshPrices();

			docObj['acc_chk_' + acc].src = configuratorImagesPath + "checkbox_on.gif";
			sel_acc += acc;
		}
		// accessory is being deselected, remove it from sel_acc
		else{
			accprice = accprice - accessories_price[acc];
			
			setConfigurationUpdated();
			
			refreshPrices();
			
			docObj['acc_chk_' + acc].src = configuratorImagesPath + "checkbox_off.gif";
			sel_acc = removeAccessory(sel_acc, acc)
		}
	}
	else if( all_accessories_state[acc] == "na" )
		showUnavailableAlertBox();
	
	deselectIllegalAccessories();
	deselectIllegalApxPkg();
}*/
	
// //////////////////////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////////////////
// set methods for setting items availability
// //////////////////////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////////////////
function setExteriorUnAvailability(intcode, optpkgcode){
	// this method sets all exterior colors availabilty based on other selected items

	var allColors = "";
	// nothing to look for
	if(intcode == "" && optpkgcode == "")
		allColors = "";
	else
		allColors = na_exterior[ intcode + optpkgcode ]; // retrieve all unavailable exterior colors.

	// only loop if there is at least 1 unavailable exterior color
	if(allColors != ""){
		var totalColors = allColors.length / size_extcd;
		for(var i = 0; totalColors - 1 >= i; i++){
			var color = allColors.substring(0, size_extcd);
			all_exterior_state[ color ] = "na";
			allColors = allColors.substring(size_extcd);
		}
	}
}

function setInteriorUnAvailability(extcode, optpkgcode){
	// this method sets all interior colors availabilty based on other selected items

	var allColors = "";
	// nothing to look for
	if(extcode == "" && optpkgcode == "")
		allColors = "";
	else
		allColors = na_interior[ extcode + optpkgcode ]; // retrieve all unavailable interior colors.

	// only loop if there is at least 1 unavailable interior color
	if(allColors != ""){
		var totalColors = allColors.length / size_intcd;
		for(var i = 0; totalColors - 1 >= i; i++){
			var color = allColors.substring(0, size_intcd);
			all_interior_state[ color ] = "na";
			allColors = allColors.substring(size_intcd);
		}
	}
}

function setOptPkgUnAvailability(extcode, intcode){
	// this method sets all option packages availabilty based on other selected items

	var allPackages = "";
	// nothing to look for
	if(extcode == "" && intcode == "")
		allPackages = "";
	else
		allPackages = na_optpkg[ extcode + intcode ]; // retrieve all unavailable option packages.

	while( allPackages.length > 0 ){
		var pkg_id_size = all_packages_id_size[ allPackages.substring(0, 1) ];
		var pkg = allPackages.substring(0, pkg_id_size);
		all_packages_state[ pkg ] = "na";
		allPackages = allPackages.substring(pkg_id_size);
	}
}

function setApxPkgUnAvailability(extcode, intcode, optpkgcode, acsycode){
	// this method sets all apx packages availabilty based on other selected items

	var allApxPackages = allApxPackages = na_apxpkg[ extcode + intcode + optpkgcode ];
	// we also need to retrieve all accessories ids.
	while( acsycode.length > 0 ){
		var acsy = acsycode.substring(0, size_acccd);
		allApxPackages += na_apxpkg[ acsy ];
		acsycode = acsycode.substring(size_acccd);
	}

	// only loop if there is at least 1 unavailable apx package
	if(allApxPackages != ""){
		var totalApxPackages = allApxPackages.length / size_apxpkgcd;
		for(var i = 0; totalApxPackages - 1 >= i; i++){
			var apxpkg = allApxPackages.substring(0, size_apxpkgcd);
			all_apxs_state[ apxpkg ] = "na";
			allApxPackages = allApxPackages.substring(size_apxpkgcd);
		}
	}
}

function setAccessoryUnAvailability(extcode, intcode, optpkgcode, apxpkgcode){
	// this method sets all accessories availabilty based on other selected items

	var allAccessories = "";
//	if(extcode == "" && intcode == "" && optpkgcode == "")
//		allAccessories = ""; // nothing to look for
//	else
	allAccessories = na_accessory[ extcode + intcode + optpkgcode ]; // retrieve all unavailable accessories.
	allAccessories += na_accessory[ apxpkgcode ]; // retrieve all unavailable accessories.

	// only loop if there is at least 1 unavailable accessory
	if(allAccessories != ""){
		var totalAccessories = allAccessories.length / size_acccd;
		for(var i = 0; totalAccessories - 1 >= i; i++){
			var accessory = allAccessories.substring(0, size_acccd);
			all_accessories_state[ accessory ] = "na";
			allAccessories = allAccessories.substring(size_acccd);
		}
	}
}

function setAll(){
	setExteriorUnAvailability(sel_int, sel_optpkg);
	setInteriorUnAvailability(sel_ext, sel_optpkg);
	setOptPkgUnAvailability(sel_ext, sel_int);
	setApxPkgUnAvailability(sel_ext, sel_int, sel_optpkg, sel_acc);
	setAccessoryUnAvailability(sel_ext, sel_int, sel_optpkg, sel_apxpkg);
}
	
// //////////////////////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////////////////
// set method for displaying all selected items
// //////////////////////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////////////////
function setSelectedChoices( colorLang, interLang ){
	if(sel_ext != ""){
		document['exclr_' + sel_ext].src = (getConfiguratorType() == "adstudio") ? blank_img : configuratorImagesPath + model_cd + "/" + "exclr_" + model_cd + model_year + "_" + sel_ext + "_on.gif";
		//document['ex_vehicle'].src = configuratorImagesPath + "excar_" + model_cd + model_year + "_" + sel_ext + ".jpg";
	
		displayExteriorSpecialPic();
		
		replaceContent('extname_layer', "<font style=\"font-size: 7pt;\">" + exterior_color[ sel_ext ] + "</font>", "Verdana, Arial, Helvetica, sans-serif", "8pt");
	}

	if (sel_int != ""){
		document['inclr_' + sel_int].src = (getConfiguratorType() == "adstudio") ? blank_img : configuratorImagesPath + model_cd + "/" + "inclr_" + model_cd + model_year + "_" + sel_int + "_on.gif";
		//document['in_vehicle'].src = configuratorImagesPath + "incar_" + model_cd + model_year + "_" + sel_int + ".jpg";

		displayInteriorSpecialPic();
	
		replaceContent('intname_layer', "<font style=\"font-size: 7pt;\">" + interior_color[ sel_int ] + "</font>", "Verdana, Arial, Helvetica, sans-serif", "8pt");
	}

	var docObj = null;
	if(sel_optpkg != ""){
		docObj = getDocumentObject( optpkgLayerName );
		docObj['optpkg_rb_' + sel_optpkg].src = configuratorImagesPath + "radiobutton_on.gif";
	}

	if(sel_acc != ""){
		docObj = getDocumentObject( accLayerName );
		// display checkbox_on.gif on ALL user selected accessories
		var temp_sel_acc = sel_acc;
		var total_sel_acc = temp_sel_acc.length / size_acccd;

		for(var i = 0; total_sel_acc - 1 >= i; i++){
			var accessory = temp_sel_acc.substring(0, size_acccd);
			
			if( isDuplicateAcsyById( accessory ) )
				docObj['acc_chk_' + getMasterAccessoryId( accessory )].src = configuratorImagesPath + "checkbox_on.gif";
			else
				docObj['acc_chk_' + accessory].src = configuratorImagesPath + "checkbox_on.gif";
						
			
			temp_sel_acc = temp_sel_acc.substring(size_acccd);
		}
	}
	
	if(sel_apxpkg != ""){
		docObj = getDocumentObject( accLayerName );
		docObj['apxpkg_rb_' + sel_apxpkg].src = configuratorImagesPath + "radiobutton_on.gif";
	}
}

/*function setSelectedChoices(){
	if(sel_ext != ""){
		document['exclr_' + sel_ext].src = (getConfiguratorType() == "adstudio") ? blank_img : configuratorImagesPath + "exclr_" + model_cd + model_year + "_" + sel_ext + "_on.gif";
		//document['ex_vehicle'].src = configuratorImagesPath + "excar_" + model_cd + model_year + "_" + sel_ext + ".jpg";
	
		displayExteriorSpecialPic();
		
		replaceContent('extname_layer', "<font class=\"default\">" + exterior_color[ sel_ext ] + "</font>", "Verdana, Arial, Helvetica, sans-serif", "8pt");
	}

	if (sel_int != ""){
		document['inclr_' + sel_int].src = (getConfiguratorType() == "adstudio") ? blank_img : configuratorImagesPath + "inclr_" + model_cd + model_year + "_" + sel_int + "_on.gif";
		//document['in_vehicle'].src = configuratorImagesPath + "incar_" + model_cd + model_year + "_" + sel_int + ".jpg";

		displayInteriorSpecialPic();
	
		replaceContent('intname_layer', "<font class=\"default\">" + interior_color[ sel_int ] + "</font>", "Verdana, Arial, Helvetica, sans-serif", "8pt");
	}

	var docObj = null;
	if(sel_optpkg != ""){
		docObj = getDocumentObject( optpkgLayerName );
		docObj['optpkg_rb_' + sel_optpkg].src = configuratorImagesPath + "radiobutton_on.gif";
	}

	if(sel_acc != ""){
		docObj = getDocumentObject( accLayerName );
		// display checkbox_on.gif on ALL user selected accessories
		var temp_sel_acc = sel_acc;
		var total_sel_acc = temp_sel_acc.length / size_acccd;

		for(var i = 0; total_sel_acc - 1 >= i; i++){
			var accessory = temp_sel_acc.substring(0, size_acccd);
			docObj['acc_chk_' + accessory].src = configuratorImagesPath + "checkbox_on.gif";
			temp_sel_acc = temp_sel_acc.substring(size_acccd);
		}
	}
	
	if(sel_apxpkg != ""){
		docObj = getDocumentObject( accLayerName );
		docObj['apxpkg_rb_' + sel_apxpkg].src = configuratorImagesPath + "radiobutton_on.gif";
	}
}*/
	
// //////////////////////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////////////////
// reset methods
// //////////////////////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////////////////
function resetExteriorAvailability(){
	// this method sets all exterior state to available
	var allColors = all_exterior;
	var totalColors = allColors.length / size_extcd;

	for(var i = 0; totalColors - 1 >= i; i++){
		var color = allColors.substring(0, size_extcd);
		all_exterior_state[ color ] = "av";
		allColors = allColors.substring(size_extcd);
	}
	
//	setConfigurationUpdated();
}
	
function resetInteriorAvailability(){
	// this method sets all interior state to available
	var allColors = all_interior;
	var totalColors = allColors.length / size_intcd;
	for(var i = 0; totalColors - 1 >= i; i++){
		var color = allColors.substring(0, size_intcd);
		all_interior_state[ color ] = "av";
		allColors = allColors.substring(size_intcd);
	}
	
//	setConfigurationUpdated();
}

function resetOptPkgAvailability(){
	// this method sets all option packages state to available
	var allPackages = all_packages;
	
	while( allPackages.length > 0 ){
		var pkg_id_size = all_packages_id_size[ allPackages.substring(0, 1) ];
		var pkg = allPackages.substring(0, pkg_id_size);
		all_packages_state[ pkg ] = "av";
		allPackages = allPackages.substring(pkg_id_size);
	}
	
//	setConfigurationUpdated();
}

function resetApxPkgAvailability(){
	// this method sets all apx packages state to available
	var allApxPackages = all_apxs;
	var totalApxPackages = allApxPackages.length / size_apxpkgcd;
	for(var i = 0; totalApxPackages - 1 >= i; i++){
		var apxpkg = allApxPackages.substring(0, size_apxpkgcd);
		all_apxs_state[ apxpkg ] = "av";
		allApxPackages = allApxPackages.substring(size_apxpkgcd);
	}
	
//	setConfigurationUpdated();
}

function resetAccessoryAvailability(){
	// this method sets all accessories state to available
	var allAccessories = all_accessories;
	var totalAccessories = allAccessories.length / size_acccd;
	for(var i = 0; totalAccessories - 1 >= i; i++){
		var accessory = allAccessories.substring(0, size_acccd);
		all_accessories_state[ accessory ] = "av";
		allAccessories = allAccessories.substring(size_acccd);
	}
	
//	setConfigurationUpdated();
}
	
function resetAll(){
	resetExteriorAvailability();
	resetInteriorAvailability();
	resetOptPkgAvailability();
	resetApxPkgAvailability();
	resetAccessoryAvailability();
}
	
// //////////////////////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////////////////
// display methods for displaying all available and unavailable items
// //////////////////////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////////////////
function displayExteriorAvailability(){
	// this method displays exterior colors availability
	var allColors = all_exterior;

	if(allColors != ""){
		var totalColors = allColors.length / size_extcd;

		for(var i = 0; totalColors - 1 >= i; i++){
			var color = allColors.substring(0, size_extcd);
			if(color == sel_ext)
				document['exclr_' + color].src = (getConfiguratorType() == "adstudio") ? blank_img : configuratorImagesPath + model_cd + "/" + "exclr_" + model_cd + model_year + "_" + color + "_on.gif";
			else if(all_exterior_state[color] == "av")
				document['exclr_' + color].src = (getConfiguratorType() == "adstudio") ? blank_img : configuratorImagesPath + model_cd + "/" + "exclr_" + model_cd + model_year + "_" + color + "_off.gif";
			else
				document['exclr_' + color].src = (getConfiguratorType() == "adstudio") ? blank_img : configuratorImagesPath + model_cd + "/" + "exclr_" + model_cd + model_year + "_" + color + "_na.gif";

			allColors = allColors.substring(size_extcd);
		}
	}
}
	
function displayInteriorAvailability(){
	// this method displays interior colors availability
	var allColors = all_interior;

	if(allColors != ""){
		var totalColors = allColors.length / size_intcd;
		for(var i = 0; totalColors - 1 >= i; i++){
			var color = allColors.substring(0, size_intcd);
			if(color == sel_int) {
				document['inclr_' + color].src = (getConfiguratorType() == "adstudio") ? blank_img : configuratorImagesPath + model_cd + "/" + "inclr_" + model_cd + model_year + "_" + color + "_on.gif";
			}	
			else if(all_interior_state[color] == "av") {
				document['inclr_' + color].src = (getConfiguratorType() == "adstudio") ? blank_img : configuratorImagesPath + model_cd + "/" + "inclr_" + model_cd + model_year + "_" + color + "_off.gif";
			}	
			else {
				document['inclr_' + color].src = (getConfiguratorType() == "adstudio") ? blank_img : configuratorImagesPath + model_cd + "/" + "inclr_" + model_cd + model_year + "_" + color + "_na.gif";
			}	

			allColors = allColors.substring(size_intcd);
		}
	}
}

function displayOptPkgAvailability(){
	var docObj = getDocumentObject( optpkgLayerName );

	// this method displays option packages availability
	var allPackages = all_packages;

	while( allPackages.length > 0 ){
		var pkg_id_size = all_packages_id_size[ allPackages.substring(0, 1) ];
		var pkg = allPackages.substring(0, pkg_id_size);

		if(all_packages_state[ pkg ] == "av")
			docObj['optpkg_rb_' + pkg].src = configuratorImagesPath + "radiobutton_off.gif";
		else
			docObj['optpkg_rb_' + pkg].src = configuratorImagesPath + "optpkg_na.gif";

		allPackages = allPackages.substring(pkg_id_size);
	}
}

function displayApxPkgAvailability(){
	var docObj = getDocumentObject( accLayerName );

	// this method displays accessories availability
	var allApxPackages = all_apxs;

	if(allApxPackages != ""){
		var totalApxPackages = allApxPackages.length / size_apxpkgcd;
		for(var i = 0; totalApxPackages - 1 >= i; i++){
			var apxpkg = allApxPackages.substring(0, size_apxpkgcd);
			if(all_apxs_state[ apxpkg ] == "av")
				docObj['apxpkg_rb_' + apxpkg].src = configuratorImagesPath + "radiobutton_off.gif";
//				docObj['apxpkg_' + apxpkg].src = configuratorImagesPath + "apxpkg_av.gif";
			else
				docObj['apxpkg_rb_' + apxpkg].src = configuratorImagesPath + "apxpkg_na.gif";
//				docObj['apxpkg_' + apxpkg].src = configuratorImagesPath + "apxpkg_na.gif";

			allApxPackages = allApxPackages.substring(size_apxpkgcd);
		}
	}
}

function displayAccessoryAvailability(){
	// this method has been modified to support duplicate accessories.
	// The original method is commented out below.
	
	var docObj = getDocumentObject( accLayerName );

	// this method displays accessories availability
	var allAccessories = all_accessories;

	if(allAccessories != ""){
		var totalAccessories = allAccessories.length / size_acccd;
		for(var i = 0; totalAccessories - 1 >= i; i++){
			var accessory = allAccessories.substring(0, size_acccd);

			if( isDuplicateAcsyById( accessory ) ){
				// come in here if accessory has been flagged as a
				// duplicate
				if( isDuplicateAcsyByIdAvailable( accessory ) )
					// if a least one dupplicate accessory is available,
					// the master accessory will be displayed as available
					docObj['acc_chk_' + getMasterAccessoryId( accessory )].src = configuratorImagesPath + "checkbox_off.gif";
				else
					// else, if all duplicate accessories are unavailable, we will
					// show the master accessory as locked.
					docObj['acc_chk_' + getMasterAccessoryId( accessory )].src = configuratorImagesPath + "acc_na.gif";
			}
			else{
				if(all_accessories_state[ accessory ] == "av")
					docObj['acc_chk_' + accessory].src = configuratorImagesPath + "checkbox_off.gif";
				else
					docObj['acc_chk_' + accessory].src = configuratorImagesPath + "acc_na.gif";
			}

			allAccessories = allAccessories.substring(size_acccd);
		}
	}
}

/*function displayAccessoryAvailability(){
	var docObj = getDocumentObject( accLayerName );

	// this method displays accessories availability
	var allAccessories = all_accessories;

	if(allAccessories != ""){
		var totalAccessories = allAccessories.length / size_acccd;
		for(var i = 0; totalAccessories - 1 >= i; i++){
			var accessory = allAccessories.substring(0, size_acccd);

			if(all_accessories_state[ accessory ] == "av")
				docObj['acc_chk_' + accessory].src = configuratorImagesPath + "checkbox_off.gif";
			else
				docObj['acc_chk_' + accessory].src = configuratorImagesPath + "acc_na.gif";

			allAccessories = allAccessories.substring(size_acccd);
		}
	}
}*/

function displayAll(){
	displayExteriorAvailability();
	displayInteriorAvailability();
	displayOptPkgAvailability();
	displayApxPkgAvailability();
	displayAccessoryAvailability();
}
	
// //////////////////////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////////////////
// display methods for displaying all items as available
// //////////////////////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////////////////
function displayAllExteriorAsAvailable(){
	// this method displays exterior colors as available
	// except for selected exterior color
	var allColors = all_exterior;

	if(allColors != ""){
		var totalColors = allColors.length / size_extcd;

		for(var i = 0; totalColors - 1 >= i; i++){
			var color = allColors.substring(0, size_extcd);
			if(color != sel_ext)
				document['exclr_' + color].src = (getConfiguratorType() == "adstudio") ? blank_img : configuratorImagesPath + model_cd + "/" + "exclr_" + model_cd + model_year + "_" + color + "_off.gif";
			allColors = allColors.substring(size_extcd);
		}
	}
}

function displayAllInteriorAsAvailable(){
	// this method displays interior colors as available
	// except for selected interior color
	var allColors = all_interior;

	if(allColors != ""){
		var totalColors = allColors.length / size_intcd;
		for(var i = 0; totalColors - 1 >= i; i++){
			var color = allColors.substring(0, size_intcd);
			if(color != sel_int)
				document['inclr_' + color].src = (getConfiguratorType() == "adstudio") ? blank_img : configuratorImagesPath + model_cd + "/" + "inclr_" + model_cd + model_year + "_" + color + "_off.gif";
			allColors = allColors.substring(size_intcd);
		}
	}
}

function displayAllOptPkgAsAvailable(){
	var docObj = getDocumentObject( optpkgLayerName );

	// this method displays option packages as available
	// except for selected option package
	var allPackages = all_packages;

	while( allPackages.length > 0 ){
		var pkg_id_size = all_packages_id_size[ allPackages.substring(0, 1) ];
		var pkg = allPackages.substring(0, pkg_id_size);

		if(pkg != sel_optpkg){
//			docObj['optpkg_' + pkg].src = configuratorImagesPath + "optpkg_av.gif";
			docObj['optpkg_rb_' + pkg].src = configuratorImagesPath + "radiobutton_off.gif";
		}
		
		allPackages = allPackages.substring(pkg_id_size);
	}
}

function displayAllApxPkgAsAvailable(){
	var docObj = getDocumentObject( accLayerName );

	// this method displays apx packages as available
	// except for selected apx package
	var allApxPackages = all_apxs;

	if(allApxPackages != ""){
		var totalApxPackages = allApxPackages.length / size_apxpkgcd;
		for(var i = 0; totalApxPackages - 1 >= i; i++){
			var apxpkg = allApxPackages.substring(0, size_apxpkgcd);
			if(apxpkg != sel_apxpkg){
//				docObj['apxpkg_' + apxpkg].src = configuratorImagesPath + "apxpkg_av.gif";
				docObj['apxpkg_rb_' + apxpkg].src = configuratorImagesPath + "radiobutton_off.gif";
			}
			allApxPackages = allApxPackages.substring(size_apxpkgcd);
		}
	}
}

function displayAllAccessoryAsAvailable(){
	// This method has been modified to support duplicate accessories.
	// The original method is comented out below.
	var docObj = getDocumentObject( accLayerName );

	// this method displays accessories as available
	// except for selected accessories
	var allAccessories = all_accessories;

	if(allAccessories != ""){
		var totalAccessories = allAccessories.length / size_acccd;
		for(var i = 0; totalAccessories - 1 >= i; i++){
			var accessory = allAccessories.substring(0, size_acccd);
			// the following if statement allows for multiple
			// accessories to be selected
			if( sel_acc.indexOf(accessory) == -1 ){
				if( isDuplicateAcsyById( accessory ) )
					docObj['acc_chk_' + getMasterAccessoryId( accessory )].src = configuratorImagesPath + "checkbox_off.gif";
				else
					docObj['acc_chk_' + accessory].src = configuratorImagesPath + "checkbox_off.gif";
			}
			allAccessories = allAccessories.substring(size_acccd);
		}
	}
}

/*function displayAllAccessoryAsAvailable(){
	var docObj = getDocumentObject( accLayerName );

	// this method displays accessories as available
	// except for selected accessories
	var allAccessories = all_accessories;

	if(allAccessories != ""){
		var totalAccessories = allAccessories.length / size_acccd;
		for(var i = 0; totalAccessories - 1 >= i; i++){
			var accessory = allAccessories.substring(0, size_acccd);
			// the following if statement allows for multiple
			// accessories to be selected
			if( sel_acc.indexOf(accessory) == -1 ){
				docObj['acc_chk_' + accessory].src = configuratorImagesPath + "checkbox_off.gif";
			}
			allAccessories = allAccessories.substring(size_acccd);
		}
	}
}*/

function displayAllAsAvailable(){
	// this method displays all items as available except selected items.
	// Selected items are items the user has already selected or clicked on.
	displayAllExteriorAsAvailable();
	displayAllInteriorAsAvailable();
	displayAllOptPkgAsAvailable();
	displayAllApxPkgAsAvailable();
	displayAllAccessoryAsAvailable();
}

// //////////////////////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////////////////
// utility methods
// //////////////////////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////////////////
function removeAccessory(removeFrom, accessoryToRemove){
	var acc_to_remove_pos = removeFrom.indexOf( accessoryToRemove );
	return removeFrom.substring(0, acc_to_remove_pos) + removeFrom.substring(acc_to_remove_pos + size_acccd);
}

function deselectIllegalApxPkg(){
	var docObj = getDocumentObject( accLayerName );

	// get not available apx packages for selected exterior, interior and option package
	var na_apxpkgs = na_apxpkg[ sel_ext + sel_int + sel_optpkg ];

	// make sure apx packages is properly selected based on availability
	if(na_apxpkgs != null && na_apxpkgs != "" && sel_apxpkg != ""){
		var total_na_apxpkgs = na_apxpkgs.length / size_apxpkgcd;
	
		for(var i = 0; total_na_apxpkgs - 1 >= i; i++){
			var na_apx = na_apxpkgs.substring(0, size_apxpkgcd);
			
			if( na_apx == sel_apxpkg ){
				apxpkgprice = apxpkgprice - apxs_price[na_apx];
				refreshPrices();
				
				sel_apxpkg = "";
				docObj['apxpkg_rb_' + na_apx].src = configuratorImagesPath + "radiobutton_off.gif";
			}

			na_apxpkgs = na_apxpkgs.substring(size_apxpkgcd);
		}
	}
}

function deselectIllegalAccessories(){
	// This method has been modified to support duplicate accessories.
	// The original method is comented out below.
	
	var docObj = getDocumentObject( accLayerName );

	// get not available accessories for selected exterior, interior and option package
	var na_accs = na_accessory[ sel_ext + sel_int + sel_optpkg ];
	na_accs += na_accessory[ sel_apxpkg ];

	// make sure all accessories are properly checked based on availability
	if(na_accs != null && na_accs != "" && sel_acc != ""){
		var temp_sel_acc = sel_acc;
		var total_sel_acc = temp_sel_acc.length / size_acccd;

		for(var i = 0; total_sel_acc - 1 >= i; i++){
			var accessory = temp_sel_acc.substring(0, size_acccd);

			// if selected accessory is found in the na_accs string than the
			// accessory is invalid and must be unselected. Also, the price
			// needs to be adjusted.
			if( na_accs.indexOf(accessory) != -1 ){
				if( isDuplicateAcsyById( accessory ) ){
					accprice = accprice - accessories_price[accessory];
					refreshPrices();
					sel_acc = removeAccessory(sel_acc, accessory);
					docObj['acc_chk_' + getMasterAccessoryId( accessory )].src = configuratorImagesPath + "checkbox_off.gif";
					
					// now that you have removed the invalid accessory. Check to see
					// if there is another duplicate accessory available that can be set.
					if( isDuplicateAcsyByIdAvailable( accessory ) ){
						var avail_acsy = getFirstAvailableDuplicateAcsyByName( duplicate_id_to_name[accessory] );
						accprice = accprice + accessories_price[avail_acsy];
						refreshPrices();
						sel_acc = sel_acc + avail_acsy;
						docObj['acc_chk_' + getMasterAccessoryId( avail_acsy )].src = configuratorImagesPath + "checkbox_off.gif";
					}
				}
				else{
					accprice = accprice - accessories_price[accessory];
					refreshPrices();

					sel_acc = removeAccessory(sel_acc, accessory);
					docObj['acc_chk_' + accessory].src = configuratorImagesPath + "checkbox_off.gif";
				}
			}

			temp_sel_acc = temp_sel_acc.substring(size_acccd);
		}
	}
}

/*function deselectIllegalAccessories(){
	var docObj = getDocumentObject( accLayerName );

	// get not available accessories for selected exterior, interior and option package
	var na_accs = na_accessory[ sel_ext + sel_int + sel_optpkg ];
	na_accs += na_accessory[ sel_apxpkg ];

	// make sure all accessories are properly checked based on availability
	if(na_accs != null && na_accs != "" && sel_acc != ""){
		var temp_sel_acc = sel_acc;
		var total_sel_acc = temp_sel_acc.length / size_acccd;

		for(var i = 0; total_sel_acc - 1 >= i; i++){
			var accessory = temp_sel_acc.substring(0, size_acccd);

			// if selected accessory is found in the na_accs string than the
			// accessory is invalid and must be unselected. Also, the price
			// needs to be adjusted.
			if( na_accs.indexOf(accessory) != -1 ){
				accprice = accprice - accessories_price[accessory];
				refreshPrices();

				sel_acc = removeAccessory(sel_acc, accessory);
				docObj['acc_chk_' + accessory].src = configuratorImagesPath + "checkbox_off.gif";
			}

			temp_sel_acc = temp_sel_acc.substring(size_acccd);
		}
	}
}*/

function getDocumentObject( forname ){
	var objDoc;

	if(document.layers){
		objDoc = getLayer( forname );
		objDoc = objDoc.document;
	}
	else
		objDoc = document;

	return objDoc;
}

function startOver(){
	var docObj;
	var temp_sel_apxpkg = sel_apxpkg;	// saved to turn image off in case an apx has been selected
	
	sel_ext = "";
	sel_int = "";
	sel_optpkg = "";
	sel_apxpkg = "";
	sel_acc = "";
	
	hideVisibility();
	resetAll();							// set all items to available
	displayAllAsAvailable();			// display all items as available

	document['ex_vehicle'].src = configuratorImagesPath + model_cd + "/" + "excar_" + model_cd + model_year + "_default.jpg";
	document['in_vehicle'].src = configuratorImagesPath + model_cd + "/" + "incar_" + model_cd + model_year + "_default.jpg";
	if( language == "en" || language =="EN"){
		replaceContent('extname_layer', "<strong>Colour:</strong>", "Verdana, Arial, Helvetica, sans-serif", "8pt");
	replaceContent('intname_layer', "<strong>Interior:</strong>", "Verdana, Arial, Helvetica, sans-serif", "8pt");
	}else{
		replaceContent('extname_layer', "<strong>Couleur:</strong>", "Verdana, Arial, Helvetica, sans-serif", "8pt");
	replaceContent('intname_layer', "<strong>Intérieur:</strong>", "Verdana, Arial, Helvetica, sans-serif", "8pt");
	}
	
	docObj = getDocumentObject( optpkgLayerName );
	
	if( temp_sel_apxpkg != "" ){
		docObj = getDocumentObject( accLayerName );
		docObj['apxpkg_rb_' + temp_sel_apxpkg].src = configuratorImagesPath + "radiobutton_off.gif";
	}
	
	totalprice = base_price;
	optpkgprice = 0;
	apxpkgprice = 0;
	accprice = 0;
	refreshPrices();
	
	//turn off the interior and exterior larger image buttons
	turnOffIntLargerButton()
	turnOffExtLargerButton()
	
//	setBasePackage();
//	setConfiguration();
}

function getTotalPrice(){
	return base_price + optpkgprice + apxpkgprice + accprice;
}

function refreshPrices(){
	var formObject = document.forms.configurator;
	
	totalprice = getTotalPrice();
	
	formObject.optionsprice.value = formatPrice( optpkgprice );
	formObject.accessoriesprice.value = formatPrice( apxpkgprice + accprice );
	formObject.totalprice.value = formatPrice( totalprice );
}

/*
function formatPrice( price ){
	var formattedPrice = "" + price;

	if( language == "en" ){
		var priceWithCommas = "";
		while( formattedPrice.length > 0 ){
			if( formattedPrice.length >= 4 ){
				priceWithCommas = "," + formattedPrice.substring( formattedPrice.length - 3 ) + priceWithCommas;
				formattedPrice = formattedPrice.substring(0, formattedPrice.length - 3 );
			}
			else{
				priceWithCommas = formattedPrice + priceWithCommas;
				formattedPrice = "";
			}
		}
		formattedPrice = priceWithCommas;
	}
	
	if(language == "en")
		return "$" + formattedPrice;
	else
		return formattedPrice + " $";
}
*/
// ILO - REBRAND - A6969
function formatPrice( price ){
	var formattedPrice = "" + price;

	var priceWithCommas = "";
	if( language == "en" || language =="EN"){
		while( formattedPrice.length > 0 ){
			if( formattedPrice.length >= 4 ){
				priceWithCommas = "," + formattedPrice.substring( formattedPrice.length - 3 ) + priceWithCommas;
				formattedPrice = formattedPrice.substring(0, formattedPrice.length - 3 );
			}
			else{
				priceWithCommas = formattedPrice + priceWithCommas;
				formattedPrice = "";
			}
		}
	} else  // ASSUMING FRENCH
	{
		while( formattedPrice.length > 0 ){
			if( formattedPrice.length >= 4 ){
				priceWithCommas = " " + formattedPrice.substring( formattedPrice.length - 3 ) + priceWithCommas;
				formattedPrice = formattedPrice.substring(0, formattedPrice.length - 3 );
			}
			else{
				priceWithCommas = formattedPrice + priceWithCommas;
				formattedPrice = "";
			}
		}
	}
	formattedPrice = priceWithCommas;
	
	if(language == "en" || language == "EN")
		return "$" + formattedPrice;
	else
		return formattedPrice + " $";
}


// ready() waits for both configurator subpages to
// load to set a saved configuration if any
var howManyReady = 0;
function ready(){
	howManyReady++;

	if( howManyReady == 2 ){
//		setBasePackage();
		setConfiguration();
		
		if (popup_credit_app_host != '') {
			//alert('kevin');
			creditAppClicked(popup_credit_app_host);
			return;
		}
		
		if (configuration_with_creditapp)
			confirmCreditApplication();
	}
}

function setBasePackage(){
	if( base_package != "" ){
		msOptPkgOver( base_package );
		msOptPkgClick( base_package );
	}
}

function setConfiguration(){
	if(configExt != ""){
		if( configOptpkg != "" ){
			msOptPkgClick( configOptpkg );
			msOptPkgOut( configOptpkg );
		}
			
		msExteriorClick( configExt );
		msExteriorOut( configExt );
		msInteriorClick( configInt );
		msInteriorOut( configInt );

		if( configApxpkg != "" )
			msApxPkgClick( configApxpkg )
			
		if( configAcc != "" ){
			var tempConfigAcc = configAcc;
			var totalConfigAcc = tempConfigAcc.length / size_acccd;

			for(var i = 0; totalConfigAcc - 1 >= i; i++){
				var accessory = tempConfigAcc.substring(0, size_acccd);
				msAccessoryClick( accessory );
				tempConfigAcc = tempConfigAcc.substring(size_acccd);
			}
		}

		msExteriorOut( configExt );
	}
	configurationUpdated = false;
	
}

function printChoices(){
	var choices = "";
	choices += "Exterior: " + sel_ext + "\n" +
				"Interior: " + sel_int + "\n" +
				"ApxPkg: " + sel_apxpkg + "\n" +
				"OptPkg: " + sel_optpkg + "\n" +
				"Accessory: " + sel_acc;
	alert(choices);
}

var preloadedImages = new Array;
function preloadConfiguratorImage( imageToPreload ){
	if(document.images){
		preloadedImages[ imageToPreload ] = new Image();
		preloadedImages[ imageToPreload ].src = configuratorImagesPath + imageToPreload;
	}
}

function alert_configuration_needed()
{
    message = saveWarning_alert;
		
     ss="";
     for(i=1; i<=message.length; i++){
      ss+="  ";
     }	
		
	if(sel_ext == "") {
	
	message += "\n" + ss  + saveWarning_alert_ext + ss; }
		
	if(sel_int == "") {
	
	
	message += "\n" + ss +  saveWarning_alert_int + ss; }
	
	
	if(sel_optpkg == "") { 
	
	
	message += "\n"+ ss + saveWarning_alert_pak + ss;}
	alert(message);

}

function saveConfiguration(saveUrl){
	
	if(sel_ext == "" || sel_int == "" || sel_optpkg == ""){
	alert_configuration_needed()
	}		
	else{
		saveUrl += getQueryString();
		openWin(saveUrl, "SAVECONFIGURATION", 650, 400, 'yes');
		
		//if (documentToLoad != '')
			//return secureReload(window, documentToLoad + getQueryString());
		setTimeout("refresh()", 3000);
			
		return false;
	}
}


function getQueryString(){
	var queryString = "?";
	
	queryString += "configId=" + configId + "&";
	queryString += "model=" + model_cd + "&";
	queryString += "year=" + model_year + "&";
	queryString += "ext_clr_cd=" + sel_ext + "&";
	queryString += "int_clr_cd=" + sel_int + "&";
	queryString += "opt_pkg_sfx=" + sel_optpkg + "&";
	queryString += "apx_pkg_sfx=" + sel_apxpkg + "&";
	queryString += "acsy_list=" + sel_acc + "&";
	queryString += "ecp_id=" + sel_ecp + "&";
	queryString += "province=" + sel_prov + "&";
	queryString += "use_tcci_rates_flag=" + tcci_flag + "&";
	queryString += "encore_discount_flag=" + encore_flag + "&";
	queryString += "finance_term=" + finance_term + "&";
	queryString += "finance_rate=" + finance_rate + "&";
	queryString += "finance_monthly_payments=" + finance_monthly_payment + "&";
	queryString += "downpayment_finance=" + finance_down_payment + "&";
	queryString += "trade_in_value=" + trade_in_value + "&";
	queryString += "trade_in_owing=" + trade_in_owing + "&";
	queryString += "trade_in_owned_flag=" + trade_in_owned_flag + "&";
	queryString += "lease_term=" + lease_term + "&";
	queryString += "lease_rate=" + lease_rate + "&";
	queryString += "downpayment_lease=" + lease_down_payment + "&";
	queryString += "msd_multiplier=" + msd_multiplier + "&";
	queryString += "excess_km=" + excess_km + "&";
	
	return queryString;
}








// /////////////////////////////////////////////////////////////////////////////////
// methods used to store calculator variables
// /////////////////////////////////////////////////////////////////////////////////
var sel_ecp = "";
var sel_prov = "";
var tcci_flag = 1;
var encore_flag = 0;
var finance_term = 0;
var finance_rate = 0;
var finance_monthly_payment = 0;
var finance_down_payment = 0;
var trade_in_value = 0;
var trade_in_owing = 0;
var trade_in_owned_flag = 1;
var lease_term = 0;
var lease_rate = 0;
var lease_down_payment = 0;
var msd_multiplier = 0;
var excess_km = 0;
var include_tax_fee = 0;
function setECP( ecp ){
	sel_ecp = ecp;
}

function setProvince( province ){
	sel_prov = province;
}

function setTcciRatesFlag( flag ){
	tcci_flag = flag;
}

function getTcciRatesFlag(){
	return tcci_flag;
}

function setEncoreDiscountFlag( flag ){
	encore_flag = flag;
}

function setFinanceTerm( term ){
	finance_term = term;
}

function setFinanceRate( rate ){
	finance_rate = rate;
}

function setFinanceMonthlyPayment( payment ){
	finance_monthly_payment = payment;
}

function setFinanceDownPayment( payment ){
	finance_down_payment = payment;
}

function setTradeInValue( value ){
	trade_in_value = value;
}

function setTradeInOwing( value ){
	trade_in_owing = value;
}

function setTradeInOwnedFlag( flag ){
	trade_in_owned_flag = flag;
}

function setLeaseDownPayment( payment ){
	lease_down_payment = payment;
}

function setLeaseTerm( term ){
	lease_term = term;
}

function setLeaseRate( rate ){
	lease_rate = rate;
}

function setMSDMultiplier( multiplier ){
	msd_multiplier = multiplier;
}

function setExcessKM( km ){
	excess_km = km;
}

function setTaxFee( tf ){
	include_tax_fee = tf;
	
}

function gotoPaymentEstimator(){
	if(sel_ext == "" || sel_int == "" || sel_optpkg == "")
		alert_configuration_needed();
	else{
		var formObj = document.forms["paymentestimator"];
		formObj.configId.value = configId;
		formObj.model.value = model_cd;
		formObj.year.value = model_year;
		formObj.ext_clr_cd.value = sel_ext;
		formObj.int_clr_cd.value = sel_int;
		formObj.opt_pkg_sfx.value = sel_optpkg;
		formObj.apx_pkg_sfx.value = sel_apxpkg;
		formObj.acsy_list.value = sel_acc;
		formObj.ecp_id.value = sel_ecp;
		formObj.province.value = sel_prov;
		formObj.use_tcci_rates_flag.value = tcci_flag;
		formObj.encore_discount_flag.value = encore_flag;
		formObj.finance_term.value = finance_term;
		formObj.finance_rate.value = finance_rate;
		formObj.finance_monthly_payments.value = finance_monthly_payment;
		formObj.downpayment_finance.value = finance_down_payment;
		formObj.trade_in_value.value = trade_in_value;
		formObj.trade_in_owing.value = trade_in_owing;
		formObj.trade_in_owned_flag.value = trade_in_owned_flag;
		formObj.lease_term.value = lease_term;
		formObj.lease_rate.value = lease_rate;
		formObj.downpayment_lease.value = lease_down_payment;
		formObj.msd_multiplier.value = msd_multiplier;
		formObj.excess_km.value = excess_km;
		formObj.include_tax_fee.value = include_tax_fee;
		formObj.submit();
	}
}

function creditAppClicked(host) { 
	if(getTcciRatesFlag() == 1) {
		if(sel_ext == "" || sel_int == "" || sel_optpkg == "")
			alert_configuration_needed();
		else {
			var url = "https://" + host + "/lexus/experience/" + language + "/popup_print_pfs/popup_credapp_selection.jsp" + getQueryString();

			//alert('Please save your vehicle and calculations before filling out the credit application');
		//alert(url);
	
			//openWin(url, 'credit_app_select', 620, 500, 'yes');
			openWin(url, 'credit_app_select', 400, 200, 'yes');
		
			setTimeout("refresh()", 3000);
		}
	}
	else
		alert( crdapp_tcci_rates_msg );
}

function printPreview(){
	if(sel_ext == "" || sel_int == "" || sel_optpkg == ""){
		alert_configuration_needed();
	}
	else{
		var url = "/lexus/experience/" + language + "/popup_print_pfs/vehicles/configurator/" + model_cd + model_year + "/pricefactsheet/popup_print_price_fact_sheet.jsp" + getQueryString();

		if( isDealer == 1 ){
			var formObject = document.forms.dealer_accessories;
			var accname = "";
			var accprice = "";
			
			for(var i = 1; i <= totalDealerAcc; i++){
				eval('accname = formObject.dlracc' + i + '_name.value');
				eval('accprice = formObject.dlracc' + i + '_price.value');
				
				if( accname != "" && accprice == "" ){
					alert(dealer_enter_price + accname);
					return;
				}
				else if( accname != "" && accprice != "" ){
					var newPrice = removeCharFromNumber(removeCharFromNumber( accprice, "," ), "$");
					url += "dlracc" + i + "_name=" + accname + "&";
					url += "dlracc" + i + "_price=" + newPrice + "&";
				}
			}
		}
		
		openWin2(url, 'price_fact_sheet', 620, 500, 'yes');
	}
}

function removeCharFromNumber( valueToCheck, charToRemove ){
	var value = "" + valueToCheck;
	
	if( value.indexOf( charToRemove ) == -1 )
		return new Number( value );
	else{
		var tempArray = value.split( charToRemove );
		var newValue = "";
		
		for(var i = 0; i <= tempArray.length - 1; i++)
			newValue += tempArray[i];
		
		return new Number( newValue );
	}
}

function refresh(){
	if (location.href.indexOf('https') < 0) {
	var formObj = document.forms["self"];
		formObj.configId.value = configId;
		formObj.model.value = model_cd;
		formObj.year.value = model_year;
		formObj.ext_clr_cd.value = sel_ext;
		formObj.int_clr_cd.value = sel_int;
		formObj.opt_pkg_sfx.value = sel_optpkg;
		formObj.apx_pkg_sfx.value = sel_apxpkg;
		formObj.acsy_list.value = sel_acc;
		formObj.ecp_id.value = sel_ecp;
		formObj.province.value = sel_prov;
		formObj.use_tcci_rates_flag.value = tcci_flag;
		formObj.encore_discount_flag.value = encore_flag;
		formObj.finance_term.value = finance_term;
		formObj.finance_rate.value = finance_rate;
		formObj.finance_monthly_payments.value = finance_monthly_payment;
		formObj.downpayment_finance.value = finance_down_payment;
		formObj.trade_in_value.value = trade_in_value;
		formObj.trade_in_owing.value = trade_in_owing;
		formObj.trade_in_owned_flag.value = trade_in_owned_flag;
		formObj.lease_term.value = lease_term;
		formObj.lease_rate.value = lease_rate;
		formObj.downpayment_lease.value = lease_down_payment;
		formObj.msd_multiplier.value = msd_multiplier;
		formObj.excess_km.value = excess_km;
		formObj.submit();
	}
}

// //////////////////////////////////////////////////////
// Methods added to support duplicate accessories.
// //////////////////////////////////////////////////////
function addDuplicateAcsyByName(name, id){
	var index = duplicates_acsy_by_name[name].length;
	duplicates_acsy_by_name[name][index] = id;
}

function isDuplicateAcsyById( id ){
	return (is_duplicate_acsy_by_id[id] == true) ? true : false;
}

function isDuplicateAcsyByName( name ){
	return (is_duplicate_acsy_by_name[name] == true) ? true : false;
}

function getDuplicatesByName( name ){
	if( isDuplicateAcsyByName( name ) == true ){
		var duplicates = duplicates_acsy_by_name[name];
		return duplicates;
	}
	else
		return null;
	}

function isDuplicateAcsyByNameAvailable( name ){
	var duplicates = getDuplicatesByName( name );

	for(var i = 0; duplicates.length -1 >= i; i++)
		if( all_accessories_state[ duplicates[i] ] == "av" )
			return true;

	return false;
}

function isDuplicateAcsyByIdAvailable( id ){
	return isDuplicateAcsyByNameAvailable( duplicate_id_to_name[id] );
}

function getFirstAvailableDuplicateAcsyByName( name ){
	var duplicates = getDuplicatesByName( name );

	for(var i = 0; duplicates.length -1 >= i; i++)
		if( all_accessories_state[ duplicates[i] ] == "av" ){
//			alert("sel_ext" + ":" + sel_ext);
//			alert("sel_int" + ":" + sel_int);
//			alert("sel_optpkg" + ":" + sel_optpkg);
//			alert("sel_acc" + ":" + sel_acc);
//			alert("duplicate:" + duplicates[i] + ":av");
			return duplicates[i];
		}
}
		
function getMasterAccessoryId( id ){
	return master_accessory[ duplicate_id_to_name[id] ];
}

function test( name ){
	var duplicates = getDuplicatesByName( name );

	if(duplicates == null)
		alert("no duplicates");
	else{
		alert( "size=" + duplicates.length );
		for(var i = 0; duplicates.length -1 >= i; i++)
			alert( duplicates[i] );
	}
}

function popupExteriorLargerImage(lang) {
	// Display pictures for special package suffix
	var pkg_sfx = "";
	if (extPkgSfxDisplay != null) {
	for (var i=0;i<extPkgSfxDisplay.length;i++) {
		if (extPkgSfxDisplay[i] == sel_optpkg) {
			pkg_sfx =  '_' + sel_optpkg;
		}
	}
	}
	
	if (sel_ext != "") {
			openWin('/' + (lang=="en"?"":lang + "/") + 'configurator/larger_ex.html?excar_lg_' + model_cd + model_year + '_' + sel_ext + pkg_sfx, 'larger_image_ext',385,200,'no');
		}
	return false;
}

function popupInteriorLargerImage(lang) {
	// Display pictures for special package suffix
	var pkg_sfx = "";
	if (intPkgSfxDisplay != null) {
	for (var i=0;i<intPkgSfxDisplay.length;i++) {
		if (intPkgSfxDisplay[i] == sel_optpkg) {
			pkg_sfx = '_' + sel_optpkg;
		}
	}
	}
	
	if (sel_int != "") {
		openWin('/' + (lang=="en"?"":lang + "/") + 'configurator/larger_int.html?incar_lg_' + 		model_cd + model_year + '_' + sel_int + pkg_sfx, 'larger_image_int',483,220,'no');
	}
	return false;
}

// ////////////////////////////////////////////////////////////////////////////////
// new methods added for the ad studio
// ////////////////////////////////////////////////////////////////////////////////
function setConfiguratorType(type){
	conftype = type;
}

function getConfiguratorType(){
	return conftype;
}

function autoSelectColors(){
	msExteriorClick(getNextAvailableExteriorColor());
	msInteriorClick(getNextAvailableInteriorColor());
}

function getNextAvailableExteriorColor(){
	var allColors = all_exterior;
	var totalColors = allColors.length / size_extcd;

	for(var i = 0; totalColors - 1 >= i; i++){
		var color = allColors.substring(0, size_extcd);
		allColors = allColors.substring(size_extcd);
		var state = all_exterior_state[ color ];
		
		if(state == "av"){
			return color;
		}
	}
	
	return "";
}

function getNextAvailableInteriorColor(){
	var allColors = all_interior;
	var totalColors = allColors.length / size_intcd;
	
	for(var i = 0; totalColors - 1 >= i; i++){
		var color = allColors.substring(0, size_intcd);
		allColors = allColors.substring(size_intcd);
		var state = all_interior_state[ color ];
		
		if(state == "av"){
			return color;
		}
	}
	
	return "";
}


// ////////////////////////////////////////////////////////////////////////////////
// ToolTip functions
// ////////////////////////////////////////////////////////////////////////////////


var cX = 0; var cY = 0;

function UpdateCursorPosition(e){ cX = e.pageX; cY = e.pageY;}

function UpdateCursorPositionDocAll(e){ cX = event.clientX; cY = event.clientY;}

if(document.all) { document.onmousemove = UpdateCursorPositionDocAll;}
else { document.onmousemove = UpdateCursorPosition;}

function AssignPosition(d,relLeft) {
	//Uses getX/getY functions from nav.js.
	d.style.left = (getX(relLeft)+10) + "px";
	d.style.top = (cY+18) + "px";
}

function HideContent(d) {
if(d.length < 1) { return; }
document.getElementById(d).style.display = "none";
}

function ShowContent(value,d) {
	var tooltip = document.getElementById(d);
	
	if (!tooltip) {
		//If our tooltip DIV does not exist, create it.
		var newdiv = document.createElement("div");
		newdiv.setAttribute("id","tooltip");
		document.body.appendChild(newdiv);
		
	}
	
	//assigning the value in the <DIV>
	for (var x = 0; x < tooltipText.length; x++){
		if (tooltipText[x].code == value){
			replaceContent('tooltip', tooltipText[x].description.innerHTML);
		}	
	}
if(d.length < 1) { return; }
var dd = document.getElementById(d);
var relLeft = document.getElementById("optionPackages");

AssignPosition(dd,relLeft);
dd.style.display = "block";
}


/* Tooltip Functions */
function text(code,description){
	this.code = code;
  	this.description = description;
	return true;
}

var tooltipText = new Array();

function assignTooltip(value){
tooltipText = value;
//alert('Assign Values done!');
//alert('first '+ tooltipText[0].code );
//alert('second '+ tooltipText[1].code);
//alert('third '+ tooltipText[2].code);

}
