AddEvento("window","load",IniCalculadora);function AddEvento(Objeto,Nombre,Funcion){var r=false;if(typeof(Objeto)=="string"){Objeto=eval(Objeto)}if(Objeto.addEventListener){Objeto.addEventListener(Nombre,Funcion,false);r=true}else{if(Objeto.attachEvent){r=Objeto.attachEvent("on"+Nombre,Funcion)}}return r}function IniCalculadora(){IniCamposNumero();$("liProvincia").style.visibility="hidden";$("fCalculadora").rTipoCalculo[0].checked=true;$("TCuota").className="bold";$("MasDatos").style.visibility="hidden";DesactivaInput("iCuota;iPrecioVivienda;iProvincia");$("iEuribor").disabled=true;$("iInteres").disabled=true;AddEvento(document.getElementById("iDiferencial"),"change",function(){InteresFinal($("iDiferencial").form)});AddEvento(document.getElementById("iDiferencial"),"keyup",function(){InteresFinal($("iDiferencial").form)});if($("iImporte").value!=""){Calcula($("fCalculadora"))}}function IniCamposNumero(){var b=0;var a=document.getElementsByTagName("input");for(b=0;b<a.length;b++){if(a[b].className=="input"){if(a[b].id!="iPlazo"){AddEvento(a[b],"keyup",FormatoNumero);AddEvento(a[b],"change",FormatoNumero)}}}}function DesactivaInput(b){var a=b.split(";");for(i=0;i<a.length;i++){$(a[i]).disabled=true;$(a[i]).value=""}}function ActivaInput(b){var a=b.split(";");for(i=0;i<a.length;i++){$(a[i]).disabled=false}}function InteresFinal(b){var a=parseFloat(b.iEuribor.value)+parseFloat(strToNum(b.iDiferencial.value));if(!isNaN(a)){b.iInteres.value=numToStr(a)}else{b.iInteres.value=0}}function Calcula(a){var e=strToNum(a.iImporte.value);var f=strToNum(a.iInteres.value);var g=strToNum(a.iPlazo.value);var c=strToNum(a.iCuota.value);var k=strToNum(a.iPrecioVivienda.value);var j=a.iEuribor.value;var b="S";if(a.rTipoVivienda[1].checked){b="N"}var d="";var h="";if(Validar(a.name)){switch(true){case a.rTipoCalculo[0].checked:d=CalculaCuota(e,f,g);h="iCuota";break;case a.rTipoCalculo[1].checked:d=CalculaImporte(c,f,g);texto="<p>El <span>Importe de la Hipoteca</span> es de:</p>";h="iImporte";break;case a.rTipoCalculo[2].checked:d=CalculaInteres(c,e,g,j);texto="<p>El <span>Interés máximo</span> es de:</p>";h="iInteres";break;case a.rTipoCalculo[3].checked:d=CalculaPlazo(c,e,f);texto="<p>El <span>Plazo en Años</span> es de:</p>";h="iPlazo";break;case a.rTipoCalculo[4].checked:if(EjecutaGastos(a)){VerGastos("TablaGastos",b)}h="TablaGastos";document.location="#multicalculadora";break}if(!isNaN(d)){if(!a.rTipoCalculo[4].checked){ActivaInput(h);if(h=="iPlazo"){$(h).value=d}else{$(h).value=numToStr(d)+" €"}}}}}function Validar(c){var b=0;var d=1;var e="";var a=document.getElementById(c).getElementsByTagName("input");for(b=0;b<a.length;b++){if(a[b].id!="iInteres"){if(a[b].id!="iDiferencial"){if(a[b].className=="input"&&!a[b].disabled&&a[b].value==""||(isNaN(a[b].value)&&(a[b].className=="input"))){d=0;e=e+" "+a[b].name+", "}}}}a=document.getElementById(c).getElementsByTagName("select");for(b=0;b<a.length;b++){if(a[b].className=="input"&&!a[b].disabled&&a[b].value==""){d=0;e=e+" "+a[b].name+", "}}e=e.substr(0,e.length-2);if(e.length>0){if(e.lastIndexOf(",")>0){e=e.substr(0,e.lastIndexOf(","))+" y"+e.substr(e.lastIndexOf(",")+1)}$aviso("Es necesario rellenar correctamente<b>"+e+"</b> para efectuar el calculo")}return d}function EjecutaGastos(e){var b=strToNum(e.iImporte.value);var f=strToNum(e.iPrecioVivienda.value);var d=strToNum(e.iProvincia.value);var a="S";var c="";if(!isNaN(b)&&!isNaN(f)&&d>0){if(e.rTipoVivienda[1].checked){a="N"}ActualizarGastos(b,f,d);TGastosCV[TGastosCV.length-1][2]=CalculaGastos(TGastosCV,f,a);TGastosH[TGastosH.length-1][2]=CalculaGastos(TGastosH,b,a);c=TGastosCV[TGastosCV.length-1]+TGastosH[TGastosH.length-1]}return c}function VerGastos(a,c){var b=document.getElementById(a);HTML=TabIzq(TGastosCV,c)+TabDrch(TGastosH,c);b.innerHTML=HTML;$("TablaGastos").style.display="block"}function EstableceClase(c,a){var b=c.split(";");for(i=0;i<b.length;i++){$(b[i]).className=a}}function TipoCalculo(a){EstableceClase("TCuota;TImporte;TPlazo;TInteres;TGastos","");ActivaInput("iCuota;iImporte;iPlazo;iDiferencial");DesactivaInput("iPrecioVivienda");DesactivaInput("iProvincia");$("liProvincia").style.visibility="hidden";$("TablaGastos").style.display="none";quitaSimboloEuro("iImporte");quitaSimboloEuro("iCuota");switch(true){case a.rTipoCalculo[0].checked:DesactivaInput("iCuota");$("TCuota").className="bold";break;case a.rTipoCalculo[1].checked:DesactivaInput("iImporte");$("TImporte").className="bold";break;case a.rTipoCalculo[2].checked:DesactivaInput("iDiferencial");$("TInteres").className="bold";break;case a.rTipoCalculo[3].checked:DesactivaInput("iPlazo");$("TPlazo").className="bold";break;case a.rTipoCalculo[4].checked:$("TGastos").className="bold";$("liProvincia").style.visibility="visible";DesactivaInput("iDiferencial;iPlazo;iCuota");ActivaInput("iProvincia");ActivaInput("iPrecioVivienda");break}}function quitaSimboloEuro(a){simboloEuro=$(a).value.split(" ");if(simboloEuro[1]=="€"){importe=simboloEuro[0].split(",");$(a).value=Math.abs(importe[0])}}function FormatoNumero(c){var a=c.which;var b=c.target;if(b==undefined){b=c.srcElement}if(a==undefined){a=c.keyCode}r=strToNum(b.value);if(!isNaN(r)){r=numToStr(r);if((a==190)||(a==188)||(a==110)){b.value=r+","}else{b.value=r}altPts(b)}else{b.title="No ha introducido un importe valido."}return r}function altPts(b){var a="";if(b.value!=""){a=strToNum(b.value);if(!isNaN(a)){a=a*166.386;a=numToStr(a);b.title=a+" pts."}}return a}function TabDrch(c,b){var a;a=0;var d="<div class='contentCuota' style='margin-top:0px;'><div class='drch'><div class='texto'>";d+="<p><b>"+c[0][0]+"</b></p>";d+="</div></div>";for(a=1;a<c.length-1;a++){if((c[a][3]==b)||(c[a][3]=="T")){d+="<div class='drch'>";d+="<div class='texto'><p><font class='naranja'>&raquo; </font>"+c[a][0]+"</p></div>";d+="<div class='rojo'><p>"+numToStr(c[a][2])+"€</p></div>";d+="</div>"}}d+="<div class='drch' style='font-weight:700;'><div class='texto'><p><font class='naranja'>&raquo; </font>";d+=c[a][0];d+="</p></b></div>";d+="<div class='rojo'><p><span>"+numToStr(c[a][2])+"€</span></p></div>";d+="</div></div>";return d}function TabIzq(c,b){var a;a=0;var d="<div class='izq'><div class='rowGastos'>";d+="<p><b>"+c[0][0]+"</b></p>";d+="</div>";for(a=1;a<c.length-1;a++){if((c[a][3]==b)||(c[a][3]=="T")){d+="<div class='rowGastos'><p><font class='naranja'>&raquo; </font>"+c[a][0]+"</p>";d+="<div class='red'><p>"+numToStr(c[a][2])+"€</p></div></div>"}}d+="<div class='rowGastos' style='font-weight:700;'><p><font class='naranja'>&raquo; </font>";d+=c[a][0];d+="</p></b>";d+="<div class='red'><p><span>"+numToStr(c[a][2])+"€</span></p></div>";d+="</div></div>";return d};