var fix_it = false;

function msieversion()
{
 var ua=window.navigator.userAgent;
 var msie=ua.indexOf("MSIE ")
 if (msie > 0)
     return ua.substring(msie+5,ua.indexOf(";",msie));
   return "";
}

var isIE4 = document.all && !document.getElementById;

if (self.name != 'display')
{
  var pagecode = location.href.substr(location.href.lastIndexOf('/')+1);
  if (isIE4)
    document.write("<a href=\"index.html#" + pagecode + "\">Show in frame</a>");
  else
    document.write("<a href=\"index.html?" + pagecode + "\">Show in frame</a>");
}

window.top.defaultStatus = "Copyright (c) 2000-2008 Alun Williams";

function actualStyle(el)
{
  if (el.currentStyle)
    return el.currentStyle;
  if (document.defaultView)
    return document.defaultView.getComputedStyle(el,null);
  return el.style;
}

function change_button(but)
{
  if (but)
  {
    but.style.borderBottomStyle= 'none'; 
    if (isIE4)
    {
      but.style.backgroundImage = but.id=="st" ? "url(sphelp.jpg)" : "url(back4.jpg)";
      but.style.backgroundPositionX =  "" + -(but.offsetLeft+2) + "px";
      but.style.backgroundPositionY =  "" + (but.offsetHeight-2 - (but.id=="st" ? 120 : 304)) + "px";
    }
    else
    {
      but.style.backgroundImage = actualStyle(document.body).backgroundImage;
      but.style.backgroundPosition =  "" + -(but.offsetLeft+2) + "px " + (but.offsetHeight-2) + "px";
    }
    if (but.getElementsByTagName)
    {
      but = but.getElementsByTagName("A")[0];
      but.style.color = "navy";
    }
    else
      but.children[0].style.color = "navy";
    fix_it = true;
  }
}

function showunload(pagecode)
{
  var butframe;
  var but;
  if (fix_it && (butframe = window.top.frames['title_area']))
  {
    if (butframe.document.all)
    {
      but = butframe.document.all[pagecode];
      if (!but)
        but = butframe.document.all["other"];
    }
    else if (butframe.document.getElementById)
    {
      but = butframe.document.getElementById(pagecode);
      if (!but)
        but = butframe.document.getElementById("other");
    }

    if (but)
    {
      but.style.borderBottomStyle=''; 
      but.style.backgroundImage='';
      but.style.backgroundPosition = '';
      if (but.getElementsByTagName)
      {
        but = but.getElementsByTagName("A")[0];
        but.style.color = "";
      }
      else
        but.children[0].style.color = "";
    }
  }
}

function fix_stylesheet()
{
  var ver = msieversion();
  if (ver && ver<"7" && document.createStyleSheet)
  {
    if (ver=="5.5")
      document.createStyleSheet("ie55.css");
    else if (ver >= "4" && ver < "5.5")
      document.createStyleSheet("ie5.css");
    else
      document.createStyleSheet("ie.css");
  }
}

function fix_links()
{
  /* Improve site navigation for Javascript browsers by making refresh() work nicely even though
     site is framed */
  var el,i;
  var sep='?';
  /* Test below is intended to pick out IE4, which does not like ? in our URL for some reason.
     # works nicely in IE but not Mozilla, which does not fire onload event if top url changes but
     document is same. ? should work in any browser as it looks like a query and should force a server trip
  */
  if (document.all && !document.getElementById) 
    sep = '#';
  for (i = 0; i < document.links.length;i++)
  {
    el = document.links[i];
    if ((!el.target || el.target=="display") && (!el.hostname || el.hostname==location.hostname) &&
         !el.type && el.className!="jsl")
    {
      el.href = "index.html" + sep + el.href;
      el.target = "_top";
    }
   }
}


function showload(pagecode)
{
  if (self.name=="display")
  {
    if (document.all)
    {
      var butframe = window.top.frames['title_area'];
      var but = butframe.document.all[pagecode];
      if (!but)
        but = butframe.document.all["other"];
      change_button(but);
    }
    else if (document.getElementById)
    {
      var butframe = window.top.frames['title_area'];
      var but = butframe.document.getElementById(pagecode);
      if (!but)
        but = butframe.document.getElementById("other");
      change_button(but);
    }
    if (document.title && window.top.document.title)
      window.top.document.title = "Alun's Web Site - " + document.title;
  }
  // Ensure images with no title get some kind of tooltip
  // Must be executed during or after onLoad() event
  for (var i = 0; i < document.images.length;i++)
  {
    var im = document.images[i];
    if (im.title=="")
      im.title = im.alt;
  }
  fix_stylesheet();
  fix_links();
  window.top.defaultStatus = "Copyright (c) 2000-2008 Alun Williams";
  return 1;
}

function MM_reloadPage(init)
{ 
  //reloads the window if Nav4 resized
  if (init==true) 
    with (navigator) 
    {
      if ((appName=="Netscape") && (parseInt(appVersion)==4)) 
      {
        document.MM_pgW=innerWidth; 
        document.MM_pgH=innerHeight; 
        onresize=MM_reloadPage;
      }
    }
  else  if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) 
    location.reload();
}

MM_reloadPage(true);
