// DYC
// $Id: dyc.js,v 1.15 2007/04/26 09:34:04 jsan Exp $

var level = 0;



var MARKET = getMarketFromUrl();
var LANGUAGE = getLanguageFromUrl();



var DYC_SELECTED        = "dyc_selected";
var DYC_DISABLED        = "dyc_disabled";
var DYC_PREVSELECTED    = "dyc_prevselected";
var DYC_PREVDISABLED    = "dyc_prevdisabled";
var DYC_PACKAGEFEATURES = "dyc_packagefeatures";
var DYC_CARID           = "dyc_carid";
var DYC_CARID_DIRECTORY = 6;
var CUR_CARID           = "carid";


/*
var debugMsg  = "";
if (debugType == "window")
{
	debugMsg ("<br/><br/>Start debug...");
}
*/

var debugWin = "";



function createDebugWindow ()
{
	var debugUrl = "/main/dyc_debug.html";
	
	if (!debugWin.closed  &&  debugWin.location)
	{
//		debugWin.location.href = debugUrl;
	}
	else
	{
		debugWin = window.open (
			debugUrl,
			"debugWin",
			"width=350,height=250,menubar=1,toolbar=1,status=1,scrollbars=1,resizable=1");
		if (!debugWin.opener)
			debugWin.opener = self;
	}
	if (window.focus)
	{
		debugWin.focus ()
	}
	
	return false;
}



function debugMsg (content)
{
	var win;
	var debugType = getDebugType ();
	
	if (debugType == "alert")
	{
		alert (content);
	}
	else if (debugType == "window")
	{
		createDebugWindow ();
		if (debugWin  &&  debugWin.addMessage)
		{
			debugWin.addMessage (level, content);
		}
	}
}



function getDebugType ()
{
	debugType = "basic";
	
	if (getParam ("debug") == "yes")
	{
		var form = getForm ("typeform");
		if (form  &&  form.debugtype)
		{
			debugType = form.debugtype.value;
		}
	}
	
	return debugType;
}



function setSelectedImages ()
{
	// see xsl/dyc/my06/car_js.xsl for the functions below
	setSelectedExterior ();
	setSelectedInterior ();
}



// global feature list
var _all_ftrs = new Array();

// Returns the feature specified by the ID, otherwise undefined.
function getFeature(id)
{
	for(var i = 0; i < _all_ftrs.length; i++)
	{
		if (_all_ftrs[i].id == id)
		{
			return _all_ftrs[i];
		}
	}
}



// Returns the feature specified by the code, otherwise undefined.
function getFeatureByCode(code)
{
	for(var i = 0; i < _all_ftrs.length; i++)
	{
		if (_all_ftrs[i].featurecode == code)
		{
			return _all_ftrs[i];
		}
	}
}



