﻿// Copyright    :   True Potential LLP 2007
// Author       :   Paul Outterside
// Created      :   26/03/2007
// Modified     :   (date - initials : details (lines))


/*
THIS FILE CONTAINS THE FOLLOWING FUNCTIONS :

    getBrowser() : very simple browser family detect.
    left(str, n) : JS equivalent of LEFT string function in VB.
    mid(str, start, len) : JS equivalent of MID string function in VB.
    inStr(str, charSearch) : JS equivalient of the instr function in VB.
    highlightRow(rowId, startingClass, action) : Highlights a whole table row by replacing the CSS class.
    openPopup(popurl, winName, winWidth, winHeight, winScroll) : Nice centered popup window.
    sizePage() : Sets up the layout of the main page, based on the available size.
    showMenu() : Shows/hides the start menu.
    changeMenuItemBg(action, cellId) : Used to add a highlight colour to the start menu items.
    httpReq() : Sets up the HTTP request for AJAX based on the browser family.
    setHtml(targetItem, content) : Parses script blocks if required in the AJAX return string.
    changeContentProxy(paramString) : always called instead of below. Allows only required parameters to be passed in on call.
    changeContent(sourceFile, paramString, targetItem, useRandom, loadMessage, spinnerType, parseScript) : The main AJAX performer function.
    passForm(targetHandler, formName, displayName) : Allows a simple (usually search) form to be parsed to a QS for the AJAX performer.
    showSub(bufferHeight) : Show the AJAX popup alternative.
    hideSub() : Hide the AJAX popup alternative.
    hideSubNoClear() : Hide the AJAX popup alternative - for Quote Engine use only.
    checkOverlay() : Size-check the overlay features for the AJAX popup alternative.
    clock(targetId) : Javascript clock display.
    checkScrollingDiv(bufferSize) : Sets the height of a scrolling DIV. Called on a page-by-page basis.
    infoBarTreeExpand(divId, loadPage, loadSource, loadTarget, loadParams, hasImage) : shows/hides extra info bar items.
    clearInfoBar() : clears any content from the infoBar
    changeTopBarText(messageText) : changes the text in the top bar (above content pane)
    callTip(action, tipHolder, vertBuffer, horizBuffer) : my own custom tooltip info panel
    captureMousePosition(e) : sub-function for above that actually performs the action
    changeControlState(controlId, controlType) : changes the state of a passed control from enabled/disabled. SUB PAGE ONLY!!
	urlEndoce(urlStream) : JS equivalent of URL ENCODE
    checkSure(messageText, showAlert) : standard confirm alert box. Returns true or false or an action cancelled.
    getDocument(targetPath, fromInbox) : opens a document from the document storage system.
    switchStyle(itemId, newClass) : used for the calendar function
	switchBack(itemId, newClass) : used for the calendar function
	changeMonth(direction) : changes the calendar between months
	getMonthName(monthId) : returns the month name as appropriate.
	dayClick(dayId, monthId, yearId) : a day has been selected in the calendar
	weekClick(rowId, dayId, monthId, yearId) : a week has been selected in the calendar
	changeMonthV2(direction) : changes the calendar between months for V2 application code
	dayClickV2(dayId, monthId, yearId) : a day has been selected in the calendar for V2 application code
	weekClickV2(rowId, dayId, monthId, yearId) : a week has been selected in the calendar for V2 application code
	entryHighlight(cellId, action) : highlight a calendar entry - this is so inefficient given I already have 2!!!
	formatCurrency(amount) : comma delimit a currency string.
	footerIdentifier(actingAs) : changes the text in the footer bar to show who you are currently acting as.
	createCook(name,value,days) : creates a cookie in JS
	readCook(name) : reads the above cookie in JS
	changeTipsContent(panelText) : changes the help/tips panel in the infoBar windows
	getMatch(searchType, controlHolder, suggestionHolder, resultValueHolder, resultTextHolder) : called by keyup on type into a textbox for drop alternative
	selectMatch(matchId, matchName, resultValueHolder, resultTextHolder, suggestionHolder) : performs the select for a drop alternative	
	isNumeric(inputText) : checks that a value passed is a number
	disableButton(buttonId) : disables a button after one click to prevent double-clicking
	keepAliveTrigger(triggerAction) : turns on or off the Keep Alive function in the main app
	secExpand(divId) : generic expand/collapse function for divs containing extra details
	genericSwapStyle(targetItem, targetClass) : simply pass in the item ID and the class name you want it to have. FINALLY!!! :o)

*/

<!--

var winWidth;
var winHeight;
var menuIsShown = 0;

//  #####################
//  BROWSER DETECT
function getBrowser() {
	var browserString;
	if (typeof(window.innerWidth) == 'number') {
		//Non-IE
		browserString = "other";
		} else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
		//IE 6+ in 'standards compliant mode'
		browserString = "ie6+";
		} else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
		//IE 4 compatible
		browserString = "ie4"
		}
	return browserString;
}


// ###########################################
// LEFT STRING FUNCTION
function left(str, n) {
	// Invalid bound, return blank string
	if (n <= 0) {
		return "";
		} else if (n > String(str).length) {
			// Invalid bound, return
			return str;
			} else {
			// Valid bound, return appropriate substring
			return String(str).substring(0,n);
			}
}


// #################################
// mid(string, start(ZERO BASED!!), length)
//
// Returns a specified number of characters from a string
function mid(str, start, len) {
	// Make sure start and len are within proper bounds
	if (start < 0 || len < 0) return "";
	
	var iEnd, iLen = String(str).length;
	
	if (start + len > iLen) {
		iEnd = iLen;
		} else {
			iEnd = start + len;
			}

	return String(str).substring(start,iEnd);
}


// #################################
// inStr(strSearch, charSearchFor)
// 
// InStr(strSearch, charSearchFor) : Returns the first location a substring (SearchForStr)
// was found in the string str.  (If the character is not found, -1 is returned.)
// Requires use of: Mid function
function inStr(str, charSearch) {
	for (i=0; i < str.length; i++) 	{
	    if (charSearch == mid(str, i, 1)) {
		return i;
	    }
	}
	return -1;
}


// ########################################
// HIGHLIGHT A TABLE ROW
//
// rowId - Id of the row to highlight
// startingClass - class to change back to when highlight is off
// action - 1 highlight is on OR <>1 highlight is off
function highlightRow(rowId, startingClass, action) {
    if (action == 1) {
        document.getElementById([rowId]).className = 'rowHover';
        } else {
        document.getElementById([rowId]).className = startingClass;
        }

}


// ###########################
// CENTERED POPUP WINDOW
function openPopup(popurl, winName, winWidth, winHeight, winScroll) {
	var winTop
	var winLeft

	winLeft = screen.width/2;
	winLeft = winLeft-(winWidth/2);

	winTop = screen.height/2;
	winTop = winTop-(winHeight/2);

	window.open(popurl,winName,"width=" + winWidth + ",height=" + winHeight + ",top=" + winTop + ",left=" + winLeft + ",scrollbars=" + winScroll + ",status=no,tool=no,location=no,resizable=1");
}


// #####################
// RESIZE FUNCTION
function sizePage() {

	// Get the inner-height of the page, then :
	// - set infoBarContent height (will force the table outwards) to : canvas height-142
	// - set contentFrame height (will force the div outwards) to : canvas height-142
	// - set contentFrame width (will force the div outwards) to : canvas width-250
	
	if (getBrowser() == 'other') {
		//Non-IE
		winWidth = window.innerWidth;
		winHeight = window.innerHeight;
		} else if (getBrowser() == 'ie6+') {
		//IE 6+ in 'standards compliant mode'
		winWidth = document.documentElement.clientWidth;
		winHeight = document.documentElement.clientHeight;
		} else if (getBrowser() == 'ie4') {
		//IE 4 compatible
		winWidth = document.body.clientWidth;
		winHeight = document.body.clientHeight;
		}

	document.getElementById("infoBarContent").style.height = parseInt(winHeight-142) + "px";
	document.getElementById("contentFrame").style.height = parseInt(winHeight-142) + "px";
	document.getElementById("contentFrame").style.width = parseInt(winWidth-246) + "px";
	if (menuIsShown == 1) {
		document.getElementById("menuHolder").style.top = parseInt(winHeight-326) + "px";
		}
}


