
<!--
///////////////////////////////////
// Default Javascript Processing //
///////////////////////////////////

// Globals - Have the scope of the parent window
var g_boolModal = false; // You want modal behaviour?
var g_functionToProcess; // You want to process the contents of a form in the modal?
var g_functionParameters;

// Tab on and off classes
var g_strTabOnClass = '';
var g_strTabOffClass = '';

// These defaults should be changed the way it best fits the site
var _POPUP_FEATURES = 'location=0,statusbar=0,menubar=0,width=190,height=140';

// Used for Modal windows
var g_skipcycle = false;

// DETECT POPUP AND CHECK MODALITY
try
{
	var g_skipcycle = false;
	var g_winTimer;
	if(window.opener)
	{
		if(window.opener.g_boolModal) 
		{
			document.captureEvents(Event.ONLOAD);
			document.onload = runmustbeloadedscripts();
			document.releaseEvents(Event.ONLOAD);
		}
	}
}
catch (exception) 
{
	// Ignore permission denied errors as probably caused by window.opener being on a different domain
	if(exception.indexOf("Permission denied to get property") == -1)
	{
		if (exception.description == null) { 
			// alert("SetTimeout Error: " + exception.message); 
			}  
		else {
			// alert("SetTimeout Error: " + exception.description); 
		}
	}
}

function popup_centre()
{
	var w = (screen.availWidth / 3) * 2;
	var h = (screen.availHeight / 3) * 2;
	var l = (screen.availWidth - w) / 2;
	var t = (screen.availHeight - h) / 2;
	_POPUP_FEATURES = 'scrollbars=1,location=0,statusbar=0,menubar=0,width='+w+',height='+h+',left='+l+',top='+t;
}

popup_centre();

// Code to replicate the working of innerText on Mozilla browsers
if (typeof Element != 'undefined' && Element.prototype && document.createRange) {
	Element.prototype.__defineGetter__('innerText',
	function () {
		var range = document.createRange();
		range.selectNodeContents(this);
		return range.toString();
	}
	);
	Element.prototype.__defineSetter__('innerText',
	function (text) {
		var range = document.createRange();
		range.selectNodeContents(this);
		range.deleteContents();
		this.appendChild(document.createTextNode(text));
	}
	);
}
// End of innerText

function runMustBeLoadedScripts()
{
	g_winTimer = setTimeout('focusOnMe()', 500);
	setInputFields();
}

function popupCentre()
{
	var w = (screen.availWidth / 3) * 2;
	var h = (screen.availHeight / 3) * 2;
	var l = (screen.availWidth - w) / 2;
	var t = (screen.availHeight - h) / 2;
	_POPUP_FEATURES = 'location=0,statusbar=0,menubar=0,width='+w+',height='+h+',left='+l+',top='+t;
}

function rawPopup(url, target, features) {
    // pops up a window containing url optionally named target, optionally having features
    if (isUndefined(features)) features = _POPUP_FEATURES;
    if (isUndefined(target  )) target   = '_blank';
    var theWindow = window.open(url, target, features);
	// message to user if the window open failed
	if(theWindow==null || typeof(theWindow)=="undefined"){
		alert('This function will only work if you allow non-automatic popups (Medium filter level in Internet Explorer SP2)');
	} else {
    	theWindow.focus();
	}
    return theWindow;
}

function toPassword(oInput) {	//Changes a text field to a password field
	var newEl = document.createElement('input');
	newEl.setAttribute('type', 'password');
    newEl.setAttribute('name', 'password');
    newEl.setAttribute('class', 'password');
	oInput.parentNode.replaceChild(newEl,oInput);
	toPassword.el = newEl;
	setTimeout('toPassword.el.focus()',100);
	return true;
}

function linkPopup(src, features) {
    // to be used in an html event handler as in: <a href="..." onclick="linkPopup(this,...)" ...
    // pops up a window grabbing the url from the event source's href
    return rawPopup(src.getAttribute('href'), src.getAttribute('target') || '_blank', features);
}

