function limpiaCotiza()
{
 primerrecibo.innerHTML = "";
 subsecuentes.innerHTML="";
 totalanual.innerHTML = "";
}

function validaPrimas(){
	var vacios = true;
	for (var i = 1; i < 6; i++)
	{
		if (eval("document.Form1.sexo"+i+".value") != "" || eval("document.Form1.edad"+i+".value") != "")
		{
			if (eval("document.Form1.sexo"+i+".value") == "")
			{
				alert("Selecciona el sexo de la persona: " + i);
				return false;
			}

			if (eval("document.Form1.edad"+i+".value") == "" || (!esEntero(eval("document.Form1.edad"+i+".value"))))
			{
				alert("Introduce una edad válida de la persona: " + i);

				return false;
			}
			if (!validaEdad("edad"+i))
			  return false;
			
			vacios = false;
		}
	}
	
	if (vacios){
		alert("Ingresa al menos el sexo y la edad de una persona");
		return false;
	}
	return true;
}
function validaCotizador(){
	if(!validaPrimas()){
		return false;
	}
	if(document.Form1.sumaasegurada.value == ""){
		alert("Selecciona la suma asegurada");
		return false;
	}
	if(document.Form1.estado.value == ""){
		alert("Selecciona el estado");
		return false;
	}

	if(document.Form1.deducible.value == ""){
		alert("Selecciona el deducible");
		return false;
	}
	if(document.Form1.coaseguro.value == ""){
		alert("Selecciona el coaseguro");
		return false;
	}
	if(document.Form1.formapago.value == ""){
		alert("Selecciona la forma de pago");
		return false;
	}
	
	return true;
}

function cotizarGastosMedicos(){
	if (validaCotizador()){
		document.Form1.action = "gastosmedicos.asp";
		document.Form1.op_gastosmedicos.value = "";
		document.Form1.op_gastosmedicosop.value = 1;
		document.Form1.submit();
		return true;
	}
	else{
		return false;
	}
}

function validaEdad(nombreCampo){
	if(eval("document.Form1." + nombreCampo + ".value") < 0 || eval("document.Form1." + nombreCampo + ".value") > 64)
	{
		alert("La edad debe ser mayor o igual a 0 y menor que 65 (>= 0 y < 65)");
		eval("document.Form1." + nombreCampo + ".value  = ''");
		return false;
	}
	return true;
}

function compraCotizador(){
	if (!validaCotizador())
	{
		alert("No ha realizado una cotización");
		return false;
	}
		document.Form1.action = "envia_gastosmedicos.asp";
		document.Form1.submit();
		return true;
}