function Selectable(vars){
    return new _Sel(vars);
}
function _Sel(vars){
    this.dom = vars.dom;
    this.valueDom = vars.valueDom;
    this.filter = vars.filter?true:false;
    this.onDblClick = vars.onDblClick;
    this.onClick = vars.onClick;
    this.callBack = vars.callBack;
    this.init(vars);
    this.filter = function(type){
        var t = this, dds = t.dom.getElementsByTagName("dd"), l = dds.length, i = 0, tx = "", t_p = type == 1?"S ":type == 2?"C ":type == 3?"D ":"";
        for(i; i < l; i = i + 1){
            if(type <= 3){
                if($eit(dds[i]).indexOf(t_p) == 1){
                    dds[i].style.display = "";
                }else{
                    dds[i].style.display = "none";
                }
            }else if(type == 4){
                if(dds[i].childNodes[0].innerHTML.indexOf("/css/images/note") > -1){
                    dds[i].style.display = "";
                }else{
                    dds[i].style.display = "none";
                }
            }
        }
    };
    this.removeFilter = function(){
        var t = this, dds = t.dom.getElementsByTagName("dd"), l = dds.length, i = 0;
        for(i; i < l; i = i + 1){
            dds[i].style.display = "";
        }
    };
    this.unselect = function(){
        this.valueDom.value = "";
        if(this.dom.oldSel){
            this.dom.oldSel.className = "";
            this.dom.oldSel = null;
        }
    }
}
_Sel.prototype.init = function(vars){
    var t = this, dds = t.dom.getElementsByTagName("dd"), l = dds.length, i = 0, val = t.valueDom.value, dbl = t.onDblClick?true:false;
    for(i; i < l; i = i + 1){
        dds[i].childNodes[0].onclick = function(){
            if(t.dom.oldSel)
                t.dom.oldSel.className = "";
            this.className = "selected";
            t.valueDom.value = this.parentNode.className;
            if(t.onClick)
                eval(t.onClick);
            if(t.dom.oldSel == this && dbl){
                eval(t.onDblClick);
            }
            t.dom.oldSel = this;
            //return false;
        };
        if(dds[i].childNodes.length > 1){
            try{
                dds[i].childNodes[1].onclick = function(){
                    if(t.dom.oldSel)
                        t.dom.oldSel.className = "";
                    this.className = "selected";
                    t.valueDom.value = this.parentNode.className;
                    if(t.onClick)
                        eval(t.onClick);
                    if(t.dom.oldSel == this && dbl){
                        eval(t.onDblClick);
                    }
                    t.dom.oldSel = this;
                }
            }catch(ignored){
            }
        }
        if(dds[i].className == val){
            dds[i].childNodes[0].className = "selected";
            dds[i].childNodes[0].focus();
            t.dom.oldSel = dds[i].childNodes[0];
        }
        dds[i].childNodes[0].onfocus = function(){
            if(this.className != "selected")
                this.className = "focused";
        };
        dds[i].childNodes[0].onblur = function(f){
            if(this.className != "selected")
                this.className = "";
        };
        if(dbl){
            dds[i].childNodes[0].onkeydown = function(e){
                if(!e)
                    e = window.event;
                var keyCode = e.keyCode?e.keyCode:e.which?e.which:e.charCode;
                if(keyCode == 13){
                    if(t.dom.oldSel != this)
                        this.onclick();
                    this.onclick();
                    return false;
                }else{
                    var x = 0;
                    for(x; x < l; x = x + 1){
                        if(dds[x].childNodes[0].innerHTML.charCodeAt(0) == keyCode){
                            dds[x].childNodes[0].focus();
                            break;
                        }
                    }
                }
                return true;
            };
            dds[i].childNodes[0].ondblclick = function(e){
                if(t.dom.oldSel != this)
                    this.onclick();
                this.onclick();
                return false;
            };
        }
    }
    if(typeof (t.callBack) == "function"){
        try{
            t.callBack()
        }catch(ignored){
        }
    }else if(typeof (t.callBack) == "string"){
        try{
            eval(t.callBack)
        }catch(ignored){
        }
    }
};