﻿function LicenseModule(productId_, top_, left_, parentControl_)
{
    try
    {
        var _productId = productId_;
        var _top = top_;
        var _left = left_;
        var _parentControl = parentControl_;
        
        var TOP_CONTENT_TEXT = "Which Version Would You Like To Download";
        
        var _widget = this;
        var _licenseModuleContainer = null;
        
        // Public methods
        this.hide_popup_ex = function()
        {
            _licenseModuleContainer.style.display = "none";
        }
        
        this.show_popup_ex = function()
        {
            _licenseModuleContainer.style.display = "block";
        }
        
        var GetDataModelForWidget = function()
        {
            var dataModel = {};
            
            switch(_productId)
            {
                case 881:
                    dataModel.MainText = "The free 30-day trial of CatTools includes support for unlimited devices, versus just 20 devices. Plus, this trial reverts to the free version after 30 days. The choice is yours:";
                    dataModel.FreeDownloadLnk = "http://www.solarwinds.com/register/kiwi_registration.aspx?Program=879&c=70150000000EIWZ";
                    dataModel.EvalDownloadLnk = "http://www.solarwinds.com/register/kiwi_registration.aspx?Program=881&c=70150000000Es8Y";
                break;
                
                case 876:
                    dataModel.MainText = "The free 30-day trial of Kiwi Syslog Server includes some advanced features that aren’t included in the free version. Plus, this trial reverts to the free version after 30 days. The choice is yours:";
                    dataModel.FreeDownloadLnk = "http://www.solarwinds.com/register/kiwi_registration.aspx?Program=874&c=70150000000EIV7";
                    dataModel.EvalDownloadLnk = "http://www.solarwinds.com/register/kiwi_registration.aspx?Program=876&c=70150000000Es8J";
                break;
            }
            
            return dataModel;
        }
        
        // Private methods
        var BuildUI = function(dataModel)
        {
            // Create parent div
            _licenseModuleContainer = document.createElement('div');
            _licenseModuleContainer.style.display = "none";
            _licenseModuleContainer.style.left = _left + "px";
            _licenseModuleContainer.style.top = _top + "px";
            _licenseModuleContainer.style.position = "absolute";
            
            _licenseModuleContainer.setAttribute("class","licenseModuleContainer");
            _licenseModuleContainer.setAttribute("className","licenseModuleContainer");
            _licenseModuleContainer.className = "licenseModuleContainer";
            
            // Create background div
            var backgroundDiv = document.createElement("div");
            
            // Setting CSS for background div
            backgroundDiv.setAttribute("class","licenseModuleBackground");
            backgroundDiv.setAttribute("className","licenseModuleBackground");
            backgroundDiv.className = "licenseModuleBackground";
            
            
            // Append background to parent div
            _licenseModuleContainer.appendChild(backgroundDiv);
            
            // Creating main content
            var mainContent = document.createElement("div");
            
            mainContent.setAttribute("class","licenseModuleMainContent");
            mainContent.setAttribute("className","licenseModuleMainContent");
            mainContent.className = "licenseModuleMainContent";
            
            // Top content (Orange button click handler
            var topButtonContent = document.createElement("div");
            topButtonContent.setAttribute("class","licenseModuleTopButtonContent");
            topButtonContent.setAttribute("className","licenseModuleTopButtonContent");
            topButtonContent.className = "licenseModuleTopButtonContent";
            
            attachEvent("onclick" , _widget.hide_popup_ex, topButtonContent);
            
            mainContent.appendChild(topButtonContent);
            
          
            // Creating top content for widget  
            var topContent = document.createElement("div");
            
            topContent.setAttribute("class","licenseModuleTopContent");
            topContent.setAttribute("className","licenseModuleTopContent");
            topContent.className = "licenseModuleTopContent";
            
            
            var topContentText = document.createElement("span");
            topContentText.setAttribute("class","licenseModuleTopText");
            topContentText.setAttribute("className","licenseModuleTopText");
            topContentText.className = "licenseModuleTopText";
            topContentText.innerHTML = TOP_CONTENT_TEXT;
            
            
            var closelink = document.createElement("a");
            closelink.setAttribute("class","licenseModuleCloseLnk");
            closelink.setAttribute("className","licenseModuleCloseLnk");
            closelink.className = "licenseModuleCloseLnk";
            
            attachEvent("onclick" , _widget.hide_popup_ex, closelink);
            
            var clearSpacerDiv = document.createElement("div");
            clearSpacerDiv.setAttribute("className", "clearSpacer");
            clearSpacerDiv.setAttribute("class", "clearSpacer");
            clearSpacerDiv.className = "clearSpacer";
            
            topContent.appendChild(topContentText);
            topContent.appendChild(closelink);
            topContent.appendChild(clearSpacerDiv);
            
            // Creating middle content for widget
            var middleContent = document.createElement("div");
            middleContent.setAttribute("class","licenseModuleMiddleContent");
            middleContent.setAttribute("className","licenseModuleMiddleContent");
            middleContent.className = "licenseModuleMiddleContent";
            
            var middleContentText = document.createElement("p");
            middleContentText.setAttribute("class","licenseModuleMiddleContentText");
            middleContentText.setAttribute("className","licenseModuleMiddleContentText");
            middleContentText.className = "licenseModuleMiddleContentText";
            
            middleContentText.innerHTML = dataModel.MainText;
            
            middleContent.appendChild(middleContentText);
            
            // Creating Bottom content for widget
            var bottomContent = document.createElement("div");
            bottomContent.setAttribute("class","licenseModuleBottomContent");
            bottomContent.setAttribute("className","licenseModuleBottomContent");
            bottomContent.className = "licenseModuleBottomContent";
            
            var centerControl = document.createElement("center");
            var evalButton = document.createElement("a");
            evalButton.setAttribute("name","&lid=download_30-day-trial");
            evalButton.setAttribute("href", dataModel.EvalDownloadLnk);
            evalButton.setAttribute("class","licenseModuleEvalButton");
            evalButton.setAttribute("className","licenseModuleEvalButton");
            evalButton.className = "licenseModuleEvalButton";
                        
            var separator = document.createElement("span");
            separator.setAttribute("class","licenseModuleBottomSeparator");
            separator.setAttribute("className","licenseModuleBottomSeparator");
            separator.className = "licenseModuleBottomSeparator";
            separator.innerHTML = "- OR -";

            var freeButton = document.createElement("a");
            freeButton.setAttribute("href", dataModel.FreeDownloadLnk);
            freeButton.setAttribute("name","&lid=download_Free-Version");
            
            freeButton.setAttribute("class","licenseModuleFreeButton");
            freeButton.setAttribute("className","licenseModuleFreeButton");
            freeButton.className = "licenseModuleFreeButton";
            freeButton.innerHTML = "Download Free Version";
            
            centerControl.appendChild(evalButton);
            centerControl.appendChild(separator);
            centerControl.appendChild(freeButton);
            
            bottomContent.appendChild(centerControl);
            
            // Append all the subcontents
            mainContent.appendChild(topContent);
            mainContent.appendChild(middleContent);
            mainContent.appendChild(bottomContent);
            
           _licenseModuleContainer.appendChild(mainContent);
           
            var wrapperBox = document.createElement("div");
            wrapperBox.style.position = "relative";
            
            wrapperBox.appendChild(_licenseModuleContainer);
           
           document.getElementById(_parentControl).appendChild(wrapperBox);
        }
        
        // Helper for event attaching
        var attachEvent = function(evname, handler, object)
        {
            if(window.addEventListener){
                object.addEventListener(evname.substr(2), handler, false);
            }else{
                object.attachEvent(evname, handler);
            }
        }
        
        var InitializeWidget = function()
        {
            var dataModel = GetDataModelForWidget();
            BuildUI(dataModel);
        }
        
        InitializeWidget();
   }
   catch(ex)
   {

   }
}
