﻿/* 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;	// with port num when necessary
var myhostname = document.location.hostname;	// without port

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 = "";

// 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_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.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_preloadImages() {
	// 20070914: even IE5.5 can preload Image on homepage (with meta no-cache)
	MM_preloadImages(
		'/images/header/btn_big5h.gif',
		'/images/header/btn_gbh.gif',
		'/images/header/btn_enh.gif',
		'/en/images/header/btn_searchh.gif',
		'/tc/images/header/btn_searchh.gif',
		'/sc/images/header/btn_searchh.gif'   );
}

function setLangPath() {
	
	// sc - 2, tc - 1, en - 0 
	if (location.href.toString().search('/sc.info.gov.hk/') != -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) {

	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 {
			org_lang_path = eng_path;
		}

		if (lang == 'e') {
			des_lang_path = eng_path;
		} else {
			des_lang_path = chi_path;
		}
	
		if (lang == 's') {
			base_path = cv_sc_base_path;
		} else {
			base_path = cv_nonsc_base_path;
		}	

		tail = org_path.replace(org_lang_path, des_lang_path);
	
		window.location.href = base_path + tail;
	}
}

/* 200810:leave it as "div", chrome will drop down when use span */
function displayEN() {
	document.writeln('<div class="topHolder"><a title="English" href="javascript:changeVer(\'e\');" onmouseout="MM_swapImgRestore()" onblur="MM_swapImgRestore()" onmouseover="MM_swapImage(\'btnEN\',\'\',\'/images/header/btn_enh.gif\',1)" onfocus="MM_swapImage(\'btnEN\',\'\',\'/images/header/btn_enh.gif\',1)"><img src="/images/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\',\'\',\'/images/header/btn_big5h.gif\',1)" onfocus="MM_swapImage(\'btnBIG5\',\'\',\'/images/header/btn_big5h.gif\',1)"><img src="/images/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\',\'\',\'/images/header/btn_gbh.gif\',1)" onfocus="MM_swapImage(\'btnGB\',\'\',\'/images/header/btn_gbh.gif\',1)"><img src="/images/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 isQueryValid(thisForm){
  with(thisForm){
    if (!query.value || clear==0){
      return 0;
    }
  }
  return 1;
}

// for search function
function validateForm(){  

	var alertMsg= [
		['Please enter search keyword.', '請輸入查詢字串。', '请输入查询字串。'],
		['Please select a valid date.', '請選擇有效的日期。', '请选择有效的日期。']		
	];

  var flag = 1;
  var frontForm = document.basic_search;  
  
  /* avoid null query */
  if (!isQueryValid(frontForm)){ alert(alertMsg[0][lang]); flag = 0;}

  return flag;
}

// 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;
}

function openwindowgih(gihId,windowName) {
	if (windowName == undefined) {
		windowName = "_blank";
	}

	// gihUrl should be something relate to gihId, here is fake
	var gihUrl = '/en/images/gih/gih_demo_map_big.gif';

	openwindowapplication(gihUrl,windowName); 
	return false; // DONT do default action
}

// 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 images
	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: "/images/fontsize/Medium_off.gif"
		
		fontimg = fontarray[i] + 'FontImg';	
		fontpath = '/images/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; } 
			
			// 200808 get "href" instead of "id", coz all css should have "href"
			var href1 = a.getAttribute("href");
			
			if (href1.indexOf("govhkprint.css")!=-1 ) {
				// 20071203: CAUTION: no matter which version, print only show standard version.
				disable_flag = false;	
			} else if (href1.indexOf("govhk.css")!=-1 || href1.indexOf("ie.css")!=-1  ) {
				// For "govhk.css", "ie.css"
				// handled by default
			} else if (href1.indexOf("access.css")!=-1) {
				// For "access.css"
				disable_flag = (myscreenmode!=modeLinear);
			} else if (href1.indexOf("sheet/format")!=-1 && myscreenmode==modeFormat)  {
				// For "modeFormatMedium", "modeFormatLarge", "modeFormatExtra"
				// for normal mode, disable first; 
				// (for linear mode, already disable by above default)
				disable_flag = (href1.indexOf(displayfonttitle) < 0);
			} else if (href1.indexOf("gih.css")!=-1) {
				// if gih.css is attach (means in WIP), enable it no matter how
				disable_flag = false;
			} 
			
			// 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 images)
	swapFontImage();

	// getElementById
	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;
			}
			
		} // 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;
  } 
  
  // 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();
}