// Popup from a form button
function formPopup(url,target,features,modal,processingfunction)
{
	// call raw popup to open window
	rawPopup(url, target, features);
	
	// set the bool modal flag
	g_boolModal = modal;
	
	// set the processing function up
	g_functionToProcess = processingfunction;
	
	// set the processing function parameters up
	g_functionParameters = new Array();
	for( i = 5; i < formPopup.arguments.length; i++ )
	{
		g_functionParameters[i-5] = formPopup.arguments[i];
	}
}

// To close the pop up and send the form back to a processing function
function formPopupReturn(frm,boolCloseMe)
{
	if(window.opener)
	{
		if(isFunction(window.opener.g_functionToProcess) || isObject(window.opener.g_functionToProcess)) 
		{
			// bodge because array.concat and function.apply don't work in IE like they should. hours of fun discovering that.
			if( 0 == window.opener.g_functionParameters.length )
			{
				window.opener.g_functionToProcess(frm);
			}
			else if( 1 == window.opener.g_functionParameters.length )
			{
				window.opener.g_functionToProcess(frm, window.opener.g_functionParameters[0]);
			}
			else if( 2 == window.opener.g_functionParameters.length )
			{
				window.opener.g_functionToProcess(frm, window.opener.g_functionParameters[0], window.opener.g_functionParameters[1]);
			}
			else
			{
				alert('Sorry, not implemented!'); // ie hint to implement it!
			}
		}
	}
    if(boolCloseMe) window.close();
}
/*
// To close the pop up and send the form back to a processing function
function formTablePopupReturn(table,frm,boolCloseMe)
{
	if(window.opener)
	{
		if(isFunction(window.opener.g_functionToProcess) || isObject(window.opener.g_functionToProcess)) window.opener.g_functionToProcess(table,frm);
	}
    if(boolCloseMe) window.close();
}
*/
// Popup from a url link and process return results

function formLinkPopup(src,features,modal,processingfunction)
{
	// call raw popup to open window
	rawPopup(src.getAttribute('href'), src.getAttribute('target') || '_blank', features);

	// set the bool modal flag
	g_boolModal = modal;
	
	// set the processing function up
	g_functionToProcess = processingfunction;
}

// Write e-mail address dynamically to avoid spambots
function email(name, domain, suffix, text){
   var address = name + "\u0040" + domain + "." + suffix;
   var url = "mailto:" + address;

   if( ! text ) {
      text = address;
   }
   document.write("<a href=\"" + url + "\">" + text + "</a>");
}

// Set the skip cycle
function cycleOn() { g_skipcycle=false; }
function cycleOff() { g_skipcycle=true; }

// Set all input fields to have the cycle set on and off according to the mode
// This fixes a problem in IE where input fields on modal windows are read only
function setInputFields() {
	if(window.opener)
	{
		if(window.opener.g_boolModal) 
		{
			var ary_elems = document.getElementsByTagName("input");
			for(i = 0; i < ary_elems.length ; i++)
			{
				//ary_elems[i].style.backgroundColor = "#FF0099"
				ary_elems[i].onfocus=cycleOff;
				ary_elems[i].onblur=cycleOn;
			}
			var ary_elems = document.getElementsByTagName("select");
			for(i = 0; i < ary_elems.length ; i++)
			{
				ary_elems[i].onfocus=cycleOff;
				ary_elems[i].onblur=cycleOn;
			}
		}
	}
}

// Set focus for a modal window
function focusOnMe()
{
	if (!g_skipcycle) window.focus();
 	g_winTimer = setTimeout('focusOnMe()', 500);
}

// set a <DIV> based tab to visible (using name tab_xxxx)
function toggleDiv(tab) {
	var regExp = new RegExp('tab_+');
	var tabTags = document.getElementsByTagName("div") ; 
	for (var i = 0; i < tabTags.length ; i++) 
	{
		if (regExp.test(tabTags[i].id))
		{ 
			tabTags[i].style.display = 'none'; 
		}
	}
	document.getElementById('tab_' + tab).style.display = 'inline';
}

