var x = 1;	 //menuObj.length
var y = 1;	 //subMenuObj.length
//var z = 1; //next subMenuObj.id
var menuObj = new Array();
var subMenuObj = new Array();
var selected_index=0;
var selected_sub=0;
var previousMenuID = "";
var imagePath;
var locationPath;
var topButton='Y';
var topButtoncount=0;

if(location.href.toString().search('westcomzivo')!=-1){
	locationPath='ht'+'tp://test1.westcomzivo.com/dev/hkieia/';
}else if(location.href.toString().indexOf('www.hkieia.org.hk')!=-1){
	locationPath='ht'+'tp://www.hkieia.org.hk/';
}else{
	locationPath="../"
}

if(document.URL.toString().search('/gb/')!=-1){
	imagePath = locationPath+'gb/';
	locationPath='ht'+'tp://'+gb_urlPath+locationPath.substring(7, locationPath.length);
}else{
	imagePath = locationPath + "images/";
}

/***** Add Section Start *****/
addMenu(1, "Opening Page"
	,"../index.htm"
	,"inside_menu_01.gif"
	,"inside_menu_01_mo.gif"
	,"N","Y","N");
addMenu(2, "About the HKIEIA"
	,"../about/news.htm"
	,"inside_menu_02.gif"
	,"inside_menu_02_mo.gif"
	,"Y","Y","Y");
addMenu(3, "Events/ Activity"
	,"../event/seminar.htm"
	,"inside_menu_03.gif"
	,"inside_menu_03_mo.gif"
	,"Y","Y","Y");
addMenu(4, "Newsletter/ Publication"
	,"../publish/newsletter.htm"
	,"inside_menu_04.gif"
	,"inside_menu_04_mo.gif"
	,"Y","Y","Y");
/*
addMenu("News and Public Affairs"
	,"#"
	,"inside_menu_05.gif"
	,"inside_menu_05_mo.gif"
	,"Y");
*/
addMenu(5, "Membership"
	,"../membership/class.htm"
	,"inside_menu_06.gif"
	,"inside_menu_06_mo.gif"
	,"Y","Y","Y");
addMenu(6, "AMP Scheme"
	,"../amp/background.htm"
	,"inside_menu_07.gif"
	,"inside_menu_07_mo.gif"
	,"Y","Y","Y");
/*
addMenu(7, "Discussion Forum"
	,"../forum/forum.asp"
//	,"../forum/forum.htm"
	,"inside_menu_08.gif"
	,"inside_menu_08_mo.gif"
	,"N","Y","Y");
*/
addMenu(8, "Download Forms"
	,"../download/form.htm"
	,"inside_menu_09.gif"
	,"inside_menu_09_mo.gif"
	,"N","Y","Y");

addMenu(9, "Financial Report"
	,"../financial/report.htm"
	,"inside_menu_10.gif"
	,"inside_menu_10_mo.gif"
	,"N","Y","Y");

addMenu(10, "Useful Links"
	,"../links/links.htm"
	,"inside_menu_11.gif"
	,"inside_menu_11_mo.gif"
	,"N","Y","Y");

addMenu(11, "Contact Us"
	,"mailto:webmaster@hkieia.org.hk"
	,"inside_menu_12.gif"
	,"inside_menu_12_mo.gif"
	,"N","Y","Y");
addMenu(12, "Site Map"
	,"../sitemap/sitemap.htm"
	,"inside_menu_13.gif"
	,"inside_menu_13_mo.gif"
	,"N","N","N");
addMenu(13, "Disclaimer / Privacy Statment"
	,"../disclaimer/disclaimer.htm"
	,"inside_menu_14.gif"
	,"inside_menu_14_mo.gif"
	,"N","Y","N");
addMenu(14, "Join Us"
	,"../join/join.htm"
	,"inside_menu_15.gif"
	,"inside_menu_15_mo.gif"
	,"N","Y","Y");
/***** Add Section End *****/


/***** Add Sub Section Start *****/
addSubMenu(2, 1, "News", "../about/news.htm","Y","Y");
addSubMenu(2, 2, "Our Institute", "../about/institute.htm","Y","Y");
addSubMenu(2, 3, "The Committee", "../about/committee.htm","Y","Y");
addSubMenu(2, 4, "The Memorandum", "../about/memo.htm","Y","Y");

