/* ------------------------------------------------------------------------------------------------------------------ */
/*                                                                                                                    */
/* ALL FUNCTIONS (c) Jamie Jones unless stated otherwise, and NOT to be used without giving full credit.              */
/*                    ---  This means YOU !                                                                           */
/*                    ---  jamie@bishopston net - http://phpbbmods.bishopston.net/                                    */
/*                                                                                                                    */
/*  Last Updated: 14th October 2006.                                                                                   */
/*                                                                                                                    */
/* ------------------------------------------------------------------------------------------------------------------ */

/* ------------------------------------------------------------------------------------------------------------------ */
function catflap_sleep(sleeptime)
  {
    var date_now = new Date();
    var cur_time = date_now.getTime();
    var return_time = cur_time + sleeptime;

    while (cur_time < return_time)
      {
        date_now = new Date(); 
        cur_time = date_now.getTime();
      }
  }

/* ------------------------------------------------------------------------------------------------------------------ */
function catflap_toggle_spoiler(linkobject, spoilerobject, opentext, closetext)
  {
    var visibleobject = spoilerobject.childNodes[1].firstChild.firstChild;
    var hiddenobject  = spoilerobject.childNodes[2].firstChild.firstChild;

    if (hiddenobject)
      if ( hiddenobject.style.display != 'block' )
        {
          hiddenobject.style.display = 'block';
          if (visibleobject) visibleobject.style.display = 'none';
          if (linkobject)    linkobject.nodeValue = 'Click here to ' + closetext;
        }
       else
        {
          hiddenobject.style.display = 'none';
          if (visibleobject) visibleobject.style.display = 'block';
          if (linkobject)    linkobject.nodeValue = 'Click here to ' + opentext;
        }
  }

/* ------------------------------------------------------------------------------------------------------------------ */
function catflap_get_flash_controls_html(flashobject, url, just_done, what)
  {
    var controlhtml="";

    if ((typeof (flashobject.IsPlaying) != "undefined") && (!flashobject.IsPlaying()) && (typeof (flashobject.Play) == "undefined"))
      controlhtml = " | <a onClick=\"catflap_control_flash(this, 'restart', '" + url + "'); return false;\">Start</a>";
     else
      {
        if (what == "flash")
          {
            if (just_done != "pause")
              if (typeof (flashobject.StopPlay) != "undefined") controlhtml += " | <a onClick=\"catflap_control_flash(this, 'pause', '" + url + "'); return false;\">Pause</a>";

            if (just_done == "pause")
              if (typeof (flashobject.Play) != "undefined")     controlhtml += " | <a onClick=\"catflap_control_flash(this, 'resume', '" + url + "'); return false;\">Resume</a>";

            if (typeof (flashobject.LoadMovie) != "undefined")  controlhtml += " | <a onClick=\"catflap_control_flash(this, 'restart', '" + url + "'); return false;\">Restart</a>";
          }

        if (typeof (flashobject.Zoom) != "undefined") controlhtml += " | <a onClick=\"catflap_control_flash(this, 'zoomin', ''); return false;\">Zoom In</a> | <a onClick=\"catflap_control_flash(this, 'zoomout', ''); return false;\">Zoom Out</a> | <a onClick=\"catflap_control_flash(this, 'zoomnormal', ''); return false;\">Normal Size</a>";
      }

    return ("[ " + controlhtml.substring(2) + " ]");
  }

