﻿//**************************************************
// Called by the 'Cancel' button on the page.
//  -Checks to see if the the page is dirty
//   and prompts if changes have been made.
//**************************************************
function pageCancel_Click(hiddenField) {
    var pageDirty = document.getElementById(hiddenField).value;

    if (pageDirty == 'true') {
        return confirm('Are you sure you wish to cancel?');
    }
    else if (pageDirty == 'false') {
        return true;
    }
    else {
        alert('ERROR: Page changes not properly handled.');
        return false;
    }
}

//**************************************************
// Called by the 'Save' button on the page.
//  -Makes the 'working' image visible and adds
//   text to the status label. Needs the names
//   of the image and label passed in.
//**************************************************
function pageSave_Click(statusImg, statusLbl) {
    document.getElementById(statusImg).style.visibility = 'visible';
    document.getElementById(statusLbl).innerText = 'Saving...';
}

//**************************************************
// Changes the hidden field on the page
// depending if changes were made.
//**************************************************
function formDirtyChanged(dirty, hiddenField) {
    document.getElementById(hiddenField).value = dirty;
}

// Dirty changed method for multiline textboxes
function multiline_DirtyChanged(dirty, hiddenField, obj) {
    formDirtyChanged(dirty, hiddenField);
    return ismaxlength(obj);
}

/***********************************************
* Textarea Maxlength script- © Dynamic Drive (www.dynamicdrive.com)
* This notice must stay intact for legal use.
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

function ismaxlength(obj) {
    var mlength = obj.getAttribute ? parseInt(obj.getAttribute("maxlength")) : ""
    if (obj.getAttribute && obj.value.length > mlength)
        obj.value = obj.value.substring(0, mlength)
}
