/* Macromedia functions */

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);

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

/*
 * Copyright © IntraSoft 2005. All rights reserved.
 * http://www.intrasoft.com.au/
 */


function elementShow(id)
{
	var e = document.getElementById(id);

	if (e)
	{
		e.style.visibility = 'visible';
	}
}

function elementHide(id)
{
	var e = document.getElementById(id);

	if (e)
	{
		e.style.visibility = 'hidden';
	}
}

function elementDisplayBlock(id)
{
	var e = document.getElementById(id);

	if (e)
	{
		e.style.display = 'block';
	}
}

function elementDisplayInline(id)
{
	var e = document.getElementById(id);

	if (e)
	{
		e.style.display = 'inline';
	}
}

function elementDisplayNone(id)
{
	var e = document.getElementById(id);

	if (e)
	{
		e.style.display = 'none';
	}
}

function elementUpdate(id, text)
{
	var e = null;

	e = document.getElementById(id);

	if (e)
	{
//		var z = e.style.display;
//		e.style.display = 'none';
//		e.innerHTML = text;
//		e.style.display = z;

//		var z = e.style.visibility;
//		e.style.display = 'hidden';
//		e.innerHTML = text;
//		e.style.visibility = z;

		e.innerHTML = text;
	}
	else
	{
//		window.status = text;
//		alert("Cannot find id=\""+ id + "\" in web page HTML");
	}
}

function elementEnable(id)
{
	var e = null;

	e = document.getElementById(id);

	if (e)
	{
		e.disabled = false;
	}
}

function elementDisable(id)
{
	var e = null;

	e = document.getElementById(id);

	if (e)
	{
		e.disabled = true;
	}
}

function elementCursor(id, cursorStyle)
{
	var e = null;

	e = document.getElementById(id);

	if (e)
	{
		e.style.cursor = cursorStyle;
	}
}

function fieldUpdate(id, text)
{
	var e = null;

	e = document.getElementById(id);

	if (e)
	{
		e.value = text;
	}
}

function fieldClear(id)
{
	var e = null;

	e = document.getElementById(id);

	if (e)
	{
		e.value = "";
	}
//	else
//	{
//		window.status = text;
//		alert("Cannot find id=\""+ id + "\" in web page HTML");
//	}
}

function windowOnload(f)
{
	var previous = window.onload;
	window.onload = function() { if (previous) { previous(); } f(); };
}

function addLoadEvent(f)
{
	var oldonload = window.onload;
	if (typeof window.onload !== 'function')
	{
		window.onload = f;
	}
	else
	{
		window.onload = function()
		{
			if (oldonload)
			{
				oldonload();
			}
			f();
		};
	}
}


// Global object for storing XMLHTTP properties
var request = null;
// Global object for storing XMLHTTP callback function
var callback = null;
var xmlFile = null;
var nodeStart = 0;
var nodeIndex = 0;
var nodeItem = 0;

function httpRequest(url, loadedCallback)
{
	var asynchronous;

	if (loadedCallback)
	{
		asynchronous = true;
		callback = loadedCallback;
	}
	else
	{
		asynchronous = false;
		callback = null;
	}

	if (window.XMLHttpRequest)
	{
		// IE 7, Firefox, Opera
//		try
//		{
//			netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
//		}
//		catch (e)
//		{
//			alert("Permission UniversalBrowserRead denied.");
//		}

		request = new XMLHttpRequest();
		request.open("GET", url, asynchronous);
		if (asynchronous)
		{
			request.onreadystatechange = xmlhttpChange;
		}
		request.send(null);
		
		if (navigator.userAgent.search(/opera 8/i) != -1)
		{
			// Opera 8.5
			nodeStart = 1;
			nodeIndex = 2;
			nodeItem = 0;
		}
		else if (navigator.userAgent.search(/opera 9/i) != -1)
		{
			// Opera 9.0
			nodeStart = 1;
			nodeIndex = 2;
			nodeItem = 1;
		}
		else if (navigator.userAgent.search(/msie /i) != -1)
		{
			nodeStart = 0;
			nodeIndex = 1;
			nodeItem = 0;
		}
		else
		{
			// Firefox
			nodeStart = 1;
			nodeIndex = 2;
			nodeItem = 1;
		}
	}
	else if (window.ActiveXObject)
	{
		// IE 5 - 6
		request = new ActiveXObject("Microsoft.XMLHTTP");
		if (request)
		{
			request.open("GET", url, asynchronous);
			if (asynchronous)
			{
				request.onreadystatechange = xmlhttpChange;
			}
			request.send();
			nodeStart = 0;
			nodeIndex = 1;
			nodeItem = 0;
		}
	}

//	var root = request.responseXML.documentElement;
//   for (var i=0; i<root.childNodes.length; i++)
//   { alert(root.childNodes.item(i).nodeValue); }

	return request.responseXML;
}

function xmlhttpChange()
{
	if (callback != null)
	{
		if (request.readyState == 4)
		{
			if (request.status == 200)
			{
				// Load has completed successfully
				callback(request.responseXML);
			}
			else
			{
				callback(null);
			}
		}
	}
}

// Date functions

var dayNames = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
var monthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];

function dateDayName(d)
{
	return dayNames[d.getDay()];
}

function dateMonthName(d)
{
	return monthNames[d.getMonth()];
}

function dateDaySuffix(d)
{
	var suffix;
	var day = d.getDate();

	if (day == 1 || day == 21 || day == 31)
	{
		suffix = "st";
	}
	else if (day == 2 || day == 22)
	{
		suffix = "nd";
	}
	else if (day == 3 || day == 23)
	{
		suffix = "rd";
	}
	else
	{
		suffix = "th";
	}

	return day + suffix;	
}

