<!--

/*
Sipmple shutter for Firefox/Gecko
I.e. produces a simple popup instead
- due to the fact that the shutter looks rubbish in i.e.
*/

var ajax;

function internet_explorer() {
    if(navigator.appName=='Microsoft Internet Explorer') {return true};
}

if(internet_explorer())
window.onload = popupInit;
else
window.onload = shutterInit;

function popupInit()
{
    ajax = getHTTPObject();
    //don't change links if ajax is off
    if (!ajax) return false;
    //crawl all links for the 'shutter' class
    //indexOf for possibility of multiple classes
    links = document.getElementsByTagName('a');
    for (i = 0; i < links.length; i++) {
        if (links[i].className.indexOf('shutter') != -1) {
            oldLink = links[i].href;
            // change the href to load the same page, but with ajax
            links[i].href = "javascript: showPop('"+oldLink+"')";
        }
    }
}

function shutterInit () {
    ajax = getHTTPObject();
    //don't change links if ajax is off
    if (!ajax) return false;
    //crawl all links for the 'shutter' class
    //indexOf for possibility of multiple classes
    links = document.getElementsByTagName('a');
    for (i = 0; i < links.length; i++) {
        if (links[i].className.indexOf('shutter') != -1) {
            oldLink = links[i].href;
            // change the href to load the same page, but with ajax
            links[i].href = "javascript: mkShutter('"+oldLink+"')";
        }
    }
}

function showPop(url)
{
     // show the popup window - i.e.
     newwindow = window.open(url,'name','height=400,width=550,scrollbars=yes');
}

function mkShutter(href) {
    // some strange instances where shutter could be duplicated
    // after clicking a link and pressing enter.
    if (document.getElementById('newShutter')) return false;
    // check the url for '?'
    op = (href.indexOf('?') != -1) ? '&' : '?';
    // get the data from link via AJAX
    // ajax=on so its possible to tell difference between loading methods
  	ajax.open("GET", href +op+ 'ajax=on', true);
	  ajax.onreadystatechange = function () {
	   // if its finished loading
	   if (ajax.readyState == 4) {
            // make a new shutter
            shutter = document.createElement('div');
            shutter.setAttribute('id','newShutter');
            // add it to the page
            document.getElementsByTagName('body')[0].appendChild(shutter);
            // make the info box
            newInfo = document.createElement('div');
            newInfo.setAttribute('id','newInfo');
            // append the ajax-returned html to newInfo
	        newInfo.innerHTML = ajax.responseText;
	        document.getElementsByTagName('body')[0].appendChild(newInfo);
  	        // delete the shutter when clicked on
            shutter.onclick = hideShutter;
	   }
    }
  	ajax.send(null);
}

// remove the shutter and the info box
function hideShutter() {
  if(internet_explorer()) {
      newwindow.close();
  } else {
      shutter = document.getElementById('newShutter');
      shutter.parentNode.removeChild(shutter);
      newInfo = document.getElementById('newInfo');
      newInfo.parentNode.removeChild(newInfo);   
  }
}

// THE ajax function, from webpasties
function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}

-->
