function aceptarhome() {

	if (document.forms[0].interes.value == '0,00')
	{
		alert("El interés no puede ser cero");
		document.forms[0].interes.focus();
		return false;
	}
	
	if ((document.forms[0].plazo.value < 1) || (document.forms[0].plazo.value > 50))	{
		alert("El plazo de años debe estar entre 1 y 50 años");
		document.forms[0].plazo.focus();
	}	else	{
		if (document.forms[0].opcion.value =="0")		{
			var retorno = calcula_cuota();
		}		else		{
			var retorno = calcula_total();
		}
//		document.forms[0].submit();
	}
}

function limpiar() {
	document.forms[0].opcion.value = "";
//	document.forms[0].submit();		
}

function cambiaTipo(cuota,total) {
	if (document.forms[0].opcion.value =="0") {
		cuota = cuota.split("[factor]")
		cuotaTXT = cuota[0] + form1.comboDIV.value + cuota[0]
		Tipo.innerHTML = cuotaTXT;
	}	

	else{
		Tipo.innerHTML  = total;
		}
}		


//****************************************************************************************************
//****************************************************************************************************
function ComprobarNumerico(objeto,comas,puntos,decimales,longitud) {
	var retorno,valor;
	valor = objeto.value
	
	if (!EsNumerico(objeto,objeto.value,puntos)){
		alert ("El valor introducido es erróneo: '" + valor + "'");
		objeto.focus();
		return false;
	}
	if (!ContadorComas(objeto,objeto.value,comas)) {
		alert ("El valor introducido es erróneo");
		objeto.focus();
		return false;
	}
	if (objeto.value.length>0) {
		objeto.value=(FormatearImporte(objeto.value,puntos,decimales,longitud));
	}
	return true;
}	
	

//****************************************************************************************************
//****************************************************************************************************
function EsNumerico(obj,dato,puntos)
{
	var i;
	var longitud;
	var caracter;
	var sumo = 0;
	longitud = dato.length;
	valido = "0123456789,";
	if (puntos=='s')
	{
		valido = valido + ".";
	}
	for ( i=0; i <= longitud; i++)
	{
		caracter = dato.substring(i,i+1)
		if (valido.indexOf(caracter) == -1)
		{
			obj.value = dato.substring(0,i);
			return false;
		}
	}
	return true;
}
//****************************************************************************************************
//****************************************************************************************************
function ContadorComas(obj,dato,comas)
{
  var contador;
  var i;
  contador = 0;
  for (i=0;i<dato.length;i++)
  {
		if (dato.substring(i,i+1)==",")
    {
			contador++;
      if (contador > comas)
			{
				obj.value = dato.substring(0,i);
				return false;
			}
    }
	}
	return true;		
}

//****************************************************************************************************
//****************************************************************************************************
function FormatearImporte(dato,puntos,decimales,longitud)
{
	var entero;
	var decimal;
	var i;
	var posicion;
	var enteroSin,enteroCon;
	var decimalSin,decimalCon;
	
	posicion = dato.length
  for (i=0;i<dato.length;i++)
  {
		if (dato.substring(i,i+1)==",")
		{	
			posicion = i;
		}
	}
	// Recuperamos la parte entera
	entero = dato.substring(0,posicion);
	
	// Recuperamos la parte decimal
	decimal = dato.substring(posicion + 1,dato.length);
	
	// Eliminamos los puntos de la parte entera
	enteroSin = QuitarPuntos(entero);
	
	// Quitamos los ceros a la izquierda
	enteroSin = String(QuitarCerosIzq(enteroSin));

	// Si el campo lleva puntos, se los ponemos
	enteroCon = enteroSin;
	if (puntos=='s')
		enteroCon = PonerPuntos(enteroSin);

	// Eliminamos los puntos en la parte decimal
	decimalSin = QuitarPuntos(decimal);

	// Formateamos la parte decimal
	if (decimales=='s')
	{
		decimalCon = ParteDecimal(decimalSin,longitud);
		return (enteroCon + ',' + decimalCon);
	}
	else
	{
		return (enteroCon);
	}
}