// ******** Start of Feature Object definition
// id = feature ID
// type = optional: RIM, INT_CLR, EXT_CLR
// code = O = option, P = package, F = standard, E = engine
function Feature (id, type, code)
{
	this.id = id;
	this.type = type;
	this.code = code;
	this.price = 0.0;
	this.name;
	this.desc; // description
	this.featurecode;
	
	// setting of the following MUST be done via the enable & select functions
	this.isSelected = false;
	this.isEnabled = true;
	
	// The following are optional arrays of feature IDs.
	// These define the feature dependencies.
	this.incl;
	this.inclBy;
	this.excl;
	this.req;
	this.reqBy;
	this.prevSelected = false;
	this.prevDisabled = false;
	
	// listener arrays
	this.listener; // listener object reference
	
	// optional associated graphical component
	this.component; 


	// -------> functions

	// Updates the enabled state.
	// Updates the associated graphical component, if any.
	this.enable = function(state)
	{
		if ((this.code != 'F'  ||  this.type == 'RIM'  ||  this.type == 'INT_CLR')  
			&&  state != this.isEnabled)
		{
			this.isEnabled = state;
			// inform the graphical component of the new state
			if (this.component)
			{
				this.component.enable (state);
			}
		}
	} // end enable(state)


	// Updates the selected state, if enabled.
	// Updates the associated graphical component, if any.
	// Updates all the dependencies according to this features selection state.
	// Updates the summary panel.
	// parameters:
	//	selected = true | false, the new selection state
	//  mediated = true | false, if true then dependencies are not checked
	this.select = function (selected, mediated) 
	{
		debugMsg ("select (" + selected + ", " + mediated + "): " + this.name + (this.featurecode == "PACKAGE" ? this.name : ""));
		++level;
			
		if ((this.code != 'F'  ||  this.type == 'RIM'  ||  this.type == 'INT_CLR')  
			&&  this.isEnabled  
			&&  selected != this.isSelected)
		{
			// update the affected features accordingly, i.e. the dependencies
			if (mediated)
			{
				// save state, but don't inform dependencies, handled by mediator
				this.isSelected = selected;
			}
			else if (selected)
			{
				// deselecting all features that are excluded by this feature
				this.deselectExcludedFeatures ();
				
				// deselect package members before selecting the package itself.
				// otherwise the prices for selected features will double.
				if (this.featurecode == 'PACKAGE')
				{
					this.disableSelectedPackageMembers ();
				}

				// this is done here because dependencies have to know if they were modified due to a package
				this.isSelected = true;

				// select and disable included features
				this.selectIncludedFeaturesWithRequired (false);
				this.selectIncludedFeaturesWithRequired (true);
				
				// enabling all features that are required by this feature
				this.enableSubFeatures ();

				if (this.featurecode == 'PACKAGE')
				{
					this.disablePackageMemberExclusions ();
				}
			}
			else   // !selected
			{
				this.deselectSubFeatures ();
				this.disableSubFeatures ();
				this.deselectIncludedFeatures ();
				this.enableIncludedFeatures ();
				
				// this is done here because dependencies have to know if the were modified due to a package
				this.isSelected = false;
				
				if (this.featurecode == 'PACKAGE')
				{
					this.enableSelectedPackageMembers ();
				}
			}

			// inform all listeners that this feature's selection state has changed
			if (this.listener)
			{
				for (var i = 0; i < this.listener.length; i++)
				{
					this.listener[i].featureListener (this);
				}
			}
			
			// inform the component of the new state
			if (this.component)
				this.component.select(selected);
			
			if (level <= 1)
			{
				setSelectedImages ();
				if (this.featurecode == 'PACKAGE'  &&  getParam ("debug") == "yes")
				{
					for (var i = 0; i < _all_ftrs.length; ++i)
					{
						var ftr = _all_ftrs[i];
						if (ftr)
						{
							if (ftr.type == "RIM")
							{
								alert (ftr.featurecode + ", " + ftr.prevSelected);
							}
						}
					}
				}
			}
		}
		--level;
		debugMsg ("done: select (" + selected + ", " + mediated + "): " + this.name + (this.featurecode == "PACKAGE" ? this.name : ""));

		if (getDebugType () == "window"  &&  level <= 1)
		{
			debugMsg ('<HR noshade="" size="1"/>');
		}
	} // end select(isSelected)
	
	
	
	this.enableSubFeatures = function ()
	{	
		// for debugging
		debugMsg ("starting - enableSubFeatures: " + this.name + (this.featurecode == "PACKAGE" ? this.name : ""));
		++level;

		if (this.reqBy)
		{
			for (var i = 0; i < this.reqBy.length; ++i)
			{
				var tmpFtr = getFeature (this.reqBy[i]);
					
				// * disable included package members
				// * enable options relying on this option
				//   as long as "this" is not a package
				if (tmpFtr  
					&&  (this.featurecode != "PACKAGE"
						||  (this.featurecode == "PACKAGE"  &&  this.incl  &&  this.incl.indexOf (tmpFtr.id) == -1))
					&&  (!tmpFtr.inclBy  ||  tmpFtr.length <= 0))
				{
					tmpFtr.enable (true);
				}
			}
		}
		
		// for debugging
		--level;
		debugMsg ("ending - enableSubFeatures: " + this.name + (this.featurecode == "PACKAGE" ? this.name : ""));
	}
	
	
	
	this.disableSubFeatures = function ()
	{
		// for debugging
		debugMsg ("starting - disableSubFeatures: " + this.name + (this.featurecode == "PACKAGE" ? this.name : ""));
		++level;

		if (this.reqBy)
		{
			for (var i = 0; i < this.reqBy.length; ++i)
			{
				var tmpFtr = getFeature (this.reqBy[i]);
				if (tmpFtr)
				{
					tmpFtr.enable (false);
				}
			}
		}

		// for debugging
		--level;
		debugMsg ("ending - disableSubFeatures: " + this.name + (this.featurecode == "PACKAGE" ? this.name : ""));
	}
	
	
	
	this.deselectSubFeatures = function ()
	{
		// for debugging
		debugMsg ("starting - deselectSubFeatures: " + this.name + (this.featurecode == "PACKAGE" ? this.name : ""));
		++level;

		if (this.reqBy)
		{
			for (var i = 0; i < this.reqBy.length; ++i)
			{
				var tmpFtr = getFeature (this.reqBy[i]);
				if (tmpFtr  &&  !tmpFtr.featureAlreadyIncluded (this.id))
				{
					tmpFtr.select (false);
				}
			}
		}

		// for debugging
		--level;
		debugMsg ("ending - deselectSubFeatures: " + this.name + (this.featurecode == "PACKAGE" ? this.name : ""));
	}
	
	
	
	this.featureAlreadyIncluded = function (id)
	{
		// for debugging
		++level;
		
		var selected = false;
		
		if (this.req)
		{
			for (var i = 0; i < this.req.length; ++i)
			{
				var tmpFtr = getFeature (this.req[i]);
				if (tmpFtr  &&  tmpFtr.id != id  &&  tmpFtr.isSelected)
				{
					selected = true;
				}
			}
		}

		// for debugging
		--level;
		
		return selected;
	}
	
	
	
	this.deselectExcludedFeatures = function ()
	{
		// for debugging
		debugMsg ("starting - deselectExcludedFeatures: " + this.name + (this.featurecode == "PACKAGE" ? this.name : ""));
		++level;

		if (this.excl)
		{
			for (var i = 0; i < this.excl.length; ++i)
			{
				var tmpFtr = getFeature (this.excl[i]);
				if (tmpFtr)
				{
					debugMsg ("deselecting " + tmpFtr.name);
					if (this.featurecode == 'PACKAGE'  &&  tmpFtr.isSelected)
					{
						tmpFtr.prevSelected = true;
					}

					if (this.featurecode == 'PACKAGE'  &&  !tmpFtr.isEnabled)
					{
						tmpFtr.prevDisabled = true;
					}

					tmpFtr.select (false);

					// does the feature have requirements?
					if (!tmpFtr.req)
					{
						// set enabled state to previous state
						ftrEnabled = tmpFtr.isEnabled;
					}
					else
					{
						// enable the feature if at least one requirement is met
						ftrEnabled = false;
						for(r = 0; r < tmpFtr.req.length; ++r)
						{
							var ftr = getFeature(tmpFtr.req[r]);

							if (ftr  &&  ftr.isSelected)
							{
								// set enabled state to previous state
								ftrEnabled = tmpFtr.isEnabled;
								break;
							}
						}
					}
					tmpFtr.enable (ftrEnabled);
				}
			}
		}

		// for debugging
		--level;
		debugMsg ("ending - deselectExcludedFeatures: " + this.name + (this.featurecode == "PACKAGE" ? this.name : ""));
	}
	
	
	
	this.disablePackageMemberExclusions = function ()
	{
		// for debugging
		++level;

		if (this.featurecode == "PACKAGE"  &&  this.incl)
		{
			for (var i = 0; i < this.incl.length; ++i)
			{
				var tmpFtr = getFeature (this.incl[i]);
				if (tmpFtr  &&  tmpFtr.excl)
				{
					tmpFtr.disableExcludedFeatures ();
				}
			}
		}

		// for debugging
		--level;
	}
	
	
	
	this.disableExcludedFeatures = function ()
	{
		// for debugging
		++level;

		if (this.excl)
		{
			for (var i = 0; i < this.excl.length; ++i)
			{
				var tmpFtr = getFeature (this.excl[i]);
				if (tmpFtr)
				{
					tmpFtr.enable (false)
				}
			}
		}

		// for debugging
		--level;
	}
	
	
	
	this.enableExcludedFeatures = function ()
	{
		// for debugging
		debugMsg ("starting - enableExcludedFeatures: " + this.name + (this.featurecode == "PACKAGE" ? this.name : ""));
		++level;

		if (this.excl)
		{
			for (var i = 0; i < this.excl.length; ++i)
			{
				var tmpFtr = getFeature (this.excl[i]);
				if (tmpFtr)
				{
					if (tmpFtr.prevDisabled)
					{
						tmpFtr.prevDisabled = !tmpFtr.prevDisabled;
					}
					else
					{
						debugMsg ("enabling " + tmpFtr.name);
						tmpFtr.enable (true)
					}
				}
			}
		}

		// for debugging
		--level;
		debugMsg ("ending - enableExcludedFeatures: " + this.name + (this.featurecode == "PACKAGE" ? this.name : ""));
	}
	
	
	
	this.selectIncludedFeaturesWithRequired = function (withReq)
	{
		// for debugging
		debugMsg ("starting: selectIncludedFeaturesWithRequired (" + withReq + "): " + this.name + (this.featurecode == "PACKAGE" ? this.name : ""));
		++level;

		if (this.incl)
		{
			for (var i = 0; i < this.incl.length; ++i)
			{
				var tmpFtr = getFeature (this.incl[i]);
				
				if (tmpFtr)
				{
					if ((withReq  &&  tmpFtr.req)
						|| (!withReq  &&  !tmpFtr.req))
					{
						debugMsg ("selecting included: " + tmpFtr.name);
						++level;
						
						if (!tmpFtr.inclBy)
							tmpFtr.inclBy = new Array ();
						if (arrayIndexOf (tmpFtr.inclBy, String (this.id)) == -1)
							tmpFtr.inclBy.push (this.id);

						// save previous rim
						if ((tmpFtr.type == "RIM"  ||  tmpFtr.type == "EXT_CLR"  ||  tmpFtr.type == "INT_CLR")
							&&  (tmpFtr.excl  ||  tmpFtr.isSelected))
						{
							if (tmpFtr.isSelected  ||  tmpFtr.prevSelected)
								tmpFtr.prevSelected = true;

							if (!tmpFtr.isEnabled  ||  tmpFtr.prevDisabled)
								tmpFtr.prevDisabled = true;

							if (tmpFtr.excl)
							{
								++level;
								
								var tmpFtr2;
								for (var j = 0; j < tmpFtr.excl.length; ++j)
								{
									tmpFtr2 = getFeature (tmpFtr.excl[j]);
									if (tmpFtr2)
									{
										tmpFtr2.prevDisabled = !tmpFtr2.isEnabled;
										tmpFtr2.prevSelected = tmpFtr2.isSelected || tmpFtr2.prevSelected;
										tmpFtr2.select (false);
										tmpFtr2.enable (false);
									}
								}
								
								--level;
							}
						}

						if (this.featurecode == 'PACKAGE'  &&  this.code == 'F')
						{
							if (!tmpFtr.isEnabled)
								tmpFtr.enable (true);
							tmpFtr.select (true, true);
							tmpFtr.enable (false);
						}
						else
						{
							
							//dtael testing...
							
							tmpFtr.prevDisabled = !tmpFtr.isEnabled;
							tmpFtr.enable (true);
							tmpFtr.select (true);
							tmpFtr.enable (false);
						}
						
						--level;
						debugMsg ("done selecting included: " + tmpFtr.name);
					}
				}
			}
		}

		// for debugging
		--level;
		debugMsg ("ending: selectIncludedFeaturesWithRequired (" + withReq + "): " + this.name + (this.featurecode == "PACKAGE" ? this.name : ""));
	}
	

	// added by eced 060828 refactored this code from the summary object.
	this.isPartOfPackage = function ()
	{
		
		for (var i = 0; i < _all_ftrs.length; ++i)
		{
			tmpFtr = _all_ftrs[i];
			// if this is a selected package, check it
			if (tmpFtr.featurecode == 'PACKAGE' &&  tmpFtr.incl
				&&  (tmpFtr.isSelected  ||  tmpFtr.code == 'F'))
			{
				for (var j = 0; j < tmpFtr.incl.length; ++j)
				{
					if (this.id == tmpFtr.incl[j])
					{
						debugMsg ('Feature ' + this.id + ', is included in pkg ' + tmpFtr.id);
						return true;
					}
				}
			}
		}
		
		return false;
	}
	
	this.deselectIncludedFeatures = function ()
	{
		// for debugging
		debugMsg ("starting - deselectIncludedFeatures: " + this.name + (this.featurecode == "PACKAGE" ? this.name : ""));
		++level;
		
		if (this.incl)
		{
			for (var i = 0; i < this.incl.length; ++i)
			{
				var tmpFtr = getFeature (this.incl[i]);
				if (tmpFtr)
				{
					if (tmpFtr.inclBy)
					{
						var index = arrayIndexOf (tmpFtr.inclBy, String (this.id));
						if (index != -1)
						{
							tmpFtr.inclBy.splice (index, 1);
						}
						
						debugMsg ("deselecting included feature: " + tmpFtr.featurecode);
						tmpFtr.enable (true);
						tmpFtr.select (false);
						
						// restore previous rim
						if ((tmpFtr.type == "RIM"  ||  tmpFtr.type == "EXT_CLR"  ||  tmpFtr.type == "INT_CLR")
							&&  tmpFtr.excl)
						{
							
							for (var j = 0; j < tmpFtr.excl.length; ++j)
							{
								var tmpFtr2 = getFeature (tmpFtr.excl[j]);

								// added by eced 060828 checks so that the replacement isn't a member of a package.
								if(tmpFtr2 && tmpFtr2.prevSelected && !tmpFtr2.isPartOfPackage())
								{
									tmpFtr2.enable (true);
									tmpFtr2.select (true);
									tmpFtr2.prevSelected = false;
									break;
								}
							}
						}
					}
				}
			}
		}

		// for debugging
		--level;
		debugMsg ("ending - deselectIncludedFeatures: " + this.name + (this.featurecode == "PACKAGE" ? this.name : ""));
	}
	
	
	
	this.enableIncludedFeatures = function ()
	{
		// for debugging
		debugMsg ("starting - enableIncludedFeatures: " + this.name + (this.featurecode == "PACKAGE" ? this.name : ""));
		++level;

		if (this.incl)
		{
			for (var i = 0; i < this.incl.length; ++i)
			{
				var tmpFtr = getFeature (this.incl[i]);
				if (tmpFtr)
				{
					debugMsg (tmpFtr.name + " enabled: " + !tmpFtr.prevDisabled);
					tmpFtr.enable (!tmpFtr.prevDisabled);
				}
			}
		}

		// for debugging
		--level;
		debugMsg ("ending - enableIncludedFeatures: " + this.name + (this.featurecode == "PACKAGE" ? this.name : ""));
	}
	
	
	
	this.enableSelectedPackageMembers = function ()
	{
		// for debugging
		debugMsg ("starting - enableSelectedPackageMembers: " + this.name + (this.featurecode == "PACKAGE" ? this.name : ""));
		++level;

		if (this.incl)
		{
			for (var i = 0; i < this.incl.length; ++i)
			{
				var tmpFtr = getFeature (this.incl[i]);
				
				if (tmpFtr)
				{
					if ((tmpFtr.inclBy  &&  tmpFtr.inclBy.length > 0)  
						||  tmpFtr.prevSelected)
					{
						debugMsg ("1 - " + tmpFtr.name + " - tmpFtr.select (true)");
						tmpFtr.select (true);

						debugMsg ("1 - " + tmpFtr.name + " - tmpFtr.prevSelected = false");
						tmpFtr.prevSelected = false;

						if (tmpFtr.inclBy  &&  tmpFtr.inclBy.length > 0)
						{
							debugMsg ("1 - " + tmpFtr.name + " - tmpFtr.enable (false), tmpFtr.disableExcludedFeatures ()");
							tmpFtr.enable (false);
							tmpFtr.disableExcludedFeatures ();
						}
					}
					else if (tmpFtr.prevDisabled)
					{
						debugMsg ("2 - " + tmpFtr.name + " - tmpFtr.enable (false)");
						tmpFtr.enable (false);

						debugMsg ("2 - " + tmpFtr.name + " - tmpFtr.prevDisabled = false");
						tmpFtr.prevDisabled = false;
					}
					else if (tmpFtr.req  && tmpFtr.req.length > 0)
					{
						var setEnabled = false;
						for (var j = 0; j < tmpFtr.req.length; ++j)
						{
							var tmpFtr2 = getFeature (tmpFtr.req[j]);
							if (tmpFtr2  &&  tmpFtr2.isSelected)
							{
								tmpFtr.prevDisabled = !tmpFtr.isEnabled;
								setEnabled = true;
							}
						}

						debugMsg ("3 - " + tmpFtr.name + " - tmpFtr.enable (" + setEnabled + ")");
						tmpFtr.enable (setEnabled);
					}
					else
					{
						debugMsg ("4 - " + tmpFtr.name + " - tmpFtr.enable (true)");
						tmpFtr.prevDisabled = !tmpFtr.isEnabled;
						tmpFtr.enable (true);
					}
					
					// enable possible features disabled before this action
					tmpFtr.enableExcludedFeatures ();
				}
			}
		}

		// for debugging
		--level;
		debugMsg ("ending - enableSelectedPackageMembers: " + this.name + (this.featurecode == "PACKAGE" ? this.name : ""));
	}

	
	
	this.disableSelectedPackageMembers = function ()
	{
		// for debugging
		debugMsg ("starting - disableSelectedPackageMembers: " + this.name + (this.featurecode == "PACKAGE" ? this.name : ""));
		++level;

		if (this.incl)
		{
			for (var i = 0; i < this.incl.length; ++i)
			{
				var tmpFtr = getFeature (this.incl[i]);
				if (tmpFtr)
				{
					if (tmpFtr.isSelected  ||  (tmpFtr.inclBy  &&  tmpFtr.inclBy.length <= 0))
						tmpFtr.prevSelected = tmpFtr.isSelected;

					debugMsg ("setting " + tmpFtr.name + " to enabled (true) and selected (false)");
					tmpFtr.prevDisabled = !tmpFtr.isEnabled;
					tmpFtr.enable (true);
					tmpFtr.select (false);
				}
			}
		}

		// for debugging
		--level;
		debugMsg ("ending - disableSelectedPackageMembers: " + this.name + (this.featurecode == "PACKAGE" ? this.name : ""));
	}

	
	
	// Updates all the features in the dependency list according to the epxression.
	// Checks if the dependency list is defined, otherwise does nothing.
	//   id = id of current feature, to avoid depending on itself
	//   list = the dependency list to be updated
	//   expr = the expression to perform on each dependency
	//          NOTE: the expr should refer to the feature as ftr
	//          EXAMPLE: expr = 'ftr.select(true);'
	this.updateDependencies = function(id, list, expr)
	{
		// for debugging
		++level;

		if (list)
		{
			for(var i = 0; i < list.length; i++)
			{
				if (list[i] != id)
				{
					var ftr = getFeature(list[i]);
					if (ftr)
					{
						eval(expr);
					}
					else
					{
						debug('Data error: unknown feature: '+list[i], 'ERROR');
					}
				}
				else
				{
					debug('Data Error: Skipping self dependency: '+id, 'ERROR');
				}
			}
		}

		// for debugging
		--level;
	}
	
	
	// toggles the features selection state via the select function
	this.click = function ()
	{
		if (this.isEnabled)
		{
			// features in groups can't be deselected
			if (this.type == 'EXT_CLR'  ||  this.type == 'INT_CLR'  ||  this.type == 'RIM')
			{
				if (!this.isSelected)
				{
					this.select(true);
				}
			}
			else
			{
				this.select(!this.isSelected);
			}
		}
		
		this.showConflictInformation ();
	}
	
	
	
	this.showConflictInformation = function ()
	{
		debugMsg ("isEnabled: " + this.isEnabled  + ", isSelected: " + this.isSelected)
//		if (!this.isSelected
//			||  (this.isSelected  &&  this.code == 'PO'  &&  this.inPkg))
		
		if (this.isEnabled)
		{
			return;
		}
		
		var msg1 = disabledGeneral + "\n";
		var msg2 = "";

		if (this.code == "PO")
		{
			if (this.inPkg  &&  (!this.isSelected  ||  this.type != "RIM"))
			{
				var stdPkg = false;
				var stdMsg = "";
				var optMsg = "";

				for (var j = 0; j  < this.inPkg.length; ++j)
				{
					var total = 0;
					var ftr = getFeature (this.inPkg[j]);

					if (ftr)
					{
						if (ftr.featurecode == 'PACKAGE'  &&  ftr.code == 'F')
						{
							stdPkg = true;
							stdMsg += '<IMG src="/main/image/dyc/conflict_bullet.gif" vspace="2" width="3" height="3"/>' 
								+ '<IMG src="../../spacer.gif" width="5" height="1"/>'
								+ ftr.name;
							stdMsg += "<BR/>\n";
							++total;
						}
						else
						{
							optMsg += '<IMG src="/main/image/dyc/conflict_bullet.gif" vspace="2" width="3" height="3"/>' 
								+ '<IMG src="../../spacer.gif" width="5" height="1"/>'
								+ ftr.name;

							// show helper links to add/remove required/dependent feature
							if (showHelpLinks  &&  !this.isSelected)
							{
								optMsg += " - " + helplinkAdd (helpLabelAdd, ftr);
							}
							else if (showHelpLinks  &&  this.isSelected  &&  this.type != "RIM"  &&  this.type != "EXT_CLR"  &&  this.type != "INT_CLR")
							{
								optMsg += " - " + helplinkRemove (helpLabelRemove, ftr);
							}
							optMsg += "<BR/>\n";
							++total;
						}
					}

					if (total > 0)
					{
						if (stdPkg)
						{
							msg1 = packageOption_included + ":\n";
							msg2 = stdMsg;
						}
						else
						{
							msg1 = (this.isSelected)
								? packageOption_included + ":\n"
								: packageOption_single + ":\n";
							msg2 = optMsg;
						}
					}
				}
			}
		}
		else if (this.req)
		{
			reqSelected = false;
			total = 0;
			msg2 = "";

			for (var j = 0; j < this.req.length; ++j)
			{
				var ftr = getFeature (this.req[j]);

				if (ftr)
				{
					if (ftr.isSelected)
					{
						reqSelected = true;
					}
					++total;
					msg2 += '<IMG src="/main/image/dyc/conflict_bullet.gif" vspace="2" width="3" height="3"/>' 
						+ '<IMG src="../../spacer.gif" width="5" height="1"/>'
						+ ftr.name;

					// show helper links to add this (and dependent features)
					if (showHelpLinks)
						msg2 += " - " + helplinkAdd (helpLabelAdd, ftr, this);

					msg2 += "<BR/>\n";
				}
			}

			if (!reqSelected)
			{
				msg1 += disabledRequired1 + " "
					+ (total > 1 ? disabledRequired2 + " " : "")
					+ disabledRequired3 + ":"
					+ "\n";
			}
		}
		else if (this.inclBy)
		{
			var total = 0;
			msg2 = "";

			for (var j = 0; j  < this.inclBy.length; ++j)
			{
				var ftr = getFeature (this.inclBy[j]);
				if (ftr)
				{
					msg2 += '<IMG src="/main/image/dyc/conflict_bullet.gif" vspace="2" width="3" height="3"/>' 
						+ '<IMG src="../../spacer.gif" width="5" height="1"/>'
						+ ftr.name + "<BR/>\n";
					++total;
				}

				if (total > 0)
				{
					msg1 = disabledIncluded + ":\n";
				}
			}
		}
		else if (this.excl)
		{
			exclSelected = false;
			total = 0;
			msg2 = "";

			var stdMsg = "";
			var optMsg = "";
			var stdPkg = false;

			for (var j = 0; j  < this.excl.length; ++j)
			{
				var ftr = getFeature (this.excl[j]);

				if (ftr  &&  ftr.inclBy  &&  ftr.inclBy.length > 0)
				{
					for (var k = 0; k < ftr.inclBy.length; ++k)
					{
						var ftr2 = getFeature (ftr.inclBy[k]);
						if (ftr2)
						{
							if (ftr2.code == 'F')
							{
								stdPkg = true;
								stdMsg += '<IMG src="/main/image/dyc/conflict_bullet.gif" vspace="2" width="3" height="3"/>' 
									+ '<IMG src="../../spacer.gif" width="5" height="1"/>'
									+ ftr2.name;
								stdMsg += "<BR/>\n";
								++total;
							}
							else
							{
								optMsg += '<IMG src="/main/image/dyc/conflict_bullet.gif" vspace="2" width="3" height="3"/>' 
									+ '<IMG src="../../spacer.gif" width="5" height="1"/>'
									+ ftr2.name;

								// show helper link to remove required/dependent feature
								if (showHelpLinks)
									optMsg += " - " + helplinkRemove (helpLabelRemove, ftr2, this);

								msg2 += "<BR/>\n";
								++total;
							}
						}
					}

					if (total > 0)
					{
						if (stdPkg)
						{
							msg1 = disabledGeneral 
								+ " " + disabledBlocking_included;
							msg2 = stdMsg;
						}
						else
						{
							msg1 = disabledBlocking + "\n";
							msg2 = optMsg;
						}
					}
				}
			}
		}

		if (msg2)
		{
			htmlstart = '<TABLE border="0" cellpadding="0" cellspacing="0" width="100%">';
			htmlstart += '<TR>';
			htmlstart += '  <TD width="1" bgcolor="#424242"><IMG src="/main/image/spacer.gif" width="1" height="1" alt="" border="0"/></TD>';
			htmlstart += '  <TD width="1" bgcolor="#424242"><IMG src="/main/image/spacer.gif" width="1" height="1" alt="" border="0"/></TD>';
			htmlstart += '  <TD width="24" bgcolor="#424242"><IMG src="/main/image/spacer.gif" width="24" height="1" alt="" border="0"/></TD>';
			htmlstart += '  <TD width="338" bgcolor="#424242"><IMG src="/main/image/spacer.gif" width="338" height="1" alt="" border="0"/></TD>';
			htmlstart += '  <TD width="25" bgcolor="#424242"><IMG src="/main/image/spacer.gif" width="25" height="1" alt="" border="0"/></TD>';
			htmlstart += '  <TD width="1" bgcolor="#424242"><IMG src="/main/image/spacer.gif" width="1" height="1" alt="" border="0"/></TD>';
			htmlstart += '  <TD width="2"><IMG src="/main/image/spacer.gif" width="2" height="1" alt="" border="0"</TD>';
			htmlstart += '</TR>';
			htmlstart += '<TR>';
			htmlstart += '  <TD width="1" bgcolor="#424242"><IMG src="/main/image/spacer.gif" width="1" height="1" alt="" border="0"/></TD>';
			htmlstart += '  <TD colspan="4" bgcolor="#CCCCCC"><IMG src="/main/image/spacer.gif" width="388" height="2" alt="" border="0"/></TD>';
			htmlstart += '  <TD width="1" bgcolor="#424242"><IMG src="/main/image/spacer.gif" width="1" height="1" alt="" border="0"/></TD>';
			htmlstart += '  <TD width="2"><IMG src="/main/image/spacer.gif" width="2" height="1" alt="" border="0"</TD>';
			htmlstart += '</TR>';
			htmlstart += '<TR>';
			htmlstart += '  <TD width="1" bgcolor="#424242"><IMG src="/main/image/spacer.gif" width="1" height="1" alt="" border="0"/></TD>';
			htmlstart += '  <TD colspan="4" bgcolor="#CCCCCC"><IMG src="/main/image/spacer.gif" width="388" height="23" alt="" border="0"/></TD>';
			htmlstart += '  <TD width="1" bgcolor="#424242"><IMG src="/main/image/spacer.gif" width="1" height="1" alt="" border="0"/></TD>';
			htmlstart += '  <TD width="2" bgcolor="#424242"><IMG src="/main/image/spacer.gif" width="2" height="23" alt="" border="0"/></TD>';
			htmlstart += '</TR>';


			htmlmiddle = '<TR>';
			htmlmiddle += '  <TD width="1" bgcolor="#424242"><IMG src="/main/image/spacer.gif" width="1" height="1" alt="" border="0"/></TD>';
			htmlmiddle += '  <TD colspan="2" bgcolor="#FFFFFF"><IMG src="/main/image/spacer.gif" width="24" height="1" alt="" border="0"/></TD>';
			htmlmiddle += '  <TD bgcolor="#FFFFFF"><IMG src="/main/image/spacer.gif" width="1" height="14" alt="" border="0"/></TD>';
			htmlmiddle += '  <TD bgcolor="#FFFFFF"></TD>';
			htmlmiddle += '  <TD width="1" bgcolor="#424242"><IMG src="/main/image/spacer.gif" width="1" height="1" alt="" border="0"/></TD>';
			htmlmiddle += '  <TD width="2" bgcolor="#424242"><IMG src="/main/image/spacer.gif" width="2" height="23" alt="" border="0"/></TD>';
			htmlmiddle += '</TR>';
			htmlmiddle += '<TR>';
			htmlmiddle += '  <TD width="1" bgcolor="#424242"><IMG src="/main/image/spacer.gif" width="1" height="1" alt="" border="0"/></TD>';
			htmlmiddle += '  <TD colspan="2" bgcolor="#FFFFFF"><IMG src="/main/image/spacer.gif" width="24" height="1" alt="" border="0"/></TD>';
			htmlmiddle += '  <TD bgcolor="#FFFFFF"><IMG src="/main/image/dyc/dependency_warning.gif" width="36" height="29" alt="" border="0"/><BR/>';
			htmlmiddle += '    <IMG src="/main/image/spacer.gif" width="1" height="11" alt="" border="0"/><BR/>';
			htmlmiddle += '  </TD>';
			htmlmiddle += '  <TD bgcolor="#FFFFFF"></TD>';
			htmlmiddle += '  <TD width="1" bgcolor="#424242"><IMG src="/main/image/spacer.gif" width="1" height="1" alt="" border="0"/></TD>';
			htmlmiddle += '  <TD width="2" bgcolor="#424242"><IMG src="/main/image/spacer.gif" width="2" height="23" alt="" border="0"/></TD>';
			htmlmiddle += '</TR>';
			htmlmiddle += '<TR>';
			htmlmiddle += '  <TD width="1" bgcolor="#424242"><IMG src="/main/image/spacer.gif" width="1" height="1" alt="" border="0"/></TD>';
			htmlmiddle += '  <TD colspan="2" bgcolor="#FFFFFF"><IMG src="/main/image/spacer.gif" width="24" height="1" alt="" border="0"/></TD>';
			htmlmiddle += '  <TD colspan="2" bgcolor="#FFFFFF"><SPAN class="smallheader">' + msg1 + '</SPAN><BR/>';
			htmlmiddle += '    <IMG src="/main/image/spacer.gif" width="1" height="9" alt="" border="0"/><BR/>';
			htmlmiddle += '    <SPAN class="smalltext">' + msg2 + '</SPAN>';
			htmlmiddle += '  </TD>';
			htmlmiddle += '  <TD width="1" bgcolor="#424242"><IMG src="/main/image/spacer.gif" width="1" height="1" alt="" border="0"/></TD>';
			htmlmiddle += '  <TD width="2" bgcolor="#424242"><IMG src="/main/image/spacer.gif" width="2" height="23" alt="" border="0"/></TD>';
			htmlmiddle += '</TR>';
			htmlmiddle += '<TR>';
			htmlmiddle += '  <TD width="1" bgcolor="#424242"><IMG src="/main/image/spacer.gif" width="1" height="1" alt="" border="0"/></TD>';
			htmlmiddle += '  <TD colspan="2" bgcolor="#FFFFFF"><IMG src="/main/image/spacer.gif" width="24" height="1" alt="" border="0"/></TD>';
			htmlmiddle += '  <TD bgcolor="#FFFFFF"><IMG src="/main/image/spacer.gif" width="1" height="15" alt="" border="0"/></TD>';
			htmlmiddle += '  <TD bgcolor="#FFFFFF"></TD>';
			htmlmiddle += '  <TD width="1" bgcolor="#424242"><IMG src="/main/image/spacer.gif" width="1" height="1" alt="" border="0"/></TD>';
			htmlmiddle += '  <TD width="2" bgcolor="#424242"><IMG src="/main/image/spacer.gif" width="2" height="23" alt="" border="0"/></TD>';
			htmlmiddle += '</TR>';
			htmlmiddle += '<TR>';
			htmlmiddle += '  <TD width="1" bgcolor="#424242"><IMG src="/main/image/spacer.gif" width="1" height="1" alt="" border="0"/></TD>';
			htmlmiddle += '  <TD colspan="2" bgcolor="#FFFFFF"><IMG src="/main/image/spacer.gif" width="24" height="1" alt="" border="0"/></TD>';
			htmlmiddle += '  <TD align="right" bgcolor="#FFFFFF">';

			closelabel = disabledClose;
			htmlmiddle += '    <TABLE border="0" cellpadding="0" cellspacing="0"><TR>'
						+ '<TD bgcolor="#FF9933"><IMG alt border="0" height="2" src="/main/image/spacer.gif" width="2"></TD>'
						+ '<TD bgcolor="#FF9933" colspan="4"><IMG alt border="0" height="2" src="/main/image/spacer.gif" width="2"></TD>'
						+ '<TD><IMG alt border="0" height="2" src="/main/image/spacer.gif" width="2"></TD>'
						+ '</TR>'
						+ '<TR>'
						+ '<TD bgcolor="#FF9933" width="2"><IMG alt border="0" height="15" src="/main/image/spacer.gif" width="2"></TD>'
						+ '<TD bgcolor="#FF9933" width="5"><IMG alt border="0" height="15" src="/main/image/spacer.gif" width="5"></TD>'
						+ '<TD bgcolor="#FF9933" valign="TOP" width="1"><NOBR><A class="whitelink" href="javascript:closeDependencyMessage()">' + closelabel + '</A></NOBR></TD>'
						+ '<TD bgcolor="#FF9933" valign="TOP"><IMG alt border="0" height="1" src="/main/image/spacer.gif" width="3" align="middle"><IMG alt border="0" height="15" src="/main/image/arrow_white.gif" width="15"></TD>'
						+ '<TD align="RIGHT" bgcolor="#FF9933" valign="TOP" width="1"><IMG alt border="0" height="1" src="/main/image/spacer.gif" width="1" align="middle"></TD>'
						+ '<TD bgcolor="#434343" width="2"><IMG alt border="0" height="15" src="/main/image/spacer.gif" width="2"></TD>'
						+ '</TR>'
						+ '<TR>'
						+ '<TD width="2"><IMG alt border="0" height="2" src="/main/image/spacer.gif" width="2"></TD>'
						+ '<TD bgcolor="#434343" colspan="4" width="NaN"><IMG alt border="0" height="2" src="/main/image/spacer.gif" width="2"></TD>'
						+ '<TD bgcolor="#434343" width="2"><IMG alt border="0" height="2" src="/main/image/spacer.gif" width="2"></TD>'
						+ '</TR>'
						+ '</TABLE>';
			htmlmiddle += '  </TD>';
			htmlmiddle += '  <TD bgcolor="#FFFFFF"></TD>';
			htmlmiddle += '  <TD width="1" bgcolor="#424242"><IMG src="/main/image/spacer.gif" width="1" height="1" alt="" border="0"/></TD>';
			htmlmiddle += '  <TD width="2" bgcolor="#424242"><IMG src="/main/image/spacer.gif" width="2" height="23" alt="" border="0"/></TD>';
			htmlmiddle += '</TR>';
			htmlmiddle += '<TR>';
			htmlmiddle += '  <TD width="1" bgcolor="#424242"><IMG src="/main/image/spacer.gif" width="1" height="1" alt="" border="0"/></TD>';
			htmlmiddle += '  <TD colspan="2" bgcolor="#FFFFFF"><IMG src="/main/image/spacer.gif" width="24" height="1" alt="" border="0"/></TD>';
			htmlmiddle += '  <TD bgcolor="#FFFFFF"><IMG src="/main/image/spacer.gif" width="1" height="25" alt="" border="0"/></TD>';
			htmlmiddle += '  <TD bgcolor="#FFFFFF"></TD>';
			htmlmiddle += '  <TD width="1" bgcolor="#424242"><IMG src="/main/image/spacer.gif" width="1" height="1" alt="" border="0"/></TD>';
			htmlmiddle += '  <TD width="2" bgcolor="#424242"><IMG src="/main/image/spacer.gif" width="2" height="23" alt="" border="0"/></TD>';
			htmlmiddle += '</TR>';


			htmlend = '<TR>';
			htmlend += '  <TD width="1" bgcolor="#424242"><IMG src="/main/image/spacer.gif" width="1" height="1" alt="" border="0"/></TD>';
			htmlend += '  <TD colspan="4" bgcolor="#CCCCCC"><IMG src="/main/image/spacer.gif" width="388" height="23" alt="" border="0"/></TD>';
			htmlend += '  <TD width="1" bgcolor="#424242"><IMG src="/main/image/spacer.gif" width="1" height="23" alt="" border="0"/></TD>';
			htmlend += '  <TD width="2" bgcolor="#424242"><IMG src="/main/image/spacer.gif" width="2" height="23" alt="" border="0"/></TD>';
			htmlend += '</TR>';
			htmlend += '<TR>';
			htmlend += '  <TD width="1" bgcolor="#424242"><IMG src="/main/image/spacer.gif" width="1" height="1" alt="" border="0"/></TD>';
			htmlend += '  <TD colspan="4" bgcolor="#CCCCCC"><IMG src="/main/image/spacer.gif" width="388" height="2" alt="" border="0"/></TD>';
			htmlend += '  <TD width="1" bgcolor="#424242"><IMG src="/main/image/spacer.gif" width="1" height="1" alt="" border="0"/></TD>';
			htmlend += '  <TD width="2" bgcolor="#424242"><IMG src="/main/image/spacer.gif" width="2" height="1" alt="" border="0"</TD>';
			htmlend += '</TR>';
			htmlend += '<TR>';
			htmlend += '  <TD width="1" bgcolor="#424242"><IMG src="/main/image/spacer.gif" width="1" height="1" alt="" border="0"/></TD>';
			htmlend += '  <TD width="1" bgcolor="#424242"><IMG src="/main/image/spacer.gif" width="1" height="1" alt="" border="0"/></TD>';
			htmlend += '  <TD width="24" bgcolor="#424242"><IMG src="/main/image/spacer.gif" width="24" height="1" alt="" border="0"/></TD>';
			htmlend += '  <TD width="338" bgcolor="#424242"><IMG src="/main/image/spacer.gif" width="338" height="1" alt="" border="0"/></TD>';
			htmlend += '  <TD width="25" bgcolor="#424242"><IMG src="/main/image/spacer.gif" width="25" height="1" alt="" border="0"/></TD>';
			htmlend += '  <TD width="1" bgcolor="#424242"><IMG src="/main/image/spacer.gif" width="1" height="1" alt="" border="0"/></TD>';
			htmlend += '  <TD width="2" bgcolor="#424242"><IMG src="/main/image/spacer.gif" width="2" height="1" alt="" border="0"</TD>';
			htmlend += '</TR>';
			htmlend += '<TR>';
			htmlend += '  <TD width="1"><IMG src="/main/image/spacer.gif" width="1" height="2" alt="" border="0"/></TD>';
			htmlend += '  <TD width="1"><IMG src="/main/image/spacer.gif" width="1" height="2" alt="" border="0"/></TD>';
			htmlend += '  <TD width="24" bgcolor="#424242"><IMG src="/main/image/spacer.gif" width="24" height="2" alt="" border="0"/></TD>';
			htmlend += '  <TD width="338" bgcolor="#424242"><IMG src="/main/image/spacer.gif" width="338" height="2" alt="" border="0"/></TD>';
			htmlend += '  <TD width="25" bgcolor="#424242"><IMG src="/main/image/spacer.gif" width="25" height="2" alt="" border="0"/></TD>';
			htmlend += '  <TD width="1" bgcolor="#424242"><IMG src="/main/image/spacer.gif" width="1" height="2" alt="" border="0"/></TD>';
			htmlend += '  <TD width="2" bgcolor="#424242"><IMG src="/main/image/spacer.gif" width="2" height="2" alt="" border="0"</TD>';
			htmlend += '</TR>';
			htmlend += "</TABLE>";

			reWriteLayer ("dependencymessage", htmlstart + htmlmiddle + htmlend);
			placeMessageWindow ();
			setVisibility ("dependencybackground", "visible");
			setVisibility ("dependencymessage", "visible");
		}
	}
	
	
	// Adds a listener function to this feature.
	// When this feature's selection state changes, the listening objects will
	// be informed via their supplied listener function, ex: obj.listener(feature)
	//   obj = listener object
	this.addListener = function(obj)
	{
		if (!this.listener) this.listener = new Array();
		this.listener[this.listener.length] = obj;
	}
	
	// register this feature
	_all_ftrs[_all_ftrs.length] = this;
} // end Feature(id, type, code)



