﻿ 

  /**
  Default constructor of TempestNS
  May 7, 2008: RB removed a semicolon after the final brace of the TempestNS() blank constructor. 
  This was an error, and I was hoping it would fix the IE problem, but apparently it did not. Still, better to fix it.
  **/
  function TempestNS()
  {

  }

  /**
  Every assembly attaches a caboose after it is written by the server
  The caboose consist of the call
  TempestNS.RegisterScript({assemblyKey})

  This call alerts the script register that the script is loaded
  which may in turn cause a callback function to be executed
  **/

  TempestNS.RegisterScript= function(assemblyKey)
  {
    if(!TempestNS.Client)return;
    if(!TempestNS.SCRIPTREGISTRY)
    {
      new TempestNS.Client.ScriptRegistry();
    }
    TempestNS.SCRIPTREGISTRY.AddAssembly(assemblyKey);
  };

  TempestNS.RequestAssembly= function(assemblyKey,callback)
  {
    if(!TempestNS.Client)return;
    if(!TempestNS.SCRIPTREGISTRY)
    {
    new TempestNS.Client.ScriptRegistry();
    }
    TempestNS.SCRIPTREGISTRY.RequestScript(assemblyKey,callback);
  };
  
 

  /**
  Common info about the Prospero Server, its build version, and dbg status
  **/
  TempestNS.Server = {
  'buildVersion' : '6830.154',
  'dbg' : '0',
  'domain' : 'boards.blackvoices.com',
  'zone':'',
  'tempestPath':'/dir-script/357519/TempestNS.',
  'Apps': {
  'forum': '/n/pfx/forum.aspx',
  'blog': '/n/blogs/blog.aspx',
  'profile': '/n/pfx/profile.aspx',
  'album' :'/n/pfx/album.aspx',
  'wiki':'/n/pfx/wiki.aspx',
  'ideashare':'/n/pfx/ideashare.aspx',
  'control':'/n/pfx/control.aspx',
  'filerepository': '/n/pfx/filerepository.aspx',
  'login': '/n/login/login.aspx'
  }
  };
  
 

/**
 <summary>
  Default constructor of TempestNS.Client
 </summary>
 <param name=""></param>
**/
TempestNS.Client = function()
{
 this.protocol = location.protocol; 
}

/**
 <summary>
  Method for resizing an image to its container so as to fit it in the same aspect ratio.
  It also centers the image horizontally and vertically.
  For an onload event handler, this function will work best if
   - Image is called WITHOUT width or height attributes (native dimensions will be calculated by browser)
   - Image style has been set to visibility: hidden
   - Container has a fixed width and height
   - Container is a block-level element with overflow set to hidden
 </summary>
 <param name="img">The image to be resized.</param>
 <param name="vertCenter">If true, image is centered vertically in container.</param>
 <param name="box">Optional. The container in which the image will be resized</param>
**/
TempestNS.Client.FitImageToContainer =  function (img, vertCenter, box)
{
  if (!img) return;
  var container = (box) ? box : img.parentNode;
  /* if (container.className != "myImage") return; */
  var imgW = img.width;
  var imgH = img.height;
  var conW = container.offsetWidth;
  var conH = container.offsetHeight;
  var imgAspect = imgW / imgH;
  var conAspect = conW / conH;
  var sizeCoefficient = 1;
  var marginTop = 0;
  if (imgAspect > conAspect) // resize horizontally
  {
    sizeCoefficient = conW / imgW;
    marginTop =  Math.floor( (conH - Math.floor(imgH*sizeCoefficient))/2);
  }
  else if (conAspect > imgAspect) // resize vertically
  {
    sizeCoefficient = conH / imgH;
  }
  img.style.width = Math.floor(imgW*sizeCoefficient) + "px";
  img.style.height = Math.floor(imgH*sizeCoefficient) + "px";
  //img.src = img.src + "?width=" + Math.floor(imgW*sizeCoefficient) + "&height=" + Math.floor(imgH*sizeCoefficient);
  if (vertCenter) img.style.marginTop = marginTop + "px";
  img.style.visibility = "visible";

};


/**
 <summary>
 Assumes the parent holds one avatar.
 - Find the parent
 - Find the prospero avatar
 - Resize it
 </summary>
 <param name=""></param>
**/
TempestNS.Client.FitImageToContainerById = function (boxId, vertCenter)
{
  var box = document.getElementById(boxId);
  if(!box) 
  {
    return;
  }
  var images = document.getElementsByTagName("img");
  for(var i = 0; i < images.length; i++)
  {
    if(images[i].className == "ptcImg")
    {
      TempestNS.Client.FitImageToContainer(images[i], vertCenter, box);
    }
  }
};


/**
 <summary>
  Cross-browser method for adding event listeners.
 </summary>
 <param name=""></param>
**/
TempestNS.Client.AddEventListener = function(elm, type, listener, useCapture) 
{
    if(document.addEventListener)
    {
        elm.addEventListener(type, listener, useCapture);
    }
    else if(document.attachEvent)
    {
        elm.attachEvent("on" + type, listener);
    }
    else
  {
        elm["on"+type] = callback;
    }
}


TempestNS.Client.StopPropogation=function(evt)
{
    if(evt==null)
    {
        evt = window.event;
    }
    if(evt.stopPropagation)
    {
        evt.stopPropagation();
        evt.preventDefault();
    }
    else if(evt.cancelBubble)
    {
        evt.cancelBubble=true;
        evt.returnValue = false;
    }
}

/**
 <summary>
  Remove a crossbrowser event listener to an element
 </summary>
**/
TempestNS.Client.RemoveEventListener = function(elm, type, listener, useCapture)
{
    if(document.removeEventListener)
    {
        elm.removeEventListener(type, listener, useCapture);
    }
    else if(document.detachEvent)
    {
        elm.detachEvent("on" + type, listener, useCapture);
    }
    else
  {
        elm["on"+type] = null;
    }
}



/**
 <summary>
  Helper function to determine if your browser prefers using the class or classname attribute
 </summary>
 <param name="elm">an element with a class attribute.  If it does NOT have a class then it will return "class".</param>
**/
TempestNS.Client.GetClassAttribute = function(elm)
{
  /* Needed to handle browser differences with JS and setting the class name.
     See if this browser uses pre IE8 model of assigning classes to elements */
  if(elm.getAttribute("className"))
  {
    return "className";
  }
  else
  {
    return "class";
  }
};