addSubMenu(3, 1, "Seminars / Conferences",	"../event/seminar.htm","Y","Y");
addSubMenu(3, 2, "Technical Visits", "../event/techvisit.htm","Y","Y");
addSubMenu(3, 3, "Reports of Technical Visits / Seminars", "../event/report.htm","Y","Y");

addSubMenu(4, 1, "Newsletter", "../publish/newsletter.htm","Y","Y");
addSubMenu(4, 2, "Position Papers", "../publish/pospaper.htm","Y","Y");

addSubMenu(5, 1, "Membership Class", "../membership/class.htm","Y","Y");
addSubMenu(5, 2, "Membership List", "../membership/list.htm","Y","Y");
addSubMenu(5, 3, "Professional Directory",	"../membership/prof.htm","Y","Y");
addSubMenu(5, 4, "Code of Conduct", "../membership/code.htm","Y","Y");

addSubMenu(6, 1, "AMP Background", "../amp/background.htm","Y","Y");
addSubMenu(6, 2, "Code of Ethics for AMP", "../amp/ethics.htm","Y","Y");
addSubMenu(6, 3, "Guidelines on AMP", "../amp/guidelines.htm","Y","Y");
addSubMenu(6, 4, "Application Form", "../amp/ampform.htm","Y","Y");
addSubMenu(6, 5, "List of Registered AMPs", "../amp/reg.htm","Y","Y");
/***** Add Sub Section End *****/






function addMenu(sectionID, caption,url,offPic,onPic,hasChild,sitemap,navigationMenu)
{
	menuObj[x]	= new Object();
	menuObj[x].id = sectionID;
	menuObj[x].caption = caption;
	menuObj[x].url = url;
	menuObj[x].onPic = imagePath + onPic;
	menuObj[x].offPic = imagePath + offPic;
	menuObj[x].hasChild = hasChild;
	menuObj[x].sitemap = sitemap;
	menuObj[x].navigationMenu = navigationMenu;
	x++;
}

function addSubMenu(menuID, subSectionID, caption,url,sitemap,navigationMenu)
{
	if (menuID != previousMenuID){
		previousMenuID=menuID;
//		z=1;
	}
	subMenuObj[y] = new Object();
	subMenuObj[y].id = subSectionID;
	subMenuObj[y].menuID = menuID;
	subMenuObj[y].caption = caption;
	subMenuObj[y].url = url;
	subMenuObj[y].sitemap = sitemap;
	subMenuObj[y].navigationMenu = navigationMenu;
	y++;
//	z++;

}

function switchPic(int_index,str_status){
	if (document.images){
		if (int_index!=selected_index){
			if (str_status=="mover")
			{
				var pic = menuObj[int_index].onPic;
			}else{
				var pic = menuObj[int_index].offPic;
			}
			eval("document.images.pic" + int_index + ".src = '"+ pic +"'");
		}
	}
}

function switchTopPic(int_status,int_topcount){
	if (document.images){
			if (int_status==1)
			{
				var pic = imagePath + "top_o.gif";
			}else{
				var pic = imagePath + "top.gif";
			}
			eval("document.images.backtotopfoot"+int_topcount+".src = '"+ pic +"'");
	}
}


function drawMenu(){
//assignSelectedIndex();
//	document.writeln("<table>");
	for (var i=1; i < x ; i ++){
		if(menuObj[i]){
			if(menuObj[i].navigationMenu=="Y"){
				var outAction = " onMouseOut='switchPic("+i+",\"mout\");' ";
				var overAction = " onMouseOver='switchPic("+i+",\"mover\");' ";
				document.writeln("<tr><td><a href='"+menuObj[i].url+"'"+ outAction + overAction + "><img name='pic"+i+"' id='pic"+i+"' src='" + menuObj[i].offPic +  "' alt='"+menuObj[i].caption+"' border=0></a></td></tr>");
			
				if (menuObj[i].id ==selected_index){
					drawMenuChild();
				}
			//}else{
			//	document.writeln("<tr style=display:none;><td><a href='"+menuObj[i].url+"'"+ outAction + overAction + "><img name='pic"+i+"' id='pic"+i+"' src='" + menuObj[i].offPic +  "' alt='"+menuObj[i].caption+"' border=0></a></td></tr>");
			}
		}
	}

	//init();
//	document.writeln("</table>");
}

