// JavaScript Document

function validaEtiqueta (campo, codigo)
{
	if	(trim(campo.value)=="")
	{
		alert (errormsg);
		campo.focus();
		return false;
	}
	
	if (isNaN(campo.value))
	{
		alert ("Código de la botella no válido");
		campo.focus();
		return false;
	}
	
	valor=parseInt(campo.value);
	if ((valor<(codigo*100000) || valor>(codigo*100000+125)) && (valor<((codigo*10+1)*10000) || valor>((codigo*10+1)*10000+125)))
	{
		alert ("Código de la botella no válido");
		campo.focus();
		return false;
	}
	return true;
}

function enviarEncuestaVinos()
{
	if (trim(document.getElementById("txtCodPers").value)=="")
	{
		alert (errormsg);
		document.getElementById("txtCodPers").focus();
		return;
	}
	else
	{
		if (parseInt(document.getElementById("txtCodPers").value)<1000 || parseInt(document.getElementById("txtCodPers").value)>1300 || isNaN(document.getElementById("txtCodPers").value))
		{
			alert ("Su código personal no es válido");
			document.getElementById("txtCodPers").focus();
			return;
		}
	}
	if (trim(document.getElementById("txtNombre").value)=="")
	{
		alert (errormsg);
		document.getElementById("txtNombre").focus();
		return;
	}
	
	// Botella Naranja
	
	if (! validaEtiqueta(document.getElementById("r0101"), 1))
	{
		return;	
	}
	
	for (i=1; i<=7; i++)
	{
		var obj='r020' + i;
		if (trim(document.getElementById(obj).value)=="")
		{
			alert (errormsg + " " + quitaTab(document.getElementById("cp02").innerHTML));
			document.location.href="#p02";
			return;
		}
	}
	
	if (document.getElementById("cmb03").value=="")
	{
		alert (errormsg + " " + quitaTab(document.getElementById("cp03").innerHTML));
		document.location.href="#p03";
		return;
	}
	
	// Botella Verde
	
	if (! validaEtiqueta(document.getElementById("r0401"), 2))
	{
		return;	
	}
	
	for (i=1; i<=7; i++)
	{
		var obj='r050' + i;
		if (trim(document.getElementById(obj).value)=="")
		{
			alert (errormsg + " " + quitaTab(document.getElementById("cp05").innerHTML));
			document.location.href="#p05";
			return;
		}
	}
	
	if (document.getElementById("cmb06").value=="")
	{
		alert (errormsg + " " + quitaTab(document.getElementById("cp06").innerHTML));
		document.location.href="#p06";
		return;
	}
	
	// Botella Negra
	
	if (! validaEtiqueta(document.getElementById("r0701"), 3))
	{
		return;	
	}
	
	for (i=1; i<=7; i++)
	{
		var obj='r080' + i;
		if (trim(document.getElementById(obj).value)=="")
		{
			alert (errormsg + " " + quitaTab(document.getElementById("cp08").innerHTML));
			document.location.href="#p08";
			return;
		}
	}
	
	if (document.getElementById("cmb09").value=="")
	{
		alert (errormsg + " " + quitaTab(document.getElementById("cp09").innerHTML));
		document.location.href="#p09";
		return;
	}
	
	// Común
	
	for (i=10; i<=17; i++)
	{
		var obj='cmb' + i;
		if (document.getElementById(obj).value=="")
		{
			alert (errormsg + " " + quitaTab(document.getElementById("cp" + i).innerHTML));
			document.location.href="#" + i;
			return;
		}
	}
	
	document.getElementById("formulario").action="encuestavinos.asp?submit=true";
	document.getElementById("formulario").submit();
}