function popup(Url, Width, Height, Scrollbars)
{
    moveToX = (screen.width/2) - (Width/2);
    moveToY = (screen.height/2) - (Height/2) - 50;
    PopupWindow = window.open(Url,'PopupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars='+Scrollbars+',resizable=no,copyhistory=yes,width='+Width+',height='+Height);
    PopupWindow.moveTo(moveToX,moveToY);
}//popup
function CopyToClipboard(s) {
    if(window.clipboardData && clipboardData.setData) { clipboardData.setData("Text", s); }
    else { alert("Internet Explorer required"); }
}//CopyToClipboard
function JSPrint() { window.print(); }//JSPrint
function ToggleDiv(DivId) {
	TheDiv = document.getElementById(DivId);
	if (TheDiv.style.display == 'none') TheDiv.style.display = '';
	else TheDiv.style.display = 'none';
}//ToggleDiv
function doHighlight(bodyText, searchTerm, highlightStartTag, highlightEndTag)
{
	if ((!highlightStartTag) || (!highlightEndTag)) {
		highlightStartTag = "<font style='font: bold; background-color:yellow;'>";
		highlightEndTag = "</font>";
	}

	var newText = "";
	var i = -1;
	var lcSearchTerm = searchTerm.toLowerCase();
	var lcBodyText = bodyText.toLowerCase();

	while (bodyText.length > 0) {
		i = lcBodyText.indexOf(lcSearchTerm, i+1);
		if (i < 0) {
			newText += bodyText;
			bodyText = "";
		} else {
			if (bodyText.lastIndexOf(">", i) >= bodyText.lastIndexOf("<", i)) {
				if (lcBodyText.lastIndexOf("/script>", i) >= lcBodyText.lastIndexOf("<script", i)) {
					newText += bodyText.substring(0, i) + highlightStartTag + bodyText.substr(i, searchTerm.length) + highlightEndTag;
					bodyText = bodyText.substr(i + searchTerm.length);
					lcBodyText = bodyText.toLowerCase();
					i = -1;
				}
			}
		}
	}

	return newText;
}

function highlightSearchTerms(searchText, treatAsPhrase, warnOnFailure, highlightStartTag, highlightEndTag)
{
	if (treatAsPhrase) { searchArray = [searchText]; } else { searchArray = searchText.split(" "); }

	if (!document.body || typeof(document.body.innerHTML) == "undefined") {
		if (warnOnFailure) { alert("Sorry, the text of this page is unavailable. Highlighting will not work."); }
		return false;
	}

	var bodyText = document.body.innerHTML;
	for (var i = 0; i < searchArray.length; i++) { bodyText = doHighlight(bodyText, searchArray[i], highlightStartTag, highlightEndTag); }
	document.body.innerHTML = bodyText;
	return true;
}

var TreeMenu = new Object();

// Initialise the tree

TreeMenu.createTree = function(treeid) {
	var ultags = document.getElementById(treeid).getElementsByTagName("ul");
	for (var i = 0; i < ultags.length; i++) TreeMenu.buildSubTree(treeid, ultags[i], i);
}

// Build sub trees

TreeMenu.buildSubTree = function(treeid, ulelement, index) {
	ulelement.parentNode.className = "submenu";

	if ((ulelement.getAttribute("rel") == null) || (ulelement.getAttribute("rel") == false)) ulelement.setAttribute("rel", "closed");
	else if (ulelement.getAttribute("rel") == "open") TreeMenu.expandSubTree(treeid, ulelement);

	ulelement.parentNode.onclick = function(e) {
		var submenu = this.getElementsByTagName("ul")[0];
		if (submenu.getAttribute("rel") == "closed") {
			submenu.style.display="block";
			submenu.setAttribute("rel", "open");
		}
		else if (submenu.getAttribute("rel") == "open") {
			submenu.style.display="none";
			submenu.setAttribute("rel", "closed");
		}
		TreeMenu.preventpropagate(e);
	}
	ulelement.onclick = function(e) { TreeMenu.preventpropagate(e); }
}

// Expand a UL element and any of its parent ULs

TreeMenu.expandSubTree = function(treeid, ulelement) {
	var rootnode = document.getElementById(treeid);
	var currentnode = ulelement;
	currentnode.style.display = "block";
	while (currentnode != rootnode){
		if (currentnode.tagName == "UL") {
			currentnode.style.display = "block";
			currentnode.setAttribute("rel", "open");
		}
		currentnode = currentnode.parentNode;
	}
}