function catflap_toggle_flash(linkobject, controlobject, spoilerobject, url, what)
  {
    var visibleobject  = spoilerobject.childNodes[1].firstChild.firstChild;
    var flashdivobject = spoilerobject.childNodes[2].firstChild.firstChild;

    if ( flashdivobject.style.display != 'block' )
      {
        flashdivobject.style.display = 'block';
        if (controlobject)
          {
            controlobject.innerHTML= catflap_get_flash_controls_html(flashdivobject.firstChild, url, "start", what);
            controlobject.style.display = 'block';
          }

        if (visibleobject) visibleobject.style.display = 'none';
        if (linkobject)    linkobject.nodeValue = 'Click here to close';

//flashdivobject.innerHTML="cheese";
//flashdivobject.innerHTML='<object type="application/x-shockwave-flash" data="http://www.jamiejones.com/humour/www.weebls-stuff.com/scampi.swf" width="700" height="500" standby="Loading Flash file..."><param name="movie" data="http://www.jamiejones.com/humour/www.weebls-stuff.com/scampi.swf"/><param name="width" value="700"/><param name="height" value="500"/><param name="loop" value="false"/><param name="quality" value="high"/><param name="allowScriptAccess" value="never"/>Unable to load Flash File</object>';

        if (typeof(flashdivobject.firstChild.StopPlay) != "undefined")  flashdivobject.firstChild.StopPlay();
        if (typeof(flashdivobject.firstChild.unloadMovie) != "undefined") flashdivobject.firstChild.unloadMovie();
        if (typeof(flashdivobject.firstChild.LoadMovie) != "undefined") flashdivobject.firstChild.LoadMovie(0, url);
//flashdivobject.firstChild.data=url;
//flashdivobject.firstChild.firstChild.attributes[0].nodeValue=url;

        if (typeof(flashdivobject.firstChild.IsPlaying) != "undefined") if (!flashdivobject.firstChild.IsPlaying())
          {
            alert("Press OK to start movie");
            if (typeof(flashdivobject.firstChild.unloadMovie) != "undefined") flashdivobject.firstChild.unloadMovie();
            if (typeof(flashdivobject.firstChild.LoadMovie) != "undefined") flashdivobject.firstChild.LoadMovie(0, url);
          }
      }
     else
      {
        // If this is a flash file, for IE in particular, stop the movie playing, and replace it with a blank file before hiding the DIV
        // - as with IE, the flash file continues to run after closing! (I.e. you can still hear any sound it's making!)
        if (typeof(flashdivobject.firstChild.StopPlay) != "undefined")  flashdivobject.firstChild.StopPlay();
        if (typeof(flashdivobject.firstChild.LoadMovie) != "undefined") flashdivobject.firstChild.LoadMovie(0, "http://phpbbmedia.bishopston.net/blank.swf");

//flashdivobject.firstChild.data="http://phpbbmedia.bishopston.net/blank.swf";
//flashdivobject.firstChild.firstChild.attributes[0].nodeValue="http://phpbbmedia.bishopston.net/blank.swf";
//flashdivobject.innerHTML="cheese";

        flashdivobject.style.display = 'none';
        if (controlobject) controlobject.style.display = 'none';
        if (visibleobject) visibleobject.style.display = 'block';
        if (linkobject)    linkobject.nodeValue = 'Click here to open';
      }
  }

function catflap_control_flash(thisobj, what, url)
  {
    var flashobject = thisobj.parentNode.parentNode.parentNode.parentNode.childNodes[2].firstChild.firstChild.firstChild;

    if (flashobject) if (flashobject.type=="application/x-shockwave-flash")
        {
          if (what=="zoomin") flashobject.Zoom(90);
          if (what=="zoomout") flashobject.Zoom(110);
          if (what=="zoomnormal") flashobject.Zoom(0);

          if (what=="restart")
            {
              flashobject.StopPlay();
              flashobject.LoadMovie(0, "http://phpbbmedia.bishopston.net/blank.swf");
              flashobject.LoadMovie(0, url);
              thisobj.parentNode.innerHTML = catflap_get_flash_controls_html(flashobject, url, "start", "flash");
            }

          if (what=="pause")
            {
              flashobject.StopPlay();
              thisobj.parentNode.innerHTML = catflap_get_flash_controls_html(flashobject, url, "pause", "flash");
            }

          if (what=="resume")
            {
              flashobject.Play();
              thisobj.parentNode.innerHTML = catflap_get_flash_controls_html(flashobject, url, "resume", "flash");
            }
        }
  }

/* ------------------------------------------------------------------------------------------------------------------ */
/*
  name - name of the desired cookie
  return string containing value of specified cookie or null
  if cookie does not exist.
  This function from http://www.webreference.com/js/column8/functions.html
*/

function catflap_getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

/* ------------------------------------------------------------------------------------------------------------------ */

/* flags variable holds 2-bit pairs for the default state of the section. Each section has a unique pair of bits.

   0 00 System/users profile default -- This value is set when the server syncs the users profile with their cookie
   1 01 Window closed
   2 10 Window minimised
   3 11 Window maximised

   Allocated unique section IDs and their corresponding html ID:

    0 whoisonline
    1 gallery
    2 latesttopics
    3 forumlistings
    4 ratings
    5 funtrivia
    6 misc
    7 weblinks
    8 sidebar
    9 forumquiz
*/

