/* This function is used by the buyers savings calculator.
 * Commission is 2.8% of sale price.
 * 66% of the commission is refunded to the customer, with the remaining 34% being a floor of $2000.
 * Yong Bakos 1/26/07
 * JNoble 11/24/08
 * Change rebate to 50%
*/
function calculateCommission(price) {
	var commission = .028 * parseFloat(price);
	return commission;
}
function calculateRebate(price) {
	var CMIN = 4000;
	var commission = calculateCommission(price);
	if ((.5 * commission) < CMIN) {
		//show('note');
		//show('pitch');
		if ((commission - CMIN) > 0) {
			return Math.round((commission - CMIN));
		} else return 0;
	} else return Math.round((.5 * commission));
}

function calculate() {
	var price = get('price').value;
	if (isNaN(price) || price == '') {
		alert('Please enter a valid sale price, no commas.');
	} else {
        var rebate = calculateRebate(price);
        var commission = calculateCommission(price);
        var rasCommission = commission - rebate;
		get('commission').innerHTML = formatCurrency(commission);
		get('rascommission').innerHTML = formatCurrency(rasCommission); 
		get('rebate').innerHTML = formatCurrency(rebate);
		show('savings');

	}
}

/* This function is used by the sellers savings calculator.
 * Assume normal commision of 3.2% of sales price for traditional transaction.
 * We charge $2500 flat fee, subtract this from 3% for the savings
 * jnoble 5/7/07
 * updated 9/10/07 for new site
 * updated 12/6/09 for change to 1% sellers plan
*/

function calcSellCommission(price) {
	var commission = 0.032 * parseFloat(price);
	return commission;
}
function calcRasFee(price) {
    return Math.max(2500, 0.01 * parseFloat(price));
}
function calculateSellRebate(price) {
	var commission = calcSellCommission(price);
    var ourfee = calcRasFee(price);
	return Math.round(commission - ourfee);
}

function sellCalculate() {
	var price = get('price').value;
	if (isNaN(price) || price == '') {
		alert('Please enter a valid sale price, no commas.');
	} else if (parseFloat(price) < 100000) {
		alert('Please enter a price of at least $100,000');
	} 
	else {
		var rebate = calculateSellRebate(price);
        var commission = calcSellCommission(price);
        var rasCommission = calcRasFee(price);
		get('commission').innerHTML = formatCurrency(commission);
		get('rascommission').innerHTML = formatCurrency(rasCommission); 
		get('rebate').innerHTML = formatCurrency(rebate);
		show('savings');
	}
}