function helplinkAdd (helpLabel, ftr1, ftr2)
{
	if (ftr1  &&  ftr2)
		return ' <A href="#" onclick="addAndLock (' + ftr1.id + ', ' + ftr2.id + '); return false;">' + helpLabel + '</A>';
	else if (ftr1)
		return ' <A href="#" onclick="addAndLock (' + ftr1.id + '); return false;">' + helpLabel + '</A>';
	else
		return "";
}




function helplinkRemove (helpLabel, removeFtr, addFtr)
{
	var args = removeFtr.id;
	if (addFtr)
	{
		args += ", " + addFtr.id;
	}
	
	return ' <A href="#" onclick="removeLocked (' + args + '); return false;">' + helpLabel + '</A>';
}



function addAndLock (ftr1Id, ftr2Id)
{
	var i = 0;
	if (ftr1Id)
	{
		var ftr = getFeature (ftr1Id);
		if (ftr)
		{
			ftr.select (true); 
		}
	}
	
	if (ftr2Id)
	{
		var ftr = getFeature (ftr2Id);
		if (ftr)
			ftr.select (true); 
		{
		}
	}

	clearAllBorders (); 
	initBorders (); 
	closeDependencyMessage ();
}



function removeLocked (removeFtrId, addFtrId)
{
	var removeFtr = getFeature (removeFtrId); 
	removeFtr.select (false); 
	
	if (addFtrId)
	{
		var addFtr = getFeature (addFtrId);
		if (addFtr)
		{
			addFtr.select (true); 
		}
	}
	
	clearAllBorders (); 
	initBorders (); 
	closeDependencyMessage ();
}


					
var myns4 = (document.layers)? true:false
var myie4 = (document.all)? true:false



