// JavaScript Document
function remaining(campo)
{
	if (campo.value.length > 500)
	{
		if (document.getElementById('restantes'))
			document.getElementById('restantes').innerHTML = '<span style="color:#F00; font-weight: bold;">Excedidos ' + ((500 - campo.value.length) * -1) + ' caracteres.</span>';
	}
	else
	{
		if (document.getElementById('restantes'))
			document.getElementById('restantes').innerHTML = (500 - campo.value.length) + ' caracteres restantes.';
	}
	
}

function validar(nombre,campos)
{
	if ((!campos) || (!nombre))
		return false;
	
	formulario = document.getElementById(nombre);
	
	error = false;
	for (x = 0; x < campos.length; x++)
	{
		tmp = document.getElementById(campos[x]);
		tmp2 = document.getElementById(campos[x]+'2');

		if (!tmp)
			continue;

		if ((tmp.type == "text") || (tmp.type == "textarea") || (tmp.type == "password") || (tmp.type == "file"))
		{
			if (!tmp.value)
			{
				error = true;
				tmp.className = "input_error";
			}
			if (tmp2)
			{
				if (tmp2.value != tmp.value)
				{
					error = true;
					tmp.className = "input_error";
					tmp2.className = "input_error";
				}
			}
		}
		else if (tmp.type == "select-one")
		{
			if ((tmp.selectedIndex <= 0) || (tmp.selectedIndex == null))
			{
				error = true;
				tmp.className = "input_error";
			}					
		}
	}
	if (error == true)
		alert("Por favor complete todos los campos");
	else
		formulario.submit();
}

function redir(url)
{
	location.href = url;	
}