// #######################
// SHOW/HIDE THE MENU	
function showMenu() {
	if (menuIsShown == 0) {
		// show
		document.getElementById("menuHolder").style.visibility = "visible";
		//document.getElementById("contentHolder").innerHTML = "SHOWING THE MENU!!!";
		if (getBrowser() == 'other') {
			document.getElementById("menuHolder").style.top = parseInt(winHeight-329) + "px";
			} else {
				document.getElementById("menuHolder").style.top = parseInt(winHeight-328) + "px";
				}
		//document.getElementById("menuStartButton").innerHTML = "start";
		menuIsShown = 1;
		} else {
		//hide
		document.getElementById("menuHolder").style.visibility = "hidden";
		//document.getElementById("contentHolder").innerHTML = "HIDING THE MENU!!!";
		document.getElementById("menuHolder").style.top = "-555px";
		//document.getElementById("menuStartButton").innerHTML = "start";
		menuIsShown = 0;
		}
}


// ################################
// CHANGE START MENU ITEM BG COLOUR
function changeMenuItemBg(action, cellId) {
	if (action == 1) {
		document.getElementById([cellId]).style.backgroundImage = "url(resources/images/menuItemHover.jpg)";
		} else {
		document.getElementById([cellId]).style.background = "";
		}
}


//  ##############################################
//  FUNCTION TO SET UP THE XMLHTTPREQUEST FOR AJAX
//
//  as different browsers use different XMLHTTP methods,
//  this function ensures the right one is used.
function httpReq() {

	var returnItem=null

	try {
		returnItem = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
				try {
				returnItem = new ActiveXObject("Microsoft.XMLHTTP");
				} catch(e) {
				//
				}
			}

	if (returnItem==null) {
		returnItem = new XMLHttpRequest();
		}


	// Now do the actual thing
	if (returnItem==null) {
		alert('Sorry, your browser does not support the HTTP request method.');
		return
		} else {
		return returnItem
		}

}


// #####################################################
// PARSE THE RETURNED TEXT TO ALLOW SCRIPT BLOCKS TO RUN
// pass in the target div id and the AJAX returned text