function catflap_section_return_shift (section_html_id)
  {
    // Basically, the number of positions to bitwise-'shift' the flags is 2 multiplied
    // by a unique number allocated to each section.

    var ret=-1;

    if (section_html_id == "whoisonline")   ret = 0;
    if (section_html_id == "gallery")       ret = 1;
    if (section_html_id == "latesttopics")  ret = 2;
    if (section_html_id == "forumlistings") ret = 3;
    if (section_html_id == "ratings")       ret = 4;
    if (section_html_id == "funtrivia")     ret = 5;
    if (section_html_id == "misc")          ret = 6;
    if (section_html_id == "weblinks")      ret = 7;
    if (section_html_id == "sidebar")       ret = 8;
    if (section_html_id == "forumquiz")     ret = 9;

    return (ret*2);
  }

function catflap_section_default (cookie_prefix, section_html_id)
  {
    var the_cookie_value = catflap_getCookie (cookie_prefix + '_catflap_fps');
    var open_state = "block";
    var minimised_state = "none";
    var section_default_state = 0;
    
    if (the_cookie_value) section_default_state = (the_cookie_value>>>catflap_section_return_shift(section_html_id) & 3);

    if (section_default_state == 1)
      {
        open_state = "none";
        minimised_state = "none";
      }
      else if (section_default_state == 2)
        {
          open_state = "none";
          minimised_state = "block";
        }

    if (section_default_state != 0)
      {
        document.getElementById(section_html_id + '_section_open').style.display = open_state;
        document.getElementById(section_html_id + '_section_minimised').style.display = minimised_state;
      }
   }

function catflap_section_setcookie (cookie_prefix, cookie_name, cookie_value)
  {
    var the_date = new Date();

    // For registered users, the cookie only needs to last until any page on the forum
    // is loaded, after which point, the information is stored in the users profile, and
    // the cookie then reset. So, choose a cookie max age of 28 days, which should be
    // plenty. -- If they don't login for 28 days, they don't deserve to have the option
    // set !! - In fact, they'll probably not remember setting the option.
    // Anonymous users will simply have to suffer resetting the cookie every 28 days, as
    // the information is not stored online in such cases.
    the_date.setTime(the_date.getTime() + 2419200000);

    /* document.cookie = cookie_prefix + '_' + cookie_name + '=; path=/; expires=Thu, 01-Jan-1970 00:00:01 GMT'; */

    // Update or create cookie:
    document.cookie = cookie_prefix + '_' + cookie_name + '=' + cookie_value + '; path=/; expires=' + the_date.toGMTString();
  }
    
function catflap_section_change (cookie_prefix, change_type, section_html_id)
  {
    var the_cookie_value = catflap_getCookie (cookie_prefix + '_catflap_fps');
    var open_state = "block";
    var minimised_state = "none";
    var section_default_state = 3;
    var section_shift = catflap_section_return_shift(section_html_id);

    if (change_type == "close")
      {
        open_state = "none";
        minimised_state = "none";
        section_default_state = 1;
      }

    if (change_type == "minimise")
      {
        open_state = "none";
        minimised_state = "block";
        section_default_state = 2;
      }

    document.getElementById(section_html_id + '_section_open').style.display = open_state;
    document.getElementById(section_html_id + '_section_minimised').style.display = minimised_state; 

    // Get new value for cookie:
    if (!the_cookie_value) the_cookie_value=0;

    // Here we XOR the relevent 2 bits in the cookie data with themselves, hence resetting them to zero.
    // Then we OR in place the new bits.
    new_cookie_value = the_cookie_value ^ (the_cookie_value>>>section_shift & 3)<<section_shift | (section_default_state<<section_shift);

    // Update or create cookie:
    catflap_section_setcookie (cookie_prefix, "catflap_fps", new_cookie_value);
  }

function catflap_section_show_all (cookie_prefix)
  {
    var the_divs = document.getElementsByTagName("div");
    var count = the_divs.length;
    var new_cookie_value = 0;
    var loop;

    for (loop=0; loop < count; loop++)
      {
        // if (the_divs[loop].hasAttribute("id")) --- "hasAttribute" doesn't work on IE :-(
        if (the_divs[loop].id)
          {
            if ((the_divs[loop].getAttribute("id").match(/_section_open$/)) || (the_divs[loop].getAttribute("id").match(/_section_minimised$/)))
              {
                section_html_id = the_divs[loop].getAttribute("id").replace(/_section_open$/, "").replace(/_section_minimised$/, "");

                if (document.getElementById(section_html_id + '_section_open'))      document.getElementById(section_html_id + '_section_open').style.display = "block";
                if (document.getElementById(section_html_id + '_section_minimised')) document.getElementById(section_html_id + '_section_minimised').style.display = "none";

                // Here we OR in place the 2 '1' bits relevent to this entry.
                new_cookie_value = new_cookie_value  | (3<<catflap_section_return_shift(section_html_id));
              }
          }
      }

    // Update or create cookie:
    catflap_section_setcookie (cookie_prefix, "catflap_fps", new_cookie_value);
  }

