    


    
                    
            
            function eEvent() {
  var me = this;
  
/////////////////////////////////
  me.get    = _get;
  me.cancel = _cancel;
  me.add    = _add;
  me.addT    = _addT;
  me.remove = _remove;
  me.fireEvent = _fireEvent;
  
/////////////////////////////////
  function _get(e) {
    var res = {ev: null, el: null};
    if (e) res.ev = e;
    if (window.event) res.ev = window.event;
    if (res.ev) {
      if (res.ev.target) res.el = res.ev.target;
      if (res.ev.srcElement) res.el = res.ev.srcElement;
    }
    return res;
  }
  function _cancel(ev) {
    if (!ev) {
      var res = _get();
      var ev  = res.ev;
    }
    if (ev.stopPropagation) ev.stopPropagation();
    if (ev.preventDefault) ev.preventDefault();
    ev.cancelBubble = true;
    ev.returnValue = false;
    
    return false;
  }
  function _addT(el, func, eventName) {
    if (el && el.addEventListener) {
      el.addEventListener (eventName, func, false);
    } else if (el && el.attachEvent) {
      el.attachEvent (eventName, func); //IE
    }
  }
  function _add(el, func, eventName) {
    if (el && el.addEventListener) {
      el.addEventListener(eventName, func, false);
    } else if (el && el.attachEvent) {
      el.attachEvent('on'+eventName, func);
    }
  }
  function _remove(el, func, eventName) {
    if (el.removeEventListener) {
      el.removeEventListener(eventName, func, false);
    } else if (el.detachEvent) {
      el.detachEvent('on'+eventName, func);
    }
  }
  function _fireEvent(el, eventName) {
    if (document.createEvent) {
      var evt = document.createEvent("MouseEvents");
      evt.initEvent(eventName, true, false);
      el.dispatchEvent(evt);
    } else el.fireEvent('on'+eventName);
  }
}

        
    

    
                    
            
            function eString(){
    var me = this;
    
    /////////////////////////////////    
    me.isLetter = _isLetter;
    me.isLetterOnly = _isLetterOnly;
    me.htmlSpecialChars = _htmlSpecialChars;
    me.html2SpecialChars = _html2SpecialChars;
    me.trim = _trim;
    me.specialTransliterate = _specialTransliterate;
    me.upFirst = _upFirst;
    me.lowFirst = _lowFirst;
    /////////////////////////////////
    
    if (typeof(String.prototype.trim) == 'undefined') {
        String.prototype.trim = function(chr){
            if (!chr) 
                chr = '';
            return this.replace(/^[\s|\n|\r|\t|\v]+|[\s|\n|\r|\t|\v]+$/gi, chr);
        }
    }
    
    function _trim(str, chr){
        if (!chr) 
            chr = '';
        return str.replace(/^[\s|\n|\r|\t|\v]+|[\s|\n|\r|\t|\v]+$/gi, chr);
    }
    
    function _isLetter(s){
        return (s.search(/[0-9a-zà-ÿ\-\/\" \r\n\¹\;\:\.\_]/gi) != -1);
    }
    
    function _isLetterOnly(s){
        return (s.search(/[0-9a-zà-ÿ]/gi) != -1)
    }
    
    function _htmlSpecialChars(nm){
        nm = nm.replace(/</g, '&lt;');
        nm = nm.replace(/>/g, '&gt;');
        nm = nm.replace(/\"/g, '&quot;');
        nm = nm.replace(/\'/g, '&#x27;');
        return nm
    }
    
    function _html2SpecialChars(str){
        return str.replace(/&quot;/g, '"').replace(/&#x27;/g, "'").replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&lt;br&gt;/gi, '\n').replace(/<br>/gi, '\n');
    }
    
    function _specialTransliterate(str){
        return str.replace(/¨/g, 'å').replace(/¸/g, 'å');
    }
    
    function _upFirst(str){
        return str.replace(/^\s*./g, function(match){
            return match.toUpperCase()
        });
    }
    
    function _lowFirst(str){
        return str.replace(/^\s*./g, function(match){
            return match.toLowerCase()
        });
    }
}

        
    

    
        
            function onGlobalKeyDown(e) {
  var res = EV.get(e);
  var ev  = res.ev;
  
  switch (ev.keyCode){
    case 112:  // F1
      if (ev.altKey == true) {
        if (!top.blockedToolbarButton.opOpenConsult) {
          if (top.consultingAvalible) top.setEvent({onClickToolbar: {windowId: 'utMainWindow', toolbarId: 'main', data: {id: 'opOpenConsult'}}});
        }
      } else top.setEvent({openHelp: showTopicNumber});
      try {
        ev.keyCode = 0;
      } catch(e) {}
      return EV.cancel(ev);
      break;
    case 113:  // F2 îñí. ìåíþ
      top.hideAllPopup();
      if (!top.blockedToolbarButton.OpenMainMenuNew) {
        top.setEvent({onClickToolbar: {windowId: 'utMainWindow', toolbarId: 'main', data: {id: 'OpenMainMenuNew'}}});
      }
      break;
    case 114:  // F3 ïðàéì
      top.hideAllPopup();
      if (!top.blockedToolbarButton.opOpenNewsLine) {
        top.setEvent({onClickToolbar: {windowId: 'utMainWindow', toolbarId: 'main', data: {id: 'opOpenNewsLine'}}});
      }
      try {
        ev.keyCode = 0;
      } catch(e) {}
      return EV.cancel(ev);
      break;
    case 115:  // F4 
      if (!top.blockedToolbarButton.opBaseSearch) {
        top.setEvent({onClickToolbar: {windowId: 'utMainWindow', toolbarId: 'main', data: {id: 'opBaseSearch'}}});
      }
      try {
        ev.keyCode = 0;
      } catch(e) {}
      return EV.cancel(ev);
      break;
    case 116:  // F5 ÏÏÑ
      top.hideAllPopup(); 
      if (!top.blockedToolbarButton.opOpenKeyWordSearch) {
        top.setEvent({onClickToolbar: {windowId: 'utMainWindow', toolbarId: 'main', data: {id: 'opOpenKeyWordSearch'}}});
      }
      try {
        ev.keyCode = 0;
      } catch(e) {}
      return EV.cancel(ev);
      break;
    case 117:  // F6 ÏÏÈÎ
      top.hideAllPopup();
      if (!top.blockedToolbarButton.opPublishSourceSearch) {
        top.setEvent({onClickToolbar: {windowId: 'utMainWindow', toolbarId: 'main', data: {id: 'opPublishSourceSearch'}}});
      }
      try {
        ev.keyCode = 0;
      } catch(e) {}
      return EV.cancel(ev);
      break;
    case 118:   // F7 ÏÏÐ
      top.hideAllPopup();      
      if (!top.blockedToolbarButton.opAttributeSearch) {
        top.setEvent({onClickToolbar: {windowId: 'utMainWindow', toolbarId: 'main', data: {id: 'opAttributeSearch'}}});
      }
      return EV.cancel(ev);
      break;
    case 120: // F9
      top.hideAllPopup();
      if (!top.blockedToolbarButton.opOpenLegistationReview) {
        top.setEvent({onClickToolbar: {windowId: 'utMainWindow', toolbarId: 'main', data: {id: 'opOpenLegistationReview'}}});
      }
      return EV.cancel(ev);
      break;
    case 122: // F11
      top.hideAllPopup();
      
      if (ev.shiftKey == true) {
        if (!top.blockedToolbarButton.opLoadFromFolder) {
          top.setEvent({onClickToolbar: {windowId: 'utMainWindow', toolbarId: 'child', data: {id: 'opLoadFromFolder'}}});
        }
        try {
          ev.keyCode = 0;
        } catch(e) {}
      }
      if (ev.ctrlKey == true) {
        if (!top.blockedToolbarButton.opSaveToFolder) {
          top.setEvent({onClickToolbar: {windowId: 'utMainWindow', toolbarId: 'child', data: {id: 'opSaveToFolder'}}});
        }
        try {
          ev.keyCode = 0;
        } catch(e) {}        
      }
      return EV.cancel(ev);
      break;
    case 123: // F12
      if (!top.blockedToolbarButton.opOpenDict) {
        top.hideAllPopup();
        top.setEvent({onClickToolbar: {windowId: 'utMainWindow', toolbarId: 'main', data: {id: 'opOpenDict'}}});
        try {
          ev.keyCode = 0;
        } catch(e) {}
        return EV.cancel(ev);
      }
      break;
    case 78 : // char n
      if (ev.altKey == true) {
        setDocumentTopic();
        try {
          ev.keyCode = 0;
        } catch(e) {}
        return EV.cancel(ev);
      }
      if (ev.ctrlKey == true) {
        try {
          ev.keyCode = 0;
        } catch(e) {}
        return EV.cancel(ev);
      }
      break;
    case 70 : //char f
      if (ev.ctrlKey == true) {
        top.hideAllPopup();  
        var onkeydownpage = top.getPage(top.getKey('lastPageKey'));
        var avail = {doc: 1, doclist: 1, consultation: 1, dictentry: 1, dictPharmEntry: 1};
        
        if (onkeydownpage && onkeydownpage.type && avail[onkeydownpage.type]) {
          top.setEvent({onClickToolbar: {windowId: onkeydownpage.windowId, toolbarId: 'child', data: {id: 'opFindContext'}}});
        }
        try {
          ev.keyCode = 0;
        } catch(e) {}
        return EV.cancel(ev);
      }
      break;
    case 73 : //char i
      if (ev.altKey == true) {
        top.hideAllPopup();  
        var onkeydownpage = top.getPage(top.getKey('lastPageKey'));
        if (onkeydownpage && onkeydownpage.type && onkeydownpage.type=='doc') {
          top.setEvent({onClickToolbar: {windowId: 'utMainWindow', toolbarId: 'child', data: {id: 'bDocInfo'}}});
        }
        try {
          ev.keyCode = 0;
        } catch(e) {}
        return EV.cancel(ev);
      }
      break;
    case 80 : //char p
      if (ev.altKey == true && typeof(setManualPage)=='function') {
        top.hideAllPopup();  
        try {
          ev.keyCode = 0;
          ev.stop();
        } catch(e) {}
        setManualPage();
        return EV.cancel(ev);
      }
      if (ev.ctrlKey == true) {
        top.hideAllPopup();  
        var onkeydownpage = top.getPage(top.getKey('lastPageKey'));
        if (onkeydownpage && onkeydownpage.type && 
            (onkeydownpage.type=='document' || onkeydownpage.type=='doclist')) {
           top.setEvent({onClickToolbar: {windowId: 'utMainWindow', toolbarId: 'child', data: {id: 'opPrintDialog'}}});
        }
      }
      break;
    case 83 : //char s
      if (ev.ctrlKey == true) {
        top.hideAllPopup();  
        var onkeydownpage = top.getPage(top.getKey('lastPageKey'));
        if (onkeydownpage && onkeydownpage.type && 
            (onkeydownpage.type=='document' || onkeydownpage.type=='doclist')) {
          top.setEvent({onClickToolbar: {windowId: 'utMainWindow', toolbarId: 'child', data: {id: 'opToMSWord'}}});
        }
        try {
          ev.keyCode = 0;
        } catch(e) {}
        return EV.cancel(ev);
      }
      break;
    case 13: //enter
      if (ev.ctrlKey == true) {
        if (top.getKey('lastPageKey')=='KZ' && typeof(onClickKZToolbar) == 'function') {
          onClickKZToolbar('b_search');          
        }
        try {
          ev.keyCode = 0;
        } catch(e) {}
        return EV.cancel(ev);          
      }
      break;
    case 27: //esc
      if (ev.ctrlLeft == true && ev.altLeft == true && ev.shiftLeft == true) {
        if (top.jsDump && !top.jsdump) top.jsdump = new top.jsDump();
        try {
          ev.keyCode = 0;
        } catch(e) {}
        return EV.cancel(ev);
      }
      if ((top.POP && top.POP.isShowPopup) ||
          (top.POPdate && top.POPdate.isShowPopup) ||
          (top.POPFULL && top.POPFULL.isShowPopup)) {
        top.hideAllPopup();
        try {
          ev.keyCode = 0;
          return EV.cancel(ev);
        } catch(e) {}
        return;
      }
      if (top.getKey('lastPageKey')=='KZ' && typeof(onClickKZToolbar)=='function') {
        onClickKZToolbar('b_cancel');
        try {
          ev.keyCode = 0;
        } catch(e) {}
        return EV.cancel(ev);
      }
      break;
    case 46:// delete
    case 110: // del
      if (ev.ctrlKey == true) {
        if (top.getKey('lastPageKey')=='KZ' && typeof(onClickKZToolbar)=='function') {
          onClickKZToolbar('b_clear');
        }
        try {
          ev.keyCode = 0;
        } catch(e) {}
        return EV.cancel(ev);
      } else if (res.el.tagName == 'INPUT') {
	  } else if (typeof(DetailBarBackFunc)=='function') {
        DetailBarBackFunc('b_delete');
        try {
          ev.keyCode = 0;
        } catch(e) {}
        return EV.cancel(ev);
      }
      break;
    case 37:
      if (ev.altKey == true) {
        var currentNumberPage = top.getKey('currentNumberPage');
        if (currentNumberPage>0) {
          if (top._DEFAULT.isMSIE5) {
            top.setEvent({setBackForwardButton: 'opBack'})
          } else top.setEvent({onClickToolbar: {windowId: 'utMainWindow', toolbarId: 'main', data: {id: 'opBack'}}});
        }
        try {
          ev.keyCode = 0;
        } catch(e) {}
        return EV.cancel(ev);
      }
      break;
    case 39:
      if (ev.altKey == true) {
        var currentNumberPage = top.getKey('currentNumberPage');
        if (currentNumberPage<=top.getKey('historyLength')) {
          if (top._DEFAULT.isMSIE5) {
            top.setEvent({setBackForwardButton: 'opForward'})
          } else top.setEvent({onClickToolbar: {windowId: 'utMainWindow', toolbarId: 'main', data: {id: 'opForward'}}});
        }
        try {
          ev.keyCode = 0;
        } catch(e) {}
        return EV.cancel(ev);
      }
      break;
    case 61:
    case 187:
    case 107:
      if (ev.ctrlKey == true) {
        top.setEvent({onClickToolbar: {windowId: 'utMainWindow', toolbarId: 'main', data: {id: 'opIncreaseFont'}}});
        try {
          ev.keyCode = 0;
        } catch(e) {}
        return EV.cancel(ev);
      }
      break;
    case 189:
    case 109:
      if (ev.ctrlKey == true) {
        top.setEvent({onClickToolbar: {windowId: 'utMainWindow', toolbarId: 'main', data: {id: 'opDecreaseFont'}}});
        try {
          ev.keyCode = 0;
        } catch(e) {}
        return EV.cancel(ev);
      }
      break;
  }
  function setDocumentTopic(text) {
    if (!text) text = '';
    var res = window.prompt('Ââåäèòå íîìåð òîïèêà', text);
    if (res) {
      res = res.substr(0,10);
      var topic_id = parseInt(Number(res));
      if (topic_id && topic_id>0 && (topic_id+100000)<2147483647) {
        top.setEvent({openObject: {
          type:'mi_doc', 
          pid: topic_id+100000,
          key: topic_id+100000,
          page: 1,
          elem_id: 0
        }});
      } else {
        alert('Ââåäåí íå êîððåêòíûé íîìåð òîïèêà.');
        arguments.callee(res);
      }
    }
  }
}

        
    
