//--------------------------------------------------------------------------
// $Log: smris_global.js,v $
// Revision 1.61  2004/04/29 04:06:44  iadmin
// *** empty log message ***
//
// Revision 1.60  2003/12/03 10:15:30  iadmin
// UAT30
//
// Revision 1.59  2003/12/03 09:57:53  iadmin
// Apply changes for implementation of Maintenance Agent
//
// Revision 1.57  2003/06/13 10:11:12  iadmin
// Final update after UAT of SC
//
// Revision 1.54  2003/06/03 11:52:21  iadmin
// UAT28
//
// Revision 1.53  2003/06/03 11:09:13  calvin
// Simplified Chinese enhanacement
//
// Revision 1.52  2002/08/30 11:54:41  iadmin
// UAT27
//
// Revision 1.51  2002/08/28 07:16:13  iadmin
// UAT26 promoted to PRD10
//
// Revision 1.50  2002/05/14 12:28:17  iadmin
// UAT25 promoted to PRD9
//
// Revision 1.49  2002/05/11 03:35:30  calvin
// Add the flag to determine whether the info box should be shown
//
// Revision 1.48  2002/03/25 13:41:45  iadmin
// UAT
//
// Revision 1.47  2002/03/20 16:59:41  iadmin
// UAT24
//
// Revision 1.46  2001/12/21 05:17:54  iadmin
// UAT23 promoted to PRD8
//
// Revision 1.45  2001/11/01 05:38:29  iadmin
// UAT22 promoted to PRD7
//
// Revision 1.44  2001/11/01 05:37:14  calvin
// Set the allowChinese to false for netscape
// major version > 4 and minor version > 77
//
// Revision 1.43  2001/10/26 04:44:47  calvin
// *** empty log message ***
//
// Revision 1.42  2001/10/09 10:07:44  iadmin
// UAT21 promoted to PRD6
//
// Revision 1.41  2001/08/24 10:06:00  iadmin
// UAT20 promoted to PRD5
//
// Revision 1.40  2001/08/22 10:46:03  iadmin
// UAT19
//
// Revision 1.39  2001/08/21 09:49:15  calvin
// Change the CED link
//
// Revision 1.38  2001/08/07 11:11:09  iadmin
// UAT18
//
// Revision 1.37  2001/08/07 10:41:06  calvin
// Only the base URL address of CED site is stated
//
// Revision 1.36  2001/08/07 08:46:58  calvin
// - Add the URL of the CED site
//
// Revision 1.35  2001/07/31 02:41:01  iadmin
// UAT17
//
// Revision 1.34  2001/05/02 11:08:45  iadmin
// UAT16 promoted to PRD4
//
// Revision 1.33  2001/04/27 12:25:14  iadmin
// UAT15
//
// Revision 1.32  2001/04/25 07:24:43  calvin
// The function setLanguage() is moved away from this file to smris.html
//
// Revision 1.31  2001/04/24 10:57:29  iadmin
// UAT14
//
// Revision 1.30  2001/03/29 11:17:42  iadmin
// UAT13 promoted to PRD3
//
// Revision 1.29  2001/03/27 13:56:40  iadmin
// UAT12
//
// Revision 1.28  2001/03/27 09:02:10  calvin
// - Check the input of plus and percentage signs for the validation functions
// - Convert more special symbols when data are passed to the PL/SQL
//
// Revision 1.27  2001/03/20 13:13:49  iadmin
// UAT11
//
// Revision 1.26  2001/03/15 11:17:15  iadmin
// UAT10
//
// Revision 1.25  2001/03/15 10:29:37  calvin
// Adjust the height and the top margin of the application window
//
// Revision 1.24  2001/03/15 03:16:43  calvin
// Use block comments instead of trailing comments to comment out the
// temporary window height and top margin. It is for compatibility with the
// build/migration script
//
// Revision 1.23  2001/03/14 13:00:54  calvin
// *** empty log message ***
//
// Revision 1.22  2001/03/13 12:46:49  iadmin
// UAT9
//
// Revision 1.21  2001/03/13 10:57:32  calvin
// *** empty log message ***
//
// Revision 1.20  2001/03/12 09:46:00  calvin
// Increase the height of the application window since more legend is added
//
// Revision 1.19  2001/03/08 12:48:58  iadmin
// UAT8
//
// Revision 1.18  2001/03/08 10:12:38  calvin
// UAT7
//
// Revision 1.17  2001/02/28 09:59:06  iadmin
// UAT6
//
// Revision 1.16  2001/02/27 10:19:44  calvin
// UAT5
//
// Revision 1.15  2001/02/14 09:29:38  calvin
// Add an variable to specify the time for timeout
//
// Revision 1.14  2001/02/09 04:32:49  calvin
// UAT4
//
// Revision 1.13  2001/02/08 09:16:30  calvin
// Add the function convertAnd() to handle the character '&' in the search
// criteria.
//
// Revision 1.12  2001/02/06 03:18:23  calvin
// temp check-in
//
// Revision 1.11  2001/02/03 13:03:49  calvin
// UAT3 uplift again - awk script becoming too complex.  The problem is
// solved in this file by including ALL http addresses in the DEV/UAT/PRD
// definitions.
//
// Revision 1.10  2001/02/03 12:51:37  calvin
// UAT3 upgrade to cater for changes in the awk (build script).
//
// Revision 1.9  2001/02/01 04:49:07  peter
// Lifted RCS symbol name up to use this version of the file as UAT3
//
// Revision 1.8  2001/02/01 04:22:00  peter
// Fixed error in build tag definition
//
// Revision 1.7  2001/01/31 10:22:21  peter
// Modified method of defining DEV, UAT and PRD environments to cater for
// the system build script.  This script performs 'awk' actions on this file
// dependent upon the chosen build target desired.
//
// Revision 1.6  2001/01/29 09:57:56  calvin
// *** empty log message ***
//
// Revision 1.5  2001/01/22 07:50:05  calvin
// UAT3
//
// Revision 1.4  2001/01/22 03:20:33  calvin
// The RCS log has been changed so that they will disappear after they
// are compressed.
//
// Revision 1.3  2001/01/15 12:24:25  calvin
// UAT2
//
// Revision 1.2  2001/01/12 06:57:32  calvin
// UAT1
//
// Revision 1.1  2001/01/11 11:05:57  calvin
// Initial revision
//
//--------------------------------------------------------------------------
//  DO NOT RENAME THIS FILE! - used by name in build script.
//--------------------------------------------------------------------------