/* ------------------------------------------------------------------------------------------------------------------ */

// Based on info from: http://www.quirksmode.org/viewport/compatibility.html
// --- "Inner Width"
// --- The inner dimensions of the window or frame.
function catflap_viewport_size()
  {
    var x = 0;
    var y = 0;

    if (self.innerWidth) x = self.innerWidth;
      else if (document.documentElement && document.documentElement.clientWidth) x = document.documentElement.clientWidth;
        else if (document.body) x = document.body.clientWidth;

    if (self.innerHeight) y = self.innerHeight;
      else if (document.documentElement && document.documentElement.clientHeight) y = document.documentElement.clientHeight;
        else if (document.body) y = document.body.clientHeight;
    
    return (x + " X " + y);
  }

/* ------------------------------------------------------------------------------------------------------------------ */
function catflap_move_box(cookie_prefix, block_id)
  {
    var catflap_open      = document.getElementById(block_id + '_block_open');
    var catflap_minimised = document.getElementById(block_id + '_block_minimised');

    var catflap_open_object  = new getObj(block_id + '_block_open');
    if (catflap_open_object.obj.captureEvents) catflap_open.obj.captureEvents(Event.MOUSEUP)
    if (catflap_open_object.obj.captureEvents) catflap_open.obj.captureEvents(Event.MOUSEDOWN)

    var e = catflap_open.event; 
    alert (e.clientX);
    document.getElementById(block_id + '_block_open').style.position = 'absolute';
    document.getElementById(block_id + '_block_minimised').style.position = 'absolute';
    document.getElementById(block_id + '_block_open').style.left = this.clientX + 'px';
    document.getElementById(block_id + '_block_open').style.top = this.clientY + 'px';
    document.getElementById(block_id + '_block_minimised').style.left = this.clientX + 'px';
    document.getElementById(block_id + '_block_minimised').style.top = this.clientY + 'px';
    alert (ee.clientX + " " + ee.clientY);
  }

function catflap_stopmove_box(cookie_prefix, block_id)
  {
    document.getElementById(block_id + '_block_open').style.position = 'relative';
    document.getElementById(block_id + '_block_minimised').style.position = 'relative';
  }

/* ------------------------------------------------------------------------------------------------------------------ */
// From http://www.quirksmode.org/js/events_properties.html
function catflap_doSomething(e)
{
        var posx = 0;
        var posy = 0;
        if (!e) var e = window.event;
        if (e.pageX || e.pageY)
        {
                posx = e.pageX;
                posy = e.pageY;
        }
        else if (e.clientX || e.clientY)
        {
                posx = e.clientX + document.body.scrollLeft;
                posy = e.clientY + document.body.scrollTop;
        }
        // posx and posy contain the mouse position relative to the document.
        // Do something with this information!
}

/* ------------------------------------------------------------------------------------------------------------------ */
function catflap_resize_image (imageref)
  {
    var winwidth = 0;
    var size_available = 500;

    if (self.innerWidth) winwidth = self.innerWidth;
      else if (document.documentElement && document.documentElement.clientWidth) winwidth = document.documentElement.clientWidth;
        else if (document.body) winwidth = document.body.clientWidth;

    size_available = winwidth - document.getElementById('catflap_leftbar').offsetWidth - 80;

    // alert (imageref.width + " " + size_available);
    if (imageref.width > size_available)
      {
        var pc = Math.round (size_available / imageref.width * 10000) / 100;
        // alert (imageref.width);
        imageref.catflap_original_width=imageref.width;
        imageref.catflap_shrunk_width=size_available;
        imageref.catflap_shrunk_pc=pc;
        imageref.catflap_shrunk_status=1;
        imageref.style.width=size_available + 'px';
        if (imageref.previousSibling)
          {
            imageref.previousSibling.style.width=size_available + 'px';
            imageref.previousSibling.firstChild.nodeValue="Image reduced to " + pc + "% of its original size. Click this bar to restore to full size.";
            imageref.previousSibling.style.display = 'block';
          }
      }
  }

