﻿/**<summary>Default constructor of TempestNS</summary>**/function TempestNS(){}/**<summary></summary><param name=""></param>**/TempestNS.Server={'buildVersion':'5667.142','dbg':'','domain':'forums.businessweek.com','host':'http://forums.businessweek.com'};



/**
 Prospero AWidgets
 Copyright (c) 2007 Prospero Technologies LLC
    
 Prospero AWidgets are dynamic elements of Prospero-served community or social media 
 content embedded in web pages served by Prospero clients or their affilliates. Each Active 
 Widget may use a token  named  "widgetId" to deal with namespacing.  The widgetId is the 
 unique key passed back to the server and is used as a key to reference the Widget in the registry.
**/




/**
 <summary>
  Default constructor of TempestNS.Ajax
 </summary>
 <param name=""></param>
**/
TempestNS.Ajax = function(src, callback, callbackArgs)
{
  /* Create Request Object */
  this.xhr = this.GetXHR();
  this.xhrSrc = src;
  var self = this;
  this.xhr.onreadystatechange = function(){
    if(self.xhr.readyState == 4 && self.xhr.status == 200)
    {
      callback(self.xhr, callbackArgs);
    }
  };
}


/**
 <summary>
  Construct and return an XMLHttpRequest object, based on the browser's capabilities
 </summary>
 <param name=""></param>
**/
TempestNS.Ajax.GetXHR = function()
{
  if(window.XMLHttpRequest)
  {
    try
    {
      return new XMLHttpRequest();
    }
    catch(e)
    {
      return null;
    }
  }
  else if(window.ActiveXObject)
  {
    try
    {
      return new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e)
    {
      try 
      {
              return new ActiveXObject("Microsoft.XMLHTTP");
          } 
      catch(e) 
      {
              return null;
          }
    }
  }
}


/**
 <summary>
  
 </summary>
 <param name=""></param>
**/
TempestNS.Ajax.Open = function(action)
{
  if(action == "post")
  {
    this.xhr.open("POST", this.xhrSrc, true);
    this.xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 
  }
}


/**
 <summary>
  
 </summary>
 <param name=""></param>
**/
TempestNS.Ajax.Send = function(params)
{
  this.xhrParams = params;
  this.xhr.send(this.xhrParams);
}


TempestNS.Ajax.prototype     = new Object();
TempestNS.Ajax.prototype.GetXHR = TempestNS.Ajax.GetXHR;
TempestNS.Ajax.prototype.Open   = TempestNS.Ajax.Open;
TempestNS.Ajax.prototype.Send   = TempestNS.Ajax.Send;


 

/**
 <summary>
  Default constructor of TempestNS.Client
 </summary>
 <param name=""></param>
**/
TempestNS.Client = function()
{
  
}


/**
 <summary>
  
 </summary>
 <param name=""></param>
**/
TempestNS.Client.IncludeScript = function(scriptUrl)
{
   var headElm = document.getElementsByTagName('head')[0];
   var scriptElm = document.createElement('script');
   scriptElm.setAttribute('type','text/javascript');
   scriptElm.setAttribute('src',scriptUrl);
   headElm.appendChild(scriptElm);
}


/**
 <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 */
      }
    }
    case "radio":
    {
      if(!ctl.checked)
      {
        return null;  /* nothing should be posted back */
      }
    }
    case "select-one":
    {
      return ctl.options[ctl.selectedIndex].value;
    }
  }
  return ctl.value;
}


