﻿/* file: combine.js */

// global variables: 

// var for detect IE VERSION (for IE5.5 )
var userAgent="";
var ie_version=0;

// for Search Keyword Box 
var clear = 0;

// for Language Version change
var lang = 0; 
var lang_prefix = "";

var myhost = document.location.host;
var myhostname = document.location.hostname;

var sc_prefix = "sc.info.gov.hk/TuniS/";
var full_path_init = document.location.href;
var index = full_path_init.indexOf('#');
var full_path = (index > 0)? full_path_init.substring(0,index) : full_path_init;

var div_path,cv_sc_base_path,cv_nonsc_base_path;

// var for Font Size and Linear Version
var fontarray = new Array("Medium","Large","Extra");
var modeFormat = 'Format';
var modeLinear = 'Linear';
var myfonttitle = "";
var myscreenmode = "";
var displayfonttitle = "";


var currentMode = "";
// functions:

// IE 5.5 handling:
function GetIEVersion() {
	
	// 20070906: find ie_version when it is MSIE
	userAgent = navigator.userAgent;
	if (userAgent.indexOf('MSIE') != -1) {
		ie_version = parseFloat(userAgent.substring(userAgent.indexOf('MSIE')+4,userAgent.length));
	}
	// 20070914: not need to rewrite as "_getElementsByTagName"
}

// MM functions:
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_preloadimg() { //v3.0
  var d=document; if(d.img){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadimg.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  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 && d.getElementById) x=d.getElementById(n); return x;
}

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 MM_changeProp(objName,x,theProp,theValue) { //v6.0
  var obj = MM_findObj(objName);
  if (obj && (theProp.indexOf("style.")==-1 || obj.style)){
    if (theValue == true || theValue == false)
      eval("obj."+theProp+"="+theValue);
    else eval("obj."+theProp+"='"+theValue+"'");
  }
}

function MM_showHideLayers() { //v6.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 govhk_preloadimg() {
	// 20070914: even IE5.5 can preload Image on homepage (with meta no-cache)
	MM_preloadimg(
		'/img/btn_big5h.gif',
		'/img/btn_gbh.gif',
		'/img/btn_enh.gif',
		'/img/btn_searchh_tw.gif',
		'/img/btn_searchh_tw.gif',
		'/img/btn_search_sc_r.gif'   );
}

function setLangPath() {
	
	// sc - 2, tc - 1, en - 0 
	if (location.href.toString().search('/sc/') != -1) {
		lang = 2;
		lang_prefix = '/sc';
	} else if (location.href.toString().search('/tc/') != -1) {
		lang = 1;
		lang_prefix = '/tc';
	} else {
		lang = 0;
		lang_prefix = '/en';
	} 

	// make sc_path and non_sc_path	
	if (full_path.indexOf(sc_prefix) < 0) {
	  // EN,TC make SC and NON_SC
	  div_path = myhost + "/";
	  cv_sc_base_path = "http:" + "//" + sc_prefix + myhostname;
	  cv_nonsc_base_path = "http:" + "//" + myhost;
	} else {
	  // SC make SC and NON_SC
	  var pathA = full_path.substring(full_path.indexOf(sc_prefix) + sc_prefix.length);
	  div_path = pathA.substring(0,pathA.indexOf("/")+1);
	  cv_sc_base_path = "http:" + "//" + sc_prefix + div_path.substring(0,div_path.length - 1);
	  cv_nonsc_base_path = "http:" + "//" + div_path.substring(0,div_path.length - 1);
	}
}

function changeVer(lang) {
	sc_path  = "/sc/";
	chi_path = "/tc/";
	eng_path = "/en/";


	// reuse global variable full_path 
	org_path = full_path;
	org_path_start = org_path.indexOf(div_path) + div_path.length - 1;
	org_path = org_path.substring(org_path_start);

	// 20061003 : add for tc-homepage or en-homepage check 
	// IF   current page is tc-homepage or en-homepage and want to do sc translate 
    	// THEN go to disclaimer first                                
	if ((org_path == '/en/residents/' || org_path == '/tc/residents/') && lang =='s' )
	{
		window.location.href = '/scdisclaimer.htm' ; 	
	}
	else 
	{
		if (org_path.indexOf(chi_path) != -1) {
			org_lang_path = chi_path;
		}else{
			if (org_path.indexOf(sc_path) != -1) {
			org_lang_path = sc_path;
			}else {
			org_lang_path = eng_path;
			}
		}

		if (lang == 'e') {
			des_lang_path = eng_path;
		} else {
			if (lang == 't') {
			des_lang_path = chi_path;
			} else {
			des_lang_path = sc_path;
			}
		}
		
		base_path = cv_nonsc_base_path;
		tail = org_path.replace(org_lang_path, des_lang_path);
		window.location.href = base_path + tail;
	}
}