function catflap_toggle_image_size (imageref)
  {
    if (imageref.nextSibling)
      {
        if (imageref.nextSibling.catflap_shrunk_status == 1)
          {
            imageref.firstChild.nodeValue="Image at full-size. Click this bar to fit to window.";
            imageref.style.width=imageref.nextSibling.catflap_original_width + 'px';
            imageref.nextSibling.style.width=imageref.nextSibling.catflap_original_width + 'px';
            imageref.nextSibling.catflap_shrunk_status=0;
            imageref.style.display = 'block';
          }
         else
          {
            imageref.firstChild.nodeValue="Image reduced to " + imageref.nextSibling.catflap_shrunk_pc + "% of its original size. Click this bar to restore to full size.";
            imageref.style.width=imageref.nextSibling.catflap_shrunk_width + 'px';
            imageref.nextSibling.style.width=imageref.nextSibling.catflap_shrunk_width + 'px';
            imageref.nextSibling.catflap_shrunk_status=1;
            imageref.style.display = 'block';
          }
      }
  }

/* ------------------------------------------------------------------------------------------------------------------ */
function catflap_convert_to_entity()
  {
    var inpstring = escape (document.myform.inputbox.value);
    var inplen = inpstring.length;
    var outstringhex="";
    var outstringbinary="";
    var loop=0;

    // Convert CF/LF pairs to just LF
    inpstring = inpstring.replace (/%0D%0A/g, "%0A");

    while (loop < inplen)
      {
        if (inpstring.charAt(loop) == "%")
          {
            if (inpstring.charAt(++loop) == "u")
              {
                singlechar = inpstring.charAt(++loop) + inpstring.charAt(++loop) + inpstring.charAt(++loop) + inpstring.charAt(++loop);
                outstringhex += "&#x" + singlechar + ";";
                outstringbinary += "&#" + parseInt (singlechar, 16) + ";";
              }
             else
              {
                singlechar = inpstring.charAt(loop) + inpstring.charAt(++loop);
                if ( (singlechar == "09") || (singlechar == "0A") || (singlechar.search(/^[2-7].$/) != -1) && (singlechar != "6F") && (singlechar != "26") )
                  {
                    outstringhex += unescape ("%" + singlechar);
                    outstringbinary += unescape ("%" + singlechar);
                  }
                 else
                  {
                    outstringhex += "&#x" + singlechar + ";";
                    outstringbinary += "&#" + parseInt (singlechar, 16) + ";";
                  }
              }
            loop++;
          }
        else
          {
            outstringhex += inpstring.charAt(loop);
            outstringbinary += inpstring.charAt(loop++);
          }
      }

    document.myform.outputboxhex.value = outstringhex;
    document.myform.outputboxbinary.value = outstringbinary;

  }

/* ------------------------------------------------------------------------------------------------------------------ */
function catflap_topic_mark_set_latestposts_class (node, highlight, title, row1_value, row2_value)
  {
    var the_trs = document.getElementsByTagName("tr");
    var count = the_trs.length;
    var loop;
    var thistopic_id = node.parentNode.parentNode.id;

    thistopic_id_re = new RegExp ("^" + thistopic_id.replace (/_[1-9][0-9]*$/, "") + "_");
    for (loop=0; loop < count; loop++)
      {
        // if (the_trs[loop].hasAttribute("id")) --- "hasAttribute" doesn't work on IE :-(
        if (the_trs[loop].id)
          {
            if (the_trs[loop].getAttribute("id").match(thistopic_id_re))
              {
                the_trs[loop].childNodes[0].className=row1_value;
                the_trs[loop].childNodes[1].className=row2_value;
                the_trs[loop].childNodes[1].firstChild.src=highlight;
                the_trs[loop].childNodes[1].firstChild.alt=title;
                the_trs[loop].childNodes[1].firstChild.title=title;
                the_trs[loop].childNodes[2].className=row1_value;
                the_trs[loop].childNodes[3].className=row2_value;
                the_trs[loop].childNodes[4].className=row2_value;
                the_trs[loop].childNodes[5].className=row1_value;
                the_trs[loop].childNodes[6].className=row2_value;
                the_trs[loop].childNodes[7].className=row1_value;
                the_trs[loop].childNodes[8].className=row2_value;
                the_trs[loop].childNodes[9].className=row2_value;
              }
          }
      }
  }