//****************************************************************************************************
//****************************************************************************************************
function QuitarPuntos(dato)
{
	var aux,i;
	aux = '';

	for (i=0;i<dato.length;i++)
	{
		if (dato.substring(i,i+1)!=".")
			aux = aux + dato.substring(i,i+1);
	}
	return aux;
}

//****************************************************************************************************
//****************************************************************************************************
function PonerPuntos(dato)
{
	var aux,i;
	aux = '';

	for (i=0;i<dato.length;i++)
	{
		if (((dato.length-i)%3)==0 && (i>0))
			aux = aux + '.';
		aux = aux + dato.substring(i,i+1);
	}
	return aux;
}

//****************************************************************************************************
//****************************************************************************************************
function ParteDecimal(dato,longitud)
{
	var aux;

	if (longitud!=dato.length)
	{
		switch (dato.length)
		{	
			case 0:
				aux = "00";
				break;
			case 1:
				aux = dato + "0";
				break;
			default :
				aux = dato.substring(0,2);
		}
	}
	else
	{
		aux = dato.substring(0,2);
	}
	return aux;
}

//****************************************************************************************************
//****************************************************************************************************
function QuitarCerosIzq(dato)
{
	aux = dato * 1;
	return aux;
}

//****************************************************************************************************
//****************************************************************************************************
function calcula_cuota()
{
	var Importe;			/* IMPORTE NOMINAL DE LA OPERACION */
	var IntTecleado		/* INTERES TECLEADO */
	var IntReal;			/* INTERES REAL */
	var Tiempo;				/* TIEMPO EN AÑOS*/
	var PeriodoAnio;	/* NUMERO DE PERIODOS EN UN AÑO */
	var Cuota;				/* VALOR DE CUOTA DE AMORTIZACION */
	var NCuotas;			/* NUMERO DE CUOTAS DE AMORTIZACION */
	var Temporal;			/* OPERANDO TEMPORAL */
	var Posicion;

	// Importe de la operacion
	Importe	= document.forms[0].Importe.value;
	Importe = QuitarPuntos(Importe);
	
	// Cambiamos la coma por un punto
	Posicion = Importe.indexOf(',');
	if (Posicion != -1)
	{
		Importe = Importe.substring(0, Posicion)+'.'+Importe.substring(Posicion+1);
	}

	// Interés tecleado
	IntTecleado = document.forms[0].interes.value;
	// Cambiamos la coma por un punto
	Posicion = IntTecleado.indexOf(',');
	if (Posicion != -1)
	{
		IntTecleado = IntTecleado.substring(0, Posicion)+'.'+IntTecleado.substring(Posicion+1);
	}

	// Tiempo en años
	Tiempo			= document.forms[0].plazo.value;
	
	// Nº de pagos en un años
	
	//PeriodoAnio = "12";
	PeriodoAnio = 12 / document.forms[0].factor.value
		
	if(document.forms[0].nuCuotas)
		{
		PeriodoAnio = document.forms[0].nuCuotas.value
		}
	// Cálculo de la cuota
	IntReal			= IntTecleado / (PeriodoAnio * 100);
	NCuotas			= PeriodoAnio * Tiempo;
	Temporal		= Math.pow((1 + IntReal), NCuotas);
	
	Cuota = (Importe * IntReal * Temporal)/(Temporal - 1);
	Cuota = String(Cuota)
	// Cambiamos el punto por una coma
	Posicion = Cuota.indexOf('.');
	if (Posicion != -1)
	{
		Cuota = Cuota.substring(0, Posicion)+','+Cuota.substring(Posicion+1);
	}
	Cuota = FormatearImporte(Cuota,'s','s','2');
	document.forms[0].salida.value = Cuota;
}

