﻿!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);

var Quiz = {

    PostFailure: function () {

    },

    FormValidate: function () {
        var formElements = $('input[id^="quiz_"]');
        var hiddenElementValue = "";

        $("#quizError").hide();

        for (var i = 0; i < formElements.length; i++) {
            if (formElements[i].type == "radio" && formElements[i].checked) {
                hiddenElementValue = formElements[i].value
            }
            if (formElements[i].type == "checkbox" && formElements[i].checked) {
                if (hiddenElementValue == "")
                    hiddenElementValue = formElements[i].value;
                else
                    hiddenElementValue += ";" + formElements[i].value;
            }
            if (formElements[i].type == "text") {
                hiddenElementValue = formElements[i].value;
            }
        }

        if (hiddenElementValue == "")
            $("#quizError").show();

        return hiddenElementValue != "";
    }
}



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)
                        $("#kcAnswer_" + pqId).show();
                },
                error: function (req, status, error) {
                    alert("We are sorry. For some reason we are not able to record your answer.");
                }
            });
    }
}

    


function openSendFriend() {
    // use SSL on prod
    if (window.location.href.search("trilipixpro.com") != -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);
}