/**
 <summary>
  Returns the coordinates of an element relative to the page
 </summary>
 <param name=""></param>
**/
TempestNS.Client.GetElementPosition = function(elm)
{
  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>
  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>
  Default Constructor for TempestNS.WidgetManager Object
 </summary>
**/
TempestNS.WidgetManager = function()
{
  /* If one already exists then use it */
  if(TempestNS.WIDGETMANAGER)
  {
    return;
  }
  /* Otherwise, create new global PT_WIDGET_MAN */
  TempestNS.WIDGETMANAGER = this;
  /* Create a object to hold all the Widgets that PT_WIDGET_MAN is managing */
  this.Widgets = new Object();
  /* An object to hold the possible Prospero Apps */
  this.Apps = {
    "forum" : "/n/pfx/forum.aspx"
    }
  /* Count of widgets in TempestNS.WidgetMan */
  this.elementCount = 0;
  /* Id of the DOM Poll for Safari and Opera */
  this.pollId = 0;
  /* Flag to test if the DOM is ready */
  this.domComplete = false;  
  /* If Safari and Opera, implement DOM Polling */
  if(document.addEventListener && document.readyState)
  {
    this.StartPolling();
  }
  /* Add listeners to window.document or window */
  this.Initialize();  
}


/**
 <summary>
  Create a setInterval to run loadWidgets() every 1 second
 </summary>
**/
TempestNS.WidgetManager.StartPolling = function() 
{
  if(this.pollId) 
  {
    return;
  }
  this.pollId = setInterval(function(){ TempestNS.WIDGETMANAGER.LoadWidgets(); }, 1000);
}


/**
 <summary>
  Clear an interval that matches the pollId
 </summary>
**/
TempestNS.WidgetManager.StopPolling = function() 
{
  if(!this.pollId) 
  {
    return;
  }
  clearInterval(this.pollId);
  this.pollId = null;
}


/**
 <summary>
  Add listeners to window.document or to the window itself.
  Once the DOM is ready, stop polling and run loadWidgets one last time.
 </summary>
**/
TempestNS.WidgetManager.Initialize = function()
{
  /* Fire the following function when the DOM is ready */
  var callBack = function(){
    /* If listening to OnReadyState */
    if(document.readyState) 
    {
      /* Only run the following when the DOM is ready */
      if(document.readyState == 'complete')
      {
        TempestNS.WIDGETMANAGER.domComplete = true; 
        TempestNS.WIDGETMANAGER.LoadWidgets();
      }
    }
    else 
    {
      TempestNS.WIDGETMANAGER.domComplete = true; 
      TempestNS.WIDGETMANAGER.LoadWidgets();
    }
  }
  
  /* If browser supports W3C Recommended event listener */
  if(document.addEventListener)
  {
    /* If Opera, and Safari, listen to OnReadyState */
    if(document.readyState) 
    {
      document.addEventListener("onreadystatechange", callBack, false);
    }
    /* Else Firefox, listen to DOMContentLoaded */
    else
    {
      document.addEventListener("DOMContentLoaded", callBack, false);
    }
  }
  /* Else the browser supports IE event listener */
  else if(document.attachEvent) 
  {
    /* Listen to OnReadyState */
    document.attachEvent("onreadystatechange", callBack);
  }
  /* Else widgets won't work on older browsers */
  else
  {
    /* window.onload = callBack; */
  }
}
  

/**
 <summary>
  Scan document for <paw:widget/> tags, and call their .Load() function
 </summary>
**/
TempestNS.WidgetManager.LoadWidgets = function()
{
  /* Scan for all widgets and kick off each */
  var elements = document.getElementsByTagName("paw:widget");
  for(var i = 0; i < elements.length; i++)
  {
    /* Create new Widget Object */
    var cModule = new TempestNS.Widget(elements[i]);
    /* If it doesn't exist */
    if(!this.Widgets[cModule.widgetId])
    {
      /* Add it to the Widget_Man Registry */
      this.Widgets[cModule.widgetId] = cModule;
      /* Increment count */
      this.elementCount++;
      /* Load Widget onto the page */
      cModule.Load();
    }
  }
  
  /* If the DOM is ready, stop DOM Polling */
  if(this.domComplete)
  {  
    this.StopPolling();
  }
}


/**
 <summary>
  Create a new src to pass to the widget's update function
 </summary>
 <param name="widgetId">Id of the widget in the Widget_Man</param>
 <param name="uri">Parameters to add to the query string</param>
 <param name="scrollId">Optional: Id of the element on the page to scroll to</param>
**/
TempestNS.WidgetManager.UpdateContent = function(widgetId, uri, scrollId)
{
  if(this.Widgets[widgetId])
  {
    this.Widgets[widgetId].Update(TempestNS.Server.host + uri, scrollId);
  }
}


/**
 <summary>
  Set the content to appear in the widget
 </summary>
 <param name="widgetId">Id of the widget in the Widget_Man</param>
 <param name="sContent">New HTML to replace old content</param>
**/
TempestNS.WidgetManager.SetContent = function(widgetId, sContent)
{
    if(this.Widgets[widgetId])
    {
        this.Widgets[widgetId].SetContent(sContent);
    }
}


/**
 <summary>
  Given a hostString, return the root domain
 </summary>
**/
TempestNS.WidgetManager.GetRootDomain = function(hostString)
{
    var hostArray = hostString.split(".");
    var rootDomain = "";
    if(hostArray.length > 3)
    { 
        rootDomain = hostArray[hostArray.length-3] + "." + hostArray[hostArray.length-2] + "." + hostArray[hostArray.length-1];
    }
    else if(hostArray.length > 2)
    {
        rootDomain = hostArray[hostArray.length-2] + "." + hostArray[hostArray.length-1];
    }
  else
  {
    rootDomain = hostString;
  }
    return rootDomain; 
}


/**
 <summary>
  Determine if the request is coming from {0: External Domain, 1: Same Domain, 2: Same Host}
 </summary>
**/
TempestNS.WidgetManager.GetEnvironment = function()
{
  /* If from Same Host, return 2 */
  if(TempestNS.Server.domain == window.location.host)
  {
    return 2;
  }
  /* Otherwise, see if it is from the Same Domain */
  else 
  { 
    /* Get and parse the domain of the current page */
    var pageDomain = window.location.host.split('\.');
    /* Parse the server domain */
    var serverDomain = TempestNS.Server.domain.split('\.');
    /* If there is a match, return 1 */
    for(i = 0; i < pageDomain.length - 1; i++)
    {
      for(j = 0; j < serverDomain.length - 1; j++)
      {
        if(pageDomain[i] == serverDomain[j] && pageDomain[i] != "www")
        {
          return 1;
        }
      }
    }
    /* Otherwise, it must be an External Domain and return 0 */
    return 0;
  }
}


/**
 <summary>
  
 </summary>
**/
TempestNS.WidgetManager.SubmitTalkback = function(widgetId, prefix)
{
  if(this.Widgets[widgetId])
  {
    var postBox = document.getElementById(prefix + "_body");
    if(postBox.value != "")
    {
      this.Widgets[widgetId].PostMessageShow("Submitting your comment...", "ptcPostMessageBefore");
      var myEnvironment = this.GetEnvironment();
      switch(myEnvironment)
      {
        case 0:
        {
          this.Widgets[widgetId].SubmitTalkbackJSS(prefix);
          break;
        }
        case 1:
        {
          this.Widgets[widgetId].SubmitTalkbackIFrame(prefix);
          break;
        }
        case 2:
        {
          this.Widgets[widgetId].SubmitTalkbackXHR(prefix);
          break;
        }
      }
    }
    else
    {
      var self = this.Widgets[widgetId];
      self.PostMessageShow("The comment box is empty.  Please enter your comments in the space provided.", "ptcPostMessageError");
          setTimeout(function(){ self.PostMessageHide(); }, 5000);
    }
  }
}
    


TempestNS.WidgetManager.prototype           = new Object();
TempestNS.WidgetManager.prototype.Initialize    = TempestNS.WidgetManager.Initialize;
TempestNS.WidgetManager.prototype.LoadWidgets     = TempestNS.WidgetManager.LoadWidgets;
TempestNS.WidgetManager.prototype.SetContent    = TempestNS.WidgetManager.SetContent;
TempestNS.WidgetManager.prototype.StartPolling     = TempestNS.WidgetManager.StartPolling;
TempestNS.WidgetManager.prototype.StopPolling     = TempestNS.WidgetManager.StopPolling
TempestNS.WidgetManager.prototype.UpdateContent   = TempestNS.WidgetManager.UpdateContent;
TempestNS.WidgetManager.prototype.GetRootDomain    = TempestNS.WidgetManager.GetRootDomain;
TempestNS.WidgetManager.prototype.GetEnvironment  = TempestNS.WidgetManager.GetEnvironment;
TempestNS.WidgetManager.prototype.SubmitTalkback  = TempestNS.WidgetManager.SubmitTalkback;



/**
 <summary>
  Create Widget Object
 </summary>
 <param name="Element">Pointer to the DOM element holding the widget - <paw:widget/></param>
**/
TempestNS.Widget = function(Element)
{
  /* Set Object properties */
  this.element = Element;
  this.canvas = null;
  this.script = null;
  /* Set a flag to make sure only one request at a time is made to the server */
  this.callingProspero = false;
  
  /* Get parameters passed from <paw:widget/> */
  /* Currently only webtag is mandatory */
  this.app = this.element.getAttribute("app");
  if(!this.app || this.app == "")
  {
    /* Current default is forum*/
    this.app = "forum"; 
  }
  this.args = this.element.getAttribute("args");
  this.config = this.element.getAttribute("config");
  this.plan = this.element.getAttribute("plan");
  /* If a unique id for a preload message is supplied by the customer, hide it when the widget content is loaded */
  if(this.element.getAttribute("preloadid"))
  {
    this.preloadId = this.element.getAttribute("preloadid");
  }
  /* Otherwise, pass id of old preloader for backwards compatability */
  else
  {
    this.preloadId = "ptcloading";
  }
  this.type = this.element.getAttribute("type");
  this.webtag = this.element.getAttribute("webtag");
  /* If a unique key is supplied by the customer, use it to create the widgetId */
  if(this.element.getAttribute("key"))
  {
    this.widgetId = TempestNS.Widget.Prefix + this.element.getAttribute("key");
  }
  /* Otherwise, use the elementCount of the Widget_Man Registry */
  else
  {
    this.widgetId = TempestNS.Widget.Prefix + TempestNS.WIDGETMANAGER.elementCount;
  }
}


/**
 <summary>
  Create a new src to pass to the widget's update function
 </summary>
**/
TempestNS.Widget.Load = function()
{
  /* Start src variable with the current host and mandatory parameters */
  this.scriptSrc = TempestNS.Server.host;
  this.scriptSrc += TempestNS.WIDGETMANAGER.Apps[this.app];
  this.scriptSrc += "?webtag=" + this.webtag;
  this.scriptSrc += "&widgetId="+ this.widgetId;
  this.scriptSrc += "&includeCSS=false";
  if(this.plan && this.plan != "")
  {
    this.scriptSrc += "&pttv=2&nav=" + this.plan; /* initial implementation of T2V2 */
  }
  else
  {
    this.scriptSrc += "&nav=jsscontent";  /* V1 */
  }
  this.scriptSrc += "&cache=n";
  /* If args exists, append it to the src variable */
  if(this.args && this.args != "")
  {
    /* Remove any semicolons */
    this.args = this.args.replace(/\%3[Bb]/g,'%20');
    this.scriptSrc += "&args=" + this.args;
  }
  /* If config exists, append it to the src variable */
  if(this.config && this.config != "")
  {
    this.scriptSrc += "&config=" + this.config;
  }
  /* If type exists, append it to the src variable */
  if(this.type && this.type != "")
  {
    this.scriptSrc += "&type=" + this.type;
  }
  /* If the debug flag has been set, add it to the src */
  if(TempestNS.Server.dbg)
  {
    this.scriptSrc += "&dbg=" + TempestNS.Server.dbg;
  }
  /* Call widget's Update function */
  this.Update(this.scriptSrc);
}


/**
 <summary>
  Add new <script> to the body of the document
 </summary>
**/
TempestNS.Widget.Update = function(src, scrollId)
{
  /* If you haven't already appended the new script */
  if(this.callingProspero != true)
  {
    /* Make sure no other requests is made for this widget until the current one is finished */
    this.callingProspero = true;
    /* Remove previously used script */ 
    if(this.script)
    {
      document.body.removeChild(this.script);
      this.script = null;
    }
    /* Add time stamp and set cache to n */
    src += "&dst="+escape(new Date().toString());
    /* Create new <script/> */
    this.script = document.createElement("script");
    this.script.setAttribute("src", src);
    /* Append <script/> to the <body/> */
    document.body.appendChild(this.script);
    /* Set Scroll Id */
    this.scrollId = scrollId;
  }
} 


/**
 <summary>
  Replace old content with new content returned from Prospero
 </summary>
**/
TempestNS.Widget.SetContent = function(sContent)
{
  /* If there is a <paw:widget/> or <div/> containing a widget */
  if(this.element)
  {
    /* Find its parent */
    var pawParent;
    if(this.element.parentNode)
    {
      pawParent = this.element.parentNode;
    }
    /* Once you have located its parent */
    if(pawParent)
    {
      /* If the <paw:widget/> has not been replaced */
      if(!this.canvas )
      {
        /* If the customer created a preload message, hide it */
        if(this.preloadId)
        {
          var preLoadingMessage = document.getElementById(this.preloadId);
          if(preLoadingMessage)
          {
            preLoadingMessage.style.display = "none";
          }
        }
        /* Create a new <div/> to hold widget content */
        this.canvas = document.createElement("div");
        /* Assign it a class and id */
        this.canvas.className = "ptcWidgetParent";
        this.canvas.id = this.widgetId;
        /* Replace <paw:widet/> node with the new <div/> */
        pawParent.replaceChild(this.canvas, this.element);
        /* Set this.element to the new <div/> */
        this.element = this.canvas;
      }
      /* Replace old content */
      this.canvas.innerHTML = sContent;
      /* Allow new calls to Prospero to occur by this widget */
      this.callingProspero = false;
      /* Move page to an elementId if one is supplied */
      TempestNS.Client.ScrollToId(this.scrollId);
    }
  }
}


/**
 <summary>
  Set error message and diplay it onscreen
 </summary>
 <param name="msg">the message to be displayed</param>
**/
TempestNS.Widget.SetError = function(msg)
{
    this._errorMessage = msg;
    alert(this._errorMessage);
}


/**
 <summary>
  
 </summary>
 <param name=""></param>
**/
TempestNS.Widget.Refresh = function()
{
  this.Update(this.scriptSrc);
}


/**
 <summary>
  
 </summary>
 <param name=""></param>
**/  
TempestNS.Widget.SubmitTalkback_AddUrlParam = function(prefix, elmId, encode)
{
  var ctl = document.getElementById(prefix + "_" + elmId);
  if(ctl) 
  {
    if(encode)
    {
      return "&" + elmId + "=" + escape(ctl.value);
    }
    else
    {
      return "&" + elmId + "=" + ctl.value;
    }
  }
  else 
  {
    return "";
  }
}


/**
 <summary>
  
 </summary>
 <param name=""></param>
**/    
TempestNS.Widget.SubmitTalkback_SetPostParams = function(prefix)
{
  var postParams = "";
  postParams += this.AddUrlParam(prefix,"folderId",false);
  postParams += this.AddUrlParam(prefix,"tid",false);
  postParams += this.AddUrlParam(prefix,"toUserId",false);
  postParams += this.AddUrlParam(prefix,"subject",true);
  postParams += this.AddUrlParam(prefix,"contentId",false);
  postParams += this.AddUrlParam(prefix,"contentUrl",true);
  postParams += this.AddUrlParam(prefix,"signature",true);
  postParams += this.AddUrlParam(prefix,"body",true);
  return postParams;
  /* Don't use for Ajax Post
  postParams += this.AddUrlParam(prefix,"returnUrl",true);
  postParams += this.AddUrlParam(prefix,"errorUrl",true);
  */
}


/**
 <summary>
  
 </summary>
 <param name=""></param>
**/    
TempestNS.Widget.SubmitTalkback_JSS = function(prefix)
{
  /*alert("Using JSS for SubmitTalkback for " + prefix);*/
  var newUrl = TempestNS.Server.host; 
  newUrl += "/dir-app/acx/ACPost.aspx?returnStatus=y&webtag="+ this.webtag + "&widgetPost=y";
  newUrl += "&jss=y&curPage="+ escape(window.location.href) +"&widgetId="+ this.widgetId; 
  newUrl += this.SetPostParams(prefix);
  //this.Update(newUrl);
TempestNS.Client.IncludeScript(newUrl);
this.PostResult(newUrl);
}


/**
 <summary>
  
 </summary>
 <param name=""></param>
**/    
TempestNS.Widget.SubmitTalkback_XHR = function(prefix)
{
  /*alert("Using XHR Request for SubmitTalkback for " + prefix); */
  var src = TempestNS.Server.host + "/dir-app/acx/ACPost.aspx?webtag=" + this.webtag + "&widgetPost=y";
  var callback = TempestNS.WIDGETMANAGER.Widgets[this.widgetId].PostComplete;
  var xhr = new TempestNS.Ajax(src, callback);
  xhr.Open("post");
  this.postParams = "&curPage="+ escape(window.location.href) +"&widgetId="+ this.widgetId; 
  this.postParams += this.SetPostParams(prefix);   
  xhr.Send(this.postParams);
}
 

/**
 <summary>
  
 </summary>
 <param name=""></param>
**/    
TempestNS.Widget.SubmitTalkback_IFrame = function(prefix)
{
  /*alert("Using IFrame Request for SubmitTalkback for " + prefix);*/
  /* Set Domain */
  this.originalDomain = document.domain;
  document.domain = TempestNS.WIDGETMANAGER.GetRootDomain(window.location.host);
  /* Get Params */
  this.postPrefix = prefix;
  this.postParams = "&curPage=" + escape(window.location.href) +"&widgetId="+ this.widgetId; 
  this.postParams += this.SetPostParams(prefix);
  /* Create iFrame */
  this.iFrame = document.createElement('iframe');
  this.iFrame.id = "ptcSubmitTalkbackIframe";  
  var iFrameSrc = TempestNS.Server.host + TempestNS.WIDGETMANAGER.Apps[this.app];
  iFrameSrc += "?webtag=" + this.webtag + "&nav=iframe&template=ActiveWidgetsBridge";
  iFrameSrc += "&widgetId=" + this.widgetId +"&parentDomain="+ document.domain;
  if(TempestNS.Server.dbg)
  {
    iFrameSrc += "&dbg=" + TempestNS.Server.dbg;
    this.iFrame.style.height = "200px";
    this.iFrame.style.width = "800px";
    this.iFrame.style.border = "2px solid #FF9900";
  }
  else
  {
    this.iFrame.style.height = "0px";
    this.iFrame.style.width = "0px";
    this.iFrame.style.visibility = "hidden";
  }
  this.iFrame.setAttribute('src',iFrameSrc);
  this.element.appendChild(this.iFrame);
}


/**
 <summary>
  
 </summary>
 <param name=""></param>
**/  
TempestNS.Widget.SubmitTalkback_PostResult = function(xhr)
{
  var self = this;
  var resultTime = 5000;
  try
  {
    /* See if the browser can read responseXML */
    if(xhr.responseXML.hasChildNodes())
    {
      var response = xhr.responseXML;
    }
  }
  catch(e)
  {
    /* Otherwise, place responseText into a div and refer to it below */
    var xmlDiv = document.createElement("div");
    xmlDiv.id = "ptcWidgetXML";
    xmlDiv.style.height = "0px";
    xmlDiv.style.width = "0px";
    xmlDiv.style.visibility = "hidden";
    xmlDiv.innerHTML = xhr.responseText;
    this.element.appendChild(xmlDiv);
    var response = document.getElementById("ptcWidgetXML");
  }
  /* Depending upon the response, show a message for resultTime seconds and perform the related action */
  var status = response.getElementsByTagName("status")[0].firstChild.nodeValue;
  switch(status)
  {
    case "ok":
    {
      self.PostMessageShow("Thank you.  Your comment will apppear shortly.", "ptcPostMessageAfter");
      setTimeout(function(){ self.PostMessageHide(); self.Refresh(); }, resultTime);
      break;
    }
    case "login":
    {
      try
      {
        var loginUrl = response.getElementsByTagName("loginUrl")[0].firstChild.nodeValue;
      }
      catch(e)
      {
        var responseArray = response.innerHTML.split(">");
        var loginArray = responseArray[4].split("<");
        var loginUrlEncoded = loginArray[0];
  var loginUrl = loginUrlEncoded.replace(/\&amp;/g,"&");
      }
      self.PostMessageShow("You will need to login before your submission will appear.  You will be redirected to the login page shortly.", "ptcPostMessageAfter");
      setTimeout(function(){ self.PostMessageHide(); window.location.replace(loginUrl); }, resultTime);
      break;
    }
    case "exception":
    {
      var message = response.getElementsByTagName("message")[0].firstChild.nodeValue;
      self.PostMessageShow("Sorry.  There was an issue with your submission.  Error: "+ message, "ptcPostMessageError");
      setTimeout(function(){ self.PostMessageHide(); }, resultTime);
      break;
    }
  }
  self.PostComplete(xhr);
}


/**
 <summary>
  
 </summary>
 <param name=""></param>
**/    
TempestNS.Widget.SubmitTalkback_PostComplete = function(xhr)
{
  /* Testing */
  if(TempestNS.Server.dbg)
  {
    var myResults = document.createElement('div');
    myResults.id = "ptcXMLResults";
    myResults.style.height = "200px";
    myResults.style.width = "800px";
    myResults.style.border = "2px solid #336699";
    myResults.innerHTML = "<p>Status: "+ xhr.status +"</p><p>Response: "+ xhr.responseText +"</p><p>Headers: "+ xhr.getAllResponseHeaders() +"</p>";
    this.element.appendChild(myResults);
  }
  if(this.iFrame)
  {
    var oldFrame = document.getElementById("ptcSubmitTalkbackIframe");
    this.element.removeChild(oldFrame);
    this.iFrame = null;
    this.postPrefix = null;
    this.postParams = null;
  }
  
  /* This causes issues in all browsers for repeat posting
  try
  {
    document.domain = this.originalDomain;
  }
  catch(e)
  {
    alert(e);
  }
  */
}



/**
 <summary>
  
 </summary>
 <param name=""></param>
**/
TempestNS.Widget.SubmitTalkback_PostMessageShow = function(resultInfo, className)
{
  /* if one is open, close it */
  this.PostMessageHide(); 
  /* create a 2 new DIVs, copy the content from the ajax request into the inner div */ 
  this.postMessage = document.createElement("div");
  this.postMessage.id = "ptcPostMessage";
  this.postMessage.className = className;
  this.postMessage.style.position = "absolute";
  var widgetPos = TempestNS.Client.GetElementPosition(this.canvas);
  this.postMessage.style.top = (widgetPos.absTop + 20) + "px";
  this.postMessage.style.left = (widgetPos.left + 20) + "px";
  var postMessageText = document.createElement("div");
  postMessageText.className = "ptcPostMessageText";
  postMessageText.innerHTML = resultInfo;
  /* attach it to the document */
  this.postMessage.appendChild(postMessageText);
  this.canvas.appendChild(this.postMessage);
}


/**
 <summary>
  
 </summary>
 <param name=""></param>
**/
TempestNS.Widget.SubmitTalkback_PostMessageHide = function()
{
  if(this.postMessage)
  {
    this.postMessage.parentNode.removeChild(this.postMessage);
    this.postMessage = null;
  }
}


TempestNS.Widget.prototype             = new Object();
TempestNS.Widget.prototype.Load              = TempestNS.Widget.Load;
TempestNS.Widget.prototype.Update         = TempestNS.Widget.Update;
TempestNS.Widget.prototype.SetContent       = TempestNS.Widget.SetContent;
TempestNS.Widget.prototype.SetError        = TempestNS.Widget.SetError;
TempestNS.Widget.prototype.Refresh        = TempestNS.Widget.Refresh;
TempestNS.Widget.prototype.AddUrlParam       = TempestNS.Widget.SubmitTalkback_AddUrlParam;
TempestNS.Widget.prototype.SetPostParams     = TempestNS.Widget.SubmitTalkback_SetPostParams;
TempestNS.Widget.prototype.SubmitTalkbackJSS   = TempestNS.Widget.SubmitTalkback_JSS;
TempestNS.Widget.prototype.SubmitTalkbackXHR   = TempestNS.Widget.SubmitTalkback_XHR;
TempestNS.Widget.prototype.SubmitTalkbackIFrame = TempestNS.Widget.SubmitTalkback_IFrame;
TempestNS.Widget.prototype.PostResult       = TempestNS.Widget.SubmitTalkback_PostResult;
TempestNS.Widget.prototype.PostComplete     = TempestNS.Widget.SubmitTalkback_PostComplete;
TempestNS.Widget.prototype.PostMessageShow     = TempestNS.Widget.SubmitTalkback_PostMessageShow;
TempestNS.Widget.prototype.PostMessageHide     = TempestNS.Widget.SubmitTalkback_PostMessageHide;
TempestNS.Widget.Prefix  = "PTWidget";
TempestNS.Widget.Rev  = 1;


/** 
 Create the singleton global object window.TempestNS.WIDGETMANAGER which 
 does all the work of module creation registration and execution.
**/
new TempestNS.WidgetManager();
var PT_WIDGET_MAN = null; /* Don't use version 0.9 */ 


 