//  IMPORTANT NOTE 
//  ==============
//  The DEV, UAT and PRD environments are all contained in this file.
//  It is currently a live file for DEV but UAT and PRD may be extracted 
//  from it using the build script.
//  Where variables are different for each environment then the line(s)        
//  are placed inside comments and prefixed with the environment name for the  
//  case of UAT and PRD definitions.                                           
//  However, due to the live nature of this file and how javascript interacts  
//  with HTML, particularly in regards to comments, the live definitions in    
//  the development environment must have a trailing comment of DEV.           
//                                                                             
//  It is essential that this convention is adhered to as these tags are used  
//  by the build script.  Please also ensure that any tags are in upper-case   
//  and have a hyphen in front of them,
//  
//  Note: be careful not to use any hyphenated tags accidentally anywhere
//        else in this file.  It could cause an incorrect build.
//                                                                             
//  see below for formatting....                                               
//-------Commented out for Developement   
// var urlLandsD   = "http://www.info.gov.hk/landsd/cover/index.htm";   // -DEV
// var urlIASMRIS  = "http://10.77.19.21:7777/dev/";                    // -DEV
// var urlMap      = "http://10.77.19.21:8080/smris/servlet/mapdata";   // -DEV
// var urlSearch   = "http://10.77.19.21:7777/pls/IASMRIS/pkg_iasmris_qry.qrySearch";   // -DEV
// var urlChinese  = "http://10.77.19.21:7777/pls/IASMRIS/pkg_chinese_qry.qrySearch";   // -DEV
// for simplified chinese, following lines are added being global variable - Cyrus
// var urlCED      = "hkss.ced.gov.hk/hkss/eng/slopeinfo/ie/dataresult/simar_data_list.asp?slope=";   // -DEV
// var urlCHCED    = "hkss.ced.gov.hk/hkss/chi/slopeinfo/ie/dataresult/c_simar_data_list.asp?slope=";   // -DEV
// var urlSCCED    = "sc_hkss.ced.gov.hk/gb/";   // -DEV
// var urlHKSCS    = "http://10.77.19.21:7777/pls/IASMRIS/pkg_iasmris_qry.qryHKSCS";    // -DEV
// var DomTranSvr  = "10.77.19.135:1980/gb/";   // -DEV
// var DomIASMRIS  = "10.77.19.21:7777/dev/";   // -DEV
// ------------------------------------------------------------------------

