/*
   Make the overlay block visible.
   The block id is "overlay" + xxx. Find the block on the page.
   If it exists make it visible.
*/
function ShowOverlay( which )
{
   var ovl = document.getElementById( "overlay" + which );
   if (ovl != null)
{
      ovl.style.display = "block";
//      ovl.style.visibility = "visible";
}
}

/*
   Make the overlay block invisible.
   The block id is "overlay" + xxx. Find the block on the page.
   If it exists make it invisible.
*/
function HideOverlay( which )
{
   var ovl = document.getElementById( "overlay" + which );
   if (ovl != null)
{
      ovl.style.display = "none";
//      ovl.style.visibility = "hidden";
}
}

/*
   Set the location to display the tooltip block.
   Need to use cookies to store the text from xml because Firefox has problems accessing the event object.
   Find the header block & set the text.
   Find the body block & set the text.
*/   
function SetLocation( e )
{
   var evt = e || window.event;
   var targ;
   if (evt.target)
      targ = evt.target;
	else if (evt.srcElement)
      targ = evt.srcElement;
	if (targ.nodeType == 3) // defeat Safari bug
		targ = targ.parentNode;

   var   sId = targ.id.substring( 3 );

   var ttid = document.getElementById( "tooltipid" );

   if (ttid != null)
   {
      ttid.innerHTML = sId;
   }

   var tttext = document.getElementById( "tooltiptext" );

   if (tttext != null)
   {
      tttext.innerHTML = getCookie(sId);
   }

   var ovl = document.getElementById( "overlaytooltip" );
   if (ovl != null)
   {
      ovl.style.left = (evt.clientX + document.documentElement.scrollLeft + 10) + "px";
      ovl.style.top = (evt.clientY + document.documentElement.scrollTop + 10) + "px";

      ovl.style.display = "block";
   }

};

/* DOM Overlay /////////////////////////////////////// */

function loadjs()
{
/* Event Handlers attached thru DOM rather than directly scripted inline */

/* Menu navigation  */
   document.getElementById( "menu_plan" ).onmouseover = function()
   {
      ShowOverlay( "plan" );
   }

   document.getElementById( "menu_plan" ).onmouseout = function()
   {
      HideOverlay( "plan" );
   }

   document.getElementById( "menu_prepare" ).onmouseover = function()
   {
      ShowOverlay( "prepare" );
   }

   document.getElementById( "menu_prepare" ).onmouseout = function()
   {
      HideOverlay( "prepare" );
   }

   document.getElementById( "menu_gethelp" ).onmouseover = function()
   {
      ShowOverlay( "gethelp" );
   }

   document.getElementById( "menu_gethelp" ).onmouseout = function()
   {
      HideOverlay( "gethelp" );
   }

   document.getElementById( "menu_manage" ).onmouseover = function()
   {
      ShowOverlay( "manage" );
   }

   document.getElementById( "menu_manage" ).onmouseout = function()
   {
      HideOverlay( "manage" );
   }

   document.getElementById( "menu_bankrupt" ).onmouseover = function()
   {
      ShowOverlay( "bankrupt" );
   }

   document.getElementById( "menu_bankrupt" ).onmouseout = function()
   {
      HideOverlay( "bankrupt" );
   }

/* Overlay  */
   document.getElementById( "overlayplan" ).onmouseleave = function()
   {
      HideOverlay( "plan" );
   }

   document.getElementById( "overlayplan" ).onmouseout = function()
   {
      HideOverlay( "plan" );
   }

   document.getElementById( "overlayplan" ).onmousemove = function()
   {
      ShowOverlay( "plan" );
   }

   document.getElementById( "overlayprepare" ).onmouseleave = function()
   {
      HideOverlay( "prepare" );
   }

   document.getElementById( "overlayprepare" ).onmouseout = function()
   {
      HideOverlay( "prepare" );
   }

   document.getElementById( "overlayprepare" ).onmousemove = function()
   {
      ShowOverlay( "prepare" );
   }

   document.getElementById( "overlaygethelp" ).onmouseleave = function()
   {
      HideOverlay( "gethelp" );
   }

   document.getElementById( "overlaygethelp" ).onmouseout = function()
   {
      HideOverlay( "gethelp" );
   }

   document.getElementById( "overlaygethelp" ).onmousemove = function()
   {
      ShowOverlay( "gethelp" );
   }

   document.getElementById( "overlaymanage" ).onmouseleave = function()
   {
      HideOverlay( "manage" );
   }

   document.getElementById( "overlaymanage" ).onmouseout = function()
   {
      HideOverlay( "manage" );
   }

   document.getElementById( "overlaymanage" ).onmousemove = function()
   {
      ShowOverlay( "manage" );
   }

   document.getElementById( "overlaybankrupt" ).onmouseleave = function()
   {
      HideOverlay( "bankrupt" );
   }

   document.getElementById( "overlaybankrupt" ).onmouseout = function()
   {
      HideOverlay( "bankrupt" );
   }

   document.getElementById( "overlaybankrupt" ).onmousemove = function()
   {
      ShowOverlay( "bankrupt" );
   }

};