function catflap_topic_mark_set_latesttopics_class (node, row1_value, row2_value)
  {
    node.parentNode.previousSibling.className=row1_value;
    node.parentNode.className=row2_value;
    node.parentNode.nextSibling.className=row1_value;
    node.parentNode.nextSibling.nextSibling.className=row2_value;
    node.parentNode.nextSibling.nextSibling.nextSibling.className=row1_value;
    node.parentNode.nextSibling.nextSibling.nextSibling.nextSibling.className=row2_value;
    node.parentNode.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.className=row2_value;
    node.parentNode.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.className=row1_value;
    node.parentNode.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.className=row2_value;
  }

function catflap_topic_mark_set_viewforum_class (node, row1_value, row2_value, row3_value)
  {
    node.parentNode.previousSibling.className=row1_value;
    node.parentNode.className=row2_value;
    node.parentNode.nextSibling.className=row1_value;
    node.parentNode.nextSibling.nextSibling.className=row1_value;
    node.parentNode.nextSibling.nextSibling.nextSibling.className=row2_value;
    node.parentNode.nextSibling.nextSibling.nextSibling.nextSibling.className=row1_value;
    node.parentNode.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.className=row2_value;
    node.parentNode.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.className=row2_value;
    node.parentNode.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.className=row2_value;
    node.parentNode.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.className=row3_value;
  }

function catflap_topic_mark_change(node, forum_id, topic_id, cookie_prefix, page, unsubscribe_allowed, highlightrow)
  {
    var normal      = "http://phpbbmedia.bishopston.net/forumimages/templates/subSilver/catflap_topic_normal.gif";
    var highlight   = "http://phpbbmedia.bishopston.net/forumimages/templates/subSilver/catflap_topic_highlighted.gif";
    var normal2     = "http://phpbbmedia.bishopston.net/forumimages/templates/subSilver/catflap_topic_normal2.gif";
    var unsubscribe = "http://phpbbmedia.bishopston.net/forumimages/templates/subSilver/catflap_topic_unsubscribed.gif";

    var the_cookie_value = catflap_getCookie (cookie_prefix + '_catflap_marked_topics');
    var cookie_flag="";

    if (!the_cookie_value) the_cookie_value = "";

    if (page == "viewtopic")
      {
        normal      = "http://phpbbmedia.bishopston.net/forumimages/templates/subSilver/icon_catflap_topic_normal.gif";
        highlight   = "http://phpbbmedia.bishopston.net/forumimages/templates/subSilver/icon_catflap_topic_highlighted.gif";
        normal2     = "http://phpbbmedia.bishopston.net/forumimages/templates/subSilver/icon_catflap_topic_normal2.gif";
        unsubscribe = "http://phpbbmedia.bishopston.net/forumimages/templates/subSilver/icon_catflap_topic_unsubscribed.gif";
      }

    if (node.src == normal)
      {
        node.src=highlight;
        node.title="Topic highlighted. Click to change.";
        node.alt=node.title;

        if (highlightrow == "1")
          {
            if (page == "latestposts") catflap_topic_mark_set_latestposts_class (node, node.src, node.title, "row3", "row3");
              else if (page == "latesttopics") catflap_topic_mark_set_latesttopics_class (node, "row3", "row3");
                else if (page == "viewforum") catflap_topic_mark_set_viewforum_class (node, "row3", "row3", "row3");
          }
         else
          {
            if (page == "latestposts") catflap_topic_mark_set_latestposts_class (node, node.src, node.title, "row1", "row2");
              else if (page == "latesttopics") catflap_topic_mark_set_latesttopics_class (node, "row1", "row2");
                else if (page == "viewforum") catflap_topic_mark_set_viewforum_class (node, "row1", "row2", "row3");
          }

         cookie_flag="h";
       }
      else if ( (node.src == highlight) || (node.src == unsubscribe) )
        {
          if ( (node.src == highlight) && (unsubscribe_allowed == "allow-unsubscribe") ) node.src=normal2;
            else node.src=normal;

          node.alt="Normal topic. Click to change.";
          node.title="Normal topic. Click to change.";

          if (page == "latestposts") catflap_topic_mark_set_latestposts_class (node, node.src, node.title, "row1", "row2");
            else if (page == "latesttopics") catflap_topic_mark_set_latesttopics_class (node, "row1", "row2");
              else if (page == "viewforum") catflap_topic_mark_set_viewforum_class (node, "row1", "row2", "row3");

          cookie_flag="n";
        }
        else if (node.src == normal2)
          {
            node.src=unsubscribe;
            node.alt="Topic unsubscribed. Click to change.";
            node.title="Topic unsubscribed. Click to change.";

            if (page == "latestposts") catflap_topic_mark_set_latestposts_class (node, node.src, node.title, "catflap_deleted", "catflap_deleted");
              else if (page == "latesttopics") catflap_topic_mark_set_latesttopics_class (node, "catflap_deleted", "catflap_deleted");
                else if (page == "viewforum") catflap_topic_mark_set_viewforum_class (node, "catflap_deleted", "catflap_deleted", "catflap_deleted");

            cookie_flag="u";
          }

    if (cookie_flag)
      {
        // Update or create cookie:
        var search_text = new RegExp (",[1-9][0-9]*:" + topic_id + "[nuh]", "g");
        catflap_section_setcookie (cookie_prefix, "catflap_marked_topics", the_cookie_value.replace (search_text, "") + "," + forum_id + ":" + topic_id + cookie_flag);
      }
  }