//---production environment-------------------------
    var urlLandsD   = "http://www.info.gov.hk/landsd/cover/index.htm";
    var urlIASMRIS  = "http://www.slope.landsd.gov.hk/smris/";
    var urlMap      = "http://www.slope.landsd.gov.hk/smris/map";
    var urlSearch   = "http://www.slope.landsd.gov.hk/smris/qry";
    var urlChinese  = "http://www.slope.landsd.gov.hk/smris/ch";
// CEDD urls modified for 2009-smris-017 - 01-sep-09 - Nivant
//    var urlCED      = "hkss.cedd.gov.hk/hkss/eng/slopeinfo/ie/dataresult/simar_data_list.asp?slope=";
//    var urlCHCED    = "hkss.cedd.gov.hk/hkss/chi/slopeinfo/ie/dataresult/c_simar_data_list.asp?slope=";
//    var urlSCCED    = "sc_hkss.cedd.gov.hk/gb/";
    var urlCED      = "hkss.cedd.gov.hk/hkss/eng/slopeinfo/disclaimer1.htm";
    var urlCHCED    = "hkss.cedd.gov.hk/hkss/chi/slopeinfo/disclaimer1.htm";
    var urlSCCED    = "sc_hkss.cedd.gov.hk/gb/";
    var urlHKSCS    = "http://www.slope.landsd.gov.hk/smris/hkscs";
    var DomTranSvr  = "www.slope.gb.landsd.gov.hk/gb/";
    var DomIASMRIS  = "www.slope.landsd.gov.hk/smris/";
//----------------------------------------------------------------------------


//---UAT environment--------------------------------
//  var urlLandsD   = "http://www.info.gov.hk/landsd/cover/index.htm";
//  var urlIASMRIS  = "http://10.77.19.21:7777/uat/";
//  var urlMap      = "http://10.77.19.21:8081/smris/servlet/mapdata";
//  var urlSearch   = "http://10.77.19.21:7777/pls/UAT/pkg_iasmris_qry.qrySearch";
//  var urlChinese  = "http://10.77.19.21:7777/pls/UAT/pkg_chinese_qry.qrySearch";
//  var urlCED      = "hkss.ced.gov.hk/hkss/eng/slopeinfo/ie/dataresult/simar_data_list.asp?slope=";
//  var urlCHCED    = "hkss.ced.gov.hk/hkss/chi/slopeinfo/ie/dataresult/c_simar_data_list.asp?slope=";
//  var urlSCCED    = "sc_hkss.ced.gov.hk/gb/";
//  var urlHKSCS    = "http://10.77.19.21:7777/pls/UAT/pkg_iasmris_qry.qryHKSCS";
//  var DomTranSvr  = "10.77.19.135:1980/gb/";
//  var DomIASMRIS  = "10.77.19.21:7777/uat/";
//----------------------------------------------------------------------------


