﻿/*
 * Functions for jQuery Lightbox-style Popup window
 */

function ShowErrorPopup() {
    ShowPopupWithMessage("Sorry, there has been an error", "There was an unexpected error processing your request. Please try again. If you continue to experience this error, please contact us", "ui-icon-alert");    
}

function ShowPopupWithMessage(title, message, fnCallback, icon) {
    $(document).ready(function() {
        icon = icon || 'ui-icon-info';
        var content = '<p><span class="ui-icon ' + icon + '" style="float:left; margin:0 7px 50px 0;"></span>' + message + '</p>';

        $("#popupdialog").dialog("destroy").remove();

        var $dialog = $("<div id='popupdialog'></div>")
		    .html(content)
		    .dialog({
		        resizeable: false,
		        autoOpen: true,
		        modal: true,
		        title: title,
		        zIndex: 2000,
		        buttons: { Ok: function() { $(this).dialog('close'); } }
		    });
    });
}

function ShowPopupMessageWithCallback(title, message, fnCallback, icon) {
    $(document).ready(function() {
        icon = icon || 'ui-icon-info';
        var content = '<p><span class="ui-icon ' + icon + '" style="float:left; margin:0 7px 50px 0;"></span>' + message + '</p>';

        $("#popupdialog").dialog("destroy").remove();

        var $dialog = $("<div id='popupdialog'></div>")
		    .html(content)
		    .dialog({
		        resizeable: false,
		        autoOpen: true,
		        modal: true,
		        title: title,
		        zIndex: 2000,
		        buttons: { Ok: function() { $(this).dialog('close'); } },
		        close: fnCallback
		    });
	});
}

function ShowAjaxPopup(title, url, awidth, aheight, showbutton) {
    $("#iframedialog").dialog("destroy").remove();
    var dialogOpts = {
        resizeable: false,
        height: aheight,
        width: awidth,
        autoOpen: true,
        modal: true,
        zIndex: 2000,
        title: title
    };
    if (showbutton) {
        dialogOpts.buttons = { Ok: function() { $(this).dialog('close'); } };
    }
    var $dialog = $('<iframe id="iframedialog" src="' + url + '" noresize="noresize" scrolling="no" frameborder="0" allowtransparency="true"></iframe>')
		.dialog(dialogOpts);

    // doing this because jquery ui adds an inline style of "width: auto"
    $("#iframedialog").width(awidth - 25);
}

function ShowAjaxPopupWithCallback(title, url, awidth, aheight, showbutton, fnCallback) {
    $("#iframedialog").dialog("destroy").remove();
    var dialogOpts = {
        resizeable: false,
        height: aheight,
        width: awidth,
        autoOpen: true,
        modal: true,
        title: title,
        zIndex: 2000,
        close: fnCallback
    };
    if (showbutton) {
        dialogOpts.buttons = { Ok: function() { $(this).dialog('close'); } };
    }
    var $dialog = $('<iframe id="iframedialog" src="' + url + '" noresize="noresize" scrolling="no" frameborder="0" allowtransparency="true"></iframe>')
		.dialog(dialogOpts);

    // doing this because jquery ui adds an inline style of "width: auto"
    $("#iframedialog").width(awidth - 25);
}

function CloseIFrameDialog(success) {
    $("#iframedialog").dialog("close");
    if (success) {
        ShowPopupWithMessage("Email Sent", "Your message has been sent successfully");
    }
    else {
        ShowErrorPopup();
    }
}