﻿function CUtils() {

    var _sPopupTitle = "_tait3wiz";

    // Overriden base class method.
    CUtils.prototype.toString = function() {
        return "CUtils :. Common utilis class";
    }

    // Launches the wizard window in a popup. returns true on success, false on failure.
    CUtils.prototype.LaunchWizard = function(sPageName, iWidth, iHeight) {

        var x = (screen.availWidth - iWidth) / 2;
        var y = (screen.availHeight - iHeight) / 2;

        try {
            window.open(sPageName, _sPopupTitle, "width=" + iWidth + ",height=" + iHeight + ",left=" + x +",top=" + y + ",resizable=1, scrollbars=1");
        } catch (e) {
            alert ("Popup blocked!");
        }
    }

    // Closes the wizard window. Placa additional shutdown tasks over here.
    CUtils.prototype.CloseWizard = function() {
        self.close();
    }

    // Sets the window title...
    CUtils.prototype.SetWndTitle = function(sWndTitle) { _sPopupTitle = sWndTitle; };

    // Streams a PDF object and embed tag to the document.
    CUtils.prototype.GenAcrobat = function (iWidth, iHeight, sSrc, sId) {
        
        var sBuffer = '<object classid="clsid:CA8A9780-280D-11CF-A24D-444553540000" width="' + iWidth + '" height="' + iHeight + '" id="' + sId + '">';
        sBuffer += '<param name="src" value="' + sSrc + '"/>"'
        sBuffer += '<embed width="' + iWidth + '" height="' + iHeight + '" id="' + sId + '" src="' + sSrc +'"></embed>';
        sBuffer += '</object>'
        document.write (sBuffer);
    }

    // Creates the tags that are necessary to render the Zeus Enlite 2.0 ActiveX/Firefox plugin.
    CUtils.prototype.GenTAIT3Obj = function (iWidth, iHeight, sAxSrc, sEmbedSrc, sId) {

        var sActiveX = "clsid:B3E32D88-8E7F-468f-B0E2-3A300FD4A82C";
        var sEmbed = "application/x-Enlite20NP";

        var sBuffer = '<object classid="' + sActiveX + '" width="' + iWidth + '" height="' + iHeight + '" id="' + sId + '" codebase="' + sAxSrc + '">';
        //sBuffer += '<param name="src" value="' + sSrc + '"/>"'
        //sBuffer += '<embed width="' + iWidth + '" height="' + iHeight + '" id="' + sId + '" src="' + sEmbedSrc +'" type="'+ sEmbed +'"></embed>';
        sBuffer += '</object>'
        document.write (sBuffer);
    }

    // Returns true if the object associated with the particular step is installed.
    CUtils.prototype.IsObjectInstalled = function(iWizardStep) {
        // BrowserSniffer.js needs to be included before this file...
        if (g_bdetect.is_firefox) {
            return this._DoNetscapeDetect(iWizardStep);
        } else {
           return this._DoIEDetect(iWizardStep); 
        }
    }

    CUtils.prototype.RenderTAIT3ObjURL = function() {
        // BrowserSniffer.js needs to be included before this file...
        if (g_bdetect.is_firefox) {
            document.write ('<a href="s/MyITLab_Firefox.exe">this</a>');
        } else {
            document.write ('<a href="s/Setup.exe">this</a>');
        }
    }

    // Returns a text string that is diaplayed when the user clicks on the next button and object detecttion fails
    CUtils.prototype.ShowObjectError = function (iWizardStep) {
    
        var sMessage = "Click OK to close this window, and follow the on-screen instructions to proceed with the installation. If you wish to exit the Installation Wizard, click OK in this window, and then click Cancel in the Installation Wizard on the bottom left of the screen.";
        switch (iWizardStep) {
            case 1: alert ("The Adobe Flash Player has not been fully installed. " + sMessage);break;
            case 2: alert ("The Adobe Reader has not been fully installed. " + sMessage);break;
            case 3: alert ("The myitlab Player has not been fully installed. " + sMessage);break
        }
    }

    // Internal methods... Not meant for public access... use at your own risk!

    // Returns true if an object with the id 'sId' has been 
    CUtils.prototype._IsObject = function(sId) {
        alert (document.getElementById(sId).readyState);
       return  (null != document.getElementById(sId)) ? true : false;
    }


    CUtils.prototype._DoIEDetect = function(iWizardStep) {
        
        var sClsName;
        var sVersion;

        switch (iWizardStep) {
            case 1: {
                // Creating an ActiveXObject of flash doesn't seem to work on some machines.
                var oFlash = document.oFlash;
                if (!oFlash) return false;

                sVersion  = oFlash.GetVariable('$version').substring(4);
                sVersion  = sVersion.split(',');
                sVersion  = parseFloat(sVersion[0] + '.' + sVersion[1]);
                return (sVersion >= 9) ? true : false;
            }

            case 2: sClsName = "AcroPDF.PDF"; break;
            case 3: sClsName = "Zeus.Enlite20Ctrl.1"; break;
            default: return true;
        }

        try {
            // An Exception will be thrown if sClsName cannot be loaded. With flash it'll be thrown anyway!
            var ocx = new ActiveXObject(sClsName);
            if (null == ocx) return false;

            // Extract the version of the PDF engine installed.
            if (2 == iWizardStep) {

                sVersion = ocx.GetVersions().split(',');
                sVersion = sVersion[0].split('=');
                sVersion = parseFloat(sVersion[1]);
                return (sVersion >= 7) ? true : false;

            }   
            
            // This is necessary as the user can choose to cancel the stub install.
            // If the user has cancelled, the following code should throw an error.
            /*if (3 == iWizardStep) {
                try {
                    document.oStub.SetSubfolder("test");
                } catch (e) {
                    return false;
                }
                
            }*/

            return true;

        } catch (e) {
            return false;            
        }

        return true;
    }


    // Firefox/Netscape plugin detection...
    CUtils.prototype._DoNetscapeDetect = function(iWizardStep) {

        var sPluginName = "Shockwave Flash";
        var sPluginDesc = "9";

        switch (iWizardStep) {
            case 1: sPluginName = "Shockwave Flash"; sPluginDesc = "9"; break;                                          /* Adobe Flash Detection */
            case 2: sPluginName = "Adobe Acrobat"; sPluginDesc = "7"; break;                                            /* Adobe Flash Detection */
            case 3: sPluginName = "Enlite 2.0 Mozilla Gecko Plugin"; sPluginDesc = "Enlite 2 Netscape Plugin"; break;   /* Enlite Plugin Detection */
            default: return true;
        }

        if (null != navigator.plugins) {
            var iLen = navigator.plugins.length;
            
            for (var iPlugin = 0; iPlugin < iLen; ++iPlugin) {
                if (sPluginName == navigator.plugins[iPlugin].name && navigator.plugins[iPlugin].description.indexOf(sPluginDesc) >0) {
                    return true;
                } 
            }
        }
        
        // Plugin not detected...
        return false;
    }
};

function CPopHelp() {

    var _m_iDefHeight = 400;
    var _m_iDefWidth = 620;

    var _m_sPopupTitle = "Help";
    var _m_hwnd;
    
    var eSYSREQ = 1;
    var eADMIN = 0;
    
    // Overriden base class method.
    CPopHelp.prototype.toString = function() {
        return "CPopHelp object";
    }

    CPopHelp.prototype.Open = function (iWidth, iHeight, iID) {

        if (0 == iWidth) iWidth = _m_iDefWidth;
        if (0 == iHeight) iHeight = _m_iDefHeight;

        var x = (screen.availWidth - iWidth) / 2;
        var y = (screen.availHeight - iHeight) / 2;

        var sPage = "help.asp?nHelpId=" + iID;

        // Close any existing help window.
        try {
            if (_m_hwnd) _m_hwnd.close();
        } catch (e) {}

        // Launch the help window and store the handle.
        try {
            _m_hwnd = window.open(sPage, _m_sPopupTitle, "width=" + iWidth + ",height=" + iHeight + ",left=" + x +",top=" + y + ",resizable=0, scrollbars=0");
        } catch (e) {
            alert ("Popup blocked!");
        }
    }
};