﻿!function ($) {
    var FastIsi = window.FastIsi = {
        pre: null,
        curr: null,
        init: function (start) {
            var self = this;
            this.navs = $("#fastNav .item");
            this.contents = $("#fastContent .contentItem");
            this.reference = $("#fastRef .refItem");

            if (this.navs.length != this.contents.length) return;

            this.navs.each(function (i, el) {
                el = $(el);
                el.bind("click", function (evt) {
                    evt.preventDefault();
                    self.show(i);
                });
            });

            this.contents.hide();

            this.show(start !== undefined ? start : 0);

            return this;
        },

        show: function (index) {
            if (index == this.curr) return;

            var curr = this.curr;

            if (curr !== null) {
                $(this.navs[this.curr]).removeClass("active");
                $(this.contents[this.curr]).hide();            
            }

            var pre = (index == 0) ? 0 : index - 1;
            var hres = (index == 5) ? 0 : index - 1;
            if (index == 5) {
                this.reference.hide();
            } else {
                this.reference.show();
            }


            $(this.navs[index]).addClass("active");
            $(this.contents[index]).show();
            
            this.pre = pre;
            this.curr = index;
        }
    };

} (jQuery);


// text size
!function (context, $) {
    var scale = ["100%", "110%", "120%"],
    cookieName = "tricortextsize",
    expires = 30;

    var Textsize = {
        curr: null,
        init: function (minus, plus, elements) {
            this.minus = $(minus);
            this.plus = $(plus);
            this.elements = $(elements);

            var curr = $.cookie(cookieName);
            curr = curr === null ? 0 : parseInt(curr, 10);

            this.setFontSize(curr);
            this.attach();

            return this;
        },

        attach: function () {
            var self = this;

            this.minus.bind("click", function (event) {
                event.preventDefault();
                self.setFontSize(Math.max(0, self.curr - 1));
            });

            this.plus.bind("click", function (event) {
                event.preventDefault();
                self.setFontSize(Math.min(scale.length - 1, self.curr + 1));
            });

            return this;
        },

        setFontSize: function (index) {
            if (index === this.curr) return;

            this.elements.css("fontSize", scale[index]);
            $.cookie(cookieName, index + "", { expires: 30, path: "/" });

            this.curr = index;
        }
    };

    $(document).ready(function () {
        Textsize.init(".textMinus", ".textPlus", ".mainWrap");
    });
} (window, jQuery);


var Quiz = {

    PostFailure: function () {

    },

    UpdateAnswer: function (source) {
        $('#oId').val(source.value);

    }
}

var AnswerList = [  '2e7efeea-d4db-43c5-aa52-b41e78536d37',
                    'adcbfc13-de38-4f1a-b285-bc73278ecb32',
                    '0a8918c8-2c57-49f4-a402-7e883501fc8c',
                    'e17a7528-adcb-4398-9482-38bcde748bfc',
                    '4326125d-d68b-4bc5-986b-3cb5c57959f1',
                    '80b32b94-82cc-4307-8fec-e6a3157d92c7',
                    'ec9cf0d0-862b-44b6-be00-ff26a61b8f7a',
                    'a0acb08d-6de8-4b3d-8abc-b13f99344e2b',
                    'd04d7eec-e123-4d51-bfaf-866507a71f7d',
                    '523c95a2-22f8-4b3c-bab4-2ffe0bcaf7f9'  ];

var KnowledgeCenter = {

    FormValidate: function () {

    },

    SaveAnswer: function (pqId, oId) {
        $.ajax(
            {
                type: "POST",
                url: "/ToolsAndResources/SaveUserResponses",
                data: "pqId=" + pqId + "&oId=" + oId,
                success: function (result) {
                    if (result.success) {
                        KnowledgeCenter.CheckCorrectAnswer(pqId, oId);
                        $("#answer_" + pqId).show();
                    }
                },
                error: function (req, status, error) {
                    alert("We are sorry. For some reason we are not able to record your answer.");
                }
            });
    },

    CheckCorrectAnswer: function (pqId, oId) {
        var index = $.inArray(oId, AnswerList)
        if (index >= 0) {
            $("#correct_" + pqId).show();
            $("#incorrect_" + pqId).hide();

            // Tracking
            var s = s_gi(s_account); s.linkTrackVars = 'prop24,prop25,eVar8,eVar9,events';
            s.linkTrackEvents = 'event17,event18';
            s.prop24 = pqId;
            s.prop25 = oId;
            s.eVar8 = pqId;
            s.eVar9 = oId;
            s.events = 'event17,event18'; 
            s.tl(this, 'o', 'Correct Quiz Answer');
            // .Tracking

        }
        else {
            $("#correct_" + pqId).hide();
            $("#incorrect_" + pqId).show();


            // Tracking
            var s = s_gi(s_account); s.linkTrackVars = 'prop24,prop25,eVar8,eVar9,events';
            s.linkTrackEvents = 'event17,event19';
            s.prop24 = pqId;
            s.prop25 = oId;
            s.eVar8 = pqId;
            s.eVar9 = oId;
            s.events = 'event17,event19';
            s.tl(this, 'o', 'Incorrect Quiz Answer');
            // .Tracking
        }

    }

}

    


function openSendFriend() {
    // use SSL on prod
    if (window.location.href.search("hcp/default.aspx") != -1) 
    {
        window.open('https://www.trilipixpro.com/SendToFriend?title=' + document.title + '&url=' + escape(window.location.href), null, 'scrollbars=no,resizable=yes,width=440,height=500');
    }
    else 
    {
        window.open('/SendToFriend?title=' + document.title + '&url=' + escape(window.location.href), null, 'scrollbars=no,resizable=yes,width=440,height=500');
    }
}

function MM_openBrWindow_(theURL, winName, features) {
    window.open(theURL, winName, features);
}

function openDisclaimer(url) {
    MM_openBrWindow_('/Site/Exitsite?url=' + url, 'winDisclaimer', 'width=400,height=400');
}

function callFloodlight_new(catId) {
    var tag_url = "http://fls.doubleclick.net/activityi;src=2644366;type=trili707;cat=" + catId + ";ord=" + Math.floor(Math.random() * 999999) + "?";
    if (document.getElementById("DCLK_FLDiv")) { var flDiv = document.getElementById("DCLK_FLDiv"); }
    else { var flDiv = document.body.appendChild(document.createElement("div")); flDiv.id = "DCLK_FLDiv"; flDiv.style.display = "none"; }
    var DCLK_FLIframe = document.createElement("iframe");
    DCLK_FLIframe.id = "DCLK_FLIframe_" + Math.floor(Math.random() * 999999);
    DCLK_FLIframe.src = tag_url;
    flDiv.appendChild(DCLK_FLIframe);
}
