if (typeof (N52) == "undefined")
{ N52 = {}; } 

N52.Configuration =
{    


  RefreshCache: function ()
  {
    try
    {
      var configuration = {};
      configuration.north52_Command = {"__metadata": {"type": "Microsoft.Crm.Sdk.Data.Services.OptionSetValue"}, "Value": 217890000};

      SDK.JQuery.updateRecord(
        Xrm.Page.data.entity.getId(),
        configuration,
        "north52_configuration", 
        N52.Configuration.RefreshCacheconfigSuccess,
        N52.Configuration.RefreshCacheconfigError
      );
   }
   catch(ex)
   {
    alert("North52 Formula Manager Exception: " + ex.message);
   } 

  },


  RefreshCacheconfigSuccess: function ()
  {
     alert('Success : Refresh of the caches will occur on the next system request to Formula Manager.');
  },

  RefreshCacheconfigError: function (error)
  {
   alert(error.message);
  },

 PublishAll: function (recordid)
  {
    try
    {
     
       var command = '217890017';
       var parameter = 'N52 Publish All'; 
       var configuration = {};
       configuration.north52_Command = { Value: command };
       configuration.north52_CommandParameter =  parameter ;

      SDK.JQuery.updateRecord(
        Xrm.Page.data.entity.getId(),
        configuration,
        "north52_configuration", 
        N52.Configuration.PublishAllconfigSuccessNoMessage,
        N52.Configuration.PublishAllconfigError
      );

   }
   catch(ex)
   {
    alert("North52 Formula Manager Exception: " + ex.message);
   } 

  },

 PublishAllconfigSuccessNoMessage: function ()
  {
      alert('Success : All formulas & schedules are now publishing. Please navigate to Settings -> System Jobs & look for the workflow N52 Publish All for further details.');
  },

  
  PublishAllconfigError: function (error)
  {

   alert(error.message);
  },

ExecuteCommand: function (command)
  {
    try
    {
        
      var configuration = {};
      configuration.north52_Command = { Value: command};
     

      SDK.JQuery.updateRecord(
        Xrm.Page.data.entity.getId(),
        configuration,
        "north52_configuration", 
        N52.Configuration.ExecuteCommandconfigSuccess,
        N52.Configuration.ExecuteCommandconfigError
      );


   }
   catch(ex)
   {
    alert("North52 Formula Manager Exception: " + ex.message);
   } 

  },


  ExecuteCommandconfigSuccess: function ()
  {
     alert('Success : The command has completed.');
  },

  ExecuteCommandconfigError: function (error)
  {

   alert(error.message);
  },


 OnLoad: function ()
  {

     window.top.moveTo(0,0);
      window.top.resizeTo(screen.availWidth, screen.availHeight);
  },



Save: function (executionContext)
  {
      var eventArgs = executionContext.getEventArgs();

      if (eventArgs.getSaveMode() == 70)
      {
           eventArgs.preventDefault();
           return;
      }

  }


}