/*   
 *    X-Web 2002
 *    CRef = Y002-C002-S002-V100 
 *    DDate = 31 Oct 2002
 */

/* 
 * Many pages use pop-up menus.
 * This set of functions provides management for the pop-up menu features 
 * and supports other uses for the event-driven showing or hiding of a 
 * DHTML 'floating' panel. 
 */

var disableShowAllOption = false;
var disableHideAllOption = false;
var	floaterValue = '';
var	floatAction = 'alert';

var DEBUGGING = false; 

function expandAll()
{
	var aTR = document.getElementsByTagName('TR'); // gets an array of all TR elements
	for (var i=0; i<aTR.length; i++)
		forceClass(aTR[i], 'hidden', 'showing');
	disableShowAllOption = true;
	disableHideAllOption = false;
}

function collapseAll()
{
	var aTR = document.getElementsByTagName('TR'); // gets an array of all TR elements
	for (var i=0; i<aTR.length; i++)
		forceClass(aTR[i], 'showing', 'hidden');
	disableHideAllOption = true;
	disableShowAllOption = false;
}

function jumpTo(url)
{
	document.location = url;
	return true;
}

function doFloatOption(v)
{
	alert('doing float option:' + v);
	hideFloater();
	return true;
}

function floatInner(iIcon, sCaption, aOption)
{	
var str = '';
	str += '\n<table cellpadding="0" cellspacing="0" id="floatinner">';
	str += '\n<tr><th colspan="2" onMouseDown="setDragging(true);" ';
	str += '\n onMouseOut="setDragging(false);" ';
	str += '\n onMouseUp="setDragging(false);" ';
	str += '\n onMouseMove="moveFloater(event);"> ' + sCaption + '</th>';
	str += '<th class="exit" onClick="hideFloater();">';
	str += '<img src="/common/images/CAL020n2.gif" ';
	str += 'onMouseOver="this.src=\'/common/images/CAL020m2.gif\'" ';
	str += 'onMouseOut="this.src=\'/common/images/CAL020n2.gif\'" ';
	str += 'width="10" height="10" alt="Close" border="0"></th></tr>';
	for (var i=0; i<aOption.length; i++) 
	{
		if (aOption[i][2] == 'separator')
		{
			str += '\n<tr><td colspan="3" ';
			str += 'style="border-bottom:1px solid blue;';
			str += 'background-color:#3399ff;">';
			str += '<img src="/common/images/shim.gif" ';
			str += 'alt="" border="0" width="1" height="1" />';
			str += '</td></tr>';
		}
		else if (aOption[i][2] == 'currency')
		{
			str += '\n<tr><td colspan="3" ';
			str += 'style="border-bottom:1px solid blue;background-color:#3399ff;">';
			str += '<img src="/common/images/shim.gif" ';
			str += 'alt="" border="0" width="1" height="1" />';
			str += '</td></tr>';
		}
		else
		{
			str += '\n<tr><td class="floatOption" colspan="3" onMouseOver="this.style.backgroundColor=\'#DEDEFF\'" ';
			str += 'onMouseOut="this.style.backgroundColor=\'#FFFFFF\'" onClick="' + aOption[i][1] + '">';
			str += aOption[i][2] + '</td></tr>';
		}
	}
	str += '\n</table>';
	return str;
}


function hideFloater()
{
	if (floatAction == 'alert')
	{
		if (floaterValue != '') 
		{
			alert('floaterValue=' + floaterValue);
		}
	}
	else if (floatAction == 'newportfolio')
	{
		if (floaterValue != '') 
		{
			jumpTo('PortfolioEdit.Asp?pfName=' + floaterValue);
		};
		floatAction = 'alert';
	};
	floatouterShadow.style.display = 'none';
	floatouter.style.display = 'none';
	floatUnderLay.style.display = 'none';
	
	// Any SELECT elements were hidden by setting their display property to 'none'
	// Reshow them before finishing...
//	var aSelects = document.getElementsByTagName('SELECT');
//	for (var n=0 ; n<aSelects.length ; n++)
//		aSelects[n].style.display = 'block';
	
	return true;

}

// Global holds reference to selected element
var bDragging;
// Globals hold location of click relative to element
var offsetX, offsetY;

function setDragging(v)
{
// Dragging option removed as it's too slow and demands dexterity form the user
//	if (v)
//	{
//		offsetX = window.event.offsetX;
//		offsetY = window.event.offsetY
//	}
//	bDragging = v;
}

function moveFloater()
{
// Dragging option removed as it's too slow and demands dexterity form the user
//	if (bDragging)
//	{
//		floatouter.style.pixelTop = window.event.y - offsetY + document.body.scrollTop;
//		floatouter.style.pixelLeft = window.event.x - offsetX + document.body.scrollLeft;
//		floatouterShadow.style.pixelTop = floatouter.style.pixelTop + 5;
//		floatouterShadow.style.pixelLeft = floatouter.style.pixelLeft + 5;
//	}
}

function setCurrency(s)
{
	hideFloater();
	jumpTo('?sessionCurrency=' + s);
	return true
}