/* PreLoad Script /////////////////////////////////////////////////////////// */


var   xmlhttp = GetXmlHttpObject();

function GetXmlHttpObject()
{
   if (window.XMLHttpRequest)
   {
  // code for IE7+, Firefox, Chrome, Opera, Safari
      return new XMLHttpRequest();
   }
   if (window.ActiveXObject)
   {
  // code for IE6, IE5
      return new ActiveXObject("Microsoft.XMLHTTP");
   }
   return null;
}

function ReadXml()
{
   xmlhttp = GetXmlHttpObject();

   if (xmlhttp != null)
   {
      xmlhttp.onreadystatechange=stateChanged;
      xmlhttp.open( "GET", "/idc/groups/ucm_ecmc/@ecmc_web/documents/native/def.xml", true );
      xmlhttp.send( null );
   }
}

function stateChanged()
{
   if (xmlhttp.readyState == 4)
   {
      var re = new RegExp( /<(\S+).*>(.*)<\/\1>/gi  );

      var   ar = xmlhttp.responseText.match( re );
  
      for (var i = 0; i < ar.length; i++)
      {
         var   reId = new RegExp( /<id>(.*)<\/id>/i );
         var   reText = new RegExp( /<text>(.*)<\/text>/i );
         var   bMatch1 = ar[i].match( reId );

         if (bMatch1[1] != null)
         {
            var bMatch2 = ar[++i].match( reText );

            if (bMatch2[1] != null)
            {
               var   sId = "tt_" + bMatch1[1];

               setCookie(bMatch1[1],bMatch2[1],1);
               var   tid = document.getElementById( sId );

               if (tid != null)
               {
                  addEvent( tid, 'mouseover', SetLocation );

                  tid.onmouseout = function()
                  {
                     HideOverlay( "tooltip" );
                  }
               }
            }
         }
      }
   }
}

function addEvent(obj, evType, fn)
{ 
//alert("in addEvent");
   if (obj.addEventListener)
   { 
//alert(fn);
      obj.addEventListener(evType, fn, false); 

      return true; 
   }
   else if (obj.attachEvent)
   { 
      var r = obj.attachEvent("on"+evType, fn); 
      return r; 
   }
   else
   { 
      return false; 
   } 
};
 
 
 
/* Table Row Script ////////////////////////////// */
    function ChangeGreyColor(tableRow, highLight)
    {
    if (highLight)
    {
      tableRow.style.backgroundColor = '#fcf3cb';



    }
    else
    {
      tableRow.style.backgroundColor = '#f3f2f1';
    }
  }
  
      function ChangeWhiteColor(tableRow, highLight)
    {
    if (highLight)
    {
      tableRow.style.backgroundColor = '#fcf3cb';




    }
    else
    {
      tableRow.style.backgroundColor = '#fff';
    }
  }


  function DoNav(theUrl)
  {
  document.location.href = theUrl;
  }

function switchRow(){document.getElementById('myswitch').className  = "changeGrey";}

function switchRowW(){document.getElementById('myswitch').className  = "changeGreyW";}