/**
 <summary>
  
 </summary>
 <param name=""></param>
**/
TempestNS.Client.GetControlValue = function(ctl)
{
  switch(ctl.type)
  {
    case "checkbox":
    {
      if(!ctl.checked)
      {
        return null;  /* nothing should be posted back */
      }
      break;
    }
    case "radio":
    {
      if(!ctl.checked)
      {
        return null;  /* nothing should be posted back */
      }
      break;
    }
    case "select-one":
    {
      return ctl.options[ctl.selectedIndex].value;
    }
  }
  return ctl.value;
}


/**
 <summary>
 Return the document height NOT the window height
 </summary>
**/
TempestNS.Client.GetDocumentHeight = function(theDoc)
{
  if(theDoc == null)
  {
    theDoc = document;
  }
  
  var h = Math.max(
    Math.max(
      Math.max(theDoc.body.scrollHeight, theDoc.documentElement.scrollHeight),
      Math.max(theDoc.body.offsetHeight, theDoc.documentElement.offsetHeight)
    ),
    Math.max(theDoc.body.clientHeight, theDoc.documentElement.clientHeight)
  );
  return h;
};


/**
 <summary>
  Returns the coordinates of an element relative to the page
 </summary>
 <param name=""></param>
**/
TempestNS.Client.GetElementPosition = function(elm)
{
  if(!elm){
    return {left:0, top:0, absTop:0};
  }
  var offsetTrail = elm;
  var offsetLeft = 0;
  var offsetTop = 0;
  while(offsetTrail) 
  {
    offsetLeft += offsetTrail.offsetLeft;
    offsetTop += offsetTrail.offsetTop;
    offsetTrail = offsetTrail.offsetParent;
  }
  if(navigator.userAgent.indexOf("Mac") != -1 && navigator.userAgent.indexOf("Safari") == -1 && typeof document.body.leftMargin != "undefined") 
  {
    offsetLeft += document.body.leftMargin;
    offsetTop += document.body.topMargin;
  }
  return {left:offsetLeft, top:offsetTop + elm.offsetHeight, absTop:offsetTop};
}


/**
 <summary>
  Returns the coordinates of an element relative to the page
 </summary>
 <param name=""></param>
**/
TempestNS.Client.GetMousePosition = function(e)
{
  var posx;
  var posy;
  if(e == null)
  {
    e = window.event;
  }
  if(e.pageX || e.pageY)
  {
    posx = e.pageX; 
    posy = e.pageY;
  }
  else if(e.clientX || e.clientY)
  {
    if(document.documentElement.scrollTop)
    {
      posx = e.clientX + document.documentElement.scrollLeft;
      posy = e.clientY + document.documentElement.scrollTop;
    }
    else
    {
      posx = e.clientX + document.body.scrollLeft;
      posy = e.clientY + document.body.scrollTop;
    }
  }
  return {"x":posx, "y":posy}
}


/**
 <summary>
  Returns the target of the mouse click
 </summary>
 <param name="e">Current window event</param>
**/
TempestNS.Client.GetMouseTarget = function(e) 
{
  var target;
  if(e == null)
  {
    e = window.event;
  }
  if(e.target) 
  {
    target = e.target;
  }
  else if(e.srcElement)
  {
    target = e.srcElement;
  }
  /* Correct for Safari bug */
  if(target.nodeType == 3)
  {
    target = target.parentNode;
  }
  return target;
}


/**
 <summary>
  Returns the height and width of the inner browser window
 </summary>
**/
TempestNS.Client.GetWindowSize = function() 
{
  var w = 0;
  var h = 0;
  if(typeof(window.innerWidth) == 'number') 
  {
    /* Non-IE */
    w = window.innerWidth;
    h = window.innerHeight;
  } 
  else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight )) 
  {
    /* IE 6+ */
    w = document.documentElement.clientWidth;
    h = document.documentElement.clientHeight;
  } 
  else if(document.body && (document.body.clientWidth || document.body.clientHeight )) 
  {
    /* IE 4 compatible */
    w = document.body.clientWidth;
    h = document.body.clientHeight;
  }
  return {"height":h, "width":w};
}


/**
 <summary>
  
 </summary>
 <param name=""></param>
**/
TempestNS.Client.IncludeScript = function(scriptUrl)
{
  /* Make sure the scriptURL is fully qualified */
  if(scriptUrl.substring(0,4) != "http")
  {
    if(scriptUrl.charAt(0) == "/")
    {
      scriptUrl = location.protocol+"//"+ TempestNS.Server.domain + scriptUrl;
    }
    if(scriptUrl.substring(0,3) == "../")
    {
      scriptUrl = location.protocol+"//"+ TempestNS.Server.domain + scriptUrl.substring(2,scriptUrl.length);
    }
  }
  var headElm = document.getElementsByTagName('head')[0];
  var scriptElm = document.createElement('script');
  scriptElm.setAttribute('type','text/javascript');
  scriptElm.setAttribute('src',scriptUrl);
  headElm.appendChild(scriptElm);
  return scriptElm;
}

TempestNS.Client.RemoveScript = function(scriptElm)
{
  var headElm = document.getElementsByTagName('head')[0];
  headElm.removeChild(scriptElm);
}




/**
 <summary>
  Scroll Page to a place on the customer's page
 </summary>
**/
TempestNS.Client.ScrollToId = function(scrollId)
{
  if(scrollId)
  {
    var placeOnPage = document.getElementById(scrollId);
    if(placeOnPage)
    {
      placeOnPage.scrollIntoView(true);
    }
  }
}


