//get the current page in order to make the link properly
var webLocate;
webLocate = window.location.toString();
for (i=1;i<webLocate.length;i++) 
	if (webLocate.substring(i,i+3)==(lang_ver[wordlang].toString()+"/")) {
		webLocate = (webLocate.substring(i+3,webLocate.length));
		break;
	}
//alert ("<META name=\"date\" content=\""+bottom_lastupdate.substring(6,10)+"-"+bottom_lastupdate.substring(3,5)+"-"+bottom_lastupdate.substring(0,2)+"T09:00:00+08:00\">");

function checkEnter(e) {
	var cCode;

	if (e && e.which) {
		e = e;
		cCode = e.which;
	} else {
		e = event;
		cCode = e.keyCode;
	}

	return cCode == 13;
}

function checkTopEnter(e) {
	if (checkEnter(e))
		return tryTopSearch();
	else
		return true;
}

function checkSearchEnter(e) {
	if (checkEnter(e))
		return tryAdvancedSearch();
	else
		return true;
}

function validateTopSearch() {
	var f = document.forms[0];

	if (f.query.value == "") {
		alert(searchreminder[wordlang]);
		f.query.focus();
		return false;
	}
	return true;
}

function validateAdvancedSearch() {
	var f = document.forms[0];

	if (!(f.query_q.value || f.exact_q.value || f.any_q.value)) {
		alert(searchreminder[wordlang]);
		f.query_q.focus();
		return false;
	}

	return true;
}

function trimTopSearch() {
}

function trimAdvancedSearch() {
	var f = document.forms[0];

	f.init_query.value = encodeURIComponent(f.query_q.value);
	f.init_exact_q.value = encodeURIComponent(f.exact_q.value);
	f.init_any_q.value = encodeURIComponent(f.any_q.value);
	f.init_none_q.value = encodeURIComponent(f.none_q.value);
	f.query.value = encodeURIComponent(f.query_q.value);

	/* doc type related data */
	f.doc_type.value = f.file_type.value;
	/* display related data */
	f.p_size.value = f.page_size.value;
	/* trim language related data */
	f.r_lang.value = f.lga_v.value;

	/* trim website related data */
	if (f.wb_all.checked){
		f.gp1.value = "0";
		f.web.value = "all";
	}else{
		f.gp1.value = f.gp0.value;
		f.web.value = "this";
	} 
}

function tryTopSearch() {
	if (validateTopSearch()) {
		trimTopSearch();
		//document.QueryText.submit();
		return true;
	} else
		return false;
}

function tryAdvancedSearch() {
	if (validateAdvancedSearch()) {
		trimAdvancedSearch();
		//document.QueryText.submit();
		return true;
	} else
		return false;
}

