function doRecalc() {
	var sellPrice;
	var rubyRealtyCommission;
	var fullFeeCommission;

	sellPrice = clean(document.getElementById('txt-sell-price'));
	document.getElementById('txt-sell-price').value = tidy(sellPrice);

	if (sellPrice <= 10000000)
		rubyRealtyCommission = sellPrice*0.02;
	
	document.getElementById('txt-ruby-realty-commission').value = tidy(rubyRealtyCommission)
	document.getElementById('txt-ruby-realty-gst').value = tidy(rubyRealtyCommission*0.1);
	document.getElementById('txt-ruby-realty-total').value = tidy(rubyRealtyCommission+rubyRealtyCommission*0.1);

	if (sellPrice < 18000)
		fullFeeCommission = 0.05 * sellPrice;
	else
		fullFeeCommission = 18000*0.05+(sellPrice-18000)*0.025;

	document.getElementById('txt-full-fee-commission').value = tidy(fullFeeCommission)
	document.getElementById('txt-full-fee-gst').value = tidy(fullFeeCommission*0.1);
	document.getElementById('txt-full-fee-total').value = tidy(fullFeeCommission+fullFeeCommission*0.1);
	
	document.getElementById('txt-saving').value = tidy((fullFeeCommission+fullFeeCommission*0.1)-(rubyRealtyCommission+rubyRealtyCommission*0.1));
}

function clean (w){
    spacing="$               ";
    max_length=12;
if(!w){
    alert("missing input after "+ w2.name);         
    return(0);
}
y="0"+w.value;                          //0 to prevent NaN
yl=y.length;
for(z=0;z<yl;z++){
if(y.charAt(z)<"." || y.substring(z,z+1)>"9" || y.substring(z,z+1)=="/"){
y=(y.substring(0,z) + y.substring(z+1));
z--;
yl--;
}
}
y=parseFloat(y);
x=Math.floor(y);
xx=y-x;
xx=xx+"00.00"                 //xx=the cents only (with zeroes).
a=xx.indexOf(".");
q=x+xx.substring(a,a+3);

ql= (q.length < max_length)?(max_length-q.length):0;
w.value=(y)?spacing.substring(0,ql)+q:"";
r=parseFloat(q);                            //should be dddd.dd
w2=w;
return (r);
}

function tidy (y){
    max_length=12;                         //max_length= length of text input
    spacing="$               ";
    x=Math.floor(y);
    xx=y-x;
    xx=xx+"00.00"                 //xx=the cents only (with zeroes).
    a=xx.indexOf(".");
    q=x+xx.substring(a,a+3);
    ql= (q.length<max_length)?(max_length-q.length):0;   
    r=(y)?spacing.substring(0,ql)+q:"";
    return (r);
}