/**
 <summary>
  
 </summary>
 <param name=""></param>
**/
TempestNS.Client.ToolTip = function(parentDiv)
{
  /* Create outer <div/> */
    this.ptcToolTipBox = document.createElement("div");
    this.ptcToolTipBox.id = "ptcToolTip";
    this.ptcToolTipBox.style.position = "absolute";
    this.ptcToolTipBox.style.visibility = "hidden";
    this.ptcToolTipBox.className = "ptcToolTipBox";
    /* Create inner <div/> */
    this.ptcToolTipText = document.createElement("div");
    this.ptcToolTipText.style.position = "relative";
    this.ptcToolTipText.className = "ptcToolTipText";
    /* Add inner <div/> to the outer <div/> */
    this.ptcToolTipBox.appendChild(this.ptcToolTipText);
  /* Create an object to hold tips */
  this.msgs = new Array();
  
  /* Add Tool Tip Method */
  this.AddToolTip = function(tsn, msg)
  {
    this.msgs['msg'+tsn] = msg;
  }

    /* Hide Tool Tip Method */
  this.HideToolTip = function()
  {
    this.ptcToolTipBox.style.visibility = "hidden";
  }
  
  /* Show Tool Tip Method */
    this.ShowToolTip = function(tsn, e)
  {
    var mouse = TempestNS.Client.GetMousePosition(e);
    this.ptcToolTipText.innerHTML = this.msgs['msg'+tsn];
    this.ptcToolTipBox.style.top = mouse.y + 15 + "px";
    this.ptcToolTipBox.style.left = mouse.x + 15 + "px";
    this.ptcToolTipBox.style.visibility = "visible";
    if(parentDiv)
    {
      parentDiv.appendChild(this.ptcToolTipBox);
    }
    else
    {
      if(this.ptcToolTipBox.parentNode != document.body)
      {
        document.getElementsByTagName("body")[0].appendChild(this.ptcToolTipBox);
      }
    }
  }
}


TempestNS.Client.ToolTip.prototype = new Object();




/**
    needs server and client
    
    gopes in client

    the script provides utility methods for including new scripts dynamically
    the registry provides the ability to request new assemblys and the ability to execute callback functions once they 
    are complete
**/

TempestNS.Client.ScriptRegistry= function()
{
    if(TempestNS.SCRIPTREGISTRY)
    {
        return;
    }
    TempestNS.SCRIPTREGISTRY= this;
    this._Scripts = new Object();
    this._callbacks = new Object();
    this._head = null;
    this._Has = "";
};



/**
    This is executed from the call by the TempestNS.RegisterScript;
    Its key is inserted in the items collection 
    

**/



  
TempestNS.Client.ScriptRegistry.AddAssembly= function(assemblyKey)
{   
    if(this._Has!=""){
        this._Has+="|";
    }
    this._Has+=assemblyKey;    
    this._Scripts[assemblyKey]= assemblyKey;
    if(this._callbacks[assemblyKey])
    {
        var len = this._callbacks[assemblyKey].length;
        for(var index = 0 ; index <len;index++){
            this._callbacks[assemblyKey][index]();
        }
        if(TempestNS.COMPONENT_REGISTRY){
         TempestNS.COMPONENT_REGISTRY.LoadChildren();
        }
      
        this._callbacks[assemblyKey]=null;
    }
};
    
TempestNS.Client.ScriptRegistry.RequestScript = function(assemblyKey,callback)
{
  if(this._Scripts[assemblyKey])
  {
    callback();
  }
  else
  {
    if(this._callbacks[assemblyKey])
    {
        //there already hass been a request for this assembly -- just add to the call back array
        this._callbacks[assemblyKey].push(callback)
    }
    else
    {   this._callbacks[assemblyKey] = new Array();
        this._callbacks[assemblyKey].push(callback)
        this.MakeRequest(assemblyKey);
    }
  }      
};    
    
TempestNS.Client.ScriptRegistry.MakeRequest = function(assemblyKey)
{
    var src = location.protocol +"//" + TempestNS.Server.domain;
    src += TempestNS.Server.tempestPath;
    src += assemblyKey + ".js?";
     if(TempestNS.Server.dbg!='0')
     {
       src+="&dbg="+TempestNS.Server.dbg+"&";
       src+="ver=" + escape(new Date().valueOf())+"&";
     }
     src +=this.Has();  
     TempestNS.Client.IncludeScript(src);
};
    
TempestNS.Client.ScriptRegistry.Has= function()
{
    return "HaveScripts="+this._Has;
}    
    
    
TempestNS.Client.ScriptRegistry.prototype = new Object();
TempestNS.Client.ScriptRegistry.prototype.AddAssembly = TempestNS.Client.ScriptRegistry.AddAssembly;
TempestNS.Client.ScriptRegistry.prototype.RequestScript = TempestNS.Client.ScriptRegistry.RequestScript;
TempestNS.Client.ScriptRegistry.prototype.MakeRequest = TempestNS.Client.ScriptRegistry.MakeRequest;
TempestNS.Client.ScriptRegistry.prototype.Has = TempestNS.Client.ScriptRegistry.Has;





TempestNS.Client.StyleRegistry = function()
{
    /*insure its a singleton*/
    if(TempestNS.Client.STYLEREGISTRY){
        return;
    }
    TempestNS.Client.STYLEREGISTRY= this;
    this._styleSheets = new Object();
};

TempestNS.Client.StyleRegistry.AddStyle=function(href)
{
    
    if(!TempestNS.Client.STYLEREGISTRY){
        new TempestNS.Client.StyleRegistry();
    }
    
    key = escape(href);
    if(!TempestNS.Client.STYLEREGISTRY._styleSheets[key]){
      TempestNS.Client.STYLEREGISTRY._styleSheets[key]=href;
      if (document.createStyleSheet) /* IE only?  */
      {
        document.createStyleSheet(href);
      }
      else 
      {
        var ptCSS = document.createElement('link');
        ptCSS.rel = 'stylesheet';
        ptCSS.type = 'text/css';
        ptCSS.href = href;
        document.getElementsByTagName('head')[0].appendChild(ptCSS);
      }
    }
    
};

TempestNS.Client.StyleRegistry.prototype = new Object();



/**
 <summary>
  Hide or show all embedded objects on the page
 </summary>
 <param name=""></param>
**/
TempestNS.Client.EmbedShowHide = function(restore)
{
   objects = document.getElementsByTagName('embed');
   for (var i = 0; i < objects.length; i++) 
   { 
      objects[i].style.visibility = (restore ? 'visible' : 'hidden');
   }
};


