﻿$(function () {

    ShowDialog();

    //Re-center dialog after widow resize
    $(window).resize(function () {
        if ($(".dialog").dialog("isOpen")) {
            ShowDialog();
        }
    });

    //Custom close event handler 
    $(".close").click(function (event, ui) {
        $(".dialog").dialog('close');
        return false;
    });

});

function ShowDialog() {
    var popup = $('.dialog');

    var opt;
    //Fix jQuery UI modal dialog centering problem in google chrome
    if ($.browser.webkit) {
        var x = Math.round((document.documentElement.clientWidth - 690) / 2);
        var y = Math.round((document.documentElement.clientHeight - 533) / 2);
        opt = {
            width: 690,
            modal: true,
            closeOnEscape: false,
            position: [x, y],
            //Remove default title bar
            open: function (event, ui) { $(".ui-dialog-titlebar").hide(); }
        };
    }
    else {
        opt = {
            width: 690,
            modal: true,
            closeOnEscape: false,
            position: "center",
            //Remove default title bar
            open: function (event, ui) { $(".ui-dialog-titlebar").hide(); }
        };
    }

    //Show dialog
    popup.dialog(opt);

    // Focus on top element
    $('#top').focus();
}
