﻿/* Global Variables */
var applicationPath;

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 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);
	}
	
}


/*********************************************
*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 = 'div_protect';	
            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.text)
    { 
        return node.text; 
    }
    else if(node.textContent)
    { 
        return node.textContent; 
    } 
    else
    {
		return '';
    }
}

function getXmlString(xmlDoc)
{
	if(xmlDoc.xml)
	{
		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].innerText;
		    
		    
		}
	}
	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].innerText = 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);



function load_page()
{
	if(initialise_page)
	{
		initialise_page();
	}
}
addEvent(window, 'load', load_page, false);
//window.onunload = function (){formDisable(true)};
//window.onbeforeunload = function (){formDisable(true)};
