<!--

var menu;
var menu2;
var theTop = 65+20+5;
//var old = theTop;
//var old2 = theTop;

function writeMenuTable(lang, idx) {
	var aMenu = new Array(
					new Array("home.html", "Home", "主頁"), 
					new Array("aboutus.html", "About us", "關於我們"), 
					new Array("news.asp", "What's new", "最新消息"), 
					new Array("search.asp", "HK Biodiversity database", "香港生物數據庫"), 
					new Array("speciesgroup_index.html", "HK Species", "香港物種"), 
					new Array("habitat.html", "HK Habitats", "香港生境"), 
					new Array("newsletters.html", "Newsletters", "下載期刊"), 
					new Array("usefullinks.html", "Useful links", "相關網站"),
					new Array("leaflets.html", "Other Information", "其他資訊"), 
					new Array("doLogoff.asp", "Logout", "登出"));
	
	var username_en = "Username";
	var password_en = "Password";
	var username_tc = "用戶名稱";
	var password_tc = "用戶密碼";
	var login_en = "Login";
	var login_tc = "登入";
	//var htmlpath_en = "/html/en/";
	//var htmlpath_tc = "/html/tc/";
	// var imagepath = "http://www.hkbiodiversity.net/images/"; // see common.js
	var imagepath_lang;
	//var imagepath_en = "http://www.hkbiodiversity.net/images/engimages/"; // see common.js
	//var imagepath_tc = "http://www.hkbiodiversity.net/images/chiimages/"; // see common.js
	var langidx = 0;
	var urlidx = 0;
	var urltemp = '';
	var i = 0;
	var loopcount = 0;
	if ( lang.toUpperCase() == "EN") {
		imagepath_lang = imagepath_en;
		langidx = 1;
	} else {
		imagepath_lang = imagepath_tc;
		langidx = 2;
	}
	
	// need to determine to write login box or logout button
	//alert(document.cookie);

	if (!getLoginState()) {
		loopcount = aMenu.length-1;  // not yet login
	} else {
		loopcount = aMenu.length;
	}
	
	document.write('<div id="leftmenu" style="POSITION: relative; top:0">');
	document.write('<table width="154" border="0" cellpadding="0" cellspacing="0">');
	
	for (i = 0; i < loopcount; i++) {
		document.write('  <tr>');
		urltemp = '';
		if ( lang.toUpperCase() == "EN") {
			//urltemp = htmlpath_en + aMenu[i][urlidx];
			if (aMenu[i][urlidx].toUpperCase().indexOf('JAVASCRIPT:') >= 0) {
					urltemp = aMenu[i][urlidx];
			} else {
				urltemp = "javascript:navigatePath('"+aMenu[i][urlidx]+"', 'en');";
			}
		} else {
			//urltemp = htmlpath_tc + aMenu[i][urlidx];
			if (aMenu[i][urlidx].toUpperCase().indexOf('JAVASCRIPT:') >= 0) {
					urltemp = aMenu[i][urlidx];
			} else {
				urltemp = "javascript:navigatePath('"+aMenu[i][urlidx]+"', 'tc');";
			}
		}
		
    	if ( idx != i ) {
    		document.write('    <td align="left" valign="top" width="154" height="36"><a href="' + urltemp +  '" onMouseOut="MM_swapImgRestore()"  onMouseOver="MM_swapImage(\'sidebar' + (i+1) + '\',\'\',\'' + imagepath_lang + 'sidebar'+ (i+1) + '_f2.gif\',1)"><img name="sidebar' + (i+1) +'" src="' + imagepath_lang + 'sidebar'+ (i+1) +'.gif" width="154" height="36" border="0" alt="' + aMenu[i][langidx] + '"></a></td>');
    	} else {
    		document.write('    <td align="left" valign="top" width="154" height="36"><a href="' + urltemp +  '" onMouseOut="MM_swapImgRestore()"  onMouseOver="MM_swapImage(\'sidebar' + (i+1) + '\',\'\',\'' + imagepath_lang + 'sidebar'+ (i+1) + '_f2.gif\',1)"><img name="sidebar' + (i+1) +'" src="' + imagepath_lang + 'sidebar'+ (i+1) +'_f2.gif" width="154" height="36" border="0" alt="' + aMenu[i][langidx] + '"></a></td>');
    	}
    	document.write('  </tr>');
    }

if (!getLoginState()) {
    document.write('  <tr>');
	document.write('    <td align="center">');
	//document.write('      <table cellspacing="0" cellpadding="0" bgcolor="#E8FCC3">');
	document.write('      <table cellspacing="0" cellpadding="0">');
	document.write('        <tr><td colspan="3" valign="bottom" height="27"><IMG border="0" src="' + imagepath_lang + 'signinheader.gif" width="140" height="27" border="0" alt="Staff only"></td></tr>');
	document.write('        <tr><td valign="top" align="left" height="82"><IMG border="0" width="1" height="82" src="' + imagepath + 'line.gif" alt=""></td>');
	document.write('		    <td valign="top" align="center" width="136">');
	document.write('			    <Table cellspacing="2">');
	document.write('				 <form name="login_form" method="POST" ACTION="' + BaseURL + 'apps/doLogin.asp" AUTOCOMPLETE="OFF" onsubmit="javascript:return(validate_login());">');
	document.write('				  <input type="hidden" name="lang" value="' + lang.toLowerCase()+ '">');
	document.write('				  <input type="hidden" name="returnurl" value="' + window.location.href + '">');
	document.write('				  <tr><td class="LoginText">');
	document.write(langidx==1?username_en:username_tc);
	document.write(':</td><td><input type="text" name="loginid" size="6" maxlength="20"></td></tr>');
	document.write('				  <tr><td class="LoginText">');
	document.write(langidx==1?password_en:password_tc);
	document.write(':</td><td><input type="password" name="passwd" size="6" maxlength="20"></td></tr>');
	document.write('				  <tr><td align="right" colspan="2" class="LoginText"><input type="submit" class="atbutton" value="');
	document.write(langidx==1?login_en:login_tc);
	document.write('" /></td></tr>');
	document.write('				 </form>');
	document.write('			    </Table>');
	document.write('		    </td>');
	document.write('            <td valign="top"align="right" height="82"><IMG border="0" width="1" height="82" src="' + imagepath + 'line.gif" alt=""></td></tr>');
	document.write('        <tr><td colspan="3" valign="top" height="12"><IMG border="0" src="' + imagepath + 'signin_bottomline.gif" width="140" height="12" border="0" alt=""></td></tr>');
    document.write('      </table>');
    document.write('    </td>');
	document.write('  </tr>');
}
	document.write('  <tr><td>&nbsp;</td></tr>');
    document.write('</table>');
    if (idx >= 0) {
    	document.write('<img src="' + imagepath + 'anibufferfly2.gif" alt="" width="26" height="20" style="position: absolute;top: ' + (idx*36) + '; left: 9;" />');
    }
    document.write('</div>');
}
	
