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 1;
}

function del_cookie(name) {
	var expdate = new Date ();
	expdate.setTime (expdate.getTime()-1);
	set_cookie (name, "", expdate)
}

function getQueryVariable(variable) {
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	
	for (var i=0;i<vars.length;i++){
		var pair = vars[i].split("=");
		if (pair[0] == variable) {
			return pair[1];
		}
	} 
}

var q = getQueryVariable("s");

if (q == 1)
	set_cookie( 'InfoGovHK', '1', null, "/");
if (q == 2)
	set_cookie( 'InfoGovHK', '2', null, "/");

if(!(window.location.href.indexOf('?') != -1 )) { 
	document.cookie = "cookieName=cookiealue";
	var cookiesenable = document.cookie.indexOf("cookieName") ;

	if(cookiesenable== -1){
		str = document.URL.toString();
		str = str + "?s=1";
		document.location = str;
	}else {
		var favorite = get_cookie('InfoGovHK');
		str = document.URL.toString();
		str = str + "?s=" + favorite;
		document.location = str;
	}
}

function gourl(i){
	var currPath = window.location.href;
	var toPath = currPath;
	if (currPath.indexOf("?")!=-1){
		tempPos = currPath.indexOf("?");
		currPath = currPath.substring(0,tempPos);
	}

	if (i == 1) {
		toPath = currPath + '?s=2';
		set_cookie( 'InfoGovHK', '2', null, "/");
		document.location = toPath;
	} else {
		toPath = currPath + '?s=1';
		set_cookie( 'InfoGovHK', '1', null, "/");
		document.location = toPath;
	}
}