//----------------------------------------------------------------------------
// 
//  Global Constants
// 
//  NOTE:  Do not use any trailing comments in this file.  This file is
//         processed by an awk script during the product build phase.
//         Comment lines and lines with trailing comments will be dropped
//         from the build!  
//
//         If you need to enter a url value (viz: http://....) you will need
//         to replicate it in the DEV, URL and PRD manner as above.  For an
//         example of this see urlLandsD above.
//
//         Be careful, you have been warned!!!
//----------------------------------------------------------------------------
var mailLandsD  = "slope_enquiry@landsd.gov.hk";
var bgImage     = "images/background.jpg";
var ldImage     = "images/landsD.jpg";
var mapFileExt  = ".jpg";
var topMargin   = 5;
var timeoutSec  = 300;
var metaStr     = "<meta http-equiv='Content-Type' content='text/html; "
                + "charset=big5'>"
                + "<meta http-equiv='Content-Language' content='zh-hk'>";
var showInfo    = false;
var infoWidth   = 480;
var infoHeight  = 300;
//  Global variables
var isEnglish    = true;
var isIE         = false;
var isNetscape   = false;
var isValidVer   = false;
var allowChinese = false;
// for simplified chinese, following lines are added to define the language and HKSCS character - Cyrus
var thruTrans    = "TC";
var chrHKSCS = new Array();
var imgHKSCS = new Array();
var imgSetting = new Array();

//---------------Following changes for 2005-SMRIS-enh6 - 28-Oct-06 - Nivant
// Following MapLevel variables modified/ added 
var mapLowResL1   = "images/maps/lowres/level1/mapL1-";
var mapLowResL2   = "images/maps/lowres/level2/mapL2-";
var mapHighResL1  = "images/maps/highres/level1/mapL1-";
var mapHighResL2  = "images/maps/highres/level2/mapL2-";
// Following two variables are now set in getResoultion() function                   
var winWidth    = 735; 
var winHeight   = 505;
// Following screen resolution flag and map variables added 
isLowRes	= false;
imgWidth	= 450;
imgHeight	= 360;
// Following two variables added for TableDisplayObject width
tblWidth1	= 250;
tblWidth2	= 325; 
// Following coordinate array value is now set in getResolution() function
var coordArray = new Array();

// Following function added 
function getResolution()
{
    if ((screen.width>=1024) && (screen.height>=768))
    {
 	isLowRes = false;
 	winWidth = 940;
 	winHeight = 645;
 	imgWidth = 575;
 	imgHeight = 465;
 	coordArray[0] = "0,0,144,115";    
	coordArray[1] = "144,0,288,115";  
	coordArray[2] = "288,0,432,115";  
	coordArray[3] = "432,0,576,115";  
	coordArray[4] = "0,115,144,230";  
	coordArray[5] = "144,115,288,230";
	coordArray[6] = "288,115,432,230";
	coordArray[7] = "432,115,576,230";
	coordArray[8] = "0,230,144,345";  
	coordArray[9] = "144,230,288,345";
	coordArray[10] = "288,230,432,345";
	coordArray[11] = "432,230,576,345";
	coordArray[12] = "0,345,144,460";  
	coordArray[13] = "144,345,288,460";
	coordArray[14] = "288,345,432,460";
	coordArray[15] = "432,345,576,460";
    }
    else
    {
  	isLowRes = true;
  	winWidth = 735;
 	winHeight = 505;
 	imgWidth = 450;
 	imgHeight = 360;
 	coordArray[0]  = "0,0,113,90";
	coordArray[1]  = "113,0,226,90";
	coordArray[2]  = "226,0,339,90";
	coordArray[3]  = "339,0,450,90";
	coordArray[4]  = "0,90,113,180";
	coordArray[5]  = "113,90,226,180";
	coordArray[6]  = "226,90,339,180";
	coordArray[7]  = "339,90,450,180";
	coordArray[8]  = "0,180,113,270";
	coordArray[9]  = "113,180,226,270";
	coordArray[10] = "226,180,339,270";
	coordArray[11] = "339,180,450,270";
	coordArray[12] = "0,270,113,360";
	coordArray[13] = "113,270,226,360";
	coordArray[14] = "226,270,339,360";
	coordArray[15] = "339,270,450,360";
    }
}
// -------------------------------------------------