function setHtml(targetItem, content) {
	var search = content;
	var script;

	var is_singleq = 0; var singleq = "'";
	var is_doubleq = 0; var doubleq = '"';
	var is_escaped = 0; var escap = "\\";
	var layer = 0;

	while( script = search.match(/(<script[^>]+javascript[^>]+>\s*(<!--)?)/)) {
		search = search.substr(search.indexOf(RegExp.$1) + RegExp.$1.length);
		if (!(endscript = search.match(/((-->)?\s*<\/script>)/))) break;
		block = search.substr(0, search.indexOf(RegExp.$1));
		search = search.substring(block.length + RegExp.$1.length);

	while(func = block.match(/(function(.+?)\((.*?)\)\s*\{)/)) {
		eval(block.substr(0,block.indexOf(RegExp.$1)));
		// for evaluating non functions

	block = block.substr(block.indexOf(RegExp.$1) + RegExp.$1.length);
	name = RegExp.$2;
	param = RegExp.$3;

	is_singleq = 0;
	is_doubleq = 0;
	is_escaped = 0;
	layer = 0;


	for(i=0;i<block.length;i++) {
		c = block.substr(i,1);

		if ((is_singleq || is_doubleq) && is_escaped) {
			is_escaped = 0;
			} else if (!is_doubleq && (c==singleq)) {
			is_singleq = !is_singleq;
			} else if (!is_singleq && (c==doubleq)) {
			is_doubleq = !is_doubleq;
			} else if ((is_singleq || is_doubleq) && (c==escap)) {
			is_escaped = 1;
			} else if ( c=="{") {
			layer++;
			} else if ( c=="}") {
			if ( layer==0 ) {
			break;
			}
			layer--;
			}
		}

		code = block.substr(0,i-1);
		block = block.substr(i +1);

		code = code.replace(/\n/g, '\\n');
		code = code.replace(/\r/g, '\\r');
		code = code.replace(/'/g,"\\'");

		eval(name + " = new Function('"+param+"','"+code+"');");
	}
	eval(block); // for evaluating non functions
	}
	document.getElementById(targetItem).innerHTML = content;
}


//	#################################################################
//	AJAX CALL PROXY FUNCTION
//
//	Allows reduced parameter calls to the changeContent function
//	Call this proxy with all parameters on the QS
function changeContentProxy(paramString) {

	// example call : sourceFile=http://www.6point4.com/blog.aspx|qs=&param1=jijd&param2=odihf|targetItem=proxyTarget|useRandom=1|loadMessage=|spinnerType=small|parseScript=1|fromStartMenu=1|errorMessage=You messed up|parentCall=0

	var itemCount = 0;
	var sourceFile = "";
	var qs = "";
	var targetItem = "";
	var useRandom = 1;
	var loadMessage = "";
	var spinnerType = "small";
	var parseScript = 1;
	var errorMessage = "";
	var fromStartMenu = 0;
	var parentCall = 0;
	
	var paramArray = paramString.split("|");
	
	while (itemCount < paramArray.length) {
		
		// sort the source file
		if (left(paramArray[itemCount], 10) == "sourceFile") {
			sourceFile = mid(paramArray[itemCount], 11, paramArray[itemCount].length);
			}
		
		// sort any QS parameters
		if (left(paramArray[itemCount], 2) == "qs") {
			qs = mid(paramArray[itemCount], 3, paramArray[itemCount].length);
			}
		
		// sort targetItem
		if (left(paramArray[itemCount], 10) == "targetItem") {
			targetItem = mid(paramArray[itemCount], 11, paramArray[itemCount].length);
			}
		
		// sort useRandom
		if (left(paramArray[itemCount], 9) == "useRandom") {
			useRandom = mid(paramArray[itemCount], 10, paramArray[itemCount].length);
			}
		
		// sort loadMessage
		if (left(paramArray[itemCount], 11) == "loadMessage") {
			loadMessage = mid(paramArray[itemCount], 12, paramArray[itemCount].length);
			}
		
		// sort spinnerType
		if (left(paramArray[itemCount], 11) == "spinnerType") {
			spinnerType = mid(paramArray[itemCount], 12, paramArray[itemCount].length);
			}
		
		// sort parseScript
		if (left(paramArray[itemCount], 11) == "parseScript") {
			parseScript = mid(paramArray[itemCount], 12, paramArray[itemCount].length);
			}
		
		// sort errorMessage
		if (left(paramArray[itemCount], 12) == "errorMessage") {
			errorMessage = mid(paramArray[itemCount], 13, paramArray[itemCount].length);
			}
		
		// sort fromStartMenu
		if (left(paramArray[itemCount], 13) == "fromStartMenu") {
			fromStartMenu = mid(paramArray[itemCount], 14, paramArray[itemCount].length);
			}
		
		// sort parentCall (for use when calling this function in parent from iFrame)
		if (left(paramArray[itemCount], 10) == "parentCall") {
			parentCall = mid(paramArray[itemCount], 11, paramArray[itemCount].length);
			}
		
		itemCount++;
		}
		
		// alert out the info for debugging
		/*alert(sourceFile);
		alert(qs);
		alert(targetItem);
		alert(useRandom);
		alert(loadMessage);
		alert(spinnerType);
		alert(parseScript);
		alert(errorMessage);
		alert(fromStartMenu);
		alert(parentCall);*/

	// now finally call the function
	// changeContent(sourceFile, qs, targetItem, useRandom, loadMessage, spinnerType, parseScript, errorMessage, fromStartMenu, parentCall);
	setTimeout('changeContent(\'' + sourceFile + '\', \'' + qs + '\', \'' + targetItem + '\', ' + useRandom + ', \'' + loadMessage + '\', \'' + spinnerType + '\', ' + parseScript + ', \'' + errorMessage + '\', ' + fromStartMenu + ', ' + parentCall + ')', 100);	

}


//  #################################################################
//  FUNCTION TO PERFORM THE AJAX REQUEST TO CHANGE THE CONTENT WINDOW
//
//  pass in the file that is to be included, plus any parameter string
// format the parameters like this : &thing=blah&thing=blah...
function changeContent(sourceFile, paramString, targetItem, useRandom, loadMessage, spinnerType, parseScript, errorMessage, fromStartMenu, parentCall) {

	// create http variable based on random number so multiple can be used
	var loadingItem;
	var ranNumber = Math.floor(Math.random() * 100000+1);
	var httpObj = eval['http' + ranNumber];

	// now set the top margin value for the spinner image
	var topMargin = 0;
	topMargin = winHeight-176;
	topMargin = topMargin/2;
	// deduct half the spinner.gif height!!
	topMargin = topMargin-16;

	// set up the loading message
	if (loadMessage != "") {
		loadingItem = loadMessage;
		} else {
		if (spinnerType == "small") {
			loadingItem = "<center><img src='/resources/images/loaderSmall.gif' style='margin-top : " + topMargin + "px;' /></center>";
			} else {
			loadingItem = "<center><img src='/resources/images/loaderLarge.gif' style='margin-top : " + topMargin + "px;' /></center>";
			}
		}

	// check the browser type so we can position the spinner in the centre
	var winHeight = 0;
	if (getBrowser() == "other") {
		//Non-IE
		winHeight = window.innerHeight;
		} else if (getBrowser() == 'ie6+') {
		//IE 6+ in 'standards compliant mode'
		winHeight = document.documentElement.clientHeight;
		} else if (getBrowser() == 'ie4') {
		//IE 4 compatible
		winHeight = document.body.clientHeight;
		}
	
	// now set the thing to be the loading item
	try {
		document.getElementById(targetItem).innerHTML = loadingItem;
		} catch(e) {
		document.write('<br />' + e.message + ' - ' + targetItem + ' - ' + sourceFile);
		}

	// set up the XMLHttp variable
	httpObj=httpReq();
	
	// modify the path to the source file if parentCall = 1
	if (parentCall == 1) {
		if (getBrowser() == 'other') {
			sourceFile = "" + sourceFile;
			}
		}

	// call the page and add a random number to prevent using a cached one if reqd!
	var url;
	if (useRandom == 1) {
		url=sourceFile + "?ran=" + Math.random() + '&' + paramString;
		} else {
			url=sourceFile + "?" + paramString;
			}

	//  call the stateChanged function
	httpObj.onreadystatechange = function () {
		if (httpObj.readyState==4||httpObj.readyState=="complete") {
			// check the status of the return (200 should be ok)
			if (httpObj.status==200) {				
				try {
					//setHtml(targetItem, eval['http' + ranNumber].responseText);
					if (parseScript == 1) {
						setHtml(targetItem, httpObj.responseText);
						} else {
						document.getElementById(targetItem).innerHTML = httpObj.responseText.replace('\'', '\'');
						}
					} catch(e) {
					document.write('e : ' + e.message);
					}
				} else {
				if (errorMessage != "") {
					document.getElementById(targetItem).innerHTML = errorMessage;
					} else {
					document.getElementById(targetItem).innerHTML = "<img src='/resources/images/icons/cross.gif' />";
					}
				}
			}
		}
	httpObj.open("GET",url,true);
	httpObj.send(' ');

}


// #####################
// HANDLE FORM IN AJAX
// 
// this function will step through the controls 
// on the form then pass them on the QS to 
// the ajax control for use in calling the code behind.
function passForm(targetHandler, formName, displayName) {

	var paramString = "passed=1";
	var fieldNameLength = 0;
	var fieldName = "";
	var fieldValue = "";
	var fieldType = "";
	
	for(i=0; i<document.forms[formName].elements.length; i++) {
	
		// set the fieldName to the err...field name!
		fieldName = document.forms[formName].elements[i].name;
		// calculate the fieldNameLength
		fieldNameLength = document.forms[formName].elements[i].name.length;
		// get the field type
		fieldType = left(fieldName, 4);
		
		// textboxes
		if (fieldType == "txt_") {
			// set the fieldValue to the..guess...
			fieldValue = document.forms[formName].elements[i].value;
			// use the mid function to get the field name without the prefix
			fieldName = mid(fieldName, 4, fieldNameLength-4);
			
			fieldValue = fieldValue.replace(/\n/g, '\\n');
			fieldValue = fieldValue.replace(/\r/g, '\\r');
			fieldValue = fieldValue.replace(/\'/g,"\\'");
			
			paramString = paramString + '&' + fieldName + '=' + fieldValue;
			}
		
		// drop downs
		if (fieldType == "drp_") {
			// set the fieldValue to the..guess...
			fieldValue = document.forms[formName].elements[i].value;
			// use the mid function to get the field name without the prefix
			fieldName = mid(fieldName, 4, fieldNameLength-4);
			
			fieldDesc = document.forms[formName].elements[i].options[document.forms[formName].elements[i].selectedIndex].text;
			fieldDesc = fieldDesc.replace(/\'/g,"\\'");
			
			paramString = paramString + '&' + fieldName + '=' + fieldValue + '&' + fieldName + 'Text=' + fieldDesc;
			}

		// check boxes
		if (fieldType == "chk_") {
			// set the fieldValue to the..guess...
			fieldValue = document.forms[formName].elements[i].checked;
			// use the mid function to get the field name without the prefix
			fieldName = mid(fieldName, 4, fieldNameLength-4);
			
			paramString = paramString + '&' + fieldName + '=' + fieldValue;
			}
		
		
		// hidden fields
		if (fieldType == "hid_") {
			// set the fieldValue to the..guess...
			fieldValue = document.forms[formName].elements[i].value;
			// use the mid function to get the field name without the prefix
			fieldName = mid(fieldName, 4, fieldNameLength-4);
			
			paramString = paramString + '&' + fieldName + '=' + fieldValue;
			}
		
		
		}

	
	//alert(paramString);
	
	changeContentProxy('sourceFile=' + targetHandler + '|qs=' + paramString + '|targetItem=' + displayName);
	
	//changeContent(targetHandler, paramString, displayName, 1, '', 'large', 1);
	
}



// ########################################
// FUNCTIONS TO SHOW/HIDE POPUP WINDOW ALTERNATIVES
function showSubFaux(bufferHeight) {

	document.getElementById("popOverlay").style.display = "block";
	document.getElementById("popOverlay").style.width = 940 + "px";
	document.getElementById("popHideSelect").style.width = 940 + "px";		
	document.getElementById("popOverlay").style.height = 530 + "px";
	document.getElementById("popHideSelect").style.height = 530 + "px";		
	document.getElementById("popHideSelect").style.display = "block";
	document.getElementById("popWindow").style.display = "block";
	document.getElementById("popWindow").style.width = "720px";
	document.getElementById("popWindow").style.height = bufferHeight + "px";
	document.getElementById("popWindow").style.top = 50 + "px";
	document.getElementById("popWindow").style.left = 100 + "px";
}


// ########################################
// FUNCTIONS TO SHOW/HIDE POPUP WINDOW ALTERNATIVES
function showSub(bufferHeight) {
	var winWidth;
	var winHeight;
	var xScroll;
	var yScroll;
	
	// get the display window dimensions
	if (getBrowser() == 'other') {
		//Non-IE
		winWidth = window.innerWidth;
		winHeight = window.innerHeight;
		} else if (getBrowser() == 'ie6+') {
		//IE 6+ in 'standards compliant mode'
		winWidth = document.documentElement.clientWidth;
		winHeight = document.documentElement.clientHeight;
		} else if (getBrowser() == 'ie4') {
		//IE 4 compatible
		winWidth = document.body.clientWidth;
		winHeight = document.body.clientHeight;
		}
	
	// now get the value of the scrolling dimensions
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight) {
			// all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
			} else {
			// Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
			}

	document.getElementById("popOverlay").style.display = "block";
	if (getBrowser() == 'other') {
		document.getElementById("popOverlay").style.width = winWidth-0 + "px";
		document.getElementById("popHideSelect").style.width = winWidth-0 + "px";
		} else {
		document.getElementById("popOverlay").style.width = winWidth-0 + "px";
		document.getElementById("popHideSelect").style.width = winWidth-0 + "px";
		}
	if (yScroll > winHeight) {
		document.getElementById("popOverlay").style.height = yScroll + "px";
		document.getElementById("popHideSelect").style.height = yScroll + "px";
		} else {
		document.getElementById("popOverlay").style.height = winHeight + "px";
		document.getElementById("popHideSelect").style.height = winHeight + "px";
		}
	document.getElementById("popHideSelect").style.display = "block";
	document.getElementById("popWindow").style.display = "block";
	document.getElementById("popWindow").style.width = "720px";
	document.getElementById("popWindow").style.height = bufferHeight + "px";
	document.getElementById("popWindow").style.top = (winHeight/2)-(bufferHeight/2) + "px";
	document.getElementById("popWindow").style.left = (winWidth/2)-360 + "px";
}


// HIDE THE POPUP ALTERNATIVE
function hideSub() {
	document.getElementById("popWindow").innerHTML = '&nbsp;';
	document.getElementById("popOverlay").style.display = "none";
	document.getElementById("popHideSelect").style.display = "none";
	document.getElementById("popWindow").style.display = "none";
}

// HIDE THE POPUP ALTERNATIVE for quote engine use
function hideSubNoClear() {
	document.getElementById("popOverlay").style.display = "none";
	document.getElementById("popHideSelect").style.display = "none";
	document.getElementById("popWindow").style.display = "none";
}


// CHECK OVERLAY
function checkOverlay() {
	var winWidth;
	var winHeight;
	var popWinHeight;
	popWinHeight = document.getElementById("popWindow").style.height;
	popWinHeight = parseFloat(popWinHeight.replace(/px/i, ""));
	if (isNaN(popWinHeight)) {
		popWinHeight = 0;
		}

	// get the display window dimensions
	if (getBrowser() == 'other') {
		//Non-IE
		winWidth = window.innerWidth;
		winHeight = window.innerHeight;
		} else if (getBrowser() == 'ie6+') {
		//IE 6+ in 'standards compliant mode'
		winWidth = document.documentElement.clientWidth;
		winHeight = document.documentElement.clientHeight;
		} else if (getBrowser() == 'ie4') {
		//IE 4 compatible
		winWidth = document.body.clientWidth;
		winHeight = document.body.clientHeight;
		}

	// now get the value of the scrolling dimensions
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight) {
			// all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
			} else {
			// Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
			}

	if (getBrowser() == 'other') {
		document.getElementById("popOverlay").style.width = winWidth-0 + "px";
		document.getElementById("popHideSelect").style.width = winWidth-0 + "px";
		} else {
		document.getElementById("popOverlay").style.width = winWidth-0 + "px";
		document.getElementById("popHideSelect").style.width = winWidth-0 + "px";
		}
	if (yScroll > winHeight) {
		document.getElementById("popOverlay").style.height = yScroll + "px";
		document.getElementById("popHideSelect").style.height = yScroll + "px";
		} else {
		document.getElementById("popOverlay").style.height = winHeight + "px";
		document.getElementById("popHideSelect").style.height = winHeight + "px";
		}
	
	document.getElementById("popWindow").style.top = (winHeight/2)-(popWinHeight/2) + "px";
	document.getElementById("popWindow").style.left = (winWidth/2)-360 + "px";
}


//	######################################
//	JAVASCRIPT CLOCK
//	call this in the onload element of the body tag on a page
function clock(targetId) {
	var thetime=new Date();
	var nhours=thetime.getHours();
	var nmins=thetime.getMinutes();
	var nsecn=thetime.getSeconds();
	var nday=thetime.getDay();
	var nmonth=thetime.getMonth();
	var ntoday=thetime.getDate();
	var nyear=thetime.getYear();
	var AorP=" ";

	if (nhours>=12)
		AorP="pm";
	else
		AorP="am";

	if (nhours>=13)
		nhours-=12;
	
	/*if (nhours<10)
		nhours="0" + nhours;*/

	if (nhours==0)
		nhours=12;

	if (nsecn<10)
		nsecn="0" + nsecn;

	if (nmins<10)
		nmins="0" + nmins;

	if (nday==0)
		nday="Sun";
	if (nday==1)
		nday="Mon";
	if (nday==2)
		nday="Tue";
	if (nday==3)
		nday="Wed";
	if (nday==4)
		nday="Thu";
	if (nday==5)
		nday="Fri";
	if (nday==6)
		nday="Sat";

	if (ntoday<10)
		ntoday="0" + ntoday

	nmonth+=1;
	if (nmonth<10)
		nmonth="0" + nmonth

	if (nyear<=99)
		nyear= "19" + nyear;

	if ((nyear>99) && (nyear<2000))
		nyear += 1900;

	document.getElementById([targetId]).innerHTML =  nday + ", " + ntoday + "/" + nmonth + "/" + nyear + ", " + nhours + ":" + nmins + ":" + nsecn + "" + AorP;

	setTimeout('clock("' + targetId + '")',1000);
}


//  ########################################
//  SET A FIXED HEIGHT FOR THE SCROLLING DIV
//  used primarily for scrolling results under a fixed header,
//  scrolling divs require a fixed height, so one must be provided
//  in script.
//  bufferSize = height to be allowed from the top of the page.
function checkScrollingDiv(bufferSize) {

    var scrollDivHeight = 0;
    
    if (getBrowser() == 'other') {
		//Non-IE
		winHeight = window.innerHeight;
		} else if (getBrowser() == 'ie6+') {
		//IE 6+ in 'standards compliant mode'
		winHeight = document.documentElement.clientHeight;
		} else if (getBrowser() == 'ie4') {
		//IE 4 compatible
		winHeight = document.body.clientHeight;
		}

    // 'try' added as scrolling div might not always be there.
    try {
        scrollDivHeight = parseInt(bufferSize);
        scrollDivHeight = winHeight-scrollDivHeight;
		document.getElementById('scrollingDiv').style.height = scrollDivHeight + 'px';
		document.getElementById('scrollingDiv').style.minHeight = scrollDivHeight + 'px';
		} catch(e) {
		// no need to do anything. If it's not working it's because the div is not there!

		}

}

//	#########################################
//	SHOW/HIDE EXTRA LIST ITEMS
//	used in expanding tree menus. Pass in :
//		divId = id of the div being shown/hidden
//		loadPage(0/1) = says if there is an ajax page to be loaded into the loadTarget
//		loadSource = path to the page to be loaded into the loadTarget
//		loadTarget = id of the target for the loadSource to populate
//		loadTarget = any paramters to be added to the loadSource
//		hasImage = is there a plus/minus?? 0/1
function infoBarTreeExpand(divId, loadPage, loadSource, loadTarget, loadParams, hasImage) {
	
	if (document.getElementById(divId).style.display == "inline") {
		document.getElementById(divId).style.display = "none";
		if (hasImage==1) {
			document.getElementById('img_' + divId).src = "/resources/images/icons/plus.gif";
			}
		} else {
			if (loadPage == 0) {
				document.getElementById(divId).style.display = "inline";
				if (hasImage==1) {
					document.getElementById('img_' + divId).src = "/resources/images/icons/minus.gif";
					}
				} else {
					document.getElementById(divId).style.display = "inline";
					if (hasImage==1) {
						document.getElementById('img_' + divId).src = "/resources/images/icons/minus.gif";
						}
					changeContent(loadSource, loadParams, loadTarget, 1, 'loading...', '', 1);
					}			
			}

}


//	###########################
//	CLEAR INFOBAR CONTENT
//	simply clears any html from the infoBar from the parent page only!
function clearInfoBar() {
	document.getElementById('infoBarContent').innerHTML = '';
	}


//	#############################
//	CHANGE CONTENT AREA TOP TEXT
//	changes the the text in the top
//	(coloured) bar on the content area
function changeTopBarText(messageText) {
	document.getElementById("topBarText").innerHTML = messageText;
	}


//	######################
//	TOOLTIP-STYLE INFO BOX - 070530 : REQUIRES RE-CODE!!!! FRICKEN I.E.!!!
var xMousePos = 0;
var yMousePos = 0;
var xMousePosMax = 0;
var yMousePosMax = 0;
var verticalBuffer = 0;
var horizontalBuffer = 0;
var tipId;

function callTip(action, tipHolder, vertBuffer, horizBuffer) {

	tipId = document.getElementById([tipHolder])
	
	verticalBuffer = vertBuffer;
	horizontalBuffer = horizBuffer;

	if (action == 1) {
		tipId.style.position = "absolute";
		tipId.style.display = "inline";

		if (document.layers) {	// Netscape
			document.captureEvents(Event.MOUSEMOVE);
			document.onmousemove = captureMousePosition;
			} else if (document.all) {	// Internet Explorer
				document.onmousemove = captureMousePosition;
				} else if (document.getElementById) {	// Netcsape 6
				document.onmousemove = captureMousePosition;
				}

		} else {
		tipId.style.display = "none";
		}
	
	}

// the meat of the function
function captureMousePosition(e) {

	if (document.layers) {
		//Opera/Nutscrape V4
		xMousePos = e.pageX;
		yMousePos = e.pageY;
		xMousePosMax = window.innerWidth+window.pageXOffset;
		yMousePosMax = window.innerHeight+window.pageYOffset;
		} else if (document.all) {
		//IE4+
		xMousePos = window.event.x+document.body.scrollLeft;
		yMousePos = window.event.y+document.body.scrollTop;
		xMousePosMax = document.body.clientWidth+document.body.scrollLeft;
		yMousePosMax = document.body.clientHeight+document.body.scrollTop;
		} else if (document.getElementById) {
		//Mozilla
		xMousePos = e.pageX;
		yMousePos = e.pageY;
		xMousePosMax = window.innerWidth+window.pageXOffset;
		yMousePosMax = window.innerHeight+window.pageYOffset;
		}

	// check to make sure the tooltip is not going to spanner off the screen
	if (xMousePos > (xMousePosMax-horizontalBuffer)) {
		xMousePos = parseInt(xMousePos) - (horizontalBuffer+15);
		//if (yMousePos > (yMousePos-verticalBuffer)) {
		//	yMousePos = parseInt(yMousePos)-(verticalBuffer+15);
		//	} else {
			yMousePos = parseInt(yMousePos) + 15;
		//	}
		} else {
		xMousePos = parseInt(xMousePos) + 15;
		//if (yMousePos > (yMousePos-verticalBuffer)) {
		//	yMousePos = parseInt(yMousePos)-(verticalBuffer+15);
		//	} else {
			yMousePos = parseInt(yMousePos) + 15;
		//	}
		}

	
	tipId.style.left = xMousePos + "px";
	tipId.style.top = yMousePos + "px";
	
	}


//	######################################
//	ENABLE/DISABLE ELEMENT - SUB PAGE ONLY
//	enables or disables a control by id.
//	pass in :
//	controlId - id of the item to alter
//	controlType - type for style change 'textbox', 'button' or 'dropdown' are all that matter.
function changeControlState(controlId, controlType) {
	
	if (document.getElementById("ctl00_ContentPlaceHolder1_" + controlId).disabled == true) {
		document.getElementById("ctl00_ContentPlaceHolder1_" + controlId).disabled = false;
		if (controlType == "textbox") {
			document.getElementById("ctl00_ContentPlaceHolder1_" + controlId).className = "standardInput";
			}
		if (controlType == "dropdown") {
			document.getElementById("ctl00_ContentPlaceHolder1_" + controlId).className = "standardDropDown";
			}
		if (controlType == "button") {
			document.getElementById("ctl00_ContentPlaceHolder1_" + controlId).className = "standardButton";
			}
		} else {
		document.getElementById("ctl00_ContentPlaceHolder1_" + controlId).disabled = true;
		if (controlType == "textbox") {
			document.getElementById("ctl00_ContentPlaceHolder1_" + controlId).className = "standardInputDisabled";
			}
		if (controlType == "dropdown") {
			document.getElementById("ctl00_ContentPlaceHolder1_" + controlId).className = "standardDropDownDisabled";
			}
		if (controlType == "button") {
			document.getElementById("ctl00_ContentPlaceHolder1_" + controlId).className = "standardButtonDisabled";
			}
		}

	}

//  ##########################
//  JS EQUIVALENT OF URLENCODE
//
//  pass in the url
function urlEncode(urlStream) {
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +
	"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +
	"abcdefghijklmnopqrstuvwxyz" +
	"-_.!~*'()";
	var HEX = "0123456789ABCDEF";

	var plaintext = urlStream;
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
		if (ch == " ") {
			encoded += "+";
			} else if (SAFECHARS.indexOf(ch) != -1) {
			encoded += ch;
			} else {
			var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
				alert( "Unicode Character '" 
				+ ch 
				+ "' cannot be encoded using standard URL encoding.\n" +
				"(URL encoding only supports 8-bit characters.)\n" +
				"A space (+) will be substituted." );
				encoded += "+";
				} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
				}
		}
	}

	alert(encoded);
	return false;
	}


