//set-up namespace if necessary
var springSpace = springSpace || {};
springSpace.sui = springSpace.sui || {};
springSpace.la = springSpace.la  || {};
springSpace.la.css_loaded = springSpace.la.css_loaded || 0;

(function() {
    try {
        var widgetId = '16719';
        var widgetProp = 'widget_' + widgetId;
        var loadProp = 'load_' + widgetId;

        //TOPIC Content items
        springSpace.la.showAllTopics = function(contentid) {
            springSpace.jq('#' + contentid + ' .hidden').removeClass('hidden').attr('aria-hidden', false);
            springSpace.jq('#' + contentid + ' .s-la-topic-toggle').remove();
            return false;
        }

        if (typeof springSpace.la[widgetProp] === 'undefined') {

            springSpace.la[widgetProp] = function() {

                this.id = widgetId;
                this.version = '1.0';
                this.iid = 420;
                this.divselector = '#s-la-widget-' + this.id;
                this.$container = springSpace.jq(this.divselector);
                this.apiDomain = 'askalibrarian.library.txstate.edu';
                this.css_url = 'https://askalibrarian.library.txstate.edu/css2.57.2/dist/LibAnswers_widget.min.css';
                this.usecss = true;
                this.customcss = '';
                this.link_target = '_blank';

                this.modalid = '#s-la-widget-modal-' + this.id;
                this.widgethtml = '\u003Csection\u0020id\u003D\u0022s\u002Dla\u002Dwidget\u002Dbody\u002D16719\u0022\u003E\u003Cdiv\u0020class\u003D\u0022s\u002Dla\u002Dwidget\u002Dheader\u0022\u003E\u003Ch1\u003EEmail\u0020Isabelle\u003C\/h1\u003E\u003C\/div\u003E\u003Cdiv\u0020id\u003D\u0022s\u002Dla\u002Daskform\u002D16719\u0022\u0020class\u003D\u0022s\u002Dla\u002Daskform\u0020s\u002Dla\u002Daskform\u002Dqu\u002D6146\u0022\u003E\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u003Cform\u0020name\u003D\u0022s\u002Dla\u002Daskform\u002Dform_16719\u0022\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020id\u003D\u0022s\u002Dla\u002Daskform\u002Dform_16719\u0022\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020class\u003D\u0022\u0022\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020method\u003D\u0022POST\u0022\u0020enctype\u003D\u0022multipart\/form\u002Ddata\u0022\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020aria\u002Dlabel\u003D\u0022Form\u0020to\u0020ask\u0020a\u0020question\u0022\u0020novalidate\u003E\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u003Cinput\u0020type\u003D\u0022hidden\u0022\u0020name\u003D\u0022instid\u0022\u0020value\u003D\u0022420\u0022\u003E\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u003Cinput\u0020type\u003D\u0022hidden\u0022\u0020name\u003D\u0022quid\u0022\u0020value\u003D\u00226146\u0022\u003E\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u003Cinput\u0020type\u003D\u0022hidden\u0022\u0020name\u003D\u0022qlog\u0022\u0020value\u003D\u00220\u0022\u003E\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u003Cinput\u0020type\u003D\u0022hidden\u0022\u0020name\u003D\u0022source\u0022\u0020value\u003D\u00224\u0022\u003E\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u003Cinput\u0020type\u003D\u0022hidden\u0022\u0020name\u003D\u0022alt_auth_id\u0022\u0020value\u003D\u00220\u0022\u0020\/\u003E\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u003Cdiv\u0020class\u003D\u0022form\u002Dgroup\u0020pquestion_wrap\u0022\u003E\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u003Clabel\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020for\u003D\u0022pquestion_16719\u0022\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020class\u003D\u0022control\u002Dlabel\u0020\u0022\u003E\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020Question\u003Cspan\u0020class\u003D\u0022reqnote\u0022\u003E\u0020\u002A\u003C\/span\u003E\n\u0020\u0020\u0020\u0020\u003C\/label\u003E\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\n\u0020\u0020\u0020\u0020\u003Cinput\u0020class\u003D\u0022form\u002Dcontrol\u0022\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020type\u003D\u0022text\u0022\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020id\u003D\u0022pquestion_16719\u0022\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020name\u003D\u0022pquestion\u0022\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020value\u003D\u0022\u0022\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020autocomplete\u003D\u0022\u0022\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020required\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\/\u003E\n\n\u0020\u0020\u0020\u0020\u003C\/div\u003E\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u003Cdiv\u0020class\u003D\u0022form\u002Dgroup\u0020pdetails_wrap\u0022\u003E\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u003Clabel\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020for\u003D\u0022pdetails_16719\u0022\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020class\u003D\u0022control\u002Dlabel\u0020\u0022\u003E\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020More\u0020Detail\/Explanation\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u003C\/label\u003E\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\n\u0020\u0020\u0020\u0020\u003Ctextarea\u0020class\u003D\u0022form\u002Dcontrol\u0022\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020id\u003D\u0022pdetails_16719\u0022\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020name\u003D\u0022pdetails\u0022\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u003E\u003C\/textarea\u003E\n\n\u0020\u0020\u0020\u0020\u003C\/div\u003E\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u003Cdiv\u0020class\u003D\u0022form\u002Dgroup\u0020pemail_wrap\u0022\u003E\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u003Clabel\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020for\u003D\u0022pemail_16719\u0022\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020class\u003D\u0022control\u002Dlabel\u0020\u0022\u003E\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020Email\u003Cspan\u0020class\u003D\u0022reqnote\u0022\u003E\u0020\u002A\u003C\/span\u003E\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u003C\/label\u003E\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\n\u0020\u0020\u0020\u0020\u003Cinput\u0020class\u003D\u0022form\u002Dcontrol\u0022\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020type\u003D\u0022email\u0022\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020id\u003D\u0022pemail_16719\u0022\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020name\u003D\u0022pemail\u0022\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020value\u003D\u0022\u0022\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020maxlength\u003D\u0022100\u0022\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020autocomplete\u003D\u0022email\u0022\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020required\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\/\u003E\n\n\u0020\u0020\u0020\u0020\u003C\/div\u003E\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u003Cdiv\u0020class\u003D\u0022form\u002Dgroup\u0020pname_wrap\u0022\u003E\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u003Clabel\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020for\u003D\u0022pname_16719\u0022\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020class\u003D\u0022control\u002Dlabel\u0020\u0022\u003E\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020Name\n\u0020\u0020\u0020\u0020\u003C\/label\u003E\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\n\u0020\u0020\u0020\u0020\u003Cinput\u0020class\u003D\u0022form\u002Dcontrol\u0022\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020type\u003D\u0022text\u0022\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020id\u003D\u0022pname_16719\u0022\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020name\u003D\u0022pname\u0022\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020value\u003D\u0022\u0022\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020maxlength\u003D\u0022100\u0022\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020autocomplete\u003D\u0022name\u0022\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\/\u003E\n\n\u0020\u0020\u0020\u0020\u003C\/div\u003E\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u003Cdiv\u0020id\u003D\u0022s\u002Dla\u002Daskform\u002Dreqnote_16719\u0022\u0020class\u003D\u0022s\u002Dla\u002Daskform\u002Dreqnote\u0022\u003E\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020Fields\u0020marked\u0020with\u0020\u003Cspan\u0020class\u003D\u0022reqnote\u0022\u003E\u0020\u002A\u003C\/span\u003E\u0020are\u0020required.\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u003C\/div\u003E\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u003Cdiv\u0020class\u003D\u0022formlibcpt\u0020hidden\u0022\u003E\u003C\/div\u003E\n\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u003Cdiv\u0020id\u003D\u0022s\u002Dla\u002Daskform\u002Dbuttons\u0022\u0020class\u003D\u0022form\u002Dgroup\u0020\u0022\u003E\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u003Cbutton\u0020id\u003D\u0022s\u002Dla\u002Daskform\u002Dsubmit\u002D16719\u0022\u0020class\u003D\u0022btn\u0020btn\u002Dprimary\u0020s\u002Dla\u002Daskform\u002Dbutton\u0022\u0020type\u003D\u0022submit\u0022\u0020\u003E\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020Send\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u003C\/button\u003E\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u003C\/div\u003E\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u003C\/form\u003E\n\u003C\/div\u003E\n\n\u003C\/section\u003E ';
                this.activator = '\u003Cbutton\u0020id\u003Ds\u002Dla\u002Dwidget\u002Dactivator\u002D16719\u0020class\u003D\u0022btn\u0020btn\u002Ddefault\u0020s\u002Dla\u002Dwidget\u002Dactivator\u0022\u0020type\u003Dbutton\u003EAsk\u0020Us\u003C\/button\u003E ';
                this.search = {};
                this.question = {};
                this.isPopup = false;
                this.isSideTab = false;
                this.isSearch = false;
                this.isForm = true;
                this.isFAQList = false;
                this.groupLimiter = 0;

                // load stylesheet if desired
                if (this.usecss && springSpace.la.css_loaded == 0) {
                    if (document.createStyleSheet) {
                        try {
                            document.createStyleSheet(this.css_url);
                        } catch (e) { }
                    } else {
                        var css_link = springSpace.jq('<link>', {
                            rel: 'stylesheet',
                            type: 'text/css',
                            href: this.css_url
                        });
                        css_link.appendTo('head');
                    }
                    springSpace.la.css_loaded = 1;
                }
                //write in custom css
                if (this.customcss !== '') {
                    springSpace.jq('<style>' + this.customcss + '</style>').appendTo('head');
                }

                var that = this; //for inside event handlers

                this.prepSearchForm = function() {
                    this.search = springSpace.la.initFaqSearchForm({contentId: this.id, iid: this.iid, apiDomain: this.apiDomain, groupId: this.groupLimiter });
                    if (this.search.form) {
                        this.search.form.setAttribute('target', this.link_target);
                    }
                };

                // Instantiate question form
                this.prepQuestionForm = function() {
                    var askform_ = new springSpace.la.askform({"content_id":16719,"queue_id":6146,"form_action":"https:\/\/askalibrarian.library.txstate.edu\/1.0\/form\/submit","errormsg":{"emailaddress":"Invalid email address.","reqfields":"Please answer all required questions.","general":"Error: Please try again.","tech":"Error: Unknown browser\/network error. Please reload the page and try again. If you are still experiencing this error, please check your network connection and\/or try a different browser."},"translations":{"max_file_size":"Maximum file size"},"autoReplySettings":{"type":0,"start":null,"end":null,"offhours":null}}, springSpace.jq);
                };

                /** adjust faq list working */
                this.prepFAQList = function() {
                    springSpace.jq('.s-la-content-faqlist a').attr('target', this.link_target);
                };

                //write out content
                                    //!embed the html and attach event handlers
                    if (this.$container.length === 0) {
                        return;
                    }
                    this.$container.addClass('s-la-widget s-la-widget-embed').html(this.widgethtml);
                    if (this.isSearch) {
                        this.prepSearchForm();
                    } else if (this.isForm) {
                        this.prepQuestionForm();
                    } else if (this.isFAQList) {
                        this.prepFAQList();
                    }
                
            } //end springSpace.la.widget

        } // end checking for widget object

        // Define the loader if we haven't already (in another widget)
        if (typeof springSpace.la.widget_loader_2_57_2 === 'undefined') {
            springSpace.la.widget_loader_2_57_2 = function(widget_id) {
                this.widget_id = widget_id;
                var that = this;

                // check jquery version up to (not including) second decimal
                // is the current version >= minimum version
                this.minVersion = function(minv, curr) {
                    var curr = curr || window.jQuery.fn.jquery;
                    var c = curr.split('.');
                    var m = minv.split('.');

                    if (parseInt(c[0], 10) > parseInt(m[0], 10)) {
                        return true;
                    } else if (parseInt(c[0], 10) < parseInt(m[0], 10)) {
                        return false;
                    }
                    if (typeof c[1] == 'undefined') { c[1] = 0; }
                    if (typeof m[1] == 'undefined') { m[1] = 0; }
                    if (parseInt(c[1], 10) > parseInt(m[1], 10)) {
                        return true;
                    } else if (parseInt(c[1], 10) < parseInt(m[1], 10)) {
                        return false;
                    } else {
                        return true;
                    }
                }

                // load jquery into the page if necessary
                this.loadJquery = function(){
                    var script_tag = document.createElement('script');
                    script_tag.setAttribute('src', 'https://askalibrarian.library.txstate.edu/js2.57.2/dist/jquery.min.js');
                    script_tag.onload = that.scriptLoadHandler;
                    (document.getElementsByTagName("head")[0] || document.documentElement).appendChild(script_tag);
                }

                //Called once jQuery has loaded
                this.scriptLoadHandler = function() {
                    // Restore $ and window.jQuery to their previous values and store the new jQuery in our local jQuery variable
                    if (window.jQuery) {
                        springSpace.jq = window.jQuery.noConflict(true);
                    }
                    //load bootstrap js
                    that.bootstrapLoadHandler();
                }

                //Bootstrap JS if we need it
                this.bootstrapLoadHandler = function() {
                    var script_tag = document.createElement('script');
                    script_tag.setAttribute('src', 'https://askalibrarian.library.txstate.edu/js2.57.2/dist/LibAnswers_widget.min.js');
                    script_tag.onload = that.loadWidget;
                    (document.getElementsByTagName("head")[0] || document.documentElement).appendChild(script_tag);
                }

                //called once we have jquery + bootstrap loaded
                this.loadWidget = function () {
                    springSpace.jq(document).ready(function(){
                        springSpace.la['widget_' + that.widget_id + '_inst'] = new springSpace.la['widget_' + that.widget_id]();
                    });
                }

                if (typeof springSpace.jq === "undefined") {
                    if (window.jQuery === undefined) {
                        this.loadJquery();
                        return;
                    }
                    if (this.minVersion('1.10', window.jQuery.fn.jquery)) {
                        springSpace.jq = window.jQuery;
                        if (typeof springSpace.sui.initAutocomplete === 'undefined'
                            || typeof springSpace.la.askform === 'undefined'
                            || typeof springSpace.la.initFaqSearchForm === 'undefined') {
                            this.bootstrapLoadHandler();
                        } else {
                            this.loadWidget();
                        }
                        return;
                    }
                    this.loadJquery();
                } else if (typeof springSpace.sui.initAutocomplete === 'undefined'
                    || typeof springSpace.la.askform === 'undefined'
                    || typeof springSpace.la.initFaqSearchForm === 'undefined') {
                    this.bootstrapLoadHandler();
                } else {
                    this.loadWidget();
                }
            }
        }

        // Instantiate.
        springSpace.la[loadProp] = new springSpace.la.widget_loader_2_57_2(widgetId);
    } catch (e) {
        console.log(e.message);
    }
})();