function leftmenu(){

	if (lang == 1){
		if (bilang){
			document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="165" height="93"><param name=movie value="' + imagePath + 'main_image.swf"><param name=quality value=high><embed src="' + imagePath + 'main_image.swf" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="165" height="93"></embed></object><br>');
	        document.write('<a href="javascript:switchLang(1);" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'Image1\',\'\',\'' + imagePath + 'btn_tc_h.gif\',1)" target="_top"><img src="' + imagePath + 'btn_tc_n.gif" width=44 height=20 border="0" name="Image1" alt="Traditional Chinese"></a><img src="' + imagePath + 'btn_line.gif" width="4" height="20"><a href="javascript:switchLang(2);" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'Image2\',\'\',\'' + imagePath + 'btn_sc_h.gif\',1)" target="_top"><img src="' + imagePath + 'btn_sc_n.gif" width=44 height=20 border="0" name="Image2" alt="Simplified Chinese"></a><a href="' + path + '/contact/index.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'Image3\',\'\',\'' + imagePath + 'btn_contactus_h.gif\',1)"><img src="' + imagePath + 'btn_contactus_n.gif" width=33 height=20 border="0" name="Image3" alt="Contact Us"></a>');
		} else {
			document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="165" height="93"><param name=movie value="' + imagePath + 'main_image.swf"><param name=quality value=high><embed src="' + imagePath + 'main_image.swf" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="165" height="93"></embed></object><br>');
	        document.write('<a href="javascript:alert(\'Traditional Chinese Version is not available at the moment.\')" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'Image1\',\'\',\'' + imagePath + 'btn_tc_h.gif\',1)" target="_top"><img src="' + imagePath + 'btn_tc_n.gif" width=44 height=20 border="0" name="Image1" alt="Traditional Chinese"></a><img src="' + imagePath + 'btn_line.gif" width="4" height="20"><a href="javascript:alert(\'Simplified Chinese Version is not available at the moment.\')" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'Image2\',\'\',\'' + imagePath + 'btn_sc_h.gif\',1)" target="_top"><img src="' + imagePath + 'btn_sc_n.gif" width=44 height=20 border="0" name="Image2" alt="Simplified Chinese"></a><a href="' + path + '/contact/index.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'Image3\',\'\',\'' + imagePath + 'btn_contactus_h.gif\',1)"><img src="' + imagePath + 'btn_contactus_n.gif" width=33 height=20 border="0" name="Image3" alt="Contact Us"></a>');
		}
	} else if (lang == 2){
		document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="165" height="93"><param name=movie value="' + imagePath + '/main_image.swf"><param name=quality value=high><embed src="' + imagePath + '/main_image.swf" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="165" height="93"></embed></object><br>');
        document.write('<a href="javascript:switchLang(2);" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'Image2\',\'\',\'' + imagePath + '/btn_sc_h.gif\',1)" target="_top"><img src="' + imagePath + '/btn_sc_n.gif" width=44 height=20 border="0" name="Image2" alt="簡體版"></a><img src="' + imagePath + '/btn_line.gif" width="4" height="20"><a href="javascript:switchLang(1);" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'Image1\',\'\',\'' + imagePath + '/btn_eng_h.gif\',1)" target="_top"><img src="' + imagePath + '/btn_eng_n.gif" width=44 height=20 border="0" name="Image1" alt="英文版"></a><a href="' + path + '/contact/index.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'Image3\',\'\',\'' + imagePath + '/btn_contactus_h.gif\',1)"><img src="' + imagePath + '/btn_contactus_n.gif" width=33 height=20 border="0" name="Image3" alt="聯絡我們"></a>');	
	} else {
		document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="165" height="93"><param name=movie value="' + imagePath + '/main_image.swf"><param name=quality value=high><embed src="' + imagePath + '/main_image.swf" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="165" height="93"></embed></object><br>');
        document.write('<a href="javascript:switchLang(2);" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'Image2\',\'\',\'' + imagePath + '/btn_tc_h.gif\',1)" target="_top"><img src="' + imagePath + '/btn_tc_n.gif" width=44 height=20 border="0" name="Image2" alt="繁體版"></a><img src="' + imagePath + '/btn_line.gif" width="4" height="20"><a href="javascript:switchLang(1);" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'Image1\',\'\',\'' + imagePath + '/btn_eng_h.gif\',1)" target="_top"><img src="' + imagePath + '/btn_eng_n.gif" width=44 height=20 border="0" name="Image1" alt="英文版"></a><a href="' + path + '/contact/index.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'Image3\',\'\',\'' + imagePath + '/btn_contactus_h.gif\',1)"><img src="' + imagePath + '/btn_contactus_n.gif" width=33 height=20 border="0" name="Image3" alt="聯絡我們"></a>');
	}

	if (q == 1){
		document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="40" height="20"><param name=movie value="' + imagePath + 'btn_sound_on.swf"><param name=quality value=high><embed src="' + imagePath + 'btn_sound_on.swf" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="40" height="20"></embed></object><br>');
	} else {
		document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="40" height="20"><param name=movie value="' + imagePath + 'btn_sound_off.swf"><param name=quality value=high><embed src="' + imagePath + 'btn_sound_off.swf" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="40" height="20"></embed></object><br>')
	}

	for (var i in leftMenu ){
		if (i == left) {
			document.write('<a href="' + leftMenuLink[i] + '" target="' + leftMenuTarget[i] + '"><img src="' + imagePath + leftMenu[i] + '_h.gif" border="0" name="' + leftMenu[i] + '" alt="' + leftMenuText[i] + '"></a><br>');
		} else {
			document.write('<a href="' + leftMenuLink[i] + '" target="' + leftMenuTarget[i] + '" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'' + leftMenu[i] + '\',\'\',\'' + imagePath + leftMenu[i] + '_h.gif\',1)"><img src="' + imagePath + leftMenu[i] + '_n.gif" border="0" name="' + leftMenu[i] + '" alt="' + leftMenuText[i] + '"></a><br>');
		}		
	}
	document.write('<img src="' + imagePath + 'btn_bottom.gif" width=165 height=16>');
}