function displayEN() {
	document.writeln('<div class="topHolder"><a title="English" href="javascript:changeVer(\'e\');" onmouseout="MM_swapImgRestore()" onblur="MM_swapImgRestore()" onmouseover="MM_swapImage(\'btnEN\',\'\',\'/img/header/btn_enh.gif\',1)" onfocus="MM_swapImage(\'btnEN\',\'\',\'/img/header/btn_enh.gif\',1)"><img src="/img/header/btn_en.gif" alt="English" lang="en" name="btnEN" id="btnEN" width="40" height="19" /></a></div>');
}

function displayTC() {
	document.writeln('<div class="topHolder"><a title="繁體中文" href="javascript:changeVer(\'t\');" onmouseout="MM_swapImgRestore()" onblur="MM_swapImgRestore()" onmouseover="MM_swapImage(\'btnBIG5\',\'\',\'/img/header/btn_big5h.gif\',1)" onfocus="MM_swapImage(\'btnBIG5\',\'\',\'/img/header/btn_big5h.gif\',1)"><img src="/img/header/btn_big5.gif" alt="繁體中文" lang="zh" name="btnBIG5" id="btnBIG5" width="40" height="19" /></a></div>');
}

function displaySC() {
	document.writeln('<div class="topHolder"><a title="简体中文" href="javascript:changeVer(\'s\');" onmouseout="MM_swapImgRestore()" onblur="MM_swapImgRestore()" onmouseover="MM_swapImage(\'btnGB\',\'\',\'/img/header/btn_gbh.gif\',1)" onfocus="MM_swapImage(\'btnGB\',\'\',\'/img/header/btn_gbh.gif\',1)"><img src="/img/header/btn_gb.gif" alt="简体中文" lang="zh" name="btnGB" id="btnGB" width="40" height="19" /></a></div>');
}


function displayTwoLang() {
	// temp check for LL 20070723
	if (lang == 2) {
		displayEN();
		displayTC();
	} else if (lang == 1) {
		displayEN();
		displaySC();
	} else {
		displayTC();
		displaySC();
	}
}

// for search function

function isQuickQueryValid(thisForm){
	var alertMsg= [
		['Enter search keyword(s)', '輸入查詢字串', '输入查询字串'],
		['Please enter search keyword.', '請輸入查詢字串。', '请输入查询字串。']		
	];


	if((trim(thisForm.query.value)=='') || (thisForm.query.value == alertMsg[0][lang])){
		return false;
	}else{
		return true;
 	}
}


function validateBasicForm(){  
  var backForm = document.basic_search;
  /* avoid null query */
	var alertMsg= [
		['Enter search keyword(s)', '輸入查詢字串', '输入查询字串'],
		['Please enter search keyword.', '請輸入查詢字串。', '请输入查询字串。']	
	];

  if (!isQuickQueryValid(backForm)){ 
	  alert(alertMsg[1][lang]); 
	  return 0;
  }
  return 1;
}

function trimQuickForm(){
  var frontForm = document.adv_search;
  var lang_code;
  with (frontForm){
    lang_code = ui_lang.value;
  }
  
  var backForm = document.basic_search;
  with (backForm){
    ui_lang.value = lang_code;
    init_query.value = encodeURIComponent(query.value);
  }
}

function trim(str){ 
 return str.replace(/(^\s*)|(\s*$)/g, "");
}


// for search function
function ClearText()
{
	if (clear == 0)
	{
		document.getElementById("topNavSearchInput").value = "";		
		document.getElementById('topNavSearchInput').style.color="#000000";		
	}
	clear = 1;
}

