// ********************************************************************************
//
// lxmscripts.js
//
// Copyright (c) 2001 Logica UK Ltd.
//
// Description:
// This script contains common Java Script functions used by all JSPs.
//
// $Log:   //gordian/olympia/LXMPVCS/archives/WebBuild1/JSPBuild/library/scripts/lxmscripts.js-arc  $
// 
//    Rev 1.21   Oct 25 2002 11:45:58   HarlleyJ
// TIR 5780 - Amended ValidBic( ) method to accomodate spaces.
// 
//    Rev 1.20   27 Sep 2002 17:13:34   EatonN
// LCM5 - TIR4506 - Added new function, CreateHeading, to allow page titles to be created using a new stylesheet entry, rather than a .gif.
// 
//    Rev 1.19   26 Sep 2002 12:57:06   EatonN
// LCM5 - TIR5496 - Corrected the unloadListBox function for Netscape.
// 
//    Rev 1.18   Sep 04 2002 17:47:14   SalmondRI
// LCM 5.0 TIR 5667 - netscape fixes for findTradeInstructions
// 
//    Rev 1.17   Aug 01 2002 11:18:58   HazeldineJ
// WP 43090/94810
// 
//    Rev 1.16   Jun 21 2002 15:23:00   HazeldineJ
// WP 43090/94810
// 
//    Rev 1.15   Jun 20 2002 15:02:36   HazeldineJ
// WP 43090/94810
// 
//    Rev 1.13   Jun 07 2002 15:44:46   WisemanI
// TIR 4435, 4789
// IW: added ValidBic() function to check format of BICs
// 
//    Rev 1.12   Apr 23 2002 15:51:16   HazeldineJ
// JakeH - First Stab at extracting common code.
// 
//    Rev 1.11   Jan 15 2002 12:25:54   WallsR
// LCM 4.0 - OR 176 / TIR 3574  Added a new method validateChar which is called by validateText to prevent the entry of chars like ;:_% etc
// Note that there is no new error message to highlight this.  So if a user name like: John_Smith is entered. The error message would be "Enter User Name".  To do anything more sophisticated would require a change to all the jsp files!.
// 
//    Rev 1.10   Nov 28 2001 14:50:46   ParkS
// LCM 4.0 WP 24050a SJP: Not tested.  Added existing function declarations into object declarations.  Reorganised file.  Fixed function CheckPositiveNumber.  Added new function declarations to WebBrowser object.
// 
//    Rev 1.9   Nov 08 2001 20:06:36   PhullA
// LCM 4.0 WI 24004
// AP - Added new web object and helper methods.
// 
//    Rev 1.8   Aug 07 2001 12:38:38   AinsworthS
// SA - TIR 469 - Reinstate checkValidNumber (accidentally removed in revision 1.6)
// 
//    Rev 1.7   Jul 24 2001 19:54:20   AinsworthS
// SA - TIR 308 - Added time to page heading
// 
//    Rev 1.6   Jun 27 2001 15:27:28   SinghS
// SS - Moved checkValidAmount to lpmscripts.js
// 
//    Rev 1.5   Jun 18 2001 15:47:14   WallsR
// Ron - sorted out a typo in the last change
// 
//    Rev 1.4   Jun 14 2001 10:46:14   PhullA
// AP - added CheckPositiveAmount.
// 
//    Rev 1.3   Jun 11 2001 12:24:28   SinghS
// SS - Added checkValidAmount method to validate amount
// 
//    Rev 1.2   Apr 25 2001 16:30:04   AinsworthS
// SA - Added functions from lcmscripts.js
// 
//    Rev 1.2   Apr 25 2001 16:09:22   AinsworthS
// SA - Added functions from lcmscripts.js
//
//    Rev 1.1   Feb 13 2001 16:11:38   AinsworthS
// SA - Updated PageHeading
// 
//    Rev 1.0   Jan 18 2001 20:11:44   AinsworthS
// Initial revision.
//  
// $Author:   HarlleyJ  $
// $Revision:   1.21  $
// $Date:   Oct 25 2002 11:45:58  $
// 
// ********************************************************************************