// Expand or contract all UL elements

TreeMenu.flatten = function(treeid, action) {
	var ultags = document.getElementById(treeid).getElementsByTagName("ul");
	for (var i = 0; i < ultags.length; i++) {
		ultags[i].style.display = (action == "expand") ? "block" : "none";
		var relvalue = (action == "expand") ? "open" : "closed";
		ultags[i].setAttribute("rel", relvalue);
	}
}

// Search an array for value. If found, delete value from array

TreeMenu.searcharray = function(thearray, value) {
	var isfound = false;
	for (var i=0; i<thearray.length; i++){
		if (thearray[i]==value){
			isfound=true;
			thearray.shift();
			break;
		}
	}
	return isfound;
}

// Prevent action from bubbling upwards

TreeMenu.preventpropagate = function(e) {
	if (typeof e!="undefined") e.stopPropagation();
	else event.cancelBubble = true;
}

// Assign a function to an event handler (ie: onload)

TreeMenu.dotask = function(target, functionref, tasktype) {
	var tasktype = (window.addEventListener) ? tasktype : "on"+tasktype;
	if (target.addEventListener) target.addEventListener(tasktype, functionref, false);
	else if (target.attachEvent) target.attachEvent(tasktype, functionref);
}

function RunQuickSearch(Link) {
	SearchStr = String(document.getElementById('Search').value);
	SearchStr = SearchStr.replace('&', '');
	if (SearchStr == 'Search') return;
	if (SearchStr == '') return;
	while (SearchStr.search('&') > -1) { SearchStr = SearchStr.replace('&', ''); }//while
	window.location = Link + 'Search=' + SearchStr;
}//RunQuickSearch

function ClearQuickSearch() {
	var SearchStr = String(document.getElementById("Search").value);
	if (SearchStr == 'Search') { document.getElementById("Search").value = ""; }
}//ClearQuickSearch

function SetQuickSearch() {
	var SearchStr = String(document.getElementById("Search").value);
	if (SearchStr == '') { document.getElementById("Search").value = "Search"; }
}//SetQuickSearch


// Global variables
jsc_aDaysInMonth = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
jsc_aMonthNames = new Array("January","February","March", "April","May","June", "July","August","September", "October","November","December");
jsc_aDatePickers = new Array();

function jscIsLeapYear(nYear) {
	return ((nYear%4)!=0?false:((nYear%100)!=0?true:((nYear%400)!=0?false:true)));
}
function jscGetFirstDay(nMonth,nYear,bMondayFirst) {
	tmp = new Date(nYear,nMonth,1);
	tmp2 = tmp.getDay();
	delete tmp;
	if(bMondayFirst) { tmp2 = ((tmp2-1)<0?6:(tmp2-1)); }
	return tmp2;
}