function index_flash() {
	var swf_file = "btn_index_sound_on.swf";
	
	if (q != 1) swf_file = "btn_index_sound_off.swf";
		
	if (lang == 1) {
		document.write('<a href="javascript:switchLang(1);" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'Image1\',\'\',\'images/index/btn_tc_h.gif\',1)" target="_top"><img src="images/index/btn_tc_n.gif" width=59 height=27 border="0" name="Image1" alt="Traditional Chinese""></a><a href="javascript:switchLang(2);" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'Image2\',\'\',\'images/index/btn_sc_h.gif\',1)" target="_top"><img src="images/index/btn_sc_n.gif" width=56 height=27 border="0" name="Image2" alt="Simplified Chinese"></a><img src="images/index/btn_eng_h.gif" width=59 height=27 alt="English"><a href="contact/index.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'Image3\',\'\',\'images/index/btn_contactus_h.gif\',1)"><img src="images/index/btn_contactus_n.gif" width=35 height=27 border="0" name="Image3" alt="Contact Us"></a><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="39" height="27"><param name=movie value="images/index/' + swf_file +'"><param name=quality value=high><embed src="images/index/' + swf_file +'" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="39" height="27"></embed></object>');
	} else if (lang == 2){
		document.write('<img src="images/index/btn_tc_h.gif" width=59 height=27 border="0" name="Image1" alt="繁體版"><a href="javascript:switchLang(2);" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'Image2\',\'\',\'images/index/btn_sc_h.gif\',1)" target="_top"><img src="images/index/btn_sc_n.gif" width=56 height=27 border="0" name="Image2" alt="簡體版"></a><a href="javascript:switchLang(1);" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'Image13\',\'\',\'images/index/btn_eng_h.gif\',1)" target="_top"><img src="images/index/btn_eng_n.gif" width=59 height=27 border="0" name="Image13" alt="英文版"></a><a href="contact/index.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'Image3\',\'\',\'images/index/btn_contactus_h.gif\',1)"><img src="images/index/btn_contactus_n.gif" width=35 height=27 border="0" name="Image3" alt="聯絡我們"></a><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="39" height="27"><param name=movie value="images/index/' + swf_file +'"><param name=quality value=high><embed src="images/index/' + swf_file +'" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="39" height="27"></embed></object>');
	} else {
		document.write('<a href="javascript:switchLang(2);" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'Image1\',\'\',\'images/index/btn_tc_h.gif\',1)" target="_top"><img src="images/index/btn_tc_n.gif" width=59 height=27 border="0" name="Image1" alt="繁體版"></a><img src="images/index/btn_sc_h.gif" width=56 height=27 border="0" name="Image2" alt="簡體版"><a href="javascript:switchLang(1);" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'Image13\',\'\',\'images/index/btn_eng_h.gif\',1)" target="_top"><img src="images/index/btn_eng_n.gif" width=59 height=27 border="0" name="Image13" alt="英文版"></a><a href="contact/index.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'Image3\',\'\',\'images/index/btn_contactus_h.gif\',1)"><img src="images/index/btn_contactus_n.gif" width=35 height=27 border="0" name="Image3" alt="聯絡我們"></a><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="39" height="27"><param name=movie value="images/index/' + swf_file +'"><param name=quality value=high><embed src="images/index/' + swf_file +'" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="39" height="27"></embed></object>');
	}
	
}

function index_menu(){
	for (i=1; i<leftMenuLink.length; i++){
		if(i==1)
		{
			imgStatus = "_h";	
		}
		else
		{
			imgStatus = "_n";	
		}

		document.write('<a href="' + leftMenuLink[i] + '" target="' + leftMenuTarget[i] + '" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'' + leftMenu[i] + '\',\'\',\'' + imagePath + 'index/' + leftMenu[i] + '_h.gif\',1)"><img src="' + imagePath + 'index/' + leftMenu[i] + imgStatus + '.gif" border="0" name="' + leftMenu[i] + '" alt="' + leftMenuText[i] + '"></a><br>');
	}
}

