var NetscapeVer = "";
var Netscape = "";
var BrowserLayer = "";
Netscape = navigator.appName == "Netscape";
if(Netscape) {NetscapeVer = parseInt(navigator.appVersion);}
//if(Netscape&&NetscapeVer == 4) {alert(NetscapeVer) }

var oSCPath = "";
var ImgPath;
var CSSPath;
var NodeArray = new Array()
var getServerName;

var locationPath = location.href.toString();
locationPath = locationPath.substring(locationPath.indexOf('://')+3);
if (locationPath.indexOf('/gb/') != -1)
	locationPath = locationPath.substring(locationPath.indexOf('/gb/')+4);
locationPath = locationPath.substring(0, locationPath.indexOf('/'));

getServerName = locationPath;

function LangSwitch(lang) {
	var langPath=location.href;
	var tmp = langPath.search('/gb/');

	if(langPath.search('jsp')!=-1){
		tmp = langPath.substring(tmp+4);
		tmp = 'ht'+'tp://'+tmp.substring(0, tmp.indexOf('/'))+lang;
		document.location=tmp;
	}else{
		if(lang.toLowerCase().search('langno=1')!=-1){
			tmp = 'ht'+'tp://'+langPath.substring(tmp+4);
			tmp = tmp.toLowerCase().replace('langno=2', 'langno=1');
		}else{
			tmp = 'ht'+'tp://'+langPath.substring(tmp+4);
		}

		document.location=tmp;
	}

/*
function LangSwitch( TCURL, SCURL ){
	alert(2);
	if(location.href.toString().search('/gb/') != -1){
		if (TCURL.search('/202.64.223.233/')!=-1)
		{
			TCURL = replaceSubstring(TCURL, '202.64.223.233/gb/', '')
		}
		document.location.href = TCURL;
	} else {

		document.location.href = SCURL;
	}
*/
}

function simg(obj,url)
{if (document.images){obj.src = url;}}

function SetImgPath(InImgPath){
	ImgPath = InImgPath;
}

function SetCSSPath(InCSSPath){
	CSSPath = InCSSPath;
}

function SetNodeArray(InNodeArray){
	NodeArray = InNodeArray;
}

function SetContentLayerFlag(Flag){
	contentLayerFlag = Flag;
}

function overTopMenu(obj)
{if (document.images){eval("document.images." + obj + ".src = '"+ ImgPath + "/" + obj + "_f2.gif'");}}

function outTopMenu(obj)
{if (document.images){eval("document.images." + obj + ".src = '"+ ImgPath + "/" + obj + ".gif'");}}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function checkBrowserLayer(formName){
	if (document.forms[formName])
	 { return document.forms[formName]; }
	else
	 { return document.content_layer.document.forms[formName]; }
}

function checkStyle() {
	if (navigator.appName != 'Netscape') {
		document.write("<LINK href='"+CSSPath+"/style.css' rel='stylesheet' type='text/css'>");
		//document.write("<LINK href='"+CSSPath+"/style_text.css' rel='stylesheet' type='text/css'>");
	} else {
		document.write("<LINK href='"+CSSPath+"/nt_style.css' rel='stylesheet' type='text/css'>");
		//document.write("<LINK href='"+CSSPath+"/nt_style_text.css' rel='stylesheet' type='text/css'>");
	}
}

function PopWin(url,page,x,y)
{
	eval("nw = window.open(url, page,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,pageXOffset=300,pageYOffset=500,top=80,left=150,width=" + x + ",height=" + y + "')");
	if ( nw.focus != null)
	{nw.focus();}
}

function PopWinResize(url,page,x,y)
{
	eval("nw = window.open(url, page,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,pageXOffset=300,pageYOffset=500,top=80,left=150,width=" + x + ",height=" + y + "')");
	if ( nw.focus != null)
	{nw.focus();}
}

function set_cookie (name, value) {
         var argv = set_cookie.arguments;
         var argc = set_cookie.arguments.length;
         var expires = (argc > 2) ? argv[2] : null;
         var path = (argc > 3) ? argv[3] : null;
         var domain = (argc > 4) ? argv[4] : null;
         var secure = (argc > 5) ? argv[5] : false;
         document.cookie = name + "=" + escape (value) +
         ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
         ((path == null) ? "" : ("; path=" + path)) +
         ((domain == null) ? "" : ("; domain=" + domain)) +
         ((secure == true) ? "; secure" : "");
}

