function calcular() {
	entrada = document.calculadora.entrada.value
	precio = document.calculadora.precio.value
	importe = precio - entrada;
	anios = document.calculadora.anios.value;
	tipointeres = document.calculadora.interes.value; 
	tipointeres = tipointeres.replace(",",".");
	if (importe >0 && tipointeres !=""){
		document.calculadora.prestamo.value = importe;
		var numpagos = 12;
    	tipointeres = tipointeres/100;
    	var tipointeresefectivo = tipointeres/numpagos;
		var unomasi = 1 + tipointeresefectivo;
    	var exponente = -(numpagos*anios);
    	var potencia = Math.pow(unomasi,exponente);      
    	var cuota = (importe * tipointeresefectivo) / (1 - potencia); 
    	cuota = cuota.toFixed(2);
		total = (cuota*numpagos)* anios;
		cuota = cuota.replace(".",",");
		total = total.toFixed(2);
		total = total.replace(".",",");
		document.calculadora.mensualidad.value = cuota;
		document.calculadora.total.value = total;
	}
}
function numerico(myfield, e, dec){
var key;
var keychar;
if (window.event)
   key = window.event.keyCode;
else if (e)
   key = e.which;
else
return true;
keychar = String.fromCharCode(key);

// control keys
if ((key==null) || (key==0) || (key==8) ||
    (key==9) || (key==13) || (key==27) || (key==44))
   return true;

// numbers
else if ((("0123456789").indexOf(keychar) > -1))
   return true;

// decimal point jump
else if (dec && (keychar == ".")){
   myfield.form.elements[dec].focus();
   return false;
}else
   return false;
}