function getFloaterCurrency(sPrompt,sDefault,e)
{
var str = '';
	str += '\n<table cellpadding="0" cellspacing="0" id="floatinner">';
	str += '\n<tr><th colspan="2" onMouseDown="setDragging(true);"';
	str += '\n onMouseMove="moveFloater();"';
	str += '\n onMouseUp="setDragging(false);">Select currency...</th>';
	str += '<th class="exit" onClick="setCurrency(\'' + sDefault + '\');">';
	str += '<img src="/common/images/CAL020n2.gif" ';
	str += 'onMouseOver="this.src=\'/common/images/CAL020m2.gif\'" ';
	str += 'onMouseOut="this.src=\'/common/images/CAL020n2.gif\'" ';
	str += 'width="10" height="10" alt="Close" border="0"></th></tr>';
	str += '<tr><td colspan="3" style="padding:3px;" id="telltale">' + sPrompt + '</td></tr>';
	str += '<tr><td class="alist" colspan="3" onMouseOver="this.style.backgroundColor=\'#DEDEFF\'" ';
			str += 'onMouseOut="this.style.backgroundColor=\'#FFFFFF\'"><a onClick="setCurrency(\'AUD\');">AUD - Australian Dollars</a></td></tr>';
	str += '<tr><td class="alist" colspan="3" onMouseOver="this.style.backgroundColor=\'#DEDEFF\'" ';
			str += 'onMouseOut="this.style.backgroundColor=\'#FFFFFF\'"><a onClick="setCurrency(\'CAD\');">CAD - Canadian Dollars</a></td></tr>';
	str += '<tr><td class="alist" colspan="3" onMouseOver="this.style.backgroundColor=\'#DEDEFF\'" ';
			str += 'onMouseOut="this.style.backgroundColor=\'#FFFFFF\'"><a onClick="setCurrency(\'CHF\');">CHF - Swiss Francs</a></td></tr>';
	str += '<tr><td class="alist" colspan="3" onMouseOver="this.style.backgroundColor=\'#DEDEFF\'" ';
			str += 'onMouseOut="this.style.backgroundColor=\'#FFFFFF\'"><a onClick="setCurrency(\'DKK\');">DKK - Danish Kroner</a></td></tr>';
	str += '<tr><td class="alist" colspan="3" onMouseOver="this.style.backgroundColor=\'#DEDEFF\'" ';
			str += 'onMouseOut="this.style.backgroundColor=\'#FFFFFF\'"><a onClick="setCurrency(\'EUR\');">EUR - Euro</a></td></tr>';
	str += '<tr><td class="alist" colspan="3" onMouseOver="this.style.backgroundColor=\'#DEDEFF\'" ';
			str += 'onMouseOut="this.style.backgroundColor=\'#FFFFFF\'"><a onClick="setCurrency(\'GBP\');">GBP - Sterling (G.B. Pounds)</a></td></tr>';
	str += '<tr><td class="alist" colspan="3" onMouseOver="this.style.backgroundColor=\'#DEDEFF\'" ';
			str += 'onMouseOut="this.style.backgroundColor=\'#FFFFFF\'"><a onClick="setCurrency(\'HKD\');">HKD - Hong Kong Dollars</a></td></tr>';
	str += '<tr><td class="alist" colspan="3" onMouseOver="this.style.backgroundColor=\'#DEDEFF\'" ';
			str += 'onMouseOut="this.style.backgroundColor=\'#FFFFFF\'"><a onClick="setCurrency(\'ISK\');">ISK - Icelandic Krona</a></td></tr>';
	str += '<tr><td class="alist" colspan="3" onMouseOver="this.style.backgroundColor=\'#DEDEFF\'" ';
			str += 'onMouseOut="this.style.backgroundColor=\'#FFFFFF\'"><a onClick="setCurrency(\'JPY\');">JPY - Japanese Yen</a></td></tr>';
	str += '<tr><td class="alist" colspan="3" onMouseOver="this.style.backgroundColor=\'#DEDEFF\'" ';
			str += 'onMouseOut="this.style.backgroundColor=\'#FFFFFF\'"><a onClick="setCurrency(\'MYR\');">MYR - Malaysian Ringgits</a></td></tr>';
	str += '<tr><td class="alist" colspan="3" onMouseOver="this.style.backgroundColor=\'#DEDEFF\'" ';
			str += 'onMouseOut="this.style.backgroundColor=\'#FFFFFF\'"><a onClick="setCurrency(\'NOK\');">NOK - Norwegian Kroner</a></td></tr>';
	str += '<tr><td class="alist" colspan="3" onMouseOver="this.style.backgroundColor=\'#DEDEFF\'" ';
			str += 'onMouseOut="this.style.backgroundColor=\'#FFFFFF\'"><a onClick="setCurrency(\'NZD\');">NZD - New Zealand Dollars</a></td></tr>';
	str += '<tr><td class="alist" colspan="3" onMouseOver="this.style.backgroundColor=\'#DEDEFF\'" ';
			str += 'onMouseOut="this.style.backgroundColor=\'#FFFFFF\'"><a onClick="setCurrency(\'SAR\');">SAR - Saudi Arabian Riyals</a></td></tr>';
	str += '<tr><td class="alist" colspan="3" onMouseOver="this.style.backgroundColor=\'#DEDEFF\'" ';
			str += 'onMouseOut="this.style.backgroundColor=\'#FFFFFF\'"><a onClick="setCurrency(\'SEK\');">SEK - Swedish Kroner</a></td></tr>';
	str += '<tr><td class="alist" colspan="3" onMouseOver="this.style.backgroundColor=\'#DEDEFF\'" ';
			str += 'onMouseOut="this.style.backgroundColor=\'#FFFFFF\'"><a onClick="setCurrency(\'SGD\');">SGD - Singapore Dollars</a></td></tr>';
	str += '<tr><td class="alist" colspan="3" onMouseOver="this.style.backgroundColor=\'#DEDEFF\'" ';
			str += 'onMouseOut="this.style.backgroundColor=\'#FFFFFF\'"><a onClick="setCurrency(\'THB\');">THB - Thailand Bhat</a></td></tr>';
	str += '<tr><td class="alist" colspan="3" onMouseOver="this.style.backgroundColor=\'#DEDEFF\'" ';
			str += 'onMouseOut="this.style.backgroundColor=\'#FFFFFF\'"><a onClick="setCurrency(\'TWD\');">TWD - New Taiwan Dollars</a></td></tr>';
	str += '<tr><td class="alist" colspan="3" onMouseOver="this.style.backgroundColor=\'#DEDEFF\'" ';
			str += 'onMouseOut="this.style.backgroundColor=\'#FFFFFF\'"><a onClick="setCurrency(\'USD\');">USD - United States Dollars</a></td></tr>';
	str += '\n</table>';

	floatdiv.innerHTML = str;
	
	floatouter.style.pixelTop = e.clientY + document.body.scrollTop + 2; 
	if (floatouter.style.pixelTop < 260) floatouter.style.pixelTop = 260; 
	// inserts vertical space to ensure that the top of the currency selector DHTML 
	// doesn't fall in the same space as any drop-down controls that it can't float over.
	
	floatouter.style.pixelLeft = e.clientX + document.body.scrollLeft + 2;

	floatouter.style.display = 'block';
	floatouterShadow.style.display = 'none';

	return true;
}
	