function get_cookie(name) {
   var arg = name + "=";
   var alen = arg.length;
   var clen = document.cookie.length;
   var i = 0;
   while (i < clen) {
      var j = i + alen;
      if (document.cookie.substring(i, j) == arg) {
	offset=j;
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1) endstr = document.cookie.length;
	return unescape (document.cookie.substring(offset, endstr));
      }
      i = document.cookie.indexOf(" ", i) + 1;
      if (i == 0) break;
   }
   return null;
}

function del_cookie(name) {
	var expdate = new Date ();
	expdate.setTime (expdate.getTime()-1);
	set_cookie (name, "", expdate)
}

/*function LangSwitch( TCURL, SCURL ){
	if(location.href.toString().search('/gb/') != -1){
		document.location.href = TCURL;
	} else {
		if(get_cookie('InfoGovHK')!='visited'){
			set_cookie( 'Link', SCURL, null, "/");
			document.location.href  = '/tc/disclaimer.html?Location=' + SCURL;
		} else {
			document.location.href = SCURL;
		}
	}
}*/

function LangSwitchToSC( SCURL ){
	if(get_cookie('InfoGovHK')!='visited'){
		set_cookie( 'Link', SCURL, null, "/");
		document.location.href  = '/tc/disclaimer.html?Location=' + SCURL;
	} else {
		document.location.href = SCURL;
	}
}

function replaceSubstring(inputString, fromString, toString) {
   // Goes through the inputString and replaces every occurrence of fromString with toString
   var temp = inputString;
   if (fromString == "") {
      return inputString;
   }
   if (toString.indexOf(fromString) == -1) { // If the string being replaced is not a part of the replacement string (normal situation)
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } else { // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop
      var midStrings = new Array("~", "`", "_", "^", "#");
      var midStringLen = 1;
      var midString = "";
      // Find a string that doesn't exist in the inputString to be used
      // as an "inbetween" string
      while (midString == "") {
         for (var i=0; i < midStrings.length; i++) {
            var tempMidString = "";
            for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
            if (fromString.indexOf(tempMidString) == -1) {
               midString = tempMidString;
               i = midStrings.length + 1;
            }
         }
      } // Keep on going until we build an "inbetween" string that doesn't exist
      // Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + midString + toTheRight;
      }
      // Next, replace the "inbetween" string with the "toString"
      while (temp.indexOf(midString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(midString));
         var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } // Ends the check to see if the string being replaced is part of the replacement string or not
   return temp; // Send the updated string back to the user
} // Ends the "replaceSubstring" function


function preload_image() {

	if ( document.images ){

		var preload = new Array()
		preload[0] = "/bullet_high.jpg";
		preload[1] = "/bullet_L1.gif";
		preload[2] = "/bullet_n_L1.gif";
		preload[3] = "/bullet_n_L2.gif";
		preload[4] = "/bullet_n_L3.gif";
		preload[5] = "/bullet_L2.gif";
		preload[6] = "/bullet_L3.gif";
		for ( var i in NodeArray ){
			preload[7+i] = NodeArray[i];
		}


		for ( var i in preload ){
			var I = new Image();
			I.src = ImgPath + preload[i];
			preload[i] = I
		}

	}
}

//--------------------------------------------------------------------------------------------//
<!-- Begin -->
function emailCheck (emailStr) {
/* The following pattern is used to check if the entered e-mail address
   fits the user@domain format.  It also is used to separate the username
   from the domain. */
var emailPat=/^(.+)@(.+)$/
/* The following string represents the pattern for matching all special
   characters.  We don't want to allow special characters in the address.
   These characters include ( ) < > @ , ; : \ " . [ ]    */
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
/* The following string represents the range of characters allowed in a
   username or domainname.  It really states which chars aren't allowed. */
var validChars="\[^\\s" + specialChars + "\]"
/* The following pattern applies if the "user" is a quoted string (in
   which case, there are no rules about which characters are allowed
   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
   is a legal e-mail address. */
var quotedUser="(\"[^\"]*\")"
/* The following pattern applies for domains that are IP addresses,
   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
   e-mail address. NOTE: The square brackets are required. */
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
/* The following string represents an atom (basically a series of
   non-special characters.) */
var atom=validChars + '+'
/* The following string represents one word in the typical username.
   For example, in john.doe@somewhere.com, john and doe are words.
   Basically, a word is either an atom or quoted string. */
var word="(" + atom + "|" + quotedUser + ")"
// The following pattern describes the structure of the user
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
/* The following pattern describes the structure of a normal symbolic
   domain, as opposed to ipDomainPat, shown above. */
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")


/* Finally, let's start trying to figure out if the supplied address is
   valid. */

/* Begin with the coarse pattern to simply break up user@domain into
   different pieces that are easy to analyze. */
var matchArray=emailStr.match(emailPat)
if (matchArray==null) {
  /* Too many/few @'s or something; basically, this address doesn't
     even fit the general mould of a valid e-mail address. */
	alert("Email address seems incorrect (check @ and .)")
	return false
}
var user=matchArray[1]
var domain=matchArray[2]

// See if "user" is valid
if (user.match(userPat)==null) {
    // user is not valid
    alert("The username doesn't seem to be valid.")
    return false
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
   host name) make sure the IP address is valid. */
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
    // this is an IP address
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
	        alert("Destination IP address is invalid!")
		return false
	    }
    }
    return true
}

