﻿/* Global Variables */
var applicationPath;
var blnRunOnReadyStateComplete = false;
var scrollWindowInterval = null;
var scrollWindowStepSize = 1;

String.prototype.startsWith = function(s) 
{
	return (this.match('^'+s)==s);
}

String.prototype.endsWith = function(s) 
{
	return (this.match(s+'$')==s);
}

String.prototype.htmlEncode = function()
{
	var encodedHtml = escape(this);
	
	encodedHtml = encodedHtml.replace(/\//g,"%2F");
	encodedHtml = encodedHtml.replace(/\?/g,"%3F");
	encodedHtml = encodedHtml.replace(/=/g,"%3D");
	encodedHtml = encodedHtml.replace(/&/g,"%26");
	encodedHtml = encodedHtml.replace(/@/g,"%40");
	
	return encodedHtml;
}

function confirmDelete(sName)
{
	if(confirm('Are you sure you want to delete ' + sName + '?'))
	{
		return true;
	}
	else 
	{
		return false;
	}
}
//Tooltip typing delay detection var
var bShowTooltip = true;




/*********************************************
*General functions
*********************************************/

function fireOnEnter(that, e, strFunction)
{
    var intKeyCode = (e.which?e.which:e.keyCode);

    if(intKeyCode == 13)
	{
		eval(strFunction);
		return false;
	}
	return true;
}

function fireOnEscape(that, e, strFunction)
{
    var intKeyCode = (e.which?e.which:e.keyCode);

    if(intKeyCode == 27)
	{
		eval(strFunction);
		return false;
	}
	return true;
}


function maxLength(field, maxlimit) 
{
	if (field.value.length > maxlimit) 
	{ 
		field.value = field.value.substring(0, maxlimit); 
		//alert('You have reached the maximum ' + maxlimit + ' characters.'); 
		raiseMessage('stoperror', 'You have reached the maximum ' + maxlimit + ' characters.', field.id);
		return (false); // Prevent the keypress occurring 
	} 
}


function ResetTimeout()
{
	debug_print('ResetTimeout | '+window.parent.document.all.hidCountdown.value+' | '+window.parent.document.all.hidTimeout.value);
	window.parent.document.all.hidCountdown.value = window.parent.document.all.hidTimeout.value;
}

function TimeFormat(sText) 
{
	var sT = sText.value;
	var lHours = 0;
	var lMins = 0;

	sT = '0000' + sT;
	sT = sT.substr(sT.length - 5, 5);
	
	if (sT.indexOf(':') == -1) {
		sT = sT.substr(sT.length - 4, 2) + ':' + sT.substr(sT.length - 2, 2);
	}
	
	lHours = sT.substr(0,2)/1;
	lMins = sT.substr(3,2)/1;
	
	if (isNaN(lHours)){
		lHours = 0;
	}else{
		if (lHours>23){
			lHours = 0;
		}			
	}

	if (isNaN(lMins)){
		lMins = 0;
	}else{
		if (lMins>59){
			lMins = 0;
		}
	}
 
	lHours = '00' + lHours;
	lHours = lHours.substr(lHours.length - 2, 2);
	
	lMins = '00' + lMins;
	lMins = lMins.substr(lMins.length - 2, 2);

	sText.value = lHours + ':' + lMins;
}

function pre_load_images() 
{
	
	if (document.images) {
		//Create an image array if there isn't one already
		if (!document.image_array) {
			document.image_array = new Array();
		}
		//Find out how big it is
		var image_count = document.image_array.length;
		//Get an array of the strings passed in to this procedure
		document.argument_array = pre_load_images.arguments;
		//If the string isn't already there, add it
		for (i=0; i < document.argument_array.length; i++) {
			if (document.argument_array[i].indexOf("#")!=0) 
			{
			    debug_print('pre_load_image : '+document.argument_array[i]);
				document.image_array[image_count] = new Image;
				document.image_array[image_count++].src = document.argument_array[i];
			}
		}
	}
}

function image_restore(e) 
{ 
	if(!e)
	{
		e = window.event;
	}
	
	var objSrcElement = (e.target) ? e.target : e.srcElement;
	if (document.old_image != '') 
	{
		var image_path = objSrcElement.src;
		if (image_path.substr(image_path.length-6,3) == 'on.') 
		{
			objSrcElement.src = document.old_image;
		}
	}
}

function image_swap(e) 
{ 
	if(!e)
	{
		e = window.event;
	}
	var objSrcElement = (e.target) ? e.target : e.srcElement;
	var image_path = objSrcElement.src;
	var image_ext = image_path.substr(image_path.length-3,3);
	//If it is currently an off image, change to an on image, and store the old image
	if (image_path.substr(image_path.length-7,3) == 'off') {
		document.old_image = image_path;
		image_path = image_path.substr(0,image_path.length-7) + 'on.'+image_ext;
		objSrcElement.src = image_path;		
	}	
}

function Print() {
	self.print();
}

function Help(page) {
	window.open('help/' + page);
}

function changeButtonImage(That){
	
	if(That.innerHTML!=''&&That.children.length>1){
		var sImgIcon = That.children(0).src;
		var sImgText = That.children(1).src;
	
		if(sImgIcon.substr(sImgIcon.length-7,7)!='_on.gif'){
			sImgIcon = sImgIcon.substr(0,sImgIcon.length-4) + '_on.gif';
			sImgText = sImgText.substr(0,sImgText.length-4) + '_on.gif'}
		else{
			sImgIcon = sImgIcon.substr(0,sImgIcon.length-7) + '.gif';
			sImgText = sImgText.substr(0,sImgText.length-7) + '.gif'
		}
		That.children(0).src = sImgIcon;
		That.children(1).src = sImgText;
	}
	else{
		var sImg = '' ;
		
		if(That.src!=undefined){
			sImg = That.src;
		}
		
		
		if(sImg.substr(sImg.length-7,7)!='_on.gif'){
			sImg = sImg.substr(0,sImg.length-4) + '_on.gif';}
		else{
			sImg = sImg.substr(0,sImg.length-7) + '.gif';
		}
		
		That.src = sImg;
	}
}

function changePngButtonImage(That){

	if(That.innerHTML!=''&&That.children.length>1){
		var sImgIcon = That.children(0).src;
		var sImgText = That.children(1).src;
	
		if(sImgIcon.substr(sImgIcon.length-9,9)!='_over.png'){
			sImgIcon = sImgIcon.substr(0,sImgIcon.length-4) + '_over.png';
			sImgText = sImgText.substr(0,sImgText.length-4) + '_over.png'}
		else{
			sImgIcon = sImgIcon.substr(0,sImgIcon.length-9) + '.png';
			sImgText = sImgText.substr(0,sImgText.length-9) + '.png'
		}
		That.children(0).src = sImgIcon;
		That.children(1).src = sImgText;
	}
	else{
		var sImg = '' ;
		
		if(That.src!=undefined){
			sImg = That.src;
		}
		
		
		if(sImg.substr(sImg.length-9,9)!='_over.png'){
			sImg = sImg.substr(0,sImg.length-4) + '_over.png';}
		else{
			sImg = sImg.substr(0,sImg.length-9) + '.png';
		}
		
		That.src = sImg;
	}
}

// Over class name functions
function Over(That)
{
	That.className=That.className + 'Over';
	
}
function Out(That)
{
	if (That.className.substr(That.className.length-4,4)=='Over'){
		That.className=That.className.substr(0,That.className.length-4);
	}
	
}

function menuOver(That) {
	That.className=That.className + 'Over';
	changeButtonImage(That);
	
}
function menuOut(That) {
	if (That.className.substr(That.className.length-4,4)=='Over') {
		That.className=That.className.substr(0,That.className.length-4);
		changeButtonImage(That);
	}
	
}

function numeric_keypress(e, that, isFloat, minimum, maximum, onEnterFunction)
{
    var intKeyCode = (e.which?e.which:e.keyCode);
    if((intKeyCode > 47)&&(intKeyCode < 58))
    {
        return true;
    }
    if(intKeyCode == 13)
    {
		if(onEnterFunction)
		{
			eval(onEnterFunction);
		}
        return false;
    }
    else if(intKeyCode == 43)
    {
		that.value = parseFloat(that.value) + 1;
		if((typeof(maximum) != 'undefined')&&(maximum != null))
		{
			if(parseFloat(that.value) > maximum)
			{
				that.value = maximum;
			}
		}
        return false;
    }
    else if((intKeyCode == 95) || (intKeyCode == 45))
    {
		that.value = parseFloat(that.value) - 1;
		if((typeof(minimum) != 'undefined')&&(minimum != null))
		{
			if(parseFloat(that.value) < minimum)
			{
				that.value = minimum;
			}
		}
        return false;
    }
    else if((intKeyCode == 46) || (intKeyCode == 62))
    {
		if(isFloat)
		{
			if(that.value.indexOf('.') > -1)
			{
				return false;
			}
			return true;
		}
		else
		{
			return false;
		}
    }
    else if(intKeyCode == 27)
    {
		that.value = 0;
        return false;
    }
    
    window.status = 'Invalid keypress ' + intKeyCode;
        
    return false;
}

function currency_keypress(e, that, minimum, maximum, onEnterFunction)
{
    var intKeyCode = (e.which?e.which:e.keyCode);
    var value = toNumericValue(that.value);
    var originalValue = value;
    
    if((intKeyCode > 47)&&(intKeyCode < 58))
    {
        return true;
    }
    if(intKeyCode == 13)
    {
		if(onEnterFunction)
		{
			if(originalValue != value)
			{
				that.value = formatCurrency(value);
			}
			eval(onEnterFunction);
		}
        return false;
    }
    else if(intKeyCode == 43)
    {
		value = value + 1;
		if((typeof(maximum) != 'undefined')&&(maximum != null))
		{
			if(value > maximum)
			{
				value = maximum;
			}
		}
		
		if(originalValue != value)
		{
			that.value = formatCurrency(value);
		}
        return false;
    }
    else if((intKeyCode == 95) || (intKeyCode == 45))
    {
		value = value - 1;
		if((typeof(minimum) != 'undefined')&&(minimum != null))
		{
			if(value < minimum)
			{
				value = minimum;				
			}
		}
		
		if(originalValue != value)
		{
			that.value = formatCurrency(value);
		}
        return false;
    }
    else if((intKeyCode == 46) || (intKeyCode == 62))
    {
		if(that.value.indexOf('.') > -1)
		{
			return false;
		}
		return true;		
    }    
    else if(intKeyCode == 27)
    {
		that.value = '£0.00';
        return false;
    }
    
    window.status = 'Invalid keypress ' + intKeyCode;
        
    return false;
}



function showContextMenu(e, menuId, hidMenuContextId, strCommandArgument)
{
	var menu = document.getElementById(menuId);
	var isRightClick;
	
	if(menu != null)
	{
		if(!e)
		{
			e = window.event;
		}
	
		if (e.which) isRightClick = (e.which == 3);
		else if (e.button) isRightClick = (e.button == 2);

		if((e.type == 'contextmenu')||(isRightClick))
		{	
			var hidMenuContext = document.getElementById(hidMenuContextId);


			hidMenuContext.value = strCommandArgument;
			var menuOffset = 2
			menu.style.left = e.x - menuOffset;
			menu.style.top = e.y - menuOffset;
			menu.style.display = '';
			e.cancelBubble = true;
		    
			return false;
		}
    }
    
    return true;
}

function toNumericValue(value)
{
	var intLength = value.length;
	var newValue = '';
	var currentChar = '';
	var foundDecimalPoint = false;
	
	for(var intIndex = 0; intIndex < intLength; intIndex++)
	{
		currentChar = value.charAt(intIndex);
		
		switch(currentChar)
		{
			case '1':
			case '2':
			case '3':
			case '4':
			case '5':
			case '6':
			case '7':
			case '8':
			case '9':
			case '0':
			
				newValue += currentChar;
				break;
				
			case '.':
				
				if(foundDecimalPoint == false)
				{
					newValue += new String(currentChar);
					foundDecimalPoint = true;
				}
				else
				{
					intIndex = intLength;
				}
				break;
			
		}
	}		
	
	if (newValue == '')
	{
		return 0;
	}
	
	return parseFloat(newValue);
}

function formatCurrency(num) 
{
	var num = num.toString().replace(/\£|\,/g,'');
	if(isNaN(num))
		num = '0';
	
	var sign = (num == (num = Math.abs(num)));
	var num = Math.floor(num*100+0.50000000001);
	var pence = num%100;
	var num = Math.floor(num/100).toString();
	
	if(pence<10)
		pence = '0' + pence;
		
/*		
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		num = num.substring(0,num.length-(4*i+3))+ ',' +
				num.substring(num.length-(4*i+3));*/
				
	return (((sign)?'':'-') + '£' + num + '.' + pence);
}


function trapESC(menu)
{
	var key = window.event.keyCode;
	if (key == 27)
	{
		menu.style.display = 'none';
	}
}

// Calculates the object's absolute position, and width and height
function GetAbsPosition(object)
{
	var position = new Object;
	position.x = 0;
	position.y = 0;

	if(object) 
	{
		position.x = object.offsetLeft;
		position.y = object.offsetTop;
		
		if(object.offsetParent) 
		{
			var parentpos = GetAbsPosition(object.offsetParent);
			position.x += parentpos.x;
			position.y += parentpos.y;
		}
	}

	position.cx = object.offsetWidth;
	position.cy = object.offsetHeight;

	return position;
}


function getOffset(that)
{

    //nicked from quirksmode.org
	var curleft = curtop = 0;
	if (that.offsetParent) 
	{
		curleft = that.offsetLeft
		curtop = that.offsetTop
		while (that = that.offsetParent) 
		{
			curleft += that.offsetLeft
			curtop += that.offsetTop
		}
	}
	return [curleft,curtop];
}

/*********************************************
*Parent control id functions
*********************************************/

function getParentId(id)
{
    //returns the id of the parent control from a child control id.
    //e.g. 
    var iIndexOf = 0;
    var sCtl = new String();
    sCtl = id;

    while(sCtl.indexOf('_',iIndexOf + 1) != -1)
    {
        iIndexOf = sCtl.indexOf('_',iIndexOf + 1);
    }	
    
    return sCtl.slice(0,iIndexOf);   
}


/*********************************************
*Tooltip functions
*********************************************/

function tooltip_show(that, html)
{
    if(that.readOnly){
        return;
    }
    
    var pos = new Array();
    pos = getOffset(that);
    
    try
    {
		debug_print('Tooltip_show | '+html+':')
		tooltip.absShow(html, pos[1]-20, pos[0]);
    }
	catch (e)
	{
	}
	
}

function getOffset(that)
{
	debug_print('getOffset | '+that.id);
    //nicked from quirksmode.org
	var curleft = curtop = 0;
	if (that.offsetParent) 
	{
		curleft = that.offsetLeft
		curtop = that.offsetTop
		while (that = that.offsetParent) 
		{
			curleft += that.offsetLeft
			curtop += that.offsetTop
		}
	}
	debug_print('getOffset | curleft | '+curleft);
	debug_print('getOffset | curtop | '+curtop);
	return [curleft,curtop];
}

/******
* Based on [ubertooltip.js] v1.0
* 2001-01-20
* Author: chrisken
* URL: http://www.cs.utexas.edu/users/chrisken/ubertooltip.html
* Supports: opacifier.js
***/
function doLoad() { 
	var sTooltip;
	sTooltip = '<div id="divTooltip" ';
	sTooltip += 'class="tooltip" ';
	sTooltip += '>';
 
    var oTooltip = document.createElement(sTooltip)
    document.body.insertBefore(oTooltip);
	tooltip = new overToolTip("divTooltip", 1); 
	tooltip.init();
}

function overToolTip(id, delay)
{
	this.id = id;
	this.mouseX = 0;
	this.mouseY = 0;
	this.updateToolTip = false;
	this.obj = null;
	this.fader = null;
	this.delay = delay || 500;
	this.getMouseX = function() { return this.mouseX; }
	this.getMouseY = function() { return this.mouseY; }
	this.show = function(html, top, left)
	{
		if (document.layers) return;
		showLayer(this.id);
		if (this.fader)	{ this.fader.setTrans(0); this.fader.fadeIn(); }
		this.obj.innerHTML = html;
		this.updateToolTip = true;
		this.update(top, left);
	}
	this.absShow = function(html, top, left)
	{
		if (document.layers) return;
		showLayer(this.id);
		if (this.fader)	{ this.fader.setTrans(0); this.fader.fadeIn(); }
		this.obj.innerHTML = html;
		this.updateToolTip = true;
		this.absUpdate(top, left);
	}
	this.update = function(top, left)
	{
		this.mouseX = window.event.clientX;
		this.mouseY = window.event.clientY;
		switch (top) {
		case '':
			this.obj.style.left = (this.mouseX + 5) + "px";
			this.obj.style.top = (this.mouseY - 20) + "px";
			break;
		default:
			var num_top = parseInt(top);
			var num_left = parseInt(left);
			this.obj.style.left = (this.mouseX + num_top) + "px";
			this.obj.style.top = (this.mouseY + num_left) + "px";
		}
	}
	this.absUpdate = function(abs_top, abs_left)
	{
		switch (abs_top) {
		case '':
			this.obj.style.left = (this.mouseX + 5) + "px";
			this.obj.style.top = (this.mouseY - 20) + "px";
			break;
		default:
			var num_top = parseInt(abs_top);
			var num_left = parseInt(abs_left);
			this.obj.style.top = num_top.toString() + "px";
			this.obj.style.left = num_left.toString() + "px";
		}
	}
	this.hide = function()
	{
		if (document.layers) return;
		this.updateToolTip = false;
		if (this.fader) this.fader.setTrans(0);
		this.obj.innerHTML = "";
		this.obj.style.left = this.obj.style.top = "0px";
		hideLayer(this.id);
	}
	this.init = function()
	{
		this.obj = document.getLayer(this.id);
		if (this.obj == null) alert('Error: tooltip layer initialized to "' + this.id + '",\nbut a <div> with that id does not exist.');
		if (window.Opacifier)
		{
			this.fader = new Opacifier(this.id, this.delay, 100, 0, null, 10);
			this.fader.setTrans(0);
			this.fader.stop();
			this.fader.norepeat();
		}	
	}
	this.mouseMove = function( e )
	{
		var mouseX, mouseY;
		if (typeof(event) != "undefined")
		{
			mouseX = event.clientX - orvset;
			mouseX +=  document.body.scrollLeft;	
			mouseY = event.clientY;
			mouseY += document.body.scrollTop;
		}
		else
		{
			mouseX = e.pageX;
			mouseY = e.pageY + 10;
		}
		this.mouseX = mouseX;
		this.mouseY = mouseY;
		if (this.obj != null && this.updateToolTip) this.update('');
	}
	this.edit = function(url,ref)
	{
		//window.open('admin/tooltip_edit.aspx?url=' + url + '&ref=' + ref)
		var str = window.showModalDialog('tooltip_edit.aspx?url=' + url + '&ref=' + ref,null,"center:yes;font-size:10px;dialogWidth:60;dialogHeight:20;help:off;status:off;scroll:off");
		//reload window if dialog not cancelled
		alert('return value = ' + str);
		//self.location.reload();
	}
	return this;
}
/*********************************************
*END Tooltip functions
*********************************************/

/*********************************************
*MINI DHTML Library functions
*********************************************/
// mini-dhtml library, intentionally doesn't support NS 4

if (!document.getElementById){
	if (document.all) document.getElementById = function(id){return (document.all[id]? document.all[id] : false );}
	if (document.layers) document.getElementById = function(id,parentObj){
		if(document.layers[id]){
			document.layers[id].style = document.layers[id];
			document.layers[id].d = document.layers[id].document;
			return document.layers[id];
		}
		return false;
	}
}
document.getLayer = document.getElementById;

function showLayer( id )
{
	if (!document.layers) document.getLayer(id).style.visibility = "visible";
}

function hideLayer( id )
{
	if (!document.layers) document.getLayer(id).style.visibility = "hidden";
}

/*********************************************
*END MINI DHTML Library functions
*********************************************/


function sDate(thedate) {
	var sMonth = thedate.getMonth();
	switch (sMonth) {
	case 0:
		sMonth = ' January ';
		break;
	case 1:
		sMonth = ' February ';
		break;
	case 2:
		sMonth = ' March ';
		break;
	case 3:
		sMonth = ' April ';
		break;
	case 4:
		sMonth = ' May ';
		break;
	case 5:
		sMonth = ' June ';
		break;
	case 6:
		sMonth = ' July ';
		break;
	case 7:
		sMonth = ' August ';
		break;
	case 8:
		sMonth = ' September ';
		break;
	case 9:
		sMonth = ' October ';
		break;
	case 10:
		sMonth = ' November ';
		break;
	case 11:
		sMonth = ' December ';
		break;
	}
	return thedate.getDate() + sMonth + thedate.getFullYear();
}

function sDateTime(thedate) {
	
	var sMonth = thedate.getMonth();
	switch (sMonth) {
	case 0:
		sMonth = ' January ';
		break;
	case 1:
		sMonth = ' February ';
		break;
	case 2:
		sMonth = ' March ';
		break;
	case 3:
		sMonth = ' April ';
		break;
	case 4:
		sMonth = ' May ';
		break;
	case 5:
		sMonth = ' June ';
		break;
	case 6:
		sMonth = ' July ';
		break;
	case 7:
		sMonth = ' August ';
		break;
	case 8:
		sMonth = ' September ';
		break;
	case 9:
		sMonth = ' October ';
		break;
	case 10:
		sMonth = ' November ';
		break;
	case 11:
		sMonth = ' December ';
		break;
	}
	return thedate.getDate() + sMonth + thedate.getFullYear() + ' ' + thedate.getHours() + ':' + thedate.getMinutes();
}

function getElementbyClass(rootobj, classname){
	var temparray=new Array();
	var inc=0;
	for (i=0; i<rootobj.length; i++){
	if (rootobj[i].className==classname)
	temparray[inc++]=rootobj[i];
	}
	return temparray;
}

var tmrReset = null;
var blnFormDisabled = false;

function formDisable(bDisable)
{
	debug_print('formDisable | '+bDisable);

	//var main_window = window.top.frames['main'];
	var main_window = window;
	//var menu_window = window.top.frames['sideBar'];
	//var header_window = window.top.frames['header'];
	
	if (main_window.document.getElementsByTagName('body'))
	{
		var aBody = main_window.document.getElementsByTagName('body');
		try
		{
		    aBody[0].setActive();
		}
		catch(ex){}
	}
	
	formFrameDisable(main_window, bDisable);
	//formFrameDisable(menu_window, bDisable);
	//formFrameDisable(header_window, bDisable);
}

function formFrameDisable(main_window, bDisable)
{

	if (main_window)
	{
	    var divMainProtect = main_window.document.getElementById('divMainProtect');
	    
		if (divMainProtect == null)
		{
			divMainProtect = main_window.document.createElement('div');
			divMainProtect.id = 'divMainProtect';
			divMainProtect.className = 'divProtect';	
            divMainProtect.style.width='0';
            divMainProtect.style.height='0';	
            divMainProtect.style.display='none';
            divMainProtect.style.top='0';	
            divMainProtect.style.left='0';
            divMainProtect.style.position='absolute';
            /*
            if(main_window.document.getElementById('base'))
            {
				main_window.document.getElementById('base').appendChild(divMainProtect);
			}
			else
			{	//Page has probably not rendered correctly therefore fall back to using body.
				main_window.document.body.appendChild(divMainProtect);
			}
			*/
			main_window.document.body.appendChild(divMainProtect);
							
		}
		
		if((bDisable==false)||(bDisable=='false'))
		{
			blnFormDisabled = false;
			divMainProtect.style.display = 'none';
			//new Effect.Fade(divMainProtect, {duration: .2, queue: 'end'});
            divMainProtect.style.width='0';
            divMainProtect.style.height='0';		
            
            tmrReset = setTimeout('resetProtectSize()', 200)	
		}
		else if(blnFormDisabled == false)
		{			
		    //divMainProtect.style.width = '100%';
			//divMainProtect.style.height = '100%';
			blnFormDisabled = true;
			divMainProtect.style.width = getDocumentWidth();
			divMainProtect.style.height = getDocumentHeight();
			divMainProtect.style.display = 'block';
			//new Effect.Appear(divMainProtect, {duration: .4, queue: 'end'});
		}
	}
}

function resetProtectSize()
{
	var main_window = window;
	var divMainProtect = main_window.document.getElementById('divMainProtect');
	
	divMainProtect.style.width='0';
    divMainProtect.style.height='0';
    
    tmrReset = null;
}

function getDocumentHeight()
{
	//TODO: check browser compatablity
	if ((document.body)&&(document.body.scrollHeight))
		return (document.body.scrollHeight)+ 'px';
	else
		return '100%'		
		
}

function getDocumentWidth()
{
	//TODO: check browser compatablity
	if ((document.body)&&(document.body.scrollWidth))
		return (document.body.scrollWidth)+ 'px';
	else
		return '200%'	
}

function setText(textbox_id, text)
{
	debug_print('setText |' + textbox_id + ' to ' + text + '');
	if(document.getElementById(textbox_id))
	{
		document.getElementById(textbox_id).value = text;
		return true;
	}
	else
	{
		return false;
	}
}


function toNormalCase(this_string, word_seperator, all_words)
{
/*
*toNormalCase sets the first letter of one or more words to capital
*
* this_string    - string ('')     - The string to be capitalised
* word_seperator - string (' ')    - Character between words 
* all_words      - boolean (false) - False capitalises first word only, true capitalises all words
*/
    //Init vars
    var first_letter = new String();
    var other_letters = new String();
    var temp_string = new String();
    //check parameters
    if (word_seperator==null)
    {
        word_seperator = ' ';
    }
    if (all_words!=true)
    {
        all_words=false
    }
    this_string = this_string.toLowerCase();
    //All words or just the first?
    if (all_words)
    {
        //Capitalise all words
        var temp_words = new Array();
        temp_words = this_string.split(word_seperator);
        var word_num = 0;
        //Iterate through words
        for (word_num = 0; word_num<temp_words.length; word_num++)
        {
            first_letter = temp_words[word_num].charAt(0);
            other_letters = temp_words[word_num].substring(1,temp_words[word_num].length);
            first_letter = first_letter.toUpperCase();
            if (temp_string=='')
            {
                temp_string += first_letter + other_letters
            }
            else
            {
                temp_string += word_seperator + first_letter + other_letters
            }
        }
    }
    else
    {
        //Capitalise first word only
        first_letter = this_string.charAt(0);
        other_letters = this_string.substring(1,this_string.length);
        first_letter = first_letter.toUpperCase();
        temp_string = first_letter + other_letters
    }
    return (temp_string);
}

function isMaxLength(that, maxLength)
{
    if (that.value.length > maxLength)
        that.value = that.value.substring(0, maxLength - 1)
}

function isValidDecimalPercent(that, min, max)
{
    /*
    Returns a boolean based on whether the value passed in is a number and is between the min and max values.
        true - if all criteria were met
        false - if any of the criteria were not met. 
    */
    var return_value = true;
    if (isNaN(that))
    {
            return_value = false;
    }
    else
    {
        if (that > max || that < min)
        {
            return_value = false;
        }
        if (that.indexOf('.')>-1)
        {
            var this_value = that.toString();
            var value_array = new Array();
            value_array = this_value.split('.');
            //alert(value_array.length);
            if (value_array.length > 0)
            {
                var decimal_part = value_array[1].toString();
                //alert(decimal_part);
            
                if (decimal_part.length > 2)
                {
                    return_value = false;
                }
            }
        }
    }
    return return_value;
}

function focusFirst() {
	//focus the first text input
	//var els = document.forms[0].elements;
	var els=document.getElementsByTagName('input');
	try {
		for(var i=0;els.length-1;i++) {
			if(els[i].type == 'text') {
				if(!els[i].disabled && !els[i].readOnly) {
					els[i].focus()
					document.execCommand("selectAll",false);
					break;
				}
			}
		}	
	}
	catch(e) {}
}

function disableContextMenu()
{
    return false;
}

function isDate(p_Expression){
	return !isNaN(new Date(p_Expression));		// <<--- this needs checking
}

function closeDatePicker()
{
	if(datePickerDivID!='' && datePickerDivID!=undefined)
	{
	  var pickerDiv = document.getElementById(datePickerDivID);
	  pickerDiv.style.visibility = "hidden";
	  pickerDiv.style.display = "none";
	  adjustiFrame();
	}
}





function lTrim(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function rTrim(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}
/*
function addToClassName(control, className)
{
    if((control)&&(className)&&(control.className))
    {
        var classNames = control.className.split(' ');
        
        for(int index = 0; index < classNames.length; index++)
        {
            if(classNames[index] == className)
            {
                // The control already has this classname.
                return;
            }
        }
        
        control.className = control.className + ' ' + className;
    
    }
}

function removeFromClassName(control, className)
{
    if((control)&&(className)&&(control.className))
    {
        var classNames = control.className.split(' ');
        var rebuiltClassName = '';
        
        for(int index = 0; index < classNames.length; index++)
        {
            if(classNames[index] != className)
            {
                rebuiltClassName = rebuiltClassName + ' ' + classNames[index];
            }
        }
        
        control.className = rebuiltClassName;
        
    }
}
*/


function selectAllText(that)
{
	that.select();
}

function padLeft(expression, length, paddingChar)
{
	var value = new String(expression);
	
	if ((paddingChar == undefined)||(paddingChar == null)||(paddingChar.length == 0))
	{
		paddingChar = ' ';
	}
		
	while(value.length < length)
	{
		value = paddingChar + value;
	}
	
	
	return value;
}


function padRight(expression, length, paddingChar)
{
	var value = new String(expression);
	
	if ((paddingChar == undefined)||(paddingChar == null)||(paddingChar.length == 0))
	{
		paddingChar = ' ';
	}
	
	while(value.length < length)
	{
		value = value + paddingChar;
	}
	
	
	return value;
}


function addEvent(elm, evType, fn, useCapture) 
{
    // cross-browser event handling for IE5+, NS6 and Mozilla
    // By Scott Andrew
    if (elm.addEventListener) 
    {
      elm.addEventListener(evType, fn, useCapture);
      return true;
    } 
    else if (elm.attachEvent) 
    {
      var r = elm.attachEvent('on' + evType, fn);
      return r;
    } 
    else 
    {
      elm['on' + evType] = fn;
    }
}


/*
    Written by Jonathan Snook, http://www.snook.ca/jonathan
    Add-ons by Robert Nyman, http://www.robertnyman.com
*/
function getElementsByClassName(oElm, strTagName, strClassName)
{
    var arrElements = (strTagName == "*" && document.all)? document.all : oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    strClassName = strClassName.replace(/\-/g, "\\-");
    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
    var oElement;
    for(var i=0; i<arrElements.length; i++)
    {
        oElement = arrElements[i];      
        if(oRegExp.test(oElement.className))
        {
            arrReturnElements.push(oElement);
        }   
    }
    return (arrReturnElements)
}

var curelem = '';

MenuHover = function() 
{
    var objMenus = getElementsByClassName(document.body, "ul", "CascadeMenu");
	for (var i=0; i<objMenus.length; i++) 
	{
	    var objItems = objMenus[i].getElementsByTagName("li");
	    for (var x=0; x<objItems.length; x++) 
	    {   
		    objItems[x].onmouseenter=function() 
		    {
			    this.className+=" MenuItemHover";
		    }
		    objItems[x].onmouseleave=function() 
		    {
		    
			    //this.className=this.className.replace(new RegExp(" MenuItemHover\\b"), "");
                this.timer = new Timer(this);
                this.timer.setTimeout("out",300);			    
		    }
            objItems[x].out=function() {
                this.className=this.className.replace(new RegExp(" MenuItemHover\\b"), "");
            }		    
		}
	}
}



/* TIMER IS FOR MENU CASCADE */

// The constructor should be called with
// the parent object (optional, defaults to window).

function Timer(){
    this.obj = (arguments.length)?arguments[0]:window;
    return this;
}

// The set functions should be called with:
// - The name of the object method (as a string) (required)
// - The millisecond delay (required)
// - Any number of extra arguments, which will all be
//   passed to the method when it is evaluated.

Timer.prototype.setInterval = function(func, msec){
    var i = Timer.getNew();
    var t = Timer.buildCall(this.obj, i, arguments);
    Timer.set[i].timer = window.setInterval(t,msec);
    return i;
}
Timer.prototype.setTimeout = function(func, msec){
    var i = Timer.getNew();
    Timer.buildCall(this.obj, i, arguments);
    Timer.set[i].timer = window.setTimeout("Timer.callOnce("+i+");",msec);
    return i;
}

// The clear functions should be called with
// the return value from the equivalent set function.

Timer.prototype.clearInterval = function(i){
    if(!Timer.set[i]) return;
    window.clearInterval(Timer.set[i].timer);
    Timer.set[i] = null;
}
Timer.prototype.clearTimeout = function(i){
    if(!Timer.set[i]) return;
    window.clearTimeout(Timer.set[i].timer);
    Timer.set[i] = null;
}

// Private data

Timer.set = new Array();
Timer.buildCall = function(obj, i, args){
    var t = "";
    Timer.set[i] = new Array();
    if(obj != window){
        Timer.set[i].obj = obj;
        t = "Timer.set["+i+"].obj.";
    }
    t += args[0]+"(";
    if(args.length > 2){
        Timer.set[i][0] = args[2];
        t += "Timer.set["+i+"][0]";
        for(var j=1; (j+2)<args.length; j++){
            Timer.set[i][j] = args[j+2];
            t += ", Timer.set["+i+"]["+j+"]";
    }}
    t += ");";
    Timer.set[i].call = t;
    return t;
}
Timer.callOnce = function(i){
    if(!Timer.set[i]) return;
    eval(Timer.set[i].call);
    Timer.set[i] = null;
}
Timer.getNew = function(){
    var i = 0;
    while(Timer.set[i]) i++;
    return i;
}


function compatModalDialog(url, width, height) {
    if(window.showModalDialog)
    {
		window.showModalDialog(url,window,
			"dialogWidth:"+width+"px;dialogHeight:"+height+"px;edge:Raised;center:1;help:0;resizable:1;maximize:1;status:0");    
    }
    else
    {
		var left = screen.availWidth/2 - width/2;
		var top = screen.availHeight/2 - height/2;
		document.activeModalWin = window.open(url, "", "status=no,width="+width+",height="+height+",left="+left+",top="+top);
		window.onfocus = function(){if (document.activeModalWin.closed == false){document.activeModalWin.focus();};};    
    }
}



addEvent(window, 'load', MenuHover, false);


function submitForm(strEmail, strName, strAction) 
{

	//Validate name if exists
	if (strName) {
	    var objEl = document.getElementById(strName);
		if (objEl.value == '') {
			alert('Please enter your name');
			objEl.className = "TagHighLight";
			objEl.focus();
			return false;
		}
		else {
		    objEl.className = "";
		}
	}	
	
	//Validate email if exists
	if (strEmail) {
	    var objEl = document.getElementById(strEmail);
		if (objEl.value=='' || !isEmail(objEl.value)) {
			alert('Please enter a valid email address');
			objEl.className = "TagHighLight";
			objEl.focus();
			return false;
		}
		else {
		    objEl.className = "";
		}		
	}


	//change action on form and submit
	if(strAction) {
		document.forms[0].action = strAction;
		document.forms[0].submit();
		return false;
	}

}

// add option to select box
function appendToSelect(objselect, value, content) 
{
    var opt;
    opt = document.createElement("option");
    opt.value = value;
    opt.appendChild(document.createTextNode(content)) 
    objselect.appendChild(opt);
}

function GetXmlNodeText(node)
{ 
    if(node && node.text)
    { 
        return node.text; 
    }
    else if(node && node.textContent)
    { 
        return node.textContent; 
    } 
    else
    {
		return '';
    }
}

function getXmlString(xmlDoc)
{
	if(typeof(xmlDoc.xml) == 'string')
	{
		return xmlDoc.xml;
	}
	else
	{
		//create a new XMLSerializer
        var objXMLSerializer = new XMLSerializer();
        
        //get the XML string
        return objXMLSerializer.serializeToString(xmlDoc);
	}
	
}

function QuickSearch(strAction)
{
	document.forms[0].action=strAction;
	var d = document.getElementById('__VIEWSTATE');
	if(d) 
	{ 
	    d.parentElement.removeChild(d);
	}
	document.forms[0].submit();
}
function QuickSearchEnterSubmit(strAction) 
{
	if (window.event && window.event.keyCode == 13)
	{
		QuickSearch(strAction);
	}
	else
	{
		return true;
	}
}

/* JAVASCRIPT INCLUDE .JS FILE */
var included_files = new Array();

function include_dom(script_filename) 
{
    var html_doc = document.getElementsByTagName('head').item(0);
    var js = document.createElement('script');
    js.setAttribute('language', 'javascript');
    js.setAttribute('type', 'text/javascript');
    js.setAttribute('src', script_filename);
    html_doc.appendChild(js);
    return false;
}

function include_once(script_filename) 
{
    if (!in_array(script_filename, included_files)) 
    {
        included_files[included_files.length] = script_filename;
        include_dom(script_filename);
    }
}

function in_array(needle, haystack) 
{
    for (var i = 0; i < haystack.length; i++) 
    {
        if (haystack[i] == needle) 
        {
            return true;
        }
    }
    return false;

}



var mobjRepeat;
var mobjItems;
var mintCurrent = 0;
var mstrTitle = '';
var mobjTitle;

AnnouncementsPanel = function() 
{
    mobjRepeat = getElementsByClassName(document.body, "ul", "Announcements");
	for (var i=0; i<mobjRepeat.length; i++) 
	{
	    mobjItems = mobjRepeat[i].getElementsByTagName("li");
	    for (var x=0; x<mobjItems.length; x++) 
	    {   
		    mobjItems[x].style.display = 'none';	    
		}
		if(mobjItems) {
		    mobjTitle = mobjItems[0];
		    mstrTitle = mobjTitle.childNodes[0].innerHTML;
		    
		    
		}
	}
	this.timer = new Timer(this);
	this.hideAdd = function() {
	    if(mobjItems) {
	        //new Effect.Fade(mobjItems[mintCurrent], {duration: 1});
	        //new Effect.DropOut(mobjItems[mintCurrent], {duration: 2});
	        new Effect.DropOut(mobjItems[mintCurrent], {duration: 1});
	        //new Effect.SwitchOff(mobjItems[mintCurrent], {duration: 1});
	        //new Effect.Puff(mobjItems[mintCurrent], {duration: 1});
	    }
	}
	this.showAnn = function() {
	    if(mobjItems) {
	        
	        new Effect.Appear(mobjItems[mintCurrent], {duration: 1});
	        
	        mobjTitle.childNodes[0].innerHTML = mstrTitle + ' (' + mintCurrent + '/' + (mobjItems.length-1) + ')';
	        mobjItems[0].innerHTML = mobjTitle.innerHTML;
	        
	        //new Effect.BlindDown(mobjItems[mintCurrent], {duration: 1});
	        new Effect.SlideDown(mobjItems[mintCurrent], {duration: 1});
	        //new Effect.Shake(mobjItems[mintCurrent], {delay:2,duration: 1});
	        this.timer.setTimeout("nextAnn",6000);
	    }
	}
	this.nextAnn = function() {
	    if(mobjItems) {
	        this.hideAdd();
	        mintCurrent++;
	        if(mintCurrent>=mobjItems.length)
	        {
	            mintCurrent=1;
	        }
	        this.timer.setTimeout("showAnn",2000);
	    }
	}
	if(mobjItems) {
	    //always display the header (first list item)
	    mobjItems[0].style.display = 'block';
	    mintCurrent++;
	   this.timer.setTimeout("showAnn",0);
	}	

}

addEvent(window, 'load', AnnouncementsPanel, false);


//check if the previous sibling node is an element node
function get_previoussibling(n)
{
	if((typeof(n) != 'undefined')&&(n != null))
	{
		var x = n.previousSibling;
		while ((n != null)&&(x.nodeType != 1))
		{
			x = x.previousSibling;
		}
		return x;
	}
	return null;
	
	/*
	Note: Internet Explorer will skip white-space text nodes that are generated between nodes (e.g. new-line characters), while Mozilla will not. So, in the example below, we have a function that checks the node type of the previous sibling node.

	Element nodes has a nodeType of 1, so if the previous sibling node is not an element node, it moves to the previous node, and checks if this node is an element node. This continues until the previous sibling node (which must be an element node) is found. This way, the result will be correct in both Internet Explorer and Mozilla.

	*/
}


function restoreScrollPosition()
{//debugger;
	var hidScrollPositionX = document.getElementById('__SCROLLPOSITIONX');
	var hidScrollPositionY = document.getElementById('__SCROLLPOSITIONY');
	if((!blnCancelRestoreScrollPosition)&&(hidScrollPositionX)&&(hidScrollPositionY))
	{
		//window.scrollTo(hidScrollPositionX.value, hidScrollPositionY.value);
		if(scrollWindowInterval != null)
		{
			clearInterval(scrollWindowInterval);
		}

		var cypos = getCurrentYPos();
		var desty = hidScrollPositionY.value;

		scrollWindowStepSize = parseInt((desty-cypos)/25);
		scrollWindowInterval = setInterval('scrollWindow('+scrollWindowStepSize+','+desty+')',10);


	}
	/*else
	{
		window.scrollTo(0, 0);
	}*/
}

var lastYScrollPos = null;
function scrollWindow(scramount,dest)
{
	var wascypos = getCurrentYPos();
	var isAbove = (wascypos < dest);
	
	if(lastYScrollPos != null)
	{
		if(wascypos != lastYScrollPos)
		{
			//user has changed the scroll pos so quit.
			clearInterval(scrollWindowInterval);
			return;
		}
	}
	
	window.scrollTo(0,wascypos + scramount);
	
	var iscypos = getCurrentYPos();
	var isAboveNow = (iscypos < dest);
	lastYScrollPos = iscypos;
	
	if ((isAbove != isAboveNow) || (wascypos == iscypos)) 
	{
		// if we've just scrolled past the destination, or
		// we haven't moved from the last scroll (i.e., we're at the
		// bottom of the page) then scroll exactly to the link
		window.scrollTo(0,dest);
		// cancel the repeating timer
		clearInterval(scrollWindowInterval);
		// and jump to the link directly so the URL's right
		//location.hash = anchor;
	}
}

function getCurrentYPos() 
{
	if (document.body && document.body.scrollTop)
		return document.body.scrollTop;
	if (document.documentElement && document.documentElement.scrollTop)
		return document.documentElement.scrollTop;
	if (window.pageYOffset)
		return window.pageYOffset;
	return 0;
}


function newId() 
{
    try
    {
		//This is the prefered method but only works with MS Browsers.
		//The reason for begin prefered is that the microsoft aproach takes more care about being unique.
		if(ActiveXObject)
		{
			var x = new ActiveXObject("Scriptlet.TypeLib");
			if(x)
			{
				return (x.GUID).substr(1, 36);// Exclude the leading and trailing braces {}
			}			
		}			
    }
    catch (e)
    {
		//Failed to create guid.
		// Fall through to generateGuid()...
    }
    
    
	//Use alternative method.
	return generateGuid();
}


// generateGuid: Author: Richard Shears. Used by browsers other than IE to generate a guid.
function generateGuid()
{
	var strResult = '';
	
	for(var j = 0; j < 32; j++)
	{
		if( j == 8 || j == 12|| j == 16|| j == 20)
		{
			strResult = strResult + '-';
		}
		strResult = strResult + Math.floor(Math.random()*16).toString(16).toUpperCase();
	}
	
	return strResult
}

/*
var ss = {
			fixAllLinks: function() 
			{
				// Get a list of all links in the page
				var allLinks = document.getElementsByTagName('a');
				// Walk through the list
				for (var i=0;i<allLinks.length;i++) 
				{
					var lnk = allLinks[i];
					if ((lnk.href && lnk.href.indexOf('#') != -1) && 
						( (lnk.pathname == location.pathname) ||
						('/'+lnk.pathname == location.pathname) ) && 
						(lnk.search == location.search)) 
					{
						// If the link is internal to the page (begins in #)
						// then attach the smoothScroll function as an onclick
						// event handler
						ss.addEvent(lnk,'click',ss.smoothScroll);
					}
				}
			},

			smoothScroll: function(e) 
			{
				// This is an event handler; get the clicked on element,
				// in a cross-browser fashion
				if (window.event) 
				{
					target = window.event.srcElement;
				} 
				else if (e) 
				{
					target = e.target;
				} 
				else return;

				// Make sure that the target is an element, not a text node
				// within an element
				if (target.nodeType == 3) 
				{
					target = target.parentNode;
				}

				// Paranoia; check this is an A tag
				if (target.nodeName.toLowerCase() != 'a') return;

				// Find the <a name> tag corresponding to this href
				// First strip off the hash (first character)
				anchor = target.hash.substr(1);
				// Now loop all A tags until we find one with that name
				var allLinks = document.getElementsByTagName('a');
				var destinationLink = null;
				for (var i=0;i<allLinks.length;i++) 
				{
					var lnk = allLinks[i];
					if (lnk.name && (lnk.name == anchor)) 
					{
						destinationLink = lnk;
						break;
					}
				}

				// If we didn't find a destination, give up and let the browser do
				// its thing
				if (!destinationLink) return true;

				// Find the destination's position
				var destx = destinationLink.offsetLeft; 
				var desty = destinationLink.offsetTop;
				var thisNode = destinationLink;
				
				while (thisNode.offsetParent && 
						(thisNode.offsetParent != document.body)) 
				{
					thisNode = thisNode.offsetParent;
					destx += thisNode.offsetLeft;
					desty += thisNode.offsetTop;
				}

				// Stop any current scrolling
				clearInterval(ss.INTERVAL);

				cypos = ss.getCurrentYPos();

				ss_stepsize = parseInt((desty-cypos)/ss.STEPS);
				ss.INTERVAL = setInterval('ss.scrollWindow('+ss_stepsize+','+desty+',"'+anchor+'")',10);

				// And stop the actual click happening
				if (window.event) 
				{
					window.event.cancelBubble = true;
					window.event.returnValue = false;
				}
				if (e && e.preventDefault && e.stopPropagation) 
				{
					e.preventDefault();
					e.stopPropagation();
				}
			},

			scrollWindow: function(scramount,dest,anchor) 
			{
				var wascypos = ss.getCurrentYPos();
				var isAbove = (wascypos < dest);
				
				window.scrollTo(0,wascypos + scramount);
				
				var iscypos = ss.getCurrentYPos();
				var isAboveNow = (iscypos < dest);
				
				if ((isAbove != isAboveNow) || (wascypos == iscypos)) 
				{
					// if we've just scrolled past the destination, or
					// we haven't moved from the last scroll (i.e., we're at the
					// bottom of the page) then scroll exactly to the link
					window.scrollTo(0,dest);
					// cancel the repeating timer
					clearInterval(ss.INTERVAL);
					// and jump to the link directly so the URL's right
					location.hash = anchor;
				}
			},

			getCurrentYPos: function() 
			{
				if (document.body && document.body.scrollTop)
					return document.body.scrollTop;
				if (document.documentElement && document.documentElement.scrollTop)
					return document.documentElement.scrollTop;
				if (window.pageYOffset)
					return window.pageYOffset;
				return 0;
			},

			addEvent: function(elm, evType, fn, useCapture) 
			{
				// addEvent and removeEvent
				// cross-browser event handling for IE5+,  NS6 and Mozilla
				// By Scott Andrew
				if (elm.addEventListener)
				{
					elm.addEventListener(evType, fn, useCapture);
					return true;
				} 
				else if (elm.attachEvent)
				{
					var r = elm.attachEvent("on"+evType, fn);
					return r;
				} 
				else 
				{
					alert("Handler could not be removed");
				}
			} 
		}

ss.STEPS = 25;
*/
//ss.addEvent(window, 'load', ss.fixAllLinks);


function load_page()
{
	//runOnReadyStateComplete();
	setTimeout('runOnReadyStateComplete()', 100);
}

	

function runOnReadyStateComplete()
{
	var intRestoreScrollDelay = 10;
	
	if(blnRunOnReadyStateComplete == true)
	{
		return;
	}
	
	
	if((typeof(mstrAppPath) != 'undefined')&&(document.getElementById(mstrFilenameId)!=null)&&((typeof(document.readyState) == 'undefined')||(document.readyState == 'complete')))
	{
		if(initialise_page)
		{
			initialise_page();
		}
   
		if(typeof(restoreScrollPosition) != 'undefined')
		{
			if(typeof(mintRestoreScrollDelay) != 'undefined')
			{
				intRestoreScrollDelay = mintRestoreScrollDelay;
			}
			setTimeout('restoreScrollPosition()', intRestoreScrollDelay);
		}
	}
	else
	{
		setTimeout('runOnReadyStateComplete()', 100);
	}
}



addEvent(window, 'load', load_page, false);
//window.onunload = function (){formDisable(true)};
//window.onbeforeunload = function (){formDisable(true)};
