if (window.getId == null)
{
	function getId(id)
	{
		return document.getElementById(id);
	}
}

function turno(id)
{
	getId('idturno' + id).value = 1;
}

function agregar_producto_input()
{
	if (getId('nombre_destinatario').value.length > 0)
	{
		getId('id_destinatario').disabled = true;
	}
	else
	{
		getId('id_destinatario').disabled = false;
	}
}

function agregar_producto_select()
{
	if (getId('id_destinatario').value > 0)
	{
		getId('nombre_destinatario').disabled = true;
	}
	else
	{
		getId('nombre_destinatario').disabled = false;
	}
}

function validar_agregar_producto()
{
	var id_destinatario = 0;
	var nombre_destinatario = 0;
	
	if (getId('id_destinatario').value > 0)
	{
		var id_destinatario = 1;
	}
	if (getId('nombre_destinatario').value.length > 0)
	{
		var nombre_destinatario = 1;
	}	
	
	if ((id_destinatario == 1 && nombre_destinatario == 1) || (id_destinatario == 0 && nombre_destinatario == 0))
	{
		alert('Debe selecionar un destinatario o agregar un nombre');
		getId('id_destinatario').focus();
		return false;
	}
}

function validar_checkout()
{
	// - Facturación
	if (getId('f_razon').value == '')
	{
		alert('Debe ingresar el destinatario.');
		window.location = '#factu';
		getId('f_razon').focus();
		return false;
	}

	if (getId('f_direccion').value == '')
	{
		alert('Debe ingresar la direccion.');
		window.location = '#factu';
		getId('f_direccion').focus();
		return false;
	}

	if (getId('f_barrio').value == '')
	{
		alert('Debe ingresar el barrio.');
		window.location = '#factu';
		getId('f_barrio').focus();
		return false;
	}

	if (getId('f_ciudad').value == '')
	{
		alert('Debe ingresar la ciudad.');
		window.location = '#factu';
		getId('f_ciudad').focus();
		return false;
	}

	if (getId('f_provincia').value == '')
	{
		alert('Debe ingresar la provincia.');
		window.location = '#factu';
		getId('f_provincia').focus();
		return false;
	}

	if (getId('f_cp').value == '')
	{
		alert('Debe ingresar el código postal.');
		window.location = '#factu';
		getId('f_cp').focus();
		return false;
	}

	if (getId('f_telefono').value == '')
	{
		alert('Debe ingresar el teléfono.');
		window.location = '#factu';
		getId('f_telefono').focus();
		return false;
	}
	
	if (getId('f_pais').value < 1)
	{
		alert('Debe seleccionar el país.');
		window.location = '#factu';
		getId('f_pais').focus();
		return false;
	}

	// - Forma de pago
	if (getId('forma_pago_1').checked == false && getId('forma_pago_2').checked == false && getId('forma_pago_3').checked == false && getId('forma_pago_4').checked == false && getId('forma_pago_5').checked == false)
	{
		alert('Debe seleccionar la forma de pago.');
		getId('forma_pago_1').focus();
		window.location = '#formadepago';
		return false;
	}
	
	// - Destinatarios
	var destinatarios = getId('cantidad_destinatarios').value;
	for (i = 0; i < destinatarios; i++)
	{
		if (getId('destinatario' + i).value == '')
		{
			alert('Debe ingresar el destinatario.');
			window.location = '#desti' + i;
			getId('destinatario' + i).focus();
			return false;
		}
		
		if (getId('direccion' + i).value == '')
		{
			alert('Debe ingresar la direccion.');
			window.location = '#desti' + i;
			getId('direccion' + i).focus();
			return false;
		}
		
		if (getId('barrio' + i).value == '')
		{
			alert('Debe ingresar el barrio.');
			window.location = '#desti' + i;
			getId('barrio' + i).focus();
			return false;
		}
		
		if (getId('ciudad' + i).value == '')
		{
			alert('Debe ingresar la ciudad.');
			window.location = '#desti' + i;
			getId('ciudad' + i).focus();
			return false;
		}
		
		if (getId('provincia' + i).value == '')
		{
			alert('Debe ingresar la provincia.');
			window.location = '#desti' + i;
			getId('provincia' + i).focus();
			return false;
		}

		if (getId('telefono' + i).value == '')
		{
			alert('Debe ingresar el teléfono.');
			window.location = '#desti' + i;
			getId('telefono' + i).focus();
			return false;
		}

		if (getId('zona' + i).value < 1)
		{
			alert('Debe seleccionar la zona de entrega.');
			window.location = '#desti' + i;
			getId('zona' + i).focus();
			return false;
		}
		
		if (getId('fechasel' + i).value == '')
		{
			alert('Debe seleccionar una fecha de engrega.');
			window.location = '#desti' + i;
			//getId('idturno' + i).focus();
			return false;
		}

		if (getId('idturno' + i).value == 0)
		{
			alert('Debe seleccionar un turno de entrega.');
			window.location = '#desti' + i;
			//getId('idturno' + i).focus();
			return false;
		}

		if (getId('tipo_destino' + i).value == "")
		{
			alert('Debe seleccionar un tipo de destino.');
			window.location = '#tipo_dest' + i;
			//getId('idturno' + i).focus();
			return false;
		}

	}
}