function drawMenuChild(){
	document.writeln("<tr><td>");
	document.writeln("<table cellpadding=1 cellspacing=1 border=0 width=174 bgcolor=white>");
	
	for (var i=1; i <= subMenuObj.length ; i++ ){
		if (subMenuObj[i])
		{
			if (subMenuObj[i].menuID==selected_index){
				if (subMenuObj[i].id != selected_sub){
					document.writeln("<tr bgcolor=white><td><img src=\"../images/spacer.gif\" width=9 height=19></td><td class=subnavmenu width=100%><a href='"+subMenuObj[i].url+"' class=subnav>"+subMenuObj[i].caption+"</a></td><td></td></tr>");
				}else{
					document.writeln("<tr bgcolor=white><td><img src=\"../images/spacer.gif\" width=9 height=19></td><td class=subnavmenu>"+subMenuObj[i].caption+"</td></tr>");
				}
			}
		}
	}

	document.writeln("</table>");
	document.writeln("</td></tr>");
}


function drawSubMenu(){
	if (selected_index=="" || menuObj[selected_index].hasChild=="N") return;
	
	document.writeln("<td width=2 nowrap>&nbsp;</td>");
					
	for (var i=1; i <= subMenuObj.length ; i++ )
	{
		if(subMenuObj[i]){
			if (subMenuObj[i].menuID==selected_index){
				if (subMenuObj[i].id != selected_sub)
				{
				document.writeln("<td class=submenu nowrap><center>&nbsp;<a href='"+subMenuObj[i].url+"' class=sublink>"+subMenuObj[i].caption+"</a>&nbsp;</center></td>");
				}else{
				document.writeln("<td class=submenu2 nowrap><center>&nbsp;"+subMenuObj[i].caption+"&nbsp;</center></td>");
				}
				document.writeln("<td width=2 nowrap></td>");
			}
		}
	}
	
}


function init(){
	if (menuObj[selected_index].navigationMenu=="N") return;
	
	var pic = menuObj[selected_index].onPic;
	if (document.images){
		eval("document.images.pic" + selected_index + ".src = '"+ pic +"'");
	}


	setTopLayerPosition(true);
}

function drawHeader(){
document.writeln("<a name=top></a><map name=home><area alt=\"HKIEIA\" coords=\"87,3,367,48\" href=\""+locationPath+"index.htm\"></map>");
document.writeln("<table cellpadding=0 cellspacing=0 border=0 width=780 bgcolor=#8FD155>");
document.writeln("<tr><td valign=bottom colspan=2><img src=\""+imagePath+"inside_01.jpg\" alt=\"HKIEIA\" border=0></td></tr>");
document.writeln("<tr><td valign=bottom rowspan=2><img src=\""+imagePath+"inside_02.jpg\" alt=\"HKIEIA\" border=0 usemap=\"#home\"></td>");
document.writeln("<td valign=bottom bgcolor=#8FD155 height=10><a href=\"mailto:webmaster@hkieia.org.hk\" class=topmenu>Contact Us</a>&nbsp;|&nbsp;");
document.writeln("<a href=\"../sitemap/sitemap.htm\" class=topmenu>Site Map</a>&nbsp;|&nbsp;<a href=\"../disclaimer/disclaimer.htm\" class=topmenu>Disclaimer / Privacy Statement</a></td>");
document.writeln("</tr>");
document.writeln("<tr>");
document.writeln("<td><img src=\""+imagePath+"inside_04.jpg\" alt=\"HKIEIA\" border=0></td>");
document.writeln("</tr>");
document.writeln("</table>");
}


function drawFooter(){

	document.write("<table cellspacing=0 cellpadding=0 width=100% border=0>");

	document.write('<tr valign=top><td align=right><img src="'+imagePath+'/spacer.gif" name="backtotopspacer" width=38 height=20></td></tr>');
	document.write("<tr valign=top><td align=right nowrap width=100%><br><span class=footer>2004 (c) Copyright HKIEIA - All rights reserved</span><br><br></td></tr>");

	document.write("</table>");
	genfooterLayer();
}


var resizeFlag;
var footerY = 600;

function moveDivs(layerObj, inObj){
	layerObj.top  = inObj;
} 

function moveTopDivs(layerObj, inObjTop, inObjLeft){
	layerObj.top  = inObjTop;
	layerObj.left  = inObjLeft;
} 

function getDim(el){
	for (var lx=0,ly=0;el!=null;
		lx+=el.offsetLeft,ly+=el.offsetTop,el=el.offsetParent);
	return {x:lx,y:ly}
}

