﻿function ajax_BeginRequest(sender, args) {
    showLoading();
    $('#ajaxErrorWindow').hide();
}
function ajax_EndRequest(sender, args) {
    hideLoading();
    if (args.get_error() != undefined) {
        $('#ajaxErrorWindow').show('blind');
        $('#ajaxErrorWindow p').html(args.get_error().message);
        args.set_errorHandled(true);
    }
}

function showLoading() {
    $('#ajaxLoader').show();
}
function hideLoading() {
    $('#ajaxLoader').hide();
}

$(function() {
    refreshFx();
    hideLoading();
    $('#ajaxErrorWindow').hide();
    $('#ajaxLoader').ajaxStart(showLoading).ajaxStop(hideLoading);
    $('#helpWindow').dialog({
        autoOpen: false,
        width: '500',
        autoSize: true,
        modal: true,
        buttons: {
            'Close': function() { $('#helpWindow').dialog('close'); }
        }
    });
});

function refreshFx() {

    $('input[type=button], input[type=submit], .button, .ui-button').addClass('ui-corner-all ui-state-default ui-button').mouseenter(function() {
        $(this).addClass('ui-state-hover')
    }).mouseleave(function() {
        $(this).removeClass('ui-state-hover').removeClass('ui-state-active');
    }).mousedown(function() {
        $(this).addClass('ui-state-active');
    }).mouseup(function() {
        $(this).removeClass('ui-state-active');
    });

    $(".datePicker").datepicker();
    $("#profileTabs").tabs({
        cookie: {
            expires: 1,
            name: 'profileTabs'
        },
        fx: {
            opacity: 'toggle'
        }
    });
    $("#editPetTabs").tabs({
        cookie: {
            expires: 1,
            name: 'editPetTabs'
        },
        fx: {
            opacity: 'toggle'
        }
    });

    $('.infoBox_Information, .infoBox_Question, .infoBox_Warning, .infoBox_Error').addClass('ui-widget ui-corner-all');
    $('.infoBox_Information, .infoBox_Question, .infoBox_Warning').addClass('ui-state-highlight');
    $('.infoBox_Error').addClass('ui-state-error');

    /*
    setTimeout("$('.notifications').fadeOut('slow');", 5000);
    setTimeout("$('.errors').fadeOut('slow');", 5000);
    */
    setTimeout("$('.fadeMe').fadeOut('slow');", 5000);
}

function showHelpWindow(anchor, language) {
    $('#helpWindow').dialog('open');
    $('#helpWindow #helpTitle').text('Loading...');
    $('#helpWindow #helpContents').text('Loading...');
    $('#helpWindow #helpTitle').load('Help.ashx', 'Language=' + language + '&Subject=' + anchor + '&GetTitle=true');
    $('#helpWindow #helpContents').load('Help.ashx', 'Language=' + language + '&Subject=' + anchor + '&GetText=true');
}