function getFloaterValue(sPrompt,sDefault,e)
{
if (DEBUGGING) alert('getFloaterValue(' + sPrompt +', ' + sDefault +', X=' + e.clientX + ',Y=' + e.clientY);
var str = '';
	str += '\n<table cellpadding="0" cellspacing="0" id="floatinner">';
	str += '\n<tr><th colspan="2" onMouseDown="setDragging(true);"';
	str += '\n onMouseMove="moveFloater();"';
	str += '\n onMouseUp="setDragging(false);">User input value...</th>';
	str += '<th class="exit" onClick="floaterValue = \'' + sDefault + '\';hideFloater();">';
	str += '<img src="/common/images/CAL020n2.gif" ';
	str += 'onMouseOver="this.src=\'/common/images/CAL020m2.gif\'" ';
	str += 'onMouseOut="this.src=\'/common/images/CAL020n2.gif\'" ';
	str += 'width="10" height="10" alt="Close" border="0"></th></tr>';
	str += '<tr><td colspan="3" style="padding:3px;" id="telltale">' + sPrompt + '</td></tr>';
	str += '<tr><td colspan="3" style="padding:3px;">';
	str += '<input type="text" name="txtFloatValue" value="' + sDefault + '" style="width:100%;border:1px solid #003399;" />';
	str += '</td></tr>';
	str += '<tr><td colspan="3" style="padding:3px;text-align:center;">';
	str += '<input type="button" value="OK"  onClick="floaterValue = txtFloatValue.value;hideFloater();" style="width:45%;" />&nbsp;';
	str += '<input type="button" value="Cancel" onClick="floaterValue = \'' + sDefault + '\';hideFloater();" style="width:45%;" />';
	str += '</td></tr>';
	str += '\n</table>';

	floaterValue='';
	floatdiv.innerHTML = str;
	
	floatouter.style.pixelTop = e.clientY + document.body.scrollTop + 2;
	floatouter.style.pixelLeft = e.clientX + document.body.scrollLeft + 2;
	
	if (floatouter.style.pixelLeft > 540) floatouter.style.pixelLeft = 540; 
	// makes sure the dialog doesn't fall too far to the right of the screen.
		
	floatouter.style.display = 'block';
	floatouterShadow.style.display = 'none';

	return true;
}
	
function getFloaterCalc(e)
{
// function not used
return;
var str = '';
	str += '\n<table cellpadding="0" cellspacing="0" id="floatinner" style="width:233px;">';
	str += '\n<tr><th colspan="2" onMouseDown="setDragging(true);"';
	str += '\n onMouseMove="moveFloater();"';
	str += '\n onMouseUp="setDragging(false);">Calculate value...</th>';
	str += '<th class="exit" onClick="floaterValue = \'\';hideFloater();">';
	str += '<img src="/common/images/CAL020n2.gif" ';
	str += 'onMouseOver="this.src=\'/common/images/CAL020m2.gif\'" ';
	str += 'onMouseOut="this.src=\'/common/images/CAL020n2.gif\'" ';
	str += 'width="10" height="10" alt="Close" border="0"></th></tr>';
	str += '\n<tr><td colspan="3" style="padding:3px;text-align:center;">';
	str += 'Fill in any three values and the fourth will be calculated for you...</td></tr>';
	str += '\n<tr><td colspan="3" style="padding:3px;">';
	str += '<table style="width:100%;border:0px;" cellpadding="0" cellspacing="0">';
    str += '\n<tr><td style="text-align:right;">Present value:</td>';
    str += '<td><input type="text" style="text-align:right;" id="NPV" /></td></tr>';
    str += '\n<tr><td style="text-align:right;">Period (months):</td>';
    str += '<td><input type="text" style="text-align:right;" id="Months" /></td></tr>';
    str += '\n<tr><td style="text-align:right;">Rate:</td>';
    str += '<td><input type="text" style="text-align:right;" id="Rate" /></td></tr>';
    str += '\n<tr><td style="text-align:right;">Future value:</td>';
    str += '<td><input type="text" style="text-align:right;" id="FV" /></td></tr>';
    str += '\n<tr><td style="text-align:right;">';
    str += '<input type="button" value="Calculate" ';
    str += 'onClick="alert(\'calculating...\');" style="width:45%;" /></td>';
    str += '<td style="text-align:right;"><input type="button" value="Close" ';
    str += 'onClick="hideFloater();" style="width:45%;" /></td></tr>';
	str += '</table>';
	str += '</td></tr>';
	str += '\n</table>';

	floatdiv.innerHTML = str;
	
	floatouter.style.pixelTop = e.clientY + document.body.scrollTop + 2;
	floatouter.style.pixelLeft = e.clientX + document.body.scrollLeft + 2;
	floatouter.style.display = 'block';
	floatouterShadow.style.display = 'none';

	return true;
}	

