﻿function txtBuscadorMentiroso_OnFocus(oMe, sIdMostrar)
{
    var oTxt = document.getElementById(sIdMostrar);
    if (oMe && oTxt)
    {
        oMe.style.display = "none";
        oTxt.style.display = "inline";
        oTxt.value = "";
        oTxt.focus();
    }
}

function txtBuscador_OnBlur(oMe, sIdMostrar)
{
    var oTxt = document.getElementById(sIdMostrar);
    if (oMe && oTxt)
    {
        if (oMe.value == "")
        {
            oMe.style.display = "none";
            oTxt.style.display = "inline";
        }
    }
}

function Buscador_Trim(s)
{
    var m = s.match(/^\s*(\S+(\s+\S+)*)\s*$/);
    return (m == null) ? "" : m[1];
}

function Buscador_MostrarCuadroCorrecto()
{
    var oTxt1 = document.getElementById("ctl00_UCSitioTitulo1_UCSitioBuscador1_txtBuscador");
    var oTxt2 = document.getElementById("ctl00_UCSitioTitulo1_UCSitioBuscador1_txtBuscadorMentiroso");
    if (oTxt1 && oTxt2)
    {
        if (oTxt1.value != "")
        {
            oTxt1.style.display = "inline";
            oTxt2.style.display = "none";
        }
        else
        {
            oTxt1.style.display = "none";
            oTxt2.style.display = "inline";
        }
    }
}

function hlkBuscador_OnClick(PathARaiz)
{
    var oTxt1 = document.getElementById("ctl00_UCSitioTitulo1_UCSitioBuscador1_txtBuscador");
    if (oTxt1)
    {
        if (Buscador_Trim(oTxt1.value) != "")
        {
            document.location.href = PathARaiz + "sitio/buscar.aspx?buscar=" + Buscador_Trim(oTxt1.value);
        }
        else
        {
            alert("Debe ingresar un texto a buscar");
        }
    }
}

function Buscador_GetKeyPressed(e)
{
	if(e.which)
	{
		keycode = e.which;  //Netscape
	}
	else
	{
		if (window.event)
		{
			keycode = window.event.keyCode; //Internet Explorer
		}
		else
		{
			keycode = -1;
		}
	}
	return keycode;
}

function txtBuscador_OnKeyPress(e, PathARaiz)
{
    keycode = Buscador_GetKeyPressed(e);
    if (keycode == 13) //enter
    {
        hlkBuscador_OnClick(PathARaiz);
		return false;
    }
    else
    {
		return true;
    }
}

