var archivoAjax = "./login_ajax.php";

function fn_txt_Busqueda_KeyPress (evento)
{
	if (!evento)
		var evento = window.event;

	if (evento.keyCode == 13)
		fn_Buscar ();
}

function fn_BloquearBotones ()
{
	var btn_Buscar = document.getElementById ("btn_Buscar");

	document.getElementById ("tablaExterior").style.cursor = 'wait';
	
	btn_Buscar.style.cursor = 'wait';
	btn_Buscar.disabled = true;
	
	if (document.getElementById ("btn_Buscar_Rubro"))
	{
		var btn_Buscar_Rubro = document.getElementById ("btn_Buscar_Rubro");
		
		btn_Buscar_Rubro.style.cursor = 'wait';
		btn_Buscar_Rubro.disabled = true;
	}
}	

function fn_Buscar ()
{
	var queryString = "";	
	var txt_Busqueda = document.getElementById ("txt_Busqueda");
	var cmb_Localidad = document.getElementById ("cmb_Localidad");

	if (trim (txt_Busqueda.value) != "")
	{
		if (fn_ValidarBarraInvertida (trim (txt_Busqueda.value)) == false)
		{
			alert ("No puede utilizarse la barra invertida en la b" + String.fromCharCode (250) + "squeda.");
			txt_Busqueda.focus ();
			return false;
		}
	}

	if (cmb_Localidad.value == "0" && trim (txt_Busqueda.value) == "")
	{
		alert ("Seleccione un criterio de b" + String.fromCharCode (250) + "squeda.");
		return false;
	}
	
	if (cmb_Localidad.value != "0")
	{
		if (queryString != "")
			queryString = queryString + "&";

		queryString = queryString + "Localidad=" + cmb_Localidad.value;
		queryString = queryString + "&nomLocalidad=" + fn_EspaciosAGuiones (cmb_Localidad[cmb_Localidad.selectedIndex].text);
	}
		
	if (trim (txt_Busqueda.value) != "")
	{
		if (queryString != "")
			queryString = queryString + "&";

		queryString = queryString + "Busqueda=" + trim (txt_Busqueda.value);
	}

	fn_BloquearBotones ();
	window.location.href = "./resultado_principal.php?" + queryString;
}

function fn_AbrirLogin (tipoAltaComercio)
{
	var ancho, alto, top, left;
	
	// Seteamos el DIV del sombreado.
	document.getElementById ("div_Sombreado").style.height = document.body.scrollHeight;
	document.getElementById ("div_Sombreado").style.width = document.body.scrollWidth;

	document.frm_Login.txt_TipoAltaComercio.value = tipoAltaComercio;

	// Limpiamos los campos.
	document.frm_Login.txt_Email.value = "";
	document.frm_Login.txt_Password.value = "";

	// Mostramos los DIVs.
	document.getElementById ("div_Sombreado").style.display = "block";
	document.getElementById ("div_Login").style.display = "block";

	// Seteamos el DIV del envío de e-mail.
	ancho = 416;
	alto = document.getElementById ("div_Login").clientHeight;
	
	top = parseInt ((document.body.clientHeight - alto) / 2) + document.body.scrollTop;
	left = parseInt ((document.body.clientWidth - ancho) / 2);	

	document.getElementById ("div_Login").style.width = ancho.toString () + "px";
	document.getElementById ("div_Login").style.top = top.toString () + "px";
	document.getElementById ("div_Login").style.left = left.toString () + "px";	

	document.getElementById ("txt_Email").focus ();
}

function fn_CerrarVentanaLogin ()
{
	document.getElementById ("div_Login").style.display = "none";
	document.getElementById ("div_Sombreado").style.display = "none";
}

function fn_BloquearBotonesLogin ()
{
	document.getElementById ("tablaFiltrosLogin").style.cursor = "wait";

	document.frm_Login.btn_Ingresar.style.cursor = "wait";
	document.frm_Login.btn_Ingresar.disabled = true;
}

function fn_HabilitarBotonesLogin  ()
{
	document.getElementById ("tablaFiltrosLogin").style.cursor = "default";

	document.frm_Login.btn_Ingresar.style.cursor = "pointer";
	document.frm_Login.btn_Ingresar.disabled = false;
}

function fn_LoginOk ()
{
	fn_BloquearBotonesLogin ();	
	window.location.href = "./editar_comercio.php?alta=" + document.frm_Login.txt_TipoAltaComercio.value;
}