// 20071012: function verifyKey put at onkeypress when onclick is used (refer sitemap)
// Modern browsers generates onclick event when pressing "Enter" key
// so this function is not required
// With onkeypress event, this verifies "Enter" key
function verifykey(oElement,oEvent) {
//	if (oEvent.keyCode==13 && oElement.onclick) {
//		oElement.onclick();
//	}
}

// different open window functions:
function openwindow(url,windowName) {
	if (windowName == undefined) {
		windowName = "_blank";
	}
	// 20080313: do not consider open by "filename" (openwindowapplication), because it may be many "index.htm"
	window.open(url,windowName);
	return false;
}

// for survey use - not use 200803
function openwindowlink(url,windowName) {
	if (windowName == undefined) {
		windowName = "_blank";
	}
	window.open(url,windowName,"width=800,height=600,copyhistory=no,scrollbars=yes,resizable=yes,screenX=0,screenY=0,left=0,top=0,hotkeys=no,status=yes");
	return false;
}

// for online demo - not use 200803
function openwindowdemo(url,windowName) {
	if (windowName == undefined) {
		windowName = "_blank";
	}
	var w = 640 ;
	var h = 480 ;
	window.open(url,windowName,"width="+w+",height="+h+",copyhistory=no,scrollbars=no,resizable=no,screenX=0,screenY=0,left=0,top=0,hotkeys=no,status=yes");
	return false;
}

// for application
function openwindowapplication(url,windowName) {
	if (windowName == undefined) {
		windowName = "_blank";
	}
	
	var translatedUrl = translateTcToSc(url);
	// height -70 is approx for window taskbar
	var newwin = window.open(translatedUrl, windowName, "width="+screen.width+",height="+(screen.height-70) +",top=0,left=0,directories=no,location=no,menubar=no,scrollbars=yes,status=yes,toolbar=no,resizable=yes");

	newwin.focus();	// set Focus to new window

	return false;
}

// for application, eg eTAX
function openwindow800x530(url,windowName) {
	if (windowName == undefined) {
		windowName = "_blank";
	}
	var translatedUrl = translateTcToSc(url);
	window.open(translatedUrl, windowName, 'width=800px,height=530px,top=0,left=0,directories=no,location=no,menubar=no,scrollbars=yes,status=yes,toolbar=no,resizable=yes');
	return false;
}

// translate url to SC version if necessary, handle /tc/apps to /sc/apps only
function translateTcToSc(url) {
	var trimUrl = TrimString(url);
	var testStr = trimUrl.toLowerCase();
	if ((lang == 2) && !(testStr.indexOf("http://")==0 || testStr.indexOf("https://")==0)) {
		// SC version, need to translate URL
		var newUrl;
		if (testStr.indexOf("/")==0) {
			if (testStr.indexOf("/tc/apps")==0) {
				newUrl = cv_nonsc_base_path + trimUrl.replace(/^\/tc\/apps/,"/sc/apps");
			} else {
				newUrl = cv_sc_base_path + trimUrl;
			}
		} else {
			// relative path, do nothing
			newUrl = trimUrl;
		}
		return newUrl;
	} else {
		return url;
	}
}