//
//  Database transmission structures.                                     
//
function headerREC(version,type,date)                                    
{                                                                        
   this.protoVersion = version;                                          
   this.respType     = type;                                             
   this.respDate     = date;                                             
}                                                                        
                                                                               
// variable maintAgent is added for displaying maint agent - Cyrus
function ownerREC(slopeNo,subDivNo,location,respParty,maintAgent,remarks)
{                                                                        
   this.slopeNumber  = slopeNo;                                          
   this.subDivNumber = subDivNo;                                         
   this.location     = location;                                         
   this.respParty    = respParty;                                        
   this.maintAgent   = maintAgent;                                          
   this.remarks      = remarks;                                          
}                                                                        
// Following function modified for DAM enhancement - 21-Jun-07 - Nivant                                                                               
function techREC(slopeNo,conCat,E,N,toeFac,toeDist,crestFac,crestDist,                      
                 featureType,SFMaterial,SFHeight,SFLength,SFAngle,
                 WFMaterial,WFHeight,WFLength,structType)
{                                                                        
   this.slopeNumber   = slopeNo;     
   this.conseqCat     = conCat;      
   this.easting       = E;           
   this.northing      = N;           
   this.toeFacility   = toeFac;      
   this.toeDistance   = toeDist;     
   this.crestFacility = crestFac;    
   this.crestDistance = crestDist;   
   this.featureType   = featureType; 
   this.SFMaterial    = SFMaterial;    
   this.SFHeight      = SFHeight;      
   this.SFLength      = SFLength;      
   this.SFAngle       = SFAngle;       
   this.WFMaterial    = WFMaterial;
   this.WFHeight      = WFHeight;
   this.WFLength      = WFLength;
   this.structType    = structType;
}                                                        

//
//  Functions for Language Swapping
//
function getLanguage()            
{                                 
   var langCookie;                
   isEnglish = true;

   langCookie = getCookie('lang');
   if ( langCookie == 'CH' )      
   {                              
      isEnglish = false;          
   }                              
   else                           
   {                              
      isEnglish = true;           
   }                              
}                                 


//
//  Functions for Browser Information
//
function getBrowserInfo()                           
{                                                   
   var appNameStr;                                  
   var appVersionStr;
   var majorVerNum;
   var minorVerNum;                                 

   // Get the browser name and version              
   appNameStr    = navigator.appName;               
   appVersionStr = navigator.appVersion;            
                                                    
   // Detect the browser name                       
   if ( appNameStr.indexOf("Netscape") != -1 )      
   {                                                
      isNetscape = true;                            
   }                                                
   else if ( appNameStr.indexOf("Microsoft") != -1 )
   {                                                
      isIE = true;                                  
   }                                                
                                                    
   // Detect the browser version                    
   majorVerNum = appVersionStr.substr(0,1);
   if ( isIE )                                
   {                                                
      if ( majorVerNum >= 4 )
      {                                          
         isValidVer = true;                     
         allowChinese = true; 
      }                                          
   }
   else if ( isNetscape )                     
   {                                                
      if ( majorVerNum >= 5)
      {                                          
         isValidVer = true;
         allowChinese = true;
      }
      // for simplified chinese, followings are modified for checking compatibility of Netscape - Cyrus
      //if ( majorVerNum > 4 )
      //{
      //   isValidVer = true;
      //   allowChinese = true;
      //}
      //else if ( majorVerNum == 4)
      //{                                          
      //   minorVerNum = appVersionStr.substr(2,2);
      //   if ( minorVerNum >= 6 )                 
      //   {                                       
      //      isValidVer = true;
      //      if ( minorVerNum >= 77 )
      //        allowChinese = true;
      //   }                                       
      //}                                          
   }                                             
}


