function FIND(item) {
	if (document.all) return(document.all[item]);
	if (document.getElementById) return(document.getElementById(item));
	return(false);
}

function round_decimals(original_number, decimals) {
    var result1 = original_number * Math.pow(10, decimals)
    var result2 = Math.round(result1)
    var result3 = result2 / Math.pow(10, decimals)
    return pad_with_zeros(result3, decimals)
}

function pad_with_zeros(rounded_value, decimal_places) {
    var value_string = rounded_value.toString()
    var decimal_location = value_string.indexOf(".")
    if (decimal_location == -1) {
        decimal_part_length = 0
        value_string += decimal_places > 0 ? "." : ""
    }
    else {
        decimal_part_length = value_string.length - decimal_location - 1
    }
    var pad_total = decimal_places - decimal_part_length
    if (pad_total > 0) {
        for (var counter = 1; counter <= pad_total; counter++) 
            value_string += "0"
        }
    return value_string
}

function toDollarsAndCents(n) {
  var s = "" + Math.round(n * 100) / 100
  var i = s.indexOf('.')
  if (i < 0) return s + ".00"
  var t = s.substring(0, i + 1) + s.substring(i + 1, i + 3)
  if (i + 2 == s.length) t += "0"
  return t
}

function updateOptionPrice(thisform,thisinput){
	var price = basePrice;
	var thedifference = 0;
	var pricevalAr = new Array();
	var direction = "add";
	var modPrice = "";
	if(price != "")
		price = parseFloat(price);
	else
		price = 0;

	for(i=0;i<thisform.elements.length;i++){ 
		priceval = 0;
		pricevalAr = 0;
		if(thisform.elements[i].type == "select-one"){
			priceval = thisform.elements[i].options[thisform.elements[i].selectedIndex].value
			
			if(priceval.indexOf("(+$") > -1) {
				pricevalAr = priceval.split("(+$");
				direction = "add";
			}else if(priceval.indexOf("(+") > -1) {
				pricevalAr = priceval.split("(+");
				direction = "add";
			}else if(priceval.indexOf("(-") > -1) {
				pricevalAr = priceval.split("(-");
				direction = "sub";
			}else if(priceval.indexOf("(-$") > -1) {
				pricevalAr = priceval.split("(-$");
				direction = "sub";
			}else if(priceval.indexOf("(*") > -1) {
				pricevalAr = priceval.split("(*");
				direction = "mult";
			}
			if(pricevalAr.length > 1){
				priceval = pricevalAr[1].split(")");
				priceval = parseFloat(priceval[0]);
			} else {
				priceval = 0;
			} 
			if(direction == "add")
				price = price + priceval
			else if(direction == "sub")
				price = price - priceval
			else {
				thedifference = (price * priceval) - price;
				price = price * priceval;
				if(thisinput) thisinput.value = "(+" + thedifference + ")";
			}
		} else {
			if(thisform.elements[i].type == "radio"){
				if(thisform.elements[i].checked){
					priceval = thisform.elements[i].value;
					fullinput = priceval;
					if(priceval.indexOf("(+$") > -1) {
						pricevalAr = priceval.split("(+$");
						direction = "add";
					} else if(priceval.indexOf("(+") > -1) {
						pricevalAr = priceval.split("(+");
						direction = "add";
					} else if(priceval.indexOf("(-") > -1) {
						pricevalAr = priceval.split("(-");
						direction = "sub";
					}else if(priceval.indexOf("(-$") > -1) {
						pricevalAr = priceval.split("(-$");
						direction = "sub";
					}else if(priceval.indexOf("(*") > -1) {
						pricevalAr = priceval.split("(*");
						direction = "mult";
					}
					if(pricevalAr.length > 1){
						priceval = pricevalAr[1].split(")");
						priceval = parseFloat(priceval[0]);
					}else
						priceval = 0;
					if(direction == "add")
						price = price + priceval
					else if(direction == "sub")
						price = price - priceval
					else {
						thedifference = (price * priceval) - price;
						price = price * priceval;
						if(thisinput) thisinput.value = "(+" + round_decimals(thedifference,2) + ")";
					}
				}
			}
		}
	}
		
	modPrice = modPrice + "$" + toDollarsAndCents(price);

	if (document.all) {
	   dispprice.innerHTML = modPrice;
	} else if (document.getElementById) {
		document.getElementById("dispprice").innerHTML = modPrice;
        }
}

