function examine(o)
{
//  var w = window.open("","_blank","status=yes,resizable=yes,scrollbars=yes,width=400,height=300");
 if ( o )
 {
   var r = "";
   for (var i in o)
   {
       if ( i.slice(0,3)=="get" )
         r += i+"="+o[i]+"\n";
   }
   alert(r); // w.document.write("<html><body><pre>"+r+"</pre></body></html>\n");
 }
 else
 {
   alert("not set"); // w.document.write("<html><body><i>not set</i></body></html>\n");
 }
//  w.document.close();
}

function examine2(o)
{
 if ( o )
 {
   var r = "";
   for (var i in o)
   {
     r += i+"="+o[i]+"\n";
   }
   alert(r);
 }
 else
 {
   alert("not set");
 }
}

// convert date from UTC date to format required by cookies
function convertDate(dateIn)
{
   var weekdaysShort = [ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ];
 var weekdaysLong  = [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ];
 var monthsShort = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ];
 var monthsLong  = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ];

 var day = dateIn.getUTCDay();
 var date = dateIn.getUTCDate();
 var month = dateIn.getUTCMonth();
 var year = ""+dateIn.getUTCFullYear();
 year = year.substr(2,year.length);

 var hours = dateIn.getUTCHours();
 var minutes = dateIn.getUTCMinutes();
 var seconds = dateIn.getUTCSeconds();

 //  Wdy, DD-Mon-YYYY HH:MM:SS GMT

 // Monday, 16-Apr-2001 21:53:41 GMT

 var dateOut = weekdaysLong[day]+", "+date+"-"+monthsShort[month]+"-"+year+" "+hours+":"+minutes+":"+seconds+" GMT";

 return dateOut;
}

function getCookie(theName)
{
 var search = theName + "=";

 if (window.document.cookie.length > 0)   // if there are any cookies
 {
   var offset = window.document.cookie.indexOf(search);
   if (offset != -1)               // if cookie exists
   {
     offset += search.length;
     var end = window.document.cookie.indexOf(";", offset);  // set index of beginning of value
     if (end == -1) end = window.document.cookie.length; // set index of end of cookie value
     return decodeURIComponent( document.cookie.substring(offset,end) );
   }
 }
}

function setCookie(name, value, path, domain, secure)
{
 var expireTime = new Date();
 expireTime.setTime(expireTime.getTime() + 3E11); // looooong time interval
 var dateString = convertDate(expireTime);
 document.cookie = name + "=" + encodeURIComponent(value) +
   "; expires=" + dateString +
   ((path)? "; path=" + path : "") +
   ((domain)? "; domain=" + domain : "") +
   ((secure)? "; secure" : "");
}

function setSessionCookie(name, value, path, domain, secure)
{
 document.cookie = name + "=" + encodeURIComponent(value) +
   "; " +
   ((path)? "; path=" + path : "") +
   ((domain)? "; domain=" + domain : "") +
   ((secure)? "; secure" : "");
}

// ****************************************************************************

function ClearSearch()
{
   var me = window.location.href;
   var q = me.indexOf("?");
   if ( q>=0 ) me = me.slice(0,q);

 setSessionCookie("search","","/");
 setSessionCookie("BLFILTER","","/");
 setSessionCookie("BLSORT","","/");

 var s = window.location.search;
 var start = s.indexOf("start=");
 if ( start>=0 )
 {
   var end = s.indexOf("&",start+1);
   if ( end>=0 )
     s = s.slice(0,start)+s.slice(end+1);
   else
     s = s.slice(0,start);
 }
 window.location.href = me+s;
}

function BackToStart()
{
   var me = window.location.href;
   var q = me.indexOf("?");
   if ( q>=0 ) me = me.slice(0,q);

 var s = window.location.search;
 var start = s.indexOf("stop=");
 if ( start>=0 )
 {
   var end = s.indexOf("&",start+1);
   if ( end>=0 )
     s = s.slice(0,start)+s.slice(end+1);
   else
     s = s.slice(0,start);
 }
 if ( s=="?" )
   window.location.href = me;
 else
   window.location.href = me+s;
}

function InitSearch()
{
   var SearchForm = window.document.forms["SearchForm"];
   if ( SearchForm!=null )
   {
     var search = SearchForm.elements["search"];
     if ( search != null )
     {
     var s = getCookie("search");
     if ( s ) search.value = s;
//      setSessionCookie('last_calendar',QUERY_STRING,'/');
   }
   }
}