//
//  Utility Functions
//
// -----------------------------------------------------------------    
// Function:  isNumeric
//                                                                      
// Ver  Date         Description                                        
// -----------------------------------------------------------------    
// 1.0  Jan 15, 2001 By Calvin Lo                                       
//                   Check whether the input is numeric [0-9].
//                                                                      
// Parameters      Mode   Type       Description                        
// -----------------------------------------------------------------    
// input           Input  String     Input to be checked
//
// Return:                Boolean    True => Numeric
//                                                                      
// -----------------------------------------------------------------

function isNumeric(input)                          
{                                                  
   var i;                                          
   var length;                                     
   var singleChar;                                 
                                                   
   length = input.length;                          
   for (i=0; i<length; i++)                        
   {                                               
      singleChar = input.charAt(i);                
      if ( (singleChar>='0') && (singleChar<='9') )
      {                                            
         continue;                                 
      }                                            
      else                                         
      {                                            
         return false;                             
      }                                            
   }                                               
   return true;                                    
}                                                  
 

// -----------------------------------------------------------------    
// Function:  withSpecialChar
//                                                                      
// Ver  Date         Description                                        
// -----------------------------------------------------------------    
// 1.0  Jan 15, 2001 By Calvin Lo                                       
//                   Check whether the input contains any one of the
//                   following characters: hyphen [-], comma [,],
//                   slash [/] or single quote ['].
// 1.1  Mar 26, 2001 By Calvin Lo
//                   Add the checking for plus [+] and percentage [%] since
//                   the plus [+] sign will be passed as space and the 
//                   percentage will be interpretted wrongly by the SQL
//                   statement.
//                                                                      
// Parameters      Mode   Type       Description                        
// -----------------------------------------------------------------    
// input           Input  String     Input to be checked
//
// Return:                Boolean    True => with any one of the special
//                                           characters
//                                                                      
// -----------------------------------------------------------------

function withSpecialChar(input)
{
   var i;
   var length;
   var singleChar;

   length = input.length;
   for (i=0; i<length; i++)
   {
      singleChar = input.charAt(i);
      if ( (singleChar=="-") || (singleChar==",") ||
           (singleChar=="/") || (singleChar=="'") ||
           (singleChar=="+") || (singleChar=="%") ) 
      {
         return true;
      }
      else
      {
         continue;
      }
   }
   return false;
}


// -----------------------------------------------------------------    
// Function:  withSpecialChar2
//                                                                      
// Ver  Date         Description                                        
// -----------------------------------------------------------------    
// 1.0  Mar 26, 2001 By Calvin Lo                                       
//                   Check whether the input contains any one of the
//                   following characters: plus [+] or percentage [%].
//                                                                      
// Parameters      Mode   Type       Description                        
// -----------------------------------------------------------------    
// input           Input  String     Input to be checked
//
// Return:                Boolean    True => with any one of the special
//                                           characters
//                                                                      
// -----------------------------------------------------------------

function withSpecialChar2(input)
{
   var i;
   var length;
   var singleChar;

   length = input.length;
   for (i=0; i<length; i++)
   {
      singleChar = input.charAt(i);
      if ( (singleChar=="+") || (singleChar=="%") ) 
      {
         return true;
      }
      else
      {
         continue;
      }
   }
   return false;
}


// -----------------------------------------------------------------    
// Function:  trim
//                                                                      
// Ver  Date         Description                                        
// -----------------------------------------------------------------    
// 1.0  Jan 15, 2001 By Calvin Lo                                       
//                   Cut the leading and pending spaces
//                                                                      
// Parameters      Mode   Type       Description                        
// -----------------------------------------------------------------    
// input           Input  String     Input String to be trimmed
//
// Return:                String     Trimmed String
//                                                                      
// -----------------------------------------------------------------