//****************************************************************************************************
//****************************************************************************************************
function calcula_total()
{
	var Importe;			/* IMPORTE NOMINAL DE LA OPERACION */
	var IntTecleado		/* INTERES TECLEADO */
	var IntReal;			/* INTERES REAL */
	var Tiempo;				/* TIEMPO EN AÑOS*/
	var PeriodoAnio;	/* NUMERO DE PERIODOS EN UN AÑO */
	var Total;				/* VALOR DE Total DE AMORTIZACION */
	var NCuotas;			/* NUMERO DE CUOTAS DE AMORTIZACION */
	var Temporal;			/* OPERANDO TEMPORAL */
	var Posicion;

	// Importe de la operacion
	Importe	= document.forms[0].Importe.value;
	Importe = QuitarPuntos(Importe);
	
	// Cambiamos la coma por un punto
	Posicion = Importe.indexOf(',');
	if (Posicion != -1)
	{
		Importe = Importe.substring(0, Posicion)+'.'+Importe.substring(Posicion+1);
	}

	// Interés tecleado
	IntTecleado = document.forms[0].interes.value;
	// Cambiamos la coma por un punto
	Posicion = IntTecleado.indexOf(',');
	if (Posicion != -1)
	{
		IntTecleado = IntTecleado.substring(0, Posicion)+'.'+IntTecleado.substring(Posicion+1);
	}

	// Tiempo en años
	Tiempo			= document.forms[0].plazo.value;

	// Nº de pagos en un años
	PeriodoAnio = "12";
	PeriodoAnio = 12 / document.forms[0].opcion.value

	IntReal			= IntTecleado / (PeriodoAnio * 100);
	NCuotas			= PeriodoAnio * Tiempo;
	Temporal		= Math.pow((1 + IntReal), NCuotas);
	
	Total = (Importe * (Temporal - 1))/(IntReal * Temporal)

	Total = String(Total)
	// Cambiamos el punto por una coma
	Posicion = Total.indexOf('.');
	if (Posicion != -1)
	{
		Total = Total.substring(0, Posicion)+','+Total.substring(Posicion+1);
	}
	Total = FormatearImporte(Total,'s','s','2');
	document.forms[0].salida.value = Total;

}

//****************************************************************************************************
//****************************************************************************************************
function cuenta_vivienda()
{
	var Importe;
	var moneda;
	var Deduccion;
	var Posicion;
	
	Importe	= document.forms[0].Importe.value;
	Importe = QuitarPuntos(Importe);
	moneda  = document.forms[0].moneda.value
	// Cambiamos la coma por un punto
	Posicion = Importe.indexOf(',');
	if (Posicion != -1)
	{
		Importe = Importe.substring(0, Posicion)+'.'+Importe.substring(Posicion+1);
	}
	
	// Calculamos el 15%
	Deduccion = Importe * 0.15;
	
	if (moneda=='PT')
	{
		if (Deduccion > Number('225000'))
		{
			Deduccion = '225.000';
		}
		else
		{
			Deduccion = String(Deduccion)
			// Cambiamos el punto por una coma
			Posicion = Deduccion.indexOf('.');
			if (Posicion != -1)
			{
				Deduccion = Deduccion.substring(0, Posicion)+','+Deduccion.substring(Posicion+1);
			}
			Deduccion = FormatearImporte(Deduccion,'s','n','0');
		}
	}
	else
	{
		if (Deduccion > Number('1352.27'))
		{
			Deduccion = '1.352,27';
		}
		else
		{
			Deduccion = String(Deduccion)
			// Cambiamos el punto por una coma
			Posicion = Deduccion.indexOf('.');
			if (Posicion != -1)
			{
				Deduccion = Deduccion.substring(0, Posicion)+','+Deduccion.substring(Posicion+1);
			}
			Deduccion = FormatearImporte(Deduccion,'s','s','2');
		}
	}		
	return Deduccion;
}


  function irA(menu){

      top.location.href = menu.options[menu.selectedIndex].value;

  }

