// Mansons JavaScript Document

/**
* Ammends the total price of an item.
*/
function ammend_item_price(currency_symbol, current_value) {
	// Set the initial price value of the item.
	//var current_value = parseFloat(document.item_selections.initial_item_price.value);
	var running_total = 0;
	
	// Loop thrugh each form element.
	for(i = 0; i < document.item_selections.elements.length; i ++) {
		// Only check select boxe values
		if(document.item_selections.elements[i].type == "select-one") {
			// Pass the value to a variable to make coding easier.
			text_value = document.item_selections.elements[i][document.item_selections.elements[i].selectedIndex].text;
			
			// Get the price ammendment of a selection.
			pos = text_value.indexOf('+ ' + currency_symbol);
			
			if (pos) prefix = "+";
			if (pos == -1) {
				pos = text_value.indexOf('- ' + currency_symbol);
				if (pos) prefix = "-";
			}
			
			// If a price ammendment is found.
			if (pos != -1) {
				ammend_value = parseFloat(text_value.substring((pos + 3), text_value.length));
				
				// Ammend the item price.
				if (prefix == "+") running_total = running_total + ammend_value;
				if (prefix == "-") running_total = running_total - ammend_value;
			}
		}
	}
	total_value = current_value + running_total;
	document.item_selections.item_price.value = total_value.toFixed(2);
}