// Form Validation Methods:
//
// GetCheckedValue                      - Returns the value of a checked  item from a collection of radio buttons
//   (Radio Obj [, STRING result])        Use to check for selection of a radio item
//
// GetSelectedValue                     - Returns the value of a selected item in a list/combo box
//   (LIST Obj [, STRING result])         Use to check for selection of a valid list item
//                                                          
// ValidateText                         - Checks a text field for a non null / zero length value
//   (TEXTFIELD Obj [, BOOLEAN popOK])    Use to check for entry of a text field
// 
// ValidateList                         - Checks that at least 1 value has been selected in a list
//   (LIST Obj [, BOOLEAN selOK])         Use to check for selection of any list item
// 
// checkValidNumber                     - Checks that the field contains a number
//   (TEXTFIELD Obj [, BOOLEAN validNo])  Use to check for a valid number in a text field
//
// CheckPositiveNumber			    - Checks that the field contains a positive number
//   (TEXTFIELD Obj [, BOOLEAN validNo])  Use to check for a valid number in a text field


// --- Begin Money object declarations

// Either convert a string into a Number object, or convert a form object's
// value into a Number object.
var browser = new BrowserInformation(); 

function parseNumericValue(anObject)
{
	var candidate = null;
	
	if (anObject.value)
	{
		candidate = anObject.value;
	}
	else
	{
		candidate = anObject;
	}
	
	return Number(candidate);
}

// Check whether either a form field or string object contains numeric data
function checkValidNumber(anObject)
{
	var aNumber = parseNumericValue(anObject);
	return (! isNaN(aNumber));
}

// Check whether either a form field or string object contains positive numeric
// data
function CheckPositiveNumber(anObject)
{
	var aNumber = parseNumericValue(anObject);
	var pos = false;
	
	if (! isNaN(aNumber))
	{
		pos = (aNumber >= 0) ? true : false;
	}
	
	return pos;
}

// Check whether a field contains valid amount data, excluding numbers with
// commas.
function checkValidAmount(Obj) 
{ 
    return checkValidNumber(Obj);
}

function Money()
{
	// Methods
	this.isPositiveNumber = CheckPositiveNumber;
	this.isValidAmount = checkValidAmount;
	this.isValidNumber = checkValidNumber;
	this.parseNumericValue = parseNumericValue;
}

// --- End Money object declarations

// --- Begin LxmHelper object declarations

/* This method updates a field with the matching value for a given key

	keyArray		- 2 dimensional array of keys, values
	key				- Key to search for (String)
	displayField	- the field to pass the matching value to (ref)

*/
function findKeyedValue(keyArray, key)
{
    for (i=0; i < keyArray.length; i++)
    {
		if (keyArray[i][0] == key) 
        {
            return keyArray[i][1];
        }
    }
    return "";
}

function findReverseKeyedValue(keyArray, key)
{
    for (i=0; i < keyArray.length; i++)
    {
		if (keyArray[i][1] == key) 
        {
            return keyArray[i][0];
        }
    }
    return "";
}

// Return the value property of the checked radio item 
// If no item is selected, return an empty string.
function GetCheckedValue(Obj)
{
    for (i=0;i<Obj.length;i++)
    {
        if (Obj[i].checked)
        {
            return Obj[i].value;
        }
    }
    return "";
}

// Return the value property of the selected item in a listbox
// If no item is selected, return a null string.
function GetSelectedValue(Obj)
{
    for (i=0;i<Obj.length;i++)
    {
        if (Obj[i].selected)
        {
            return Obj[i].value;
        }
    }
    return "";
}

/* This method updates the contents of a list depending upon the selected value
	of another list

	selectList	- the selection list (ref)
	resultList	- the result list (ref)
	listArray 	- the subset name of the arrays containing the new values.  These must
				  have the format xxxxxxxx<selected_value>, pass in xxxxxxxx here.

*/
function updateLists(selValue, resultList, listArray)
{
    var selectedArray = eval(listArray + selValue);

    while (resultList.length > 0)
    {
        resultList.options[0] = null;
    }
    for (i=0; i<selectedArray.length; i++)
    {
        resultList.options[i] = new Option(selectedArray[i],selectedArray[i]);
    }
	
	if (resultList.length > 0)
	{
	    resultList[0].selected = true;
	}
}