// remark: call "linearFontSize" only at page-onload

/* 20081029: Basic function for GIHS */
/* position of object */
function coorObject() {
  this.left = -1000;
  this.top = -1000;
  this.width = 10;
  this.height = 10;	
}

function findPos(objectId) {

	var obj = document.getElementById(objectId);
	var coor = new coorObject();

	/* get the width and height first, since the "obj" will change */
	coor.width = obj.offsetWidth;
	coor.height = obj.offsetHeight;
	
	/* left and top */
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
				curleft += obj.offsetLeft;
				curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
		
	}
	/* get the left and top */
	coor.left = curleft;
	coor.top = curtop;
	
	return coor;
}	

function movePos(objectId,coor) {
	
	//Move the image to the new location
	document.getElementById(objectId).style.top  = coor.top+'px';
	document.getElementById(objectId).style.left = coor.left+'px';

	// change only when input width or height >= 0, otherwise use default width or height
	if (coor.width >= 0 ) {
		document.getElementById(objectId).style.width = coor.width+'px';
	}	
	if (coor.height >= 0 ) {
		document.getElementById(objectId).style.height = coor.height+'px';	
	}

}

// GIHS function
var mapId = "map";	// css define in govhk.css

function addMapDiv() {
	// create the "searchAssist" Div and attache to 'pageAll'
	obj = document.createElement("div");
	obj.id = mapId;
	document.getElementById('pageAll').appendChild(obj);
	
	// if WIP
	if (myhost.indexOf("wip.")!=-1||myhost.indexOf("localhost")!=-1||myhost.indexOf("staging.")!=-1||myhost.indexOf("www0.")!=-1) {

		document.getElementById(mapId).style.display = "none"; // IE and FF default have not value
		//document.getElementById(mapId).className = "ignore";
	
		if(document.createStyleSheet) {
			// IE only
			document.createStyleSheet('/en/stylesheet/gih.css');

		} else {
			// FF only
			var newSS=document.createElement('link');
			// link cannot have ID here.
			newSS.rel='stylesheet';
			newSS.href='/en/stylesheet/gih.css';
			document.getElementById("access").appendChild(newSS);
			
		}
		
	}
}

function toggleMap(gihId) {

	var mapDisplay = document.getElementById(mapId).style.display;
	// mapDisplay can be "block", "none", (empty string or null - both FF and IE)
	if (mapDisplay == "block") {
		hideMap();
	} else {
		showMap('map'+gihId);
	}
}

function hideMap() {
	document.getElementById(mapId).style.display = "none";
}

function showMap(gihId) {
	
	// imgSrc should be generate from gihId, here hardcode/fake
	var imgSrc = '/en/images/gih/gih_demo_map_small.jpg';

	// put the HTML to div 'map'
	var maphtm,hidehtm,fullhtm;
	maphtm = '<a href="javascript:hideMap();">';
	maphtm += '<img src="'+imgSrc+'">';
	maphtm += '</a>';		

	hidehtm = '<p><a href="javascript:hideMap();">Hide Map</a></p>';

	// ico - icon coordinate
	var ico = new coorObject();
	ico = findPos(gihId);
	
	var paco = new coorObject();
	paco = findPos('pageAll');
	
	var mapco = new coorObject();
	// assume map is fixed
	mapco.width = 647;	// sample photo is 647x430
	mapco.height = 460;	// with "close" text
	var offset = 30;
	
	//mapco.left=ico.left-mapco.width	//  200808 for writesup pos
	mapco.left=ico.left		// 20081029 for support page

	
	if (ico.top+offset+mapco.height<paco.height) {
		// map under icon
		mapco.top = ico.top+offset;
		fullhtm = hidehtm + maphtm;
	} else {
		// map above icon
		mapco.top = ico.top-offset-mapco.height;
		fullhtm = maphtm + hidehtm ;
	}
	
	document.getElementById(mapId).innerHTML = fullhtm;
	document.getElementById(mapId).style.display = "block";
	//document.getElementById(mapId).className = "showblock";
	movePos(mapId,mapco);
	
} 




