SpecialTypes = {
    ExitAction:0,
    OpenDocumentAction:1,
    PrintHtmlDocumentAction:2,
    JumpAction:3,
    ShowReferenceWindowAction:4,
    StartTimer:5
};
ExitTypes = {
    Lesson:0,
    CurrentOption:1
};
SpecialClassHelper = {
    loadSpacialAction:function (cfgXML, o, actionSequence) {
        var specialType = XmlHelper.getInteger(cfgXML, 'specialType');
        switch (specialType) {
            case SpecialTypes.ExitAction:
                return new ExitSpecialActionClass(cfgXML, o, actionSequence);
                break;
            case SpecialTypes.OpenDocumentAction:
                return new OpenWebResourceSpecialAction(cfgXML, o, actionSequence);
                break;
            case SpecialTypes.PrintHtmlDocumentAction:
                return new PrintSpecialActionClass(cfgXML, o, actionSequence);
                break;
            case SpecialTypes.JumpAction:
                return new JumpToOptionSpecialAction(cfgXML, o, actionSequence);
                break;
            case SpecialTypes.ShowReferenceWindowAction:
                return new ShowReferenceWindowSpecialActionClass(cfgXML, o, actionSequence);
                break;
            case SpecialTypes.StartTimer:
                return new StartTimerSpecialActionClass(cfgXML, o, actionSequence);
                break;

        }
    }
};
Ext.define('SpecialClass15', {
    extend:'GeneralAction',
    constructor:function (cfgXML, o, actionSequence) {
        this.callParent([cfgXML, o, actionSequence]);
        this.SpecialType = XmlHelper.getInteger(cfgXML, 'specialType');
    },
    processAction:function () {
        this.IsProcessed = true;
        return 0;
    },
    toString:function () {
        return Ext.String.format("Special Action ID: {0}, type: {1}.", this.id, this.SpecialType);
    }
});
Ext.define('JumpToOptionSpecialAction', {
    extend:'SpecialClass15',
    constructor:function (cfgXML, o, actionSequence) {
        this.callParent([ cfgXML, o, actionSequence]);
        this.OptionID = XmlHelper.getInteger(cfgXML, 'toOptionID');
        this.MarkIntroductionCompleted = XmlHelper.tryGetValue(cfgXML, 'markIntroductionCompleted', TryGetValueOption.Boolean, false);
        this.MarkOptionCompleted = XmlHelper.tryGetValue(cfgXML, 'markOptionCompleted', TryGetValueOption.Boolean, false);
    },
    processAction:function () {
        this.IsProcessed = true;
        var nextOption = Author.LessonManager.AuthorLesson.getLessonNodeByID(this.OptionID);
        // Author.log(Ext.String.format('Jumbto: {0}', this.OptionID));
        // Author.log(Ext.String.format('CurrentListType: {0}', Author.CurrentStateManager.CurrentList.ListType));
        // Author.log(Ext.String.format('CurrentNodeType: {0}', Author.CurrentStateManager.CurrentLessonNode.Type));
        if (this.MarkIntroductionCompleted && Author.CurrentStateManager.CurrentList.ListType == 'INTRODUCTION') {
            Author.CurrentStateManager.CurrentLessonNode.IsIntroductionListShown = true;
        }
        if (this.MarkOptionCompleted && Author.CurrentStateManager.CurrentLessonNode.Type != 'MENU') {
            Author.CurrentStateManager.CurrentLessonNode.IsCompleted = true;
        }
        // Author.CurrentStateManager.CurrentLessonNode.IsIntroductionListShown= true;
        Author.DisplayManager.showLessonNode(nextOption);
        return {MoveOn:false, Interval:0};
    }
});
//SpecialClass - Exit
Ext.define('OpenWebResourceSpecialAction', {
    extend:'SpecialClass15',
    constructor:function (cfgXML, o, actionSequence) {
        this.callParent([ cfgXML, o, actionSequence]);
        this.ResourceType = XmlHelper.getInteger(cfgXML, 'resourceType');
        this.Url = XmlHelper.getString(cfgXML, 'resourceUrl');
    },
    processAction:function () {
        this.IsProcessed = true;
        var urlToOpen = this.ResourceType == ResourceTypes.Web ? this.Url : AuthorUtils.getAbsoluteResourcePath(Author.resourcePath) + this.Url;
        if (Author.isAuthorViewer()){
            window.location = "author:OpenURL:" + urlToOpen;
        }else{
            window.open(urlToOpen, 'win' + this.id);
        }
        return {MoveOn:true, Interval:0};
    }
});
//SpecialClass - Exit
Ext.define('ExitSpecialActionClass', {
    extend:'SpecialClass15',
    constructor:function (cfgXML, o, actionSequence) {
        this.callParent([cfgXML, o, actionSequence]);
        this.ExitType = XmlHelper.getInteger(cfgXML, 'exitType');
    },
    processAction:function () {
        this.IsProcessed = true;
        switch (this.ExitType) {
            case ExitTypes.Lesson:
                Author.LessonManager.AuthorLesson.LessonRoot.ChildNode.onExitLesson();
                break;
            case ExitTypes.CurrentOption:
                if (Author.CurrentStateManager.CurrentLessonNode.ParentNode.Type == 'MENU') {
                    Author.CurrentStateManager.CurrentLessonNode.onGoBackToParentNode();
                } else {
                    Author.CurrentStateManager.CurrentLessonNode.onExitLesson();
                }
                break;
        }
        return {MoveOn:false, Interval:0};
    }
});
//SpecialClass - ShowReferenceWindow
Ext.define('ShowReferenceWindowSpecialActionClass', {
    extend:'SpecialClass15',
    constructor:function (cfgXML, o, actionSequence) {
        this.callParent([cfgXML, o, actionSequence]);
        this.ReferenceWindowTitle = XmlHelper.tryGetValue(cfgXML, 'referenceTitle', TryGetValueOption.Normal, 'Reference');
        this.ShowExpended = XmlHelper.getBoolean(cfgXML, 'isExpended');
    },
    processAction:function () {
        if (Author.LessonManager.ReferenceWindow) {
            Author.LessonManager.ReferenceWindow.show(this.ReferenceWindowTitle, this.ShowExpended);
        }
        this.IsProcessed = true;
        return {MoveOn:true, Interval:0};
    }
});