// Returns true if the bic conforms to SWIFT format 4!a2!a2!c[3!c], else returns false
function ValidBic(bic)
{
	var alphaUpper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ ";
	var digits = "0123456789";
	
	if (bic == null) return false;

	// Validate length
	if (bic.value.length != 8 && bic.value.length != 11) return false;

    for (var i = 0; i < bic.value.length; i++ )
	{
		if (i < 6)
		{
			// First six chars must be uppercase alpha
			// (Note: indexOf() returns -1 if char not found)
	        if (-1 == alphaUpper.indexOf(bic.value.charAt(i))) return false;
		}
		else
		{
			// Chars 7 to 11 must be uppercase alpha or digit
	        if (-1 == alphaUpper.indexOf(bic.value.charAt(i)) &&
				-1 == digits.indexOf(bic.value.charAt(i))) return false;
		}
	}
	
	// All checks passed
	return true;
}


// Check whether a list has any selected item, including null items
function ValidateList(Obj) 
{
    if (Obj.value == 0)
    {
        return false;
    }
    return true;
}

// Check text field for a non null / zero length value and call checkValidChar to check for malicious code

function ValidateText(Obj) 
{
    if (Obj != null)
    {
        if (Obj.value.length == 0)
        {
            return false;
        }
        else
        {
            if (checkValidChar(Obj))
            { 
                return true;
            }
            else
            {
                return false;
            }
        }
    }           
    else
    {
        return false;
    }
}

// Returns false if the characters in the object contain any characters which could 
// be used to create malicious html eg ''';_%&<>\*+#[]{}
// Allow / and : so that dates and times may be entered.

function checkValidChar(Obj) 
{ 
    var chchar = 0;
    for (var i = 0; i < Obj.value.length && chchar == 0; i++ )
    {
        var chr = Obj.value.charAt(i);

        if ((chr == ";") || (chr == "_")  || (chr == "%") || (chr == "<") || 
            (chr == ">") || (chr == "\\") || (chr == "*") || (chr == "+") || 
            (chr == "#") || (chr == "[")  || (chr == "]") || (chr == "{") || (chr == "}") || 
            (chr == "'") || (chr =="&")  )
        {
            chchar = 1;
        }
    }

    if (chchar == 1)
    {
        return false;
    }
    else
    {
        return true;
    }
}

// LxmHelper
function LxmHelper()
{
	// Methods
    this.findKeyedValue = findKeyedValue;
    this.findReverseKeyedValue = findReverseKeyedValue;
	this.getCheckedValue = GetCheckedValue;
    this.getSelectedValue = GetSelectedValue;
    this.updateLists = updateLists;
	this.validateList = ValidateList;
	this.validateText = ValidateText;
	this.validBic = ValidBic;
}

// --- End LxmHelper object declarations

// --- Begin WebBrowser object declarations

function getVersion() {
	return this.bV;
}
function isExplorer4() {
	return this.IE4;
}
function isNavigator4() {
	return this.NS4;
}
function isNavigator5() {
	return this.NS5;
}
function isVersion4Browser() {
	return this.ver4;
}
function isVersion5Browser() {
	return this.ver4;
}
// WebBrowser
function WebBrowser() {
	// Properties
	this.bV = parseInt(navigator.appVersion);
	this.IE4 = ((document.all) && (this.bV >= 4)) ? true : false;
	this.NS5 = (document.layers) ? true : false;
	this.ver4 = (this.NS5 || this.IE4) ? true : false;
	// Methods
	this.getVersion = getVersion;
	this.isIE4 = isExplorer4;
	this.isExplorer4 = isExplorer4;
	this.isNN4 = isNavigator4;
	this.isNN5 = isNavigator5;
	this.isNavigator4 = isNavigator4;
	this.isNavigator5 = isNavigator5;
	this.isVersion4 = isVersion4Browser;
	this.isVersion4Browser = isVersion4Browser;
	this.isVersion5 = isVersion5Browser;
	this.isVersion5Browser = isVersion5Browser;
}

// --- End WebBrowser object declarations

// --- Begin miscelleneous helper functions

// Display warning for a function that is not yet implemented
function NotYetImplemented()
{
    alert("This function is not yet implemented");
}

