﻿var dialog;
function setDialog(val) {
    dialog = val;
}
var di;
function getDialog() {
    if (!dialog) {
        setDialog($("#modal"));
    }
    if (dialog.length <= 0) {
        $("<div id='modal'></div>").appendTo("body");
        setDialog($("#modal"));
    }
    //check to see if the dialog is initialized
    if (!dialog.dialog('isOpen')) {
        dialog.dialog({
            autoOpen: false,
            resizable: true,
            draggable: true,
            modal: true,
            position: 'top',
            height: 475,
            width: 525
        });
    }
    return dialog;
}
function closeDialog() {
    getDialog().dialog('close');
}

$(document).ready(function() {
    var userAgreement = $('.userAgreement'); //.append('<a href="#">User Agreement</a>');
    if (userAgreement.length > 0) {
        getDialog().load('Overlay/UserAgreementModalOverlay.aspx form div', {}, function(data) {
            getDialog().dialog('option', 'title', 'User Agreement')
        });
        userAgreement.click(function() {
            $('html, body').animate({ scrollTop: 0 }, 'fast');
            getDialog().dialog('open');
            $('.ui-dialog').animate({ 'top': '10px' }, 'slow');
            return false;
        });
    }
});

function toHtml(value) {
    value = value.replace('&gt;', '>');
    value = value.replace('&lt;', '<');
    return value;
}