function toggleRows(myRow)
{
/*
 * for each TR matching identifier
 *   if actionSetting is unknown then 
 *     set actionSetting to the opposite of the TR present setting
 *   end if
 *   set presentSetting to actionSetting
 * end for
 * if actionsetting is 'hide'
 *   for each TR matching parentidentifer
 *     set presentsetting to actionsetting
 *   end for
 * end if
 *
 * loop though all TRs and find those with toggleID set to identifier
 * set all to the opposite of the setting found for the first one in the set
 * if action was hide then loop though again and find those with parentID set to parent_identifier
 * set all to 'hidden'
 *
 */
if (DEBUGGING) alert('getting an array of TR elements');
	var aTR = document.getElementsByTagName('TR');
	var classToSet = 'unknown';
	var rowCount = 0;
	var childCount = 0;
	
if (DEBUGGING) alert('looping through ' + aTR.length + ' TR elements');
	for (var i = 0; i<aTR.length ;i++)
	{
		if ((aTR[i].toggleID) && (aTR[i].toggleID == myRow))
		{
			if (classToSet == 'unknown')
			{
if (DEBUGGING) alert('found one with toggleID = \'' + myRow + '\'');
				if (aTR[i].className.indexOf('hidden') != -1)
					classToSet = 'showing'
				else
					classToSet = 'hidden';
if (DEBUGGING) alert('classToSet was \'unknown\' but changed to \'' + classToSet + '\'');
			}
			if (classToSet == 'hidden')
			{
if (DEBUGGING) alert('forcing class to \'hidden\' for TR #' + i);	
				forceClass(aTR[i], 'showing','hidden');
			}
			else
			{
if (DEBUGGING) alert('forcing class to \'showing\' for TR #' + i);	
				forceClass(aTR[i], 'hidden','showing');
			}
			rowCount += 1;
		}
	};
	if (classToSet == 'hidden')
	{
if (DEBUGGING) alert('looping through again looking for parentID=\'' + myRow + '\'');	
		for (var i = 0; i<aTR.length ;i++)
		{
			if ((aTR[i].parentID) && (aTR[i].parentID == myRow))
			{
if (DEBUGGING) alert('TR #' + i + ' has parentID set to ' + myRow + '\nForcing class to \'hidden\' for child TR #' + i);	
				forceClass(aTR[i],'showing', 'hidden');
				childCount += 1;
			}
		}
	};
if (DEBUGGING) alert('classToSet=' + classToSet + '\nrows=' + rowCount + '\nchildren=' + childCount);
	if (classToSet == 'hidden')
	{
		disableShowAllOption = false; // enable 'Show all' on page menu
	}
	else if (classToSet == 'showing')
	{
		disableHideAllOption = false; // enable 'Hide all' on page menu
	}	
	
}

function swapClass(obj, s1, s2)
{
var aClasses = obj.className.split(' ');
	for (var i = 0; i<aClasses.length; i++)
	{
		if (aClasses[i] == s1)
		{
			aClasses[i] = s2
		}
		else
		{
			if (aClasses[i] == s2)
				aClasses[i] = s1
		}
	};
	obj.className = aClasses.join(' ');
	return true;
}

function forceClass(obj, s1, s2)
{
var aClasses = obj.className.split(' ');
var msg = obj.className;

//alert('number of classes = ' + aClasses.length);
	for (var i = 0; i<aClasses.length; i++)
	{
		if (aClasses[i] == s1)
			aClasses[i] = s2;
	}
	obj.className = aClasses.join(' ');
//alert(msg + '\nbecomes\n' + obj.className);
	return true;
}



// A bunch of functions handling tri-state logic within tables
// A set of constants for readability NB: Actual values are arbitrary
var TRI_FALSE = 0;
var TRI_MIXED = 7;
var TRI_TRUE = -1

function cascade(td, v, noUpCheck)
{
// takes an object - td - a TD element that has attributes 'triState', 'mID' and 'pID'
// and an optional value v one of TRI_TRUE, 'TRI_MIXED, TRI_FALSE
// and an optional boolean denoting whether to disable the check upwards


// set a local variable to either the passed state or the _new_ state of the element
	
	var newState, oInput;
	
	if ((td.triState == TRI_FALSE) || (td.triState == TRI_MIXED)) 
		newState = TRI_TRUE
	else
		newState = TRI_FALSE;

	if ((v == TRI_TRUE) || (v == TRI_FALSE) || (v == TRI_MIXED)) newState = v;
	
	td.triState = newState;
	td.innerHTML = showFor(newState);
// look for an associated (hidden) INPUT element			
	oInput = document.getElementById(td.mID);
// if there is one, set it to newState
	if ((oInput) && (oInput.value != newState)) 
	{
		oInput.value = newState;
	}

// get the collection of all TD elements
	var oChk = document.getElementsByTagName('TD');
	
// loop through looking for any with me declared as its parent
	for (var i = 0; i<oChk.length ; i++)
	{
		if (oChk[i].pID == td.mID)
		{
// set its state to match mine
			oChk[i].triState = newState;
			oChk[i].innerHTML = showFor(newState);
// look for an associated (hidden) INPUT element			
			oInput = document.getElementById(oChk[i].mID);
// if there is one, set it to newState
			if ((oInput) && (oInput.value != newState)) oInput.value = newState;
			
// cascade this down all its children too
			cascade(oChk[i], newState, true);
		}
	}

	if (noUpCheck != true)
	{
	// now look for my parent to see if it needs to be fuzzy
	// first see if I have a parent
		if ((td.pID) && (td.pID != ""))
		{
	// now check its ancestors to see if they're all true or all false
			for (var i = 0; i<oChk.length ; i++)
			{
				if (oChk[i].mID == td.pID)
				{
					oChk[i].triState = checkState(oChk[i]);
					oChk[i].innerHTML = showFor(oChk[i].triState)
					if ((oChk[i].pID) && (oChk[i].pID != ""))
					{
						for (var j = 0; j<oChk.length ; j++)
						{
							if (oChk[j].mID == oChk[i].pID)
							{
								oChk[j].triState = checkState(oChk[j]);
								oChk[j].innerHTML = showFor(oChk[j].triState)
							}
						}
					};
					break
				}
			}
		}
	}
}

function checkState(td)
{
var countTrue = 0;
var countFalse = 0;
var countMixed = 0;

if (DEBUGGING) alert('checking ' + td.mID);
	var oChk = document.getElementsByTagName('TD');
	
	for (var i = 0; i<oChk.length ; i++)
	{
		if (oChk[i].pID == td.mID)
		{
if (DEBUGGING) alert('found a child of ' + td.mID + ' as ' + oChk[i].mID + ' showing ' + oChk[i].innerHTML);
			if (oChk[i].triState == TRI_TRUE) 
			{
				countTrue++ ;
if (DEBUGGING) alert('countTrue = ' + countTrue )
			}
			else if (oChk[i].triState == TRI_FALSE) 
			{
				countFalse++  ;
if (DEBUGGING) alert('countFalse = ' + countFalse )

			}
			else if (oChk[i].triState == TRI_MIXED)
			{
				countMixed++ ;
if (DEBUGGING) alert('countMixed = ' + countMixed )

			}
		};
		if (countMixed>0) break
	};
	if ((countMixed>0) || ((countFalse!=0) && (countTrue!=0))) return TRI_MIXED
	else if (countFalse==0) return TRI_TRUE
	else if (countTrue==0) return TRI_FALSE
}

