//-------------------------------------------------------------------------- 
// File:  smris_component.js
//                                                                           
// Copyright (c) 2000,2001 Lands Department, HKSAR                           
//                                                                           
// Ver  Date         Description                                             
// ------------------------------------------------------------------------- 
// 1.0  Jan 15, 2001 By Peter Barratt and Calvin Lo                          
//                   This javascript file contains all the sources for the
//                   custom components, including Radio Button component,
//                   Table Display component and Selection List component.
//
// $Log: smris_component.js,v $
// Revision 1.40  2003/12/03 10:15:30  iadmin
// UAT30
//
// Revision 1.39  2003/12/03 09:57:31  iadmin
// Apply changes for implementation of Maintenance Agent
//
// Revision 1.38  2003/06/13 09:04:23  iadmin
// UAT29
//
// Revision 1.37  2003/06/13 08:56:53  iadmin
// final version after UAT of SC
//
// Revision 1.36  2003/06/03 11:52:21  iadmin
// UAT28
//
// Revision 1.35  2003/06/03 11:09:09  calvin
// Simplified Chinese enhanacement
//
// Revision 1.34  2002/08/30 11:54:40  iadmin
// UAT27
//
// Revision 1.33  2002/08/28 07:16:13  iadmin
// UAT26 promoted to PRD10
//
// Revision 1.32  2002/05/14 12:28:17  iadmin
// UAT25 promoted to PRD9
//
// Revision 1.31  2002/03/25 13:41:44  iadmin
// UAT
//
// Revision 1.30  2002/03/20 16:59:40  iadmin
// UAT24
//
// Revision 1.29  2001/12/21 05:17:54  iadmin
// UAT23 promoted to PRD8
//
// Revision 1.28  2001/11/01 05:38:28  iadmin
// UAT22 promoted to PRD7
//
// Revision 1.27  2001/10/09 10:07:44  iadmin
// UAT21 promoted to PRD6
//
// Revision 1.26  2001/08/24 10:06:00  iadmin
// UAT20 promoted to PRD5
//
// Revision 1.25  2001/08/22 10:46:03  iadmin
// UAT19
//
// Revision 1.24  2001/08/07 11:11:09  iadmin
// UAT18
//
// Revision 1.23  2001/07/31 02:41:01  iadmin
// UAT17
//
// Revision 1.22  2001/05/02 11:08:44  iadmin
// UAT16 promoted to PRD4
//
// Revision 1.21  2001/04/27 12:25:14  iadmin
// UAT15
//
// Revision 1.20  2001/04/24 10:57:28  iadmin
// UAT14
//
// Revision 1.19  2001/03/29 11:17:42  iadmin
// UAT13 promoted to PRD3
//
// Revision 1.18  2001/03/27 13:56:40  iadmin
// UAT12
//
// Revision 1.17  2001/03/20 13:13:49  iadmin
// UAT11
//
// Revision 1.16  2001/03/15 11:17:15  iadmin
// UAT10
//
// Revision 1.15  2001/03/15 03:15:00  calvin
// For Selection List Component, use the font to display the items in the list
// if it is already defined
//
// Revision 1.14  2001/03/14 13:00:50  calvin
// *** empty log message ***
//
// Revision 1.13  2001/03/13 12:46:49  iadmin
// UAT9
//
// Revision 1.12  2001/03/08 12:48:58  iadmin
// UAT8
//
// Revision 1.11  2001/03/08 10:12:38  calvin
// UAT7
//
// Revision 1.10  2001/03/08 10:10:12  calvin
// Add the setFont() method for Selection List Component
//
// Revision 1.9  2001/03/01 03:35:39  calvin
// Fix the bug when there is large number of records for the Table Display
// Component
//
// Revision 1.8  2001/02/28 09:59:06  iadmin
// UAT6
//
// Revision 1.7  2001/02/27 10:19:44  calvin
// UAT5
//
// Revision 1.6  2001/02/12 08:38:38  calvin
// Allow to change the font and the font size of the content in the table
//
// Revision 1.5  2001/02/09 04:32:48  calvin
// UAT4
//
// Revision 1.4  2001/02/06 03:18:13  calvin
// temp check-in
//
// Revision 1.3  2001/01/22 07:50:05  calvin
// UAT3
//
// Revision 1.2  2001/01/18 07:52:13  calvin
// - Use the method exec() directly instead of _doRBOclick() for radio button
//
// Revision 1.1  2001/01/18 02:12:40  calvin
// Initial revision
//
//
//--------------------------------------------------------------------------


      // Constants
      var UNDEFINED = 'undefined';


      // -----------------------------------------------------------------    
      // Function:  _setObjectDocumentName
      //                                                                      
      // Ver  Date         Description                                        
      // -----------------------------------------------------------------    
      // 1.0  Jan 15, 2001 By Peter Barratt
      //                   Set the document where the custom object belongs to
      //                                                                      
      // Parameters      Mode   Type       Description                        
      // -----------------------------------------------------------------    
      // documentName    Input  String     Document Name
      //                                                                      
      // -----------------------------------------------------------------

      function _setObjectDocumentName(documentName)
      { this.document = documentName; }


      // -----------------------------------------------------------------    
      // Function:  _setObjectFormName
      //                                                                      
      // Ver  Date         Description                                        
      // -----------------------------------------------------------------    
      // 1.0  Jan 15, 2001 By Peter Barratt
      //                   Set the form where the custom object belongs to
      //                                                                      
      // Parameters      Mode   Type       Description                        
      // -----------------------------------------------------------------    
      // formName        Input  String     Form Name
      //                                                                      
      // -----------------------------------------------------------------

      function _setObjectFormName(formName)
      { this.form = formName; }


      // -----------------------------------------------------------------    
      // Function:  _setObjectReferenceName
      //                                                                      
      // Ver  Date         Description                                        
      // -----------------------------------------------------------------    
      // 1.0  Jan 15, 2001 By Peter Barratt
      //                   Set the reference name so that others can
      //                   use this name to refer to current object
      //                                                                      
      // Parameters      Mode   Type       Description                        
      // -----------------------------------------------------------------    
      // objRefName      Input  String     Object Reference Name
      //                                                                      
      // -----------------------------------------------------------------

      function _setObjectReferenceName(objRefName)
      { this.refName = objRefName; }


      // -----------------------------------------------------------------    
      // Function:  _setObjectTitleString
      //                                                                      
      // Ver  Date         Description                                        
      // -----------------------------------------------------------------    
      // 1.0  Jan 15, 2001 By Calvin Lo
      //                   Set the title of the custom object
      //                                                                      
      // Parameters      Mode   Type       Description                        
      // -----------------------------------------------------------------    
      // titleName       Input  String     Title
      //                                                                      
      // -----------------------------------------------------------------

      function _setObjectTitleString(titleName)
      { this.title = titleName; }

     
 
      // ============================
      // -- Radio Button Component --
      // ============================
      // TODO
      //  - validate data before write
      //  - add clear() method
      //  - add capability to maintain state between refreshes
      //  - check number of params when adding new button, use varargs method
      // ============================

      // -----------------------------------------------------------------    
      // Function:  radioButtonObj
      //                                                                      
      // Ver  Date         Description                                        
      // -----------------------------------------------------------------    
      // 1.0  Jan 15, 2001 By Peter Barratt
      //                   Constructor for the Radio Button Object. The 
      //                   properties and the methods will be initialised.
      //                                                                      
      // Parameters      Mode   Type       Description                        
      // -----------------------------------------------------------------    
      //                                                                      
      // -----------------------------------------------------------------

      function radioButtonObj()
      {
         // Properties
         this.refName   = UNDEFINED;
         this.document  = UNDEFINED;
         this.form      = UNDEFINED;
         this.title     = UNDEFINED;
         this.selected  = 0;
         this.btnList   = new Array();
         this.font      = UNDEFINED;
         this.separator = UNDEFINED;
    
         // Methods
         this.setObjectName   = _setObjectReferenceName;
         this.setDocumentName = _setObjectDocumentName;
         this.setFormName     = _setObjectFormName;
         this.setTitle        = _setObjectTitleString;
         this.setFont         = _setRadioButtonFont;
         this.setSeparator    = _setRadioButtonSeparator;
         this.getValue        = _getRadioButtonValue;
         this.addButton       = _addRadioButton;
         this.write           = _writeRadioButtonObject;
         this.exec            = _execRadioButtonClick;
      }


      // -----------------------------------------------------------------    
      // Function:  _radioButtonObjectData
      //                                                                      
      // Ver  Date         Description                                        
      // -----------------------------------------------------------------    
      // 1.0  Jan 15, 2001 By Peter Barratt
      //                   Constructor for an option in the Radio Button object
      //                                                                      
      // Parameters      Mode   Type       Description                        
      // -----------------------------------------------------------------    
      // value           Input  String     The value of the option. This value
      //                                   will be submitted when the form
      //                                   submits the data.
      // label           Input  String     The label to be shown with the
      //                                   current option.
      // command         Input  String     The command to be executed when
      //                                   the option is clicked.
      // toolTip         Input  String     Tooltip to be shown when the mouse
      //                                   is over the option. 
      //                                                                      
      // -----------------------------------------------------------------

      function _radioButtonObjectData(value,label,command,toolTip)
      {
         this.value   = value;
         this.label   = label;
         this.command = command;
         this.toolTip = toolTip;
      }


      // -----------------------------------------------------------------    
      // Function:  _setRadioButtonFont
      //                                                                      
      // Ver  Date         Description                                        
      // -----------------------------------------------------------------    
      // 1.0  Jan 15, 2001 By Calvin Lo
      //                   Set the font of the labels in Radio Button object
      //                                                                      
      // Parameters      Mode   Type       Description                        
      // -----------------------------------------------------------------    
      // font            Input  String     Font Name
      //                                                                      
      // -----------------------------------------------------------------

      function _setRadioButtonFont(font)
      {
         this.font = font;
      }


      // -----------------------------------------------------------------    
      // Function:  _setRadioButtonSeparator
      //                                                                      
      // Ver  Date         Description                                        
      // -----------------------------------------------------------------    
      // 1.0  Jan 15, 2001 By Calvin Lo                                       
      //                   Set the separator for the options in the Radio
      //                   Button object
      //                                                                      
      // Parameters      Mode   Type       Description                        
      // -----------------------------------------------------------------    
      // separator       Input  String     Separator in HTML format
      //                                                                      
      // -----------------------------------------------------------------

      function _setRadioButtonSeparator(separator)
      {
         this.separator = separator;
      }


      // -----------------------------------------------------------------    
      // Function:  _getRadioButtonValue
      //                                                                      
      // Ver  Date         Description                                        
      // -----------------------------------------------------------------    
      // 1.0  Jan 15, 2001 By Peter Barratt
      //                   Get the value of the selection of the Radio Button 
      //                   object
      //                                                                      
      // Parameters      Mode   Type       Description                        
      // -----------------------------------------------------------------    
      //
      // Return:                String     Value of the selection
      //                                                                      
      // -----------------------------------------------------------------

      function  _getRadioButtonValue()
      {
         var i;
         var value  = null;

         for ( i=0; i<this.btnList.length; i++ )
         {
            if (i==this.selected)
            { 
               value = this.btnList[i].value;
               break;
            }
         }
         return value;
      }


      // -----------------------------------------------------------------    
      // Function:  _addRadioButton
      //                                                                      
      // Ver  Date         Description                                        
      // -----------------------------------------------------------------    
      // 1.0  Jan 15, 2001 By Peter Barratt
      //                   Add an option to the Radio Button object
      //                                                                      
      // Parameters      Mode   Type       Description                        
      // -----------------------------------------------------------------    
      // value           Input  String     The value of the option. This value
      //                                   will be submitted when the form
      //                                   submits the data.
      // label           Input  String     The label to be shown with the
      //                                   current option.
      // command         Input  String     The command to be executed when
      //                                   the option is clicked.
      // toolTip         Input  String     Tooltip to be shown when the mouse
      //                                   is over the option. 
      //                                                                      
      // -----------------------------------------------------------------

      function _addRadioButton(value,label,command,toolTip)
      {
         var i = this.btnList.length;

         this.btnList[i] = new _radioButtonObjectData(value,
                                                      label,command,toolTip);
      }


      // -----------------------------------------------------------------    
      // Function:  _writeRadioButtonObject
      //                                                                      
      // Ver  Date         Description                                        
      // -----------------------------------------------------------------    
      // 1.0  Jan 15, 2001 By Peter Barratt
      //                   Display the Radio Button object in HTML format
      //                                                                      
      // Parameters      Mode   Type       Description                        
      // -----------------------------------------------------------------    
      //                                                                      
      // Return:                String     The HTML string for Radio Button
      //
      // -----------------------------------------------------------------

      function _writeRadioButtonObject()
      {
         var i = 0;
         var content = "";

         if ( this.title != UNDEFINED )
         {
            content += "<font class='Bold'>" + this.title + "</font>";
            content += "<br>";
         }
         content += "<font class='" + this.font + "'>";

         for ( i=0; i<this.btnList.length; i++ )
         {
            if (i==this.selected)
            { 
               content += "<input type='radio' name='" + this.refName
                       +  "' value='" + this.btnList[i].value
                       +  "' title='" + this.btnList[i].toolTip
                       +  "' onClick=parent." + this.refName + ".exec() "
                       +  "CHECKED>" + this.btnList[i].label;
            }
            else
            {
               content += "<input type='radio' name='" + this.refName
                       +  "' value='" + this.btnList[i].value
                       +  "' title='" + this.btnList[i].toolTip
                       +  "' onClick=parent." + this.refName + ".exec() "
                       +  ">" + this.btnList[i].label;
            }
            content += this.separator;
         }
         content += "</font>";

         return content;
      }


      // -----------------------------------------------------------------    
      // Function:  _execRadioButtonClick
      //                                                                      
      // Ver  Date         Description                                        
      // -----------------------------------------------------------------    
      // 1.0  Jan 15, 2001 By Peter Barratt
      //                   Execute the command of the selected option of
      //                   the Radio Button object
      //                                                                      
      // Parameters      Mode   Type       Description                        
      // -----------------------------------------------------------------    
      //                                                                      
      // -----------------------------------------------------------------

      function _execRadioButtonClick()
      {
         var i;
         var command = null;
         var objRef  = eval(this.document + "." + this.form 
                          + "." + this.refName);

         for ( i=0; i<objRef.length; i++ )
         {
            if ( objRef[i].checked )
            {
              this.selected = i;
              command = this.btnList[i].command;
              break;
            }
         }
         eval(command);
      }



      // =============================
      // -- Table Display Component --
      // =============================
      // TODO
      //  - implement H or V formatting control
      //  - automate column number from num args passed in
      //  - range check column -vs- data elements
      //  - pad missing rowValues with ""
      //  - validate data before write
      //  - add clear() method
      // =============================

      // -----------------------------------------------------------------    
      // Function:  tableDisplayObj
      //                                                                      
      // Ver  Date         Description                                        
      // -----------------------------------------------------------------    
      // 1.0  Jan 15, 2001 By Peter Barratt
      //                   Constructor of the Table Display object. The
      //                   properties and the methods are initialised here.
      // 1.1  Feb 12, 2001 By Calvin Lo
      //                   Add the properties font and fontSize, and the 
      //                   functions setFont() and setFontSize().
      //                                                                      
      // Parameters      Mode   Type       Description                        
      // -----------------------------------------------------------------    
      //                                                                      
      // -----------------------------------------------------------------

      function tableDisplayObj()
      {
         // Properties
         this.refName     = UNDEFINED;
         this.document    = UNDEFINED;
         this.title       = UNDEFINED;
         this.font        = UNDEFINED;
         this.colCount    = 0;            // Number of columns
         this.colHeader   = new Array();  // Array to store column headers
         this.rowCount    = 0;            // Number of rows
         this.rowValCount = 0;            // Number of cells
         this.rowValues   = new Array();  // Array to store the cells
         this.tableWidth  = 0;		  // Property added for 2005-SMRIS-enh6 - 09Dec05- Nivant

         // Methods
         this.setObjectName   = _setObjectReferenceName;
         this.setDocumentName = _setObjectDocumentName;
         this.setTitle        = _setObjectTitleString;
         this.setFont         = _setTableFont;
         this.setFontSize     = _setTableFontSize;
         this.setColumnCount  = _setTableColumnCount;
         this.setHeadingInfo  = _setTableHeadingInfo;
         this.getLength       = _getTableRowCount;
         this.addRow          = _addTableRow;
         this.write           = _writeTableDisplayObject;
// Method added for 2005-SMRIS-enh6 - 09Dec05- Nivant         
         this.setTableWidth   = _setTableWidth; 
      }


      // -----------------------------------------------------------------    
      // Function:  _setTableFont
      //                                                                      
      // Ver  Date         Description                                        
      // -----------------------------------------------------------------    
      // 1.0  Feb 12, 2001 By Calvin Lo
      //                   Set the font of the contents in the Table Display
      //                   Component
      //                                                                      
      // Parameters      Mode   Type       Description                        
      // -----------------------------------------------------------------    
      // font            Input  String     Font Name
      //                                                                      
      // -----------------------------------------------------------------

      function _setTableFont(font)
      {
         this.font = font;
      }


      // -----------------------------------------------------------------    
      // Function:  _setTableFontSize
      //                                                                      
      // Ver  Date         Description                                        
      // -----------------------------------------------------------------    
      // 1.0  Feb 12, 2001 By Calvin Lo
      //                   Set the font size of the contents in the Table 
      //                   Display Component
      //                                                                      
      // Parameters      Mode   Type       Description                        
      // -----------------------------------------------------------------    
      // fontSize        Input  Integer    Font Size
      //                                                                      
      // -----------------------------------------------------------------

      function _setTableFontSize(fontSize)
      {
         this.fontSize = fontSize;
      }


      // -----------------------------------------------------------------    
      // Function:  _addTableRow
      //                                                                      
      // Ver  Date         Description                                        
      // -----------------------------------------------------------------    
      // 1.0  Jan 15, 2001 By Peter Barratt
      //                   Add a row to the Table Display object
      //                                                                      
      // Parameters      Mode   Type       Description                        
      // -----------------------------------------------------------------    
      // .arguments      Input  Array      The values of the cells in the new
      //                                   row
      //                                                                      
      // -----------------------------------------------------------------

      function _addTableRow()
      {
         var numArgs = _addTableRow.arguments.length;
         var i;

         if ( numArgs >= 1 )
         {
            for ( i=0; i<numArgs; i++ )
            {
               this.rowValues[this.rowValCount] = _addTableRow.arguments[i];
               this.rowValCount++;
            }
            this.rowCount++;
         }
      }


      // -----------------------------------------------------------------    
      // Function:  _setTableHeadingInfo
      //                                                                      
      // Ver  Date         Description                                        
      // -----------------------------------------------------------------    
      // 1.0  Jan 15, 2001 By Peter Barratt
      //                   Set the column headers of the Table Display object
      //                                                                      
      // Parameters      Mode   Type       Description                        
      // -----------------------------------------------------------------    
      // .arguments      Input  Array      The values of the column headers 
      //                                                                      
      // -----------------------------------------------------------------

      function _setTableHeadingInfo()
      {
         var numArgs = _setTableHeadingInfo.arguments.length;
         var i;

         // Check num args against specified number of column.
         // Ensure that columns have precedence unless 0 and num args defined.
         if ( this.colCount == 0 ) this.colCount = numArgs;

         if ( numArgs >= 1 )
         {
            for ( i=0; i<numArgs; i++ )
            {
               this.colHeader[i] = _setTableHeadingInfo.arguments[i];
            }
         }
      }


      // -----------------------------------------------------------------    
      // Function:  _setTableColumnCount
      //                                                                      
      // Ver  Date         Description                                        
      // -----------------------------------------------------------------    
      // 1.0  Jan 15, 2001 By Peter Barratt
      //                   Set the number of columns of the table
      //                                                                      
      // Parameters      Mode   Type       Description                        
      // -----------------------------------------------------------------    
      // numColumns      Input  Integer    Number of Columns
      //                                                                      
      // -----------------------------------------------------------------

      function _setTableColumnCount(numColumns)
      {
         this.colCount = numColumns;
      }


      // -----------------------------------------------------------------    
      // Function:  _getTableRowCount
      //                                                                      
      // Ver  Date         Description                                        
      // -----------------------------------------------------------------    
      // 1.0  Jan 15, 2001 By Peter Barratt
      //                   Get the number of rows of the table
      //                                                                      
      // Parameters      Mode   Type       Description                        
      // -----------------------------------------------------------------    
      //                                                                      
      // Return:                Integer    Number of rows
      //
      // -----------------------------------------------------------------

      function  _getTableRowCount()
      {
         return this.rowCount;
      }
      
      // -----------------------------------------------------------------    
      // Function:  _setTableWidth
      //                                                                      
      // Ver  Date         Description                                        
      // -----------------------------------------------------------------    
      // 1.0  Dec 09, 2005 By Nivant Jariwala
      //                   Set table width based on screen resolution
      // Added for 2005-SMRIS-enh6
      // -----------------------------------------------------------------

      function  _setTableWidth(tableWidth)
      {
         this.tableWidth = tableWidth;
      }

      // -----------------------------------------------------------------    
      // Function:  _writeTableDisplayObject
      //                                                                      
      // Ver  Date         Description                                        
      // -----------------------------------------------------------------    
      // 1.0  Jan 15, 2001 By Peter Barratt
      //                   Display the Table Display object in HTML format
      // 1.1  Feb 12, 2001 By Calvin Lo
      //                   Use the predefined font instead of hardcoding the
      //                   font so that the HKSCS characters can be displayed.
      // 1.2  Mar 01, 2001 By Calvin Lo
      //                   Pass the document object so that even if the number
      //                   of rows is large, it will write the HTML for each
      //                   row instead of cumulating all the rows and returning
      //                   the result HTML once. This will prevent the browser
      //                   to hang for parsing the HTML output.
      //                                                                      
      // Parameters      Mode   Type       Description                        
      // -----------------------------------------------------------------    
      // documentObj     Input  Document   Document object where the parsed
      //                                   HTML will be written
      //
      // -----------------------------------------------------------------

      function _writeTableDisplayObject(documentObj)
      {
         var i;
         var j;
         var offset     = 0;
         var borderSize = 1;
         var frameRule  = "";
         var content    = "";
         var bgColor1;
         var bgColor2;

         if ( this.rowCount == 1 ) 
         {
            borderSize = 1;
            frameRule  = ' frame=box ';
         }

         if ( this.title != UNDEFINED );
         {
            content += "<b>" + this.title + "</b>";
            content += "<br>";
         }
// Following line modified to add var tableWidth for 2005-SMRIS-enh6 - 09-Dec-05 - Nivant
         content += "<table width=" + this.tableWidth + " cellspacing=0 cellpadding=4"
                 +  " border=" + borderSize + frameRule + "align=centre>";

         for ( i=0; i<this.rowCount; i++ )
         {
            bgColor1 = "#A1A1A1";
            bgColor2 = "#A1A1A1";

            offset = this.colCount * i;
            for ( j=0; j<this.colCount; j++ )
            {
            // Following work around is to hide maint_agent if it is not gov. dept as per user req. - 27-Oct-03 - Nivant
               if ( this.rowValues[offset+j] != "N/A" && this.rowValues[offset+j] != "¤£¾A¥Î" )
               {
               content += "<tr>";
               content += "<td width=25% bgcolor=" + bgColor1
                       +  " height=5 valign=top align=right>";
    
               // Modified in _writeTableDisplayObject Ver 1.1
               content += "<font face='" + this.font + "' size='" 
                       +  this.fontSize + "'>";

               content += this.colHeader[j];
               content += "</font>";
               content += "</td>";
               content += "<td width=75% bgcolor=" + bgColor2
                       +  " height=20 valign=top align=left>";

               // Modified in _writeTableDisplayObject Ver 1.1
               content += "<font face='" + this.font + "' size='" 
                       +  this.fontSize + "'>";

               content += this.rowValues[offset+j];
               content += "</font>";
               content += "</td>";
               content += "</tr>";
                
               documentObj.write(content);
               content = "";

               bgColor1 = "#E0E0E0";
               bgColor2 = "White";
               }
            }
         }

         content += "</table>";
         documentObj.write(content);
      }



      // ==============================
      // -- Selection List Component --
      // ==============================
      // TODO
      //  - validate data before write
      //  - add clear() method
      //  - add handling for multiple selections in getValue()
      //  - add capability to maintain state between refreshes
      //  - improve getSelected function to cope with isMultiple lists
      // ==============================

      // -----------------------------------------------------------------    
      // Function:  selectListObj
      //                                                                      
      // Ver  Date         Description                                        
      // -----------------------------------------------------------------    
      // 1.0  Jan 15, 2001 By Peter Barratt
      //                   Constructor of the Selection List object. The
      //                   properties and the methods will be initialised.
      // 1.1  Mar 08, 2001 By Calvin Lo
      //                   Add the method setFont() to set the font of the
      //                   items in the list
      //                                                                      
      // Parameters      Mode   Type       Description                        
      // -----------------------------------------------------------------    
      //                                                                      
      // -----------------------------------------------------------------

      function selectListObj()
      {
         // Properties
         this.refName    = UNDEFINED;
         this.document   = UNDEFINED;
         this.form       = UNDEFINED;
         this.title      = UNDEFINED;
         this.font       = UNDEFINED;
         this.isMultiple = false;
         this.size       = 1;
         this.itemList   = new Array();
         this.command    = UNDEFINED;
         this.selected   = 0;

         // Methods
         this.setObjectName   = _setObjectReferenceName;
         this.setDocumentName = _setObjectDocumentName;
         this.setFormName     = _setObjectFormName;
         this.setTitle        = _setObjectTitleString;
         this.setSize         = _setSelectListSize;
         this.setFont         = _setSelectListFont;
         this.setCommand      = _setSelectListCommand;
         this.getValue        = _getSelectListValue;
         this.getText         = _getSelectListText;
         this.getLength       = _getSelectListLength;
         this.getSelected     = _getSelectListChosenItems;
         this.getCommand      = _getSelectListCommand;
         this.addItem         = _addSelectListItem;
         this.write           = _writeSelectListObject;
         // for simplified chinese, following new methods are designed to use hyperlink instead of listbox in the result displaying page - Nivant
         this.writeHref       = _writeResultListHref;
         this.setClickedID    = _setClickedID;
         this.getClickedText  = _getClickedText;
         this.getClickedValue = _getClickedValue;
      }


      // -----------------------------------------------------------------    
      // Function:  _selectListObjectData
      //                                                                      
      // Ver  Date         Description                                        
      // -----------------------------------------------------------------    
      // 1.0  Jan 15, 2001 By Peter Barratt
      //                   A data structure for one option in the  
      //                   Selection List component
      //                                                                      
      // Parameters      Mode   Type       Description                        
      // -----------------------------------------------------------------    
      // value           Input  String     The value of the option. This value
      //                                   will be submitted when the form
      //                                   submits the data.
      // label           Input  String     The label to be shown with the
      //                                   current option.
      //                                                                      
      // -----------------------------------------------------------------

      function _selectListObjectData(value,label)
      {
         this.value = value;
         this.label = label;
      }


      // -----------------------------------------------------------------    
      // Function:  _setSelectListSize
      //                                                                      
      // Ver  Date         Description                                        
      // -----------------------------------------------------------------    
      // 1.0  Jan 15, 2001 By Peter Barratt
      //                   Set the size of the list
      //                                                                      
      // Parameters      Mode   Type       Description                        
      // -----------------------------------------------------------------    
      // value           Input  Integer    The size of the list
      //                                                                      
      // -----------------------------------------------------------------

      function _setSelectListSize(value)
      {
         if ( value > 0 ) this.size = value;
      }


      // -----------------------------------------------------------------    
      // Function:  _setSelectListFont
      //                                                                      
      // Ver  Date         Description                                        
      // -----------------------------------------------------------------    
      // 1.0  Mar 08, 2001 By Calvin Lo
      //                   Set the font of the items in the list
      //                                                                      
      // Parameters      Mode   Type       Description                        
      // -----------------------------------------------------------------    
      // font            Input  String     Font Name
      //                                                                      
      // -----------------------------------------------------------------

      function _setSelectListFont(font)
      {
         this.font = font;
      }


      // -----------------------------------------------------------------    
      // Function:  _setSelectListCommand 
      //                                                                      
      // Ver  Date         Description                                        
      // -----------------------------------------------------------------    
      // 1.0  Jan 15, 2001 By Calvin Lo
      //                   Set the command to be executed when an option
      //                   is selected in the Selection List object
      //                                                                      
      // Parameters      Mode   Type       Description                        
      // -----------------------------------------------------------------    
      // command         Input  String     Command to be executed
      //                                                                      
      // -----------------------------------------------------------------

      function _setSelectListCommand(command)
      {
         this.command = command;
      }


      // -----------------------------------------------------------------    
      // Function:  _getSelectListValue
      //                                                                      
      // Ver  Date         Description                                        
      // -----------------------------------------------------------------    
      // 1.0  Jan 15, 2001 By Peter Barratt
      //                   Get the value of the selected option in the list
      //                                                                      
      // Parameters      Mode   Type       Description                        
      // -----------------------------------------------------------------
      //
      // Return:                String     Value of the selected option
      //                                                                      
      // -----------------------------------------------------------------

      function _getSelectListValue()
      {
         var i;
         var value  = null;
         var objRef = eval(this.document + "." + this.form + "." 
                         + this.refName);

         for ( i=0; i<objRef.length; i++ )
         {
            if ( objRef.options[i].selected )
            {
               value = objRef.options[i].value;
               break;
            }
         }
         return value;
      }


      // -----------------------------------------------------------------    
      // Function:  _getSelectListText
      //                                                                      
      // Ver  Date         Description                                        
      // -----------------------------------------------------------------    
      // 1.0  Jan 15, 2001 By Calvin Lo
      //                   Get the text of the selected option in the list
      //                                                                      
      // Parameters      Mode   Type       Description                        
      // -----------------------------------------------------------------    
      //
      // Return:                String     Displayed text of the selected
      //                                   option
      //
      // -----------------------------------------------------------------

      function _getSelectListText()
      {
         var i;
         var value  = null;
         var objRef = eval(this.document + "." + this.form + "." 
                         + this.refName);

         for ( i=0; i<objRef.length; i++ )
         {
            if ( objRef.options[i].selected )
            {
               value = objRef.options[i].text;
               break;
            }
         }
         return value;
      }


      // -----------------------------------------------------------------    
      // Function:  _getSelectListLength
      //                                                                      
      // Ver  Date         Description                                        
      // -----------------------------------------------------------------    
      // 1.0  Jan 15, 2001 By Peter Barratt
      //                   Get the length of the list
      //                                                                      
      // Parameters      Mode   Type       Description                        
      // -----------------------------------------------------------------    
      //
      // Return:                Integer    Length of the list
      //
      // -----------------------------------------------------------------

      function _getSelectListLength()
      {
         return this.itemList.length;
      }


      //
      // TODO enhance to return multiple selected values.
      //

      // -----------------------------------------------------------------    
      // Function:  _getSelectListChosenItems
      //                                                                      
      // Ver  Date         Description                                        
      // -----------------------------------------------------------------    
      // 1.0  Jan 15, 2001 By Peter Barratt
      //                   Get the index of the selected option in the list.
      //                   The property selected will also be set.
      //                                                                      
      // Parameters      Mode   Type       Description                        
      // -----------------------------------------------------------------    
      // 
      // Return:                Integer    Index of the selected option. It is
      //                                   zero-based.
      //
      // -----------------------------------------------------------------

      function _getSelectListChosenItems()
      {
         var i;

         // Get the Select List Object. 
         // if the form object is not created yet, it means that
         // the page is not loaded completely and so return zero.
         var objRef = eval(this.document + "." + this.form + "." 
                         + this.refName);
         if ( objRef==null )
         {
            this.selected = 0;
            return 0;
         }

         for ( i=0; i<objRef.length; i++ )
         {
            if ( objRef.options[i].selected )
            {
               break;
            }
         }
         this.selected = i;
         return i;
      }


      // -----------------------------------------------------------------    
      // Function:  _getSelectListCommand
      //                                                                      
      // Ver  Date         Description                                        
      // -----------------------------------------------------------------    
      // 1.0  Jan 15, 2001 By Calvin Lo                                       
      //                   Get the command property of the list.
      //                                                                      
      // Parameters      Mode   Type       Description                        
      // -----------------------------------------------------------------    
      //
      // Return:                String     The command property
      //
      // -----------------------------------------------------------------

      function _getSelectListCommand()
      {
         return this.command;
      }


      // -----------------------------------------------------------------    
      // Function:  _addSelectListItem
      //                                                                      
      // Ver  Date         Description                                        
      // -----------------------------------------------------------------    
      // 1.0  Jan 15, 2001 By Peter Barratt
      //                   Add an option to the end of the list
      //                                                                      
      // Parameters      Mode   Type       Description                        
      // -----------------------------------------------------------------    
      // value           Input  String     The value of the option. This value
      //                                   will be submitted when the form
      //                                   submits the data.
      // label           Input  String     The label to be shown with the
      //                                   current option.
      //                                                                      
      // -----------------------------------------------------------------

      function _addSelectListItem(value,label)
      {
         var i = this.itemList.length;
         this.itemList[i] = new _selectListObjectData(value,label);
      }


      // -----------------------------------------------------------------    
      // Function:  _writeSelectListObject
      //                                                                      
      // Ver  Date         Description                                        
      // -----------------------------------------------------------------    
      // 1.0  Jan 15, 2001 By Peter Barratt
      //                   Display the Selection List object
      // 1.1  Mar 08, 2001 By Calvin Lo
      //                   Use the font given to display the items in the list
      // 1.2  Mar 14, 2001 By Calvin Lo
      //                   Use the font to display the items if it is already
      //                   defined
      //                                                                      
      // Parameters      Mode   Type       Description                        
      // -----------------------------------------------------------------    
      //                                                                      
      // Return:                String     HTML String for the list
      //
      // -----------------------------------------------------------------

      function _writeSelectListObject()
      {
         var i = 0;
         var selectedItems = this.selected;
         var commandStr    = "";
         var content       = "";

         if ( this.title != UNDEFINED )
         {
            content += "<font class='Normal'>" + this.title + "</font>";
            content += "&nbsp;&nbsp;";
         }

         if ( this.command != UNDEFINED )
         {
            commandStr = " onChange='" + this.command + "'";
         }
         else
         {
            commandStr = "";
         }

         if ( this.font != UNDEFINED )
         {
            content += "<span class='" + this.font + "'>";
         }
         content += "<select name='" + this.refName + "' size='" + this.size
                 +  "'";
         if ( this.font != UNDEFINED )
         {
            content += " class='" + this.font + "'";
         }
         content += commandStr +">";

         for ( i=0; i<this.itemList.length; i++ )
         {
            if ( i==selectedItems )
            {
               content += "<option value='" + this.itemList[i].value 
                       +  "' selected>" + this.itemList[i].label 
                       +  "</option>";
            }
            else
            {
               content += "<option value='" + this.itemList[i].value 
                       +  "'>" + this.itemList[i].label 
                       +  "</option>";
            }      
         }

         content += "</select>";
         if ( this.font != UNDEFINED )
         {
            content += "</span>";
         }

         return content;
      }


      // -----------------------------------------------------------------
      // Function:  _writeResultListHref
      //
      // Ver  Date         Description
      // -----------------------------------------------------------------    
      // 1.0  Feb 14, 2003 By Nivant Jariwala
      //                   Display the Selection List as hyperlink instead of Listbox
      //
      // Parameters      Mode   Type       Description
      // -----------------------------------------------------------------
      //
      // Return:                String     HTML String for the list
      //
      // -----------------------------------------------------------------

      function _writeResultListHref()
      {
         var i = 0;
         var content = "";
         var dispString;

         for ( i=0; i<this.itemList.length; i++ )
         {
            if ( parent.thruTrans == "SC" )
            {
             parent.imgSetting[0] = "blue";
             parent.imgSetting[1] = "14";
             parent.imgSetting[2] = "center";
             dispString = replaceHKSCS(parent.chrHKSCS, parent.imgHKSCS, parent.imgSetting, this.itemList[i].label);
            }
            else
            {
               dispString = this.itemList[i].label;
            }
            //content += "<a href='javascript:parent.setSearchID(" + '"' + this.itemList[i].label + '","' + this.itemList[i].value + '"' + ")'>" + dispString + "</a><br>";		
            content += "<a href='javascript:parent." + this.refName + ".setClickedID(" + i + ")'>" + dispString + "</a><br>";
         }
         return content;
      }


      // -----------------------------------------------------------------
      // Function:  _setClickedID
      //
      // Ver  Date         Description
      // -----------------------------------------------------------------
      // 1.0  Feb 14, 2003 By Nivant Jariwala
      //                   Display the Selection List as hyperlink instead of Listbox
      //
      // Parameters      Mode   Type       Description
      // -----------------------------------------------------------------
      //
      // Input:                String     HTML String for the list
      //
      // -----------------------------------------------------------------

      function _setClickedID(itemi)
      {
      this.selected = itemi;
      parent.searchDB();
      }


      // -----------------------------------------------------------------
      // Function:  _getClickedText
      //
      // Ver  Date         Description
      // -----------------------------------------------------------------
      // 1.0  Feb 14, 2003 By Nivant Jariwala
      //                   Display the Selection List as hyperlink instead of Listbox
      //
      // Parameters      Mode   Type       Description
      // -----------------------------------------------------------------
      //
      // Return:                String     Stored Text (Chinese Text) of hyperlink from array
      //
      // -----------------------------------------------------------------

      function _getClickedText()
      {
      var selIndex = this.selected;
      return this.itemList[selIndex].label;
      }


      // -----------------------------------------------------------------
      // Function:  _getClickedValue
      //
      // Ver  Date         Description
      // -----------------------------------------------------------------
      // 1.0  Feb 14, 2003 By Nivant Jariwala
      //                   Display the Selection List as hyperlink instead of Listbox
      //
      // Parameters      Mode   Type       Description
      // -----------------------------------------------------------------
      //
      // Input:                String     Stored value (Georef) of hyperlink from array
      //
      // -----------------------------------------------------------------

      function _getClickedValue()
      {
      var selIndex = this.selected;
      return this.itemList[selIndex].value;
      }
