function compruebaEntero(obj)
{
	obj.style.backgroundColor="white";
	
	obj.style.backgroundColor="red";
	return true;
}

function compruebaCamposIguales(obj)
{
	obj.style.backgroundColor="white";
	if (obj.value != document.all.obj2.value)
	{
		obj.value="";
		obj2.value="";
		obj.style.backgroundColor="red";
		return false;	
	}		
    else 
   		return true;
}

function compruebaRequerido(obj)
{
	obj.style.backgroundColor="white";
	if ((obj.selectedIndex=="") || (obj.value == "") || (obj.value==0))
	{
		obj.style.backgroundColor="red";
		return false;	
	} 
	else
		return true;		
}

function rounddecimal(numero)
{
	var original=parseFloat(numero);
	var resultado=Math.round(original*100)/100 ;
	return resultado;
}


function calculaPrestamo(interes, capital, amortizacion)
{
	if (capital == '') {
		alert('Debe ingresar el importe a financiar');
		return false;
		}
		
	if (interes == '') {
		alert('Debe ingresar el interés');
		return false;
		}	
	if (amortizacion == '') {
		alert('Debe ingresar los años');
		return false;
		}
	interes = interes/(100);
	capital = (Delete_miles(capital) * interes) / 12;
	tae = Math.pow((1+interes/12),12*amortizacion);
	tae = 1- (1 / tae);
	form.cuota.value = rounddecimal(capital/tae);
}
 

function formatea_enteros_con_puntos (id)
{
	var tam, valor, temp, cont, tres;
	tam = id.value.length;
	// Si la persona digitó algo diferente de números enteros, no lo coge.
	if ((event.keyCode < 48) || (event.keyCode > 57))
	{
		event.returnValue = false;
	}
	else
	{
		valor = id.value;
		temp = "";
		// Miro la string y veo si ya he puesto puntos en ella. Y lo que no es punto copio a temp.
		for (cont=0; cont<id.value.length; cont++)
		{
			if (valor.charAt(cont)!= '.')
			{
				temp += valor.charAt(cont);
			}					
		}
		tres = 0;
		// Percorro de derecha a izquierda contando las casas y añadiendo el punto.
		valor= "";
		for (cont=temp.length; cont>=0; cont--)
		{
			if ((tres%3 == 0) && (tres!=0))
			{
				valor = '.' + valor;
			}
			valor = temp.charAt(cont) + valor;
			tres++;
		}
		id.value = valor;
	}
}

function formatea_entero (id)
{
	var tam;
	tam = id.value.length;
	// Si la persona digitó algo diferente de números enteros, no lo coge.
	if ((event.keyCode < 48) || (event.keyCode > 57))
	{
		event.returnValue = false;
	}
}

function formatea_interes (id)
{
	var tam;
	tam = id.value.length;
	if ((event.keyCode < 46) || (event.keyCode > 57))
	{
		if (event.keyCode == 44)
			alert('Utilizar el punto como separador.');
		event.returnValue = false;
	}
}