function CreateHeading(rootDir, titleText, helpPage)
{
    // Is this a child or top-level window?
    if ((parent != null) && 
        (parent.banner != null) &&
        (parent.banner.document != null) &&
        (parent.banner.document.mainform != null) &&
        (parent.banner.document.mainform.id != null))
    {
        // This is a child window, so set help page on main banner
        parent.banner.document.mainform.id.value = helpPage;
    }
    else
    {
        // This is a top-level window, so create a page banner
        closeCmd = "self.close();";
        helpCmd  = "picwin=window.open('','Help','scrollbars=yes,resizable=yes,top=100,left=100,height=450,width=650');picwin.focus();picwin.location.href='"+rootDir+"/WebHelp/"+helpPage+"';";

        document.write('<TABLE HEIGHT=29 WIDTH=100% BGCOLOR="#000080">');
        document.write('    <TR>');
        document.write('        <TD WIDTH=200><IMG ALT="" BORDER=0 HEIGHT=25 WIDTH=65 SRC="' + rootDir + '/images/page_logo_blue.gif"></TD>');
        document.write('        <TD></TD>');
        document.write('        <TD WIDTH=70><INPUT TYPE=IMAGE NAME="Close" SRC="' + rootDir + '/images/page_close_blue.gif" ALT="Close Window" onClick="' + closeCmd + '"></TD>');
        document.write('        <TD WIDTH=70><INPUT TYPE=IMAGE NAME="Help" SRC="' + rootDir + '/images/page_help_blue.gif" ALT="Display Help" onClick="' + helpCmd + '"></TD>');
        document.write('    </TR>');
        document.write('</TABLE>');
    }

    // Page title
    document.write('<P>');
    document.write('<TABLE WIDTH=100%>');
    document.write('    <TR>');
    document.write('        <TD CLASS="PageTitle">' + titleText + '</TD>');
    document.write('        <TD CLASS="Label" ALIGN=RIGHT>' + TimeNow() +'</TD>');
    document.write('    </TR>');
    document.write('</TABLE>');
    document.write('<P>');
}

// Create page heading (with page banner if appropriate)
function PageHeading(rootDir, title, titleGIF, helpPage)
{
    // Is this a child or top-level window?
    if ((parent != null) && 
        (parent.banner != null) &&
        (parent.banner.document != null) &&
        (parent.banner.document.mainform != null) &&
        (parent.banner.document.mainform.id != null))
    {
        // This is a child window, so set help page on main banner
        parent.banner.document.mainform.id.value = helpPage;
    }
    else
    {
        // This is a top-level window, so create a page banner
        closeCmd = "self.close();";
        helpCmd  = "picwin=window.open('','Help','scrollbars=yes,resizable=yes,top=100,left=100,height=450,width=650');picwin.focus();picwin.location.href='"+rootDir+"/WebHelp/"+helpPage+"';";

        document.write('<TABLE HEIGHT=29 WIDTH=100% BGCOLOR="#000080">');
        document.write('    <TR>');
        document.write('        <TD WIDTH=200><IMG ALT="" BORDER=0 HEIGHT=25 WIDTH=65 SRC="' + rootDir + '/images/page_logo_blue.gif"></TD>');
        document.write('        <TD></TD>');
        document.write('        <TD WIDTH=70><INPUT TYPE=IMAGE NAME="Close" SRC="' + rootDir + '/images/page_close_blue.gif" ALT="Close Window" onClick="' + closeCmd + '"></TD>');
        document.write('        <TD WIDTH=70><INPUT TYPE=IMAGE NAME="Help" SRC="' + rootDir + '/images/page_help_blue.gif" ALT="Display Help" onClick="' + helpCmd + '"></TD>');
        document.write('    </TR>');
        document.write('</TABLE>');
    }

    // Page title
    document.write('<P>');
    document.write('<TABLE WIDTH=100%>');
    document.write('    <TR>');
    document.write('        <TD><IMG ALT="' + title + '" BORDER=0 SRC="' + rootDir + '/images/titles/' + titleGIF + '"></TD>');
    document.write('        <TD CLASS="Label" ALIGN=RIGHT>' + TimeNow() +'</TD>');
    document.write('    </TR>');
    document.write('</TABLE>');
    document.write('<P>');
}

