jQuery.noConflict();
     
jQuery(document).ready(function(){
				
				jQuery('form#compare input[name=brookhaven_rate]').blur( function () {
				    var value = jQuery(this).attr('value')*1;
								var value = money(value);
								jQuery('input[name=brookhaven_subtotal]').attr('value', value);					
								jQuery('input[name=brookhaven_total]').attr('value', value);	
				});
				
				
				jQuery('form#compare input[name=house_sell]').blur( function () {
				    var proceeds = jQuery(this).attr('value')*1;
								var interest_rate = .06;
								var yearly_income = money(proceeds * interest_rate);
								var monthly_income = money(yearly_income/12);
								jQuery('input[name=house_invest]').attr('value', yearly_income);	
								jQuery('input[name=house_income]').attr('value', monthly_income);	
				});
				
				jQuery('form#compare input').blur( function () {
				    jQuery("input").each(function (i) {
										  var value = jQuery(this).attr('value')*1;
												if (value != '') {
														  jQuery(this).attr('value', money(value));
												}
								});		
								jQuery('form#compare').ajaxSubmit({ 
												url: '/hcore/calculator/calculate.php',
												target: '#total',
												success: showTotal
								}); 
								return false;
				});
	
});

function showTotal(response)  { 
    var sub_total = money(response);
				var monthly_income = money(jQuery('input[name=house_income]').attr('value'));
				var total = (sub_total*1) + (monthly_income*1);
				var total = money(total);
    jQuery('input[name=home_subtotal]').attr('value', sub_total);	
				jQuery('input[name=home_total]').attr('value', total);	
}

function money(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.substring(num.length-(4*i+3));
				return (((sign)?'':'-') + num + '.' + cents);
}