//debug.js
//debug functionality
//provides facilities for error logging and transmission
//These functions have a global scope.  Will be converted to an object in the future.
//DEBUG_MODE is a boolean indicating that debugging is enabled.
//DEBUG_TEXT is a string; all current debug information
//DEBUG_TARGET is a pointer to an html element used for display of debugging information
//DEBUG_ADDRESS is a string; email address of the recipient of debug emails


DEBUG_TARGET = null;
dprintf = function(newDebugMessage)
{
  if (DEBUG_MODE)
  {
    DEBUG_TEXT = DEBUG_TEXT + newDebugMessage+'<br>\n';
    if (DEBUG_TARGET!=null)
    {
      if (document.getElementById('debugLogOuterContainer').style.display == 'block')
        DEBUG_TARGET.innerHTML = DEBUG_TEXT;
    }
  }
};

dEmail = function()
{
  //sends a HTML formatted email to the address specified by DEBUG_ADDRESS
  var fromAddress = '';
  var bugReport = prompt('Please describe your problem in as much detail as possible','');
  var emailFilter=/^.+@.+\..{2,3}$/;
  if (fromAddress){
    if (!(emailFilter.test(fromAddress))) 
      fromAddress = 'freeanceBugs@freeance.com';
  }
  else
    fromAddress = 'freeanceBugs@freeance.com';
  if (bugReport){
    mailContent = '<html>\n<body>\n<b>'+document.location+'</b><hr>'+bugReport+'<br><i>'+fromAddress+'</i><hr>\n\n'+DEBUG_TEXT+'\n\n</body>\n</html>';
    makeSyncPostRequest(XMLRPC_URL,'EMail.enhanced.send',document.getGuiValue("ApplicationConfig").adminEmail,fromAddress,'The Freeance Bug Reporter','Freeance Bug Report','Freeance:  We load the map viewer!','',mailContent,Array(),Array());
  }
};

dClear = function()
{
  DEBUG_TEXT = '';
  if ((DEBUG_MODE)&&(DEBUG_TARGET!=null))
    DEBUG_TARGET.innerHTML = '';
};