// Construct current HH:MM:SS time string (in browser local timezone)
function TimeNow()
{
    var now = new Date();
    var hour = "00" + now.getHours();
    var minute = "00" + now.getMinutes();
    var second = "00" + now.getSeconds();
    return hour.substring(hour.length-2) + ":" +
           minute.substring(minute.length-2) + ":" +
           second.substring(second.length-2);
}

// --- End miscelleneous helper functions

function BrowserInformation ()
{   
	var agt=navigator.userAgent.toLowerCase();

    this.major = parseInt(navigator.appVersion);
    this.minor = parseFloat(navigator.appVersion);

    this.nav  = ((agt.indexOf('mozilla')!=-1) && ((agt.indexOf('spoofer')==-1)
                && (agt.indexOf('compatible') == -1)));
    this.nav2 = (this.nav && (this.major == 2));
    this.nav3 = (this.nav && (this.major == 3));
    this.nav4 = (this.nav && (this.major == 4));
    this.nav4 = (this.nav && (this.major == 4));
    this.nav4up = (this.nav && (this.major >= 4));
    this.navonly      = (this.nav && ((agt.indexOf(";nav") != -1) ||
                          (agt.indexOf("; nav") != -1)) );
    this.nav6 = (this.nav && (this.major == 5));
    this.nav6up = (this.nav && (this.major >= 5));
    this.gecko = (agt.indexOf('gecko') != -1);


    this.ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
    this.ie3    = (this.ie && (this.major < 4));
    this.ie4    = (this.ie && (this.major == 4) && (agt.indexOf("msie 4")!=-1) );
    this.ie4up  = (this.ie && (this.major >= 4));
    this.ie5    = (this.ie && (this.major == 4) && (agt.indexOf("msie 5.0")!=-1) );
    this.ie5_5  = (this.ie && (this.major == 4) && (agt.indexOf("msie 5.5") !=-1));
    this.ie5up  = (this.ie && !this.ie3 && !this.ie4);
    this.ie5_5up =(this.ie && !this.ie3 && !this.ie4 && !this.ie5);
    this.ie6    = (this.ie && (this.major == 4) && (agt.indexOf("msie 6.")!=-1) );
    this.ie6up  = (this.ie && !this.ie3 && !this.ie4 && !this.ie5 && !this.ie5_5);

    this.webtv = (agt.indexOf("webtv") != -1); 

    this.TVNavigator = ((agt.indexOf("navio") != -1) || (agt.indexOf("navio_aoltv") != -1)); 

    this.hotjava = (agt.indexOf("hotjava") != -1);
    this.hotjava3 = (this.hotjava && (this.major == 3));
    this.hotjava3up = (this.hotjava && (this.major >= 3));

    // *** PLATFORM ***
    this.win   = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) );
    // NOTE: On Opera 3.0, the userAgent string includes "Windows 95/NT4" on all
    //        Win32, so you can't distinguish between Win95 and WinNT.
    this.win95 = ((agt.indexOf("win95")!=-1) || (agt.indexOf("windows 95")!=-1));

    // is this a 16 bit compiled version?
    this.win16 = ((agt.indexOf("win16")!=-1) || 
               (agt.indexOf("16bit")!=-1) || (agt.indexOf("windows 3.1")!=-1) || 
               (agt.indexOf("windows 16-bit")!=-1) );  

    this.win31 = ((agt.indexOf("windows 3.1")!=-1) || (agt.indexOf("win16")!=-1) ||
                    (agt.indexOf("windows 16-bit")!=-1));

    this.winme = ((agt.indexOf("win 9x 4.90")!=-1));
    this.win2k = ((agt.indexOf("windows nt 5.0")!=-1));

    // NOTE: Reliable detection of Win98 may not be possible. It appears that:
    //       - On Nav 4.x and before you'll get plain "Windows" in userAgent.
    //       - On Mercury client, the 32-bit version will return "Win98", but
    //         the 16-bit version running on Win98 will still return "Win95".
    this.win98 = ((agt.indexOf("win98")!=-1) || (agt.indexOf("windows 98")!=-1));
    this.winnt = ((agt.indexOf("winnt")!=-1) || (agt.indexOf("windows nt")!=-1));
    this.win32 = (this.win95 || this.winnt || this.win98 || 
                    ((this.major >= 4) && (navigator.platform == "Win32")) ||
                    (agt.indexOf("win32")!=-1) || (agt.indexOf("32bit")!=-1));

    this.os2   = ((agt.indexOf("os/2")!=-1) || 
                    (navigator.appVersion.indexOf("OS/2")!=-1) ||   
                    (agt.indexOf("ibm-webexplorer")!=-1));

    this.mac    = (agt.indexOf("mac")!=-1);
    // hack ie5 js version for mac
    if (this.mac && this.ie5up) this.js = 1.4;
    this.mac68k = (this.mac && ((agt.indexOf("68k")!=-1) || 
                               (agt.indexOf("68000")!=-1)));
    this.macppc = (this.mac && ((agt.indexOf("ppc")!=-1) || 
                                (agt.indexOf("powerpc")!=-1)));

    this.sun   = (agt.indexOf("sunos")!=-1);
    this.sun4  = (agt.indexOf("sunos 4")!=-1);
    this.sun5  = (agt.indexOf("sunos 5")!=-1);
    this.suni86= (this.sun && (agt.indexOf("i86")!=-1));
    this.irix  = (agt.indexOf("irix") !=-1);    // SGI
    this.irix5 = (agt.indexOf("irix 5") !=-1);
    this.irix6 = ((agt.indexOf("irix 6") !=-1) || (agt.indexOf("irix6") !=-1));
    this.hpux  = (agt.indexOf("hp-ux")!=-1);
    this.hpux9 = (this.hpux && (agt.indexOf("09.")!=-1));
    this.hpux10= (this.hpux && (agt.indexOf("10.")!=-1));
    this.aix   = (agt.indexOf("aix") !=-1);      // IBM
    this.aix1  = (agt.indexOf("aix 1") !=-1);    
    this.aix2  = (agt.indexOf("aix 2") !=-1);    
    this.aix3  = (agt.indexOf("aix 3") !=-1);    
    this.aix4  = (agt.indexOf("aix 4") !=-1);    
    this.linux = (agt.indexOf("inux")!=-1);
    this.sco   = (agt.indexOf("sco")!=-1) || (agt.indexOf("unix_sv")!=-1);
    this.unixware = (agt.indexOf("unix_system_v")!=-1); 
    this.mpras    = (agt.indexOf("ncr")!=-1); 
    this.reliant  = (agt.indexOf("reliantunix")!=-1);
    this.dec   = ((agt.indexOf("dec")!=-1) || (agt.indexOf("osf1")!=-1) || 
           (agt.indexOf("dec_alpha")!=-1) || (agt.indexOf("alphaserver")!=-1) || 
           (agt.indexOf("ultrix")!=-1) || (agt.indexOf("alphastation")!=-1)); 
    this.sinix = (agt.indexOf("sinix")!=-1);
    this.freebsd = (agt.indexOf("freebsd")!=-1);
    this.bsd = (agt.indexOf("bsd")!=-1);
    this.unix  = ((agt.indexOf("x11")!=-1) || this.sun || this.irix || this.hpux || 
                 this.sco ||this.unixware || this.mpras || this.reliant || 
                 this.dec || this.sinix || this.aix || this.linux || this.bsd || this.freebsd);

    this.vms   = ((agt.indexOf("vax")!=-1) || (agt.indexOf("openvms")!=-1));
}

