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

		if (!tmp)
			continue;
		
		if ((tmp.type == "text") || (tmp.type == "textarea"))
		{
			if (tmp.value == "")
			{
				if (!tmp2) 
				{
					error = true;
					tmp.className = "input_error";
					continue;
				}
				if ((tmp2.selectedIndex <= 0) || (tmp2.selectedIndex == null))
				{
					
					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 filtrar()
{
	var blogs = document.getElementById('blogs');
	
	location.href = '/backend/comentarios/listar/idblog/' + blogs.options[blogs.selectedIndex].value;
}

function valRegistro()
{
	if (document.getElementById('password').value != document.getElementById('password2').value)
	{
		document.getElementById('password').className = 'input_error';
		document.getElementById('password2').className = 'input_error';
	}
	
	var campos = Array('nombre', 'usuario', 'password', 'password2', 'email');
	
	validar('frmRegistro',campos);
}
