if(!$D){
    function DomObj( e2 ){
        this.e=e2;
        //
        this.isNull=function(){return this.e==null;}
        //
        this.parentUp=function(n){
            //
        }
        this.enabled=function( ok ){this.e.disabled=(ok!=undefined ? !ok : false );}
        this.disabled=function(){this.enabled(false);}
        //
        this.setAttr=function( n, v){this.e.setAttribute(n, v);}
        //
        this.getAttr=function( n ){return this.e.getAttribute( n );}
        this.attr=function(n,v){
            if(v==undefined) return this.getAttr(n);
            else this.setAttr(n, v);
        }
        this.html=function(v){
            if(v==undefined) return this.e.innerHTML;
            else this.e.innerHTML=v;
        }
        //
        this.addClass=function(n){
            if(this.isNull()) return this;
            var pat=new RegExp('(^|\\s)'+n+'(\\s|$)');
            var attr=this.e.className;
            if(!pat.test(attr)){
                this.e.className+=' '+n;
            }
            return this;
        }
        //
        this.removeClass=function(n){
            if(this.isNull()) return this;
            var pat=new RegExp('(^|\\s)'+n+'(\\s|$)');
            this.e.className=this.e.className.replace( pat, ' ');
            return this;
        }
        //
        this.getValue=function(){return this.e.value;}
        this.setValue=function(v){this.e.value=v;}
        this.value=function(v){
            if(v!=undefined){
                if(this.e.value) this.e.value=v;
                else this.setAttr('value',v);
            }else{
                if(this.e && this.e.value) return this.e.value;
                else return this.getAttr('value');
            }
        }
        //
        this.toXString=function(){
            var ret='';
            if(this.isNull()) return 'Object is null';
            //alert(this.e)
            for(var o in this.e){
                ret+=o+'='+this.e[o]+';\t';
            }
            return ret;
        }
        this.$=function(){return this.e;}
        this.element=function(){return this.e;}
        /**
         * list = array( array( n=>name, v=value ), array( n=>name, v=value ) )
         */
        this.options=function( list ){
            var e=this.e;
            if(e.options){
                e.options.length=list.length;
                for(var i=0;i<list.length;i++){
                    e.options[i]=new Option(list[i].n,list[i].v);
                }
            }
        }
    }
    /**
     * 
     */
    function DomLibrary(){
        this.elems={};
        /**
         * @param id id of object
         */
        this.$=function(id){
            return document.getElementById(id);
        }
        /**
         * @param e DomObj or string id
         * @return DomObj
         */
        this.$$=function( e ){
            var e2=new DomObj(null);
            //alert(typeof e);
            if(e instanceof DomObj){
                e2=e;
            }
//            else if(e instanceof String){
            else if(typeof e=='string'){
                //alert(e);
                if(this.elems[e] && !this.elems[e].isNull() ){
                    var e3=document.getElementById( e );
                    this.elems[e].e=e3;
                    e2=this.elems[e];
                }else{
                    var e3=document.getElementById( e );
                    if(e3){
                        e2=new DomObj(e3);
                        this.elems[e]=e2;
                    }
                }
            }else /*if(e instanceof HTMLInputElement)*/{
//            }else if(typeof e=='object'){
                //alert(e);
                if(e.id){
                    if(this.elems[e.id]){
                        e2=this.elems[e.id];
                    }else{
                        e2=new DomObj(e);
                        this.elems[e.id]=e2;
                    }
                }else{
                    e.id='dom_'+(new Date).getTime();
                    e2=new DomObj(e);
                    this.elems[e.id]=e2;
                }
            }
            return e2;
        }
        /**
         * @return array
         */
        this.paramsGET=function(){
            var get=location.search;
            var tmp=[],tmp2=[],param=[];
            if(get != '') {
                tmp = (get.substr(1)).split('&');   // разделяем переменные
                for(var i=0; i < tmp.length; i++) {
                    tmp2 = tmp[i].split('=');       // массив param будет содержать
                    param[tmp2[0]] = tmp2[1];       // пары ключ(имя переменной)->значение
                }
            }
            return param;
        }
        /**
         * join two object
         */
        this.joinObjects=function( obj1, obj2 ){
            var ret=obj1;
            for(var p in obj2){
                ret[p]=obj2[p];
            }
            return ret;
        }
        this.printObject=function( obj ){
            var ret='';
            if( !obj ) return 'Object is null';

            for(var o in obj ){
                /*
                if(obj[o].length>0){
                    ret+=o+'='+this.printObject(obj[o])+';\t';
                }else{*/
                //if(!obj[o]) alert(o+'=fail');
                ret+=o+'='+(obj[o]!=undefined ? obj[o]:'')+';\t';
//                    ret+=o+'='+';\t';
                //}
            }
            return ret;
        }
        this.getScript=function( u, s_params, callback ){
            if(this._body==undefined) this._body=document.getElementsByTagName('body')[0];
            //alert( document.getElementsByTagName('body')[0] );
            var s=document.createElement('script');
            s.src=u+'?'+s_params;
            s.type='text/javascript';
            s.callback=(callback!=undefined ? callback : null );
            s.onerror=s.onload=s.onreadystatechange=function(){
                if(!this.loaded && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete')){
                    this.loaded = 1;
                    this.onerror = this.onload = this.onreadystatechange = null;
                    if(s.callback) s.callback();
                    var _this=this;
                    window.setTimeout(function(){_this.parentNode.removeChild(_this);delete s;}, 500 );
                }
            }
            this._body.appendChild(s);
        }
        //
        this.urlSearch2Array=function(){
            var data = {};
            if(location.search) {
                var pair = (location.search.substr(1)).split('&');
                for(var i = 0; i < pair.length; i ++) {
                    var param = pair[i].split('=');
                    data[param[0]] = param[1];
                }
            }
            return data;
        }
        //
        this.array2UrlSearch=function( a ){
            var s='';
            for(var o in a){
                s+=(s==''?'?':'&')+o+'='+a[o];
            }
            return s;
        }

    }
    var $D=new DomLibrary();
    // synonyms
    var domLib=$D;
    var $$=function(e){return $D.$$(e);}
}