function trim(input)
{
   var singleChar;
   var beginIndex;
   var endIndex;
   var length;

   if ( input=="" )
      return "";

   length = input.length;
   beginIndex = 0;
   singleChar = input.charAt(beginIndex);
   while ( singleChar==' ' )
   {
      beginIndex = beginIndex + 1;
      if ( beginIndex<length )
      {
         singleChar = input.charAt(beginIndex);
      }
      else
      {
         return "";
      }
   }

   endIndex   = input.length-1;
   singleChar = input.charAt(endIndex);
   while ( singleChar==' ' )
   {
      endIndex   = endIndex - 1;
      singleChar = input.charAt(endIndex);
   }

   return input.substr(beginIndex, endIndex-beginIndex+1);
}


// -----------------------------------------------------------------    
// Function:  prependZero
//                                                                      
// Ver  Date         Description                                        
// -----------------------------------------------------------------    
// 1.0  Jan 15, 2001 By Calvin Lo                                       
//                   Add a "0" to the beginning of the input if the
//                   input is single digit number [1-9]. For searching
//                   corresponding file in Map Search.
//                                                                      
// Parameters      Mode   Type       Description                        
// -----------------------------------------------------------------    
// number          Input  Integer    Input number to be converted
//
// Return:                String     Converted String
//                                                                      
// -----------------------------------------------------------------

function prependZero(number)
{
   if ( (number>=1) && (number<=9) )
   {
      return "0" + number;
   }
   else
   {
      return number;
   }
}


// -----------------------------------------------------------------    
// Function:  convertSpecial
//                                                                      
// Ver  Date         Description                                        
// -----------------------------------------------------------------    
// 1.0  Feb 07, 2001 By Calvin Lo                                       
//                   Convert the symbol "&" into ascii code in the input
//                   string.
// 1.1  Mar 26, 2001 By Calvin Lo
//                   This function has been renamed as "convertSpecial" since
//                   not only the symbol "&" will be converted. Now the symbols
//                   "&", "%", "+"  and "=" will be converted into ascii code.
//                                                                      
// Parameters      Mode   Type       Description                        
// -----------------------------------------------------------------    
// input           Input  String     Input to be converted
//
// Return:                String     Converted output string
//                                                                      
// -----------------------------------------------------------------

function convertSpecial(input)
{
   var i;
   var length;
   var singleChar;
   var output;

   length = input.length;
   output = "";
   for (i=0; i<length; i++)
   {
      singleChar = input.charAt(i);
      if ( ( singleChar == "&" ) || ( singleChar == "%" ) ||
           ( singleChar == "=" ) || ( singleChar == "+" ) )
      {
         output = output + escape(singleChar);
      }
      else
      {
         output = output + singleChar;
      }
   }
   return output;
}



//
//  Functions for Cookie Handling
//
function getCookie(asName)                                          
{                                                                   
   var lsSearch = asName + "=";                                     
   var liSearchLen = lsSearch.length;                               
   var liCookieLen = document.cookie.length;                        
   var liEndStr = 0;                                                
   var liI = 0;                                                     
                                                                    
   while (liI < liCookieLen)                                        
   {                                                                
      var j = liI + liSearchLen;                                    
      if (document.cookie.substring(liI, j) == lsSearch)            
      {                                                             
         liEndStr = document.cookie.indexOf (";", j);               
         if (liEndStr == -1) liEndStr = document.cookie.length;     
            return unescape(document.cookie.substring(j, liEndStr));
      }                                                             
                                                                    
      liI = document.cookie.indexOf(" ", liI) + 1;                  
      if (liI == 0) break;                                          
   }                                                                
   return '';                                                       
}                                                                   