function createConflictBackgroundLayer ()
{
	var winW = (myns4)? window.innerWidth  : document.body.scrollWidth;
	var winH = (myns4)? window.innerHeight : document.body.scrollHeight;
	var f = getObject ("dependencybackground");
	
	f.width = winW;
	f.height = winH;
	reWriteLayer ('dependencybackground', '<IMG src="/main/image/spacer.gif" height="' + winH + '" width="' + winW + '">');
}



function placeMessageWindow ()
{
	var msg = getObject ("dependencymessage");
	var w = msg.width;
	if (w.indexOf ("px"))
	{
		w = w.substring (0, w.indexOf ("px"));
	}
	var h = msg.height;
	if (h.indexOf ("px"))
	{
		h = h.substring (0, h.indexOf ("px"));
	}
	var winW = document.body.clientWidth;
	var winH = document.body.clientHeight;
	var midX = (winW - w) / 2;
	var midY = (winH - h) / 2;

	msg.top = Number (getScrollHeight () + midY) + "px";
	msg.left = midX + "px";
}



function getScrollHeight ()
{
	var deltaY = 0;
	
	if( typeof (window.pageYOffset) == 'number' ) 
	{
		//Netscape compliant
		deltaY = window.pageYOffset;
	} 
	else if (document.body  
		&&  document.body.scrollTop)
	{
		//DOM compliant
		deltaY = document.body.scrollTop;
	}
	else if (document.documentElement 
		&&  document.documentElement.scrollTop)
	{
		//IE6 standards compliant mode
		deltaY = document.documentElement.scrollTop;
	}

	return deltaY;
}
	
	