// set a <TABLE> based tab to visible (using name tab_xxxx)
function toggleTable(tab) {
	var regExp = new RegExp('tab_+');
	
	// if this is the first time through then store the tab index classes
	if (g_strTabOnClass == '') {
		if (isObject(document.getElementById('index_1'))) { 
			g_strTabOnClass = document.getElementById('index_1').className;
		}
	}
	if (g_strTabOffClass == '') {
		if (isObject(document.getElementById('index_2'))) { 
			g_strTabOffClass = document.getElementById('index_2').className;
		}
	}
	
	// get all table elements from DOM
	var tabTags = document.getElementsByTagName("table") ; 
	for (var i = 0; i < tabTags.length ; i++) 
	{
		// set all tab index classes to inactive
		if (isObject(document.getElementById('index_' + i))) {
			document.getElementById('index_' + i).className = g_strTabOffClass;
		}
		
		// set all tabs to hidden
		if (regExp.test(tabTags[i].id)) { 
			tabTags[i].style.display = 'none'; 
		}
	}
	
	// set the selected tab index to active and show the selected tab details
	document.getElementById('tab_' + tab).style.display = 'inline';
	document.getElementById('index_' + tab).className = g_strTabOnClass;;
}

// script by Arash Ramin (http://www.digitalroom.net) - Mods by Larry @ Senior
function setCurrentDate(dayDropDown, monthDropDown, yearDropDown) {
	
  	// changes the date selector menus to the current date
  	var currentDate = new Date();

  	yearDropDown.selectedIndex = 0;
  	monthDropDown.selectedIndex = currentDate.getMonth();

  	setDays(dayDropDown, monthDropDown, yearDropDown);  
  	dayDropDown.selectedIndex = currentDate.getDate() - 1;
}

// script by Arash Ramin (http://www.digitalroom.net) - Mods by Larry @ Senior
function setDays(dayDropDown, monthDropDown, yearDropDown) {

  	var y = yearDropDown.options[yearDropDown.selectedIndex].value;
  	var m = monthDropDown.selectedIndex;
  	var d;

  	// find number of days in current month
  	if ( (m == 3) || (m == 5) || (m == 8) || (m == 10) ) {
    	days = 30;
  	}
  	else if (m == 1) {
    	// check for leapyear - Any year divisible by 4, except those divisible by 100 (but NOT 400)
    	if ( (Math.floor(y/4) == (y/4)) && ((Math.floor(y/100) != (y/100)) || (Math.floor(y/400) == (y/400))) )
      		days = 29
    	else
      		days = 28
  	}
  	else {
    	days = 31;
  	}

  	// if (days in new month > current days) then we must add the extra days
  	if (days > dayDropDown.length) {
    	for (i = dayDropDown.length; i < days; i++) {
      		dayDropDown.length = days;
      		dayDropDown.options[i].text = i + 1;
      		dayDropDown.options[i].value = i + 1;
    	}
  	}
  
  	// if (days in new month < current days) then we must delete the extra days
  	if (days < dayDropDown.length) {
    	dayDropDown.length = days;
    	if (dayDropDown.selectedIndex == -1) 
      		dayDropDown.selectedIndex = days - 1;
  	}

}

// Apply a given class to all elements of a certain type
function applyClass(type, className) {
	
	// if button specified then get both inputs and buttons
	if (type == 'button') {
		var ary_elems = document.getElementsByTagName('input');
		for(i = 0; i < ary_elems.length ; i++) {
			if (ary_elems[i].type == 'button' || ary_elems[i].type == 'submit') {
				ary_elems[i].className=className;
			}
		}
	}
	
	// get all elements of type specified and apply the given class
	var ary_elems = document.getElementsByTagName(type);
	for(i = 0; i < ary_elems.length ; i++) {
		ary_elems[i].className=className;
	}
}

// Left(String, Length)
function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}

// Right(String, Length)
function Right(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);
    }
}

