

/* Noca's OneClick Pay Ubiquity plugin */
CmdUtils.CreateCommand({ 
  name: "donate",
  homepage: "http://www.noca.com/",
  author: { name: "Luke Gotszling", email: "luke@noca.com"},
  license: "GPL",
  description: "Allows a user to donate to a site using Noca's OneClick Pay",
  help: "Navigate to a page that has an account with Noca's OneClick Pay and supports the Ubiquity method. Then type donate (amount)",
  takes: {"amount": noun_arb_text},
  preview: function( pblock, amount ) {
    if(typeof(CmdUtils.getDocument().getElementsByName('NocaUbiquityID')[0])!='undefined'){
      pblock.innerHTML = "Donate " + amount.text;
    }
    else {
      pblock.innerHTML = "This site does not support Noca's OneClick Pay Ubiquity extension. You can ask them to sign up for a free merchant account <a href='https://secure2.noca.com/portal/signup.jsp' style='text-decoration:underline;'>here</a>";
    }
  },
  execute: function( amount ) {
    if (typeof(CmdUtils.getDocument().getElementsByName('NocaUbiquityID')[0])!='undefined'){
      //displayMessage( "Donating " + amount.text );
      var merchantID = escape(CmdUtils.getDocument().getElementsByName('NocaUbiquityID')[0].content);
      var cleanAmount = amount.text.replace(/[^\d\.]*/,"");
      var url = "https://secure2.noca.com/hosted.php?OCPformMerchantID="+merchantID+"&OCPformTotalAmount="+cleanAmount;
      Utils.openUrlInBrowser(url);
    }
    else {
      displayMessage( "This site does not support Noca's OneClick Pay Ubiquity extension. Please ask the owner to sign up for a free merchant account on www.noca.com" );
    }
  }
});