// Speed thing for Internet Explorer
try { window.offscreenBuffering=true; } catch(e) { }

// Browser Determination
var is_firefox=(navigator.userAgent.toLowerCase().indexOf("firefox")>=0);
var is_msie=(navigator.userAgent.toLowerCase().indexOf("msie")>=0);
var is_safari=(navigator.userAgent.toLowerCase().indexOf("safari")>=0);
var is_opera=(navigator.userAgent.toLowerCase().indexOf("opera")>=0);
var is_netscape=(navigator.userAgent.toLowerCase().indexOf("netscape")>=0);
var is_other=!(is_firefox || is_msie || is_safari || is_opera || is_netscape || is_other);

// This tests whether the browser is a pre-IE7 version of IE.
function is_old_msie()
{
	var r=is_msie;
	if (r)
	{
		var v=navigator.userAgent.toLowerCase();
		v=v.substring(v.indexOf("msie")+5,v.length);
		v=v.substring(0,v.indexOf("."));
		r=(parseFloat(v)<7);
	}
	return r;
}

// This opens a popup
function openPopup(url,x1,y1,title,opener)
{
	try
	{
  	x=screen.width/2-(x1/2)
  	y=screen.height/2-(y1/2)
  	windowReference = window.open(url,title,'left='+x+',top='+y
	   +',resizable=no,toolbar=no,alwaysRaised=yes,directories=no,resizable=no,'
	   +'menubar=no,location=no,status=no,width='+x1+',height='+y1,true);
		if (opener)
			windowReference.opener=opener;
	  else if (!windowReference.opener)
		{
			windowReference.opener = document;
		  if (!windowReference.opener)
  		  windowReference.opener = self;
		}
		return windowReference;
	}
	catch(e) 
	{
		alert("openPopup: "+e.message);
		return null;
	}
}

// This adds an event to be processed at <BODY>.onLoad()
function addLoadEvent(func)
{
  var oldonload = window.onload;
  if (typeof window.onload != 'function') 
  {
    window.onload = func;
  }
  else 
  {
    window.onload = function() { oldonload(); func(); }
  }
}

// This schedules an event to take place. The function call should be passed as a string.
// Example:
//   scheduleEvent("alert('This is an alert')");
//
// I have generalised this functionality so that the number of milliseconds may be
// standardised.
function scheduleEvent(functionCall)
{
	setTimeout(functionCall,20);
}

function tableWidth(t)
{
	var rv=0;
	var x=document.getElementById(t);
	if (is_firefox || is_opera || is_safari)
	{
		var r=x.rows[x.rows.length-1];
		if (r)
		{
			var td=r.cells[r.cells.length-1];
			if (td)
				rv=parseFloat(td.offsetLeft)+parseFloat(td.offsetWidth);
		}
	}
	else
		rv=x.offsetWidth;
	return rv;
}

function tableHeight(t)
{
	var rv=0;
	var x=document.getElementById(t);
	if (is_firefox || is_opera || is_safari)
	{
		var r=x.rows[x.rows.length-1];
		if (r)
		{
			var td=r.cells[r.cells.length-1];
			if (td)
				rv=parseFloat(td.offsetTop)+parseFloat(td.offsetHeight)+15;
		}
	}
	else
		rv=x.offsetHeight;
	return rv;
}

function refreshPage()
{
	try
	{
		window.location.reload(false);
	}
	catch(e)
	{
		var url=unescape(window.location.pathname);
		window.location.replace(url);
	}
}

// Returns the file name of the current page
function pageName()
{
	var s=window.location+"?";
	s=s.substring(0,s.indexOf("?")).replace("\\","/");
	if (s.indexOf("/")>=0)
		s=s.substring(s.lastIndexOf("/")+1);
	else if (s.indexOf(":")>=0)
		s=s.substring(s.indexOf(":")+1);
	return s;
}
