PopupVirtualKeyboard = new function() {
    var self = this;
    var hWnd = null;
    var unloadHandler;
    var p = (function (sname){var sc = document.getElementsByTagName('script'),sr = new RegExp('^(.*/|)('+sname+')([#?]|$)');for (var i=0,scL=sc.length; i<scL; i++) {var m = String(sc[i].src).match(sr);if (m) {if (m[1].match(/^((https?|file)\:\/{2,}|\w:[\\])/)) return m[1];if (m[1].indexOf("/")==0) return m[1];b = document.getElementsByTagName('base');if (b[0] && b[0].href) return b[0].href+m[1];return (document.location.href.match(/(.*[\/\\])/)[0]+m[1]).replace(/^\/+(?=\w:)/,"");}}return null;})('vk_popup.js');
    self.isOpen = function () {
        return null!=hWnd && !hWnd.closed;
    }
    var tgt = null;
    self.attachInput = function(el) {
        if (hWnd && !hWnd.closed && hWnd.VirtualKeyboard) {
            return hWnd.VirtualKeyboard.attachInput(el);
        }
        return false
    }
    self.open =
    self.show = function (target, unload) {
        if (!hWnd || hWnd.closed) {
          hWnd = (window.showModelessDialog||window.open)(p+"vk_popup.html",window.showModelessDialog?window:"_blank","status=0,title=0,dependent=yes,dialog=yes,resizable=no,scrollbars=no,width=500,height=500");
          unloadHandler = unload;
          tgt = target;
          return true;
        }
        return false;
    }
    self.close = 
    self.hide = function (target) {
        if (!hWnd || hWnd.closed) return false;
        if (hWnd.VirtualKeyboard.isOpen()) hWnd.VirtualKeyboard.hide();
        hWnd.close();
        hWnd = null;
        if ('function' == typeof unloadHandler) {
            unloadHandler();
        }
    }
    self.toggle = function (input) {
        self.isOpen()?self.close():self.open(input);
    }
    self.onload = function () {
        if ('string' == typeof tgt)
            tgt = document.getElementById(tgt);
        hWnd.VirtualKeyboard.show( tgt
                                  ,hWnd.document.body
                                  ,hWnd.document.body.parentNode
                                 );
        hWnd.document.body.className = hWnd.document.body.parentNode.className = 'VirtualKeyboardPopup';
        if (hWnd.sizeToContent) {
            hWnd.sizeToContent();
        } else {
            var kbd = hWnd.document.body.firstChild;
            while ("virtualKeyboard" != kbd.id) {
                hWnd.document.body.removeChild(kbd);
                kbd = hWnd.document.body.firstChild;
            }
            hWnd.dialogHeight = kbd.offsetHeight+'px';
            hWnd.dialogWidth = kbd.offsetWidth+'px';
            hWnd.resizeTo(kbd.offsetWidth+hWnd.DOM.getOffsetWidth()-hWnd.DOM.getClientWidth()
                         ,kbd.offsetHeight+hWnd.DOM.getOffsetHeight()-hWnd.DOM.getClientHeight());
        }
        hWnd.onunload = self.close;
    }
    if (window.attachEvent) window.attachEvent('onunload', self.close);
    else if (window.addEventListener) window.addEventListener('unload', self.close, false);
}