/**
 <summary>
  Return the scroll top position
 </summary>
 <param name=""></param>
**/
TempestNS.Client.GetScrollTop = function()
{
  var ScrollTop = document.body.scrollTop;
  if(ScrollTop == 0)
  {
    if(window.pageYOffset)
    {
      ScrollTop = window.pageYOffset;
    }
    else
    {
      ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
    }
  }
  return ScrollTop;
};



 
  

/**
 <summary>
  Submit Prospero Template Commands and manage results
 </summary>
 <param name=""></param>
**/
TempestNS.CommandHandler = function()
{
  /* If one already exists then use it */
  if(TempestNS.COMMANDHANDLER)
  {
    return;
  }
  /* Otherwise, create new global TempestNS.COMMANDHANDLER */
  TempestNS.COMMANDHANDLER = this;
  /* Create a object to hold in-process commands (their callbacks) */
  this.CommandCallbacks = new Object();
  this.nextCommandId = 1;
}

/**
 <summary>
 </summary>
 <param name="widgetId"></param>
 <param name="application"></param>
 <param name="cmd"></param>
 <param name="controlList"></param>
**/
TempestNS.CommandHandler.SendCommand = function(widgetId, application, webtag, cmd, form, controlList, callback)
{
  var src = "http://" + TempestNS.Server.domain;
  src += TempestNS.Server.Apps[application];
  src += "?webtag=" + webtag;
  src += (widgetId) ? "&widgetId="+ widgetId : "";
  src += "&nav=jsscommandhandler";
  src += "&dst="+escape(new Date().toString());
  if(TempestNS.Server.dbg)
  {
    src += "&dbg=" + TempestNS.Server.dbg;
  }
  
  if(callback)
  {
    this.CommandCallbacks[widgetId] = callback;
  }
  
  var postParams = "&ptButtonCmd=" + escape(cmd) + "&ptButtonValidate=false";
  
  // build up a regexp that matches the controls we want
  if(controlList && form)
  {
    var controlsToGet = "^" + controlList.replace(",", "$|^").replace("*", ".*") + "$";
    var controlsRE = new RegExp(controlsToGet, "i");
    for(var i = 0; i < form.elements.length; i++)
    {
      var el = form.elements[i];
      var elId = el.id;
      if(elId)
      {
        if(elId.search(controlsRE) != -1)
        {
          // this control is in our list
          var ctlVal = TempestNS.Client.GetControlValue(el);
          if(ctlVal != null)
          {
            postParams += "&" + el.name + "=" + escape(ctlVal);
          }
        }
      }
    }
  }
  else if(controlList)
  {
    for(var i = 0; i < controlList.length; i++)
    {
      for(var j = 0; j < controlList[i].length; j++)
      {
        var ctlVal = TempestNS.Client.GetControlValue(controlList[i][j]);
        if(ctlVal)
        {
          // var name = controlList[i][j].id.split("_");name[name.length - 1]
          postParams += "&" + controlList[i][j].name + "=" + escape(ctlVal);
        }
      }
    }
  }
  
  src += postParams;
      if(TempestNS.Server.dbg == '53')
  {
      alert(src);
   }
  TempestNS.Client.IncludeScript(src);  
}

TempestNS.CommandHandler.CommandComplete = function(widgetId, commandResult)
{
  var callback = this.CommandCallbacks[widgetId];
  if (callback)
    callback(commandResult);
}
/**
** An alias of the SetRelationship fucntion, specifying "ignore" as the relationship.
**/
TempestNS.CommandHandler.IgnoreUser = function(webtag, userId, callback)
{
  this.SetRelationship(webtag,userId,"ignore",callback);  
}
/**
** An alias of the SetRelationship fucntion, specifying "friend" as the relationship.
**/
TempestNS.CommandHandler.AddFriend = function(webtag, userId, callback)
{
  this.SetRelationship(webtag,userId,"friend",callback);   
}
/**
** An alias of the SetRelationship fucntion, specifying "neutral" as the relationship.
**/
TempestNS.CommandHandler.ResetRelationship = function(webtag, userId, callback)
{
  this.SetRelationship(webtag,userId,"neutral",callback);  
}
/**
**  Creates or updates a Roster Item
**  webtag - webtag of the forum which contains the user
**  userId - userId to act on
**  relationship - friend, ignore, neutral -- required to determine relationship value to set
**  callback - javascript function to call on completion
**/
TempestNS.CommandHandler.SetRelationship = function(webtag, userId, relationship, callback)
{
  var cmdId = 'PCmd' + this.nextCommandId;
  this.nextCommandId++;
  var cmd = 'rosterSetRelationship(' + userId + ',' + relationship + ')';
    if(TempestNS.Server.dbg == '53')
  {
      alert(cmd);
   }
  this.SendCommand(cmdId, 'forum', webtag, cmd, null, null, callback);  
}
/**
**  Sets the rating on a message.
**  tid - message tid
**  tsn - message tsn
**  ratingValue - Integer (0-5) rating to set.
**/
TempestNS.CommandHandler.SetMessageRating = function(webtag, tid, tsn, ratingValue, callback)
{
  var cmdId = 'PCmd' + this.nextCommandId;
  this.nextCommandId++;
  var cmd = 'cmdSetMessageRating(' + tid + ',' + tsn + ',' + ratingValue + ')';
  this.SendCommand(cmdId, 'forum', webtag, cmd, null, null, callback);  
}

TempestNS.CommandHandler.AddFolder = function(webtag, formName, fldPrefix, ctlList, callback)
{
  var cmdId = 'PCmd' + this.nextCommandId;
  this.nextCommandId++;
  var cmd = 'cmdAddRepoFolder(' + fldPrefix + ')';
  this.SendCommand(cmdId, 'filerepository', webtag, cmd, formName, ctlList, callback);  
}