function showFor(x)
{
	var sImg;
	switch (x) {
		case TRI_FALSE :
			sImg =  '<img src="/common/images/CKS005nT.gif" ';
			sImg += 'onMouseOver="this.src=\'/common/images/CKS005mT.gif\'" ';
			sImg += 'onMouseOut="this.src=\'/common/images/CKS005nT.gif\'" ';
			sImg += 'width="20" height="20" alt="None selected; Select all including any subordinate rows" border="0">';
			return sImg;
			break;
		case TRI_MIXED :
			sImg =  '<img src="/common/images/MXD007nT.gif" ';
			sImg += 'onMouseOver="this.src=\'/common/images/MXD007mT.gif\'" ';
			sImg += 'onMouseOut="this.src=\'/common/images/MXD007nT.gif\'" ';
			sImg += 'width="20" height="20" alt="Some selected; Select all including any subordinate rows" border="0">';
			return sImg;
			break;
		case TRI_TRUE :
			sImg =  '<img src="/common/images/UCK006nT.gif" ';
			sImg += 'onMouseOver="this.src=\'/common/images/UCK006mT.gif\'" ';
			sImg += 'onMouseOut="this.src=\'/common/images/UCK006nT.gif\'" ';
			sImg += 'width="20" height="20" alt="All selected; Unselect all including any subordinate rows" border="0">';
			return sImg;
			break;
		default : return 'x';
	}
}

function showResults()
{
// this is a dummy function for checking the operation of the tristate 
// functions and HTML content during testing and development.
	var s = 'Results to send:';
	var aInputs = document.getElementsByTagName('INPUT');
	for (var i=0; i<aInputs.length ; i++)
	{
		s += '\n' + aInputs[i].name + ':' + aInputs[i].value;
	};
	alert(s);
	return true;
}


	
	
	

