function contextSearch() {1
    this.containers = new Array();
    this.form = 'context_search_form';
    this.query = '';
   
    this.x = 0;
    this.y = 0;

    // Определяем всплывающий DIV-меню
    this.menu = document.createElement('div');
    this.menu.id = 'contextMenuDiv';
    this.menu.style.width = '175px';
    this.menu.style.height = '20px';
    this.menu.style.left = '150px';
    this.menu.style.top = '30px';
    this.menu.style.position = 'absolute';
    this.menu.style.background = '#FAFAFA';
    this.menu.style.border = '1px solid #c7c7c7';
    this.menu.style.padding = '7px';
    this.menu.style.display = 'none';
//    this.menu.style.overflow = 'hidden';
    this.menu.style.overflow = 'hidden';
    this.menu.innerHTML = '<a href="/search/" onclick="contextSearchForm.showForm(); return false;">Найти выделенный фрагмент</a>';
    document.getElementById('main').appendChild(this.menu);

    this.menuFocus = document.createElement('input');
    this.menuFocus.style.height = '0';
    this.menuFocus.style.width = '0';
    this.menuFocus.style.border = '0';
    this.menuFocus.onblur = function() { 
        setTimeout("contextSearchForm.menu.style.display = 'none';", 500);
    }
    this.menu.appendChild(this.menuFocus);
}

contextSearch.prototype.add = function(who) {
    // Входное...
    if(!who) {
        return false;
    }
    if(!who.id) {
        who = document.getElementById(who);
    }
    if(!who || !who.id) {
        return false;
    }
//    who.oncontextmenu = function() {return contextSearchForm.show();};
    this.containers.push(who);
    this.scan();
}

contextSearch.prototype.scan = function() {
    for(i=0,j=this.containers.length; i<j; i++) {
        
        this.containers[i].onmousedown = function(event) {
            contextSearchForm.getMousePos(event);
        }
        this.containers[i].oncontextmenu = function() {
            var res = contextSearchForm.show();
            return res;
        };
    }
}


contextSearch.prototype.show = function(e) {
    this.query = '';
    // Получаем выделенный текст
    if (document.selection != undefined) {
        var s = document.selection.createRange(); 
        if (s.text) {
            this.query = s.text;
            this.showMenu();
            return false;
        }
    }
    else {
        var s = document.getSelection();
        if(s && s.length > 0) {
            this.query = document.getSelection();
            this.showMenu();
            return false;
        }
    }
    return true;
}

contextSearch.prototype.getMousePos = function(e) {
    // Получаем координаты правой кнопки мыши
    if (!e) e = window.event;
    if(e.button != 2) {
        return false;
    }
    if (e.pageX || e.pageY) {
        this.x = e.pageX;
        this.y = e.pageY;
    }
    else if (e.clientX || e.clientY) {
        this.x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
        this.y = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
    }
}

contextSearch.prototype.showMenu = function() {
    this.menu.style.left = this.x+'px';
    this.menu.style.top  = this.y+'px';
    this.menu.style.display = 'block';
    this.menuFocus.focus();
}

contextSearch.prototype.showForm = function() {
    openLayer('context_search_form');
    if(document.getElementById('context_searchform')) {
        document.getElementById('context_searchform').value = trim(this.query);
        document.getElementById('context_searchform').focus();
        document.getElementById('context_search_form').style.top = (this.y-60)+'px';
    }
}