//	#########################
//	CHECK SURE CONFIRM BOX
//
//	pass in message string (JS format) and 0/1 if an 
//	additional 'cancelled' alert should be shown
function checkSure(messageText, showAlert) {

	var checkSure;

	checkSure = confirm(messageText);

	if (checkSure) {
		// do what you want if they click ok
		return true;
		} else {
		// they clicked cancel
		if (showAlert == 1) {
			alert('Action cancelled.');
			return false;
			} else {
				return false;
				}
		}

	}



// ################################
// OPEN A MyDocs DOCUMENT IN A NEW WINDOW
// function getDocument(targetPath, fromInbox) {
function getDocument(targetPath, fromInbox) {
	var winTop;
	var winLeft;
	var winWidth;
	var winHeight;

	winWidth = 270;
	winHeight = 130;

	// calculate the position to get the centre of the screen
	winLeft = screen.width/2;
	winLeft = winLeft-(winWidth/2);
	winTop = screen.height/2;
	winTop = winTop-(winHeight/2);

	// generate the popup
	openPopup('viewer.aspx?targetPath=' + targetPath + '&fromInbox=' + fromInbox, 'documentViewer', 270, 130, 'no');
	}



// ################################
// SWITCH THE STYLE UNLESS SELECTED
function switchStyle(itemId, newClass) {
	try {
		if (document.getElementById(itemId.id).className != 'calDaySelected') {
		document.getElementById(itemId.id).className = newClass;
		}
	} catch(e) {
		try {
			if (document.getElementById(itemId.id).className != 'calDaySelected') {	
				document.getElementById(itemId).className = newClass;
				}
			} catch(e) {
			}
	}
}