function showElement(el) 
{

    if (browser.major < 4) return;
	if (browser.nav4)
	{
		// Netscape 4 uses layers - code to handle this
		whichEl = eval("document." + el);
		if (whichEl.visibility == "hidden"
			||whichEl.visibility == "hide") 
		{
			whichEl.visibility = "show";
		}
		else {
			hideElement(el);
		}	
	}
	else
	{
		var elm = document.getElementById(el);
	    if (elm.style.display == "none") 
        {
		    elm.style.display = "block";
    	}
	    else
        {
		    hideElement(el);
        }
	}
}

function hideElement(el)
{
    if (browser.major < 4) return;
    if (! browser.nav4)
    {
        var elm = document.getElementById(el);
        elm.style.display = "none";
    }
    else
    {
        // Special code for Netscape Navigator 4
    	whichEl = eval("document." + el);
	    whichEl.visibility = "hide";
    }
}

// Returns a string of the id of the tab selected.
function initTab()
{
	if (browser.nav4)
	{
	    for (i=0; i<document.layers.length; i++) 
        {
			whichEl = document.layers[i];
			if (whichEl.id.indexOf("Child") != -1) whichEl.visibility = "hide";
		}

	}
	else
	{
		tempColl = document.getElementsByTagName("DIV");
		for (i=0; i<tempColl.length; i++)
        {
            if (tempColl[i].className == "child")
            {
                tempColl[i].style.display = "none";
            }
            else
            {
                tempColl[i].style.display = "block";
            }
        }

	}
}