document.write("<title>"+(top_titlebar[wordlang])+"<\/title>"+
		"<META "+
"content=\""+(top_meta_content[wordlang])+"\" "+
"name=keywords>"+
"<META content=\""+(top_meta_desc[wordlang])+"\" name=description>"+
"<META name=\"date\" content=\""+bottom_lastupdate.substring(6,10)+"-"+bottom_lastupdate.substring(3,5)+"-"+bottom_lastupdate.substring(0,2)+"T09:00:00+08:00\">"+
"<script language=\"javascript\" src=\"/phisweb/include/js/header.js\"></script>"+
"<link rel=\"stylesheet\" href=\"/phisweb/css/common.css\" type=\"text/css\">"+
"<link rel=\"stylesheet\" href=\"/phisweb/css/menu/custom_menu.css\" type=\"text/css\">"+
"<\/head>"+
"<body bgcolor=\"#FFFFFF\" text=\"#000000\" leftmargin=\"0\" topmargin=\"0\" marginwidth=\"0\" marginheight=\"0\" bgcolor=\"#DEF4FF\"><body onLoad=\"MM_preloadImages('images\/mainbar1_f22.gif','images\/main_tc2.gif','images\/mainbar3_f22.gif','images\/mainbar4_f22.gif','images\/mainbar10_f2.gif','images\/mainbar9_f22.gif','images\/mainbar8_f2.gif','images\/mainbar6_f22.gif','images\/left_2_en_2.gif','images\/left_3_en_2.gif','images\/left_4_en_2.gif','images\/left_5_en_2.gif','images\/left_6_en_2.gif','images\/left_7_en_2.gif','images\/left_8_en_2.gif','images\/left_9_en_2.gif','images\/left_10_en_2.gif','images\/left_11_en_2.gif','images\/left_12_en_2.gif')\">"+

"<form name=\"QueryText\" action=\"http://search.gov.hk/search.html\" method=\"get\" target=\"_blank\">"+
"    <input type=\"hidden\" name=\"tpl_id\" value=\"healthyhk\">"+
"    <input type=\"hidden\" name=\"ui_lang\" value=\""+search_form_par_ui_lang[wordlang]+"\">"+
"    <input type=\"hidden\" name=\"ui_charset\" value=\""+search_form_par_ui_charset[wordlang]+"\">"+
"    <input type=\"hidden\" name=\"gp0\" value=\"healthyhk_home\">"+
"    <input type=\"hidden\" name=\"gp1\" value=\"healthyhk_home\">"+
"    <input type=\"hidden\" name=\"web\" value=\"this\">"+

"  <table width=\"760\" border=\"0\" height=\"100%\" cellpadding=\"0\" cellspacing=\"0\">"+
"    <tr>"+
"      <td valign=\"top\">"+
"        <!-- Begin of Site Header ENG Version -->"+

"<table width=\"770\" height=\"87\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" background=\"\/phisweb\/images\/bkgdtexture.gif\">"+
"  <tr>"+
"    <td width=\"20%\" height=\"60\"><a href=\"\/phisweb\/\"><img src=\"\/phisweb\/images\/"+top_healthyhk_brand[wordlang]+"\" height=\"60\" border=\"0\" alt=\""+top_titlebar[wordlang]+"\"><\/a><\/td><td width=\"46%\" height=\"60\" align=\"right\"><a href=\""+BrandOfHK[wordlang]+"\" target=\"_blank\"><img src=\"\/phisweb\/images\/"+top_dragon_brand[wordlang]+"\" alt=\""+bottom_menu[0][wordlang]+"\" border=\"0\"><\/a></td>"+
"  <\/tr>"+
"  <tr>"+
"    <td height=\"20\" valign=\"bottom\"><a href=\""+gicLink[wordlang]+"\" target=\"_blank\" onMouseOut=\"MM_swapImgRestore()\" onMouseOver=\"MM_swapImage('Image24','','\/phisweb\/images\/"+(top_button_ro[0][wordlang])+"',1)\"><img src=\"\/phisweb\/images\/"+(top_button_grp[0][wordlang])+"\" name=\"Image24\"  border=\"0\" alt=\""+top_button_alt[0][wordlang]+"\"><\/a><a href=\"\/phisweb\/plain\/"+lang_ver[top_button_link[0][wordlang]]+"\/"+webLocate+"\" onMouseOut=\"MM_swapImgRestore()\" onMouseOver=\"MM_swapImage('Image34','','\/phisweb\/images\/"+(top_button_ro[1][wordlang])+"',1)\"><img src=\"\/phisweb\/images\/"+(top_button_grp[1][wordlang])+"\" name=\"Image34\"    border=\"0\" alt=\""+top_button_alt[1][wordlang]+"\"><\/a><a href=\"\/phisweb\/"+lang_ver[top_button_link[5][wordlang]]+"\/"+webLocate+"\" onMouseOut=\"MM_swapImgRestore()\" onMouseOver=\"MM_swapImage('Image26','','\/phisweb\/images\/"+(top_button_ro[2][wordlang])+"',1)\"><img src=\"\/phisweb\/images\/"+(top_button_grp[2][wordlang])+"\" name=\"Image26\"   border=\"0\" alt=\""+top_button_alt[2][wordlang]+"\"><\/a><a href=\"\/phisweb\/"+lang_ver[top_button_link[6][wordlang]]+"\/"+webLocate+"\" onMouseOut=\"MM_swapImgRestore()\" onMouseOver=\"MM_swapImage('Image27','','\/phisweb\/images\/"+(top_button_ro[3][wordlang])+"',1)\"><img src=\"\/phisweb\/images\/"+(top_button_grp[3][wordlang])+"\" name=\"Image27\"  border=\"0\" alt=\""+top_button_alt[3][wordlang]+"\"><\/a><img src=\"\/phisweb\/images\/angle.gif\" width=\"20\" height=\"20\"><br>"+
"        <img src=\"\/phisweb\/images\/mainbar9.gif\" width=\"425\" height=\"2\"><br><\/td>"+
"    <td height=\"20\" align=\"right\" valign=\"bottom\"><p><a href=\"#\" onMouseOut=\"MM_swapImgRestore()\" onMouseOver=\"MM_swapImage('Image31','','\/phisweb\/images\/"+(top_button_ro[4][wordlang])+"',1)\">"+
"<img src=\"/phisweb/images/"+(top_button_grp[4][wordlang])+"\" name=\"Image31\"  border=\"0\" align=\"absbottom\" alt=\""+top_button_alt[4][wordlang]+"\""+
" onclick=\"if(validateTopSearch()){trimTopSearch();document.QueryText.submit();}else{return false;}\""+
" onKeyPress=\"if(validateTopSearch()){trimTopSearch();document.QueryText.submit();}else{return false;}\"></a>"+
"     <input name=\"query\" type=\"text\" size=\"18\" class=\"search\" onKeyPress=\"if(!checkTopEnter(event)){return false;}else{}\">"+
"      <a href=\"#\" onMouseOut=\"MM_swapImgRestore()\" onMouseOver=\"MM_swapImage('Image33','','\/phisweb\/images\/mainbar8_f2.gif',1)\"><img src=\"\/phisweb\/images\/mainbar8.gif\" name=\"Image33\" border=\"0\" align=\"absbottom\" alt=\""+top_button_alt[4][wordlang]+"\""+
" onclick=\"if(validateTopSearch()){trimTopSearch();document.QueryText.submit();}else{return false;}\""+
" onKeyPress=\"if(validateTopSearch()){trimTopSearch();document.QueryText.submit();}else{return false;}\"><\/a><a href=\"\/phisweb\/"+lang_ver[top_button_link[4][wordlang]]+"\/site_map\/\" onMouseOut=\"MM_swapImgRestore()\" onMouseOver=\"MM_swapImage('Image29','','\/phisweb\/images\/"+(top_button_ro[5][wordlang])+"',1)\"><img src=\"\/phisweb\/images\/"+(top_button_grp[5][wordlang])+"\" name=\"Image29\"  border=\"0\" align=\"absbottom\" alt=\""+top_button_alt[5][wordlang]+"\"><\/a><a href=\"\/phisweb\/"+lang_ver[top_button_link[4][wordlang]]+"\/contact_us\/\" onMouseOut=\"MM_swapImgRestore()\" onMouseOver=\"MM_swapImage('Image28','','\/phisweb\/images\/mainbar10_f2.gif',1)\"><img src=\"\/phisweb\/images\/mainbar10.gif\" name=\"Image28\" width=\"36\" height=\"20\" border=\"0\" align=\"absbottom\" alt=\""+top_button_alt[6][wordlang]+"\"><\/a><br>"+
"      <img src=\"\/phisweb\/images\/mainbar9.gif\" width=\"345\" height=\"2\"><br>"+
"   <\/p>"+
"      <\/td>"+
"  <\/tr>"+
"<\/table>"+
"<!-- End of Site Header ENG Version -->      <\/td>"
);
