      
    //__________________________________________________________________    
      function calcula_cuota()
      {
       var formato = new NumberFormat();
       formato.setSeparators(true, ".", ",");   
       
       var resultado="";   
       n=(document.getElementById("anios").value*12)+parseInt(document.getElementById("meses").value);
       if (n<=24) return false;
       n=n-24; //ELIMINAMOS 2 PRIMEROS AÑOS SIN INTERESES
       capital=document.getElementById("importe").value.replace(",",".");
       capital=document.getElementById("importe").value.replace(".","");
       
       //Euribor 2
       i=2.75;
       i=i/1200; 
       //alert(capital +"-"+n+"-"+i);
       resultado=capital*((Math.pow((1+i),n)*i)/(Math.pow((1+i),n)-1))+"";
       formato.setNumber(resultado);
       document.getElementById("2_con").innerHTML=formato.toFormatted()+" &euro;";
              
       i=3.20;
       i=i/1200; 
       resultado=capital*((Math.pow((1+i),n)*i)/(Math.pow((1+i),n)-1))+"";
       formato.setNumber(resultado);
       document.getElementById("2_sin").innerHTML=formato.toFormatted()+" &euro;";
       
       //Euribor 3
       i=3.75;
       i=i/1200; 
       resultado=capital*((Math.pow((1+i),n)*i)/(Math.pow((1+i),n)-1))+"";
       formato.setNumber(resultado);
       document.getElementById("3_con").innerHTML=formato.toFormatted()+" &euro;";
       
       i=4.20;
       i=i/1200; 
       resultado=capital*((Math.pow((1+i),n)*i)/(Math.pow((1+i),n)-1))+"";
       formato.setNumber(resultado);
       document.getElementById("3_sin").innerHTML=formato.toFormatted()+" &euro;";
       
       //Euribor 4
       i=4.75;
       i=i/1200; 
       resultado=capital*((Math.pow((1+i),n)*i)/(Math.pow((1+i),n)-1))+"";
       formato.setNumber(resultado);
       document.getElementById("4_con").innerHTML=formato.toFormatted()+" &euro;";
       
       i=5.20;
       i=i/1200; 
       resultado=capital*((Math.pow((1+i),n)*i)/(Math.pow((1+i),n)-1))+"";
       formato.setNumber(resultado);
       document.getElementById("4_sin").innerHTML=formato.toFormatted()+" &euro;";
       
       //Euribor 5
       i=5.75;
       i=i/1200; 
       resultado=capital*((Math.pow((1+i),n)*i)/(Math.pow((1+i),n)-1))+"";
       formato.setNumber(resultado);
       document.getElementById("5_con").innerHTML=formato.toFormatted()+" &euro;";
       
       i=6.20;
       i=i/1200; 
       resultado=capital*((Math.pow((1+i),n)*i)/(Math.pow((1+i),n)-1))+"";
       formato.setNumber(resultado);
       document.getElementById("5_sin").innerHTML=formato.toFormatted()+" &euro;";       
       
      }    

    //__________________________________________________________________
	function calcula_importe_cuota(importe)
	{
		//importe_int=parseInt(importe.replace(".",""));
		importe=String(importe);

		importe=importe.replace(/[.]/g,'');
		importe=importe.replace(/[€]/g,'');
		importe=importe.replace(/[ ]/g,'');
	    var importe_int=parseInt(importe);
		
	    var cuota="";
	    
        if (importe_int>150000) cuota="400";
        if (importe_int>200000) cuota="500";
        if (importe_int>250000) cuota="600";  
        if (importe_int>300000) cuota="700";        
        if (importe_int>350000) cuota="800";      
        if (importe_int>400000) cuota="900";      
        if (importe_int>450000) cuota="1000";      
        if (importe_int>500000) cuota="1100";      
        if (importe_int>550000) cuota="1200";     
        if (importe_int>600000) cuota="1300";      
        if (importe_int<150001) cuota="300";
        
        return cuota;
	}

      
    //__________________________________________________________________
    function calcula()
    {
      var importe=0;
      
      if (document.getElementById("importe").value!=""){

          importe=parseInt(document.getElementById("importe").value.replace(".",""));  
          
          document.getElementById("cuota_fija").innerHTML=calcula_importe_cuota(importe)+" €";
           
      } 

          calcula_cuota();  
    }

    
    function calcula_plazo(){
        
        var edad = document.getElementById("edad").value ;
        
        if (edad<18) {
            alert("La edad minima para solicitar una hipoteca es de 18 años.");
            document.getElementById("edad").value="";
            return 0;
        }
        
        var maximo = 75 - document.getElementById("edad").value ;
        document.getElementById("anios").length=0;
        
        if (maximo>40){ //ajustamos plazo maximo
           maximo=40;
        }   
           
        var i;   
        for (i=1;i<=maximo;i++){  
           if (i>2) 
           document.getElementById("anios").options[i-1]=new Option(i,i,"defaultSelected");
        }   
    }
    
    function limita_importe(){
        
        var importe = document.getElementById("importe").value ;
        
        if (importe>300000){ //ajustamos plazo maximo
           document.getElementById("importe").value="300000";
        }   
       
    }
             
    
    function limita_edad(){
        
        var edad = document.getElementById("edad").value ;
        
        
        if (edad<18){ //ajustamos edad mínima
           document.getElementById("edad").value="18";
        }   
       
    }