function closeDependencyMessage ()
{
	setVisibility ("dependencymessage", "hidden");
	setVisibility ("dependencybackground", "hidden");
}



// ******** Start Summary function definitions.
// Expects a global feature list called: _all_ftrs
// Expects an HTML form called DYC_SUMMARY with the following input fields:
//   EXTERIOR, INTERIOR, WHEELS, MET_PAINT, PACKAGES, OPTIONS, TOTAL

// dtae - addition of INT_CLR for MY07 refresh

function Summary()
{
	this.form;

	// listens for selection and deselection of features
	this.featureListener = function (ftr)
	{
		if (!this.form)
			this.form = document.forms['DYC_SUMMARY'];
		
		// check if feature is included in a selected package
		var partOfPkg = ftr.isPartOfPackage();

		// adjust the names and prices for interior, exterior, and wheels
		if (ftr.type == 'EXT_CLR')
		{
			if (ftr.isSelected)
			{
				if (!partOfPkg)
					this.adjustValue (this.form.elements['MET_PAINT'], ftr);
			}
			else
			{
				this.form.elements['MET_PAINT'].value = '';
			}
		}
		else if (ftr.type == 'INT_CLR')
		{
			if (!partOfPkg)
				this.adjustValue(this.form.elements['INT_CLR'], ftr);
		}
		else if (ftr.type == 'RIM')
		{
			if (!partOfPkg)
				this.adjustValue (this.form.elements['OPTIONS'], ftr);
		}
		else if (ftr.code == 'O'  &&  ftr.featurecode != 'PACKAGE')   // options and packages
		{
			if (!partOfPkg)
				this.adjustValue (this.form.elements['OPTIONS'], ftr);
		}
		else if (ftr.featurecode == 'PACKAGE')
		{
			if (!partOfPkg)
				this.adjustValue (this.form.elements['PACKAGES'], ftr);
		}
	
		if (!partOfPkg)
			this.adjustValue (this.form.elements['TOTAL'], ftr);
	} // end featureListener(ftr)


	
	// goes through all the selected features and updates the summary panel
	this.refresh = function ()
	{
	
		if (! this.form) this.form = document.forms['DYC_SUMMARY'];
		if (this.form)
		{

			// clear all summary values
			this.form.elements['MET_PAINT'].value = "";
			this.form.elements['INT_CLR'].value = ""; //dtae refresh07
			this.form.elements['OPTIONS'].value = "";

			// special case for summary page
			if (this.form.elements['PACKAGES']) 
				this.form.elements['PACKAGES'].value = "";
		
			// set base car price
			if (this.form.elements['PRICE'].value > 0)
			{
				this.form.elements['PRICE'].value = localizePrice (
					this.form.elements['PRICE'].value, 
					thousanddelimiter, 
					decimaldelimiter, 
					true);
				this.form.elements['TOTAL'].value = this.form.elements['PRICE'].value;
			}
			else
			{
				this.form.elements['TOTAL'].value = this.form.elements['PRICE'].value;
			}
	
			// update all selected features
			for(var i=0; i < _all_ftrs.length; i++)
			{
				if (_all_ftrs[i].isSelected)
				{
					this.featureListener(_all_ftrs[i]);
				}
			}
		}
	} // refresh()


	
	// *** private function
	// Adds 2 strings together as numbers, result is 0 if not a number
	// element = form element to start value in
	// ftr = Feature object
	// adjustment = + or -, an override for ftr.selected
	this.adjustValue = function(element, ftr, adjustment)
	{
		if (!element) 
			return "";

		var a = parseFloat (delocalizePrice (element.value, thousanddelimiter, decimaldelimiter));
		var b = parseFloat (ftr.price);
		if (isNaN(a)) 
			a = 0;
		if (isNaN(b)) 
			b = 0;
		var result = (ftr.isSelected) ? (a + b) : (a - b);
		result = localizePrice (result, thousanddelimiter, decimaldelimiter, true);
		
		element.value = (result == 0) ?  "" : result;
	} // adjustValue(element,ftr,adjustment)


	// *** private function
	// Adjusts the total price of options included in a package 
	// ftr = Feature object
	this.adjustPackage = function(ftr)
	{
		if (ftr.incl)
		{
			for(var i = 0; i < ftr.incl.length; i++)
			{
			}
		}
	} // adjustPackage(ftr)

} // Summary()



