var MAG = Object.extend({}, MAG || {});
MAG.Fee = Class.create();
MAG.Fee.prototype = {
	initialize: function(options)
	{
		$('fee_calculator').observe('click', this.calculateFee.bind(this));
	},
	
	calculateFee: function() {		
		var price = $('price').value;
		var enter_tax = price*(0.1/100);
		var notarial_tax = 0;
		var local_tax = 0;
		if(price <= 100) {
			notarial_tax = 30;
		} 
		
		else if(price>100 && price<=1000) {
			notarial_tax = 30+(1.5/100)*(price-100);
		}
		
		else if(price > 1000 && price <= 10000) {
			notarial_tax = 43.5 + (1.3/100)*(price-1000);
		}
		
		else if(price > 10000 && price <= 50000) {
			notarial_tax = 160.5 + (0.8/100)*(price-10000);
		}
		
		else if(price > 50000 && price <= 100000) {
			notarial_tax = 480.5 + (0.5/100)*(price-50000);
		}
		
		else if(price > 100000 && price <= 500000) {
			notarial_tax = 730.5 + (0.2/100)*(price-100000);
		}
		
		else if(price > 500000) {
			notarial_tax = 1530.5 + (0.1/100)*(price-500000);
		}
		
		
		notarial_tax = (notarial_tax < 6000) ? notarial_tax : 6000;
		enter_tax = (enter_tax > 10) ? enter_tax : 10;
		local_tax = price*(2.5/100);
		total = notarial_tax + enter_tax + local_tax;
		
		
		$('notarial_tax').value = notarial_tax.toFixed(2);
		$('local_tax').value = local_tax.toFixed(2);
		$('enter_tax').value = enter_tax.toFixed(2);
		$('total').value = total.toFixed(2);
	}
};

document.observe('dom:loaded', function(){new MAG.Fee;});
