﻿function getDemoTheme() {
    var theme = document.body ? $.data(document.body, 'theme') : null
    if (theme == null) {
        theme = '';
    }
    else {
        return theme;
    }
    var themestart = window.location.toString().indexOf('?');
    if (themestart == -1) {
        return '';
    }

    var theme = window.location.toString().substring(1 + themestart);
    if (theme.indexOf('(') >= 0)
    {
        theme = theme.substring(1);
    }
    if (theme.indexOf(')') >= 0) {
        theme = theme.substring(0, theme.indexOf(')'));
    }

    var url = "../../jqwidgets/styles/jqx." + theme + '.css';
    if (window.location.href.toString().indexOf("angularjs") >= 0) {
        var loc = window.location.href.toString();
        if (loc.indexOf('button') >= 0 ||
        (loc.indexOf('treegrid') == -1 && loc.indexOf('grid') >= 0) ||
        loc.indexOf('dropdownlist') >= 0 ||
        loc.indexOf('combobox') >= 0 ||
        loc.indexOf('datatable') >= 0 ||
        loc.indexOf('listbox') >= 0 ||
        loc.indexOf('tabs') >= 0 ||
        (loc.indexOf('listmenu') == -1 && loc.indexOf('menu') >= 0) ||
        loc.indexOf('calendar') >= 0 ||
        loc.indexOf('datetimeinput') >= 0 ||
        (loc.indexOf('chart') >= 0 && loc.indexOf('bulletchart') == -1)) {
            url = "../../../jqwidgets/styles/jqx." + theme + '.css';
        }
    }
    if(window.location.href.toString().indexOf("typescript") >= 0)
    {
        url = "../../../jqwidgets/styles/jqx." + theme + '.css';
    }

    if (document.createStyleSheet != undefined) {
        var hasStyle = false;
        $.each(document.styleSheets, function (index, value) {
            if (value.href != undefined && value.href.indexOf(theme) != -1) {
                hasStyle = true;
                return false;
            }
        });
        if (!hasStyle) {
            document.createStyleSheet(url);
        }
    }
    else {
        var hasStyle = false;
        if (document.styleSheets) {
            $.each(document.styleSheets, function (index, value) {
                if (value.href != undefined && value.href.indexOf(theme) != -1) {
                    hasStyle = true;
                    return false;
                }
            });
        }
        if (!hasStyle) {
            var link = $('<link rel="stylesheet" href="' + url + '" media="screen" />');
            link[0].onload = function () {
                if ($.jqx && $.jqx.ready) {
                    $.jqx.ready();
                };
            }
            $(document).find('head').append(link);
        }
    }
    $.jqx = $.jqx || {};
    $.jqx.theme = theme;
    return theme;
};
var theme = '';
try
{
    if (jQuery) {
        $(document).ready(function () {
            $(".example-description").css('margin-bottom', 15);
        });
        theme = getDemoTheme();
        if (window.location.toString().indexOf('file://') >= 0) {
            var loc = window.location.toString();
            var addMessage = false;
            if (loc.indexOf('grid') >= 0 || loc.indexOf('chart') >= 0 || loc.indexOf('tree') >= 0 || loc.indexOf('list') >= 0 || loc.indexOf('combobox') >= 0 || loc.indexOf('php') >= 0 || loc.indexOf('adapter') >= 0 || loc.indexOf('datatable') >= 0 || loc.indexOf('ajax') >= 0) {
                addMessage = true;
            }

            if (addMessage) {
                $(document).ready(function () {
                    setTimeout(function () {
                        $(document.body).prepend($('<div style="font-size: 12px; font-family: Verdana;">Note: To run a sample that includes data binding, you must open it via "http://..." protocol since Ajax makes http requests.</div><br/>'));
                    }
                    , 50);
                });
            }
        }
    }
    else {
        $(document).ready(function () {
            theme = getDemoTheme();
        });
    }
}
catch (error) {
    var er = error;
}