calc_on = new Image();
calc_off = new Image();
calc_on.src = "/images/calculate_.gif";
calc_off.src = "/images/calculate.gif";

function calculateCashback() {
	var price1 = strip(document.calculator.price1.value);
	var price2 = strip(document.calculator.price2.value);
	document.calculator.discount.value = formatCurrency((price1 * 0.50 * 0.3 * 0.03) + (price2 * 0.50 * 0.3 * 0.03));
}

function strip(num){ // this function removes spaces and illegal characters
	num = "" + num;
		if (num == "") return "";
	var result = "";
	for (i=0; i<num.length; i++){
	character = num.charAt(i);
	if ("0123456789".indexOf(character) != -1)
		result += character;
	}
	return result;
}

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);
}