/**
**  Send an email message.
**  fieldPrefix - All fields that are referenced by this command must have IDs comprised of this prefix, followed by an underscore, followed by the field name.
**  form - form that contains the fields that begin with the fieldPrefix
**/
TempestNS.CommandHandler.EmailSend = function(webtag, fieldPrefix, form, callback)
{
  var cmdId = 'PCmd' + this.nextCommandId;
  this.nextCommandId++;
  var cmd = 'cmdEmailSend(' + fieldPrefix + ')';
  this.SendCommand(cmdId, 'forum', webtag, cmd, form, fieldPrefix+'*', callback);
}
/**
**  Delete a single message.
**  tid - tid of message
**  tsn - tsn of message to delete
**/
TempestNS.CommandHandler.MsgDelete = function(webtag, tid, tsn, callback)
{
  var cmdId = 'PCmd' + this.nextCommandId;
  this.nextCommandId++;
  var cmd = 'cmdMsgDelete(' + tid + ',' + tsn + ')';
  this.SendCommand(cmdId, 'forum', webtag, cmd, null, null, callback);
}
/**
**  Delete a message.
**  msg - The message to delete, formatted as tid.tsn
**/
TempestNS.CommandHandler.ApplyDelete = function(webtag, msg, callback)
{
  var cmdId = 'PCmd' + this.nextCommandId;
  this.nextCommandId++;
  var cmd = 'cmdApplyDelete(' + msg + ')';
  this.SendCommand(cmdId, 'forum', webtag, cmd, null, null, callback);  
}
/**
**  Sets the interest level on a discussion.
**  tid - tid of discussion to set interest level of.
**  newLevel - the interest level to set.  Integer 0, 1, or 2
**/
TempestNS.CommandHandler.SetInterestLevel = function(webtag, tid, newLevel, callback)
{
  var cmdId = 'PCmd' + this.nextCommandId;
  this.nextCommandId++;
  var cmd = 'setInterestLevel('+ tid + ',' + newLevel + ')';
  this.SendCommand(cmdId, 'forum', webtag, cmd, null, null, callback);
}
/**
**  Mark all discussions older than the date specified as read.
**  newestDate - Discussions older than this will be treated as having been read.
**/
TempestNS.CommandHandler.MarkAsRead = function(webtag, newestDate, callback)
{
  var cmdId = 'PCmd' + this.nextCommandId;
  this.nextCommandId++;
  var cmd = 'cmdMarkAsRead(' + newestDate + ')';
  this.SendCommand(cmdId, 'forum', webtag, cmd, null, null, callback);
}
/**
**  Send a Terms-of-Service Violation Report
**  fieldPrefix - All fields that are referenced by this command must have IDs comprised of this prefix, followed by an underscore, followed by the field name.
**  form - form that contains the fields that begin with the fieldPrefix
**/
TempestNS.CommandHandler.SendTOSViolationReport = function(webtag, fieldPrefix, form, callback)
{
  var cmdId = 'PCmd' + this.nextCommandId;
  this.nextCommandId++;
  var cmd = 'cmdSendTOS(' + fieldPrefix + ')';
  this.SendCommand(cmdId, 'forum', webtag, cmd, form, fieldPrefix+'*', callback);
}
/**
**  Send the current message by email to somebody else.  If no template name is specified in the parameters, then a standard format header is prepended to the body, and the template Forum.CCMessage is invoked.
**  fieldPrefix - All fields that are referenced by this command must have IDs comprised of this prefix, followed by an underscore, followed by the field name.
**  templateName - If a template name is specified as the second command argument, a templated email message is generated and sent.  This functionality is then identical to that provided by cmdEmailSend.  All
**  fields with the specified prefix are available in the template as params with the same names (without prefix, of course)
**  form - form that contains the fields that begin with the fieldPrefix
**/
TempestNS.CommandHandler.ForwardMessage = function(webtag, fieldPrefix, templateName, form, callback)
{
  var cmdId = 'PCmd' + this.nextCommandId;
  this.nextCommandId++;
  var cmd = "";
  if(templateName != null) {cmd = 'cmdForward(' + fieldPrefix +',' + templateName + ')'; }
  else { cmd = 'cmdForward(' + fieldPrefix +')'; }
  this.SendCommand(cmdId, 'forum', webtag, cmd, form, fieldPrefix+'*', callback);
}

TempestNS.CommandHandler.SetPresence = function(webtag, fieldPrefix, form, callback)
{
  var cmdId = 'PCmd' + this.nextCommandId;
  this.nextCommandId++;
  var cmd = 'cmdSetPresence(' + fieldPrefix +')';
  this.SendCommand(cmdId, 'forum', webtag, cmd, form, fieldPrefix+'*', callback);
}

/**
**  Casts a vote in a poll
**  fieldPrefix - All fields that are referenced by this command must have IDs comprised of this prefix, followed by an underscore, followed by the field name.
**  form - form that contains the fields that begin with the fieldPrefix
**  fields:  
**    choice - The number of the desired choice (1 thru 25). A choice of 0 means don't enter a vote. A choice of -1 means remove any previous vote.
**    tid - The tid of the poll discussion.
**/
TempestNS.CommandHandler.Vote = function(webtag, fieldPrefix, form, callback)
{
  var cmdId = 'PCmd' + this.nextCommandId;
  this.nextCommandId++;
  var cmd = 'cmdVote(' + fieldPrefix +')';
  this.SendCommand(cmdId, 'forum', webtag, cmd, form, fieldPrefix+'*', callback);
}

/**
**  Creates a new poll.
**  fieldPrefix - All fields that are referenced by this command must have IDs comprised of this prefix, followed by an underscore, followed by the field name.
**  form - form that contains the fields that begin with the fieldPrefix
**  fields:  
**    allowVoteChanges - If true, then users may change their votes after casting them.
**    choice[n] - The text of the poll answers (choices). n can be from 1 to 25.
**    expiration - The number of days until the poll is closed. If -1, then it never closes.
**    folderId - The folderId of the folder where the poll should reside.
**    graphType - if 1 =&gt; vertical, else horiztonal.
**    sendAsHtml - If true, then the question and choices can contain HTML markup.
**    showResults - If true, then users may view the results of the poll before the poll closes.
**    subject - The subject of the poll, i.e. the poll question
**    toScreenName - The screenname of the addressee of the poll. Should be ALL.
**    tid - This is used when editing an existing poll
**/
TempestNS.CommandHandler.NewPoll = function(webtag, fieldPrefix, form, callback)
{
  var cmdId = 'PCmd' + this.nextCommendId;
  this.nextCommandId++;
  var cmd = 'cmdNewPoll(' + fieldPrefix +')';
  this.SendCommand(cmdId, 'forum', webtag, cmd, form, fieldPrefix+'*', callback);
}