// Returns the value of the selected radio button within a group.
// 
// 2 fold function
// Reduce code in JSPs and indeed browser detection
// Allows work-around for Mozilla bug 34297 to be placed centrally, rather than in each JSP
//
// Note - I know some code is repeated in different sections here - but this is intentional - allows blocks of code to be removed later
/*function getRadioButtonValue(radioButtonName, divName, formName)
{
	var value = "";
	if (browser.nav4)
	{
		// Netscape 4 uses layers
		selForm = document.layers.eval(divName).document.eval(formName);
		for (var count = 0; count < selForm.eval(radioButtonName).length; count++)
		{
			if (selForm.eval(radioButtonName)[count].checked == true)
			{
				value = selForm.eval(radioButtonName)[count].value;
			}
		}
	}
	else if (browser.nav6up)
	{
		// Mozilla bug 34297 means cannot unload radio buttons when display: none
		selForm = document.eval(formName);
		element = document.getElementById(divName);

		// Can only unload data whilst control display style is visisble
		var currentDisplayStatus = element.style.display
	    element.style.display = "block";

		for (var count = 0; count < selForm.eval(radioButtonName).length; count++)
		{
			if (selForm.eval(radioButtonName)[count].checked == true)
			{
				value = selForm.eval(radioButtonName)[count].value;
			}
		}

		// Set back to original setting
		element.style.display = currentDisplayStatus;
	}
	else
	{
		selForm = eval("document." + formName);
		for (var count = 0; count < (eval("selForm." + radioButtonName)).length; count++)
		{
			if (eval("selForm." + radioButtonName + "[" + count + "].checked") == true)
			{
				value = eval("selForm." + radioButtonName + "[" + count + "].value");
			}
		}
	}
	return value;
}*/

// controlName - name of control - including form (e.g. selForm.RadioButton)
function getRadioButtonSelectedValue(controlName)
{
	for (var i =0 ; i < controlName.length; i++)
	{
		if (controlName[i].checked == true)
		{
			return controlName[i].value;
		}
	}
}


// Returns an HTML form object, regardless of browser used.
function getFormObject(divName, formName)
{
	if (browser.nav4)
	{
		returnForm = eval("document.layers." + divName + ".document." + formName);
	}
	else
	{
		returnForm = eval("document." + formName);
	}

	return returnForm;
}

// Unloads a listbox to specified array
//
// listboxControl - full name of control including form
// targetArray - full name of control including form e.g. document.mainform.organisation_list
//
// Be warned - does no checking or array sizes
function unloadListbox(listboxControl, targetArray)
{
	if (listboxControl.length > 1)
	{
		for (i = 0; i < listboxControl.length; i++) {
			if (listboxControl[i].selected == true ) {
				targetArray[i].value = listboxControl[i].value;
			}
			else
			{
				targetArray[i].value = "";
			}
		}
	}
	else
	{
		if (browser.nav4 || browser.nav6)
		{
			if(listboxControl[0].selected)
			{
				targetArray.value = listboxControl[0].value;
			}
		}
		else
		{
			targetArray.value = listboxControl.value;
		}
	}		
}

/// *** Set of functions for listbox/radio button combinations ***