// #####################################
// SWITCH THE STYLE BACK UNLESS HAS BEEN SELECTED
function switchBack(itemId, newClass) {
	try {
		if (document.getElementById(itemId.id).className != 'calDaySelected') {
		document.getElementById(itemId.id).className = newClass;
		}
		} catch(e) {
		}
}


// ###############################
// CHANGE THE MONTH ON DISPLAY
// direction = previous/next
function changeMonth(direction) {
	var monthToGet;
	var yearToGet;
	var newPreviousMonth;
	var newPreviousYear;
	var newNextMonth;
	var newNextYear;
	var monthName;
	
	// get the month to get information from the hidden holders
	monthToGet = parseInt(document.getElementById([direction + 'MonthHolder']).value);
	yearToGet = parseInt(document.getElementById([direction + 'YearHolder']).value);

	// set up the monthName variable from the other function
	monthName = getMonthName(monthToGet);
	
	// calculate the new previous month
	if (monthToGet == 1) {
		newPreviousMonth = 12;
		newPreviousYear = parseInt(yearToGet-1);
		} else {
		newPreviousMonth = parseInt(monthToGet-1);
		newPreviousYear = yearToGet;
		}
	
	// calculate the new next month
	if (monthToGet == 12 ) {
		newNextMonth = 1;
		newNextYear = parseInt(yearToGet+1);
		} else {
		newNextMonth = parseInt(monthToGet+1);
		newNextYear = yearToGet;
		}
	
	// alert that shit
	/*alert('monthToGet = ' + monthToGet + '\n\nyearToGet = ' + yearToGet);
	alert('newPreviousMonth = ' + newPreviousMonth + '\n\newPreviousYear = ' + newPreviousYear);
	alert('newNextMonth = ' + newNextMonth + '\n\nnewNextYear = ' + newNextYear);*/
	
	// set the hidden values with the new previous and hidden values
	document.getElementById("previousMonthHolder").value = newPreviousMonth;
	document.getElementById("previousYearHolder").value = newPreviousYear;
	document.getElementById("nextMonthHolder").value = newNextMonth;
	document.getElementById("nextYearHolder").value = newNextYear;
	
	// set the text in the title to be the new month on display
	document.getElementById("monthTitle").innerHTML = monthName + " " + yearToGet;
	
	changeContentProxy('sourceFile=diary/calendarDays.aspx|qs=&monthId=' + monthToGet + '&yearId=' + yearToGet + '|targetItem=calDays');
	
}


// ######################
// RETURN THE MONTH AS A WORD
function getMonthName(monthId) {

	switch(monthId) {
		case 1: return 'january';
		case 2: return 'february';
		case 3: return 'march';
		case 4: return 'april';
		case 5: return 'may';
		case 6: return 'june';
		case 7: return 'july';
		case 8: return 'august';
		case 9: return 'september';
		case 10: return 'october';
		case 11: return 'november';
		case 12: return 'december';
		}

}