function Search()
{
   var SearchForm = window.document.forms["SearchForm"];
   if ( SearchForm!=null )
   {
     var search = SearchForm.elements["search"];
     if ( search != null )
     {
     if ( search.value.length > 0 )
     {
       setSessionCookie("search",search.value,"/");
       window.location.reload();
     }
   }
 }
 return false;
}

function updateDesc(i)
{
 if ( i.checked )
   setSessionCookie("descendants","yes","/");
 else
   setSessionCookie("descendants","no","/");
 window.location.reload();
 return false;
}

function addLoadEvent(fn)
{
 var oldonload = window.onload;
 if (typeof window.onload != 'function')
 {
   window.onload = fn;
 }
 else
 {
   window.onload = function() { oldonload(); fn(); }
 }
}

 function filter()
 {
   var w = window.open("filter.php","_blank","modal=yes,status=yes,resizable=no,scrollbars=no,width=600,height=400");
   return false;
 }

 function sort()
 {
   var w = window.open("sort.php","_blank","modal=yes,status=yes,resizable=no,scrollbars=no,width=600,height=400");
   return false;
 }

   function login()
   {
   var w = window.open("login.php?dialog=true","_blank","modal=yes,status=yes,resizable=no,scrollbars=no,width=400,height=100");
   return false;
   }
      function logout()
   {
       setSessionCookie("BLID", null, "/" );
   window.location.reload();
   }

           function EditorKey(e)
           {
               var keyCode = null;
               var el = null;
               if ( document.all )
               {
         keyCode = event.keyCode;
         el = event.srcElement;
               }
               else
               {
                   keyCode = e.which;
                   el = e.target;
               }
               var keyChar = String.fromCharCode(keyCode);
                              var PostForm = document.forms["PostForm"];
               if ( PostForm != null )
               {
                   var message = PostForm.elements["message"];
                   if ( message != null )
                   {
               setCookie("BLED","MSG="+message.value+keyChar,"/");
               var recover = PostForm.elements["recover"];
                       if ( recover != null )
                       {
                       recover.style.display = 'none';
                       }
                   }
               }

               return true;
           }
                      function EditorInit()
           {
               var PostForm = document.forms["PostForm"];
               if ( PostForm != null )
               {
                   var message = PostForm.elements["message"];
                   if ( message != null )
                   {
                       message.onkeypress = EditorKey;
                   }
                   var cookie = getCookie("BLED");

                   if ( cookie!=null && cookie.length>4 && cookie.slice(0,4)=="MSG=" )
                       cookie = cookie.slice(4);
                 else
                     cookie="";
                                      if ( cookie!=null && cookie.length>0 )
                   {
                       var recover = PostForm.elements["recover"];
                       if ( recover != null )
                       {
                       recover.style.display = 'inline';
                     }
                     else
                     {
                       alert("missing recover button!");
                     }
                   }
                   else
                   {
                       var recover = PostForm.elements["recover"];
                       if ( recover != null )
                       {
                       recover.style.display = 'none';
                     }
                     else
                     {
                       alert("missing recover button!");
                     }
                   }
               }
               else
               {
                   alert("missing PostForm!");
               }
               return true;
           }
                      function EditorOk()
           {
               setCookie("BLED", null, "/" );                               return true;
           }
                      function EditorCancel(returnURL)
           {
               setCookie("BLED", null, "/" );
               window.location.href = returnURL;                           }
                      function EditorRecover()
           {
               var PostForm = document.forms["PostForm"];
               if ( PostForm != null )
               {
                   var message = PostForm.elements["message"];
                   if ( message != null )
                   {
                       var cookie = getCookie("BLED");

                     if ( cookie!=null && cookie.length>4 && cookie.slice(0,4)=="MSG=" )
                         cookie = cookie.slice(4);
                   else
                       cookie="";

                       if ( cookie!=null && cookie.length>0 )
                       {
                           message.value = cookie;
                           var recover = PostForm.elements["recover"];
                           if ( recover != null )
                           {
                               recover.style.display = 'none';
                           }
                           setCookie("BLED", null, "/" );                                       }
                   }
               }                       }

 function bookmark()
 {
     window.open(
         "bookmark.php"+
         "?path=_0_"+
         "&title="+escape(window.document.title)+
         "&message="+escape(window.location.href),
         'MRBM_WINDOW',
         'status=yes,resizable=yes,scrollbars=yes,width=500,height=350');
 }
             addLoadEvent(InitSearch);