// 20080829 added
// remark: careful use on "load and unload" event
function govhkBind(event,func){
	
	if ((typeof(window[func])=="function")&&document.body){
		
		if (document.body.addEventListener){
			// Mozilla
			document.body.addEventListener(event, window[func], true);
		}
		else if(document.body.attachEvent){
			// IE
			document.body.attachEvent("on"+event, window[func]);
		}
		
	}
}

// 20080829 added
function govhkEvt(evt,tag){
	var e=evt.target||evt.srcElement;
	while (e.tagName&&(e.tagName!=tag)){
		e=e.parentElement||e.parentNode;
	}
	return e;
}

// 20080829 added
function govhkClick(evt) {

  // Note: ANY click action will go here, even click on page without element
  
	// filter "A" (Anchor) element
	var rtnAct=true;     // return action, default must be true, since it may not be "a" element
	var e=govhkEvt(evt,"A");  

	// Note: cannot check by "e" since it always exist (even not "a" element)
	// when it is "a" node and href is javascript:
	// e.href       :both FF and IE7 have value (error when it is not "a" node)
	// e.pathname   :FF have not value, IE7 have
	// e.hostname   :both FF and IE7 have NOT value 

	// So try-catch "rel" and "href" attribute
	// old: Save the Rel and Href In-The-Beginning, otherwise may not capture it back
	// Must try in seperate statement, since each attribute may not exist
  try {	govRel=e.getAttribute('rel');   } catch (e) {	govRel="";  }
  try { govHref=e.getAttribute('href'); } catch (e) {	govHref=""; }
  try { govId=e.getAttribute('id'); } catch (e) {	govId=""; }
  
  // on FF3, if anchor have not "rel", typeof(rel) is OBJECT, so assign it as empty STRING
  if (typeof(govRel)=="object") { govRel=""; }
  if (typeof(govId)=="object") { govId=""; }

// All possible GovHK Url type:
// 1) <a rel="external" href="http://www.external"  >    (external)
// 2) <a rel="map" href="map.jpg"  id="map123456" (GIH map - internal)
// 3) <a href="/en/residents/taxes/"..     (internal)
// 4) <a href="javascript:changeVer(t)"..  (simple javascript - internal )
// 5) <a href="javascript:void(0);" onClick="openwindowapplication('/en/apps/abc.htm'..  (app default - external)
// 6) <a href="javascript:void(0);" onClick="openwindow800x530('/en/apps/def.htm'..      (app by subject - external)
// Obsolete:
// <a rel="external" 
// <a rel="onlinedemo"

//  Remark: obsolete code
//  <a onkeypress="verifyKey()"
//  <a rel="application" 
//  <a rel="onlinedemo"
  
	switch ( govRel ) {
					
	case "external" :
		rtnAct = false;	// do not change current window	
		openwindow(govHref); // open new window
		break;

		/* 20081030: IE8B2 have bug - can force emuIE7 by meta header (X-UA) */
		/* keep this for GIHS production, currently not use, afraid crawl url by search engine */
		/*		
		case "map" :
			var gihId = govId;  // now govId means gihId
			var mapDisplay = document.getElementById(mapId).style.display;
			if (mapDisplay == "block") {
				hideMap();
			} else {
				showMap(gihId);
			}
			rtnAct = false;
			break;		
		*/
	default:
		// do nothing here, leave for browser default action
		break;
	} // end switch

    // Firefox preventDefault: when open new window, prevent current browse change
  	if (rtnAct==false && evt.preventDefault) {
  		evt.preventDefault(); 
  	}
	
	// For IE, return true means continue browser default action, return false stop browser action
	// For FF, no effect (continue browser default action), unless stop by evt.preventDefault
	return rtnAct;
}

/* 20070605: prevent loading of GovHK content in frames */
function breakOutOfFrame()
{
  if (self != top)
  {
    if (document.images)
      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 = "";
		
		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);
		}
		
		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 ; 

    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_preloadImages();

	// 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 - 20081029 - govhk itself (Not WebAnalysis)
	govhkBind('click','govhkClick');
	//anchorRel();

	// for GIHS
	addMapDiv();	

}

/*
	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;

/**
 * SWFObject v1.5: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
 *
 * SWFObject is (c) 2007 Geoff Stearns and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 */