// Cookie Functions:
function createCookie(name,value,days) {
  if (days != null) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  var caLength = ca.length;
  for(var i=0;i < caLength;i++) {
    var c = TrimString(ca[i]);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

function TrimString(strIn) {
  return strIn.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}

function readAccessCookie() {
	// if FF or IE6+
	if (ie_version==0 || ie_version>=6) { 
		myfonttitle = readCookie("govhkfonttitle");
		if (myfonttitle==null) {myfonttitle=fontarray[0]; }
		
		myscreenmode = readCookie("govhkscreenmode");
		if (myscreenmode==null) {myscreenmode=modeFormat; } 
		
		// for clear old R2 cookie
		if (myfonttitle!=fontarray[0] && myfonttitle!=fontarray[1] && myfonttitle!=fontarray[2] ) 
		   { myfonttitle = fontarray[0]; }
		if (myscreenmode!=modeFormat && myscreenmode!=modeLinear) { myscreenmode = modeFormat; }
		
		displayfonttitle = myfonttitle;
	} else {
		// ie5.5 or down, provide Linear Version only
		myfonttitle = fontarray[2];
		myscreenmode = modeLinear;
		displayfonttitle = myfonttitle;
	}
}


function swapFontImage() {
	// display - swap on or off img
	var fontarrayLength = fontarray.length;
	for (i=0;i<fontarrayLength;i++)
	{
		if (displayfonttitle==fontarray[i] ) {
		  // seperate to 2 part, avoid change 'gif' to 'htm' when grab the website
		  fonttail = '_on.' + 'gif';
		} else {

		  fonttail = '_off.' + 'gif';
		}
		
		// fontimg:  "MediumFontImg", "LargeFontImg", "ExtraFontImg"
		// fontpath: "/img/fontsize/Medium_off.gif"
		
		fontimg = fontarray[i] + 'FontImg';	
		fontpath = '/img/fontsize/' + fontarray[i] + fonttail;
		MM_swapImage(fontimg,'',fontpath,1);
	}
}

function switchCss() {

  // CAUTION reminder 20070913: 
  // 1) IE7 need a.disabled=true first, no matter how (is this true?)
  // 2) firefox2.04 canNOT use: a.getAttribute("title").indexOf("linear"), else break for-loop
  // 3) firefox can use: var1=a.getAttribute("title"), then compare on var1

	var linkArray = document.getElementsByTagName("link");
	var linkArrayLength = linkArray.length;
	for(i=0; i<linkArrayLength; i++) 
	{
		a=linkArray[i];
		  
		// for all "stylesheet" in Link
		if (a.getAttribute("rel").indexOf("stylesheet")!=-1) 
		{
			var disable_flag = false;
			// if it is linear mode, assume all css disable first
			if (myscreenmode==modeLinear) { disable_flag=true; } 
			
			// get the id of css object first
			var id1 = a.getAttribute("id");
			if (id1 != null) {
				if (id1.indexOf("govhkPrint")!=-1 ) {
					// 20071203: CAUTION: no matter which version, print only show standard version.
					disable_flag = false;	
				} else if (id1.indexOf("govhkCss")!=-1 || id1.indexOf("iecss")!=-1  ) {
					// For "govhk.css", "ie.css"
					// handled by default
				} else if (id1.indexOf("access")!=-1) {
					// For "access.css"
					disable_flag = (myscreenmode!=modeLinear);
					//
				} else if (id1.indexOf("modeFormat")!=-1 && myscreenmode==modeFormat)  {
					// For "modeFormatMedium", "modeFormatLarge", "modeFormatExtra"
					// for normal mode, disable first; 
					// (for linear mode, already disable by above default)
					disable_flag = (id1.indexOf(displayfonttitle) < 0);
				} 

			} // end id1!=null
			
			// 20070917: finally set the enable or disable, set true first for IE7 bug
			a.disabled = true;
			a.disabled = disable_flag;
			

			// for IE5.5, disable can be set by a.disabled = true;
			// BUT for ENABLE, IE5.5 need to set the alt-stylesheet as "stylesheet"
			// CAUTION: do NOT set "alternate stylesheet" in this way, will hang IE5.5 browser
			if (ie_version>0 && ie_version<6 && disable_flag==false) {
				a.setAttribute("rel","stylesheet");									
			}
		} // end if rel stylesheet
	} // end for linkArray
}

function linearFontSize()
{
	var toggleMsg= [
		['Linear Version', '簡化格式', '简化格式'],
		['Standard Version', '標準格式', '标准格式']	
	];
  
	// call to swap Font Image (3A img)
	swapFontImage();

	// getElementById
	if( document.getElementById("pagePrefix") != null){
	var pp = document.getElementById("pagePrefix");		
	var tnr = document.getElementById("topNavRight");		
	// for ie5.5, hide the "Normal Version and 3A" - user must use Linear Version
	if (ie_version>0 && ie_version<6) {
		tnr.innerHTML="";
		pp.innerHTML="";
		MM_showHideLayers('topNavRight','','hide');
		MM_showHideLayers('pagePrefix','','hide');		
	} else {
		// ie6+ or firefox
		// handle by myscreenmode
		if (myscreenmode==modeFormat) {
			// myscreenmode==modeFormat; change A-title and A-HTML
			MM_changeProp('screenmodeLink','','title',toggleMsg[0][lang],'A');	
			MM_changeProp('screenmodeLink','','innerHTML',toggleMsg[0][lang],'A');	

			// if pagePrefix contain the HTML code, move to topNavRight
			// (put a "nbsp" to pagePrefix when necessary)
			// (and gt 10 means text is "Normal/Linear Version" code, not the "nbsp")
			temp = pp.innerHTML;
			if (temp.length > 10 ) 		{
				pp.innerHTML = "";
				tnr.innerHTML = temp;	
			}
			
		} else {
			// myscreenmode = modeLinear; change A-title and A-HTML
			MM_changeProp('screenmodeLink','','title',toggleMsg[1][lang],'A');	
			MM_changeProp('screenmodeLink','','innerHTML',toggleMsg[1][lang],'A');

			// if topNavRight contain the HTML code, move to pagePrefix
			temp = tnr.innerHTML;

			if (temp.length > 10 ) 		{
				tnr.innerHTML = "";
				pp.innerHTML = temp;
			}
			//	disableMenuSlide();
		} // end else myscreenmode
	}	// end else ie55
	}
  switchCss();
}

// changeFontTitle just handle global variable change, then call "linearFontSize"
function changeFontTitle(ft) {

	// change global variable "myfonttitle"
	myfonttitle = ft;
	
	// display font is same for Format Version
	displayfonttitle = myfonttitle;
	
	// immediately set fonttitle cookie to 2 months 
	createCookie("govhkfonttitle", myfonttitle, 60);
	
	// for 3+1, change Font mean change to "Format" mode also
	myscreenmode = modeFormat;
	createCookie("govhkscreenmode", myscreenmode, 60);
	// call linearFontSize to handle stylesheets
	linearFontSize();
}

// toggleLinearStyleSheet just handle global variable change, then call "linearFontSize"
function toggleLinearStyleSheet(linearflag) {

  // change 'toggle' to modeFormat or modeLinear
  if (linearflag=='toggle') 
  { 
	// change global variable 'myscreenmode'
    if (myscreenmode==modeFormat) {
	  myscreenmode = modeLinear;
	} else {
	  myscreenmode = modeFormat;
	}
  } else {
	  // what it pass from parameter
	  myscreenmode = linearflag;
  } 
  currentMode = myscreenmode;
  // immediately set screenmode cookie to 2 months
  createCookie("govhkscreenmode", myscreenmode, 60);
  
  // for 3+1 mode, set display font to "Largest" if it is Linear mode
  // here DONT affect "myfonttitle"
  if (myscreenmode==modeLinear) {
	  var displayfonttitle = fontarray[2];
  }
  
  // just call linearFontSize and let it handle
  linearFontSize();
  location.reload();
}

// remark: call "linearFontSize" only at page-onload

// 200804: copy dcsBind
// remark: cannot use on "load and unload" event
function govhkBind(event,func){

	//alert('govhkBind '+event+' '+func);
	
	if ((typeof(window[func])=="function")&&document.body){
		
		//alert('func and body');
		
		if (document.body.addEventListener){
			//alert('govhkbind - Mozilla');
			// Mozilla
			document.body.addEventListener(event, window[func], true);
		}
		else if(document.body.attachEvent){
			// IE
			//alert('govhkbind - IE');			
			document.body.attachEvent("on"+event, window[func]);
		}
		
	}
}

function govhkEvt(evt,tag){
	var e=evt.target||evt.srcElement;
	while (e.tagName&&(e.tagName!=tag)){
		e=e.parentElement||e.parentNode;
	}
	return e;
}

// move function anchorRel2() to dcs_tag.js

function anchorRel() { 

	if (document.getElementsByTagName) {
		var anchors = document.getElementsByTagName("a");
		var anchorsLength = anchors.length;
		for (var i=0; i<anchorsLength; i++) {
			
			var anch = anchors[i];
			
			if (anch.getAttribute("rel") )
			{
				// remark: anch.onkeypress, verifyKey is obsolete here
				
				// check for different "rel"
				var anchRel = anch.getAttribute("rel");
				switch ( anchRel ) {
					
					case "external" :
						anch.onclick=function() { return openwindow(this.href);	}
						break;
	
					case "application" :
						anch.onclick=function() { return openwindowapplication(this.href); }
						break;
	
					case "window800x530" :
						anch.onclick=function() { return openwindow800x530(this.href); }
						break;
				
					case "onlinedemo" :			
						anch.onclick=function() { return openwindowdemo(this.href);	}
						break;
				} // end switch
			} // end if href
		} // end for
    } // remark end if ByTag
}

/* 20070605: prevent loading of GovHK content in frames */
function breakOutOfFrame()
{
  if (self != top)
  {
    if (document.img)
      top.location.replace(window.location.href);
    else
      top.location.href = window.location.href;
  }
}

// 20071224: added
// Read a page's GET URL variables and return them as an associative array.
function getUrlVars()
{
    var vars = [], hash;
		var urltemp = window.location.href;
		var pos1 = urltemp.indexOf('?');
		var pos2 = urltemp.indexOf('#');
		var pos3 = urltemp.length;
		var posend = pos3;
		var strque = "";
		var stranc = "";

		//alert('pos1=' + pos1+'pos2='+pos2+'pos3 = ' + pos3);
		
		if (pos1 >= 0) {
			posend = pos2 > pos1 ? pos2 : pos3;
			strque = urltemp.substring(pos1+1,posend); 
		}
		
		if (pos2 >= 0) {
			posend = pos1 > pos2 ? pos1 : pos3;
			stranc = urltemp.substring(pos2+1,posend);
		}
		
		//alert('strque: '+strque + '      stranc:'+stranc);
		
		if (strque.length > 0 ) {
			var hashes = strque.split('&');
	
			for(var i = 0; i < hashes.length; i++)
			{
					hash = hashes[i].split('=');
					vars.push(hash[0]);
					vars[hash[0]] = hash[1];
			}
		}

		// push the 'anchor' to the vars as special element
		vars.push('anchor');
		vars['anchor'] = stranc ; 

		//alert("usergroup = " + vars['usergroup'] );
		//alert("cluster = " + vars['cluster'] );
		//alert("anchor = " + vars['anchor'] );
		//alert('vars length='+vars.length);

    return vars;
}


/*
	CAUTION: one html page canNOT have 2 onload functions (will count last one only).
	For "loadClusterExpand" (Online Service and Sitemap) 
	WorkAround: use try-catch block below
*/
function startList() {

	// readAccessCookie is already executed in beforeOnload
	// readAccessCookie();	

    // these functions can be call after page is render
	govhk_preloadimg();

	// 20070917: need to display appropriate image AFTER onload
	// else cannot Enlarge the Fonts even user select it before
	linearFontSize();

	// prevent loading GovHK in frames 
	breakOutOfFrame();
	
	// load for Cluster Expand (Online-Services-Residents, Sitemap) 
	//if (typeof(loadClusterExpand) == "function" && typeof(initExpand) == "function") {
	if (typeof(initExpand) == "function") {
		try { 
			initExpand();
			//loadClusterExpand(); 	// depend on initExpand()
		} catch (e) {}  
	}

	// handle anchor rel
	//anchorRel() - call anchor by dcs_tag now 

}

/*
	Do switchCss BEFORE page-onload
	Because if not do and user choose "Linear Version"
	Firefox may "Flash" for "normal version" first before show the Linear Version

	CAUTION: especially important for ie5.5, 
	force Linear Version before load all the page-objects (by calling switchCss function)
	can lower the heavy rendering time on CSS (else will hang ie5.5 browser)
*/
function beforeOnload() {
	GetIEVersion();					// (a) - depend on browser
	setLangPath();					// (b) - depend on URL
	readAccessCookie();				// (c) - depend on cookie, (a)
//	switchCss();					// (e) - depend on (a), (c)
	// (on HTML: displayTwoLang();  // (f) - depend on (b)
}


function ie6unload() {
  if (ie_version>=6 && ie_version<7) {
	  createCookie("govhkfonttitle", myfonttitle, 60);
	  createCookie("govhkscreenmode", myscreenmode, 60);
  }
}

function endList() {
	ie6unload();	
}
/*
  unload function here
  remark (1): do not create cookie when unload, 
              since tab-browsing or new-window do not call page-unload 
  remark (2): IE6 can NEW WINDOW with cookie when click "Linear Version"
              BUT the OWN window cannot have new cookie value.
			  so own window need to set cookie -- OnUnLoad --
*/

// really call onload and onunload
// page Load and Unload cannot use "govhkBind"
beforeOnload();
window.onload=startList;
window.onunload=endList;