var summaryPanel = new Summary();
// ******** End of Summary function definitions.



// imgObjName = name of the HTML image object
// src = the source to be swapped into thh image object's source property.
function ImageSwapper(imgObjName, src)
{
	this.img;
	this.imgObjName = imgObjName;
	this.src = src;
	
	// functions
	this.featureListener = function()
	{
		if (!this.img) this.img = getImage(this.imgObjName);
		
		if (this.img)
		{
			this.img.src = this.src;
		}
		else
		{
			debug('ImageSwapper image object missing: '+this.imgObjName, 'ERROR');
		}
	} // end featureListener()
} // end ImageSwapper(imgObjName, src)



function FormBinding(formName, elemName)
{
	this.elem;
	this.formName = formName;
	this.elemName = elemName;

	this.featureListener = function(ftr)
	{
		debug( "updating binding: document.forms['"+this.formName+"'].elements['"+this.elemName+"']", 'DEBUG' );
		if (!this.elem) this.elem = eval("document.forms['"+this.formName+"'].elements['"+this.elemName+"']");
		this.elem.value = ftr.name;
	}
} // FormBinding(formName,elemName)



// sets the default for this feature type
function setDefaults (type)
{
	var def;
	
	// first, check packages for included features of 
	// the requested type
	for (var i = 0; i < _all_ftrs.length; ++i)
	{
		var tmpFtr = _all_ftrs[i];
		if (tmpFtr  &&  tmpFtr.featurecode == "PACKAGE"  
			&&  tmpFtr.incl 
			&& (tmpFtr.code == "F"
				||  (tmpFtr.code == "O"  &&  tmpFtr.isSelected)))
		{
			for (var j = 0; j < tmpFtr.incl.length; ++j)
			{
				var packageFtr = getFeature (tmpFtr.incl[j]);
				
				if (packageFtr  &&  packageFtr.type == type)
				{
					def = packageFtr;
				}
			}
		}
	}

	if (!def)
	{
		for(var i = 0; i < _all_ftrs.length; i++)
		{
			if (_all_ftrs[i].type == type)
			{
				// if a feature is selected, use that
				if (_all_ftrs[i].isSelected) 
					return;

				// get the first feature in the group
				if (!def) 
					def = _all_ftrs[i];

				// if a feature is standard, use that instead of the first feature
				if (_all_ftrs[i].code == 'F') 
					def = _all_ftrs[i];
			}

		}
	}
	
	if (def) 
	{
		var isDisabled = !def.isEnabled;
		if (isDisabled)
			def.enable (true)
		def.select(true);
		if (isDisabled)
			def.enable (false)

	}
} // end setDefaults(type)



// Expects the following:
//   - a global feature array called: _all_ftrs
//   - a selected feature array called: selected
//   - a disabled feature array called: disabled
//   - a form to exist called: DYC
//   - all form elements tied to features have feature IDs as names
//   - a summary panel javascript object must be defined, called summaryPanel
// Does the following:
//   - Sets the selected & enabled state of each feature as per the global lists.
//   - Disables features that don't have their required features.
//   - Creates the Component objects for all features.
function dycInit()
{
	// this information is saved in cookies as a comma separated list of IDs
	var dyc_selected     = getCookie (DYC_SELECTED);
	var dyc_disabled     = getCookie (DYC_DISABLED);
	var dyc_prevselected = getCookie (DYC_PREVSELECTED);
	var dyc_prevdisabled = getCookie (DYC_PREVDISABLED);
	var dyc_carid        = getCookie (DYC_CARID);
	var cur_carid        = getDirectoryFromUrl (DYC_CARID_DIRECTORY);

	debugMsg ("dyc_selected:" + dyc_selected + "\n"
		+ "dyc_disabled:" + dyc_disabled + "\n"
		+ "dyc_prevselected:" + dyc_prevselected + "\n"
		+ "dyc_prevdisabled:" + dyc_prevdisabled + "\n"
		+ "dyc_carid:" + dyc_carid + "\n"
		+ "cur_carid:" + cur_carid);
	
	if (!cur_carid || (dyc_carid && (dyc_carid == cur_carid)))
	{
		// set the selected state of each feature
		initStandardPackages ();
		initSelectedFeatures (dyc_selected);
		initSelectedSubFeatures (dyc_selected);
	
		// set the enabled state of each feature
		initDisabledFeatures (dyc_disabled);
		initPreviouslySelected (dyc_prevselected);
		initPreviouslyDisabled (dyc_prevdisabled);
	}
	else
	{
		// not the same car in the cookies, so remove those
		deleteCookie (DYC_SELECTED);
		deleteCookie (DYC_DISABLED);
		deleteCookie (DYC_PACKAGEFEATURES);
		deleteCookie (DYC_PREVSELECTED);
		deleteCookie (DYC_PREVDISABLED);
		deleteCookie (DYC_CARID);
		
		initStandardPackages ();
	}
	
	// - Disable features if any of their required features are not selected.
	// - Add the Summary panel listener to each feature.
	// - Add the interior, exterior, and rim listeners
	disableRequiredSubFeatures ();
	
	// adjust the spec group selection dropdown, if it is available
	// this is only in step 2
	setSpecgroupDropdownDefault ();
	
	setDefaults ('EXT_CLR');
	setDefaults ('INT_CLR');
	setDefaults ('RIM');
	refreshCheckboxes ();
	summaryPanel.refresh ();
	setSelectedImages ();
} // end dycInit()



function initSelectedFeatures (dyc_selected)
{
	if (dyc_selected)
	{
		selected = eval('new Array (' + dyc_selected + ');');
		for(var j = 0; j < selected.length; ++j)
		{
			var ftr = getFeature (selected[j]);
			
			if (ftr)
			{
				ftr.select (true, true);
			}
			else 
			{
				debug('init:data error: invalid feature: '+selected[j], 'ERROR');
			}
		}
	}
}



function initSelectedSubFeatures (dyc_selected)
{
	if (dyc_selected)
	{
		selected = eval('new Array (' + dyc_selected + ');');
		for(var j = 0; j < selected.length; ++j)
		{
			var ftr = getFeature (selected[j]);
			
			if (ftr)
			{
				ftr.selectIncludedFeaturesWithRequired (false);
				ftr.selectIncludedFeaturesWithRequired (true);
			}
			else 
			{
				debug('init:data error: invalid feature: '+selected[j], 'ERROR');
			}
		}
	}
}



function initStandardPackages ()
{
	for(var j = 0; j < _all_ftrs.length; ++j)
	{
		var ftr = _all_ftrs[j];

		if (ftr)
		{
			if (ftr.featurecode == 'PACKAGE'  &&  ftr.code == 'F')
			{
				ftr.selectIncludedFeaturesWithRequired (false);
				ftr.selectIncludedFeaturesWithRequired (true);
			}
		}
		else 
		{
			debug('init:data error: invalid feature: '+selected[j], 'ERROR');
		}
	}
}



function initDisabledFeatures (dyc_disabled)
{
	if (dyc_disabled)
	{
		disabled = eval('new Array('+dyc_disabled+');');

		for (j = 0; j < disabled.length; ++j)
		{
			var ftr = getFeature (disabled[j]);
			if (ftr)
			{
				ftr.enable (false);
//				ftr.deselectExcludedFeatures ();
//				ftr.disableExcludedFeatures ();
			}
		}
	}
}



function initPreviouslySelected (dyc_prevselected)
{
	if (dyc_prevselected)
	{
		var prevSelected = eval('new Array(' + dyc_prevselected + ');');

		for (j = 0; j < prevSelected.length; ++j)
		{
			var ftr = getFeature (prevSelected[j]);
			if (ftr)
			{
				ftr.prevSelected = "true";
			}
		}
	}
}



function initPreviouslyDisabled (dyc_prevdisabled)
{
	if (dyc_prevdisabled)
	{
		var prevDisabled = eval('new Array(' + dyc_prevdisabled + ');');

		for (j = 0; j < prevDisabled.length; ++j)
		{
			var ftr = getFeature (prevDisabled[j]);
			if (ftr)
			{
				ftr.prevDisabled = "true";
			}
		}
	}
}