// Validates list and radio button combinations where a user can use a radio button to determing 'All' or 'Selection'.
// If 'Selection' then at least one item from list must be selected
//
// This should be called after values are copied to main form
// selectionName should be 'ALL' for 'All' and 'SEL' for 'Selection'
//
// listName and selectionName should be full - i.e. document.mainform.currencyList
function ValidateSelectionList(listControl, selectionName)
{
	listControl = eval(listControl);
	selectionName = eval(selectionName);
	if (selectionName.value == "SEL")
	{
		LISTOK=false;
		if (listControl.length > 1)
		{
			for (i = 0; i < listControl.length; i++) 
			{
				if (listControl[i].value != "")
	        		{
				        LISTOK = true;
				}
			}
		}
		else
		{
		 if (listControl.value != "")
		 {
		 	LISTOK=true;
		 }
		}
	}
	else
	{ 
		LISTOK=true; 
	}

	return LISTOK;
}

function deSelectList(listControl) 
{
	listControl = eval(listControl);
	for (i = 0; i < listControl.length; i++)
	{
		listControl[i].selected = false;
	}
}

// Moved this code to here not to save any lines - but so that same code path it used and functionality easily altered.
function selectList(assosiatedRadioButton)
{
	assosiatedRadioButton = eval(assosiatedRadioButton);
	assosiatedRadioButton[1].checked=true
}

/// *** End of set of functions for listbox/radio button combinations ***

// NS4 specific code
function showAll() {
	for (i=0; i<document.layers.length; i++) {
		whichEl = document.layers[i];
		whichEl.visibility = "show";
	}
}

function getIndex(el) {
	ind = null;
	for (i=0; i<document.layers.length; i++) {
		whichEl = document.layers[i];
		if (whichEl.id == el) {
			ind = i;
			break;
		}
	}
	return ind;
}

function writePositioning()
{
	with (document) 
	{
		write("<STYLE TYPE='text/css'>");
		if (browser.nav4) {
			write(".parent {position:absolute; visibility:hidden}");
			write(".child {position:absolute; visibility:hidden}");
			write(".regular {position:absolute; visibility:hidden}")
		}
		else {
			write(".child {display:none}")
		}
		write("</STYLE>");
	}
}

function SelectTab(el)
{
	initTab();
    showElement(el);
}

function getSelectedTabName()
{
	var tabName = "";
	if (browser.nav4)
	{
	    for (i=0; i<document.layers.length; i++) 
        {
			whichEl = document.layers[i];
			if (whichEl.id.indexOf("Child") != -1)
			{
				if (whichEl.visibility == "show")
				{
					tabName = whichEl.id;
				}
			}
		}

	}
	else
	{
		tempColl = document.getElementsByTagName("DIV");
		for (i=0; i<tempColl.length; i++)
        {
			if (tempColl[i].style.display == "block")
			{
				tabName = tempColl[i].id;
			}
        }

	}
	return tabName;
}

// Resets all forms starting 'data_'
function resetChildren()
{
	var selectedTab = getSelectedTabName();

	if (browser.nav4)
	{
		for (k=0; k < document.layers.length; k++) 
        {
			tempCol2 = document.layers[k].document.forms;
			for (j=0; j<tempCol2.length; j++)
			{	
				if ((tempCol2[j].name).substring(0,5) == "data_")
				{
					tempCol2[j].reset();
				}
			}
		}

	}
	else
	{
		if (browser.nav6)
		{
			// NS6 seems to need DIV to be block before it can reset it - loop through forms for each div.
			tempColl = document.getElementsByTagName("DIV");
			for (divCounter = 0; divCounter < tempColl.length; divCounter++)
			{
				SelectTab(tempColl[divCounter].id);

				tempCol2 = document.getElementsByTagName("FORM");
				for (j=0; j<tempCol2.length; j++)
				{	
					if ((tempCol2[j].name).substring(0,5) == "data_")
					{
						tempCol2[j].reset();
					}
				}
			}
		}
		else
		{
			tempCol2 = document.getElementsByTagName("FORM");
			for (i=0; i<tempCol2.length; i++)
			{	
				if ((tempCol2[i].name).substring(0,5) == "data_")
				{
					tempCol2[i].reset();
				}
			}
			
		}
	}
	SelectTab(selectedTab);
}

function hideLayer (el){
	if (browser.nav4){
	
		whichEl = eval("document." + el);
		if (whichEl.visibility == "show") 
		{
			whichEl.visibility = "hidden";
		}
	}
}

function loadArchivesPage(year)
{
	var frm = document.mainform;

        frm.action = "index.php?page=archives&&year=" + year;

        frm.submit();
}
