//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

/*
dprintf = function(newDebugMessage)
{
  if (DEBUG_MODE)
    DEBUG_TEXT = DEBUG_TEXT + newDebugMessage+'<br>';
  if (DEBUG_MODE && (DEBUG_TARGET != null))
  {
    DEBUG_TARGET.cbe.innerHtml(DEBUG_TEXT)
  }
};
*/

function dprintf(msg){
  if (!DEBUG_MODE)
    return;
  var forceHTML = false;
  var debugLogElement = DEBUG_TARGET;
  var newMessageDIV = xCreateElement('DIV');
  setClass(newMessageDIV,'logMessage');
  if (arguments.length > 1){
    if (arguments[1]==true)
      forceHTML = true;
  }
  if (forceHTML)
    newMessageDIV.innerHTML = msg;
  else{
    var message = document.createTextNode(msg);
    newMessageDIV.appendChild(message);
  }
  debugLogElement.appendChild(newMessageDIV);
};

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><body><b>'+document.location+'<br>'+'</b><hr>'+bugReport+'<br><i>'+fromAddress+'</i><hr>'+DEBUG_TARGET.innerHTML+'</body></html>';
    //makeASyncPostRequest(callbackTarget, 'dEmail', 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());
    //makeASyncPostRequest(callbackTarget, 'dEmail', XMLRPC_URL,'EMail.enhanced.send',document.getGuiValue("debugEmailAddress"),fromAddress,'The Freeance Bug Reporter','Freeance Bug Report','Freeance:  We load the map viewer!','',mailContent,Array(),Array());
    makeSyncPostRequest(XMLRPC_URL,'EMail.enhanced.send',document.getGuiValue("debugEmailAddress"),fromAddress,'The Freeance Bug Reporter','Freeance Bug Report','Freeance:  We load the map viewer!','',mailContent,Array(),Array());
    //makeSyncPostRequest(XMLRPC_URL,'EMail.enhanced.send','bbogovich@woh.rr.com',fromAddress,'The Freeance Bug Reporter','Freeance Bug Report','Freeance:  We load the map viewer!','',mailContent,Array(),Array());
  }
};