function disableRequiredSubFeatures ()
{
	for(j = 0; j < _all_ftrs.length; ++j)
	{
		// add the summary panel listener
		_all_ftrs[j].addListener (summaryPanel);
		
		// does the feature have requirements?
		if (_all_ftrs[j].req)
		{
			// enable the feature if at least one requirement is met
			ftrEnabled = false;
			for(r = 0; r < _all_ftrs[j].req.length; ++r)
			{
				var ftr = getFeature(_all_ftrs[j].req[r]);
				
				if (ftr  &&  (ftr.isSelected  ||  ftr.code == 'F'))
				{
					ftrEnabled = true;
					break;
				}
			}
			_all_ftrs[j].enable (ftrEnabled);
		}
	}
}



function setSpecgroupDropdownDefault ()
{
	var specgroup = getParam ('specgroup');
	var formSpecGroup = getForm ('specgroup');
	
	if (formSpecGroup  &&  specgroup)
	{
		var dropdown = eval ("document.forms['specgroup'].specgroup");
		var idx = 0;
    	for(var i = 0; i < dropdown.options.length; ++i)
		{
	    	if (dropdown.options[i].value == specgroup)
			{
				idx = i;
				break;
			}
    	}
		dropdown.selectedIndex = idx;
	}
}



// Saves the selected and disabled states in cookies
function saveState(carid)
{
	if (!carid  ||  carid == -1) carid = getDirectoryFromUrl (DYC_CARID_DIRECTORY);
	var dyc_selected = '';
	var dyc_disabled = '';

	for(var i=0; i < _all_ftrs.length; i++)
	{
		if (_all_ftrs[i].code != 'F'  ||  _all_ftrs[i].type == 'RIM'  ||  _all_ftrs[i].type == 'INT_CLR')
		{
			if (getDebugType () == "alert" && _all_ftrs[i].isSelected   &&  (!_all_ftrs[i].inclBy  ||  _all_ftrs[i].inclBy.length <= 0))
			{
				debugMsg ("selected: " + _all_ftrs[i].name);
			}
			if (_all_ftrs[i].isSelected  &&  (!_all_ftrs[i].inclBy  || _all_ftrs[i].inclBy.length <= 0))
			{
				dyc_selected = (dyc_selected) ? dyc_selected+",'"+_all_ftrs[i].id+"'" : "'"+_all_ftrs[i].id+"'";
			}
			if (!_all_ftrs[i].isEnabled)
			{ 
				dyc_disabled = (dyc_disabled) ? dyc_disabled+",'"+_all_ftrs[i].id+"'" : "'"+_all_ftrs[i].id+"'";
			}
		}
	}
	
	setCookie (DYC_SELECTED, dyc_selected);
	setCookie (DYC_DISABLED, dyc_disabled);
	setCookie (DYC_PACKAGEFEATURES, getPackageFeatures ());
	setCookie (DYC_PREVSELECTED, getPreviouslySelected ());
	setCookie (DYC_PREVDISABLED, getPreviouslyDisabled ());
	setCookie (DYC_CARID, carid);
	debugMsg (getCookie (DYC_SELECTED));
} // end saveState(carid)



/* 
 * get a string of all included feature for selected packages.
 * these features are not supposed to be included in the SQL
 * query to get all prices for selected features.
 *
 */
function getPackageFeatures ()
{
	var s = "";
	
	for (var i = 0; i < _all_ftrs.length; ++i)
	{
		var ftr = getFeature (_all_ftrs[i].id);
		if (ftr  &&  ftr.featurecode == 'PACKAGE'  &&  ftr.isSelected) 
		{
			for (var j = 0; ftr.incl  &&  j < ftr.incl.length; ++j)
			{
				var tmpFtr = getFeature (ftr.incl[j]);
				if (tmpFtr)
				{
					if (s != '')
					{
						s += ',';
					}
					s += "'" + tmpFtr.id + "'";
				}
			} 
		}
	}
	
	return s;
}



function getPreviouslySelected ()
{
	var s = "";
	
	for (var i = 0; i < _all_ftrs.length; ++i)
	{
		var ftr = _all_ftrs[i];
		if (ftr  &&  ftr.prevSelected
			&&  (ftr.type == "RIM"  ||  ftr.type == "EXT_CLR"  ||  ftr.type == "INT_CLR"))
		{
			if (s != '')
			{
				s += ',';
			}
			s += "'" + ftr.id + "'";
		}
		else if (ftr  &&  ftr.featurecode == 'PACKAGE'  &&  ftr.isSelected) 
		{
			for (var j = 0; ftr.incl  &&  j < ftr.incl.length; ++j)
			{
				var tmpFtr = getFeature (ftr.incl[j]);
				if (tmpFtr  &&  tmpFtr.prevSelected)
				{
					if (s != '')
					{
						s += ',';
					}
					s += "'" + tmpFtr.id + "'";
				}
			} 
		}
	}
	
	return s;
}



function getPreviouslyDisabled ()
{
	var s = "";
	
	for (var i = 0; i < _all_ftrs.length; ++i)
	{
		var ftr = _all_ftrs[i];
		if (ftr  &&  ftr.prevDisabled
			&&  (ftr.type == "RIM"  ||  ftr.type == "EXT_CLR"  ||  ftr.type == "INT_CLR"))
		{
			if (s != '')
			{
				s += ',';
			}
			s += "'" + ftr.id + "'";
		}
		else if (ftr  &&  ftr.featurecode == 'PACKAGE'  &&  ftr.isSelected) 
		{
			for (var j = 0; ftr.incl  &&  j < ftr.incl.length; ++j)
			{
				var tmpFtr = getFeature (ftr.incl[j]);
				if (tmpFtr  &&  tmpFtr.prevDisabled  &&  s.indexOf (tmpFtr.id) < 0)
				{
					if (s != '')
					{
						s += ',';
					}
					s += "'" + tmpFtr.id + "'";
				}
			} 
		}
	}
	
	return s;
}



function arrayIndexOf (arr, val)
{
	var index = -1;
	
	if (arr)
	{
		for (var i = 0; i < arr.length; ++i)
		{
			if (arr[i] == val)
			{
				index = i;
				break;
			}
		}
	}
	
	return index;
}



function showDisabled ()
{
	for (var i = 0; i < _all_ftrs.length; ++i)
	{
		var ftr = _all_ftrs[i];
		if (ftr  &&  !ftr.isEnabled)
		{
			debugWin ("disabled feature: " + ftr.name + " (" + ftr.id + ")");
		}
	}
}



function arrIndexOf (item)
{
        var pos = -1;
        if (this)
        {
        	for (var i = 0; i < this.length; ++i)
        	{
        		if (this[i] == item)
        		{
        			pos = i;
        			break;
        		}
        	}
        }
        
        return pos;
}
if (typeof Array.prototype.indexOf == "undefined")
{
        Array.prototype.indexOf = arrIndexOf;
}



function arrPush (item)
{
        this[this.length] = item;
}
if (typeof Array.prototype.push == "undefined")
{
        Array.prototype.push = arrPush;
}



function arrSplice (index, delTotal)
{
        var arr = new Array ();
        var ret = new Array ();
        var i = 0;

        // copy the elements before the first element to splice away
        for (i = 0; i < index; ++i)
        {
                arr[i] = this[i];
        }

        // copy the elements after the last element to splice away
        for (i = index + delTotal; i < this.length; ++i)
        {
                arr[arr.length] = this[i]
        }

        // copy the elements that are spliced away
        for (i = 0; i < delTotal; ++i)
        {
                ret[i] = this[index + i];
        }

        // copy the temp array to the current
        this.length = 0
        for (i = 0; i < arr.length; ++i)
        {
                this[this.length] = arr[i]
        }

        return ret;
}
if (typeof Array.prototype.splice == "undefined")
{
        Array.prototype.splice = arrSplice;
}



function getSelectedOfType (ftype)
{
	var ftr;
	var s = "";
	var i = 0;
	var j = 0;
	for (i = 0; i < _all_ftrs.length; ++i)
	{
		var tmpFtr = _all_ftrs[i];
		
		if (tmpFtr  &&  tmpFtr.type == ftype  
			&&  (tmpFtr.isSelected  ||  (ftype == "ENG"  &&  tmpFtr.code == "E")))
		{
			ftr = tmpFtr;
			break;
		}
		else if (tmpFtr  &&  tmpFtr.type == "PACKAGE"  &&  tmpFtr.incl)
		{
			for (j = 0; j < tmpFtr.incl.length; ++j)
			{
				var packageFtr = tmpFtr.incl[i];
				if (packageFtr.type == "RIM"  &&  packageFtr.isSelected)
				{
					ftr = packageFtr;
				}
			}
		}
	}
	
	
	
	return (ftr) ? ftr : "";
	
}



function setSaveForm ()
{
	var selected = "";
	var total = 0;
	var form = getForm ("DYC_SUMMARY");
	
	for (var i = 0; i < _all_ftrs.length; ++i)
	{
		var ftr = _all_ftrs[i];
		if (ftr  &&  ftr.isSelected)
		{
			if (selected != "")
				selected += ",";
			selected += ftr.id;
			total += Number (ftr.price);
		}
	}
	
	form.FEATURE.value = selected;
	form.TOTAL.value = total;
	form.CARID.value = carid;
}



function openExtended(id, modelcode)
{
	upDir = (location.href.indexOf ("step2.shtml") > 0)
		? "../../"
		: "../../../";
	newWindow = window.open(upDir + "model/" + modelcode + "/" + id + "/fc_extended.shtml","Saab","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=no,width=403,height=492");
	newWindow.focus ();
}


function updateFeatureName (featureType)
{
	var name = "name" + featureType;
	reWriteLayer (name, getSelectedOfType (featureType).name);
}



function initFeatureNames()
{
	updateFeatureName ("EXT_CLR");
	updateFeatureName ("INT_CLR");
	updateFeatureName ("RIM");
}