function calculos(form){



var notariacv;

var regristrocv;

var compraventa;



if (form.compraventa.value=="cv1") {notariacv=405;registrocv=149;compraventa=54091;}

if (form.compraventa.value=="cv2") {notariacv=412;registrocv=155;compraventa=60101;}

if (form.compraventa.value=="cv3") {notariacv=419;registrocv=161;compraventa=66111;}

if (form.compraventa.value=="cv4") {notariacv=426;registrocv=166;compraventa=72121;}

if (form.compraventa.value=="cv5") {notariacv=433;registrocv=171;compraventa=78132;}

if (form.compraventa.value=="cv6") {notariacv=440;registrocv=176;compraventa=84141;}

if (form.compraventa.value=="cv7") {notariacv=447;registrocv=182;compraventa=90151;}

if (form.compraventa.value=="cv8") {notariacv=454;registrocv=187;compraventa=96161;}

if (form.compraventa.value=="cv9") {notariacv=461;registrocv=192;compraventa=102172;}

if (form.compraventa.value=="cv10") {notariacv=468;registrocv=197;compraventa=108182;}

if (form.compraventa.value=="cv11") {notariacv=475;registrocv=203;compraventa=114192;}

if (form.compraventa.value=="cv12") {notariacv=482;registrocv=208;compraventa=120202;}

if (form.compraventa.value=="cv13") {notariacv=489;registrocv=213;compraventa=126212;}

if (form.compraventa.value=="cv14") {notariacv=496;registrocv=218;compraventa=132222;}

if (form.compraventa.value=="cv15") {notariacv=503;registrocv=223;compraventa=138232;}

if (form.compraventa.value=="cv16") {notariacv=510;registrocv=229;compraventa=144242;}

if (form.compraventa.value=="cv17") {notariacv=517;registrocv=234;compraventa=150253;}

if (form.compraventa.value=="cv18") {notariacv=520;registrocv=236;compraventa=156263;}

if (form.compraventa.value=="cv19") {notariacv=524;registrocv=238;compraventa=162273;}

if (form.compraventa.value=="cv20") {notariacv=527;registrocv=240;compraventa=168283;}

if (form.compraventa.value=="cv21") {notariacv=531;registrocv=242;compraventa=174293;}

if (form.compraventa.value=="cv22") {notariacv=534;registrocv=244;compraventa=180303;}

if (form.compraventa.value=="cv23") {notariacv=538;registrocv=246;compraventa=186313;}

if (form.compraventa.value=="cv24") {notariacv=541;registrocv=249;compraventa=192232;}

if (form.compraventa.value=="cv25") {notariacv=545;registrocv=251;compraventa=198333;}

if (form.compraventa.value=="cv26") {notariacv=548;registrocv=253;compraventa=204344;}

if (form.compraventa.value=="cv27") {notariacv=552;registrocv=255;compraventa=210354;}

if (form.compraventa.value=="cv28") {notariacv=555;registrocv=257;compraventa=216364;}

if (form.compraventa.value=="cv29") {notariacv=559;registrocv=259;compraventa=222374;}

if (form.compraventa.value=="cv30") {notariacv=562;registrocv=261;compraventa=228384;}

if (form.compraventa.value=="cv31") {notariacv=566;registrocv=263;compraventa=234394;}

if (form.compraventa.value=="cv32") {notariacv=569;registrocv=265;compraventa=240404;}

if (form.compraventa.value=="cv33") {notariacv=572;registrocv=267;compraventa=246414;}

if (form.compraventa.value=="cv34") {notariacv=575;registrocv=269;compraventa=252424;}

if (form.compraventa.value=="cv35") {notariacv=578;registrocv=271;compraventa=258434;}

if (form.compraventa.value=="cv36") {notariacv=581;registrocv=273;compraventa=264444;}

if (form.compraventa.value=="cv37") {notariacv=584;registrocv=275;compraventa=270454;}

if (form.compraventa.value=="cv38") {notariacv=587;registrocv=277;compraventa=276464;}

if (form.compraventa.value=="cv39") {notariacv=590;registrocv=279;compraventa=282474;}

if (form.compraventa.value=="cv40") {notariacv=593;registrocv=281;compraventa=288484;}

if (form.compraventa.value=="cv41") {notariacv=596;registrocv=283;compraventa=294494;}

if (form.compraventa.value=="cv42") {notariacv=599;registrocv=285;compraventa=300504;}

if (form.compraventa.value=="cv43") {notariacv=602;registrocv=287;compraventa=306514;}

if (form.compraventa.value=="cv44") {notariacv=605;registrocv=289;compraventa=312524;}

if (form.compraventa.value=="cv45") {notariacv=608;registrocv=291;compraventa=318534;}

if (form.compraventa.value=="cv46") {notariacv=611;registrocv=293;compraventa=324544;}

if (form.compraventa.value=="cv47") {notariacv=614;registrocv=295;compraventa=330554;}

if (form.compraventa.value=="cv48") {notariacv=617;registrocv=297;compraventa=336564;}

if (form.compraventa.value=="cv49") {notariacv=620;registrocv=299;compraventa=342574;}

if (form.compraventa.value=="cv50") {notariacv=623;registrocv=301;compraventa=348584;}


form.notariacv.value=notariacv+".- Euros";

form.registrocv.value=registrocv +".- Euros";

ajdc=0.005

ajdcv=Math.round(compraventa*ajdc)

if (form.tipo[3].checked) {ajdcv=0;}

form.ajdcv.value=ajdcv+".- Euros"



var ivacv



if (form.tipo[0].checked) {ivacv=0.04;}

if (form.tipo[0].checked) {ivacv=0.07;}

if (form.tipo[2].checked) {ivacv=0.16;}

if (form.tipo[3].checked) {ivacv=0.07;}



ivacv=compraventa*ivacv



ivacv=Math.round(ivacv)

form.ivacv.value=ivacv +".- Euros";





var notascv



if (form.tipo[0].checked) {notascv="Tenga en cuenta que además deberá pagar la plusvalía, que es un impuesto municipal, aunque en este caso suele ser mínimo";}

if (form.tipo[1].checked) {notascv="Tenga en cuenta que además deberá pagar la plusvalía del inmueble que adquiere";}

if (form.tipo[2].checked) {notascv="Tenga en cuenta que además deberá pagar la plusvalía del inmueble que adquiere ";}

if (form.tipo[3].checked) {notascv="Tenga en cuenta que en este caso la plusvalía que deberá abonar a su ayuntamiento puede ser importante, así como recuerde revisar, en el registro de la propiedad, el estado de cargas del inmueble, así como deudas con la comunidad, empresas eléctricas,etc. ";}



form.notascv.value=notascv



var registroh;

var notariah;

var hipoteca;

if (form.hipoteca.value=="h1") {registroh=137.5;notariah=540;hipoteca=45075;}

if (form.hipoteca.value=="h2") {registroh=139;notariah=543;hipoteca=48080;}

if (form.hipoteca.value=="h3") {registroh=140.5;notariah=545;hipoteca=51086;}

if (form.hipoteca.value=="h4") {registroh=142;notariah=547;hipoteca=54091;}

if (form.hipoteca.value=="h5") {registroh=143.5;notariah=549;hipoteca=57096;}

if (form.hipoteca.value=="h6") {registroh=145;notariah=551;hipoteca=60101;}

if (form.hipoteca.value=="h7") {registroh=146.5;notariah=553;hipoteca=63106;}

if (form.hipoteca.value=="h8") {registroh=148;notariah=555;hipoteca=66111;}

if (form.hipoteca.value=="h9") {registroh=149.5;notariah=558;hipoteca=69116;}

if (form.hipoteca.value=="h10") {registroh=151;notariah=560;hipoteca=72121;}

if (form.hipoteca.value=="h11") {registroh=152.5;notariah=562;hipoteca=75126;}

if (form.hipoteca.value=="h12") {registroh=155;notariah=564;hipoteca=78131;}

if (form.hipoteca.value=="h13") {registroh=156.5;notariah=567;hipoteca=81136;}

if (form.hipoteca.value=="h14") {registroh=158;notariah=569;hipoteca=84141;}

if (form.hipoteca.value=="h15") {registroh=159.5;notariah=571;hipoteca=87146;}

if (form.hipoteca.value=="h16") {registroh=162;notariah=573;hipoteca=90151;}

if (form.hipoteca.value=="h17") {registroh=162.5;notariah=574;hipoteca=93156;}

if (form.hipoteca.value=="h18") {registroh=163;notariah=575;hipoteca=96161;}

if (form.hipoteca.value=="h19") {registroh=163.5;notariah=575;hipoteca=99166;}

if (form.hipoteca.value=="h20") {registroh=164;notariah=576;hipoteca=102172;}

if (form.hipoteca.value=="h21") {registroh=165;notariah=578;hipoteca=105177;}

if (form.hipoteca.value=="h22") {registroh=166;notariah=580;hipoteca=108182;}

if (form.hipoteca.value=="h23") {registroh=166.5;notariah=581;hipoteca=111187;}

if (form.hipoteca.value=="h24") {registroh=167;notariah=582;hipoteca=114192;}

if (form.hipoteca.value=="h25") {registroh=167.5;notariah=583;hipoteca=117197;}

if (form.hipoteca.value=="h26") {registroh=168;notariah=584;hipoteca=120202;}

if (form.hipoteca.value=="h27") {registroh=170;notariah=587;hipoteca=126212;}

if (form.hipoteca.value=="h28") {registroh=171;notariah=589;hipoteca=132212;}

if (form.hipoteca.value=="h29") {registroh=172;notariah=591;hipoteca=138222;}

if (form.hipoteca.value=="h30") {registroh=174;notariah=593;hipoteca=144232;}

if (form.hipoteca.value=="h31") {registroh=175;notariah=596;hipoteca=150242;}

if (form.hipoteca.value=="h32") {registroh=176;notariah=598;hipoteca=156252;}

if (form.hipoteca.value=="h33") {registroh=178;notariah=600;hipoteca=162272;}

if (form.hipoteca.value=="h34") {registroh=179;notariah=603;hipoteca=168282;}

if (form.hipoteca.value=="h35") {registroh=180;notariah=605;hipoteca=174292;}

if (form.hipoteca.value=="h36") {registroh=182;notariah=607;hipoteca=180302;}

if (form.hipoteca.value=="h37") {registroh=183;notariah=609;hipoteca=186312;}

if (form.hipoteca.value=="h38") {registroh=185;notariah=612;hipoteca=192322;}

if (form.hipoteca.value=="h39") {registroh=186;notariah=614;hipoteca=198332;}

if (form.hipoteca.value=="h40") {registroh=189;notariah=618;hipoteca=210352;}

if (form.hipoteca.value=="h41") {registroh=191;notariah=623;hipoteca=222372;}

if (form.hipoteca.value=="h42") {registroh=194;notariah=627;hipoteca=234392;}

if (form.hipoteca.value=="h43") {registroh=197;notariah=631;hipoteca=246412;}

if (form.hipoteca.value=="h44") {registroh=200;notariah=635;hipoteca=258432;}

if (form.hipoteca.value=="h45") {registroh=203;notariah=639;hipoteca=270452;}

if (form.hipoteca.value=="h46") {registroh=206;notariah=643;hipoteca=282472;}

if (form.hipoteca.value=="h47") {registroh=209;notariah=647;hipoteca=294492;}

if (form.hipoteca.value=="h48") {registroh=211;notariah=651;hipoteca=306512;}

if (form.hipoteca.value=="h49") {registroh=214;notariah=655;hipoteca=318532;}

if (form.hipoteca.value=="h50") {registroh=217;notariah=659;hipoteca=330552;}

if (form.hipoteca.value=="h51") {registroh=220;notariah=663;hipoteca=342572;}


form.registroh.value=registroh +".- Euros";

form.notariah.value=notariah +".- Euros";

ajde=0.009

ajdh=Math.round(hipoteca*ajde)

form.ajdh.value=ajdh +".- Euros"; 



tasacionh=250

form.tasacionh.value=tasacionh  +".- Euros.";



seguro=975

seguroh=compraventa/seguro

seguroh=Math.round(seguroh)

form.seguroh.value=seguroh +".- Euros.";



if(compraventa<=hipoteca){alert("Lo más aconsejable es que el valor de la compraventa sea mayor que el de la hipoteca")}



comision=form.comision.value;

cah=comision/100;

cah=cah*hipoteca;

form.cah.value=cah +".- Euros.";



notash="Los anteriores gastos se pueden ver incrementados por el seguro de amortización( un seguro de vida por el importe de la hipoteca) más el coste de la gestoría que gestione los pagos de impuestos y la presentación de la documentación en el registro"

form.notash.value=notash



//Totales

var totalcv;

totalcv=(ivacv+notariacv+registrocv+ajdcv);

form.totalcv.value=totalcv +".- Euros.";



var totalh;

totalh=(ajdh+notariah+registroh+cah+seguroh+tasacionh);

form.totalh.value=totalh +".- Euros.";

var total

total=(totalcv+totalh)

form.total.value=total +".- Euros.";



}