function jscDatePicker(bSundayFirst, FieldName, InitDate, InitMonth, InitYear) {

	// Set external object references
	this.anchor_id = "DATE_SELECT_IMG"+FieldName;
	this.field_full = "DATE_SELECT"+FieldName;
	this.object_name = "Date"+FieldName;
	this.div_container = "DATE_SELECT_CONTAINER"+FieldName;

	// Set initial date
	tmp = new Date();
	this.current_date = InitDate;
	this.current_month = InitMonth;
	this.current_year = InitYear;
	delete tmp;

	// Is Monday the first day of the week?
	this.monday_first = (bSundayFirst?false:true);
	this.current_month_first_day = jscGetFirstDay(this.current_month,this.current_year,this.monday_first);

	// Selected date
	this.selected_month_first_day = this.current_month_first_day;
	this.selected_date = this.current_date;
	this.selected_month = this.current_month;
	this.selected_year = this.current_year;
	this.selected_is_leap_year = jscIsLeapYear(this.selected_year);

	// Currently being viewed month/year
	this.view_month_first_day = this.current_month_first_day;
	this.view_month = this.current_month;
	this.view_year = this.current_year;
	this.view_is_leap_year = this.selected_is_leap_year

	// Minimum date
	this.min_date = 1;
	this.min_month = 0;
	this.min_year = 1970;

	// Maximum date
	this.max_date = 0;
	this.max_month = 0;
	this.max_year = 0;

	// Timeout to hide datepicker on mouseout
	this.to_hide = null;

	// Has been drawn?
	this.is_drawn = false;

	// Is the control currently visible?
	this.is_visible = false;

	// Controls to set the values of when SetDate is called
	this.field_date = null;
	this.field_month = null;
	this.field_year = null;

	// Function to call when SetDate is called
	this.call_func = null;

	// Index in the jsc_aDatePickers array
	this.index = jsc_aDatePickers.length;
	jsc_aDatePickers.push(this);

	// Position, found from obj_anchor when declared
	this.x = 0;
	this.y = 0;

	// Creation of div container element & ID
	//this.div_id = "jsc_dp_"+this.index;
	this.div_id = this.div_container;

	// ID of anchor object
	this.obj_anchor = null;

	// Styles
	this.cellpadding = 0;
	this.cellspacing = 0;
	this.css_class = "jscCalendar";

	return this;
}
jscDatePicker.prototype.SetDate = function(nDate,nMonth,nYear) {
	this.Hide();
	this.selected_year = (nYear<this.min_year?this.min_year:nYear);
	if(this.max_year) { this.selected_year = (this.selected_year>this.max_year?this.max_year:this.selected_year); }
	this.selected_is_leap_year = jscIsLeapYear(this.selected_year);
	this.selected_month = (nMonth<0?0:(nMonth>11?11:nMonth));
	if(this.selected_year==this.min_year && this.selected_month<this.min_month) {
		this.selected_month = this.min_month;
	} else if(this.selected_year==this.max_year && this.selected_month>this.max_month) {
		this.selected_month = this.max_month;
	}
	if(this.selected_month==1 && this.selected_is_leap_year) {
		this.selected_date = (nDate<1?1:(nDate>29?29:nDate));
	} else {
		this.selected_date = (nDate<1?1:(nDate>jsc_aDaysInMonth[nMonth]?jsc_aDaysInMonth[nMonth]:nDate));
	}
	if(this.selected_year==this.min_year && this.selected_month==this.min_month && this.selected_date<this.min_date) {
		this.selected_date = this.min_date;
	} else if(this.selected_year==this.max_year && this.selected_month==this.max_month && this.selected_date>this.max_date) {
		this.selected_date = this.max_date;
	}

	this.selected_month_first_day = jscGetFirstDay(this.selected_month,this.selected_year,this.monday_first);

	var FullDate; FullDate = this.selected_date+"-"+(this.selected_month+1)+"-"+this.selected_year;

	// Attempt to set any form fields associated with this control
	if(document.getElementById) {
		if(this.field_full) { document.getElementById(this.field_full).value = FullDate; }
	} else if(document.all) {
		if(this.field_full) { document.all[this.field_full].value = FullDate; }
	}

	// If there's an associated function, call it
	if(this.call_func) { eval(this.call_func+"(jsc_aDatePickers["+this.index+"]);"); }

	// Update the viewed date information to reflect this
	this.view_month = this.selected_month;
	this.view_year = this.selected_year;
	this.view_month_first_day = this.selected_month_first_day;
	this.view_is_leap_year = this.selected_is_leap_year;

	this.Draw();

	return;
};
jscDatePicker.prototype.SetMinDate = function(nDate,nMonth,nYear) {
	// Check the date is valid
	this.min_year = (nYear<1970?1970:nYear);
	this.min_month = (nMonth<0?0:(nMonth>11?11:nMonth));
	if(this.min_month==1 && jscIsLeapYear(this.min_year)) {
		this.min_date = (nDate<1?1:(nDate>29?29:nDate));
	} else {
		this.min_date = (nDate<1?1:(nDate>jsc_aDaysInMonth[nMonth]?jsc_aDaysInMonth[nMonth]:nDate));
	}

	// Check the date isn't greater than the maximum date
	if(!this.max_year) { return; } // No maximum year has been declared
	if(this.min_year>this.max_year ||
		(this.min_year==this.max_year && this.min_month>this.max_month) ||
		(this.min_year==this.max_year && this.min_month==this.max_month && this.min_date>this.max_date)) {
		this.min_year = this.max_year;
		this.min_month = this.max_month;
		this.min_date = this.max_date;
	}
	return;
};
jscDatePicker.prototype.SetMaxDate = function(nDate,nMonth,nYear) {
	// Check the date is valid
	if(nYear==0) { this.max_year = 0; this.max_month = 0; this.max_date = 0; }
	this.max_year = (nYear<1970?1970:nYear);
	this.max_month = (nMonth<0?0:(nMonth>11?11:nMonth));
	if(this.max_month==1 && jscIsLeapYear(this.max_year)) {
		this.max_date = (nDate<1?1:(nDate>29?29:nDate));
	} else {
		this.max_date = (nDate<1?1:(nDate>jsc_aDaysInMonth[nMonth]?jsc_aDaysInMonth[nMonth]:nDate));
	}

	// Check the date isn't less than the minimum date
	if(this.max_year<this.min_year ||
		(this.max_year==this.min_year && this.max_month<this.min_month) ||
		(this.max_year==this.min_year && this.max_month==this.min_month && this.max_date<this.min_date)) {
		this.max_year = this.min_year;
		this.max_month = this.min_month;
		this.max_date = this.min_date;
	}
	return;
};
jscDatePicker.prototype.ViewDate = function(nMonth,nYear) {
	nYear = parseInt(nYear); nMonth = parseInt(nMonth);
	this.view_year = (nYear<1970?1970:nYear);
	this.view_month = (nMonth<0?0:(nMonth>11?11:nMonth));
	// Check the date isn't less than the minimum date, or greater
	// than the maximum date
	if(this.min_year &&
		(this.view_year<this.min_year ||
		(this.view_year==this.min_year && this.view_month<this.min_month))) {
		this.view_year = this.min_year;
		this.view_month = this.min_month;
	} else if(this.max_year &&
		(this.view_year>this.max_year ||
		(this.view_year==this.max_year && this.view_month>this.max_month))) {
		this.view_year = this.max_year;
		this.view_month = this.max_month;
	}
	this.view_is_leap_year = jscIsLeapYear(this.view_year);
	this.view_month_first_day = jscGetFirstDay(this.view_month,this.view_year,this.monday_first);

	this.Draw();
	return;
};