// Domain is symbolic name
var domainArray=domain.match(domainPat)
if (domainArray==null) {
	alert("The domain name doesn't seem to be valid.")
    return false
}

/* domain name seems valid, but now make sure that it ends in a
   three-letter word (like com, edu, gov) or a two-letter word,
   representing country (uk, nl), and that there's a hostname preceding
   the domain or country. */

/* Now we need to break up the domain to get a count of how many atoms
   it consists of. */
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 ||
    domArr[domArr.length-1].length>3) {
   // the address must end in a two letter or three letter word.
   alert("The address must end in a three-letter domain, or two letter country.")
   return false
}

// Make sure there's a host name preceding the domain.
if (len<2) {
   var errStr="This address is missing a hostname!"
   alert(errStr)
   return false
}

// If we've gotten this far, everything's valid!
return true;
}
//  End -->

// Trim function
function Trim(TRIM_VALUE){
if(TRIM_VALUE.length < 1){
return"";
}
TRIM_VALUE = RTrim(TRIM_VALUE);
TRIM_VALUE = LTrim(TRIM_VALUE);
if(TRIM_VALUE==""){
return "";
}
else{
return TRIM_VALUE;
}
} //End Function

function RTrim(VALUE){
var w_space = String.fromCharCode(32);
var v_length = VALUE.length;
var strTemp = "";
if(v_length < 0){
return"";
}
var iTemp = v_length -1;

while(iTemp > -1){
if(VALUE.charAt(iTemp) == w_space){
}
else{
strTemp = VALUE.substring(0,iTemp +1);
break;
}
iTemp = iTemp-1;

} //End While
return strTemp;

} //End Function

function LTrim(VALUE){
var w_space = String.fromCharCode(32);
if(v_length < 1){
return"";
}
var v_length = VALUE.length;
var strTemp = "";

var iTemp = 0;

while(iTemp < v_length){
if(VALUE.charAt(iTemp) == w_space){
}
else{
strTemp = VALUE.substring(iTemp,v_length);
break;
}
iTemp = iTemp + 1;
} //End While
return strTemp;
} //End Function

var iGotoTopNum = 0;

function goToTop(langID){
	if(!p){
		if (langID == 2) {
			document.writeln('<div align="right"><a href="#top" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage(\'btn_gototop' + iGotoTopNum + '\',\'\',\'/FileManager/TC/Common/btn_gototop_over.gif\',1)"><img src="/FileManager/TC/Common/btn_gototop.gif" border="0" vspace="3" name="btn_gototop' + iGotoTopNum + '"></a></div>');
		}else {
			document.writeln('<div align="right"><a href="#top" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage(\'btn_gototop' + iGotoTopNum + '\',\'\',\'/FileManager/EN/Common/btn_gototop_over.gif\',1)"><img src="/FileManager/EN/Common/btn_gototop.gif" border="0" vspace="3" name="btn_gototop' + iGotoTopNum + '"></a></div>');
		}
		iGotoTopNum++;
	}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function openSVG(charsetID)
{
	var folder;
	var isSC = "";
	if (!charsetID) charsetID = 1;

	if(location.href.toString().search('/gb/')!=-1)
		isSC = "&isSC=1";

	ua = navigator.userAgent;
	if (ua.indexOf("Netscape/7") != -1 || ua.indexOf("Netscape/8") != -1  || ua.indexOf("Firefox") != -1)
		folder = "/svgmap_ns7_8";
	else
		folder = "/svgmap";
	MM_openBrWindow('ht' + 'tp://' + getServerName + folder + '/frame.jsp?charsetID=' + charsetID + isSC, 'SVG_Map', 'width=900,height=565,resizable=0,scrollbars');
}

