﻿function OnBeforeUnload()
{   
    var flag = false;

    if (typeof (NewPost) != "undefined")
    {
        if (NewPost.EditMode != "New")
        {
            if (NewPost.IsDirty)
                flag = true;
        }
        else
        {
            if (typeof (NewThread) != "undefined")
            {
                if (NewThread.IsDirty && !NewPost.IsSubmitClicked)
                    flag = true;
            }            
        }
    }
    else if (typeof (EditProfile) != "undefined")
    {
        if (EditProfile.IsDirty)
            flag = true;                
    }
    
    
    if (flag)
        return "All your pending changes will be cancelled.";
}