﻿// JScript File
hasChanges = false; // Page has changes?

function changeMade()
{
    hasChanges = true;
}

function submitFunction()
{
    // Turn hasChanges off, we want to submit and save the form.
    hasChanges = false;
}

function load()
{
    // Attaches changeMade function to each input tag on the page.
    // Supports textbox, checkbox, radio elements.
    // ** TO-DO Add support for large textarea. **

    var inputCollection=document.getElementsByTagName("input");
    
    for(var i = 0; i < inputCollection.length; i++)
    {
        // Is this the submit button?
        if(inputCollection[i].id.toLowerCase().indexOf("submit") != -1)
        {
            inputCollection[i].onclick = submitFunction;
        }
        else // This is a standard input.
            inputCollection[i].onchange = changeMade;
    }
}
function beforeunload()
{
    // Trigger browser navigation dialog with the custom message below.
    if(hasChanges)
        return "You will loose any data entered.  Press “okay” to exit without saving changes or “cancel” to continue...";
}
window.onload = load;
window.onbeforeunload = beforeunload;