/**
**  Ends a current poll
**  fieldPrefix - All fields that are referenced by this command must have IDs comprised of this prefix, followed by an underscore, followed by the field name.
**  form - form that contains the fields that begin with the fieldPrefix
**  fields:  
**    tid - The tid of the poll discussion to be deleted.
**/
TempestNS.CommandHandler.EndPoll = function(webtag, fieldPrefix, form, callback)
{
  var cmdId = 'PCmd' + this.nextCommandId;
  this.nextCommandId++;
  var cmd = 'cmdEndPoll(' + fieldPrefix +')';
  this.SendCommand(cmdId, 'forum', webtag, cmd, form, fieldPrefix+'*', callback); 
}

/**
**  Add a forum or forums to current user's list of favorites.
**  fieldPrefix - All fields that are referenced by this command must have IDs comprised of this prefix, followed by an underscore, followed by the field name.
**  form - form that contains the fields that begin with the fieldPrefix
**  fields:  
**    for check boxes - id = [fieldprefix]_[forumId]  Any checked boxes will be added to list.
**    for list boxes - item values = [forumId]  Any selected items will be added to list.
**/
TempestNS.CommandHandler.SetMyForums = function(webtag, fieldPrefix, form, callback)
{
  var cmdId = 'PCmd' + this.nextCommandId;
  this.nextCommandId++;
  var cmd = 'cmdMyForumsSet(' + fieldPrefix +')';
  this.SendCommand(cmdId, 'forum', webtag, cmd, form, fieldPrefix+'*', callback);
}

/**
**  Remove a forum or forums from current user's list of favorites.
**  fieldPrefix - All fields that are referenced by this command must have IDs comprised of this prefix, followed by an underscore, followed by the field name.
**  form - form that contains the fields that begin with the fieldPrefix
**  fields:  
**    for check boxes - id = [fieldprefix]_[forumId]  Any checked boxes will be removed from list.
**    for list boxes - item values = [forumId]  Any selected items will be removed from list.
**/
TempestNS.CommandHandler.ResetMyForums = function(webtag, fieldPrefix, form, callback)
{
  var cmdId = 'PCmd' + this.nextCommandId;
  this.nextCommandId++;
  var cmd = 'cmdMyForumsReset(' + fieldPrefix +')';
  this.SendCommand(cmdId, 'forum', webtag, cmd, form, fieldPrefix+'*', callback); 
}

TempestNS.CommandHandler.SetRating = function(webtag, fieldPrefix, form, callback)
{
  var cmdId = 'PCmd' + this.nextCommandId;
  this.nextCommandId++;
  var cmd = 'cmdSetRating(' + fieldPrefix +')';
  this.SendCommand(cmdId, 'forum', webtag, cmd, form, fieldPrefix+'*', callback); 
}

/**
**  Various commands to manage a discussion.
**  fieldPrefix - All fields that are referenced by this command must have IDs comprised of this prefix, followed by an underscore, followed by the field name.
**  action - Action describing which manage command to execute.  Possible values: closediscussion, opendiscussion, deletediscussion, changesubject, movetofolder, movetowebtag,
**       prune, graft, transplant, setsticky
**  form - form that contains the fields that begin with the fieldPrefix
**  fields:  
**    tid - the tid of the discussion to be closed. (always required for each action)
**    various other fields, see specific commands from the action values for required fields.  All fields are required for each command unless otherwise specified.
**/
TempestNS.CommandHandler.ManageDiscussion = function(webtag, fieldPrefix, action, form, callback)
{
  var cmdId = 'PCmd' + this.nextCommandId;
  this.nextCommandId++;
  var cmd = 'cmdManageDiscussion('+ fieldPrefix + ',' + action + ')';
  this.SendCommand(cmdId, 'forum', webtag, cmd, form, fieldPrefix+'*', callback); 
}

/**
**  Close a discussion.
**  fieldPrefix - All fields that are referenced by this command must have IDs comprised of this prefix, followed by an underscore, followed by the field name.
**  form - form that contains the fields that begin with the fieldPrefix
**  fields:  
**    tid - the tid of the discussion to be closed.
**/
TempestNS.CommandHandler.CloseDiscussion = function(webtag, fieldPrefix, form, callback)
{
  this.ManageDiscussion(webtag, fieldPrefix, "closediscussion", form, callback);
}

/**
**  Open a discussion.
**  fieldPrefix - All fields that are referenced by this command must have IDs comprised of this prefix, followed by an underscore, followed by the field name.
**  form - form that contains the fields that begin with the fieldPrefix
**  fields:  
**    tid - the tid of the discussion to be opened.
**/
TempestNS.CommandHandler.OpenDiscussion = function(webtag, fieldPrefix, form, callback)
{
  this.ManageDiscussion(webtag, fieldPrefix, "opendiscussion", form, callback);
}

/**
**  Delete a discussion.
**  fieldPrefix - All fields that are referenced by this command must have IDs comprised of this prefix, followed by an underscore, followed by the field name.
**  form - form that contains the fields that begin with the fieldPrefix
**  fields:  
**    tid - the tid of the discussion to be deleted.
**/
TempestNS.CommandHandler.DeleteDiscussion = function(webtag, fieldPrefix, form, callback)
{
  this.ManageDiscussion(webtag, fieldPrefix, "deletediscussion", form, callback);
}

/**
**  Change the subject of a discussion.
**  fieldPrefix - All fields that are referenced by this command must have IDs comprised of this prefix, followed by an underscore, followed by the field name.
**  form - form that contains the fields that begin with the fieldPrefix
**  fields:  
**    tid - the tid of the discussion to have it's subject changed.
**    newSubject - Text of the new subject (should contain no HTML, but will be stripped if there is)
**/
TempestNS.CommandHandler.ChangeSubject = function(webtag, fieldPrefix, form, callback)
{
  this.ManageDiscussion(webtag, fieldPrefix, "changesubject", form, callback);
}

/**
**  Move a discussion or discussions to a new folder.
**  fieldPrefix - All fields that are referenced by this command must have IDs comprised of this prefix, followed by an underscore, followed by the field name.
**  form - form that contains the fields that begin with the fieldPrefix
**  fields:  
**    tid - the tid of the discussion to be moved to a new folder.
**    newFolderId - the folderId of the new folder the discussion(s) are being moved to.
**    discussions - a comma delimited list of tid(s) to move to specified folder.
**/
TempestNS.CommandHandler.MoveToFolder = function(webtag, fieldPrefix, form, callback)
{
  this.ManageDiscussion(webtag, fieldPrefix, "movetofolder", form, callback);
}