function genfooterLayer(){
	var altText='Top';
	
//	if(langID!=1) altText='­¶­º';

//	if(!isText){
		if (document.layers)
			{document.writeln('<layer name=footer_layer top=0 left=0 width=26 height=26 visibility="hide">');}
		else
			{document.writeln('<div id="footer_layer" style="position:absolute; left:0; top:0; width:26; height:26; z-index:1; visibility: hidden"> ');}
//		document.writeln('<table width="100%" border=0 cellspacing=0 cellpadding=0>');
//		document.writeln('<tr valign=top>');
//		document.writeln('	<td align=right><a href="#top" onmouseout="javascript:switchTopPic(0,0);" onmouseover="javascript:switchTopPic(1,0);"><img src = "'+imagePath+'top.gif" alt= "'+altText+'" border=0 name=backtotopfoot0 id=backtotopfoot0></a></td>');
//		document.writeln('</tr>');
//		document.writeln('</table>');
		drawTopButton();
		if (document.layers)
			{document.writeln('</layer>');}
		else
			{document.writeln('</div>');}			
//	}
}

function setTopLayerPosition(resizeFlag){
	if(topButton=='Y'){
		if (document.all && document.all["footer_layer"]!=null)
		{
	//		footerY = getDim(document.images.leftMenuLineBottom).y;
			moveTopDivs(document.all["footer_layer"].style, getDim(document.images.backtotopspacer).y, getDim(document.images.backtotopspacer).x);
			if (getDim(document.images.backtotopspacer).y > footerY)
			{
				if (resizeFlag)
				{document.all["footer_layer"].style.visibility = "visible";}
			}
		}
		if (document.layers && document.layers["footer_layer"])
		{
	//		footerY = document.images["leftMenuLineBottom"].y;
			moveTopDivs(document.layers["footer_layer"], document.images["backtotopspacer"].y, document.images["backtotopspacer"].x);
			if (document.images["backtotopspacer"].y > footerY)
			{
				if (resizeFlag)
				{document.layers["footer_layer"].visibility = "show"}
			}
		}
		if (!document.all && document.getElementById && document.getElementById("footer_layer")!=null)
		{
	//		footerY = document.images["leftMenuLineBottom"].y;
			moveTopDivs(document.getElementById("footer_layer").style, document.images["backtotopspacer"].y, document.images["backtotopspacer"].x);
			if (document.images["backtotopspacer"].y > footerY)
			{
				if (resizeFlag)
				{document.getElementById("footer_layer").style.visibility = "visible"}
			}
		}
	}
}

function drawSitemap(){

document.writeln("<table cellspacing=0 cellpadding=4 border=0 width=\"100%\">");
 for (var i=1; i<x; i++){

	if (menuObj[i].sitemap=="Y"){
		if (menuObj[i].hasChild=="Y"){		
			document.writeln("<tr><td><img src=\"../images/inside_bullet.jpg\" border=0 width=10 alt=\"*\"></td><td width=100%>"+menuObj[i].caption+"</td></tr>");
		}else{
			document.writeln("<tr><td><img src=\"../images/inside_bullet.jpg\" border=0 width=10 alt=\"*\"></td><td width=100%><a href=\""+menuObj[i].url+"\">"+menuObj[i].caption+"</a></td></tr>");
		}

		if (menuObj[i].hasChild=="Y"){
			document.writeln("<tr><td>&nbsp;</td><td><table cellspacing=0 cellpadding=4 border=0 width=\"100%\">");
			for (var j=1; j<y; j++){
				if (subMenuObj[j].sitemap=="Y" && subMenuObj[j].menuID == menuObj[i].id){
					document.writeln("<tr><td width=10><img src=\"../images/inside_bullet2.jpg\" border=0 alt=\"*\"></td><td width=100%><a href=\""+subMenuObj[j].url+"\">"+subMenuObj[j].caption+"</a></td></tr>");			
				}
			}
			document.writeln("</table></td></tr>");
		}// end check whether this menuObj has child
	}//end check show in sitemap

 }
document.writeln("</table>");

}


function drawTopButton(){
	document.write("<table cellspacing=0 cellpadding=0 width=100% border=0>");
	document.write("<tr><td align=right nowrap width=100%><br><a href=\"#top\" onmouseout=\"javascript:switchTopPic(0,"+topButtoncount+");\" onmouseover=\"javascript:switchTopPic(1,"+topButtoncount+");\"><img name=\"backtotopfoot"+topButtoncount+"\" src=\""+imagePath+"top.gif\" border=0 alt=\"Top\"></a></td></tr>");
	document.write("</table>");
	topButtoncount++;
}


