

//
//
function incrementQuantity(quantityFieldId)
{
	var txtQuantity = document.getElementById(quantityFieldId);
	
	if (!txtQuantity) {
		return;
	}
	
	var q = parseInt(txtQuantity.value);
	
	if (isNaN(q)) {
		return;
	}
	
	txtQuantity.value = q + 1;
}

//
//
function decrementQuantity(quantityFieldId)
{
	var txtQuantity = document.getElementById(quantityFieldId);
	
	if (!txtQuantity) {
		return;
	}
	
	var q = parseInt(txtQuantity.value);
	
	if (isNaN(q)) {
		return;
	}
	
	if (q < 2) {
		return;
	}
	
	txtQuantity.value = q - 1;
}

//
//
function recalculatePrice(basePrice, choicePriceModifiers)
{
	var new_price = parseFloat(basePrice);
	
	var nodes = document.getElementsByTagName("select");

	for (i = 0; i < nodes.length; i++)
	{ 
		var node = nodes.item(i);
		
		if (startsWith(node.getAttribute("id"), "lstChoices_")) {
			var modifier = parseFloat( choicePriceModifiers[node.options[node.selectedIndex].value] );
			
			if (!isNaN(modifier)) {
				new_price += modifier;
			}
			
		}
	}
	
	// load the values into the labels
	//
	var price_label = document.getElementById("lblPrice");
	
	if (price_label) {
	
		// clear out the label
		//
		while (price_label.hasChildNodes()) {
			price_label.removeChild(price_label.firstChild);
		}
		
		price_label.appendChild(document.createTextNode(""));
			
		// update the value
		//
		price_label.firstChild.data = "$" + new_price.toFixed(2);
	
	}
	
	return;	
}

//
//
function startsWith(Source, Target)
{
	if (!Source || !Target) {
		return false;
	}
	
	return (Source.substring(0, Target.length) == Target);
}


//
//
function parseCurrency(currencyString)
{
	return currencyString.replace(/\$|\.00|,/gi, "");
}