/* ------------------------------------------------------------------------------------------------------------------ */
function catflap_set_topic_summary_coords(e)
  {

    mouse_y = 0;

    if (typeof (e) == "undefined") var e = window.event;
    if (!e) var e = window.event;
    if (e.pageY) mouse_y = e.pageY;
     else if (e.clientY) mouse_y = e.clientY + document.body.scrollTop;
  }

function catflap_show_topic_summary(node, bgcol, topicinfo)
  {
    catflap_show_topic_or_post_summary (node, bgcol, topicinfo, "Topic");
  }

function catflap_show_post_summary(node, bgcol, topicinfo)
  {
    catflap_show_topic_or_post_summary (node, bgcol, topicinfo, "Post");
    node.nextSibling.style.backgroundColor="#" + bgcol;
  }

function catflap_show_topic_or_post_summary(node, bgcol, topicinfo, what)
  {
    var preview_box = document.getElementById("catflap_preview_box");
    var height=0;

    if (self.innerHeight) height = self.innerHeight;
      else if (document.documentElement && document.documentElement.clientHeight) height = document.documentElement.clientHeight;
        else if (document.body) height = document.body.clientHeight;

    // In case this function is called before the page has completed loading, and therefore before the event has been initialised:
    if (typeof (mouse_y) == "undefined") mouse_y=0;

    // Stop box displaying off the bottom of the window:
    if (mouse_y+140 > height+document.body.scrollTop ) mouse_y = height-140+document.body.scrollTop;

    preview_box.style.right=120;
    preview_box.style.top=mouse_y;

    preview_box.style.display="block";
    preview_box.innerHTML="<b>" + what + " Summary:</b> " + unescape (topicinfo);
    node.style.backgroundColor="#" + bgcol;
  }

function catflap_hide_topic_summary(node)
  {
    var preview_box = document.getElementById("catflap_preview_box");

    preview_box.style.display="none";
    preview_box.innerHTML="";

    // The following removes the background colour override of the topic-subject TD, thus
    // reverting it to the colour specified by the class assigned to the element:
    node.style.backgroundColor='';
  }

function catflap_hide_post_summary(node)
  {
    var preview_box = document.getElementById("catflap_preview_box");

    preview_box.style.display="none";
    preview_box.innerHTML="";

    // The following removes the background colour override of the topic-subject and post-subject TD's, thus
    // reverting it to the colour specified by the class assigned to the element:
    node.style.backgroundColor='';
    node.nextSibling.style.backgroundColor='';
  }

