/**
 ******************************************************************************
 *
 * Confidential Property of Documentum, Inc.
 * (c) Copyright Documentum, Inc. 2001.
 * All Rights reserved.
 * May not be used without prior written agreement
 * signed by a Documentum corporate officer.
 *
 ******************************************************************************
 *
 * Project        WDK Forms
 * File           trace.js
 * Description    Client Side Tracing
 * Created on     22 May 2001
 * Tab width      3
 *
 ******************************************************************************
 *
 * PVCS Maintained Data
 *
 * Revision       $Revision: 5$ 
 * Modified on    $Date: 11/20/2006 6:32:47 PM$
 *
 * Log at EOF
 * 
 ******************************************************************************
 */


/** The Trace Window */
if (typeof(g_traceWindow) == "undefined")
{
   g_traceWindow = null;
}

// Private
function openTraceWindow()
{
   if (g_traceWindow == null || g_traceWindow.closed == true)
   {
      var xpos = (window.screenLeft ? window.screenLeft : window.screenX) - 50;
      xpos = xpos > 0 ? xpos : 0;
      g_traceWindow = window.open("","trace", "left=" + xpos
         + ",height=480,width=550,status=yes,toolbar=no,menubar=yes,location=no,resizable=yes,scrollbars=yes");
   }
}

function escapeHtmlTags(strHtml)
{
   var str = strHtml;
   if(str)
   {
      try
      {
         str = str.replace(/\</g, "&lt;");
         str = str.replace(/\>/g, "&gt;");
      }
      catch(e)
      {
         str = "Error Parsing HTML";
      }
   }
   return str;
}

function Trace_println(strMessage)
{
   _Trace_println("<span style='white-space : nowrap;font:11px arial'>" + strMessage + "</span><br>");
}

function _Trace_println(strMessage)
{
   openTraceWindow();
   g_traceWindow.document.write(strMessage);
   window.setTimeout(_Trace_scroll, 0);
}

function _Trace_scroll()
{
   g_traceWindow.scrollBy(0, 100);
}

function Trace_dump(obj, reAttrFilter)
{
   if (obj)
   {
      if (typeof obj == 'string')
      {
         Trace_println(escapeHtmlTags(obj));
      }
      else
      {
         _Trace_println("<hr/><table style='white-space : nowrap;font:11px arial'>");

         for ( var attr in obj )
         {
            attr = attr.toString();
            if ( !reAttrFilter || !reAttrFilter.test(attr) )
            {
               var attrStrValue = obj[attr];
               if (attrStrValue)
               {
                  try
                  {
                     attrStrValue = attrStrValue + "";
                  }
                  catch(e)
                  {
                     attrStrValue = "[Object] (string representation not defined)";
                  }
               }
               attrStrValue = escapeHtmlTags(attrStrValue);
               _Trace_println("<tr><td style='background-color:#eeeeee'><b>" + attr + "</b></td><td>" + attrStrValue + "</td></tr>");
            }
         }

         _Trace_println("</table>");
      }
   }
   else
   {
      Trace_println("<span style='color:red'>Object Not Found. Value = " + obj + "</span>");
   }
}

