﻿var isPageDirty = false;
var nextUrl = "";
var discardYesButton;

if ($("#pageDirty").val()=="1") isPageDirty = true;

function EnableTracePageDirty() {
    jQuery('input').bind('change', MarkPageDirty);
}

function MarkPageDirty(e) {
    isPageDirty = true;
    $("#pageDirty").attr("value", "1");
}

function SetPageClean(e) {
    isPageDirty = false;
    $("#pageDirty").attr("value", "0");
}

function PageModified() {
    return isPageDirty;
}

function NavMenuPage(url) {
    if (PageModified()) {
        $("#discardChangesDialog").css({ display: 'inline' }).dialog('open');
        nextUrl = url;
    }
    else
        window.location = url;
}

function CancelChanges() {
    if (PageModified() == true) {
        nextUrl = "";
        $("#discardChangesDialog").css({ display: 'inline' }).dialog('open');
        return false;
    }
    return true;
}

function DiscardChangesYes_CallBack() {
    $('#discardChangesDialog').dialog('close');
    if (nextUrl != "") {
        window.location = nextUrl;
        nextUrl = "";
    }
    else {
        SetPageClean();
        $("input[id$='" + discardYesButton + "']").trigger('click');
    }
}

function BackgroundShow() {
    $('#grayBoxDiv').css({
        opacity: 0.7,
        top: 0,
        left: 0,
        width: document.documentElement.scrollWidth,
        height: document.documentElement.scrollHeight,
        display: 'inline',
        'z-index': 2000
    });
    $('.ui-dialog').css('z-index', '999999');
    if (jQuery.browser.msie && jQuery.browser.version < 6.5) {
        $('.selectFree iframe').css('display', 'inline');
        $('select').css('visibility', 'hidden');
    }
}

function BackgroundHide() {
    $('#grayBoxDiv').css({ display: 'none' });
    $('select').css('visibility', 'visible');
}