// ######################################
// HANDLE THE CLICK OF A SINGLE DAY ON THE CALENDAR
function dayClick(dayId, monthId, yearId, hourId) {
	
	var cellCount;
	var rowCount;
	var returnThing;
	var calendarControl;
	calendarControl = document.getElementById("calendarDays");
	
	// deselect all other selected cells
	for (rowCount=0; rowCount<calendarControl.rows.length; rowCount++) {
		for (cellCount=0; cellCount<calendarControl.rows[rowCount].cells.length; cellCount++) {
			if (calendarControl.rows[rowCount].cells[cellCount].className == 'calDaySelected') {
				if (left(calendarControl.rows[rowCount].cells[cellCount].id, 4) == 'prev') {
					calendarControl.rows[rowCount].cells[cellCount].className = 'calOtherDay';
					} else {
					if (left(calendarControl.rows[rowCount].cells[cellCount].id, 4) == 'next') {
						calendarControl.rows[rowCount].cells[cellCount].className = 'calOtherDay';
						} else {
							if (calendarControl.rows[rowCount].cells[cellCount].getAttribute("hasEntry") == "1") {
							calendarControl.rows[rowCount].cells[cellCount].className = "calEntry";
							} else {
							calendarControl.rows[rowCount].cells[cellCount].className = 'calDay';
							}
						}
					}
				}
			}
		}
	
	// do whatever you want with this info, kiddo!
	top.frames['contentFrame'].location.href = "diary/dayView.aspx?year=" + yearId + "&month=" + monthId + "&day=" + dayId + "#" + hourId
	changeContentProxy('sourceFile=diary/calendar.aspx|qs=day=' + dayId + '&month=' + monthId + '&year=' + yearId + '|targetItem=infoBarContent|fromStartMenu=1');

}


// ##################################
// HANDLE THE CLICK OF A WEEK ON THE CALENDAR
function weekClick(rowId, dayId, monthId, yearId) {
	
	var cellCount;
	var rowCount;
	var returnThing;
	var calendarControl;
	calendarControl = document.getElementById("calendarDays");
	
	// deselect all other cells
	for (rowCount=0; rowCount<calendarControl.rows.length; rowCount++) {
		for (cellCount=0; cellCount<calendarControl.rows[rowCount].cells.length; cellCount++) {
			if (calendarControl.rows[rowCount].cells[cellCount].className == 'calDaySelected') {
				if (left(calendarControl.rows[rowCount].cells[cellCount].id, 4) == 'prev') {
					calendarControl.rows[rowCount].cells[cellCount].className = 'calOtherDay';
					} else {
					if (left(calendarControl.rows[rowCount].cells[cellCount].id, 4) == 'next') {
						calendarControl.rows[rowCount].cells[cellCount].className = 'calOtherDay';
						} else {
						if (calendarControl.rows[rowCount].cells[cellCount].getAttribute("hasEntry") == "1") {
							calendarControl.rows[rowCount].cells[cellCount].className = "calEntry";
							} else {
							calendarControl.rows[rowCount].cells[cellCount].className = 'calDay';
							}
						}
					}
				}
			}
		}
	
	// select the whole row
	for (cellCount=0; cellCount<document.getElementById([rowId]).cells.length; cellCount++) {
		if (document.getElementById([rowId]).cells[cellCount].className != 'calWeekHeader') {
			document.getElementById([rowId]).cells[cellCount].className = 'calDaySelected';
			}
		}
	
	// do whatever you want with this info, kiddo!
	top.frames['contentFrame'].location.href = "diary/weekView.aspx?year=" + yearId + "&month=" + monthId + "&day=" + dayId
	//changeContentProxy('sourceFile=diary/weekView.aspx|qs=doWeek=1&day=' + dayId + '&month=' + monthId + '&year=' + yearId + '|targetItem=dayDisplay');	

}


// ###############################
// CHANGE THE MONTH ON DISPLAY - V2 APPLICATION CODE
// direction = previous/next
function changeMonthV2(direction) {
	var monthToGet;
	var yearToGet;
	var newPreviousMonth;
	var newPreviousYear;
	var newNextMonth;
	var newNextYear;
	var monthName;
	
	// get the month to get information from the hidden holders
	monthToGet = parseInt(document.getElementById([direction + 'MonthHolder']).value);
	yearToGet = parseInt(document.getElementById([direction + 'YearHolder']).value);

	// set up the monthName variable from the other function
	monthName = getMonthName(monthToGet);
	
	// calculate the new previous month
	if (monthToGet == 1) {
		newPreviousMonth = 12;
		newPreviousYear = parseInt(yearToGet-1);
		} else {
		newPreviousMonth = parseInt(monthToGet-1);
		newPreviousYear = yearToGet;
		}
	
	// calculate the new next month
	if (monthToGet == 12 ) {
		newNextMonth = 1;
		newNextYear = parseInt(yearToGet+1);
		} else {
		newNextMonth = parseInt(monthToGet+1);
		newNextYear = yearToGet;
		}
	
	// alert that shit
	/*alert('monthToGet = ' + monthToGet + '\n\nyearToGet = ' + yearToGet);
	alert('newPreviousMonth = ' + newPreviousMonth + '\n\newPreviousYear = ' + newPreviousYear);
	alert('newNextMonth = ' + newNextMonth + '\n\nnewNextYear = ' + newNextYear);*/
	
	// set the hidden values with the new previous and hidden values
	document.getElementById("previousMonthHolder").value = newPreviousMonth;
	document.getElementById("previousYearHolder").value = newPreviousYear;
	document.getElementById("nextMonthHolder").value = newNextMonth;
	document.getElementById("nextYearHolder").value = newNextYear;
	
	// set the text in the title to be the new month on display
	document.getElementById("monthTitle").innerHTML = monthName + " " + yearToGet;
	
	changeContentProxy('sourceFile=diaryV2/calendarDays.aspx|qs=&monthId=' + monthToGet + '&yearId=' + yearToGet + '|targetItem=calDays');
	
}



// ####################################################################
// HANDLE THE CLICK OF A SINGLE DAY ON THE CALENDAR - V2 APPLICATION CODE
function dayClickV2(dayId, monthId, yearId, hourId) {
	
	var cellCount;
	var rowCount;
	var returnThing;
	var calendarControl;
	calendarControl = document.getElementById("calendarDays");
	
	// deselect all other selected cells
	for (rowCount=0; rowCount<calendarControl.rows.length; rowCount++) {
		for (cellCount=0; cellCount<calendarControl.rows[rowCount].cells.length; cellCount++) {
			if (calendarControl.rows[rowCount].cells[cellCount].className == 'calDaySelected') {
				if (left(calendarControl.rows[rowCount].cells[cellCount].id, 4) == 'prev') {
					calendarControl.rows[rowCount].cells[cellCount].className = 'calOtherDay';
					} else {
					if (left(calendarControl.rows[rowCount].cells[cellCount].id, 4) == 'next') {
						calendarControl.rows[rowCount].cells[cellCount].className = 'calOtherDay';
						} else {
							if (calendarControl.rows[rowCount].cells[cellCount].getAttribute("hasEntry") == "1") {
							calendarControl.rows[rowCount].cells[cellCount].className = "calEntry";
							} else {
							calendarControl.rows[rowCount].cells[cellCount].className = 'calDay';
							}
						}
					}
				}
			}
		}
	
	// do whatever you want with this info, kiddo!
	top.frames['contentFrame'].location.href = "diaryV2/dayView.aspx?year=" + yearId + "&month=" + monthId + "&day=" + dayId + "#" + hourId
	changeContentProxy('sourceFile=diaryV2/menuBar.aspx|qs=day=' + dayId + '&month=' + monthId + '&year=' + yearId + '|targetItem=infoBarContent|fromStartMenu=1');

}


// ##############################################################
// HANDLE THE CLICK OF A WEEK ON THE CALENDAR - V2 APPLICATION CODE
function weekClickV2(rowId, dayId, monthId, yearId) {
	
	var cellCount;
	var rowCount;
	var returnThing;
	var calendarControl;
	calendarControl = document.getElementById("calendarDays");
	
	// deselect all other cells
	for (rowCount=0; rowCount<calendarControl.rows.length; rowCount++) {
		for (cellCount=0; cellCount<calendarControl.rows[rowCount].cells.length; cellCount++) {
			if (calendarControl.rows[rowCount].cells[cellCount].className == 'calDaySelected') {
				if (left(calendarControl.rows[rowCount].cells[cellCount].id, 4) == 'prev') {
					calendarControl.rows[rowCount].cells[cellCount].className = 'calOtherDay';
					} else {
					if (left(calendarControl.rows[rowCount].cells[cellCount].id, 4) == 'next') {
						calendarControl.rows[rowCount].cells[cellCount].className = 'calOtherDay';
						} else {
						if (calendarControl.rows[rowCount].cells[cellCount].getAttribute("hasEntry") == "1") {
							calendarControl.rows[rowCount].cells[cellCount].className = "calEntry";
							} else {
							calendarControl.rows[rowCount].cells[cellCount].className = 'calDay';
							}
						}
					}
				}
			}
		}
	
	// select the whole row
	for (cellCount=0; cellCount<document.getElementById([rowId]).cells.length; cellCount++) {
		if (document.getElementById([rowId]).cells[cellCount].className != 'calWeekHeader') {
			document.getElementById([rowId]).cells[cellCount].className = 'calDaySelected';
			}
		}
	
	// do whatever you want with this info, kiddo!
	top.frames['contentFrame'].location.href = "diaryV2/weekView.aspx?year=" + yearId + "&month=" + monthId + "&day=" + dayId
	//changeContentProxy('sourceFile=diary/weekView.aspx|qs=doWeek=1&day=' + dayId + '&month=' + monthId + '&year=' + yearId + '|targetItem=dayDisplay');	

}