/**
**  Move a discussion or all discussions to a new webtag.
**  fieldPrefix - All fields that are referenced by this command must have IDs comprised of this prefix, followed by an underscore, followed by the field name.
**  form - form that contains the fields that begin with the fieldPrefix
**  fields:  
**    tid - the tid of the discussion to be moved to a new webtag.
**    newWebtag - the new webtag to move discussion(s) to.
**    moveAllDiscussions - if true, all the discussions in the original folder will be moved to the new folder location. 
**    newWebtagFolderId - the new webtag's folder the discussion(s) are moving to.
**    linkOriginalDiscussion - if true, then the original discussion will contain a single message displaying a link to the new discussion location. 
**    If it is not checked, the original discussion will be deleted. 
**/
TempestNS.CommandHandler.MoveToWebtag = function(webtag, fieldPrefix, form, callback)
{
  this.ManageDiscussion(webtag, fieldPrefix, "movetowebtag", form, callback);
}

/**
**  Prune a discussion - Remove a message from the discussion specified along with all of its replies and create a new discussion.
**  fieldPrefix - All fields that are referenced by this command must have IDs comprised of this prefix, followed by an underscore, followed by the field name.
**  form - form that contains the fields that begin with the fieldPrefix
**  fields:  
**    tid - the tid of the discussion to be pruned.
**    newSubjectPrune - new subject of the discussion being created
**    tsnPrune - the tsn to start pruning from
**    newFolderIdPrune - the destination folder of the pruned discussion.
**/
TempestNS.CommandHandler.PruneDiscussion = function(webtag, fieldPrefix, form, callback)
{
  this.ManageDiscussion(webtag, fieldPrefix, "prune", form, callback);
}

/**
**  Graft a discussion - Remove a message from the specified discussion along with all of its replies and insert it in another discussion.
**  fieldPrefix - All fields that are referenced by this command must have IDs comprised of this prefix, followed by an underscore, followed by the field name.
**  form - form that contains the fields that begin with the fieldPrefix
**  fields:  
**    tid - the tid of the discussion to be grafted.
**    tsnGraft - the tsn (that has replies) to be inserted into another discussion.
**    destMsgGraft - In the form of tid.tsn.  This should be the message to which the message to be removed(tsnGraft) should be a reply.
**/
TempestNS.CommandHandler.GraftDiscussion = function(webtag, fieldPrefix, form, callback)
{
  this.ManageDiscussion(webtag, fieldPrefix, "graft", form, callback);
}

/**
**  Transplant a discussion - Insert the entire discussion into another discussion.
**  fieldPrefix - All fields that are referenced by this command must have IDs comprised of this prefix, followed by an underscore, followed by the field name.
**  form - form that contains the fields that begin with the fieldPrefix
**  fields:  
**    tid - the tid of the discussion to be transplanted.
**    destMsgTransplant - the tid.tsn to transplant disscussion to. This should be the message to which the first message of this discussion should be a reply.
**/
TempestNS.CommandHandler.TransplantDiscussion = function(webtag, fieldPrefix, form, callback)
{
  this.ManageDiscussion(webtag, fieldPrefix, "transplant", form, callback);
}

/**
**  Set whether a discussion should contain sticky posts (always new or always unread).
**  fieldPrefix - All fields that are referenced by this command must have IDs comprised of this prefix, followed by an underscore, followed by the field name.
**  form - form that contains the fields that begin with the fieldPrefix
**  fields:  
**    tid - the tid of the discussion to be set sticky.
**    alwaysNew - boolean specifying whether or not to set this discussion as always new.
**    alwaysUnread - boolean specifying whether or not to set this discussion as always unread.
**/
TempestNS.CommandHandler.SetSticky = function(webtag, fieldPrefix, form, callback)
{
  this.ManageDiscussion(webtag, fieldPrefix, "setsticky", form, callback);
}

TempestNS.CommandHandler.Post = function(webtag, fieldPrefix, msgType, form, callback)
{
  var cmdId = 'PCmd' + this.nextCommandId;
  this.nextCommandId++;
  var cmd;
  if(msgType != null) { cmd = 'cmdPost('+ fieldPrefix + ',' + msgType + ')'; }
  else { cmd = 'cmdPost(' + fieldPrefix + ')'; }
  this.SendCommand(cmdId, 'forum', webtag, cmd, form, fieldPrefix+'*', callback); 
}

TempestNS.CommandHandler.SetStatusInfo = function(webtag, fieldPrefix, tid, objectStatusId, comment, form, callback)
{
  var cmdId = 'PCmd' + this.nextCommandId;
  this.nextCommandId++;
  if(fieldPrefix != null)
  {
    var cmd = 'cmdSetStatusInfo(' + fieldPrefix + ')'; 
    this.SendCommand(cmdId, 'forum', webtag, cmd, form, fieldPrefix+'*', callback);
  }
  else
  {
    var cmd = 'cmdSetStatusInfo(' + tid + ',' + objectStatusId + ',' + comment + ')'; 
    this.SendCommand(cmdId, 'forum', webtag, cmd, null, null, callback);
  }
}

TempestNS.CommandHandler.ApplyDeleteByForm = function(webtag, fieldPrefix, form, callback)
{
  var cmdId = 'PCmd' + this.nextCommandId;
  this.nextCommandId++;
  var cmd = 'cmdApplyDelete('+ fieldPrefix + ')';
  this.SendCommand(cmdId, 'forum', webtag, cmd, form, fieldPrefix+'*', callback); 
}

TempestNS.CommandHandler.ApplyEdit = function(webtag, fieldPrefix, msgType, form, callback)
{
  var cmdId = 'PCmd' + this.nextCommandId;
  this.nextCommandId++;
  var cmd = 'cmdApplyEdit('+ fieldPrefix + ',' + msgType + ')';
  this.SendCommand(cmdId, 'forum', webtag, cmd, form, fieldPrefix+'*', callback); 
}