if(typeof deconcept=="undefined"){var deconcept=new Object();}if(typeof deconcept.util=="undefined"){deconcept.util=new Object();}if(typeof deconcept.SWFObjectUtil=="undefined"){deconcept.SWFObjectUtil=new Object();}deconcept.SWFObject=function(_1,id,w,h,_5,c,_7,_8,_9,_a){if(!document.getElementById){return;}this.DETECT_KEY=_a?_a:"detectflash";this.skipDetect=deconcept.util.getRequestParameter(this.DETECT_KEY);this.params=new Object();this.variables=new Object();this.attributes=new Array();if(_1){this.setAttribute("swf",_1);}if(id){this.setAttribute("id",id);}if(w){this.setAttribute("width",w);}if(h){this.setAttribute("height",h);}if(_5){this.setAttribute("version",new deconcept.PlayerVersion(_5.toString().split(".")));}this.installedVer=deconcept.SWFObjectUtil.getPlayerVersion();if(!window.opera&&document.all&&this.installedVer.major>7){deconcept.SWFObject.doPrepUnload=true;}if(c){this.addParam("bgcolor",c);}var q=_7?_7:"high";this.addParam("quality",q);this.setAttribute("useExpressInstall",false);this.setAttribute("doExpressInstall",false);var _c=(_8)?_8:window.location;this.setAttribute("xiRedirectUrl",_c);this.setAttribute("redirectUrl","");if(_9){this.setAttribute("redirectUrl",_9);}};deconcept.SWFObject.prototype={useExpressInstall:function(_d){this.xiSWFPath=!_d?"expressinstall.swf":_d;this.setAttribute("useExpressInstall",true);},setAttribute:function(_e,_f){this.attributes[_e]=_f;},getAttribute:function(_10){return this.attributes[_10];},addParam:function(_11,_12){this.params[_11]=_12;},getParams:function(){return this.params;},addVariable:function(_13,_14){this.variables[_13]=_14;},getVariable:function(_15){return this.variables[_15];},getVariables:function(){return this.variables;},getVariablePairs:function(){var _16=new Array();var key;var _18=this.getVariables();for(key in _18){_16[_16.length]=key+"="+_18[key];}return _16;},getSWFHTML:function(){var _19="";if(navigator.plugins&&navigator.mimeTypes&&navigator.mimeTypes.length){if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","PlugIn");this.setAttribute("swf",this.xiSWFPath);}_19="<embed type=\"application/x-shockwave-flash\" src=\""+this.getAttribute("swf")+"\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\"";_19+=" id=\""+this.getAttribute("id")+"\" name=\""+this.getAttribute("id")+"\" ";var _1a=this.getParams();for(var key in _1a){_19+=[key]+"=\""+_1a[key]+"\" ";}var _1c=this.getVariablePairs().join("&");if(_1c.length>0){_19+="flashvars=\""+_1c+"\"";}_19+="/>";}else{if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","ActiveX");this.setAttribute("swf",this.xiSWFPath);}_19="<object id=\""+this.getAttribute("id")+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\">";_19+="<param name=\"movie\" value=\""+this.getAttribute("swf")+"\" />";var _1d=this.getParams();for(var key in _1d){_19+="<param name=\""+key+"\" value=\""+_1d[key]+"\" />";}var _1f=this.getVariablePairs().join("&");if(_1f.length>0){_19+="<param name=\"flashvars\" value=\""+_1f+"\" />";}_19+="</object>";}return _19;},write:function(_20){if(this.getAttribute("useExpressInstall")){var _21=new deconcept.PlayerVersion([6,0,65]);if(this.installedVer.versionIsValid(_21)&&!this.installedVer.versionIsValid(this.getAttribute("version"))){this.setAttribute("doExpressInstall",true);this.addVariable("MMredirectURL",escape(this.getAttribute("xiRedirectUrl")));document.title=document.title.slice(0,47)+" - Flash Player Installation";this.addVariable("MMdoctitle",document.title);}}if(this.skipDetect||this.getAttribute("doExpressInstall")||this.installedVer.versionIsValid(this.getAttribute("version"))){var n=(typeof _20=="string")?document.getElementById(_20):_20;n.innerHTML=this.getSWFHTML();return true;}else{if(this.getAttribute("redirectUrl")!=""){document.location.replace(this.getAttribute("redirectUrl"));}}return false;}};deconcept.SWFObjectUtil.getPlayerVersion=function(){var _23=new deconcept.PlayerVersion([0,0,0]);if(navigator.plugins&&navigator.mimeTypes.length){var x=navigator.plugins["Shockwave Flash"];if(x&&x.description){_23=new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/,"").replace(/(\s+r|\s+b[0-9]+)/,".").split("."));}}else{if(navigator.userAgent&&navigator.userAgent.indexOf("Windows CE")>=0){var axo=1;var _26=3;while(axo){try{_26++;axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+_26);_23=new deconcept.PlayerVersion([_26,0,0]);}catch(e){axo=null;}}}else{try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");}catch(e){try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");_23=new deconcept.PlayerVersion([6,0,21]);axo.AllowScriptAccess="always";}catch(e){if(_23.major==6){return _23;}}try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");}catch(e){}}if(axo!=null){_23=new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));}}}return _23;};deconcept.PlayerVersion=function(_29){this.major=_29[0]!=null?parseInt(_29[0]):0;this.minor=_29[1]!=null?parseInt(_29[1]):0;this.rev=_29[2]!=null?parseInt(_29[2]):0;};deconcept.PlayerVersion.prototype.versionIsValid=function(fv){if(this.major<fv.major){return false;}if(this.major>fv.major){return true;}if(this.minor<fv.minor){return false;}if(this.minor>fv.minor){return true;}if(this.rev<fv.rev){return false;}return true;};deconcept.util={getRequestParameter:function(_2b){var q=document.location.search||document.location.hash;if(_2b==null){return q;}if(q){var _2d=q.substring(1).split("&");for(var i=0;i<_2d.length;i++){if(_2d[i].substring(0,_2d[i].indexOf("="))==_2b){return _2d[i].substring((_2d[i].indexOf("=")+1));}}}return "";}};deconcept.SWFObjectUtil.cleanupSWFs=function(){var _2f=document.getElementsByTagName("OBJECT");for(var i=_2f.length-1;i>=0;i--){_2f[i].style.display="none";for(var x in _2f[i]){if(typeof _2f[i][x]=="function"){_2f[i][x]=function(){};}}}};if(deconcept.SWFObject.doPrepUnload){if(!deconcept.unloadSet){deconcept.SWFObjectUtil.prepUnload=function(){__flash_unloadHandler=function(){};__flash_savedUnloadHandler=function(){};window.attachEvent("onunload",deconcept.SWFObjectUtil.cleanupSWFs);};window.attachEvent("onbeforeunload",deconcept.SWFObjectUtil.prepUnload);deconcept.unloadSet=true;}}if(!document.getElementById&&document.all){document.getElementById=function(id){return document.all[id];};}var getQueryParamValue=deconcept.util.getRequestParameter;var FlashObject=deconcept.SWFObject;var SWFObject=deconcept.SWFObject;