jscDatePicker.prototype.Draw = function() {
	outHTML = '<table width="210" border="0" cellpadding="'+this.cellpadding+'px"';
	outHTML+= ' cellspacing="'+this.cellspacing+'" class="'+this.css_class+'"';
	outHTML+= ' onmouseout=\'Javascript:jsc_aDatePickers['+this.index+'].to_hide=window.setTimeout("jsc_aDatePickers['+this.index+'].Hide();",3000);\'';
	outHTML+= ' onmouseover=\'Javascript:window.clearTimeout(jsc_aDatePickers['+this.index+'].to_hide);\'';
	outHTML+= '>\n';

	// Calendar navigation controls
	outHTML+= '<tr>';

	outHTML+= '<td class="navRow" colspan="7"><select id="id_currentmonth_'+this.index+'" onchange=\'Javascript:jsc_aDatePickers['+this.index+'].ViewDate(this.value,'+this.view_year+');\'>';
		for(i=0;i<12;i++) {
			if((this.view_year==this.min_year && i<this.min_month) ||
				(this.max_year && this.view_year==this.max_year && i>this.max_month)) { continue; }
			outHTML+= '<option value="'+i+'"'+(this.view_month==i?' selected="selected"':'')+'>'+jsc_aMonthNames[i]+'</option>\n';
		}
		outHTML+= '</select>';
	outHTML+= '<select id="id_currentyear_'+this.index+'" class="selYear" onchange=\'Javascript:jsc_aDatePickers['+this.index+'].ViewDate('+this.view_month+',this.value);\'>';
		for(i=-2;i<=2;i++) {
			if((this.view_year+i)<this.min_year || (this.max_year && (this.view_year+i)>this.max_year)) { continue; }
			outHTML+= '<option value="'+(this.view_year+i)+'"'+(i==0?' selected="selected"':'')+'>'+(this.view_year+i).toString().substr(2,2)+'</option>\n';
		}
		outHTML+= '</select>';

	outHTML+= '&nbsp;|&nbsp;<a onclick="javascript:'+this.object_name+'.Hide();" title="Close">Close</a></td>';

	outHTML+= '</tr>\n';
	// END Calendar navigation controls

	// Row displaying days of the week
	outHTML+= '<tr class="dayRow">'+(this.monday_first?'':'<td>S</td>')+'<td>M</td><td>T</td><td>W</td><td>T</td><td>F</td>';
	outHTML+= '<td>S</td>'+(this.monday_first?'<td>S</td>':'')+'</tr>\n';

	// Draw the days
	nDaysInMonth = jsc_aDaysInMonth[this.view_month];
	if(this.view_is_leap_year && this.view_month==1) { nDaysInMonth+=1; }
	nDaysToDraw = this.view_month_first_day+nDaysInMonth;
	nDaysToDraw+= ((7-(nDaysToDraw%7))==7?0:(7-(nDaysToDraw%7)));
	outHTML+= '<tr class="calRow">';
	j = 1;
	for(i=(1-this.view_month_first_day);i<=(nDaysToDraw-this.view_month_first_day);i++) {
		addStyle = 0;
		if(i<1 || i>nDaysInMonth) {
			if(this.monday_first && j>5) { addStyle = "weDay"; }
			else if(!this.monday_first && (j==1 || j==7)) { addStyle = "weDay"; }
			outHTML+= '<td'+(addStyle?' class="'+addStyle+'"':'')+'>&nbsp;</td>';
		}
		else {
			if((this.view_year==this.min_year && this.view_month==this.min_month && i<this.min_date) ||
				(this.max_year && this.view_year==this.max_year && this.view_month==this.max_month && i>this.max_date)) {
				if(this.monday_first && j>5) { addStyle = "invWeDay"; }
				else if(!this.monday_first && (j==1 || j==7)) { addStyle = "invWeDay"; }
				else { addStyle = "invDay"; }
			} else {
				if(this.monday_first && j>5) { addStyle = "weDay"; }
				else if(!this.monday_first && (j==1 || j==7)) { addStyle = "weDay"; }
			}
			// Is this the currently selected day?
			if(this.view_year==this.selected_year && this.view_month==this.selected_month && i==this.selected_date) {
				outHTML+= '<td class="curDay">'+i+'</td>';
			} else {
				outHTML+= '<td'+(addStyle?' class="'+addStyle+'"':'')+'>';
				outHTML+= '<a onclick=\'Javascript:jsc_aDatePickers['+this.index+'].SetDate('+i+','+this.view_month+','+this.view_year+');\'>'+i+'</a></td>';
			}
		}
		if(j==7) { outHTML+= '</tr>\n<tr class="calRow">'; j = 1; } else { j+= 1; }
	}
	outHTML+= '</tr>\n';
	outHTML+= '</table>\n';

	if(document.getElementById) {
		document.getElementById(this.div_id).innerHTML = outHTML;
	} else if(document.all) {
		document.all[this.div_id].innerHTML = outHTML;
	}

	return;
};
jscDatePicker.prototype.Show = function() {
	// Draw the container div
	//if (!document.getElementById(this.div_id)) document.body.innerHTML+= '<div id="'+this.div_id+'" style="position:absolute;left:0;top:0;display:none;z-index:999;"></div>\n';
	// Set the anchor
	this.SetAnchor(this.anchor_id);
	if(!this.is_drawn) { this.Draw(); this.is_drawn = true; }
	if(document.getElementById) {
		document.getElementById(this.div_id).style.display = "block";
	} else if(document.all) {
		document.all[this.div_id].style.display = "block";
	}
	// Hide all other controls...
	for(i=0;i<jsc_aDatePickers.length;i++) {
		if(jsc_aDatePickers[i].is_visible) { jsc_aDatePickers[i].Hide(); }
	}
	this.is_visible = true;
	return;
};
jscDatePicker.prototype.Hide = function() {
	if(document.getElementById) {
		document.getElementById(this.div_id).style.display = "none";
	} else if(document.all) {
		document.all[this.div_id].style.display = "none";
	}
	this.is_visible = false;
	// Change the view date to be the selected date
	this.view_year = this.selected_year;
	this.view_month = this.selected_month;
	this.Draw();
	return;
};
jscDatePicker.prototype.SetAnchor = function(objID) {
	this.obj_anchor = objID;
	if(document.getElementById) {
		objA = document.getElementById(objID);
		objD = document.getElementById(this.div_id);
	} else if(document.all) {
		objA = document.all[objID];
		objD = document.all[this.div_id];
	}

	if(!objA) { return false; }
	else if(!objA.offsetParent) { return false; }

	this.x = 0; this.y = objA.offsetHeight;

	tmpOBJ = objA;

	do {
		this.x+= tmpOBJ.offsetLeft;
		this.y+= tmpOBJ.offsetTop;
	} while (tmpOBJ = tmpOBJ.offsetParent);

	if(objD.style.posLeft) { objD.style.posLeft = (this.x+25)+"px"; }
	if(objD.style.left) { objD.style.left = (this.x+25)+"px"; }

	if(objD.style.posTop) { objD.style.posTop = (this.y-100)+"px"; }
	if(objD.style.top) { objD.style.top = (this.y-100)+"px"; }

	return true;
};
jscDatePicker.prototype.SetFunction = function(idFunction) {
	if(eval("typeof "+idFunction)=='function') {
		this.call_func = idFunction; return true;
	}
	return false;
};
