﻿/** 
* Website selector function 
*/

function ddlWebsites_ClientSelectedIndexChanged(sender, eventArgs) {
    var selectedItem = eventArgs.get_item();
    var webSite = selectedItem.get_value();

    window.location.href = webSite;
}

/** 
* Accordion function 
*/

$(document).ready(function () {

    $("#rs-accordion").accordion({ header: "h6", autoHeight: false });

});


/** 
* Smoothscroll function 
*/

$(document).ready(function () {

    $("#topnav .col").each(function () {
        $("a.navAnchor", this).each(function (i) {
            $(this).attr("href", $(this).attr("href") + "#?n" + (i + 1));
        });
    });

    $(".rs-content").each(function () {
        $("a.navAnchor", this).each(function (i) {
            $(this).attr("href", $(this).attr("href") + "#?p" + (i + 1));
        });
    });

    $.smoothAnchors(2000, "easeInOutExpo", false);
    $.smoothAnchorsOnLoad(2000, "easeInOutExpo");

});


/** 
* Expander/Readmore function 
*/

$(document).ready(function () {

    $('.rs-readmore').expander({
        slicePoint: 0,
        expandText: _readMore,
        expandPrefix: '',
        collapseTimer: 0,
        userCollapseText: _readMoreClose,
        beforeExpand: function ($thisEl) { $thisEl.addClass('expanded'); },
        onCollapse: function ($thisEl, byUser) { $thisEl.removeClass('expanded'); }
    });

    $('.rs-termreadmore').expander({
        slicePoint: 0,
        expandText: _terminology,
        expandPrefix: '',
        collapseTimer: 0,
        userCollapseText: _readMoreClose,
        beforeExpand: function ($thisEl) { $thisEl.addClass('term-expanded'); },
        onCollapse: function ($thisEl, byUser) { $thisEl.removeClass('term-expanded'); }
    });

});


/** 
* Dialog function 
*/

$(document).ready(function () {

    var page = ""
    var w = 0;
    var h = 0;
    var external = false;

    $('.showdialog').click(
        function () {
            page = $(this).attr('href');

            if (page.indexOf("http://") != -1 || page.indexOf("https://") != -1) {
                w = pageWidth() * 0.8;
                h = pageHeight() * 0.8;
                external = true;
            }
            else {
                w = 790;
                h = pageHeight() * 0.8;
                external = false;
            }

            var dialogOpts = {
                modal: true,
                bgiframe: true,
                autoOpen: false,
                height: h,
                width: w,
                open: function () {
                    if (external)
                        $("#rs-dialog").html("<iframe src ='" + page + "' width='" + (w - 80) + "' height='" + (h - 60) + "' frameborder='0'></iframe>");
                    else
                        $("#rs-dialog").load(page + " .rs-content");
                },
                close: function () {
                    $("#rs-dialog").html("");
                }
            };
            $(document).click(function (e) { // Close on outside-click
                if (!$(e.target).parents().filter('.ui-dialog').length) {
                    $("#rs-dialog").dialog("close");
                }
            });
            $("#rs-dialog").dialog(dialogOpts);
            $("#rs-dialog").dialog("open");
            return false;
        }
    );
});

function showPressDialog(id) {
    CisionPressRelease.GetPressRelease(id, showPressDialogSuccess, showPressDialogError);
}

function showPressDialogSuccess(result) {

    var dialogOpts = {
        modal: true,
        bgiframe: true,
        autoOpen: false,
        height: pageHeight() * 0.8,
        width: 790,
        open: function () {
            $("#rs-dialog").html("<div class='rs-content'>" +
                "<img src='" + result.logo + "' />" +
                "<br /><br />" + result.title + "<br />" + result.body + "<hr />" +
                "<p><a href='" + result.furl + "'><img src='" + result.ficon + "'> " + result.fdesc + "</img></a></p></div>");
        },
        close: function () {
            $("#rs-dialog").html("");
        }
    };

    $(document).click(function (e) {
        if (!$(e.target).parents().filter('.ui-dialog').length) {
            $("#rs-dialog").dialog("close");
        }
    });

    $("#rs-dialog").dialog(dialogOpts);
    $("#rs-dialog").dialog("open");
}

function showPressDialogError(result) {
    alert("Unable to retrieve press release data");
}

function pageWidth() {
    return window.innerWidth != null ? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
}

function pageHeight() {
    return window.innerHeight != null ? window.innerHeight : document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body != null ? document.body.clientHeight : null;
}