function titlemenu(){
//	document.write('<img src="' + imagePath + titleMenu[left] + '.gif" alt="' + titleMenuText[left] + '" border="0">');
	
	var j = left;
	var k = left_sub;

	if (left==5){
		if (left_sub==1){
		document.write('' +
			'<img src="'+ imagePath +'hd_subcom_01.gif" alt="' +titleMenuSubText[k]+ '" border="0">' +
			'')
		}
		else if (left_sub==2){
		document.write('' +
			'<img src="'+ imagePath +'hd_subcom_02.gif" alt="' +titleMenuSubText[k]+ '" border="0">' +
			'')
		}
		else if (left_sub==3){
		document.write('' +
			'<img src="'+ imagePath +'hd_subcom_03.gif" alt="' +titleMenuSubText[k]+ '" border="0">' +
			'')
		}
		else if (left_sub==5){
		document.write('' +
			'<img src="'+ imagePath +'hd_subcom_05.gif" alt="' +titleMenuSubText[k]+ '" border="0">' +
			'')
		}
		else{
			document.write('' +
			'<img src="' + imagePath + titleMenu[j] + '.gif" alt="' + titleMenuText[j] + '" border="0">' +
			'')
		}
	}
	else if (left==6){
		if (left_sub==6){
		document.write('' +
			'<img src="'+ imagePath +'hd_uds_01.gif" alt="' +titleMenuSubText[k]+ '" border="0">' +
			'')
		}
		else if (left_sub==7){
		document.write('' +
			'<img src="'+ imagePath +'hd_uds_02.gif" alt="' +titleMenuSubText[k]+ '" border="0">' +
			'')
		}
		else if (left_sub==8){
		document.write('' +
			'<img src="'+ imagePath +'hd_uds_03.gif" alt="' +titleMenuSubText[k]+ '" border="0">' +
			'')
		}
		else if (left_sub==9){
		document.write('' +
			'<img src="'+ imagePath +'hd_uds_04.gif" alt="' +titleMenuSubText[k]+ '" border="0">' +
			'')
		}
		else{
			document.write('' +
			'<img src="' + imagePath + titleMenu[j] + '.gif" alt="' + titleMenuText[j] + '" border="0">' +
			'')
		}
	}
	else{
	document.write('<img src="' + imagePath + titleMenu[j] + '.gif" alt="' + titleMenuText[j] + '" border="0">');
	}
}

function get_searchbox() {
	document.write('	<tr> ');
	document.write('<form name="searchform" action="http://search.gov.hk/search.html" method="get" onsubmit="submitsearch()">');
	document.write('		<td width="10" align="left" valign="top" height="27"></td>');
	document.write('		<td width="758" align="left" valign="top" height="27" background="../images/index/search_box_bg.gif"><img src="../images/index/btn_bar_bg.gif" width="530" height=27>');
	document.write('<input type="hidden" name="tpl_id" value="harbour" />');
	document.write('<input type="hidden" name="gp0" value="harbourfront_home" />');
	document.write('<input type="hidden" name="gp1" value="harbourfront_home" />');
	document.write('<input type="hidden" name="web" value="this" />');
	document.write('<input type="hidden" name="ui_lang" value="" />');
	document.write('<input type="hidden" name="ui_charset" value="" />');
	document.write('<img src="../images/index/search_txt.gif" width="43" height="27"><input type="text" name="query" id="query" class="searchbox"><a href="#" onclick="submitsearch();document.searchform.submit()" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage(\'btn_search\',\'\',\'../images/index/btn_search_o.gif\',1)"><img src="../images/index/btn_search.gif" width="39" height="27" border="0" id="btn_search" name="btn_search"></a></td>');
	document.write('		<td width="11" align="left" valign="top" height="27" background="../images/index/spacer.gif"></td>');
	document.write('</form>');
	document.write('	</tr>');
}

function submitsearch() {
	if (location.href.indexOf("/chs/")>0) {
		document.searchform.ui_lang.value = "zh-cnhk";
		document.searchform.ui_charset.value = "utf-8";
		document.searchform.action = ""+"ht"+"tp://search.gov.hk/search.html";
	}
	if (location.href.indexOf("/eng/")>0) {
		document.searchform.ui_lang.value = "en";
		document.searchform.ui_charset.value = "iso-8859-1";
	}
	if (location.href.indexOf("/tc/")>0) {
		document.searchform.ui_lang.value = "zh-hk";
		document.searchform.ui_charset.value = "big5";
	}
	if (location.href.indexOf("/sc/")>0) {
		document.searchform.ui_lang.value = "zh-cnhk";
		document.searchform.ui_charset.value = "utf-8";
	}
}