zk.load('zul,zul.wgt,zul.inp,zul.lang',function(){if(zk._p=zkpi('signer.widgets'))try{
var version_regex_base        = "^(\\d+)(?:\\.(\\d+)(?:\\.(\\d+)(?:[_\\.](\\d+))?)?)?";
var version_regex_strict      = version_regex_base + "$";
var version_regex_with_family_modifier = version_regex_base + "(\\*|\\+)?$";


var deployJavaContainer = 'appletContainerSafe';

var deployJava = function() {
	
	
	function documentWriteReplacement(t) {
        var conatainer = document.getElementById(deployJavaContainer);
        conatainer.innerHTML = t;
	}

	
	
	
    
    var hattrs = {
        core: [ 'id', 'class', 'title', 'style' ],
        i18n: [ 'lang', 'dir' ],
        events: [ 'onclick', 'ondblclick', 'onmousedown', 'onmouseup',
            'onmouseover', 'onmousemove', 'onmouseout', 'onkeypress',
            'onkeydown', 'onkeyup' ],
        applet: [ 'codebase', 'code', 'name', 'archive', 'object',
            'width', 'height', 'alt', 'align', 'hspace', 'vspace' ],
        object: [ 'classid', 'codebase', 'codetype', 'data', 'type',
            'archive', 'declare', 'standby', 'height', 'width', 'usemap',
            'name', 'tabindex', 'align', 'border', 'hspace', 'vspace' ]
    };

    var object_valid_attrs = hattrs.object.concat(hattrs.core, hattrs.i18n,
        hattrs.events);
    var applet_valid_attrs = hattrs.applet.concat(hattrs.core);

    
    
    function log(message) {
        if ( ! rv.debug ) {return};

        if (console.log) {
            console.log(message);
        } else {
            alert(message);
        }
    }

    
    
    
    
    function versionCheckEx(query, version) {
        if (query == null || query.length == 0) return true;

        var c = query.charAt(query.length - 1);

        
        if (c != '+' && c != '*' && (query.indexOf('_') != -1 && c != '_')) {
            query = query + "*";
            c = '*';
        }

        query = query.substring(0, query.length - 1);
        
        
        if (query.length > 0) {
            var z = query.charAt(query.length - 1);
            if (z == '.' || z == '_') {
                query = query.substring(0, query.length - 1);
            }
        }
        if (c == '*') {
            
            return (version.indexOf(query) == 0);
        } else if (c == '+') {
            
            return query <= version;
        }
        return false;
    }

    function getWebStartLaunchIconURL() {
        var imageUrl = '//java.com/js/webstart.png';
        try {
            
            return document.location.protocol.indexOf('http') != -1 ? 
                imageUrl : 'http:' + imageUrl;
        } catch (err) {
            return 'http:' + imageUrl;
        }
    }

     
     function constructGetJavaURL(query) {
	    
	var getJavaURL = 'http://java.com/dt-redirect';

	if (query == null || query.length == 0) return getJavaURL;
	if(query.charAt(0) == '&')
	{
	   query = query.substring(1, query.length);	
	}
	return getJavaURL + '?'+  query;
    }

    function arHas(ar, attr) {
        var len = ar.length;
        for (var i = 0; i < len; i++) {
            if (ar[i] === attr) return true;
        }
        return false;
    }

    function isValidAppletAttr(attr) {
        return arHas(applet_valid_attrs, attr.toLowerCase());
    }

    function isValidObjectAttr(attr) {
        return arHas(object_valid_attrs, attr.toLowerCase());
    }

    
    function enableWithoutCertMisMatchWorkaround(requestedJREVersion) {

       
       if ('MSIE' != deployJava.browserName) return true;

       
       
       
       if (deployJava.compareVersionToPattern(deployJava.getPlugin().version, 
                                     ["10", "0", "0"], false, true)) {
          return true;
       }

       

       if (requestedJREVersion  == null) {
          
          
          
          return false;
       }

       
       
       
       
       return !versionCheckEx("1.6.0_33+", requestedJREVersion);
    }

    

    var rv = {

    debug: null,

    
    version: "20120801",

    firefoxJavaVersion: null,

    myInterval: null,
    preInstallJREList: null,
    returnPage: null,
    brand: null,
    locale: null,
    installType: null,

    EAInstallEnabled: false,
    EarlyAccessURL: null,


    
    oldMimeType: 'application/npruntime-scriptable-plugin;DeploymentToolkit',
    mimeType: 'application/java-deployment-toolkit',

    
    launchButtonPNG: getWebStartLaunchIconURL(),

    browserName: null,
    browserName2: null,

    
    getJREs: function() {
        var list = new Array();
        if (this.isPluginInstalled()) {
            var plugin =  this.getPlugin();
            var VMs = plugin.jvms;
            for (var i = 0; i < VMs.getLength(); i++) {
                list[i] = VMs.get(i).version;
            }
        } else {
            var browser = this.getBrowser();

            if (browser == 'MSIE') {
                if (this.testUsingActiveX('1.7.0')) {
                    list[0] = '1.7.0';
                } else if (this.testUsingActiveX('1.6.0')) {
                    list[0] = '1.6.0';
                } else if (this.testUsingActiveX('1.5.0')) {
                    list[0] = '1.5.0';
                } else if (this.testUsingActiveX('1.4.2')) {
                    list[0] = '1.4.2';
                } else if (this.testForMSVM()) {
                    list[0] = '1.1';
                }
            } else if (browser == 'Netscape Family') {
                this.getJPIVersionUsingMimeType();
                if (this.firefoxJavaVersion != null) {
                    list[0] = this.firefoxJavaVersion;
                } else if (this.testUsingMimeTypes('1.7')) {
                    list[0] = '1.7.0';
                } else if (this.testUsingMimeTypes('1.6')) {
                    list[0] = '1.6.0';
                } else if (this.testUsingMimeTypes('1.5')) {
                    list[0] = '1.5.0';
                } else if (this.testUsingMimeTypes('1.4.2')) {
                    list[0] = '1.4.2';
                } else if (this.browserName2 == 'Safari') {
                    if (this.testUsingPluginsArray('1.7.0')) {
                        list[0] = '1.7.0';
                    } else if (this.testUsingPluginsArray('1.6')) {
                        list[0] = '1.6.0';
                    } else if (this.testUsingPluginsArray('1.5')) {
                        list[0] = '1.5.0';
                    } else if (this.testUsingPluginsArray('1.4.2')) {
                        list[0] = '1.4.2';
                    }
                }
            }
        }

        if (this.debug) {
            for (var i = 0; i < list.length; ++i) {
                log('[getJREs()] We claim to have detected Java SE ' + list[i]);
            }
        }

        return list;
    },

    
    installJRE: function(requestVersion, installCallback) {
        var ret = false;
        if (this.isPluginInstalled() && 
            this.isAutoInstallEnabled(requestVersion)) {
            var installSucceeded = false;
            if (this.isCallbackSupported()) {
               installSucceeded = 
                  this.getPlugin().installJRE(requestVersion, installCallback);
            } else {
               installSucceeded = this.getPlugin().installJRE(requestVersion);
            }

            if (installSucceeded) {
                this.refresh();
                if (this.returnPage != null) {
                    document.location = this.returnPage;
                }
            }
            return installSucceeded;
        } else {
            return this.installLatestJRE();
        }
    },

    
    isAutoInstallEnabled: function(requestedJREVersion) {
       
       if (!this.isPluginInstalled()) return false;

       if (typeof requestedJREVersion  == 'undefined') {
           requestedJREVersion = null;
       }

       return enableWithoutCertMisMatchWorkaround(requestedJREVersion);

    },

    
    isCallbackSupported: function() {
       return this.isPluginInstalled() && 
          this.compareVersionToPattern(this.getPlugin().version, 
                                       ["10", "2", "0"], false, true);
    },

    
    installLatestJRE: function(installCallback) {
        if (this.isPluginInstalled() && this.isAutoInstallEnabled()) {
            var installSucceeded = false;
            if (this.isCallbackSupported()) {
               installSucceeded = this.getPlugin().installLatestJRE(installCallback);
            } else {
               installSucceeded = this.getPlugin().installLatestJRE();
            }
            if (installSucceeded) {
                this.refresh();
                if (this.returnPage != null) {
                    document.location = this.returnPage;
                }
            }
            return installSucceeded;
        } else {
            var browser = this.getBrowser();
            var platform = navigator.platform.toLowerCase();
            if ((this.EAInstallEnabled == 'true') &&
                (platform.indexOf('win') != -1) &&
                (this.EarlyAccessURL != null)) {

                this.preInstallJREList = this.getJREs();
                if (this.returnPage != null) {
                    this.myInterval =
                        setInterval("deployJava.poll()", 3000);
                }

                location.href = this.EarlyAccessURL;

                
                
                return false;
            } else {
                if (browser == 'MSIE') {
                    return this.IEInstall();
                } else if ((browser == 'Netscape Family') &&
                           (platform.indexOf('win32') != -1)) {
                    return this.FFInstall();
                } else {
                    location.href = constructGetJavaURL(
                        ((this.returnPage != null) ?
                        ('&returnPage=' + this.returnPage) : '') +
                        ((this.locale != null) ?
                        ('&locale=' + this.locale) : '') +
                        ((this.brand != null) ?
                         ('&brand=' + this.brand) : ''));
                }
                
                
                return false;
            }
        }
    },


    
    runApplet: function(attributes, parameters, minimumVersion) {
        if (minimumVersion == 'undefined' || minimumVersion == null) {
            minimumVersion = '1.1';
        }


        var matchData = minimumVersion.match(version_regex_strict);

        if (this.returnPage == null) {
            
            this.returnPage = document.location;
        }

        if (matchData != null) {
            var browser = this.getBrowser();
            if (browser != '?') {
                if (this.versionCheck(minimumVersion + '+')) {
                    this.writeAppletTag(attributes, parameters);
                } else if (this.installJRE(minimumVersion + '+')) {
                    
                    
                    this.refresh();
                    location.href = document.location;
                    this.writeAppletTag(attributes, parameters);
                }
            } else {
                
                this.writeAppletTag(attributes, parameters);
            }
        } else {
            log('[runApplet()] Invalid minimumVersion argument to runApplet():' +
                      minimumVersion);
        }
    },


    
    writeAppletTag: function(attributes, parameters) {
        var startApplet = '<' + 'applet ';
        var params = '';
        var endApplet = '<' + '/' + 'applet' + '>';
        var addCodeAttribute = true;

        if (null == parameters || typeof parameters != 'object') {
            parameters = new Object();
        }

        for (var attribute in attributes) {
            if (! isValidAppletAttr(attribute)) {
                parameters[attribute] = attributes[attribute];
            } else {
                startApplet += (' ' +attribute+ '="' +attributes[attribute] + '"');
                if (attribute == 'code') {
                    addCodeAttribute = false;
                }
            }
        }

        var codebaseParam = false;
        for (var parameter in parameters) {
            if (parameter == 'codebase_lookup') {
                codebaseParam = true;
            }
            
            
            
            if (parameter == 'object' || parameter == 'java_object' ||
                parameter == 'java_code' ) {
                addCodeAttribute = false;
            }
            params += '<param name="' + parameter + '" value="' +
                parameters[parameter] + '"/>';
        }
        if (!codebaseParam) {
            params += '<param name="codebase_lookup" value="false"/>';
        }

        if (addCodeAttribute) {
            startApplet += (' code="dummy"');
        }
        startApplet += '>';

        documentWriteReplacement(startApplet + '\n' + params + '\n' + endApplet);
    },
  

     
    versionCheck: function(versionPattern)
    {
        var index = 0;

        var matchData = versionPattern.match(version_regex_with_family_modifier);
        if (matchData != null) {
            
            
            
            
            
            
            var familyMatch = false;
            var minMatch = false;

            var patternArray = new Array();

            for (var i = 1; i < matchData.length; ++i) {
                
                
                if ((typeof matchData[i] == 'string') && (matchData[i] != '')) {
                    patternArray[index] = matchData[i];
                    index++;
                }
            }

            if (patternArray[patternArray.length-1] == '+') {
                
                minMatch = true;
                familyMatch = false;
                patternArray.length--;
            } else if (patternArray[patternArray.length-1] == '*') {
                
                minMatch = false;
                familyMatch = true;
                patternArray.length--;
            } else if (patternArray.length < 4) {
                
                
                
                minMatch = false;
                familyMatch = true;
            }

            var list = this.getJREs();
            for (var i = 0; i < list.length; ++i) {
                if (this.compareVersionToPattern(list[i], patternArray,
                                                 familyMatch, minMatch)) {
                    return true;
                }
            }

            return false;
        } else {
            var msg = 'Invalid versionPattern passed to versionCheck: ' +
                  versionPattern;
            log('[versionCheck()] ' + msg);
            alert(msg);
            return false;
        }
    },


    
    isWebStartInstalled: function(minimumVersion) {

        var browser = this.getBrowser();
        if (browser == '?') {
            
            return true;
        }

        if (minimumVersion == 'undefined' || minimumVersion == null) {
            minimumVersion = '1.4.2';
        }

        var retval = false;
        var matchData = minimumVersion.match(version_regex_strict);
        if (matchData != null) {
            retval = this.versionCheck(minimumVersion + '+');
        } else {
            log('[isWebStartInstaller()] Invalid minimumVersion argument to isWebStartInstalled(): ' + minimumVersion);
            retval = this.versionCheck('1.4.2+');
        }
        return retval;
    },

    
    
    getJPIVersionUsingMimeType: function() {
        
        for (var i = 0; i < navigator.mimeTypes.length; ++i) {
            var s = navigator.mimeTypes[i].type;
            
            
            var m = s.match(/^application\/x-java-applet;jpi-version=(.*)$/);
            if (m != null) {
                this.firefoxJavaVersion = m[1];
                
                if ('Opera' != this.browserName2) {
                    break;
                }
            }
        }
    },

   
   
   
   
   
   launchWebStartApplication: function(jnlp) {
	var uaString = navigator.userAgent.toLowerCase();

	this.getJPIVersionUsingMimeType();

	
        if (this.isWebStartInstalled('1.7.0') == false) {

		
  		if ((this.installJRE('1.7.0+') == false) ||
                         ((this.isWebStartInstalled('1.7.0') == false))) {
                          return false;
                }
	}

        var jnlpDocbase = null;

        
        if (document.documentURI) {
		jnlpDocbase = document.documentURI;
	}

	
        if (jnlpDocbase == null) {
		jnlpDocbase = document.URL;
	}

        var browser = this.getBrowser();

        var launchTag;

        if (browser == 'MSIE') {

            launchTag = '<' +
                'object classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" ' +
		'width="0" height="0">' +
		'<' + 'PARAM name="launchjnlp" value="' + jnlp + '"' + '>' +
	        '<' + 'PARAM name="docbase" value="' + encodeURIComponent(jnlpDocbase) + '"' + '>' +
                '<' + '/' + 'object' + '>';
        } else if (browser == 'Netscape Family') {

            launchTag = '<' +
		'embed type="application/x-java-applet;jpi-version=' +
		this.firefoxJavaVersion + '" ' +
                'width="0" height="0" ' +
                'launchjnlp="' +  jnlp + '"' +
                'docbase="' +  encodeURIComponent(jnlpDocbase) + '"' +
                ' />';
        }

        if (document.body == 'undefined' || document.body == null) {
        	documentWriteReplacement(launchTag);
           
           document.location = jnlpDocbase;
        } else {
           var divTag = document.createElement("div");
           divTag.id = "div1";
           divTag.style.position = "relative";
           divTag.style.left = "-10000px";
           divTag.style.margin = "0px auto";
           divTag.className ="dynamicDiv";
           divTag.innerHTML = launchTag;
           document.body.appendChild(divTag);
        }
   },

   createWebStartLaunchButtonEx: function(jnlp, minimumVersion) {

        if (this.returnPage == null) {
            
            this.returnPage = jnlp;
        }

        var url = 'javascript:deployJava.launchWebStartApplication(\'' + jnlp +
			'\');';

        documentWriteReplacement('<' + 'a href="' + url +
                       '" onMouseOver="window.status=\'\'; ' +
                       'return true;"><' + 'img ' +
                       'src="' + this.launchButtonPNG + '" ' +
                       'border="0" /><' + '/' + 'a' + '>');
    },


    
    createWebStartLaunchButton: function(jnlp, minimumVersion) {

        if (this.returnPage == null) {
            
            this.returnPage = jnlp;
        }

        var url = 'javascript:' +
                  'if (!deployJava.isWebStartInstalled(&quot;' +
                      minimumVersion + '&quot;)) {' +
                      'if (deployJava.installLatestJRE()) {' +
                        'if (deployJava.launch(&quot;' + jnlp + '&quot;)) {}' +
                      '}' +
                  '} else {' +
                      'if (deployJava.launch(&quot;' + jnlp + '&quot;)) {}' +
                  '}';

        documentWriteReplacement('<' + 'a href="' + url +
                       '" onMouseOver="window.status=\'\'; ' +
                       'return true;"><' + 'img ' +
                       'src="' + this.launchButtonPNG + '" ' +
                       'border="0" /><' + '/' + 'a' + '>');
    },


    
    launch: function(jnlp) {
   
        document.location=jnlp;
        return true;
    },


    
    isPluginInstalled: function() {
        var plugin = this.getPlugin();
        if (plugin && plugin.jvms) {
            return true;
        } else {
            return false;
        }
    },

    
    isAutoUpdateEnabled: function() {
        if (this.isPluginInstalled()) {
            return this.getPlugin().isAutoUpdateEnabled();
        }
        return false;
    },

    
    setAutoUpdateEnabled: function() {
        if (this.isPluginInstalled()) {
            return this.getPlugin().setAutoUpdateEnabled();
        }
        return false;
    },

    
    setInstallerType: function(type) {
        this.installType = type;
        if (this.isPluginInstalled()) {
            return this.getPlugin().setInstallerType(type);
        }
        return false;
    },

    
    setAdditionalPackages: function(packageList) {
        if (this.isPluginInstalled()) {
            return this.getPlugin().setAdditionalPackages(
                                                     packageList);
        }
        return false;
    },

    
    setEarlyAccess: function(enabled) {
        this.EAInstallEnabled = enabled;
    },

    
    isPlugin2: function() {
        if (this.isPluginInstalled()) {
            if (this.versionCheck('1.6.0_10+')) {
                try {
                    return this.getPlugin().isPlugin2();
                } catch (err) {
                    
                }
            }
        }
        return false;
    },

    
    allowPlugin: function() {
        this.getBrowser();

        
        
        var ret = ('Safari' != this.browserName2 &&
            'Opera' != this.browserName2);

        return ret;
    },

    getPlugin: function() {
        this.refresh();

        var ret = null;
        if (this.allowPlugin()) {
            ret = document.getElementById('deployJavaPlugin');
        }
        return ret;
    },

    compareVersionToPattern: function(version, patternArray,
                                      familyMatch, minMatch) {
        if (version == undefined || patternArray == undefined) {
           return false;
        }
        var matchData = version.match(version_regex_strict);
        if (matchData != null) {
            var index = 0;
            var result = new Array();

            for (var i = 1; i < matchData.length; ++i) {
                if ((typeof matchData[i] == 'string') && (matchData[i] != ''))
                {
                    result[index] = matchData[i];
                    index++;
                }
            }

            var l = Math.min(result.length, patternArray.length);

            
            
            if (minMatch) {
                
                
                for (var i = 0; i < l; ++i) {
                    var resultTemp = parseInt(result[i]);
                    var patternArrayTemp = parseInt(patternArray[i]);
                    if (resultTemp < patternArrayTemp) {
                        return false;
                    } else if (resultTemp > patternArrayTemp) {
                        return true;
                    }
                }
                return true;
            } else {
                for (var i = 0; i < l; ++i) {
                    if (result[i] != patternArray[i]) return false;
                }
                if (familyMatch) {
                    
                    
                    return true;
                } else { 
                    
                    
                    return (result.length == patternArray.length);
                }
            }
        } else {
            return false;
        }
    },

    getBrowser: function() {

        if (this.browserName == null) {
            var browser = navigator.userAgent.toLowerCase();

            log('[getBrowser()] navigator.userAgent.toLowerCase() -> ' + browser);


            
            
            
            if ((browser.indexOf('msie') != -1) && (browser.indexOf('opera') == -1)) {
                this.browserName = 'MSIE';
                this.browserName2 = 'MSIE';
            } else if (browser.indexOf('trident') != -1 || browser.indexOf('Trident') != -1) {
				this.browserName = 'MSIE';
				this.browserName2 = 'MSIE';
			} else if (browser.indexOf('iphone') != -1) {
                
                this.browserName = 'Netscape Family';
                this.browserName2 = 'iPhone';
            } else if ((browser.indexOf('firefox') != -1) && (browser.indexOf('opera') == -1)) {
                this.browserName = 'Netscape Family';
                this.browserName2 = 'Firefox';
            } else if (browser.indexOf('chrome') != -1) {
                this.browserName = 'Netscape Family';
                this.browserName2 = 'Chrome';
            } else if (browser.indexOf('safari') != -1) {
                this.browserName = 'Netscape Family';
                this.browserName2 = 'Safari';
            } else if ((browser.indexOf('mozilla') != -1) && (browser.indexOf('opera') == -1)) {
                this.browserName = 'Netscape Family';
                this.browserName2 = 'Other';
            } else if (browser.indexOf('opera') != -1) {
                this.browserName = 'Netscape Family';
                this.browserName2 = 'Opera';
            } else {
                this.browserName = '?';
                this.browserName2 = 'unknown';
            }

            log('[getBrowser()] Detected browser name:'+ this.browserName +
                       ', ' + this.browserName2);
        }
        return this.browserName;
    },


    testUsingActiveX: function(version) {
        var objectName = 'JavaWebStart.isInstalled.' + version + '.0';

        
        
        
        if (typeof ActiveXObject == 'undefined' || !ActiveXObject) {
            log('[testUsingActiveX()] Browser claims to be IE, but no ActiveXObject object?');
            return false;
        }

        try {
            return (new ActiveXObject(objectName) != null);
        } catch (exception) {
            return false;
        }
    },


    testForMSVM: function() {
        var clsid = '{08B0E5C0-4FCB-11CF-AAA5-00401C608500}';

        if (typeof oClientCaps != 'undefined') {
            var v = oClientCaps.getComponentVersion(clsid, "ComponentID");
            if ((v == '') || (v == '5,0,5000,0')) {
                return false;
            } else {
                return true;
            }
        } else {
            return false;
        }
    },


    testUsingMimeTypes: function(version) {
        if (!navigator.mimeTypes) {
            log ('[testUsingMimeTypes()] Browser claims to be Netscape family, but no mimeTypes[] array?');
            return false;
        }

        for (var i = 0; i < navigator.mimeTypes.length; ++i) {
            s = navigator.mimeTypes[i].type;
            var m = s.match(/^application\/x-java-applet\x3Bversion=(1\.8|1\.7|1\.6|1\.5|1\.4\.2)$/);
            if (m != null) {
                if (this.compareVersions(m[1], version)) {
                    return true;
                }
            }
        }
        return false;
    },

    testUsingPluginsArray: function(version) {
        if ((!navigator.plugins) || (!navigator.plugins.length)) {
            return false;
        }
        var platform = navigator.platform.toLowerCase();

        for (var i = 0; i < navigator.plugins.length; ++i) {
            s = navigator.plugins[i].description;
            if (s.search(/^Java Switchable Plug-in (Cocoa)/) != -1) {
                
                if (this.compareVersions("1.5.0", version)) {
                    return true;
                }
            } else if (s.search(/^Java/) != -1) {
                if (platform.indexOf('win') != -1) {
                    
                    
                    if (this.compareVersions("1.5.0", version) ||
                        this.compareVersions("1.6.0", version)) {
                        return true;
                    }
                }
            }
        }
        
        if (this.compareVersions("1.5.0", version)) {
            return true;
        }
        return false;



    },

    IEInstall: function() {

        location.href = constructGetJavaURL(
            ((this.returnPage != null) ?
            ('&returnPage=' + this.returnPage) : '') +
            ((this.locale != null) ?
            ('&locale=' + this.locale) : '') +
            ((this.brand != null) ? ('&brand=' + this.brand) : ''));

         
         return false;
    },

    done: function (name, result) {
    },

    FFInstall: function() {

        location.href = constructGetJavaURL(
            ((this.returnPage != null) ?
            ('&returnPage=' + this.returnPage) : '') +
            ((this.locale != null) ?
            ('&locale=' + this.locale) : '') +
            ((this.brand != null) ? ('&brand=' + this.brand) : '') +
            ((this.installType != null) ?
                ('&type=' + this.installType) : ''));

         
         return false;
    },

    
    
    compareVersions: function(installed, required) {
        var a = installed.split('.');
        var b = required.split('.');

        for (var i = 0; i < a.length; ++i) {
            a[i] = Number(a[i]);
        }
        for (var i = 0; i < b.length; ++i) {
            b[i] = Number(b[i]);
        }
        if (a.length == 2) {
            a[2] = 0;
        }

        if (a[0] > b[0]) return true;
        if (a[0] < b[0]) return false;

        if (a[1] > b[1]) return true;
        if (a[1] < b[1]) return false;

        if (a[2] > b[2]) return true;
        if (a[2] < b[2]) return false;

        return true;
    },

    enableAlerts: function() {
        
        this.browserName = null;
        this.debug = true;
    },

    poll: function() {

        this.refresh();
        var postInstallJREList = this.getJREs();

        if ((this.preInstallJREList.length == 0) &&
            (postInstallJREList.length != 0)) {
            clearInterval(this.myInterval);
            if (this.returnPage != null) {
                location.href = this.returnPage;
            };
        }

        if ((this.preInstallJREList.length != 0) &&
            (postInstallJREList.length != 0) &&
            (this.preInstallJREList[0] != postInstallJREList[0])) {
            clearInterval(this.myInterval);
            if (this.returnPage != null) {
                location.href = this.returnPage;
            }
        }

    },

    writePluginTag: function() {
        var browser = this.getBrowser();

        if (browser == 'MSIE') {
            document.write('<' +
                'object classid="clsid:CAFEEFAC-DEC7-0000-0001-ABCDEFFEDCBA" ' +
                'id="deployJavaPlugin" width="0" height="0">' +
                '<' + '/' + 'object' + '>');
        } else if (browser == 'Netscape Family' && this.allowPlugin()) {
            this.writeEmbedTag();
        }
    },

    refresh: function() {
        navigator.plugins.refresh(false);

        var browser = this.getBrowser();
        if (browser == 'Netscape Family' && this.allowPlugin()) {
            var plugin = document.getElementById('deployJavaPlugin');
            
            if (plugin == null) {
                this.writeEmbedTag();
            }
        }
     },

    writeEmbedTag: function() {
        var written = false;
        if (navigator.mimeTypes != null) {
            for (var i=0; i < navigator.mimeTypes.length; i++) {
                if (navigator.mimeTypes[i].type == this.mimeType) {
                    if (navigator.mimeTypes[i].enabledPlugin) {
                    	documentWriteReplacement('<' +
                            'embed id="deployJavaPlugin" type="' +
                            this.mimeType + '" hidden="true" />');
                        written = true;
                    }
                }
            }
            
            if (!written) for (var i=0; i < navigator.mimeTypes.length; i++) {
                if (navigator.mimeTypes[i].type == this.oldMimeType) {
                    if (navigator.mimeTypes[i].enabledPlugin) {
                    	documentWriteReplacement('<' +
                            'embed id="deployJavaPlugin" type="' +
                            this.oldMimeType + '" hidden="true" />');
                    }
                }
            }
        }
    }
    }; 

    
	if  (rv.getBrowser() == "MSIE") {
		document.write('<object classid="clsid:CAFEEFAC-DEC7-0000-0001-ABCDEFFEDCBA" id="deployJavaPlugin" width="0" height="0"></object>')
	}
    if (rv.locale == null) {
        var loc = null;

        if (loc == null) try {
            loc = navigator.userLanguage;
        } catch (err) { }

        if (loc == null) try {
            loc = navigator.systemLanguage;
        } catch (err) { }

        if (loc == null) try {
            loc = navigator.language;
        } catch (err) { }

        if (loc != null) {
            loc.replace("-","_")
            rv.locale = loc;
        }
    }

    return rv;
}();



(function UMD(name,context,definition){
	
	context[name] = context[name] || definition();
	if (typeof module != "undefined" && module.exports) { module.exports = context[name]; }
	else if (typeof define == "function" && define.amd) { define(function $AMD$(){ return context[name]; }); }
})("Promise",typeof global != "undefined" ? global : this,function DEF(){
	
	"use strict";

	var builtInProp, cycle, scheduling_queue,
		ToString = Object.prototype.toString,
		timer = (typeof setImmediate != "undefined") ?
			function timer(fn) { return setImmediate(fn); } :
			setTimeout
	;

	
	try {
		Object.defineProperty({},"x",{});
		builtInProp = function builtInProp(obj,name,val,config) {
			return Object.defineProperty(obj,name,{
				value: val,
				writable: true,
				configurable: config !== false
			});
		};
	}
	catch (err) {
		builtInProp = function builtInProp(obj,name,val) {
			obj[name] = val;
			return obj;
		};
	}

	
	scheduling_queue = (function Queue() {
		var first, last, item;

		function Item(fn,self) {
			this.fn = fn;
			this.self = self;
			this.next = void 0;
		}

		return {
			add: function add(fn,self) {
				item = new Item(fn,self);
				if (last) {
					last.next = item;
				}
				else {
					first = item;
				}
				last = item;
				item = void 0;
			},
			drain: function drain() {
				var f = first;
				first = last = cycle = void 0;

				while (f) {
					f.fn.call(f.self);
					f = f.next;
				}
			}
		};
	})();

	function schedule(fn,self) {
		scheduling_queue.add(fn,self);
		if (!cycle) {
			cycle = timer(scheduling_queue.drain);
		}
	}

	
	function isThenable(o) {
		var _then, o_type = typeof o;

		if (o != null &&
			(
				o_type == "object" || o_type == "function"
			)
		) {
			_then = o.then;
		}
		return typeof _then == "function" ? _then : false;
	}

	function notify() {
		for (var i=0; i<this.chain.length; i++) {
			notifyIsolated(
				this,
				(this.state === 1) ? this.chain[i].success : this.chain[i].failure,
				this.chain[i]
			);
		}
		this.chain.length = 0;
	}

	
	
	
	function notifyIsolated(self,cb,chain) {
		var ret, _then;
		try {
			if (cb === false) {
				chain.reject(self.msg);
			}
			else {
				if (cb === true) {
					ret = self.msg;
				}
				else {
					ret = cb.call(void 0,self.msg);
				}

				if (ret === chain.promise) {
					chain.reject(TypeError("Promise-chain cycle"));
				}
				else if (_then = isThenable(ret)) {
					_then.call(ret,chain.resolve,chain.reject);
				}
				else {
					chain.resolve(ret);
				}
			}
		}
		catch (err) {
			chain.reject(err);
		}
	}

	function resolve(msg) {
		var _then, self = this;

		
		if (self.triggered) { return; }

		self.triggered = true;

		
		if (self.def) {
			self = self.def;
		}

		try {
			if (_then = isThenable(msg)) {
				schedule(function(){
					var def_wrapper = new MakeDefWrapper(self);
					try {
						_then.call(msg,
							function $resolve$(){ resolve.apply(def_wrapper,arguments); },
							function $reject$(){ reject.apply(def_wrapper,arguments); }
						);
					}
					catch (err) {
						reject.call(def_wrapper,err);
					}
				})
			}
			else {
				self.msg = msg;
				self.state = 1;
				if (self.chain.length > 0) {
					schedule(notify,self);
				}
			}
		}
		catch (err) {
			reject.call(new MakeDefWrapper(self),err);
		}
	}

	function reject(msg) {
		var self = this;

		
		if (self.triggered) { return; }

		self.triggered = true;

		
		if (self.def) {
			self = self.def;
		}

		self.msg = msg;
		self.state = 2;
		if (self.chain.length > 0) {
			schedule(notify,self);
		}
	}

	function iteratePromises(Constructor,arr,resolver,rejecter) {
		for (var idx=0; idx<arr.length; idx++) {
			(function IIFE(idx){
				Constructor.resolve(arr[idx])
				.then(
					function $resolver$(msg){
						resolver(idx,msg);
					},
					rejecter
				);
			})(idx);
		}
	}

	function MakeDefWrapper(self) {
		this.def = self;
		this.triggered = false;
	}

	function MakeDef(self) {
		this.promise = self;
		this.state = 0;
		this.triggered = false;
		this.chain = [];
		this.msg = void 0;
	}

	function Promise(executor) {
		if (typeof executor != "function") {
			throw TypeError("Not a function");
		}

		if (this.__NPO__ !== 0) {
			throw TypeError("Not a promise");
		}

		
		
		this.__NPO__ = 1;

		var def = new MakeDef(this);

		this["then"] = function then(success,failure) {
			var o = {
				success: typeof success == "function" ? success : true,
				failure: typeof failure == "function" ? failure : false
			};
			
			
			
			o.promise = new this.constructor(function extractChain(resolve,reject) {
				if (typeof resolve != "function" || typeof reject != "function") {
					throw TypeError("Not a function");
				}

				o.resolve = resolve;
				o.reject = reject;
			});
			def.chain.push(o);

			if (def.state !== 0) {
				schedule(notify,def);
			}

			return o.promise;
		};
		this["catch"] = function $catch$(failure) {
			return this.then(void 0,failure);
		};

		try {
			executor.call(
				void 0,
				function publicResolve(msg){
					resolve.call(def,msg);
				},
				function publicReject(msg) {
					reject.call(def,msg);
				}
			);
		}
		catch (err) {
			reject.call(def,err);
		}
	}

	var PromisePrototype = builtInProp({},"constructor",Promise,
		false
	);

	
	Promise.prototype = PromisePrototype;

	
	builtInProp(PromisePrototype,"__NPO__",0,
		false
	);

	builtInProp(Promise,"resolve",function Promise$resolve(msg) {
		var Constructor = this;

		
		
		if (msg && typeof msg == "object" && msg.__NPO__ === 1) {
			return msg;
		}

		return new Constructor(function executor(resolve,reject){
			if (typeof resolve != "function" || typeof reject != "function") {
				throw TypeError("Not a function");
			}

			resolve(msg);
		});
	});

	builtInProp(Promise,"reject",function Promise$reject(msg) {
		return new this(function executor(resolve,reject){
			if (typeof resolve != "function" || typeof reject != "function") {
				throw TypeError("Not a function");
			}

			reject(msg);
		});
	});

	builtInProp(Promise,"all",function Promise$all(arr) {
		var Constructor = this;

		
		if (ToString.call(arr) != "[object Array]") {
			return Constructor.reject(TypeError("Not an array"));
		}
		if (arr.length === 0) {
			return Constructor.resolve([]);
		}

		return new Constructor(function executor(resolve,reject){
			if (typeof resolve != "function" || typeof reject != "function") {
				throw TypeError("Not a function");
			}

			var len = arr.length, msgs = Array(len), count = 0;

			iteratePromises(Constructor,arr,function resolver(idx,msg) {
				msgs[idx] = msg;
				if (++count === len) {
					resolve(msgs);
				}
			},reject);
		});
	});

	builtInProp(Promise,"race",function Promise$race(arr) {
		var Constructor = this;

		
		if (ToString.call(arr) != "[object Array]") {
			return Constructor.reject(TypeError("Not an array"));
		}

		return new Constructor(function executor(resolve,reject){
			if (typeof resolve != "function" || typeof reject != "function") {
				throw TypeError("Not a function");
			}

			iteratePromises(Constructor,arr,function resolver(idx,msg){
				resolve(msg);
			},reject);
		});
	});

	return Promise;
});

;(function () {

  var object = typeof exports != 'undefined' ? exports : this; 
  var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';

  function InvalidCharacterError(message) {
    this.message = message;
  }
  InvalidCharacterError.prototype = new Error;
  InvalidCharacterError.prototype.name = 'InvalidCharacterError';

  
  
  object.btoa || (
  object.btoa = function (input) {
    var str = String(input);
    for (
      
      var block, charCode, idx = 0, map = chars, output = '';
      
      
      
      str.charAt(idx | 0) || (map = '=', idx % 1);
      
      output += map.charAt(63 & block >> 8 - idx % 1 * 8)
    ) {
      charCode = str.charCodeAt(idx += 3/4);
      if (charCode > 0xFF) {
        throw new InvalidCharacterError("'btoa' failed: The string to be encoded contains characters outside of the Latin1 range.");
      }
      block = block << 8 | charCode;
    }
    return output;
  });

  
  
  object.atob || (
  object.atob = function (input) {
    var str = String(input).replace(/=+$/, '');
    if (str.length % 4 == 1) {
      throw new InvalidCharacterError("'atob' failed: The string to be decoded is not correctly encoded.");
    }
    for (
      
      var bc = 0, bs, buffer, idx = 0, output = '';
      
      buffer = str.charAt(idx++);
      
      ~buffer && (bs = bc % 4 ? bs * 64 + buffer : buffer,
        
        
        bc++ % 4) ? output += String.fromCharCode(255 & bs >> (-2 * bc & 6)) : 0
    ) {
      
      buffer = chars.indexOf(buffer);
    }
    return output;
  });

}());

signer.widgets.Signer = zk.$extends(zul.Widget, {
	
	_chromeFirefoxExtension : 'IsignChromeSigning',
	_javaVersion: '1.7',
	_language: 'lt',
	_appletLocation: '',
	_appletTimer: null,
	_appletId: 0,
	_policies: null,
	_pinPromptText: '',
	_pinConfirmText: '',
	_pinCancelText: '',

	
	$define : {
		chromeFirefoxExtension : function(v) {
		},
		javaVersion : function(v) {
		},
		language : function(v) {
		},
		appletLocation : function(v) {
		},
		pinPromptText : function(v) {
		},
		pinConfirmText : function(v) {
		},
		pinCancelText : function(v) {
		},
		policies : function(v) {
		}
	},
	
	$init : function() {
		this.$super('$init', arguments);
		this._zclass = 'z-signer';
	},
	
	hasExtensionFor : function(cls) {
		return (typeof window[cls] === 'function') ? 'true' : 'false';
	},
	
	hexToBase64 : function(str) {
	  return btoa(String.fromCharCode.apply(null, str.replace(/\r|\n/g, "").replace(/([\da-fA-F]{2}) ?/g, "0x$1 ").replace(/ +$/, "").split(" ")));
	},
	
	base64ToHex : function(str) {
		  for (var i = 0, bin = atob(str.replace(/[ \r\n]+$/, "")), hex = []; i < bin.length; ++i) {
		    var tmp = bin.charCodeAt(i).toString(16);
		    if (tmp.length === 1) tmp = "0" + tmp;
		    hex[hex.length] = tmp;
		  }
		  return hex.join("");
	},
	
	cleanup : function() {
		jq(this.$n()).empty();
	},
	
	checkSigningInfrastructure : function() {
		var result = {};
		var maybeEdge = (navigator.userAgent.indexOf('Edge') != -1);
		var maybeChrome = (navigator.userAgent.indexOf('Chrome') != -1);
		var maybeOpera = (navigator.userAgent.indexOf('OPR') != -1);
		var maybeFirefoxSince52 = false;
		if (navigator.userAgent.indexOf('Firefox') > -1) {
			var matches = navigator.userAgent.match(/Firefox\/([0-9\.]+)/);
			if (matches.length > 1 && parseInt(matches[1]) >= 52) {
				maybeFirefoxSince52 = true;
			}
		}
		
		if (maybeChrome && !maybeEdge && !maybeOpera && !maybeFirefoxSince52) {
			result.chromePlugin = this.hasExtensionFor(this._chromeFirefoxExtension); 
		}
		if (maybeEdge && !maybeOpera && !maybeFirefoxSince52) {
			result.edgePlugin = this.hasExtensionFor(this._chromeFirefoxExtension);
		}
		if (maybeFirefoxSince52) {
			result.firefoxPlugin = this.hasExtensionFor(this._chromeFirefoxExtension); 
		}
		if (typeof result.javaPlugin === "undefined" && !maybeChrome && !maybeEdge && !maybeOpera && !maybeFirefoxSince52) {
			result.javaPlugin = deployJava.versionCheck(this._javaVersion + '+') ? 'true' : 'false';
		}
		this.fire('onSigningInfrastructureChecked', result);
	},
	
	chromePluginSign: function(digest, type) {
		zAu.cmd0.showBusy();
		var zeta = this;
		var policyIds = this._policies[type] || '';
		var p = new window[this._chromeFirefoxExtension]();
		var failure = function(error) { 
			var data = JSON.parse(error.message);
			zeta.fire('onSigningFailed', data);
		};
		
		var authResult = {digest: digest};
		
		var signed = function(signature) {
			var encoded = zeta.hexToBase64(signature.hex);
			authResult.signature = encoded;
			zeta.fire('onSigningSuccess', authResult);
		};
		
		var lang = {lang: this._language};
		
		var certificateSelected = function(certificate) {
			authResult.certificate = zeta.hexToBase64(certificate.hex);
			p.sign(certificate, {type: 'sha2', hex: zeta.base64ToHex(digest)}, lang).then(signed, failure);
		};
		
		var checkSuccess = function(result) {
			if (result.driversFound && result.driversFound > 0) {
				p.getCertificate({lang: zeta._language, certificatePurpose:'login', policyIds:policyIds}).then(certificateSelected, failure);
			} else {
				zeta.fire('onSigningFailed', {result:'no_drivers'});
			}
		};
		p.getVersion().then(checkSuccess, failure);
	},
	
	firefoxPluginGetCertificate: function(type) {
		zAu.cmd0.showBusy();
		var zeta = this;
		var policyIds = this._policies[type] || '';
		var p = new window[this._chromeFirefoxExtension]();
		
		var failure = function(error) { 
			var data = JSON.parse(error.message);
			zeta.fire('onSigningFailed', data);
		};
		
		var certificateSelected = function(certificate) {
			zeta.fire('onCertificateSelected', {result: zeta.hexToBase64(certificate.hex), fullCertInfo: certificate, type: type});
		};
		
		var checkSuccess = function(result) {
			if (result.driversFound && result.driversFound > 0) {
				p.getCertificate({lang: zeta._language, certificatePurpose:'login', policyIds:policyIds}).then(certificateSelected, failure);
			} else {
				zeta.fire('onSigningFailed', {result:'no_drivers'});
			}
		};
		
		p.getVersion().then(checkSuccess, failure);
	},
	
	firefoxPluginSignDigest: function(certificate, digest, algorithm, type, token) {
		var zeta = this;
		var p = new window[this._chromeFirefoxExtension]();
		var authResult = {digest: digest, certificate: zeta.hexToBase64(certificate.hex), type: type, iSignSessionToken: token}; 
		
		var failure = function(error) { 
			var data = JSON.parse(error.message);
			zeta.fire('onSigningFailed', data);
		};
		
		var signed = function(signature) {
			var encoded = zeta.hexToBase64(signature.hex);
			authResult.signature = encoded;
			zeta.fire('onSigningSuccess', authResult);
		};
		
		var lang = {lang: this._language};
		
		p.sign(certificate, {type: algorithm, hex: zeta.base64ToHex(digest)}, lang).then(signed, failure);
	},
	
	javaPluginSignPhase2: function(alias) {
		var zeta = this;

		var opts = {
			title: this._pinPromptText,
			message: this._pinPromptText,
			animate: false,
			inputType: 'password'
		};
		opts.buttons = {};
		opts.buttons.confirm = {
			label: this._pinConfirmText,
			className: 'btn-success'
		};
		opts.buttons.cancel = {
			label: this._pinCancelText,
			className: 'btn-default'
		};
		opts.callback = function(result) {
			if (result == null) {
				zeta.fire('onSigningFailed', {result:'applet_operation_was_canceled' });
				return;
			}
			
			zAu.cmd0.showBusy();
			
			var password = result;
			var complete = function(resultString) {
				var result = JSON.parse(resultString);
				if (result[0] == null) {
					zeta.fire('onSigningFailed', result[1]);
				} else {
					zeta.fire('onSigningSuccess', result[0]);
				}
				zeta.cleanup();
			};
			
			var delegate = function() {
				var applet = zeta.$n('applet' + zeta._appletId);
				var resultString = applet.authenticate(alias, password);
				complete(resultString);
			};
			
			var tries = 40;
			
			var checkLiveConnect = function() {
				var applet = zeta.$n('applet' + zeta._appletId);
				try {
					var test = applet.checkLiveConnect("ping");
					delegate();
				} catch (e) {
					tries = tries - 1;
					if (tries < 0) {
						zeta.fire('onSigningFailed', {result:'applet_failed_communications', log:'Failed to communicate with applet:' + e.toString() });
						return;
					}
					setTimeout(checkLiveConnect, 10);
				}
			};
			checkLiveConnect();
		};
		bootbox.prompt(opts);
	},
	
	javaPluginSign: function(digest, type, flag) {
		var zeta = this;
		if (flag) {
			jq(this.$n()).empty();
			
			setTimeout(function() { zeta.javaPluginSign(digest, type)}, 100);
		}

		this._appletId = this._appletId + 1;
		var parameters = {'type' : type, 'digest' : digest, 'classloader_cache' : 'false', 'separate_jvm' : 'true' };
		
		var attributes = {
				id: this.uuid + '-applet' + this._appletId,
				code : 'lt.atea.viisp.applet.AuthApplet',
				archive : this._appletLocation + '?' + new Date().getTime(),
				width : 1,
				height : 1,
				mayscript : 'mayscript'
			};

		deployJavaContainer = this.uuid;
		deployJava.runApplet(attributes, parameters, this._javaVersion);
		var appletTimeout = 60;
		
		this._appletTimer = setTimeout(function() {
			if (zeta._appletTimer) {
				zeta.fire('onSigningFailed', {result: 'applet_failed_communications'});
			}
		}, appletTimeout * 1000);
	},
	
	sign: function(infrastructure, digest, type) {
		if (infrastructure == 'javaPlugin') {
			this.javaPluginSign(digest, type);
			return;
		}
	},

	redraw : function(out) {
		var s = this.prolog;
		if (s) {
			out.push(s);
		}

		out.push('<div', this.domAttrs_(), '>');
		out.push('</div>');

		s = this.epilog;
		if (s) {
			out.push(s);
		}
	},
	
	bind_ : function() {
		this.$supers('bind_', arguments);
		var zeta = this;
		
		window.onCertificateLoadStart = function(diag) {
			if (zeta._appletTimer) {
				clearTimeout(zeta._appletTimer);
				zeta._appletTimer = null;
			}
		};
		
		window.onCertificateLoad = function(cert, diag) {
			if (cert != null) {
				var decodedCertificates = JSON.parse(cert);
				zeta.fire('onSigningCertificatesLoaded', { certificates: decodedCertificates });
			} else {
				var data = JSON.parse(diag);
				zeta.fire('onSigningFailed', data);
			}
		}
	},
	
	unbind_ : function() {
		delete window.onCertificateLoadStart;
		delete window.onCertificateLoad;
		
		this.$supers('unbind_', arguments);
	}
});
zkreg('signer.widgets.Signer');signer.widgets.LogViewer = zk.$extends(zul.wgt.A, {
	_log: '',
	_logWindowTitle: null,
	_window: null,
	
	$define : {
		log : function(v) {
		},
		logWindowTitle : function(v) {
		}
	},
	
	$init : function() {
		this.$super('$init', arguments);
		this._zclass = 'z-log-viewer';
	},
	
	doClick_: function(evt) {
		if (this._window) {
			this._window.close();
		}
		this._window = window.open();
		this._window.document.write('<html><head><title>' + zUtl.encodeXML(this._logWindowTitle) + '</title></head><body><pre>' + zUtl.encodeXML(this._log) + "</pre></body></html>" );
	}
});
zkreg('signer.widgets.LogViewer');
}finally{zk.setLoaded(zk._p.n);}});zk.setLoaded('signer.widgets',1);