/* finds value identified by id = intValueID from the attribute
storage array */
	
	function getValueFromAttributeArray(intValueID) {
		var i=0;
		var thisValue = 0;
		if (oAttribute) {
			for(i=0; i < oAttribute.length; i++) {
				thisValue = oAttribute[i];
				if (thisValue.valyuID == intValueID)
					return thisValue;
			}
		}
		return 0;
	}

	

/* changes page to show configuration identified by passed value ID */
		
	function showOption(intValueID) {
		var oValue = getValueFromAttributeArray(intValueID);
		if (oValue) {
	
			// swap image
			var sourceImage = oValue.img;
			var oBigImage = document.images["bigImage"];
			if (sourceImage && oBigImage)
				{oBigImage.src = sourceImage.src;}
				
	
			// swapReadout
			changeReadout(oValue);
		}
	}

/* runs showOption against stored selected value */
	
	function showSelectedOption() {
		if (oSelectedValue && oSelectedValue.valyuID) {
			showOption(oSelectedValue.valyuID);
		}
		else
		{
			showOption(0);
		}
	}
		
	
/* runs when an option is selected, stores a bunch of variables
in document and in form fields */
	
	function selectOption(oClickedImage,intValueID) {
		
		// store selected ID
		intSelectedValueID = intValueID;
		
		// change hidden field
		var oValue = getValueFromAttributeArray(intValueID);
		var oID = document.forms["chooseValue"].elements["valyuID"];
		if (oID && oValue && oValue.valyuID) {
			oID.value = oValue.valyuID;
		}
		
		// deselect the clicked image
		if (oSelectedValue && oSelectedValue.clickedImage) {
			oSelectedValue.clickedImage.className = null;
		}
		
		// store the new selected value and clicked image reference
		if (oValue) {
			oSelectedValue = oValue;
			oSelectedValue.clickedImage = oClickedImage;
			
			// calculate the price text field
			if (oAttribute.startPrice && !isNaN(oAttribute.startPrice) && oValue.priceModifier && !isNaN(oValue.priceModifier)) {
				oSelectedValue.price = parseInt(oAttribute.startPrice) + parseInt(oValue.priceModifier);
			}		
		}
		
		// change the class of the clicked image
		if (oClickedImage) {
			oClickedImage.className = "selected";
		}
		
		// turn the submit button on
		document.all.mySubmit.src = oMySubmit.img.src;
		document.all.mySubmit.disabled = false;
	}
	

/* reformats readout area based on passed value */
	
	function changeReadout(oValue) {
		var oReadout = DynAPI.document.all["readout"];
		
		if (oReadout && oValue) {
			
			var newPrice = parseFloat(oAttribute.startPrice) + parseFloat(oValue.priceModifier);
			newPrice = dollarFormat(newPrice);
			
			// write string to put in readout div
			var strHTML = "<p>";
			strHTML += "<b>" + oValue.valyuName + "</b><br>";
			if (oValue.valyuDescription.length > 0) {
				strHTML += oValue.valyuDescription + "<br>";
			}
			strHTML += "</p>";
	
			oReadout.setHTML(strHTML);
		}
	}


/* adds .00 format to a float */

	function dollarFormat(fl) {
	    fl -= 0;
	    fl = (Math.round(fl*100))/100;
	    return (fl == Math.floor(fl)) ? fl + '.00' 
	              : ( (fl*10 == Math.floor(fl*10)) ? 
	                       fl + '0' : fl);
	}
	 

