/*
* Funcion que busca un string en un select
*/
function BuscaSelect(nse, obj)
{
    var key = nse?nse.keyCode:event.keyCode;
    if(key>=33 && key<=40)
    {
        return true;
    }
    var text = obj.getAttribute("filter");
    if(typeof(text)=="undefined" || text==null)
    {
        text = "";
    }
    if(key==8 && text.length>0)
    {
        text = text.substring(0, text.length-1);
    }
    else if(key>31)
    {
        text += String.fromCharCode(key);
    }
    else
    {
        return true;
    }
    text = text.toLowerCase();
    var plist = obj.getAttribute("list");
    var list = [];
    if(typeof(plist)=="undefined" || plist==null)
    {
        plist = "";
        for(var i=0, ilen=obj.options.length; i<ilen; i++)
        {
            list[i] = [obj.options[i].text, obj.options[i].value];
            plist += obj.options[i].text+":"+obj.options[i].value+",";
        }
        obj.setAttribute("list", plist);
    }
    else
    {
        var tlist = plist.split(',');
        for(var i=0, ilen=tlist.length; i<ilen; i++)
        {
            list[i] = tlist[i].split(':');
        }
    }
    for(var i=obj.options.length-1; i>=0; i--)
    {
        obj.options[i] = null;
    }
    var mode = obj.getAttribute("mode");
    if(typeof(mode)=="undefined" || mode==null)
    {
        mode = -1;
    }
    var optn;
    if(mode==1)
    {
        optn = document.createElement("OPTION");
        optn.text = text;
        optn.value = text;
        optn.selected = true;
        obj.options.add(optn);
        obj.selectedIndex = 0;
    }
    for(var i=0, ilen=list.length; i<ilen; i++)
    {
        if(list[i][0].toLowerCase().indexOf(text)==0)
        {
            optn = document.createElement("OPTION");
            optn.text = list[i][0];
            optn.value = list[i][1];
            if(mode==1)
            {
                optn.selected = true;
            }
            obj.options.add(optn);
            optn.selected = true;
        }
    }
    if(obj.options.length==0)
    {
        if(mode==0)
        {
            optn = document.createElement("OPTION");
            optn.text = text;
            optn.value = text;
            obj.options.add(optn);
        }
        else if(mode==2)
        {
            for(var i=0, ilen=list.length; i<ilen; i++)
            {
                optn = document.createElement("OPTION");
                optn.text = list[i][0];
                optn.value = list[i][1];
                obj.options.add(optn);
            }
            obj.selectedIndex = 0;
            text = "";
        }
            /* by patofeo, muestra el no hay resultados*/
            optn = document.createElement("OPTION");
            optn.text = "Sin Resultados";
            optn.value = "Sin Resultados";
            obj.options.add(optn);

    }
    obj.setAttribute("filter", text);
    return false;
}
