// --------------------------------------------------------------------------
// Name        : pseutils.js
// Created     : 12/09/2001
// Author      : Peter Ebdon, Professional Software Engineering Ltd (peter.ebdon@pseltd.com)
// Purpose     : Generic javascript utlility finctions
// Copyright   : Copyright (c) 2002 Professional Software Engineering Ltd
// ---------------------------------------------------------------------------------------
// Revision History
// 18/09/2009 MPW Added missing MM_* functions for image rollovers
//                (These used to be in a .inc file but that is no longer referenced by base template)
// --------------------------------------------------------------------------

var gstrAgent = window.navigator.userAgent;
var gstrAgentVers = parseInt(gstrAgent.charAt(gstrAgent.indexOf("/")+1),10);

function is_explorer()
{
	return gstrAgent.indexOf("MSIE") > 0;
}
	
function is_macexplorer()
{
	if (gstrAgent.indexOf("Mac") <= 0)
		return false;
	else
		return gstrAgent.indexOf("MSIE") > 0;
}
	
function is_macnetscape()
{
	if (gstrAgent.indexOf("Mac") <= 0)
		return false;
	else
		return !(gstrAgent.indexOf("MSIE") > 0);
}
	
function is_macie4()
{
	if ((gstrAgent.indexOf("Mac") > 0) && (gstrAgent.indexOf("MSIE") > 0) && (gstrAgentVers < 5))
		return true;
	else
		return false;
}

function is_pcnetscape()
{
	if (gstrAgent.indexOf("Mac") > 0)
		return false;
	else
		return !(gstrAgent.indexOf("MSIE") > 0);
}
	
function is_aol()
{
	return gstrAgent.indexOf("AOL") > 0;
}

// Popup window handling

var gwinPopup = "none";

// Open a window in either the topleft or topright screen corner

function openPSEWin(url,w,h,l,t)
{
	var secs = new Date();
	closePopupIfOpen();
//	if fixed == 0//		{
		gwinPopup=window.open(url,'popup'+secs.getTime(),'width='+w+',height='+h+',left='+l+',top='+t+',toolbar=no,location=no,status=no,scrollbars=yes,resizable=yes');
//		}
//	else
//		{//		gwinPopup=window.open(url,'popup'+secs.getTime(),'width='+w+',height='+h+',left='+l+',top='+t+',toolbar=no,location=no,status=no,scrollbars=yes,resizable=no');
//		}}

// If the popup window has been opened, close it now

function closePopupIfOpen()
{	
	if (gwinPopup)
	{
		if (!is_macie4())
			{
				if (typeof(gwinPopup) == "object")
				{
					if (gwinPopup.closed == false)
					{
						gwinPopup.close();
					}
					gwinPopup="none";
				}
			}
		else
			{
				if (typeof(gwinPopup) == "object")
				{
					gwinPopup="none";
				}
			}
	}
}// establish current windows' widthfunction getWindowWidth() {
	if (is_explorer)	{
		return top.window.outerWidth;	}
	else
	{
		return self.innerWidth;	}}

// establish current windows' widthfunction getWindowHeight() {
		if (is_explorer)	{		return top.window.outerHeight;	}
	else
	{
		return self.innerHeight;	}}

function StringBuilder(value)
{
	this.strings = new Array("");
	this.append(value);
};

StringBuilder.prototype.append = function (value)
{
	if (value)
	{
		this.strings.push(value);
	}
};

StringBuilder.prototype.clear = function ()
{
	this.strings.length = 1;
};

StringBuilder.prototype.toString = function ()
{
	return this.strings.join("");
};


// image roll-over functions
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_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_findObj(n, d) { //v4.0
    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 && document.getElementById) x = document.getElementById(n); return x;
}

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]; }
}