/* ------------------------------------------------------------------------------------------------------------------ */
function catflap_process_bbcode_aligns()
{
  var the_spans = document.getElementsByTagName("span");
  var count = the_spans.length;
  var max_lengths = new Array();
  var loop;
  var loop2;
  var tab_index;
  var class_name;
  var bbcode_align_padding=30;

  for (loop=0; loop < count; loop++)
    {
      // Gotta love browser incompatabilities :-(
      class_name = the_spans[loop].getAttribute("class");
      if (!class_name) class_name = the_spans[loop].getAttribute("className");

      if (class_name)
        if (class_name.match(/^catflap_bbcode_align_[0-9]{1,2}_[0-9]{1,2}$/))
          {
            tab_index = class_name.replace(/^catflap_bbcode_align_/, "");
            if (typeof (max_lengths[tab_index]) == "undefined") max_lengths[tab_index]=0;
            if (the_spans[loop].offsetLeft > max_lengths[tab_index]) max_lengths[tab_index]=the_spans[loop].offsetLeft;
          }
    }

var shit=0;
  for (loop=0; loop < count; loop++)
    {
      // Gotta love browser incompatabilities :-(
      class_name = the_spans[loop].getAttribute("class");
      if (!class_name) class_name = the_spans[loop].getAttribute("className");

      if (class_name)
        if ( class_name.match(/^catflap_bbcode_align_[0-9]{1,2}_[0-9]{1,2}$/) || class_name.match(/^catflap_bbcode_align_after_tag_[0-9]{1,2}_[0-9]{1,2}$/) )
          {
            if (class_name.match(/^catflap_bbcode_align_[0-9]{1,2}_[0-9]{1,2}$/))
              {
                tab_index = class_name.replace(/^catflap_bbcode_align_/, "");
                the_spans[loop].style.paddingLeft=(max_lengths[tab_index] - the_spans[loop].offsetLeft+bbcode_align_padding) + "px";
              }

            var bbcode_align_content=the_spans[loop].childNodes;
            for (loop2=0; loop2 < bbcode_align_content.length; loop2++)
              if (bbcode_align_content[loop2].nodeName=="SPAN")
              {
                // Gotta love browser incompatabilities :-(
                class_name = bbcode_align_content[loop2].getAttribute("class");
                if (!class_name) class_name = bbcode_align_content[loop2].getAttribute("className");

                if (class_name)
                  if (class_name == "catflap_bbcode_align_word")
                    {
                      offie_left=bbcode_align_content[loop2].offsetLeft;
                      if (!offie_left) offie_left=0;
		      if (shit++ < 6) document.getElementById("catflap_menu_td").innerHTML += ("<pre style=\"text-align:left\">offieleft = " + offie_left + "\n" +
			     "(the_spans[loop].offsetLeft+bbcode_align_padding) = " + (the_spans[loop].offsetLeft+bbcode_align_padding) + "\n" +
			     "max_lengths[tab_index] = " + max_lengths[tab_index] + "\n" + 
			     "(max_lengths[tab_index] + bbcode_align_padding) = " + (max_lengths[tab_index] + bbcode_align_padding) + "\n" + 
			     "(max_lengths[tab_index] - offie_left + bbcode_align_padding) = " + (max_lengths[tab_index] - offie_left + bbcode_align_padding) + "\n" + 
			     "bbcode_align_content[loop2].innerHTML = " + bbcode_align_content[loop2].innerHTML + "</pre>");
                      if (offie_left < (the_spans[loop].offsetLeft+bbcode_align_padding)) bbcode_align_content[loop2].style.paddingLeft=(max_lengths[tab_index] - offie_left + bbcode_align_padding) + "px";
                    }
              }
          }
    }
}

/* ------------------------------------------------------------------------------------------------------------------ */
function catflap_size_menu_nicely()
  {
    var menuref=document.getElementById("catflap_menu_td");
    var space_width=document.getElementById("space_width").clientWidth;
    var max_width=menuref.clientWidth - (space_width * 3);
    var the_spans = document.getElementsByTagName("span");
    var count = the_spans.length;
    var total_menu_items=0;
    var lines_needed=1;
    var this_line_width=space_width + space_width;
    var menu_spans = new Array();
    var loop;

    for (loop=0; loop < count; loop++)
      {
        // if (the_spans[loop].hasAttribute("class")) --- "hasAttribute" doesn't work on IE :-(
        if (the_spans[loop].className)
          {
            // IE NEEDS className here!:
            if (the_spans[loop].getAttribute("class") == "catflap_menu_nowrap")
              {
                span_width = the_spans[loop].clientWidth + space_width;
                menu_spans[total_menu_items++] = span_width;
                this_line_width += span_width;
                if (this_line_width > max_width)
                  {
                    this_line_width=span_width+space_width;
                    lines_needed++;
                  }
              }
          }
       }

   // For testing, set innerHTML to (lines_needed + "<br>");
   // alert (total_menu_items + " : " + total_menu_width + " : " + max_width + " : " + menuref.clientWidth);
   // if (max_width > 150) menuref.style.width=max_width - 100 + 'px';
  }

/* ------------------------------------------------------------------------------------------------------------------ */