function menuinit()
{	MM_preloadImages('/images/line.gif');
	MM_preloadImages('/images/engimages/sidebar1_f2.gif','/images/engimages/sidebar2_f2.gif','/images/engimages/sidebar3_f2.gif','/images/engimages/sidebar4_f2.gif','/images/engimages/sidebar5_f2.gif','/images/engimages/sidebar6_f2.gif','/images/engimages/sidebar7_f2.gif','/images/engimages/sidebar8_f2.gif');
	MM_preloadImages('/images/chiimages/sidebar1_f2.gif','/images/chiimages/sidebar2_f2.gif','/images/chiimages/sidebar3_f2.gif','/images/chiimages/sidebar4_f2.gif','/images/chiimages/sidebar5_f2.gif','/images/chiimages/sidebar6_f2.gif','/images/chiimages/sidebar7_f2.gif','/images/chiimages/sidebar8_f2.gif');
	MM_preloadImages('/images/simimages/sidebar1_f2.gif','/images/simimages/sidebar2_f2.gif','/images/simimages/sidebar3_f2.gif','/images/simimages/sidebar4_f2.gif','/images/simimages/sidebar5_f2.gif','/images/simimages/sidebar6_f2.gif','/images/simimages/sidebar7_f2.gif','/images/simimages/sidebar8_f2.gif');
	menu = new getObj('leftmenu');
	//menu2 = new getObj('topmenu');
	movemenu();
}

function movemenu()
{
	var pos;
	var old;
	var old2;
	if (window.innerHeight) {
		pos = window.pageYOffset
	}
	else if (document.documentElement && document.documentElement.scrollTop) {
		pos = document.documentElement.scrollTop
	}
	else if (document.body) {
		pos = document.body.scrollTop
	}
	if (pos < theTop) pos = (theTop);
		
		//else pos += 30;

	
	if (parseInt(menu.style.top) > 0) old = parseInt(menu.style.top) + theTop;
	//if (parseInt(menu2.style.top) > 0) old2 = parseInt(menu2.style.top) + theTop;
	
	//alert(pos + ":" + old + ":" + old2);
	if (menu.style && pos != old) {
		if (pos - theTop > 0) {
			menu.style.top = pos - theTop;				
		} else {
			menu.style.top = 0;
		}
	}
	/*
	if (menu2.style && pos != old2) {

		if (pos - theTop > 0) {
			menu2.style.top = pos - theTop;				
		} else {
			menu2.style.top = 0;
		}
	}
	*/
	temp = setTimeout('movemenu()',500);
}
//-->
