﻿// 4/7/2010 nkt: for modules that needs isDirty validation)...  supports Telerik controls

var isDirty = 0
function setDirty() {
    isDirty = 1;
}

function setDirtyOff() {
    isDirty = 0;
}

//function checkIsDirtySave() {
//    // 11/24/2010 add hidden field so don't have to redirect / refresh a page on save
//    if (document.getElementById('ctl00$ctl00$ContentPlaceHolder1$hdnIsDirtySave').value == 'Saved') {
//        isDirty = false;
//    }
//}

//function checkIsDirtySave() {

// //   alert(document.form1.item("ctl00$ctl00$hdnIsDirtySave").value);
//    alert(document.getElementById("ctl00$ctl00$hdnIsDirtySave").value);
// //   alert(document.getElementById("hdnIsDirtySave").value);
//    alert(document.aspnetForm['ctl00$ctl00$hdnIsDirtySave'].value);
//    
////    alert(document.getElementById('ctl00$ctl00$hdnIsDirtySave').value);
////    alert(document.getElementById('hdnIsDirtySave').value);


////    alert(document.getElementById('hdnIsDirtySave'.value));
////    alert(document.getElementById('ctl00$ctl00$hdnIsDirtySave'.value));


////    if (document.aspnetForm['ctl00$ctl00$hdnIsDirtySave'].value == 'Saved') {
////        isDirty = 0;
////    }
////    if (document.getElementById('ctl00$ctl00$hdnIsDirtySave'.value == 'Saved')) {
////        isDirty = 0;
////    }


//}


// reset value when save is clicked... add attributes to all save buttons
// btnSave.Attributes.Add("onclick", "resetDirty();")
function resetDirty() {
    isDirty = 0;
    return true;
}


// used by hyperlinks on the home page... open in a new window
function checkDirtyUrlPopup(myUrl, myMessage, winName) {

    var sContinue;
    
 //   checkIsDirtySave(); // 11/26/2010

    if (isDirty == 1) {
        sContinue = window.confirm(myMessage);
        if (sContinue != true) {
            return false;     // cancel so they can save
        }
    }
    // nkt: pass in URL, then the name of the window, this will force a popup
    // i don't want it to be the same window, in case it is in back, and they can't find it...
    // so pass in a unique value as the second param so it will force a new window every time
    window.open(myUrl, winName);
    return false;
}

// used on buttons
function checkDirty(myMessage) {
    var sContinue;

 //   checkIsDirtySave(); // 11/26/2010

    if (isDirty == 1) {
        sContinue = window.confirm(myMessage);
        if (sContinue != true) {
            return false;     // cancel so they can save
        }
        isDirty = 0; // reset if true...
    }
    return true;
}

function checkDelete(myMessage) {
    var sContinue;
        sContinue = window.confirm(myMessage);
        if (sContinue != true) {
            return false;     // cancel so they can save
        }
        isDirty = 0; // reset if true...
    return true;
}

function checkCloneDirty(myMessage) {
    var sContinue;

  //  checkIsDirtySave(); // 11/26/2010

    if (isDirty == 1) {
        sContinue = window.confirm(myMessage);
        if (sContinue != true) {
            return false;     // cancel so they can save
        }
    }
    isDirty = 1;
    // clone should force a save! set the flag as changed!
    return true;
}

// 11/18/2010 leave the isDirty flag the way you set it...
function checkComboBoxDirty(myMessage) {
    var sContinue;

 //   checkIsDirtySave(); // 11/26/2010

    if (isDirty == 1) {
        sContinue = window.confirm(myMessage);
        if (sContinue != true) {
            return false;     // cancel so they can save
        }
        isDirty = 0; // reset if true...
    }
    return true;
}

//  used on menu clicks to check dirty, and cancel propagation as needed
function GetDirtyMenuClick(e, message) {
    var sContinue;

//    checkIsDirtySave(); // 11/26/2010

    if (isDirty == 1) {
        sContinue = window.confirm(message);
        if (sContinue != true) {
            if (e.stopPropagation)
                e.stopPropagation();
            return false;     // cancel so they can save
        }
    }
    return true;
}

// 4/13/2010
function GetDirtySetCancelClick(sender, eventArgs) {
    var sContinue;

//    checkIsDirtySave(); // 11/26/2010

    if (isDirty == 1) {
        sContinue = window.confirm("You have unsaved changes. Please select CANCEL if you would like to return to the form to save your changes. Please select OK if you wish to proceed and lose your changes.");
        if (sContinue != true) {
            eventArgs.set_cancel(true);
            return false;     // cancel so they can save
        }
    }
    isDirty = 0; // reset if continue
    return true;
}

