function InitSearchSelect(id)
{

    $("#boxsearch"+id).hide();

    $("#btnSearchSelect"+id).click(function(e) {
        $("#boxsearch"+id).show();
        $("#txtSearchItem"+id).focus();
        e.preventDefault();

        // Showlist
        //ShowSelectSearchItems(id,action,filter,order,dir,select);
        DoFilter(id);
        $(this).prop('disabled', true);

    });

    $("#btnCloseSearch"+id).click(function(e) {
         CloseSelectSearch(id);
        e.preventDefault();
    });

    $("#btnClearSearch"+id).click(function(e) {
        $("#txtSearchItem"+id).val("");
        $("#btnSearchItem"+id).click();
        e.preventDefault();
    });

    $("#txtSearchItem"+id).keypress(function(e) {
        if (e.keyCode==13)
        {
            $("#btnSearchItem"+id).click();
            e.preventDefault();
        }
    });

    $("#btnSearchItem"+id).click(function(e) {
        DoFilter(id);
        e.preventDefault();
    });
}

function ShowSelectSearchItems(id,action,f,o,d,s)
{

    var action = ajax_path+"lib/actions/"+action;
	var form_data = {
        filter: f,
        order: o,
        dir: d,
        select: s
    }

    //alert("Creando filtro: "+id+", "+action+", "+f+", "+o+", "+d+", "+s);



		$.ajax({
			type: "POST",
			url:     action,
			data:    form_data,
			async: 	 true,
            dataType:    "html",
			success: function(data)
			{
                $("#selectitems"+id).html(data);
			},
			error: function(response)
			{
				ShowAlertError("Problemas con el servidor al mostrar los datos de busqueda");

			}
		});

}

function CloseSelectSearch(id)
{
    $("#txtSearchItem"+id).val("");
    $("#boxsearch"+id).hide();
    $("#btnSearchSelect"+id).prop('disabled', false);
}