/* SWFObject v2.1 <http://code.google.com/p/swfobject/>
	Copyright (c) 2007-2008 Geoff Stearns, Michael Williams, and Bobby van der Sluis
	This software is released under the MIT License <http://www.opensource.org/licenses/mit-license.php>
*/
var swfobject=function(){var b="undefined",Q="object",n="Shockwave Flash",p="ShockwaveFlash.ShockwaveFlash",P="application/x-shockwave-flash",m="SWFObjectExprInst",j=window,K=document,T=navigator,o=[],N=[],i=[],d=[],J,Z=null,M=null,l=null,e=false,A=false;var h=function(){var v=typeof K.getElementById!=b&&typeof K.getElementsByTagName!=b&&typeof K.createElement!=b,AC=[0,0,0],x=null;if(typeof T.plugins!=b&&typeof T.plugins[n]==Q){x=T.plugins[n].description;if(x&&!(typeof T.mimeTypes!=b&&T.mimeTypes[P]&&!T.mimeTypes[P].enabledPlugin)){x=x.replace(/^.*\s+(\S+\s+\S+$)/,"$1");AC[0]=parseInt(x.replace(/^(.*)\..*$/,"$1"),10);AC[1]=parseInt(x.replace(/^.*\.(.*)\s.*$/,"$1"),10);AC[2]=/r/.test(x)?parseInt(x.replace(/^.*r(.*)$/,"$1"),10):0}}else{if(typeof j.ActiveXObject!=b){var y=null,AB=false;try{y=new ActiveXObject(p+".7")}catch(t){try{y=new ActiveXObject(p+".6");AC=[6,0,21];y.AllowScriptAccess="always"}catch(t){if(AC[0]==6){AB=true}}if(!AB){try{y=new ActiveXObject(p)}catch(t){}}}if(!AB&&y){try{x=y.GetVariable("$version");if(x){x=x.split(" ")[1].split(",");AC=[parseInt(x[0],10),parseInt(x[1],10),parseInt(x[2],10)]}}catch(t){}}}}var AD=T.userAgent.toLowerCase(),r=T.platform.toLowerCase(),AA=/webkit/.test(AD)?parseFloat(AD.replace(/^.*webkit\/(\d+(\.\d+)?).*$/,"$1")):false,q=false,z=r?/win/.test(r):/win/.test(AD),w=r?/mac/.test(r):/mac/.test(AD);/*@cc_on q=true;@if(@_win32)z=true;@elif(@_mac)w=true;@end@*/return{w3cdom:v,pv:AC,webkit:AA,ie:q,win:z,mac:w}}();var L=function(){if(!h.w3cdom){return }f(H);if(h.ie&&h.win){try{K.write("<script id=__ie_ondomload defer=true src=//:><\/script>");J=C("__ie_ondomload");if(J){I(J,"onreadystatechange",S)}}catch(q){}}if(h.webkit&&typeof K.readyState!=b){Z=setInterval(function(){if(/loaded|complete/.test(K.readyState)){E()}},10)}if(typeof K.addEventListener!=b){K.addEventListener("DOMContentLoaded",E,null)}R(E)}();function S(){if(J.readyState=="complete"){J.parentNode.removeChild(J);E()}}function E(){if(e){return }if(h.ie&&h.win){var v=a("span");try{var u=K.getElementsByTagName("body")[0].appendChild(v);u.parentNode.removeChild(u)}catch(w){return }}e=true;if(Z){clearInterval(Z);Z=null}var q=o.length;for(var r=0;r<q;r++){o[r]()}}function f(q){if(e){q()}else{o[o.length]=q}}function R(r){if(typeof j.addEventListener!=b){j.addEventListener("load",r,false)}else{if(typeof K.addEventListener!=b){K.addEventListener("load",r,false)}else{if(typeof j.attachEvent!=b){I(j,"onload",r)}else{if(typeof j.onload=="function"){var q=j.onload;j.onload=function(){q();r()}}else{j.onload=r}}}}}function H(){var t=N.length;for(var q=0;q<t;q++){var u=N[q].id;if(h.pv[0]>0){var r=C(u);if(r){N[q].width=r.getAttribute("width")?r.getAttribute("width"):"0";N[q].height=r.getAttribute("height")?r.getAttribute("height"):"0";if(c(N[q].swfVersion)){if(h.webkit&&h.webkit<312){Y(r)}W(u,true)}else{if(N[q].expressInstall&&!A&&c("6.0.65")&&(h.win||h.mac)){k(N[q])}else{O(r)}}}}else{W(u,true)}}}function Y(t){var q=t.getElementsByTagName(Q)[0];if(q){var w=a("embed"),y=q.attributes;if(y){var v=y.length;for(var u=0;u<v;u++){if(y[u].nodeName=="DATA"){w.setAttribute("src",y[u].nodeValue)}else{w.setAttribute(y[u].nodeName,y[u].nodeValue)}}}var x=q.childNodes;if(x){var z=x.length;for(var r=0;r<z;r++){if(x[r].nodeType==1&&x[r].nodeName=="PARAM"){w.setAttribute(x[r].getAttribute("name"),x[r].getAttribute("value"))}}}t.parentNode.replaceChild(w,t)}}function k(w){A=true;var u=C(w.id);if(u){if(w.altContentId){var y=C(w.altContentId);if(y){M=y;l=w.altContentId}}else{M=G(u)}if(!(/%$/.test(w.width))&&parseInt(w.width,10)<310){w.width="310"}if(!(/%$/.test(w.height))&&parseInt(w.height,10)<137){w.height="137"}K.title=K.title.slice(0,47)+" - Flash Player Installation";var z=h.ie&&h.win?"ActiveX":"PlugIn",q=K.title,r="MMredirectURL="+j.location+"&MMplayerType="+z+"&MMdoctitle="+q,x=w.id;if(h.ie&&h.win&&u.readyState!=4){var t=a("div");x+="SWFObjectNew";t.setAttribute("id",x);u.parentNode.insertBefore(t,u);u.style.display="none";var v=function(){u.parentNode.removeChild(u)};I(j,"onload",v)}U({data:w.expressInstall,id:m,width:w.width,height:w.height},{flashvars:r},x)}}function O(t){if(h.ie&&h.win&&t.readyState!=4){var r=a("div");t.parentNode.insertBefore(r,t);r.parentNode.replaceChild(G(t),r);t.style.display="none";var q=function(){t.parentNode.removeChild(t)};I(j,"onload",q)}else{t.parentNode.replaceChild(G(t),t)}}function G(v){var u=a("div");if(h.win&&h.ie){u.innerHTML=v.innerHTML}else{var r=v.getElementsByTagName(Q)[0];if(r){var w=r.childNodes;if(w){var q=w.length;for(var t=0;t<q;t++){if(!(w[t].nodeType==1&&w[t].nodeName=="PARAM")&&!(w[t].nodeType==8)){u.appendChild(w[t].cloneNode(true))}}}}}return u}function U(AG,AE,t){var q,v=C(t);if(v){if(typeof AG.id==b){AG.id=t}if(h.ie&&h.win){var AF="";for(var AB in AG){if(AG[AB]!=Object.prototype[AB]){if(AB.toLowerCase()=="data"){AE.movie=AG[AB]}else{if(AB.toLowerCase()=="styleclass"){AF+=' class="'+AG[AB]+'"'}else{if(AB.toLowerCase()!="classid"){AF+=" "+AB+'="'+AG[AB]+'"'}}}}}var AD="";for(var AA in AE){if(AE[AA]!=Object.prototype[AA]){AD+='<param name="'+AA+'" value="'+AE[AA]+'" />'}}v.outerHTML='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'+AF+">"+AD+"</object>";i[i.length]=AG.id;q=C(AG.id)}else{if(h.webkit&&h.webkit<312){var AC=a("embed");AC.setAttribute("type",P);for(var z in AG){if(AG[z]!=Object.prototype[z]){if(z.toLowerCase()=="data"){AC.setAttribute("src",AG[z])}else{if(z.toLowerCase()=="styleclass"){AC.setAttribute("class",AG[z])}else{if(z.toLowerCase()!="classid"){AC.setAttribute(z,AG[z])}}}}}for(var y in AE){if(AE[y]!=Object.prototype[y]){if(y.toLowerCase()!="movie"){AC.setAttribute(y,AE[y])}}}v.parentNode.replaceChild(AC,v);q=AC}else{var u=a(Q);u.setAttribute("type",P);for(var x in AG){if(AG[x]!=Object.prototype[x]){if(x.toLowerCase()=="styleclass"){u.setAttribute("class",AG[x])}else{if(x.toLowerCase()!="classid"){u.setAttribute(x,AG[x])}}}}for(var w in AE){if(AE[w]!=Object.prototype[w]&&w.toLowerCase()!="movie"){F(u,w,AE[w])}}v.parentNode.replaceChild(u,v);q=u}}}return q}function F(t,q,r){var u=a("param");u.setAttribute("name",q);u.setAttribute("value",r);t.appendChild(u)}function X(r){var q=C(r);if(q&&(q.nodeName=="OBJECT"||q.nodeName=="EMBED")){if(h.ie&&h.win){if(q.readyState==4){B(r)}else{j.attachEvent("onload",function(){B(r)})}}else{q.parentNode.removeChild(q)}}}function B(t){var r=C(t);if(r){for(var q in r){if(typeof r[q]=="function"){r[q]=null}}r.parentNode.removeChild(r)}}function C(t){var q=null;try{q=K.getElementById(t)}catch(r){}return q}function a(q){return K.createElement(q)}function I(t,q,r){t.attachEvent(q,r);d[d.length]=[t,q,r]}function c(t){var r=h.pv,q=t.split(".");q[0]=parseInt(q[0],10);q[1]=parseInt(q[1],10)||0;q[2]=parseInt(q[2],10)||0;return(r[0]>q[0]||(r[0]==q[0]&&r[1]>q[1])||(r[0]==q[0]&&r[1]==q[1]&&r[2]>=q[2]))?true:false}function V(v,r){if(h.ie&&h.mac){return }var u=K.getElementsByTagName("head")[0],t=a("style");t.setAttribute("type","text/css");t.setAttribute("media","screen");if(!(h.ie&&h.win)&&typeof K.createTextNode!=b){t.appendChild(K.createTextNode(v+" {"+r+"}"))}u.appendChild(t);if(h.ie&&h.win&&typeof K.styleSheets!=b&&K.styleSheets.length>0){var q=K.styleSheets[K.styleSheets.length-1];if(typeof q.addRule==Q){q.addRule(v,r)}}}function W(t,q){var r=q?"visible":"hidden";if(e&&C(t)){C(t).style.visibility=r}else{V("#"+t,"visibility:"+r)}}function g(s){var r=/[\\\"<>\.;]/;var q=r.exec(s)!=null;return q?encodeURIComponent(s):s}var D=function(){if(h.ie&&h.win){window.attachEvent("onunload",function(){var w=d.length;for(var v=0;v<w;v++){d[v][0].detachEvent(d[v][1],d[v][2])}var t=i.length;for(var u=0;u<t;u++){X(i[u])}for(var r in h){h[r]=null}h=null;for(var q in swfobject){swfobject[q]=null}swfobject=null})}}();return{registerObject:function(u,q,t){if(!h.w3cdom||!u||!q){return }var r={};r.id=u;r.swfVersion=q;r.expressInstall=t?t:false;N[N.length]=r;W(u,false)},getObjectById:function(v){var q=null;if(h.w3cdom){var t=C(v);if(t){var u=t.getElementsByTagName(Q)[0];if(!u||(u&&typeof t.SetVariable!=b)){q=t}else{if(typeof u.SetVariable!=b){q=u}}}}return q},embedSWF:function(x,AE,AB,AD,q,w,r,z,AC){if(!h.w3cdom||!x||!AE||!AB||!AD||!q){return }AB+="";AD+="";if(c(q)){W(AE,false);var AA={};if(AC&&typeof AC===Q){for(var v in AC){if(AC[v]!=Object.prototype[v]){AA[v]=AC[v]}}}AA.data=x;AA.width=AB;AA.height=AD;var y={};if(z&&typeof z===Q){for(var u in z){if(z[u]!=Object.prototype[u]){y[u]=z[u]}}}if(r&&typeof r===Q){for(var t in r){if(r[t]!=Object.prototype[t]){if(typeof y.flashvars!=b){y.flashvars+="&"+t+"="+r[t]}else{y.flashvars=t+"="+r[t]}}}}f(function(){U(AA,y,AE);if(AA.id==AE){W(AE,true)}})}else{if(w&&!A&&c("6.0.65")&&(h.win||h.mac)){A=true;W(AE,false);f(function(){var AF={};AF.id=AF.altContentId=AE;AF.width=AB;AF.height=AD;AF.expressInstall=w;k(AF)})}}},getFlashPlayerVersion:function(){return{major:h.pv[0],minor:h.pv[1],release:h.pv[2]}},hasFlashPlayerVersion:c,createSWF:function(t,r,q){if(h.w3cdom){return U(t,r,q)}else{return undefined}},removeSWF:function(q){if(h.w3cdom){X(q)}},createCSS:function(r,q){if(h.w3cdom){V(r,q)}},addDomLoadEvent:f,addLoadEvent:R,getQueryParamValue:function(v){var u=K.location.search||K.location.hash;if(v==null){return g(u)}if(u){var t=u.substring(1).split("&");for(var r=0;r<t.length;r++){if(t[r].substring(0,t[r].indexOf("="))==v){return g(t[r].substring((t[r].indexOf("=")+1)))}}}return""},expressInstallCallback:function(){if(A&&M){var q=C(m);if(q){q.parentNode.replaceChild(M,q);if(l){W(l,true);if(h.ie&&h.win){M.style.display="block"}}M=null;l=null;A=false}}}}}();