function calculate_price(item_num) {
	item_price = parseFloat(eval('document.myForm.item_price' + item_num + '.value'));
	item_qty = parseFloat(eval('document.myForm.item_qty' + item_num + '.value'));
	
	item_total = formatCurrency(item_price * item_qty);
	document.getElementById('item_total' + item_num).innerHTML = item_total;

}

function change_price(item_num,option_price) {
	var re = /.*\$/;
	var option_price = option_price.replace  (re ,'');
	option_price = parseFloat(option_price);
	old_price = parseFloat(eval('document.myForm.starting_price' + item_num + '.value'));
	this_price = eval('document.myForm.item_price' + item_num);
	this_price.value = (old_price + option_price);
	calculate_price(item_num);
}

function formatCurrency(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + '$' + num + '.' + cents);
}
// first parameter is number of items on the page
// second paramter is number of options for the items
// option1 thru option3 are the names of the options: e.g. 'color'
function validate(items, opts, option1, option2, option3) {
	//alert("checking item " + 0 + ": " + eval('document.myForm.item_qty0.value'));
	//alert(eval('document.myForm.option_choices0_0.options[' + parseFloat(eval('document.myForm.option_choices0_0.options.selectedIndex')) + '].value'));
	empty = 0;
	for (item_num = 0; item_num < items; item_num++) {
		//alert("checking item " + item_num + ": " + parseFloat(eval('document.myForm.item_qty' + item_num + '.value')));
		if (parseFloat(eval('document.myForm.item_qty' + item_num + '.value')) > 0) {
			for (opt_num = 0; opt_num < opts; opt_num++) {
				if (eval('document.myForm.option_choices' + item_num + '_' + opt_num + '.nodeName') == 'SELECT') {
					if (eval('document.myForm.option_choices' + item_num + '_' + opt_num + '.options[' + parseFloat(eval('document.myForm.option_choices' + item_num + '_' + opt_num + '.options.selectedIndex')) + '].value') == "") {
						alert("Please select a " + eval('option' + eval(1 + opt_num)) + " for the " + eval('document.myForm.item_name' + item_num + '.value') + ' (Item #' + eval(item_num + 1) + ')');
						eval('document.myForm.option_choices' + item_num + '_' + opt_num + '.focus()');
						return 0;
					}
				}
			}
		} else {
			empty++;
		}
	}
	if (empty == items) {
		alert("Please enter the quantity of the product you would like");
	} else {
		document.myForm.submit();
	}
}