//If the SDK namespace object is not defined, create it.
if (typeof (N52) == "undefined")
{ N52 = {}; }
// Create Namespace container for functions in this library;
N52.Command = {

GetServerUrl: function()
{
    var context, crmServerUrl;  
    if (typeof GetGlobalContext != "undefined") {  
        context = GetGlobalContext();  
    }  
    else if (typeof Xrm != "undefined") {  
        context = Xrm.Page.context;  
    }  
    else {  
        throw new Error("CRM context is not available.");  
    }  
  
 
      if (typeof context.getClientUrl != "undefined") 
      {
         crmServerUrl = context.getClientUrl();
      }
      else
      {
          crmServerUrl = context.getServerUrl();  
          crmServerUrl = crmServerUrl.replace(/^(http|https):\/\/([_a-zA-Z0-9\-\.]+)(:([0-9]{1,5}))?/, window.location.protocol + "//" + window.location.host);  
          crmServerUrl = crmServerUrl.replace(/\/$/, ""); // remove trailing slash if any  
      }

   
    return crmServerUrl; 

},


CallCommand: function(targetentityid, name, inputstring1, inputstring2, inputstring3, inputstring4, inputstring5, inputstring6, inputstring7, inputstring8, inputstring9, inputstring10)
{

try{
   
    //Set defaults if null
    if (inputstring1 == null) inputstring1 = '??'; 
    if (inputstring2 == null) inputstring2 = '??';
    if (inputstring3 == null) inputstring3 = '??';
    if (inputstring4 == null) inputstring4 = '??';
    if (inputstring5 == null) inputstring5 = '??';
    if (inputstring6 == null) inputstring6 = '??';
    if (inputstring7 == null) inputstring7 = '??';
    if (inputstring8 == null) inputstring8 = '??';
    if (inputstring9 == null) inputstring9 = '??';
    if (inputstring10 == null) inputstring10 = '??';
        
    if (targetentityid == null) {
           alert('Please select a record before running the command.');
    }
    else
    {

       var dataValue = encodeURIComponent('name=' + name +'&inputstring1='+ inputstring1 +'&inputstring2='+ inputstring2+'&inputstring3='+ inputstring3+'&inputstring4='+ inputstring4+'&inputstring5='+ inputstring5+'&inputstring6='+ inputstring6+'&inputstring7='+ inputstring7+'&inputstring8='+ inputstring8+'&inputstring9='+ inputstring9+'&inputstring10='+ inputstring10 );
       var finalUrl = N52.Command.GetServerUrl() + '/WebResources/north52_html_commanduser?data=' + dataValue + '&id=' + targetentityid+'&userlcid='+ Xrm.Page.context.getUserLcid();

        window.open(finalUrl, self, 'top=300, left=300, width=400, height=200');

      }
    
 }
 catch (ex)
 {
   alert('Failure unable to launch command:  ' + ex.message);
 }

}


}