TempestNS.CommandHandler.MoveCategories = function(webtag, fieldPrefix, tid, form, callback)
{
  var cmdId = 'PCmd' + this.nextCommandId;
  this.nextCommandId++;
  var cmd = 'cmdMoveCategories('+ fieldPrefix + ',' + tid + ')';
  this.SendCommand(cmdId, 'forum', webtag, cmd, form, fieldPrefix+'*', callback); 
}


TempestNS.CommandHandler.MemberSet = function(webtag, fieldPrefix, userId, form, callback)
{
  var cmdId = 'PCmd' + this.nextCommandId;
  this.nextCommandId++;
  var cmd = 'cmdMemberSet('+ fieldPrefix + ',' + userId + ')';
  this.SendCommand(cmdId, 'forum', webtag, cmd, form, fieldPrefix+'*', callback); 
}

TempestNS.CommandHandler.UploadFile = function(webtag, fieldPrefix, includeUrl, thumbMaxSize, form, callback)
{
  var cmdId = 'PCmd' + this.nextCommandId;
  this.nextCommandId++;
  var cmd = 'cmdUploadFile('+ fieldPrefix + ',' + includeUrl + ',' + thumbMaxSize + ')';
  this.SendCommand(cmdId, 'forum', webtag, cmd, form, fieldPrefix+'*', callback); 
}

TempestNS.CommandHandler.prototype.SendCommand                = TempestNS.CommandHandler.SendCommand;
TempestNS.CommandHandler.prototype.CommandComplete            = TempestNS.CommandHandler.CommandComplete;
TempestNS.CommandHandler.prototype.IgnoreUser                 = TempestNS.CommandHandler.IgnoreUser;
TempestNS.CommandHandler.prototype.AddFriend                  = TempestNS.CommandHandler.AddFriend;
TempestNS.CommandHandler.prototype.ResetRelationship          = TempestNS.CommandHandler.ResetRelationship;
TempestNS.CommandHandler.prototype.SetRelationship            = TempestNS.CommandHandler.SetRelationship;
TempestNS.CommandHandler.prototype.SetMessageRating           = TempestNS.CommandHandler.SetMessageRating;
TempestNS.CommandHandler.prototype.EmailSend                  = TempestNS.CommandHandler.EmailSend;
TempestNS.CommandHandler.prototype.MsgDelete          = TempestNS.CommandHandler.MsgDelete;
TempestNS.CommandHandler.prototype.ApplyDelete                = TempestNS.CommandHandler.ApplyDelete;
TempestNS.CommandHandler.prototype.SetInterestLevel           = TempestNS.CommandHandler.SetInterestLevel;
TempestNS.CommandHandler.prototype.MarkAsRead                 = TempestNS.CommandHandler.MarkAsRead;
TempestNS.CommandHandler.prototype.SendTOSViolationReport     = TempestNS.CommandHandler.SendTOSViolationReport;
TempestNS.CommandHandler.prototype.ForwardMessage             = TempestNS.CommandHandler.ForwardMessage;
TempestNS.CommandHandler.prototype.SetPresence          = TempestNS.CommandHandler.SetPresence;
TempestNS.CommandHandler.prototype.AddFolder                  = TempestNS.CommandHandler.AddFolder;
TempestNS.CommandHandler.prototype.Vote              = TempestNS.CommandHandler.Vote;
TempestNS.CommandHandler.prototype.NewPoll            = TempestNS.CommandHandler.NewPoll;
TempestNS.CommandHandler.prototype.EndPoll            = TempestNS.CommandHandler.EndPoll;
TempestNS.CommandHandler.prototype.SetMyForums          = TempestNS.CommandHandler.SetMyForums;
TempestNS.CommandHandler.prototype.ResetMyForums        = TempestNS.CommandHandler.ResetMyForums;
TempestNS.CommandHandler.prototype.SetRating          = TempestNS.CommandHandler.SetRating;
TempestNS.CommandHandler.prototype.ManageDiscussion        = TempestNS.CommandHandler.ManageDiscussion;
TempestNS.CommandHandler.prototype.CloseDiscussion        = TempestNS.CommandHandler.CloseDiscussion;
TempestNS.CommandHandler.prototype.OpenDiscussion        = TempestNS.CommandHandler.OpenDiscussion;
TempestNS.CommandHandler.prototype.DeleteDiscussion        = TempestNS.CommandHandler.DeleteDiscussion;
TempestNS.CommandHandler.prototype.ChangeSubject        = TempestNS.CommandHandler.ChangeSubject;
TempestNS.CommandHandler.prototype.MoveToFolder          = TempestNS.CommandHandler.MoveToFolder;
TempestNS.CommandHandler.prototype.MoveToWebtag          = TempestNS.CommandHandler.MoveToWebtag;
TempestNS.CommandHandler.prototype.PruneDiscussion        = TempestNS.CommandHandler.PruneDiscussion;
TempestNS.CommandHandler.prototype.GraftDiscussion        = TempestNS.CommandHandler.GraftDiscussion;
TempestNS.CommandHandler.prototype.TransplantDiscussion      = TempestNS.CommandHandler.TransplantDiscussion;
TempestNS.CommandHandler.prototype.SetSticky          = TempestNS.CommandHandler.SetSticky;
TempestNS.CommandHandler.prototype.Post                          = TempestNS.CommandHandler.Post;
TempestNS.CommandHandler.prototype.SetStatusInfo                 = TempestNS.CommandHandler.SetStatusInfo;
TempestNS.CommandHandler.prototype.ApplyDeleteByForm             = TempestNS.CommandHandler.ApplyDeleteByForm;
TempestNS.CommandHandler.prototype.ApplyEdit                     = TempestNS.CommandHandler.ApplyEdit;
TempestNS.CommandHandler.prototype.MoveCategories                = TempestNS.CommandHandler.MoveCategories;
TempestNS.CommandHandler.prototype.MemberSet                     = TempestNS.CommandHandler.MemberSet;
TempestNS.CommandHandler.prototype.UploadFile                    = TempestNS.CommandHandler.UploadFile;

new TempestNS.CommandHandler();


 TempestNS.RegisterScript('Core');TempestNS.RegisterScript('Server');TempestNS.RegisterScript('Client');TempestNS.RegisterScript('CommandHandler');
