
function ValidarBusquedaAvanzada (frm)
{

	var message = "";
	
	if ((!frm.chk_virus.checked) && (!frm.chk_articulos.checked))
	{
		alert("Debe elegir buscar por al menos una de las opciones: Virus o Artículos");
		frm.chk_virus.focus();
		frm.chk_virus.select();
		return false;
	}
	else
	{
		if (frm.chk_virus.checked)
		{
			
			// Chequear que haya al menos un campo completado
			if (!hay_campo_virus)
			{
				alert("Ha seleccionado una búsqueda por virus pero no ha completado ningún campo.");
				frm.chk_virus.focus();
				frm.chk_virus.select();
				return false;
			}
			
			if (frm.vir_desde.value != "dd/mm/aaaa")
			{
				message = dateCheck(frm.vir_desde.value, "La fecha desde debe estar en formato dd/mm/aaaa");
				if (message != null)
				{
					validatePrompt(frm.vir_desde, message);
					return false;	
				}
			}

			if (frm.vir_hasta.value != "dd/mm/aaaa")
			{
				message = dateCheck(frm.vir_hasta.value, "La fecha hasta debe estar en formato dd/mm/aaaa");
				if (message != null)
				{
					validatePrompt(frm.vir_hasta, message);
					return false;	
				}
			}

			// Para vaciar estos campos			
			FocoEnFecha (frm.vir_desde);
			FocoEnFecha (frm.vir_hasta);			

		}

		if (frm.chk_articulos.checked)
		{

			// Chequear que haya al menos un campo completado
			if (!hay_campo_articulos)
			{
				alert("Ha seleccionado una búsqueda por artículos pero no ha completado ningún campo.");
				frm.chk_articulos.focus();
				frm.chk_articulos.select();
				return false;				
			}
			
			
			if (frm.art_desde.value != "dd/mm/aaaa")
			{
				message = dateCheck(frm.art_desde.value, "La fecha desde debe estar en formato dd/mm/aaaa");
				if (message != null)
				{
					validatePrompt(frm.art_desde, message);
					return false;	
				}
			}

			if (frm.art_hasta.value != "dd/mm/aaaa")
			{
				message = dateCheck(frm.art_hasta.value, "La fecha hasta debe estar en formato dd/mm/aaaa");
				if (message != null)
				{
					validatePrompt(frm.art_hasta, message);
					return false;	
				}
			}

			// Para vaciar estos camposz
			FocoEnFecha (frm.art_desde);
			FocoEnFecha (frm.art_hasta);

		}

	}

	return true;
	
}


function CampoTexto (campo, flagname)
{

	eval("tmp_campo = campo_" + flagname + "_con_info;");
	eval("flag = hay_campo_" + flagname + ";");

	if (campo.value != "")
	{
		flag = true;
		tmp_campo = campo.name;
	}
	else
	{
		if (tmp_campo == campo.name)
		{
			flag = false;
			tmp_campo = "";
		}
	}

	eval("campo_" + flagname + "_con_info = tmp_campo;");
	eval("hay_campo_" + flagname + " = flag;");


}

function CampoCombo (campo, flagname)
{

	eval("tmp_campo = combo_" + flagname + "_con_info;");
	eval("flag = hay_campo_" + flagname + ";");

	if (campo[campo.selectedIndex].value != "")
	{
		flag = true;
		tmp_campo = campo.name;
	}
	else
	{
		if (tmp_campo == campo.name)
		{
			flag = false;
			tmp_campo = "";
		}
	}

	eval("combo_" + flagname + "_con_info = tmp_campo;");
	eval("hay_campo_" + flagname + " = flag;");


}


function CampoCheckBox (campo, flagname)
{

	eval("tmp_campo = checkbox_" + flagname + "_con_info;");
	eval("flag = hay_campo_" + flagname + ";");

	if (campo.checked)
	{
		flag = true;
		tmp_campo = campo.name;
	}
	else
	{
		if (tmp_campo == campo.name)
		{
			flag = false;
			tmp_campo = "";
		}
	}

	eval("checkbox_" + flagname + "_con_info = tmp_campo;");
	eval("hay_campo_" + flagname + " = flag;");


}

