// le agrega un formato tipo moneda  a un numero
function FormatoMoneda(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 = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + '$' + num + '.' + cents);
}

function floor(number){
  return Math.floor(number*Math.pow(10,2))/Math.pow(10,2);
}

//esta funcion calcula los prestamos hipotecarios
function calcular() {

  var mi = document.prestamo.Interes.value / 1200;
  var base = 1;
  var mbase = 1 + mi;
  var precio = document.prestamo.precio.value;
  var inicial = document.prestamo.inicial.value;
  var monto = precio - inicial;
  document.prestamo.monto.value = FormatoMoneda(monto);
  for (i=0; i<document.prestamo.Anos.value * 12; i++)
  {
    base = base * mbase
  }
  document.prestamo.cuota.value = FormatoMoneda(floor(monto * mi / ( 1 - (1/base))))

}

// muestra una capa tipo div
function mostrardiv(capa) {
div = document.getElementById(capa);
div.style.display = '';
}

// cierra una capa tipo div
function cerrar(capa) {
div = document.getElementById(capa);
div.style.display='none';

}

function actualizarformularios() {
div = document.getElementById(pl);
document.pl1.style.display='none';


}



//abre la ventana con la calculadora
function abrir(url,ancho,alto){ 
window.open(url,'cal','width='+ancho+',height='+alto+',scrollbars=NO');
}

function seleccionar_todo(){ 
   for (i=0;i<document.f1.elements.length;i++) 
      if(document.f1.elements[i].type == "checkbox") 
         document.f1.elements[i].checked=1 
} 
function deseleccionar_todo(){ 
   for (i=0;i<document.f1.elements.length;i++) 
      if(document.f1.elements[i].type == "checkbox") 
         document.f1.elements[i].checked=0 
}


