// JavaScript Document

function anadirCarro(codproducto)
{
	document.getElementById("codproducto").value=codproducto;
	document.getElementById("formulario").submit();
}

function borrarProducto(codproducto)
{
	document.getElementById("cant" + codproducto).value="0";
	document.getElementById("formulario").submit();
}

function vaciarCesta()
{
	document.getElementById("accion").value="v";
	document.getElementById("formulario").submit();
}

function controlTecla(e)
{
	tecla = (document.all) ? e.keyCode : e.which;
	if (tecla<48 || tecla>57)
	{
		return false;
	}
}

function cesta()
{
	document.getElementById("formulario").action="cestacompra.php";
	document.getElementById("formulario").submit();	
}

function confirmar()
{
	document.getElementById("formulario").action="confirmarpedido.php";
	document.getElementById("formulario").submit();
}

function volver()
{
	document.getElementById("formulario").action="cestacompra.php";
	document.getElementById("formulario").submit();
}

function catalogo()
{
	document.getElementById("formulario").action="catalogo.php";
	document.getElementById("formulario").submit();
}

function validarPedido()
{
	if (trim(document.getElementById("txtNombre").value)=="")
	{
		alert ("Introduzca el nombre");
		document.getElementById("txtNombre").focus();
		return;
	}
	
	if (trim(document.getElementById("txtTlf").value)=="")
	{
		alert ("Introduzca un teléfono de contacto");
		document.getElementById("txtTlf").focus();
		return;
	}
	
	if (! check_email(document.getElementById("txtEmail").value))
	{
		alert ("Dirección de e-mail no válida");
		document.getElementById("txtEmail").focus();
		return;
	}
	
	if (trim(document.getElementById("txtDireccion").value)=="")
	{
		alert ("Introduzca la dirección");
		document.getElementById("txtDireccion").focus();
		return;
	}
	
	if (trim(document.getElementById("txtCP").value)=="")
	{
		alert ("Introduzca el código postal");
		document.getElementById("txtCP").focus();
		return;
	}
	
	if (trim(document.getElementById("txtCiudad").value)=="")
	{
		alert ("Introduzca la ciudad");
		document.getElementById("txtCiudad").focus();
		return;
	}
	
	if (trim(document.getElementById("txtProvincia").value)=="")
	{
		alert ("Introduzca la provincia");
		document.getElementById("txtProvincia").focus();
		return;
	}
	
	document.getElementById("formulario").submit();
}