function EstadoVirus (frm, valor)
{

	var frm_elem = frm.elements;
	var s = new String();

	frm.vir_nombre.disabled = valor;
	//frm.vir_fecha.disabled = valor;
	frm.vir_lenguaje.disabled = valor;
	frm.vir_gravedad.disabled = valor;
	frm.vir_desde.disabled = valor;
	frm.vir_hasta.disabled = valor;

	for (var i = 0; i < frm_elem.length; i++)
	{

		// Tengo que corregir esto

		s = new String(frm_elem[i].name);

		if ((s.match("vir_tip") != null) && (frm_elem[i].type) && (frm_elem[i].type = "checkbox"))
		{
			if ((frm_elem[i].name != "chk_virus") && (frm_elem[i].name != "chk_articulos"))
				frm_elem[i].disabled = valor;
		}
	}

	frm.vir_keyword.disabled = valor;

}

function EstadoArticulos (frm, valor)
{

	var frm_elem = frm.elements;
	var s = new String();

	frm.art_cat_todos.disabled = valor;
	frm.art_desde.disabled = valor;
	frm.art_hasta.disabled = valor;

	for (var i = 0; i < frm_elem.length; i++)
	{

		// Tengo que corregir esto

		s = new String(frm_elem[i].name);

		if ((s.match("art_cat") != null) && (frm_elem[i].type) && (frm_elem[i].type = "checkbox"))
		{
			if ((frm_elem[i].name != "chk_virus") && (frm_elem[i].name != "chk_articulos"))
				frm_elem[i].disabled = valor;
		}
	}

	frm.art_keyword.disabled = valor;

}

function DesmarcarCategorias (frm)
{

	var frm_elem = frm.elements;
	var s = new String();

	for (var i = 0; i < frm_elem.length; i++)
	{

		// Tengo que corregir esto

		s = new String(frm_elem[i].name);

		if ((s.match("art_cat") != null) && (frm_elem[i].type) && (frm_elem[i].type = "checkbox"))
		{
			if ((frm_elem[i].name != "chk_virus") && (frm_elem[i].name != "chk_articulos") && (frm_elem[i].name != "art_cat_todos"))
				frm_elem[i].checked = false;
		}
	}

}

function DesmarcarTipos (frm)
{

	var frm_elem = frm.elements;
	var s = new String();

	for (var i = 0; i < frm_elem.length; i++)
	{

		// Tengo que corregir esto

		s = new String(frm_elem[i].name);

		if ((s.match("vir_tip") != null) && (frm_elem[i].type) && (frm_elem[i].type = "checkbox"))
		{
			if ((frm_elem[i].name != "chk_virus") && (frm_elem[i].name != "chk_articulos") && (frm_elem[i].name != "vir_tip_todos"))
				frm_elem[i].checked = false;
		}
	}

}

function FocoEnFecha (campo)
{
	if (campo.value == "dd/mm/aaaa")
		campo.value = "";

}

function SubmitFrmForzado (campo)
{
	
	if ((window.event) && (window.event.keyCode))
	{
		if (window.event.keyCode == 13)
		{
			campo.blur();
			campo.form.submit();			
		}
	
	}

}

function FondoCampos (frm, color, cuales)
{

	var vir = 1;
	var art = 1;
	
	if (cuales != "todos")
	{
		if (cuales == "virus")
			art = 0;
	
		if (cuales == "articulos")
			vir = 0;
	
	}

	if (vir)
	{

		if (frm.vir_nombre.style)
			frm.vir_nombre.style.backgroundColor = color;

		if (frm.vir_lenguaje.style)
			frm.vir_lenguaje.style.backgroundColor = color;

		if (frm.vir_gravedad.style)
			frm.vir_gravedad.style.backgroundColor = color;

		if (frm.vir_keyword.style)
			frm.vir_keyword.style.backgroundColor = color;

		if (frm.vir_desde.style)
			frm.vir_desde.style.backgroundColor = color;

		if (frm.vir_hasta.style)
			frm.vir_hasta.style.backgroundColor = color;

	}
	
	if (art)
	{
	
		if (frm.art_desde.style)
			frm.art_desde.style.backgroundColor = color;

		if (frm.art_hasta.style)
			frm.art_hasta.style.backgroundColor = color;

		if (frm.art_keyword.style)
			frm.art_keyword.style.backgroundColor = color;
	
	}
	
}

var hay_campo_virus = false;
var campo_virus_con_info = "";
var checkbox_virus_con_info = "";
var combo_virus_con_info = "";

var hay_campo_articulos = false;
var campo_articulos_con_info = "";
var checkbox_articulos_con_info = "";
var combo_articulos_con_info = "";
