
  /* SuckerFish focus method on tds, only slightly modified
  --------------------------------------------------------------*/
  attachHover = function ()
  {
    // List of tags to add hover and focus to
    var elmnts = new Array ('td', 'input', 'textarea');

    // Do it up!
    for (var i = 0; i < elmnts.length; i++)
    {
      var elmPntrs = document.getElementsByTagName (elmnts[i]);
      for (var j = 0; j < elmPntrs.length; j++)
      {
        // Hover
        elmPntrs[j].onmouseover = function () { this.className += ' hover'; }
        elmPntrs[j].onmouseout = function () { this.className = this.className.replace (' hover', ''); }

        // Focus
        elmPntrs[j].onfocus = function () { this.className += ' focus'; }
        elmPntrs[j].onblur = function () { this.className = this.className.replace (' focus', ''); }
      }
    }
  }

  if (window.attachEvent) window.attachEvent('onload', attachHover);


  /* Sleight for PNGs
  --------------------------------------------------------*/
  if (navigator.platform == "Win32" && navigator.appName == "Microsoft Internet Explorer" && window.attachEvent) {
  	window.attachEvent("onload", alphaBackgrounds);
  }

  function alphaBackgrounds(){
  	var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
  	var itsAllGood = (rslt != null && Number(rslt[1]) >= 5.5);
  	for (i=0; i<document.all.length; i++){
  		var bg = document.all[i].currentStyle.backgroundImage;
  		if (itsAllGood && bg){
  			if (bg.match(/\.png/i) != null){
  				var mypng = bg.substring(5,bg.length-2);
  				document.all[i].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+mypng+"', sizingMethod='scale')";
  				document.all[i].style.backgroundImage = "url('/assets/images/x.gif')";
  			}
  		}
  	}
  }


  /* target="_blank" emulation, thanks to http://www.sitepoint.com/article/standards-compliant-world/3
  --------------------------------------------------------------*/
  function externalLinks()
  {
    if (!document.getElementsByTagName) return;
    var anchors = document.getElementsByTagName ('a');
    for (var i = 0; i < anchors.length; i++)
    {
      var anchor = anchors[i];
      if (anchor.getAttribute ('href') && anchor.getAttribute('rel') == 'external')
        anchor.target = "_blank";
    }
  }

  window.onload = externalLinks;


  /* Calendar event popups
  --------------------------------------------------------------*/
  var delay = 150;
  var posX = 0;
  var posY = 0;
  var offset = 5;
  var eventTimer = new Array();

  function getMouseXY (e)
  {
    if (navigator.appName == 'Netscape')
    {
      posX = e.pageX;
      posY = e.pageY;
    }
    else
    {
      posX = event.clientX + document.body.scrollLeft;
      posY = event.clientY + document.body.scrollTop;
    }

    if (posX < 0) posX = 0;
    if (posY < 0) posY = 0;

    posX += offset;
    posY += offset;

    return true;
  }
  window.document.onmousemove = getMouseXY;

  function showEvents (cal, day)
  {
    // A timer thread for this calendar should be created only if it doesn't exist
    if (typeof eventTimer[cal] != 'object') eventTimer[cal] = new Array ();

    eventDL = document.getElementById ('events_' + cal + '_' + day);

    // Kill any pending request to hide the object
    clearTimeout (eventTimer[cal][day]);

    // Hide all open tooltips, except this one
    for (var i in eventTimer)
    {
      // Go through days in that calendar
      for (var j in eventTimer[i])
      {
        if ((i == cal && j != day) || i != cal)
        {
          // Hide it
          document.getElementById ('events_' + i + '_' + j).style.display = 'none';

          // Free its pending timeout
          clearTimeout (eventTimer[i][j]);

          // Delete it from the array
          delete eventTimer[i][j];
        }
      }
    }

    // Display the box on the proper side of the mouse
    if (posX < document.body.clientWidth - 220)
      eventDL.style.left = posX + 'px';
    else
      eventDL.style.left = (posX - 200) + 'px';

    /*if (posY + getElementHeight ('events_' + day) < document.body.clientHeight)
      eventDL.style.top = posY + 'px';
    else
      eventDL.style.top = (posY - getElementHeight ('events_' + day)) + 'px';*/
    eventDL.style.top = posY + 'px';

    // Show it
    eventDL.style.display = 'block';

    // Attatch a function to the onMouseOver event to prevent the events from hiding
    eventDL.onmouseover = function () { clearTimeout (eventTimer[cal][day]); }
    // Attatch a function to the onMouseOut event to hide the events after they're read.
    eventDL.onmouseout = function () { hideEvents (cal, day); }
  }

  // Set a timeout to kill the object in 'delay' milliseconds
  function hideEvents (cal, day)
  {
    eventTimer[cal][day] = setTimeout ('document.getElementById (\'events_' + cal + '_' + day + '\').style.display = \'none\'', delay);
  }

  var op5 = navigator.userAgent.indexOf ('Opera 5') != -1 || navigator.userAgent.indexOf ('Opera/5') != -1;
  function getElementHeight(Elem)
  {
		if (document.getElementById)
			var elem = document.getElementById (Elem);
		else if (document.all)
			var elem = document.all[Elem];

		if (op5)
			xPos = elem.style.pixelHeight;
		else
			xPos = elem.offsetHeight;

		return xPos;
  }

  /* Date Field Manager
  --------------------------------------------------------*/
  daysInMonth = new Array (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

  function valiDate (set)
  {
    objMonth = document.getElementById (set + 'Month');
    objDay   = document.getElementById (set + 'Day');
    objYear  = document.getElementById (set + 'Year');

    // Save the selected day. Save as the end of the month if that's what's selected
    if (objDay.selectedIndex == objDay.options.length - 1 && objDay.options.length != 0) // Last day selected
      var selectedDay = daysInMonth[objMonth.selectedIndex - 1];
    else
      var selectedDay = objDay.selectedIndex;

    // Empty the day object
    for (var i = objDay.options.length; i >= 0; i--)
      objDay.options[i] = null;

    // Get the days in this month
    var daysInThisMonth = daysInMonth[objMonth.selectedIndex - 1];

    // Leap year, and it's February? 29 days then!
    if (objYear.selectedIndex > 0 && objYear.options[objYear.selectedIndex].value % 4 == 0 && objMonth.selectedIndex == 2) daysInThisMonth = 29;

    // Add the proper number of days
    for (var i = 1; i <= daysInThisMonth; i++)
      objDay.options[i - 1] = new Option (i, i);

    // Select the last-selected date, or the last item in the list if this month is shorter
    objDay.selectedIndex = Math.min (objDay.options.length - 1, selectedDay);
  }

  /* A method to swap images thumbs with originals
  --------------------------------------------------------*/
  function swap (obj)
  {
    if (obj.src.indexOf ('-thumb') != -1)
      obj.src = obj.src.replace ('-thumb.jpg', '.jpg');
    else
      obj.src = obj.src.replace ('.jpg', '-thumb.jpg');
  }

  /* Adjust display
  --------------------------------------------------------*/
  function display (id, display)
  {
    document.getElementById (id).style.display = display;
  }