// Set the content of the FCKEditor dynamically
//  Just for good measure the function returns what was in the editor before the content was changed. 
function setFCKContent(instanceName,content) { 
	editor_frame = document.getElementById(instanceName+'___Frame'); 
	if (editor_frame!=null) { 
		editor_source = editor_frame.contentWindow.document.getElementById('eEditorArea'); 
		if (editor_source!=null) { 
			var oldcontent = editor_source.contentWindow.document.body.innerHTML; 
			editor_source.contentWindow.document.body.innerHTML=content; 
			return oldcontent; 
		} 
		else { 
			return false; 
		} 
	} 
	else { 
		return false; 
	} 
} 

// replace the ampersand representations that get returned
function decodeCpaint(p_strCpaintContent){
	var re = /\\u0026amp;/gi;
	var sanitised = p_strCpaintContent.replace(re,"&");
	//var re = /\&amp;/gi;
	//sanitised = sanitised.replace(re,"&");
	return sanitised;
}

// Replace function
function replaceString(str,searchFor,replaceWith) {
  	var i = str.indexOf(searchFor);
  	while ( i!=-1 ) {
    	var j = i+searchFor.length;
    	str = str.substring(0,i)+replaceWith+str.substring(j,str.length);
    	i = str.indexOf(searchFor,i+replaceWith.length);
  	} 
	return str;
}

function LCase(Value) {
  return Value.toString().toLowerCase();
}

function UCase(Value) {
  return Value.toString().toUpperCase();
}

function Len(Expression) {
  return Expression.toString().length;
}

// Get the content of the FCKEditor dynamically
function getFCKContent(instanceName) { 
	editor_frame = document.getElementById(instanceName+'___Frame'); 
	if (editor_frame!=null) { 
		editor_source = editor_frame.contentWindow.document.getElementById('eEditorArea'); 
		if (editor_source!=null) { 
			var content=editor_source.contentWindow.document.body.innerHTML;
			return content; 
		} 
		else { 
			return false; 
		} 
	} 
	else { 
		return false; 
	} 
} 

function URLencode(sStr) {
	return escape(sStr).replace(/\+/g, '%2C').replace(/\"/g,'%22').replace(/\'/g, '%27');
}

function errorMessage(elem,message){
	alert(message);
	elem.focus();
	elem.select();
}

/**************************************************************************
* Name    : FastArraySearch
* Purpose : Searches an array for a specified value using shortest path.
*		    It can be used for char string as well as number searches also.
*           But the array to be searched must be sorted in asc/desc order.
* Input   : Value to be searched. The array should be sorted alphabetically
* Output  : Index number of the value found. -1 if value is not found.
***************************************************************************/
function FastArraySearch(vArray, vValue)
{
	var iStartIndex, iEndIndex, iMiddleIndex;

	iStartIndex = 0;
	iMiddleIndex = -1;
	iEndIndex = vArray.length - 1;		
		
	while (true)
	{		
		iMiddleIndex = iStartIndex + Math.ceil((iEndIndex - iStartIndex) / 2);
		
		switch(vValue)
		{
		case vArray[iStartIndex]: return iStartIndex;
		case vArray[iMiddleIndex]: return iMiddleIndex;
		case vArray[iEndIndex]: return iEndIndex;
		}	
		
		if (iStartIndex == iMiddleIndex || iEndIndex == iMiddleIndex) return -1;
		
		if (vValue > vArray[iMiddleIndex])
		{
			iStartIndex = iMiddleIndex + 1;
		}
		else if (vValue < vArray[iMiddleIndex])
		{
			iEndIndex = iMiddleIndex - 1;
		}
	}
	return -1;
}

// Type Checking
function isUndefined(a) 	{ return typeof a == 'undefined' }
function isObjectNull(a)	{ return typeof a == 'object' && !a }
function isFunction(a) 		{ return typeof a == 'function'; }
function isObject(a) 		{ return (a && typeof a == 'object') || isFunction(a); }
function isArray(a) 		{ return (a && typeof a == 'array'); }
// (c) Senior Internet 2004
//-->
