var Selected = "";
//var MyBrowser = BrowserDetect();
var AdTime = new Date();


// Ensures the expanded message appears reasonably close to where 
// it should appear: on screen, and if possible, under the mouse cursor.
function SwitchMessage(e)
{
   if ( !e ) e = window.event;
   var target = e.target ? e.target : e.srcElement;

   // is it a post?
   while ( target && target.id != 'DynMessLink' )
      target = target.parentNode;
   if ( !target || target.id != 'DynMessLink' )
      return;

   if (Selected)
   {
      var body = document.getElementById(Selected + "_h1");
      if (body)
         body.style.display = 'none';
      var head = document.getElementById(Selected + "_h0");
      if (head)
         head.bgColor = 'white';
   }

   if (Selected == target.name) // just collapse
      Selected="";
   else
   {
      Selected = target.name;
      var body = document.getElementById(Selected + "_h1");
      if (body)
      {
         if (body.style.display=='none')
            body.style.display='';
         else
            body.style.display = 'none';
      }
      var head = document.getElementById(Selected + "_h0");
      if (head)
         head.bgColor = '#99CCFF';

      if ( body && head && body.style.display != 'none' )
      {
         // the bit that keeps the post on-screen and under the cursor
         //var dif = (getRealPos(head, "Top") + head.offsetHeight/2) - (document.body.scrollTop+e.clientY);
         //document.body.scrollTop += dif;
         document.body.scrollTop = getRealPos(head, "Top") - document.body.clientHeight/10;
         EnsureMessageVisible(target.name, true);
      }
   }

   if ( e.preventDefault )
      e.preventDefault();
   else
      e.returnValue = false;
   return false;
}

// does its best to make a message visible on-screen (vs. scrolled off somewhere).
function EnsureMessageVisible(msgID, bShowTop) {
   var msgHeader = document.getElementById(msgID + "_h0");
   var msgBody = document.getElementById(msgID + "_h1");

   // determine scroll position of top and bottom
   var scrollContainer = document.body;
   var top = getRealPos(msgHeader, 'Top');
   var bottom = getRealPos(msgBody, 'Top') + msgBody.offsetHeight;

   // if not already visible, scroll to make it so
   if ( scrollContainer.scrollTop > top && !bShowTop)
      scrollContainer.scrollTop = top - document.body.clientHeight/10;
   if ( scrollContainer.scrollTop+scrollContainer.clientHeight < bottom )
      scrollContainer.scrollTop = bottom-scrollContainer.clientHeight;
   if ( scrollContainer.scrollTop > top && bShowTop)
      scrollContainer.scrollTop = top - document.body.clientHeight/10;
}

// utility
function getRealPos(i,which)
{
   iPos = 0
   while (i!=null)
   {
      iPos += i["offset" + which];
      i = i.offsetParent;
   }
   return iPos
}

function UTC2Local(rfc2822string)
{
    var m_names = new Array("January", "February", "March",
    "April", "May", "June", "July", "August", "September",
    "October", "November", "December");
    var MyTime=new Date(rfc2822string);
    var curr_date = MyTime.getDate();
    var curr_month = m_names[MyTime.getMonth()];
    var curr_year = MyTime.getFullYear()+'';
    var curHour = MyTime.getHours();
    var apm="a";
    if (curHour==0)
    {
        curHour = "12";
    } else if (curHour>=12)
    {
        apm="p";
        if (curHour>12) curHour-=12;
    }
    var curMin = MyTime.getMinutes();
    if(curMin < 10) curMin = "0" + curMin;
    if(curHour < 10) curHour = "0" + curHour;
    if(curr_date < 10) curr_date = "0" + curr_date;
    // 16:08 03 oct '07
    //var ttime = curHour + ":" + curMin + " " + curr_date + " " + curr_month.substring(0,3) + " '" + curr_year.substring(2,4);
    // 03-Oct-07 12:37a
    var ttime = curr_date + "-" + curr_month.substring(0,3) + "-" + curr_year.substring(2,4) + " " + curHour + ":" + curMin + apm;;
    return ttime;
}
/*
function BrowserDetect()
{
    // returns "F", "M", or "O" for FireFox, MSIE, or Other
    string ua = request.getHeader( "User-Agent" );
    if ( ua != null && ua.indexOf( "Firefox/" ) != -1 )
    {
        return "F";
    } else if ( ua != null && ua.indexOf( "MSIE" ) != -1 )
    {
        return "M";
    }
    return "O";
}
*/
function install (aEvent)
{
  var params = {
    "BlipNut Sidebar": { URL: aEvent.target.getAttribute("xpiURL"),//aEvent.target.href,
             IconURL: aEvent.target.getAttribute("iconURL"),
             //Hash: aEvent.target.getAttribute("hash"),
             toString: function () { return this.URL; }
    }
  };
  InstallTrigger.install(params);

  return false;
}

function validate_helpform (form) {
    if ( form.helprequest.value == "" ) {
        alert ( "Please fill in your question." );
        form.helprequest.focus();
        return false;
    }
    return true;
}


//function RelativeTime(rfc2822string)
//{
//    var MyTime=new Date(rfc2822string);
    
