﻿/// <reference path="../../Editor/jquery.markitup.js" />
/// <reference path="../../jquery-ui-1.7.2.custom.min.js" />
/// <reference path="../../jquery-1.4.1.min.js" />

var siteConfiguration = { defaultWebServiceUrl: '/Services/Default.asmx/' };
//not needed as this time
//var userRoles = { isAdministrator = false, isSuperAdministrator: false, isPowerUser: false, isUser: false };

$(function () {
    loadUIControls();
    applyRoles();
});

function loadUIControls() {

    loadDatePicker();
    loadTextEditor();
    loadDeleteAction();
}

function loadTextEditor() {
    $('.text-editor textarea').markItUp(xBBCodeSettings);
}

function loadDatePicker() {
    $('.date-picker input').datepicker({ changeMonth: true, changeYear: true, yearRange: '1930:2010' });
}

function loadDeleteAction() {
    $('.delete-action').mousedown(function () {
        var button = $(this);

        var onClick = $(button).attr('onclick');
        $(button).removeAttr('onclick');

        $('<div class="confirmation-dialog" title="Delete Confimation"><p>Are you sure you wish to delete this entity?</p></div>').dialog({
            resizable: false,
            modal: true,
            buttons: {
                'Delete': function () {
                    $(this).dialog('close');
                    $(button).attr('onclick', onClick);
                    $(button).trigger('click');
                    $(button).parent().remove();
                },
                Cancel: function () {
                    $(this).dialog('close');
                    $(button).attr('onclick', onClick); // todo fix this
                    return false;
                }
            }
        });
        return false;
    });
}

function applyRoles() {
    if (!userRoles.isSuperAdministrator)
        $('.isSuperAdministrator').hide();
    if (!userRoles.isAdministrator)
        $('.isAdministrator').hide();
    if (!userRoles.isPowerUser)
        $('.isPowerUser').hide();
    if (!userRoles.isUser)
        $('.isUser').hide();

}