//SpecialClass - StartTimer
Ext.define('StartTimerSpecialActionClass', {
    extend:'SpecialClass15',
    constructor:function (cfgXML, o, actionSequence) {
        this.callParent([ cfgXML, o, actionSequence]);
    },
    processAction:function () {
        this.IsProcessed = true;
        Author.LessonManager.AuthorLesson.registerInternalTimer(new InternalTimer(this));
        return {MoveOn:true, Interval:0};
    }
});

//SpecialClass - StartTimer
Ext.define('PrintSpecialActionClass', {
    extend:'SpecialClass15',
    constructor:function (cfgXML, o, actionSequence) {
        this.callParent([ cfgXML, o, actionSequence]);
        this.HtmlFileName = XmlHelper.getString(cfgXML, 'htmlFileName');
        this.HtmlData = XmlHelper.getString(cfgXML, 'data');
    },
    processAction:function () {
        this.IsProcessed = true;
       // Author.log(Ext.String.format("Print html document: {0}", this.HtmlFileName));
        var print = ExpressionEngine.replaceVariablesWithValue(this.HtmlData);
        if (Ext.isIE ) {
            printHidden(print);
            return {MoveOn:false, Interval:0};
        }
        else {
            var content = Author.DisplayManager.BackgroundObject.getContent().createChild({
                tag:"iframe",
                style:"position:absolute;overflow:auto;height:0px;width:0px;"
            });
            content.setWidth(0);
            content.setHeight(0);
            // content.setVisible(false);
            var ifrm = content.dom;
            ifrm = (ifrm.contentWindow) ? ifrm.contentWindow : (ifrm.contentDocument.document) ? ifrm.contentDocument.document : ifrm.contentDocument;
            ifrm.document.open();
            ifrm.document.write(print);
            ifrm.document.close();
            ifrm.focus();
            ifrm.print();
            return {MoveOn:true, Interval:0};
        }

    }
});