// ######################
// RETURN THE MONTH AS A WORD - MODULE APPLICATION CODE
function getMonthImage(monthId) {

	switch(monthId) {
		case 1: return 'jan';
		case 2: return 'feb';
		case 3: return 'mar';
		case 4: return 'apr';
		case 5: return 'may';
		case 6: return 'jun';
		case 7: return 'jul';
		case 8: return 'aug';
		case 9: return 'sep';
		case 10: return 'oct';
		case 11: return 'nov';
		case 12: return 'dec';
		}

}


// ###############################
// CHANGE THE MONTH ON DISPLAY - MODULE APPLICATION CODE
// direction = previous/next
function changeMonthMod(direction) {
	var monthToGet;
	var yearToGet;
	var newPreviousMonth;
	var newPreviousYear;
	var newNextMonth;
	var newNextYear;
	var monthName;
	
	// get the month to get information from the hidden holders
	monthToGet = parseInt(document.getElementById([direction + 'MonthHolder']).value);
	yearToGet = parseInt(document.getElementById([direction + 'YearHolder']).value);

	// set up the monthName variable from the other function
	monthName = getMonthImage(monthToGet);
	
	// calculate the new previous month
	if (monthToGet == 1) {
		newPreviousMonth = 12;
		newPreviousYear = parseInt(yearToGet-1);
		} else {
		newPreviousMonth = parseInt(monthToGet-1);
		newPreviousYear = yearToGet;
		}
	
	// calculate the new next month
	if (monthToGet == 12 ) {
		newNextMonth = 1;
		newNextYear = parseInt(yearToGet+1);
		} else {
		newNextMonth = parseInt(monthToGet+1);
		newNextYear = yearToGet;
		}
	
	// alert that shit
	/*alert('monthToGet = ' + monthToGet + '\n\nyearToGet = ' + yearToGet);
	alert('newPreviousMonth = ' + newPreviousMonth + '\n\newPreviousYear = ' + newPreviousYear);
	alert('newNextMonth = ' + newNextMonth + '\n\nnewNextYear = ' + newNextYear);*/
	
	// set the hidden values with the new previous and hidden values
	document.getElementById("previousMonthHolder").value = newPreviousMonth;
	document.getElementById("previousYearHolder").value = newPreviousYear;
	document.getElementById("nextMonthHolder").value = newNextMonth;
	document.getElementById("nextYearHolder").value = newNextYear;
	document.getElementById("currMonthHolder").value = monthToGet;
	document.getElementById("currYearHolder").value = yearToGet;
	
	// change the month image
	document.getElementById("img_monthName").src = "/resources/calImages/monthHeaders/" + monthName + ".jpg"; // + " " + yearToGet;
	// change the year images
	document.getElementById("img_yearThou").src = "/resources/calImages/numbers/" + left(yearToGet, 1) + ".jpg";
	document.getElementById("img_yearHun").src = "/resources/calImages/numbers/" + mid(yearToGet, 1, 1) + ".jpg";
	document.getElementById("img_yearTen").src = "/resources/calImages/numbers/" + mid(yearToGet, 2, 1) + ".jpg";
	document.getElementById("img_yearSin").src = "/resources/calImages/numbers/" + mid(yearToGet, 3, 1) + ".jpg";
	
	changeContentProxy('sourceFile=diaryModule/calPop.aspx|qs=type=body&month=' + monthToGet + '&year=' + yearToGet + '|targetItem=calBodyHolder');
	
}


// ####################################################################
// HANDLE THE CLICK OF A SINGLE DAY ON THE CALENDAR - MODULE APPLICATION CODE
function dayClickMod(dayId, monthId, yearId, hourId, doHead) {
	
	var cellCount;
	var rowCount;
	var returnThing;
	var calendarControl;
	calendarControl = document.getElementById("calendarDays");
	
	// deselect all other selected cells
	/*for (rowCount=0; rowCount<calendarControl.rows.length; rowCount++) {
		for (cellCount=0; cellCount<calendarControl.rows[rowCount].cells.length; cellCount++) {
			if (calendarControl.rows[rowCount].cells[cellCount].className == 'calDaySelected') {
				if (left(calendarControl.rows[rowCount].cells[cellCount].id, 4) == 'prev') {
					calendarControl.rows[rowCount].cells[cellCount].className = 'calOtherDay';
					} else {
					if (left(calendarControl.rows[rowCount].cells[cellCount].id, 4) == 'next') {
						calendarControl.rows[rowCount].cells[cellCount].className = 'calOtherDay';
						} else {
							if (calendarControl.rows[rowCount].cells[cellCount].getAttribute("hasEntry") == "1") {
							calendarControl.rows[rowCount].cells[cellCount].className = "calEntry";
							} else {
							calendarControl.rows[rowCount].cells[cellCount].className = 'calDay';
							}
						}
					}
				}
			}
		}*/
	
	// do whatever you want with this info, kiddo!
	document.getElementById('viewFrame').src = "diaryModule/dayView.aspx?year=" + yearId + "&month=" + monthId + "&day=" + dayId + "#" + hourId
	
	if (doHead == 1) {
		changeContentProxy('sourceFile=diaryModule/calPop.aspx|qs=type=head&month=' + monthId + '&year=' + yearId + '|targetItem=calTitleHolder');
		}
	
	changeContentProxy('sourceFile=diaryModule/calPop.aspx|qs=type=body&day=' + dayId + '&month=' + monthId + '&year=' + yearId + '|targetItem=calBodyHolder');

}

// ##############################################################
// HANDLE THE CLICK OF A WEEK ON THE CALENDAR - MODULE APPLICATION CODE
function weekClickMod(rowId, dayId, monthId, yearId, hourId) {
	
	var cellCount;
	var rowCount;
	var returnThing;
	var calendarControl;
	calendarControl = document.getElementById("calendarDays");
	
	// deselect all other cells
	/*for (rowCount=0; rowCount<calendarControl.rows.length; rowCount++) {
		for (cellCount=0; cellCount<calendarControl.rows[rowCount].cells.length; cellCount++) {
			if (calendarControl.rows[rowCount].cells[cellCount].className == 'calDaySelected') {
				if (left(calendarControl.rows[rowCount].cells[cellCount].id, 4) == 'prev') {
					calendarControl.rows[rowCount].cells[cellCount].className = 'calOtherDay';
					} else {
					if (left(calendarControl.rows[rowCount].cells[cellCount].id, 4) == 'next') {
						calendarControl.rows[rowCount].cells[cellCount].className = 'calOtherDay';
						} else {
						if (calendarControl.rows[rowCount].cells[cellCount].getAttribute("hasEntry") == "1") {
							calendarControl.rows[rowCount].cells[cellCount].className = "calEntry";
							} else {
							calendarControl.rows[rowCount].cells[cellCount].className = 'calDay';
							}
						}
					}
				}
			}
		}*/
	
	// select the whole row
	/*for (cellCount=0; cellCount<document.getElementById([rowId]).cells.length; cellCount++) {
		if (document.getElementById([rowId]).cells[cellCount].className != 'calWeekHeader') {
			document.getElementById([rowId]).cells[cellCount].className = 'calDaySelected';
			}
		}*/
	
	// do whatever you want with this info
	document.getElementById('viewFrame').src = "diaryModule/weekView.aspx?year=" + yearId + "&month=" + monthId + "&day=" + dayId + '#' + hourId

}


// ########################################
// HIGHLIGHT AN ENTRY
//
// cellId - Id of the cell to highlight
// action - 1 highlight is on OR <>1 highlight is off
function entryHighlight(cellId, action) {
    if (action == 1) {
        document.getElementById([cellId]).className = 'dayViewHourContentActiveHover';
        } else {
        document.getElementById([cellId]).className = 'dayViewHourContentActive';
        }

}

// ####################################################################################
// HIGHLIGHT AN ENTRY - yes another one! should have written it properly the first time....
//
// cellId - Id of the cell to highlight
// action - 1 highlight is on OR <>1 highlight is off
function weekEntryHighlight(cellId, action) {
    if (action == 1) {
        document.getElementById([cellId]).className = 'weekViewHeaderHover';
        } else {
        document.getElementById([cellId]).className = 'weekViewHeader';
        }

}