function createSummary ()
{
//	getSelectedOfType ("EXT_CLR");
	var html = '';
	var ftr = '';
	var total = 0;
	var engine = getSelectedOfType ("ENG");
	

	// General options and features
	html = '<TABLE border="0" cellpadding="0" cellspacing="0" width="100%">';
	//html += tableHeader (summarytitle + ' ' + summarymodelname + ' ' + summarycarname)
	html += tableSpacer (10);
	html += tableHeader ("&#160;"+summarymodeltrimengine, "left", "color:#FFFFFF;")
	html += lightGrayLine ();
	html += tableSpacer (4);
	html += tableRowStart (3);
	//html += tableCell (summarymodelname + ' ' + '<A href="javascript:openExtended(' + engine.id + ',\'' + summarymodelcode + '\');">' + summarycarname + '</A>', 'smalltext');
	html += tableCell (summarymodelname + ' ' + summarycarname, 'smalltext');
	if (summarycarprice > 0)
		html += tableCell (getPrice (summarycarprice) + disclaimersymbol, 'smalltext', 'right');
	html += tableRowEnd (8);
	html += tableSpacer (5);
	html += lightGrayLine ();
	html += tableSpacer (25)
	total += Number (summarycarprice);

	// Exterior and interior
	html += tableHeader ("&#160;"+summaryextint, "left", "color:#FFFFFF;")
	html += lightGrayLine ();
	
	ftr = getSelectedOfType ("EXT_CLR");
	html += tableSpacer (4);
	html += tableRowStart (3);
	html += tableCell (ftr.name, 'smalltext');
	if (ftr.price > 0)
		html += tableCell (getPrice (ftr.price) + disclaimersymbol, 'smalltext', 'right');
	html += tableRowEnd (8);
	html += tableSpacer (5);
	html += lightGrayLine ();
	total += Number (ftr.price);

	ftr = getSelectedOfType ("INT_CLR");
	html += tableSpacer (4);
	html += tableRowStart (3);
	html += tableCell (ftr.name, 'smalltext');
	if (ftr.price > 0  &&  !inPackage (ftr))
	{
		html += tableCell (getPrice (ftr.price) + disclaimersymbol, 'smalltext', 'right');
		total += Number (ftr.price);
	}
	html += tableRowEnd (8);
	html += tableSpacer (5);
	html += lightGrayLine ();

	ftr = getSelectedOfType ("RIM");
	html += tableSpacer (4);
	html += tableRowStart (3);
	html += tableCell (ftr.name, 'smalltext');
	if (ftr.price > 0  &&  !inPackage (ftr))
	{
		html += tableCell (getPrice (ftr.price) + disclaimersymbol, 'smalltext', 'right');
		total += Number (ftr.price);
	}
	html += tableRowEnd (8);
	html += tableSpacer (5);
	html += lightGrayLine ();
	html += tableSpacer (25)


	// All other options
	var firstOption = true;
	var hasOptions = false;
	
	for (var i = 0; i < _all_ftrs.length; ++i)
	{
		var ftr = _all_ftrs[i];
		if (ftr  
			&&  ftr.isSelected
			&&  (ftr.type != 'EXT_CLR'  &&  ftr.type != 'INT_CLR'  &&  ftr.type != 'RIM')
			&&  !inPackage (ftr))
		{
			if (firstOption)
			{
				html += tableHeader ("&#160;"+summaryoptions, "left", "color:#FFFFFF;");
				html += lightGrayLine ();
				firstOption = false;
				hasOptions = true;
			}

			html += tableSpacer (4);
			html += tableRowStart (3);
			html += tableCell (ftr.name, 'smalltext');
			if (ftr.price > 0)
				html += tableCell (getPrice (ftr.price) + disclaimersymbol, 'smalltext', 'right');
			html += tableRowEnd (8);
			html += tableSpacer (5);
			html += lightGrayLine ();
			
			total += Number (ftr.price);
		}
	}
    
	if (hasOptions)
	{
		html += tableSpacer (25)
	}
	
	if (total > 0)
	{
		// Total cost
		html += lightGrayLine ();
		html += tableSpacer (4);
		html += tableRowStart (3);
		html += tableCell (summarytotal, 'smallheader');
		html += tableCellNoWrap (getPrice (total) + disclaimersymbol, 'smallheader', 'right');
		html += tableRowEnd (8);
		html += tableSpacer (5);
		html += lightGrayLine ();
		
		if (disclaimertext!='') {
			html += tableHeader (disclaimertext, "right", "font-style: italic;");
		}
		
		html += tableSpacer (25)
	}
	//html += tableRowStart (3);
	//html += tableCell ('', 'smallheader', '', 250);
	//html += tableCell ('', 'smallheader', 'right', 89);
	//html += tableRowEnd (8);
	html += '</TABLE>';
	
	reWriteLayer ("summarylayer", html);
}

function getPrice (msrp)
{
	var s = "";
	
	if (Number (msrp) > 0)
	{
		s = localizePrice (msrp, thousanddelimiter, decimaldelimiter, true);
	}
	
	return s;
}



function localizePrice (val, sepThousands, sepDecimal, intOnly)
{
	var s = String (Number (val));
	var i = s.indexOf (".");
	var s1 = "0";
	var s2 = "00";
	var ret = "";

	if (val == ""  ||  isNaN (val)  ||  val == "0")
	{
		ret = s1 + (intOnly ? "" : sepDecimal + s2);
	}
	else
	{
		if (i > 0)
		{
			s1 = s.substring (0, i);
			s2 = s.substring (i + 1, s.length);
		}
		else
		{
			s1 = s;
		}


		if (sepThousands == "")
		{
			ret = s1;
		}
		else
		{
			while (s1.length > 3)
			{
				ret = s1.substring (s1.length - 3, s1.length)
					+ (ret.length > 0 ? sepThousands : "")
					+ ret;
				s1 = s1.substring (0, s1.length - 3);
			}
			ret = (ret.length > 0) ? s1 + sepThousands + ret : s1;
		}
		
		ret += (intOnly ? "" : sepDecimal + s2);

		if (currencyprefix == "&#128;")
		{
			currencyprefix = 'Euro';
		}
		else if (currencysuffix == "&#128;")
		{
			if (MARKET = 'FR') {
				currencysuffix = 'Euros';
			} else {
				currencysuffix = 'Euro';
			}
		}
		if (currencyprefix != "")
		{
			ret = currencyprefix + " " + ret;
		}
		if (currencysuffix != "")
		{
			ret += " " + currencysuffix;
		}
	}
	
	return ret;
}



function delocalizePrice (val, sepThousands, sepDecimal)
{
	var ret = String (val);
	var regexp;
	
	if (sepThousands == ".")
		sepThousands = "\\" + sepThousands;

	regexp = new RegExp (sepThousands, "gi");
	ret = ret.replace (regexp, "");
	
	if (sepDecimal != ".")
	{
		regexp = new RegExp (sepDecimal, "gi");
		ret = ret.replace (regexp, ".");
	}

	if (currencyprefix != ""  &&  ret != "")
	{
		var prefix = currencyprefix;
		regexp = new RegExp ("\\$", "gi");
		prefix = prefix.replace (regexp, "\\$");
		
		regexp = new RegExp (prefix, "gi");
		ret = ret.replace (regexp, "");
	}
	if (currencysuffix != ""  &&  ret != "")
	{
		var suffix = currencysuffix;
		regexp = new RegExp ("\\$", "gi");
		suffix = suffix.replace (regexp, "\\$");
		
		regexp = new RegExp (suffix, "gi");
		ret = ret.replace (regexp, "");
	}
	
	return ret;
}



function tableHeader (s, align, style)
{
	return ''
		+ '<TR>'
		+ '<TD colspan="4" align="' + align + '" bgcolor="#92A5B4">'
		+ '<B><SPAN class="featuretext" style="' + style + '">' + s + '</SPAN><B><BR/>'
		+ '<IMG src="/main/image/spacer.gif" width="1" height="2"/>'
		+ '</TD>'
		+ '</TR>';
}



function lightGrayLine ()
{
	return ''
		+ '<TR>'
		+ '<TD colspan="4" height="1" bgcolor="#CCCCCC"><IMG src="/main/image/spacer.gif" width="1" height="1"/></TD>'
		+ '</TR>'
		+ '<TR>';
}



function tableSpacer (height)
{
	return ''
		+ '<TR>'
		+ '<TD colspan="4" height="' + height + '"><IMG src="/main/image/spacer.gif" width="1" height="' + height + '"/></TD>'
		+ '</TR>';
}



function tableRowStart (width)
{
	return ''
		+ '<TR>'
		+ '<TD width="' + width + '"><IMG src="/main/image/spacer.gif" width="' + width + '" height="1"/></TD>';
}



function tableRowEnd (width)
{
	return ''
		+ '<TD width="' + width + '"><IMG src="/main/image/spacer.gif" width="' + width + '" height="1"/></TD>'
		+ '</TR>';
}



function tableCell (s, style, align, cellWidth)
{
	var alignment = align ? align : "left";

	return ''
		+ '<TD class="' + style + '" align="' + alignment + '"'
		+ ((cellWidth  &&  cellWidth != ''  &&  cellWidth != 0) ? ' width="' + cellWidth + '"' : '')
		+ '>'
		+ s
		+ ((cellWidth  &&  cellWidth != ''  &&  cellWidth != 0) ? '<img src="/main/image/spacer.gif" width="' + cellWidth + '" height="1" border="0"/>' : '')
		+ '</TD>';
}



function tableCellNoWrap (s, style, align)
{
	var alignment = align ? align : "left";

	return ''
		+ '<TD class="' + style + '" align="' + alignment + '" nowrap="">'
		+ s
		+ '</TD>';
}



function inPackage (ftr)
{
	var partOfPkg = false;
	for (var i = 0; i < _all_ftrs.length; ++i)
	{
		var pkgFtr = _all_ftrs[i];
		// if this is a selected package, check it
		if ((pkgFtr.isSelected  ||  pkgFtr.code == 'F')  &&  pkgFtr.featurecode == 'PACKAGE'  &&  pkgFtr.incl)
		{
			for (var j = 0; j < pkgFtr.incl.length; ++j)
			{
				if (ftr.id == pkgFtr.incl[j])
				{
					partOfPkg = true;
					debug ('Not counting ftr ' + ftr.id + ', included in pkg ' + _all_ftrs[i].id, 'DEBUG');
					break;
				}
			}
		}
	}
	
	return partOfPkg;
}