function showFloater(PageType, Position, ItemType, key, e, childData, childText)
// PageType is one of 'a0', 'a1', 'a2', 'f0', 'f1', 'f2', 'p0', 'p1', 'p2', 'p3', 'p4', 't0', 't1', 't2' 
//   (Accounts, Funds, Portfolios, Transactions)
//   (main, enquirer, not linked, under-edit, summary
// Position is one of 'pg', 't0', 't1', 'gp', 'r0', 'r1' 
//   (Page, Table, Group, Row)
//   (logged user, linked)
// ItemType is one of 'pg', 'a0a..f', 'a1a..f', 'f0', 'f1', 'p0', 'p1', 's0', 's1', 't0', 't1'
//    (Page, Account, Fund, Portfolio, Share, Transaction
//    (logged user, linked)
//    (current ISA, closed ISA, non-cash fund, cash fund, share, user designated)
//'a0 a1 f0 f1'.indexOf('a0') returns 0
//'a0 a1 f0 f1'.indexOf('f0') returns 6
//'a0 a1 f0 f1'.indexOf('pg') returns -1
// so we can check for the existence of the given argument in our 'accepted' list
// NB: Many cases are checked repeatedly. This is to make the logic easier to follow.
//     Bear in mind the need to make sure all tests are mutually exclusive, 
//     otherwise the same option may be repeated on one menu.
{
var ary = [];

// debug output
// ary[ary.length] = ['','',PageType + ', ' + Position + ', ' + ItemType + ', ' + key];
// ary[ary.length] = ['','','separator']; // separator only

// The following options appear on all page level menus...	
	// page level only - go to set user preferences 
	if ('a0 a1 a2 f0 f1 f2 p0 p1 p2 p4 t0 t1 t2'.indexOf(PageType) != -1) // NB Everything except p3 (portfolio under edit)
		if ('pg'.indexOf(Position) != -1)
			ary[ary.length] = ['','jumpTo(\'/WORKAREA/direct/AccountManagement/OptsPersonal.asp\')','Display preferences' ];

	// page level only - sets currency for the current session only
	if ('a0 a1 a2 f0 f1 f2 p0 p1 p2 p4 t0 t1 t2'.indexOf(PageType) != -1) // NB Everything except p3 (portfolio under edit)
		if ('pg'.indexOf(Position) != -1)
			ary[ary.length] = ['','getFloaterCurrency(\'Click on any currency to set the display currency for this session only.\',\'GBP\',event)','Display currency' ];

	// Show all
	if (('pg'.indexOf(Position) != -1) && (disableShowAllOption != true))
		ary[ary.length] = ['','expandAll();hideFloater()','Show all hidden data' ];

	// Hide all
	if (('pg'.indexOf(Position) != -1) && (disableHideAllOption != true))
		ary[ary.length] = ['','collapseAll();hideFloater()','Hide all optional data' ];

	// Show/Hide child data
	if (('t0 t1 gp r0 r1'.indexOf(Position) != -1) && (childData) && (childData != ''))
	{
		var aTR = document.getElementsByTagName('TR'); // gets an array of all TR elements
		var showHide;
		for (var i=0; i<aTR.length; i++)
		{
			if (aTR[i].toggleID == childData)
			{
				if (aTR[i].className.indexOf('showing') != -1)
					showHide = 'Hide ' + childText // showing is one of the class names applied to the found TR so we need to offer to hide the rows...
				else
					showHide = 'Show ' + childText // showing is not one of the class names applied to the found TR so we need to offer to show the rows...
			}
		}
		ary[ary.length] = ['','toggleRows(\'' + childData +'\');hideFloater()', showHide ]
	}
			
	if (ary.length != 0) 
		ary[ary.length] = ['','','separator']; // separator only

	
	// Account holder's details
	if ('p0'.indexOf(PageType) != -1)
		if ('pg r0 r1'.indexOf(Position) != -1)
			if ('pg f0, f1, s0, s1'.indexOf(ItemType) != -1)
				ary[ary.length] = ['','doFloatOption(\'Account holders details: ' + key + '\')','Account holders details' ];

	if ('f0'.indexOf(PageType) != -1)
		if ('pg'.indexOf(Position) != -1)
			if ('pg'.indexOf(ItemType) != -1)
				ary[ary.length] = ['','doFloatOption(\'Account holders details: ' + key + '\')','Account holders details' ];

	// Analysis
	if ('a0 p0 p3 f0'.indexOf(PageType) != -1)
		if ('pg'.indexOf(Position) != -1)
			ary[ary.length] = ['','jumpTo(\'overview.asp\')','Analysis' ];

	// Market news
	if ('p0 p1 p2 p4'.indexOf(PageType) != -1)
		if ('pg t0 t1'.indexOf(Position) != -1)
			ary[ary.length] = ['','doFloatOption(\'Market news: ' + key + '\')','Market news' ];

	if ('a0 a1 a2 f0 f1 f2'.indexOf(PageType) != -1)
		if ('pg'.indexOf(Position) != -1)
			ary[ary.length] = ['','doFloatOption(\'Market news: ' + key + '\')','Market news' ];

	if ('a0 a1 a2'.indexOf(PageType) != -1)
		if ('t0 t1'.indexOf(Position) != -1)
			ary[ary.length] = ['','doFloatOption(\'Market news: ' + key + '\')','Market news' ];

	// Funds news
	if ('a0'.indexOf(PageType) != -1)
		if ('gp r0 r1'.indexOf(Position) != -1)
			if ('a0a a0b a0c a0d a0f a1a a1b a1c a1d a1f'.indexOf(ItemType) != -1)
				ary[ary.length] = ['','doFloatOption(\'Funds news: ' + key + '\')','Funds news' ];
	
	if ('a1'.indexOf(PageType) != -1)
		if ('r0'.indexOf(Position) != -1)
			ary[ary.length] = ['','doFloatOption(\'Funds news: ' + key + '\')','Funds news' ];

	if ('p0'.indexOf(PageType) != -1)
		if ('r0 r1'.indexOf(Position) != -1)
			if ('f0 f1 s0 s1'.indexOf(ItemType) != -1)
				ary[ary.length] = ['','doFloatOption(\'Funds news: ' + key + '\')','Funds news' ];

	if ('f0 f1'.indexOf(PageType) != -1)
		if ('t0 t1'.indexOf(Position) != -1)
			if ('f0 f1'.indexOf(ItemType) != -1)
				ary[ary.length] = ['','doFloatOption(\'Funds news: ' + key + '\')','Funds news' ];
	
	// Transactions on funds
	if ('a0'.indexOf(PageType) != -1)
		if ('r0 r1'.indexOf(Position) != -1)
			if ('a0a a0b a0c a0d a0e a0f a1a a1b a1c a1d a1e a1f f0 f1'.indexOf(ItemType) != -1)
				ary[ary.length] = ['','jumpTo(\'Transactions.asp\')','Transactions' ];

	if ('f0'.indexOf(PageType) != -1)
		if ('r0'.indexOf(Position) != -1)
			if ('f0'.indexOf(ItemType) != -1)
				ary[ary.length] = ['','jumpTo(\'Transactions.asp\')','Transactions' ];

	// Transactions on funds or accounts
	if ('a0'.indexOf(PageType) != -1)
		if ('t0 t1 gp'.indexOf(Position) != -1)
			if ('a0a a0b a0c a0d a0e a0f a1a a1b a1c a1d a1e a1f f0 f1'.indexOf(ItemType) != -1)
				ary[ary.length] = ['','jumpTo(\'Transactions.asp\')','Transactions' ];

	// Transactions on portfolio account funds
	if ('p0'.indexOf(PageType) != -1)
		if ('r0 r1'.indexOf(Position) != -1)
			if ('f0 f1'.indexOf(ItemType) != -1)
				ary[ary.length] = ['','jumpTo(\'Transactions.asp\')','Transactions' ];

	// Transactions on shares
	if ('a0'.indexOf(PageType) != -1)
		if ('t0 t1 gp r0 r1'.indexOf(Position) != -1)
			if ('s0 s1'.indexOf(ItemType) != -1)
				ary[ary.length] = ['','doFloatOption(\'Transactions (ShareNetwork): ' + key + '\')','Transactions' ];
	
	// Factsheet
	if ('a0 p0 f0'.indexOf(PageType) != -1)
		if ('r0 r1'.indexOf(Position) != -1)
			if ('f0 f1'.indexOf(ItemType) != -1)
			ary[ary.length] = ['','doFloatOption(\'Factsheet: ' + key + '\')','Factsheet' ];
		
	// Factsheet
	if ('p0'.indexOf(PageType) != -1)
		if ('r0 r1'.indexOf(Position) != -1)
			if ('s0 s1'.indexOf(ItemType) != -1)
			ary[ary.length] = ['','doFloatOption(\'Factsheet: ' + key + '\')','Factsheet' ];
		
	// Chart
	if ('a0 a1 a2 p0 p3 f0 f1 f2'.indexOf(PageType) != -1)
		if ('pg'.indexOf(Position) != -1)
			ary[ary.length] = ['','doFloatOption(\'Chart: ' + key + '\')','Chart' ];

	if ('f1'.indexOf(PageType) != -1)
		if ('t0'.indexOf(Position) != -1)
			ary[ary.length] = ['','doFloatOption(\'Chart: ' + key + '\')','Chart' ];

	// Separator /*********************************************************************************/
	if ((ary.length != 0) && (ary[ary.length-1][2]))
		if (ary[ary.length-1][2] != 'separator')	// don't add 2 separators together
			ary[ary.length] = ['','','separator'];  // separator only

	// Create new account outside an ISA
	if ('a0 p0'.indexOf(PageType) != -1)
		if ('pg'.indexOf(Position) != -1)
			ary[ary.length] = ['','doFloatOption(\'Create new account outside an ISA\')','Create new account outside an ISA' ];
	
	if ('f0'.indexOf(PageType) != -1)
		if ('t0 t1'.indexOf(Position) != -1)
			if ('f0'.indexOf(ItemType) != -1)
				ary[ary.length] = ['','doFloatOption(\'Create new account outside an ISA\')','Create new account outside an ISA' ];
	
	// Create new joint account
	if ('a0 p0'.indexOf(PageType) != -1)
		if ('pg'.indexOf(Position) != -1)
			ary[ary.length] = ['','doFloatOption(\'Create new joint account\')','Create new joint account' ];
	
	if ('f0'.indexOf(PageType) != -1)
		if ('pg t0'.indexOf(Position) != -1)
			if ('f0'.indexOf(ItemType) != -1)
				ary[ary.length] = ['','doFloatOption(\'Create new joint account\')','Create new joint account' ];

	// Top-up
	if ('a0 f0'.indexOf(PageType) != -1)
		if ('r0 r1'.indexOf(Position) != -1)
			if ('f0'.indexOf(ItemType) != -1)
				ary[ary.length] = ['','doFloatOption(\'Top-up: ' + key + '\')','Top-up' ];

	if ('p0'.indexOf(PageType) != -1)
		if ('r0 r1'.indexOf(Position) != -1)
			if ('f0'.indexOf(ItemType) != -1)
				if (key.indexOf('this year') != -1) // this is a current year ISA fund
					ary[ary.length] = ['','doFloatOption(\'Top-up: ' + key + '\')','Top-up' ];

	if ('a0'.indexOf(PageType) != -1)
		if ('r0'.indexOf(Position) != -1)
			if ('a0a'.indexOf(ItemType) != -1)
				if (key.indexOf('this year') != -1) // this is a current year ISA fund
					ary[ary.length] = ['','doFloatOption(\'Top-up: ' + key + '\')','Top-up' ];

	// Switch
	if ('a0 p0 f0'.indexOf(PageType) != -1)
		if ('r0 r1 gp'.indexOf(Position) != -1)
			if ('a0a a0b a0c a0d a0f f0'.indexOf(ItemType) != -1)
				ary[ary.length] = ['','doFloatOption(\'Switch: ' + key + '\')','Switch' ];

	// Buy shares
	if ('a0 p0 f0'.indexOf(PageType) != -1)
		if ('r0'.indexOf(Position) != -1)
			if ('s0'.indexOf(ItemType) != -1)
				ary[ary.length] = ['','doFloatOption(\'Buy: ' + key + '\')','Buy shares' ];

	// Share network
	if ('p1 p2 p4 f1 f2'.indexOf(PageType) != -1)
		if ('pg'.indexOf(Position) != -1)
			ary[ary.length] = ['','doFloatOption(\'ShareNetwork: ' + key + '\')','ShareNetwork' ];

	if ('a0 p0'.indexOf(PageType) != -1)
		if ('r0 r1'.indexOf(Position) != -1)
			if ('a0e'.indexOf(ItemType) != -1)
				ary[ary.length] = ['','doFloatOption(\'ShareNetwork: ' + key + '\')','ShareNetwork' ];

	if ('f0 f1'.indexOf(PageType) != -1)
		if ('t0 t1 r0 r1'.indexOf(Position) != -1)
			if ('s0 s1'.indexOf(ItemType) != -1)
				ary[ary.length] = ['','doFloatOption(\'ShareNetwork: ' + key + '\')','ShareNetwork' ];

	// Funds network
	if ('p1 p2 p4 f1 f2'.indexOf(PageType) != -1)
		if ('pg'.indexOf(Position) != -1)
			ary[ary.length] = ['','doFloatOption(\'FundsNetwork: ' + key + '\')','FundsNetwork' ];

	if ('p0'.indexOf(PageType) != -1)
		if ('r0 r1'.indexOf(Position) != -1)
			if ('f0 f1'.indexOf(ItemType) != -1)
				ary[ary.length] = ['','doFloatOption(\'FundsNetwork: ' + key + '\')','FundsNetwork' ];

	if ('f0 f1'.indexOf(PageType) != -1)
		if ('t0 t1 r0 r1'.indexOf(Position) != -1)
			if ('f0 f1'.indexOf(ItemType) != -1)
				ary[ary.length] = ['','doFloatOption(\'FundsNetwork: ' + key + '\')','FundsNetwork' ];

	// Buy outside ISA
	if ('p0'.indexOf(PageType) != -1)
		if ('pg'.indexOf(Position) != -1)
			ary[ary.length] = ['','doFloatOption(\'Buy outside ISA\')','Buy outside ISA' ];

	if ('p0'.indexOf(PageType) != -1)
		if ('r0 r1'.indexOf(Position) != -1)
			if ('f0'.indexOf(ItemType) != -1)
				if (key.indexOf('outside') != -1)
					ary[ary.length] = ['','doFloatOption(\'Buy outside ISA\')','Buy outside ISA' ];

	if ('f0'.indexOf(PageType) != -1)
		if ('t0 t1'.indexOf(Position) != -1)
			if ('f0'.indexOf(ItemType) != -1)
				ary[ary.length] = ['','doFloatOption(\'Buy outside ISA\')','Buy outside ISA' ];

	if ('a0'.indexOf(PageType) != -1)
		if ('r0 r1'.indexOf(Position) != -1)
			if ('a0c a0d'.indexOf(ItemType) != -1)
				if (key.indexOf('Outside ISA') != -1)
					ary[ary.length] = ['','doFloatOption(\'Buy outside ISA: ' + key +'\')','Buy outside ISA' ];

				
	// Sell funds
	if ('a0 f0'.indexOf(PageType) != -1)
		if ('r0 r1'.indexOf(Position) != -1)
			if ('f0'.indexOf(ItemType) != -1)
				ary[ary.length] = ['','doFloatOption(\'Sell funds: ' + key +'\')','Sell funds' ];

	// Sell
	if ('a0'.indexOf(PageType) != -1)
		if ('gp r0 r1'.indexOf(Position) != -1)
			if ('a0a a0b a0c a0d a0e a0f'.indexOf(ItemType) != -1)
				ary[ary.length] = ['','doFloatOption(\'Sell: ' + key + '\')','Sell' ];

	// Sell shares
	if ('a0 p0 f0'.indexOf(PageType) != -1)
		if ('r0'.indexOf(Position) != -1)
			if ('s0'.indexOf(ItemType) != -1)
				ary[ary.length] = ['','doFloatOption(\'Sell shares: ' + key +'\')','Sell shares' ];


	// Transfer
	if ('p0'.indexOf(PageType) != -1)
		if ('r0 r1'.indexOf(Position) != -1)
			if ('f0 s0'.indexOf(ItemType) != -1)
				if (key.indexOf('xfr') != -1)
					ary[ary.length] = ['','doFloatOption(\'Transfer: ' + key +'\')','Transfer' ];

	// Reregister
	if ('p0'.indexOf(PageType) != -1)
		if ('r0 r1'.indexOf(Position) != -1)
			if ('f0'.indexOf(ItemType) != -1)
				if (key.indexOf('rereg') != -1)
					ary[ary.length] = ['','doFloatOption(\'Reregister: ' + key +'\')','Reregister' ];

	// Transaction detail
	if ('t0'.indexOf(PageType) != -1)
		if ('r0'.indexOf(Position) != -1)
			if ('t0'.indexOf(ItemType) != -1)
				ary[ary.length] = ['','jumpTo(\'TransactionDetail.asp?xn=' + key + '\')','Contract details' ];


	// Peculiar to Portfolio Summary page - options regarding indivdiual portfolios
	if ('p4'.indexOf(PageType) != -1)
		if ('r0'.indexOf(Position) != -1)
			if ('p0'.indexOf(ItemType) != -1)
				ary[ary.length] = ['','jumpTo(\'PortfolioEdit.asp?pf=' + key + '\')','Edit portfolio' ];

	if ('p4'.indexOf(PageType) != -1)
		if ('r0'.indexOf(Position) != -1)
			if ('p0'.indexOf(ItemType) != -1)
				ary[ary.length] = ['','jumpTo(\'Overview.asp?pf=' + key + '\')','Portfolio analysis' ];

	if ('p4'.indexOf(PageType) != -1)
		if ('r0'.indexOf(Position) != -1)
			if ('p0'.indexOf(ItemType) != -1)
				ary[ary.length] = ['','jumpTo(\'Portfolios.asp?pf=' + key + '\')','Details' ];

	// Peculiar to Portfolio Edit page - options favorites
	if ('p3'.indexOf(PageType) != -1)
		if ('t0'.indexOf(Position) != -1)
			if ('t0'.indexOf(ItemType) != -1)
				ary[ary.length] = ['','doFloatOption(\'Add to favourites\')','Add to favourites' ];



// The remaining options don't appear on Dermot's lists...	
	
	// Account contract details
//	if ('a'.indexOf(PageType) != -1)
//		if ('r'.indexOf(Position) != -1)
//			if ('a'.indexOf(ItemType) != -1)
//				ary[ary.length] = ['','doFloatOption(\'Account contract details: ' + key + '\')','Contract details' ];

	// portfolio edit
//	if ('x'.indexOf(PageType) != -1)
//		if ((Position == 'p'))
//			ary[ary.length] = ['','jumpTo(\'PortfolioEdit.asp\')','Edit portfolio' ];

	// funds breakdown
//	if ('x'.indexOf(PageType) != -1)
//		if ((Position == 'p') || (Position == 'i') || (Position == 't'))
//			ary[ary.length] = ['','doFloatOption(\'Funds breakdown: ' + key + '\')','Funds breakdown' ];

//	// Chart shares performance
//	if ('x'.indexOf(PageType) != -1)
//		if ((Position == 'st'))
//			ary[ary.length] = ['','doFloatOption(\'Chart shares performance: ' + key + '\')','Chart shares performance' ];

	// Chart share performance
//	if ('x'.indexOf(PageType) != -1)
//		if ((Position == 's'))
//			ary[ary.length] = ['','doFloatOption(\'Chart 1 share performance: ' + key + '\')','Chart 1 share performance' ];

	// Chart investments performance
//	if ('x'.indexOf(PageType) != -1)
//		if ((Position == 'p') || (Position == 't') || (Position == 'st'))
//			ary[ary.length] = ['','doFloatOption(\'Chart investments performance: ' + key + '\')','Chart investments performance' ];

	// Chart investment performance
//	if ('x'.indexOf(PageType) != -1)
//		if ((Position == 'i') || (Position == 'f') || (Position == 's'))
//			ary[ary.length] = ['','doFloatOption(\'Chart 1 investment performance: ' + key + '\')','Chart 1 investment performance' ];

	// Alert
//	if ('x'.indexOf(PageType) != -1)
//		if ((Position == 'i') || (Position == 'f') || (Position == 's'))
//			ary[ary.length] = ['','doFloatOption(\'Alert: ' + key + '\')','Alert' ];

	// Email
//	if ('x'.indexOf(PageType) != -1)
//		if ((Position == 'f'))
//			ary[ary.length] = ['','doFloatOption(\'Email: ' + key + '\')','Email' ];

	// Edit
//	if ('x'.indexOf(PageType) != -1)
//		if ((ItemType == 'p') || (ItemType == 'f'))
//			if ((Position == 'f') || (Position == 's'))
//				ary[ary.length] = ['','doFloatOption(\'Edit: ' + key + '\')','Edit' ];


	floatdiv.innerHTML = floatInner('&nbsp;', 'Select...', ary);
	
	floatouter.style.pixelTop = e.clientY + document.body.scrollTop + 2;
	floatouter.style.pixelLeft = e.clientX + document.body.scrollLeft + 2;
	floatouter.style.display = 'block';
	floatouterShadowShim.style.height = (ary.length * 13) +'px';
	floatouter.style.pixelTop -= (ary.length * 13);
	if (floatouter.style.pixelTop < document.body.scrollTop) floatouter.style.pixelTop = document.body.scrollTop;
	
	floatouterShadow.style.pixelTop = floatouter.style.pixelTop + 5;
	floatouterShadow.style.pixelLeft = floatouter.style.pixelLeft + 5;
	floatouterShadow.style.display = 'block';
	
	// Any SELECT elements will not be covered even if the DHTML block has a higher z-index
	// They must be hidden by setting their display property to 'none'
	// This would give the appearance of movement on the page if we specifically set the 
	// width of the element containing the SELECT beforehand!
//	var aSelects = document.getElementsByTagName('SELECT');
//	for (var n=0 ; n<aSelects.length ; n++)
//		aSelects[n].style.display = 'none'
	
	// fixed at 735 px
	// floatUnderLay.style.width = document.body.clientWidth + "px";
	floatUnderLay.style.height = (document.body.clientHeight - 96 + document.body.scrollTop) + "px";
	floatUnderLay.style.zIndex = '1200';
	floatUnderLay.style.display = 'block';
	
	return true;
}