// ##################################
// FORMAT A CURRENCY VALUE FOR A PAGE
function formatCurrency(num) {
	var sign;
	var pence;
	
	num = num.toString().replace(/\$|\,/g,'');
	
	if(isNaN(num)) {
		num = "0";
		}
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	pence = num%100;
	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);
}


// ############################################################
// PASS THE NAME OF THE PERSON YOU ARE ACTING AS TO THE FOOTER
function footerIdentifier(actingAs) {

	try {
		document.getElementById("hid_identifier").value = actingAs;
		
		document.getElementById("footerRight").innerHTML = 'Currently acting as ' + actingAs + ' <a href="#" onclick="javascript:changeContentProxy(\'sourceFile=other/globalIdReset.aspx\|targetItem=footerRight\|loadMessage=reverting...\');footerIdentifier(\'yourself\');return false;"><img src="/resources/images/icons/revert.gif" /></a>';
		} catch(e) {
		
		}

	createCook('prvcaaro', actingAs, 1);

	}


// #############################################################
// CREATE COOKIES USING JS
function createCook(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

// #############################################################
// READ COOKIES USING JS
function readCook(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
	return null;
	}


// ############################################################
// PASS THE NAME OF THE PERSON YOU ARE ACTING AS TO THE FOOTER
function changeTipsContent(panelText) {

	document.getElementById('tipsPanel').innerHTML = panelText;

	}

// #########################
// DROP ALTERNATIVE SCRIPTS
var delayTimer;

function callMatchTimer(searchType, controlHolder, suggestionHolder, resultValueHolder, resultTextHolder, limitUser, e) {

	var doSearch;
	doSearch = 1;

	//alert(key + ' ' + e + ' ' + doSearch);
	
	// check for the enter fey
	if (e!=null) {
		var key = e.keyCode||e.which;
		} else {
		key = 0;
		}
	
	if (key == 13){
		try {
			window.event.keyCode = 0;
			doSearch = 0;
			}
		catch(broken) {
			e.stopPropagation();
			doSearch = 0;
			}
		
		alert('Hitting the \'enter\' key is invalid in this field.');
		
		}
	
	//alert(key + ' ' + e + ' ' + doSearch);	
	
	if (doSearch==1) {
		clearTimeout(delayTimer);

		delayTimer = setTimeout('getMatch(\'' + searchType + '\', \'' + controlHolder + '\', \'' + suggestionHolder + '\', \'' + resultValueHolder + '\', \'' + resultTextHolder+ '\', \'' + limitUser + '\')',1250);
		}
	

	}

function getMatch(searchType, controlHolder, suggestionHolder, resultValueHolder, resultTextHolder, limitUser) {

	var suggestions = document.getElementById(suggestionHolder);
	var selectHide = document.getElementById("suggestionHideSelect");
	
	var leftPos = findPosX(document.getElementById(controlHolder));
	var topPos = findPosY(document.getElementById(controlHolder));
	
	if (document.layers) {
		//Opera/Nutscrape V4
		suggestions.style.position = 'absolute';
		suggestions.style.display = 'inline';
		suggestions.style.left = parseFloat(leftPos+3) + 'px';
		suggestions.style.top = parseFloat(topPos+21) + 'px';
		selectHide.style.position = 'absolute';
		selectHide.style.display = 'inline';
		selectHide.style.left = parseFloat(leftPos+3) + 'px';
		selectHide.style.top = parseFloat(topPos+21) + 'px';
		} else if (document.all) {
		//IE4+
		suggestions.style.position = 'absolute';
		suggestions.style.display = 'inline';
		suggestions.style.left = parseFloat(leftPos+3) + 'px';
		suggestions.style.top = parseFloat(topPos+24) + 'px';
		selectHide.style.position = 'absolute';
		selectHide.style.display = 'inline';
		selectHide.style.left = parseFloat(leftPos+3) + 'px';
		selectHide.style.top = parseFloat(topPos+24) + 'px';
		} else if (document.getElementById) {
		//Mozilla
		suggestions.style.position = 'absolute';
		suggestions.style.display = 'inline';
		suggestions.style.left = parseFloat(leftPos+3) + 'px';
		suggestions.style.top = parseFloat(topPos+21) + 'px';
		selectHide.style.position = 'absolute';
		selectHide.style.display = 'inline';
		selectHide.style.left = parseFloat(leftPos+3) + 'px';
		selectHide.style.top = parseFloat(topPos+21) + 'px';
		}

	changeContentProxy('sourceFile=../other/suggestions.aspx|qs=searchString=' + escape(document.getElementById(resultTextHolder).value) + '&searchType=' + searchType + '&resultValueHolder=' + resultValueHolder + '&resultTextHolder=' + resultTextHolder + '&suggestionHolder=' + suggestionHolder + '&limitUser=' + limitUser + '|targetItem=' + suggestionHolder);

	}

function findPosX(obj) {
	var curleft = 0;
	if(obj.offsetParent)
	while(1) {
	curleft += obj.offsetLeft;
	if(!obj.offsetParent)
		break;
	obj = obj.offsetParent;
	}
	else if(obj.x)
		curleft += obj.x;
	return curleft;
	}

function findPosY(obj) {
	var curtop = 0;
	if(obj.offsetParent)
	while(1)
	{
	curtop += obj.offsetTop;
	if(!obj.offsetParent)
		break;
	obj = obj.offsetParent;
	}
	else if(obj.y)
		curtop += obj.y;
	return curtop;
	}

function selectMatch(matchId, matchName, resultValueHolder, resultTextHolder, suggestionHolder) {
	
	document.getElementById(resultTextHolder).value = matchName;
	document.getElementById(resultValueHolder).value = matchId;
	document.getElementById(suggestionHolder).style.display = "none";
	document.getElementById("suggestionHideSelect").style.display = "none";

	}


// CHECK VALUE PASSED IS NUMERIC
function isNumeric(inputText) {
	var validChars = "0123456789.";
	var isNumber=true;
	var char;

	for (i = 0; i < inputText.length && isNumber == true; i++) 
	  { 
	  char = inputText.charAt(i); 
	  if (validChars.indexOf(char) == -1) 
		 {
		 isNumber = false;
		 }
	  }
	return isNumber;
	}


// DISABLE SECONDARY BUTTON CLICK
function disableButton(buttonId) {

	document.getElementById(buttonId).onclick = function() {return false;};
	document.getElementById(buttonId).value = 'please wait...';
	document.getElementById(buttonId).className = 'standardButtonDisabled';

	}


// TRIGGER KEEP ALIVE
function keepAliveTrigger(triggerAction) {

		var ranNumber = Math.floor(Math.random() * 100000+1);

	if (triggerAction == 'yes') {
		// turn on keep alive
		
		document.getElementById('aliveTrigger').innerHTML = '<a href=\"#\" onclick=\"javascript:keepAliveTrigger(\'no\');\">keep alive on!<\/a>\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;';
		document.getElementById('aliveTrigger').style.color = '#00ff00';
		document.getElementById('aliveTrigger').style.fontWeight = 'bold';
		document.getElementById('footerRightKeepAlive').style.backgroundImage = "url(resources/images/grey/keepAliveOn.jpg)";
		
		document.getElementById('keepAliveFrame').src = 'other/keepAlive.aspx?keepAlive=alive&ran=' + ranNumber;
		
		} else {
		// turn off keep alive
		
		document.getElementById('aliveTrigger').innerHTML = '<a href=\"#\" onclick=\"javascript:keepAliveTrigger(\'yes\');\">keep alive off<\/a>\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;\&nbsp\;';
		document.getElementById('aliveTrigger').style.color = '#666666';
		document.getElementById('aliveTrigger').style.fontWeight = 'normal';
		document.getElementById('footerRightKeepAlive').style.backgroundImage = "url(resources/images/grey/keepAliveOff.jpg)";
		document.getElementById('keepAliveFrame').src = 'other/keepAlive.aspx?keepAlive=no&ran=' + ranNumber;
		
		}

	}


// SECTION EXPAND
function secExpand(divId) {
	
	if (document.getElementById(divId).style.display == "block") {
		document.getElementById(divId).style.display = "none";
		document.getElementById('img_' + divId).src = "/resources/images/icons/plus.gif";
		} else {
		document.getElementById(divId).style.display = "block";
		document.getElementById('img_' + divId).src = "/resources/images/icons/minus.gif";
		}

	}


// GENERIC STYLE SWITCH
function genericStyleSwitch(targetItem, targetClass) {

	document.getElementById(targetItem).className = targetClass;

	}


//-->