function setCookie(asName, asValue)                     
{                                                       
   var ldExp = new Date();                              
   ldExp.setTime (ldExp.getTime() + 365*24*60*60*1000); 
   document.cookie = asName + "=" + escape (asValue) +  
      "; expires=" + ldExp.toGMTString() +              
      "; path=/"                                        
} 


// 
//  Time Related Functions
//
function getAMPM(inputDate)
{
   var hour;
   hour = inputDate.getHours();

   // The conversion for the hour will be like this:
   // hour from JavaScript :   0   1   ....   11  12  13  ....   23
   // hour to be displayed :   12  1   ....   11  12  1   ....   11
   // AM/PM to be displayed:   AM  AM  ....   AM  PM  PM  ....   PM 

   if ( hour <= 11 )
   {
      return "AM";
   }
   else
   {
      return "PM";
   }
}   


function getMinute(inputDate)
{
   var minute;
   minute = inputDate.getMinutes().toString();
   if ( minute.length == 1 )
   {
      minute = "0" + minute;
   }
   return minute;
}


function getHour(inputDate)
{
   var hour;
   hour = inputDate.getHours();

   if ( hour > 12 )
   {
      hour = hour - 12;
   }
   else if ( hour == 0 )
   {
      hour = 12;
   }

   if ( hour.toString().length == 1 )
   {
      hour = "0" + hour;
   }

   return hour;
}


function getDay(inputDate)
{
   var day;
   day = inputDate.getDate().toString();
   if ( day.length == 1 )
   {
      day = "0" + day;
   }
   return day;
} 


function getMonth(inputDate)
{
   var month;
   month = inputDate.getMonth()+1;
   if ( month.toString().length == 1 )
   {
      month = "0" + month;
   }
   return month;
}


function getYear(inputDate)
{
   if ( isIE )
   {
      return inputDate.getYear();
   }
   else if ( isNetscape )
   {
      return inputDate.getYear() + 1900;
   }
}


// for simplified chinese, following new functions are added - Cyrus
//
// HKSCS handle function, image would be used to replace the hkscs character in simplified chinese interface
//
function replaceHKSCS(chrHKSCS, imgHKSCS, imgSetting, inputString)
{
var i;
var iMax;
var j;
var jMax;
var tmpInputStr = new String(inputString);
var searchFlag;
var outputStr = "";

iMax = tmpInputStr.length;
jMax = chrHKSCS.length;

for ( i=0; i<=iMax; i++ )
 {
    searchFlag = false;
    for ( j=0; j<=jMax; j++)
    {
        if ( tmpInputStr.substr(i,1) == chrHKSCS[j] )
        {
            searchFlag = true;
            outputStr += "<img src='" + urlIASMRIS + "images/" + imgSetting[0] + "/" + imgHKSCS[j] + ".gif'";
            outputStr += "border=0 height=" + imgSetting[1] + " width=" + imgSetting[1] + " align=" + imgSetting[2] + ">";
            break;
        }
    }
    if ( searchFlag == false )
    {
       outputStr += tmpInputStr.substr(i,1);
    }
 }
return outputStr;
}


//
// language defineing function for disclaimer page
//
function setPath()
{
  var locString = new String();
  locString = location.pathname;

  setCookie('lang','CH');
  if ( locString.substr(1,2) == "gb" )
  {
    setCookie('translate','SC');
  }
  else
  {
    if ( locString.substr(locString.length - 22, 17) == "edisclaimer_frame" )
    {
      setCookie('lang','EN');
    }
    setCookie('translate','TC');
  }
}


//
// language defineing function for smris page
//
function setLangPath()
{
  var locString = new String();
  locString = parent.location.pathname;
  
  setCookie('lang','CH');
  if ( locString.substr(1,2) == "gb" )
  {
    setCookie('translate','SC');
  }
  else
  {
    if ( locString.substr(locString.length - 11, 6) == "esmris" )
    {
      setCookie('lang','EN');
    }
    setCookie('translate','TC');
  }
}
