var siteXML;
var objDom;
var langPath;
var top_menu_1;
var top_menu_2;
var top_menu_3;
var top_menu_4;
var stock_link;
var navType;
var timerID;
var maxTime;
var timerTag = false;
var loadXmlTime = 0;

function startTimer(){
	//alert("aa");
	maxTime += 100;
	if(objDom){
		initalPage();
		clearInterval(timerID);
	}else
		timerTag = true;
	if(maxTime == 3000){
		clearInterval(timerID);
	}
}

function initalPage(){
	//alert(navType);
	type = navType;
	// Type 2: Generate sitemap.
	// Other: Generate navigation.
	if (!((level1 == "") && (level2 == "") && (level3 == "") && (level4 == ""))){
		setTimeout("genTopMenu('143')",1000);
		setTimeout("genTopMenu('144')",2000);
		setTimeout("genTopMenu('145')",3000);
		setTimeout("genTopMenu('146')",4000);
		setTimeout("genTopMenu('414')",5000);
		setTimeout("genPromoMenu('subnav_107')",6000);
		setTimeout("genToolsMenu('subnav_109')",6000);
	}
}

function onLoadEvent(){
	startTimer();
	if(timerTag == true)
		timerID = setInterval("startTimer()",50);
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {  
    window.onload = function() {
      oldonload();
      func();
    }
  }
}


function requestNav(type){
	//alert(navType + "aaaa" + type);
	navType = type;
	var xmlhttp=false;	

	if (lang == 'tc') {
		langPath = '/tc/';
	} else if (lang == 'sc') {
		langPath = '/sc/';
	} else {
		langPath = '/en/';
	}
	var url = langPath + '/common/xml/sitemap.xml';
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		xmlhttp = new XMLHttpRequest();
		if (xmlhttp.overrideMimeType) {
			xmlhttp.overrideMimeType('text/xml');
		}
	} else if (window.ActiveXObject) { // IE
		try {
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}

	if (!xmlhttp) {
		alert('Cannot generate navigation for your browser!');
	} else {
		xmlhttp.open("GET",url,true);
		try {
			xmlhttp.onreadystatechange=function() {
				if (xmlhttp.readyState==4) {					
					siteXML = xmlhttp.responseText;
					
					addLoadEvent(onLoadEvent);
					
					objDom = new XMLDoc('');
					objDom.loadXML(siteXML);
					if(type==2) {
						genSitemap();
					} else {
						if (document.getElementById('divTop')) {
							setTimeout('genTop()', 30);
						}
						
						if (document.getElementById('divFooter')) {
							setTimeout('genFooter()', 30);
						}
						// Grab current sitemap node's login type.
						if (document.getElementById('divLogin')) {
							setTimeout('genLogin()', 30);
						}
						
						if (document.getElementById('divLeft')) {
							setTimeout('genLeft()', 30);
						}
						
						if (document.getElementById('divCards')) {
							setTimeout('genCards()', 30);
						}
						
						if (document.getElementById('divRightPanel')) {
							setTimeout('genRightPanel()', 30);
						}
					}
				}		
			}			
			xmlhttp.send(null);
		} catch (err) {
			if(loadXmlTime < 6){
				setTimeout('countLoadXml()', 30);
			}else{
				if((lang == 'tc') || (lang == 'sc'))
					alert("網頁讀取出現錯誤，請重試。");
				else
					alert('Page loading encounters errors, please retry.');
			}
		}
	}
	
	// Clear cookies on page change.
	var pressPath = readCookie('PressReleasePath');
	var tmp = location.href.replace(/\/(tc|en)\//,"/lang/");
	
	if (pressPath != tmp) {
		eraseCookie('DahSingPressYear');
		eraseCookie('PressReleasePath');
	}
}

function countLoadXml(){
	loadXmlTime ++;
	requestNav(navType);
}
 
function genLogin() {

	var tagPath = '/section/*[@id="' + level1 + '"]';
	if (level2!='') tagPath += '/*[@id="' + level2 + '"]';
	if (level3!='') tagPath += '/*[@id="' + level3 + '"]';
	if (level4!='') tagPath += '/*[@id="' + level4 + '"]';
	
	var curNode = objDom.selectNode(tagPath);
	var bgimage = '';
	
	type = curNode.getAttribute('loginType');
	
	if (type != "4") {
	
		var lvl1site = objDom.selectNode('/section/*[@id="' + level1 + '"]');

		tempHtml = '<!-- Login Start --><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td valign="top" style="background:url(/common/images/common/bg_ebanking.gif) no-repeat; height:68px;">';
		if(lvl1site.getAttribute('link').indexOf('/commercial_banking/') > -1) {
			if (lang == 'en') {
				bgimage = '/common/images/common/title_ibanking_en.gif';
			} else if(lang == 'tc') {
				bgimage = '/common/images/common/title_ibanking.gif';
			}
			tempHtml += '<table width="186px" border="0" cellspacing="0" cellpadding="0">';
			try {		
				tempHtml += '<tr><td colspan="2" style="padding:9px 0px 0px 7px;"><img src="' + bgimage + '" border="0" /></td></tr><tr valign="top">';
				// Grab the login image.
				curNode = objDom.selectNode('/section[@name="login"]/section[@name="CBDLoginImage"]');
				tempHtml += '<td width="91" style="padding:2px 0px 0px 55px;"><a href="' + curNode.getAttribute('link') + '"><img src="' + curNode.getAttribute('image') + '" alt="' + unescape(curNode.getAttribute('title_image')) + '" width="91" height="27" border="0" /></a></td>';

			} catch (err) {
				tempHtml += '<tr><td colspan="2" style="padding:9px 0px 0px 7px;">Unable to retrieve login information...</td></tr>';
			}
			tempHtml += '</table>';
		} else {
			if (lang == 'en') {
				bgimage = '/common/images/common/title_ebanking_en.gif';
			} else if(lang == 'tc') {
				bgimage = '/common/images/common/title_ebanking.gif';
			}
			tempHtml += '<table width="186px" border="0" cellspacing="0" cellpadding="0">';
			try {		
				tempHtml += '<tr><td colspan="2" style="padding:9px 0px 0px 7px;"><img src="' + bgimage + '" border="0" /></td></tr><tr valign="top">';
				// Grab the login image.
				curNode = objDom.selectNode('/section[@name="login"]/section[@name="loginImage"]');
				tempHtml += '<td width="91" style="padding:2px 0px 0px 25px;"><a href="' + curNode.getAttribute('link') + '"><img src="' + curNode.getAttribute('image') + '" alt="' + unescape(curNode.getAttribute('title_image')) + '" width="91" height="27" border="0" /></a></td>';
				
				// Grab the no password name.
				curNode = objDom.selectNode('/section[@name="login"]/section[@name="noPassword"]/section');
				tempHtml += '<td width="109" style="padding:5px 0px 0px 5px;" class="nopassword"><a href="' + curNode.getAttribute('link') + '" class="nopassword"><u>' + unescape(curNode.getAttribute('name')) +'</u></a></td></tr>';
			} catch (err) {
				tempHtml += '<tr><td colspan="2" style="padding:9px 0px 0px 7px;">Unable to retrieve login information...</td></tr>';
			}
			tempHtml += '</table>';
		}
		
		tempHtml += '</td></tr><tr><td><img src="/common/images/common/login_top.gif" width="200" height="3" /></td></tr><tr><td valign="top" style="background:url(/common/images/common/bg_login.gif) repeat-y;"><table width="100%" border="0" cellspacing="0" cellpadding="0">';
		
		// Grab Login items for Login Type.
		try {		
			var curNode = objDom.selectNode('/section[@name="login"]/section[@name="loginType' + type + '"]');
			if (curNode) {
				var a1 = curNode.getElements().length;
				for(var i=0;i<a1;i++) {
					var name = curNode.getElements()[i].getAttribute('name');
					var link = curNode.getElements()[i].getAttribute('link');
					var target = curNode.getElements()[i].getAttribute('target');

					tempHtml += '<tr valign="top"><td width="8" height="23" style="padding:6px 8px 0px 15px;"><img src="/common/images/common/icon_lock.gif" width="8" height="11" /></td><td style="padding:5px 8px 0px 0px;" class="content"><a href="' + link + '" target="' + target + '" class="content">' + unescape(name) + '<img src="/common/images/common/arrow_red.gif" width="4" height="5" hspace="8" align="absmiddle" border="0" /></a></td></tr>';
				}
			} else {
				throw('Node not found');
			}
		} catch (err) {
			tempHtml += '<tr valign="top"><td colspan="2">Unable to retrieve login type...</td></tr>';
		}
		
		tempHtml += '</table></td></tr><tr><td><img src="/common/images/common/bg_login_b.gif" width="200" height="14"></td></tr></table>';
	} else {
		var login_link = "";
		if (lang == 'en') {
			bgimage = '/common/images/common/title_applynow_en.gif';
			login_link = 'javascript:NewWindow(\'http://dimension.jobsdb.com/career/Default.asp?PID=1&AC=DSFG&EC=001&GC=&LID=1&SP=1&ATZA62434023618698\',\'rate\',900,600,\'yes\',\'no\');';
		} else if(lang == 'tc') {
			bgimage = '/common/images/common/title_applynow.gif';
			login_link = 'javascript:NewWindow(\'http://dimension.jobsdb.com/career/Default.asp?PID=1&AC=DSFG&EC=001&GC=&LID=2&GID=&HKB175957888364792\',\'rate\',900,600,\'yes\',\'no\');';
		}
		tempHtml = '<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td valign="top" style="background:url(/common/images/common/bg_ebanking.gif) no-repeat; height:68px;"><table width="186px" border="0" cellspacing="0" cellpadding="0">';
		try {		
			tempHtml += '<tr><td colspan="2" style="padding:5px 0px 0px 7px;"><img src="' + bgimage + '" border="0" /></td></tr><tr valign="top">';
			// Grab the login image.
			curNode = objDom.selectNode('/section[@name="login"]/section[@name="loginImage"]');
			tempHtml += '<td style="padding:2px 0px 0px 55px;"><a href="' + login_link + '"><img src="' + curNode.getAttribute('image') + '" alt="' + unescape(curNode.getAttribute('name')) + '" width="91" height="27" border="0" /></a></td>';
		} catch (err) {
			tempHtml += '<tr><td colspan="2" style="padding:9px 0px 0px 7px;">Unable to retrieve login information...</td></tr>';
		}
		tempHtml += '</table></td></tr><tr><td><img src="/common/images/common/login_top.gif" width="200" height="3" /></td></tr><tr><td valign="top" style="background:url(/common/images/common/bg_login.gif) repeat-y;"><table width="100%" border="0" cellspacing="0" cellpadding="0">';
		// Grab Login items for Login Type.
		try {		
			var curNode = objDom.selectNode('/section[@name="login"]/section[@name="loginType' + type + '"]');
			if (curNode) {
				var a2 = curNode.getElements().length;
				for(var i=0;i<a2;i++) {
					var name = curNode.getElements()[i].getAttribute('name');
					var link = curNode.getElements()[i].getAttribute('link');
					var target = curNode.getElements()[i].getAttribute('target');

					tempHtml += '<tr valign="top"><td width="8" height="23" align=\"right\" style="padding:10px 5px 0px 15px;"><img src="/common/images/common/dot.gif" /></td><td style="padding:1px 8px 0px 0px;" class="content"><a href="' + link + '" target="' + target + '" class="content">' + unescape(name) + '<img src="/common/images/common/arrow_red.gif" width="4" height="5" hspace="8" align="absmiddle" border="0" /></a></td></tr>';
				}
			} else {
				throw('Node not found');
			}
		} catch (err) {
			tempHtml += '<tr valign="top"><td colspan="2">Unable to retrieve login type...</td></tr>';
		}
		tempHtml += '</table></td></tr><tr><td><img src="/common/images/common/bg_login_b.gif" width="200" height="14"></td></tr></table><!-- Login End -->';
	}
	
	document.getElementById('divLogin').innerHTML = tempHtml;
	
}

function genTop() {

	var topID;
	var topPromoID = "";
	var topToolsID = "";
	
	tempHtml = '<!-- Top Start --><table width="987" border="0" cellspacing="0" cellpadding="0" align="center"><tr><td><div style="visibility:show; position:relative;"><table width="987" border="0" cellspacing="0" cellpadding="0"><tr><td><table width="100%" border="0" cellspacing="0" cellpadding="0" id="topNav"><tr valign="top"><td width="203" style="padding:22px 0px 12px 0px;"><a href="' + langPath + 'html/index.html"><img src="/common/images/common/logo.gif" hspace="11" border="0" /></a></td><td width="784" height="100%"><table width="100%" border="0" cellspacing="0" cellpadding="0" height="100%"><tr><td valign="top" align="right" style="padding:10px 0px 0px 0px;"><table border="0" cellspacing="0" cellpadding="0"><tr>';
	
	/* -----------------------------------------------------
	 * Generate Topmost items for Top menu.
	 * ------------------------------------------------------
	 */
	try {		
		var curNode = objDom.selectNode('/section[@name="top"]');
		if (curNode) {
			var a3 = curNode.getElements().length;
			tempHtml += '<td><img src="/common/images/common/line_v.gif" width="1" height="7"></td>';
			for(var i=0;i<a3;i++) {
				var name = curNode.getElements()[i].getAttribute('name');
				var link = curNode.getElements()[i].getAttribute('link');
				var target = curNode.getElements()[i].getAttribute('target');
				var unescape_str = unescape(name);
			
				if (unescape_str.indexOf("@") != -1){
					unescape_str = unescape_str.replace(/@/, "");
					if (unescape_str != "Eng"){		//change to Eng
						if (haveOtherLang != "f"){		
							tempHtml += '<td class="topnav" style="padding:0px 10px 0px 10px;"><span style="vertical-align:middle; font-size:9px;font-family:Verdana, Arial;" onClick="changelang();">中文</span></td><td><img src="/common/images/common/line_v.gif" width="1" height="7"></td>';
						} else {
							tempHtml += '<td class="topnav2" style="padding:0px 10px 0px 10px;"><span style="vertical-align:middle;color: #EEEEEE; font-size:9px;font-family:Verdana, Arial;">中文</span></td><td><img src="/common/images/common/line_v.gif" width="1" height="7"></td>';
						}
					} else {		// change to Non-Eng => Chin
						if (haveOtherLang != "f"){	
							tempHtml += '<td class="topnav" style="padding:0px 10px 0px 10px;"><span style="vertical-align:middle;font-size:10px;font-family:Verdana, Arial;" onClick="changelang();">Eng</span></td><td><img src="/common/images/common/line_v.gif" width="1" height="7"></td>';
						} else {
							tempHtml += '<td class="topnav2" style="padding:0px 10px 0px 10px;"><span style="vertical-align:middle;color: #EEEEEE; font-size:10px;font-family:Verdana, Arial;">Eng</span></td><td><img src="/common/images/common/line_v.gif" width="1" height="7"></td>';
						}
					}
				} else {
					var cssclass = 'topnav';
					if (curNode.getElements()[i].getAttribute('id')==level1) {
						cssclass = 'topnav2';
					}
					tempHtml += '<td class="topnav" style="padding:0px 10px 0px 10px;"><a href="' + link + '" target="' + target + '" class="' + cssclass + '">' + unescape(name) + '</a></td><td><img src="/common/images/common/line_v.gif" width="1" height="7"></td>';
				}
			
			}
		} else {
			throw('Node not found');
		}
	} catch (err) {
		tempHtml += '<td class="topnav">Unable to retrieve topmost items...</td>';
	}
	
	tempHtml += '</tr></table></td></tr><tr><td valign="bottom" style="padding:25px 0px 1px 0px;">';

	/* -----------------------------------------------------
	 * Generate Section Front items on Top menu.
	 * ------------------------------------------------------
	 */
	tempHtml += '<table border="0" cellspacing="0" cellpadding="0"><tr>';
	
	try {	
		var curNode = objDom.selectNode('/section[@name="section"]');		
		
		if (curNode) {
			var a4 = curNode.getElements().length;
			topID = new Array(a4);
			
			for(var i=0;i<a4;i++) {
				
				var image = curNode.getElements()[i].getAttribute('image');				

				if (image.length>0) {
					topID[i] = curNode.getElements()[i].getAttribute('id');
					var name = curNode.getElements()[i].getAttribute('name');
					var link = curNode.getElements()[i].getAttribute('link');				
					var target = curNode.getElements()[i].getAttribute('target');
					var m_image = curNode.getElements()[i].getAttribute('mouseover_image');
					
					if (topID[i] == level1) {
						tempHtml += '<td><a href="' + link + '" target="' + target + '" onMouseOut="MM_showHideLayers(\'subnav_' + topID[i] + '\',\'\',\'hide\');" onMouseOver="MM_showHideLayers(\'subnav_' + topID[i] + '\',\'\',\'show\');genTopMenu(\'' + topID[i] + '\');"><img src="' + m_image + '" alt="' + unescape(name) + '" border="0" name="btn_' + topID[i] + '" /></a></td>';
					} else {	
						tempHtml += '<td><a href="' + link + '" target="' + target + '" onMouseOut="MM_swapImgRestore(); MM_showHideLayers(\'subnav_' + topID[i] + '\',\'\',\'hide\');" onMouseOver="MM_swapImage(\'btn_' + topID[i] + '\',\'\',\'' + m_image + '\',1); MM_showHideLayers(\'subnav_' + topID[i] + '\',\'\',\'show\');genTopMenu(\'' + topID[i] + '\');"><img src="' + image + '" alt="' + unescape(name) + '" border="0" name="btn_' + topID[i] + '" /></a></td>';
					}

				}
			}
				
		} else {
			throw('Node not found');
		}
	} catch (err) {
		tempHtml += '<td>Unable to retrieve Section Front items...</td>';
	}

	/* -----------------------------------------------------
	 * Generate Promotion Front on Top menu.
	 * ------------------------------------------------------
	 */
	try {		
		var curNode = objDom.selectNode('/section[@name="promotion"]');
		if (curNode) {

			var image = curNode.getAttribute('image');

			if (image.length>0) {
				topPromoID = curNode.getAttribute('id');
				var name = curNode.getAttribute('name');
				var link = curNode.getAttribute('link');				
				var target = curNode.getAttribute('target');
				var title = curNode.getAttribute('title_image');
				var m_image = curNode.getAttribute('mouseover_image');
				tempHtml += '<td><a href="' + link + '" target="' + target + '" onMouseOut="javascript:showCCPullDown();MM_swapImgRestore(); MM_showHideLayers(\'subnav_' + topPromoID + '\',\'\',\'hide\');" onMouseOver="hideCCPullDown();genPromoMenu(\'subnav_' + topPromoID + '\');MM_swapImage(\'btn_' + topPromoID + '\',\'\',\'' + m_image + '\',1); MM_showHideLayers(\'subnav_' + topPromoID + '\',\'\',\'show\');"><img  src="' + image + '" alt="' + unescape(title) + '" border="0" name="btn_' + topPromoID + '" /></a></td>';
			}				
		} else {
			throw('Node not found');
		}
	} catch (err) {
		tempHtml += '<td>Unable to retrieve Promotion Front...</td>';
	}

	/* -----------------------------------------------------
	 * Generate Tools Front on Top menu.
	 * ------------------------------------------------------
	 */
	try {	
		var curNode = objDom.selectNode('/section[@name="tools"]');
		if (curNode) {
			var image = curNode.getAttribute('image');
			if (image.length>0) {
				topToolsID = curNode.getAttribute('id');
				var name = curNode.getAttribute('name');
				var link = curNode.getAttribute('link');				
				var target = curNode.getAttribute('target');
				var title = curNode.getAttribute('title_image');
				var m_image = curNode.getAttribute('mouseover_image');
				tempHtml += '<td><a href="' + link + '" target="' + target + '" onMouseOut="javascript:showCCPullDown();MM_swapImgRestore(); MM_showHideLayers(\'subnav_' + topToolsID + '\',\'\',\'hide\');" onMouseOver="hideCCPullDown();genToolsMenu(\'subnav_' + topToolsID + '\');MM_swapImage(\'btn_' + topToolsID + '\',\'\',\'' + m_image + '\',1); MM_showHideLayers(\'subnav_' + topToolsID + '\',\'\',\'show\');"><img src="' + image + '" alt="' + unescape(title) + '" border="0" name="btn_' + topToolsID + '" /></a></td>';
			}				
		} else {
			throw('Node not found');
		}
	} catch (err) {
		tempHtml += '<td>Unable to retrieve Tools Front...</td>';
	}

	tempHtml += '</tr></table>';

	var absTop = "73";
	if (lang == "tc") {
		absTop = "75";
	}
	/* -----------------------------------------------------
	 * Generate Section items on Top menu.
	 * ------------------------------------------------------
	 */
	
	try {	
		var curNode = objDom.selectNode('/section[@name="section"]');	
		if (curNode) {
			var a5 = curNode.getElements().length;
			for(var i=0;i<a5;i++) {
				var lvl1Node = curNode.getElements()[i];				
				if (lvl1Node.getAttribute('showAtTop')=="true"){
					var m_image = curNode.getElements()[i].getAttribute('mouseover_image');
					tempHtml += '<div style="z-index:100;visibility:hidden; position:absolute; left:203px; top:' + absTop + 'px; padding:1px 0px 0px 0px;" id="subnav_' + topID[i] + '" onMouseOver="MM_swapImage(\'btn_' + topID[i] + '\',\'\',\'' + m_image + '\',1);MM_showHideLayers(\'subnav_' + topID[i] + '\',\'\',\'show\');" onMouseOut="MM_showHideLayers(\'subnav_' + topID[i] + '\',\'\',\'hide\');MM_swapImgRestore();"></div>';
				}
			}
		}
	} catch(err) {
	}
	
	tempHtml += '<div style="z-index:100;visibility:hidden; position:absolute; left:792px; top:' + absTop + 'px; width:189px; border-left:#A54E6A 1px solid; border-right:#A54E6A 1px solid; border-bottom:#A54E6A 1px solid; padding:0px 2px 0px 2px; background-color:#FFFFFF;" id="subnav_' + topPromoID + '" onMouseOver="hideCCPullDown();javascript:MM_showHideLayers(\'subnav_' + topPromoID + '\',\'\',\'show\');" onMouseOut="javascript:MM_showHideLayers(\'subnav_' + topPromoID + '\',\'\',\'hide\');javascript:showCCPullDown();"></div><div style="z-index:100;visibility:hidden; position:absolute; left:792px; top:' + absTop + 'px; width:189px; border-left:#A54E6A 1px solid; border-right:#A54E6A 1px solid; border-bottom:#A54E6A 1px solid; padding:0px 2px 0px 2px; background-color:#FFFFFF;" id="subnav_' + topToolsID + '" onMouseOver="hideCCPullDown();javascript:MM_showHideLayers(\'subnav_' + topToolsID + '\',\'\',\'show\');" onMouseOut="javascript:MM_showHideLayers(\'subnav_' + topToolsID + '\',\'\',\'hide\');javascript:showCCPullDown();"></div></td></tr></table></td></tr></table><!-- Top End -->';

	document.getElementById('divTop').innerHTML = tempHtml;
/*	
	try {	
		var curNode = objDom.selectNode('/section[@name="section"]');		
		
		if (curNode) {
			var a4 = curNode.getElements().length;
			topID = new Array(a4);
			
			for(var i=0;i<a4;i++) {
				topID[i] = curNode.getElements()[i].getAttribute('id');
				genTopMenu(topID[i]);
			}
		}
	} catch (err) {
		//alert(err);
	}
*/
}

function genFooter() {
	var tempHtml = '';
	tempHtml += '<!-- Footer Start --><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td align="right"><table border="0" cellspacing="0" cellpadding="0" id="footer"><tr bgcolor="#F0F0F0"><td><img src="/common/images/common/footer_l.gif" width="8" height="22"></td><td class="footer" style="padding:0px 5px 0px 5px;">';
	
	// Grab footer items for Footer.
	try {
		var curNode = objDom.selectNode('/section[@name="footer"]');
		if (curNode) {
			// Loop through footer elements 0 to n-1.
			var a6 = curNode.getElements().length-1;
			for(var i=0;i<a6;i++) {
				var name = curNode.getElements()[i].getAttribute('name');
				var link = curNode.getElements()[i].getAttribute('link');
				if (link.length!=0) {
					var target = curNode.getElements()[i].getAttribute('target');
					tempHtml += '&nbsp;&nbsp;<a href="' + link + '" target="' + target + '" class="footer">' + unescape(name) + '</a>&nbsp;&nbsp;|';
				} else {
					tempHtml += '&nbsp;&nbsp;' + unescape(name) + '&nbsp;&nbsp;|';
				}
			}
			
			// Finally add the last element.
			var name = curNode.getElements()[a6].getAttribute('name');
			var link = curNode.getElements()[a6].getAttribute('link');			

			if (link.length!=0) {
				var target = curNode.getElements()[a6].getAttribute('target');
				tempHtml += '&nbsp;&nbsp;<a href="' + link + '" target="' + target + '">' + unescape(name) + '</a>';
			} else {
				tempHtml += '&nbsp;&nbsp;' + unescape(name);
			}
		} else {
			throw('Node not found');
		}
	} catch (err) {
		tempHtml += 'Unable to retrieve footer items...';
	}
	
	tempHtml += '</td><td><img src="/common/images/common/footer_r.gif" width="8" height="22"></td></tr></table></td></tr></table><!-- Footer End -->';
	
	document.getElementById('divFooter').innerHTML = tempHtml;
}

function genLeft() {

	var tempHtml = '<!-- Left Start -->';
	var tagPath = '/section/*[@id="' + level1 + '"]';
	if (level2!='') tagPath += '/*[@id="' + level2 + '"]';
	if (level3!='') tagPath += '/*[@id="' + level3 + '"]';
	if (level4!='') tagPath += '/*[@id="' + level4 + '"]';
	var curNode = objDom.selectNode(tagPath);
	type = curNode.getAttribute('loginType');
	
	if(type!="4") {
		try {
			// Determine current section and grab its children.
			var lvl1Node = objDom.selectNode('/section/section[@id="' + level1 + '"]');		
			
			if (!lvl1Node) throw ('Level 1 node not found!');
			
			tempHtml += '<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td style="padding:5px 0px 0px 12px;"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr valign="top"><td><img src="' + lvl1Node.getAttribute('title_image') + '" alt="' + unescape(lvl1Node.getAttribute('name')) + '" /></td></tr><tr valign="top"><td style="padding:7px 0px 0px 0px"><table width="100%" border="0" cellspacing="0" cellpadding="3">';

			// Generate a row for each lvl 2 child with attribute "showAtLeft" set to true.
			var i1 = lvl1Node.getElements().length;
			for(var i=0;i<i1;i++) {
				var lvl2Node = lvl1Node.getElements()[i];
				if (lvl2Node.getAttribute('showAtLeft').toLowerCase() == 'true') {
				
					// Check to see if this lvl 2 node is selected.
					var lvl2Name = unescape(lvl2Node.getAttribute('name'));
					
					if (level2.toLowerCase() == lvl2Node.getAttribute('id').toLowerCase()) {
						lvl2Name = '<strong>' + lvl2Name + '</strong>';
					}
					
					tempHtml += '<tr valign="top"><td width="1%" style="padding:9px 0px 0px 1px;"><img src="/common/images/common/arrow_red.gif" width="4" height="5" /></td><td class="content"><a href="' + lvl2Node.getAttribute('link') + '" target="' + lvl2Node.getAttribute('target') + '" class="content">' + lvl2Name + '</a></td></tr>';

					// Check to see if lvl 3 Nodes are required.
					var i2 = lvl2Node.getElements().length;
					if(level2.toLowerCase() == lvl2Node.getAttribute('id').toLowerCase() && i2 > 0) {
						tempHtml += '<tr><td colspan="2" style="border-top:#E0E0E0 1px solid; border-bottom:#E0E0E0 1px solid; padding:5px 0px 5px 12px;"><table width="100%" border="0" cellspacing="0" cellpadding="3">';
						
						// Generate a row for each lvl 3 child with attribute "showAtLeft" set to true.
						for(var j=0;j<i2;j++) {
							var lvl3Node = lvl2Node.getElements()[j];
							if (lvl3Node.getAttribute('showAtLeft').toLowerCase() == 'true') {
							
								// Check to see if this lvl 3 node is selected.
								var lvl3Point;
								var lvl3Style;
								if (level3.toLowerCase() == lvl3Node.getAttribute('id').toLowerCase()) {
									lvl3Point = 'pt_purple.gif';
									lvl3Style = ' style="color:#9D3C51;"';
								} else {
									lvl3Point = 'pt_gray.gif';
									lvl3Style = '';
								}
								
								tempHtml += '<tr valign="top"><td width="3" style="padding:10px 6px 0px 2px;"><img src="/common/images/common/' + lvl3Point + '" width="3" height="3" /></td><td class="leftnav"><a href="' + lvl3Node.getAttribute('link') + '" target="' + lvl3Node.getAttribute('target') + '" class="leftnav"' + lvl3Style + '>' + unescape(lvl3Node.getAttribute('name')) + '</a></td></tr>';
							}
							// Check to see if lvl 4 Nodes are required.
							var i3 = lvl3Node.getElements().length;
							if(level3.toLowerCase() == lvl3Node.getAttribute('id').toLowerCase() && i3 > 0) {
								tempHtml += '<tr><td>&nbsp;</td><td style="padding:5px 7px 5px 2px;"><table width="100%" border="0" cellspacing="0" cellpadding="3">';
								
								// Generate a row for each lvl 3 child with attribute "showAtLeft" set to true.
								for(var k=0;k<i3;k++) {
									var lvl4Node = lvl3Node.getElements()[k];
									if (lvl4Node.getAttribute('showAtLeft').toLowerCase() == 'true') {
									
										// Check to see if this lvl 4 node is selected.
										var lvl4Point;
										var lvl4Style;
										if (level4.toLowerCase() == lvl4Node.getAttribute('id').toLowerCase()) {
											lvl4Point = '#9D3C51';
											lvl4Style = ' style="color:#9D3C51;"';
										} else {
											lvl4Point = '';
											lvl4Style = '';
										}
										
										tempHtml += '<tr valign="top"><td width="3" style="padding:0px 6px 0px 2px;"><font color = "' + lvl4Point + '">-</font></td><td class="leftnav"><a href="' + lvl4Node.getAttribute('link') + '" target="' + lvl4Node.getAttribute('target') + '" class="leftnav"' + lvl4Style + '>' + unescape(lvl4Node.getAttribute('name')) + '</a></td></tr>';
									}
								}
								tempHtml += '</table></td></tr>';
							}
						}
						tempHtml += '</table></td></tr>';
					}
				}
			}

			tempHtml += '</table></td></tr></table></td></tr></table><!-- Left End -->';		
		} catch (err) {
			tempHtml = '<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td style="padding:5px 8px 0px 12px;">Unable to retrieve Left menu items...</td></tr></table>';
		}	
	} else {
		try {
			// Determine current section and grab its children.
			var lvl1Node = objDom.selectNode('/section/section[@id="' + level1 + '"]');		
			
			if (!lvl1Node) throw ('Level 1 node not found!');
			
			tempHtml += '<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr valign="top"><td style="padding:0px 0px 0px 0px"><table width="100%" border="0" cellspacing="0" cellpadding="3">';

			// Generate a row for each lvl 2 child with attribute "showAtLeft" set to true.
			var b1 = lvl1Node.getElements().length;
			for(var i=0;i<b1;i++) {
				var lvl2Node = lvl1Node.getElements()[i];
				if (lvl2Node.getAttribute('showAtLeft').toLowerCase() == 'true') {
				
					// add lvl 2 node.
					// Check to see if this lvl 2 node is selected.
					var lvl2Name = unescape(lvl2Node.getAttribute('name'));
					var node_class = 'graduate';
					
					if (level2.toLowerCase() == lvl2Node.getAttribute('id').toLowerCase()) {
						node_class = 'graduate_active';
					}
					
					tempHtml += '<tr valign="top"><td width="1%" style="padding:9px 5px 0px 1px;"><img src="/common/images/common/arrow_red.gif" width="4" height="5" /></td><td class="content"><a href="' + lvl2Node.getAttribute('link') + '" target="' + lvl2Node.getAttribute('target') + '" class="' + node_class + '">' + lvl2Name + '</a></td></tr>';

					if (i==1) {
						tempHtml += '<tr><td colspan="2" style="padding-top:4px;border-top:#E0E0E0 1px solid;"><img src="/common/images/common/spacer.gif" alt="*" /></td></tr>';
					}
					// Check to see if lvl 3 Nodes are required.
					var b2 = lvl2Node.getElements().length;
					if(level2.toLowerCase() == lvl2Node.getAttribute('id').toLowerCase() && b2 > 0) {
						tempHtml += '<tr><td colspan="2" style="padding:4px 0px 5px 12px;"><table width="100%" border="0" cellspacing="0" cellpadding="3">';
						
						// Generate a row for each lvl 3 child with attribute "showAtLeft" set to true.
						
						for(var j=0;j<b2;j++) {
							var lvl3Node = lvl2Node.getElements()[j];
							if (lvl3Node.getAttribute('showAtLeft').toLowerCase() == 'true') {
							
								// Check to see if this lvl 3 node is selected.
								var lvl3Point;
								var lvl3Style;
								if (level3.toLowerCase() == lvl3Node.getAttribute('id').toLowerCase()) {
									lvl3Point = 'pt_purple.gif';
									lvl3Style = ' style="color:#9D3C51;"';
								} else {
									lvl3Point = 'pt_gray.gif';
									lvl3Style = '';
								}
								
								tempHtml += '<tr valign="top"><td width="3" style="padding:10px 6px 0px 2px;"><img src="/common/images/common/' + lvl3Point + '" width="3" height="3" /></td><td class="leftnav"><a href="' + lvl3Node.getAttribute('link') + '" target="' + lvl3Node.getAttribute('target') + '" class="leftnav"' + lvl3Style + '>' + unescape(lvl3Node.getAttribute('name')) + '</a></td></tr>';
							}
						}
						tempHtml += '</table></td></tr><tr><td colspan="2" style="border-top:#E0E0E0 1px solid;padding-bottom:1px;"><img src="/common/images/common/spacer.gif" alt="*" /></td></tr>';
					}
				}
			}

			var description;
			
			if (lang == 'tc') {
				description = '大新銀行是大新集團旗下的一家上市公司。請<a href="/tc/html/aboutus/aboutus.html" class="purple">按此</a>查詢詳情。';
			} else if(lang == 'en'){
				description = 'Dah Sing Bank is one of the listed companies of the Dah Sing Group. Click <a href="/en/html/aboutus/aboutus.html" class="purple">here</a> to find out more.';
			}
			tempHtml += '<tr><td colspan="2" style="padding-top:5px;"><img src="/common/images/common/spacer.gif" alt="*" /></td></tr><tr><td colspan="2" style="border-top:#E0E0E0 1px solid;padding-top:7px;">' + description + '<br /><br /><img src="/common/images/common/caring.gif" /></td></tr></table></td></tr></table></td></tr></table><!-- Left End -->';		
		} catch (err) {
			tempHtml = '<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td style="padding:5px 8px 0px 12px;">Unable to retrieve Left menu items...</td></tr></table>';
		}	
	}
	document.getElementById('divLeft').innerHTML = tempHtml;
}

function genSitemap() {

	var sitemapName;
	
	if (lang == 'tc') {
		sitemapName = "網頁指南";
	} else if (lang == 'sc') {
		sitemapName = "";
	} else {
		sitemapName = "";
	}
	
	var tempHtml = '';
	tempHtml += '<!-- Sitemap Start --><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr valign="top"><td style="border-bottom:#E0E0E0 1px solid; padding:0px 15px 1px 10px;"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr valign="bottom"><td class="title" style="padding:0px 0px 7px 0px;">' + sitemapName + '</td></tr></table></td></tr>';
	try{
		// Determine current section and grab its children.
		var sectionNode = objDom.selectNode('/section[@name="section"]');	
		var c1 = sectionNode.getElements().length;
		// Generate a new section for each level 1 child.
		for(var i=0;i<c1;i++){
			var lvl1Node = sectionNode.getElements()[i];
			
			tempHtml += '<tr><td style="padding:15px 15px 0px 10px; border-bottom:#E0E0E0 1px solid;"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td class="purple" colspan="3"><strong><a href="' + lvl1Node.getAttribute('link') + '" class="purple" target="' + lvl1Node.getAttribute('target') + '">' + unescape(lvl1Node.getAttribute('name')) + '</a></strong></td></tr>';
			
			var showOnSitemapLvl2 = new Array();
			var showOnSitemapLvl2NoChild = new Array();
			var noChildHtml = '';
			var c2 = lvl1Node.getElements().length;
			for(var j=0;j<c2;j++) {
				var lvl2ID = lvl1Node.getElements()[j].getAttribute('id');
				if(lvl1Node.getElements()[j].getAttribute('showOnSitemap').toLowerCase() == 'true') {
					if (objDom.selectNode('/section/section/section[@id="' + lvl2ID +'"]/section[@showOnSitemap="true"]')) {
						// Add lvl 2 subsections where the attribute "showOnSitemap" equals true inside this section and has at
						// least one child with attribute "showOnSitemap" equals true.
						showOnSitemapLvl2.push(lvl2ID);
					} else {
						// Add lvl 2 subsections where the attribute "showOnSitemap" equals true inside this section and has no children
						// with attribute "showOnSitemap" equals true.
						showOnSitemapLvl2NoChild.push(lvl2ID);
					}
				}
			}
			
			// Prepare the html for lvl 2 sections with no children to be displayed at the top.
			if (showOnSitemapLvl2NoChild.length > 0) {
				noChildHtml += '<td style="padding:0px 20px 15px 0px;"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr valign="top"><td><table width="100%" border="0" cellspacing="0" cellpadding="3">';
				
				var f1 = showOnSitemapLvl2NoChild.length;
				for (var j=0; j<f1;j++) {
					var lvl2Node = objDom.selectNode('/section/section/section[@id="' + showOnSitemapLvl2NoChild[j] + '"]');
					
					noChildHtml += '<tr valign="top"><td style="padding:10px 3px 0px 1px;"><img src="/common/images/common/arrow_red.gif" width="4" height="5" /></td><td width="100%" class="purple"><a href="' + lvl2Node.getAttribute('link') + '" class="purple" target="' + lvl2Node.getAttribute('target') + '">' + unescape(lvl2Node.getAttribute('name')) + '</a></td></tr>';
				}
				noChildHtml += '</table></td></tr></table></td>';			
			}
			
			var displayedCount = showOnSitemapLvl2.length;
			// Generate a new table row for every 3 items.
			for(var j=0;j<Math.ceil(showOnSitemapLvl2.length/3);j++) {
				tempHtml += '<tr valign="top">';

				for(var k=0;k<Math.min(3,displayedCount);k++) {
					var lvl2Node = objDom.selectNode('/section/section/section[@id="' + showOnSitemapLvl2[k+j*3] + '"]');
					var lvl2Name = unescape(lvl2Node.getAttribute('name'));
					
					tempHtml += '<td width="33%" style="padding:0px 20px 15px 0px;"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr valign="top"><td><table width="100%" border="0" cellspacing="0" cellpadding="3"><tr valign="top"><td style="padding:10px 3px 0px 1px;"><img src="/common/images/common/arrow_red.gif" width="4" height="5" /></td><td width="100%" class="purple"><a href="' + lvl2Node.getAttribute('link') + '" target="' + lvl2Node.getAttribute('target') + '" class="purple">' + lvl2Name + '</a></td></tr><tr valign="top"><td>&nbsp;</td><td style="padding:0px;"><table width="100%" border="0" cellspacing="0" cellpadding="3">';
					var c3 = lvl2Node.getElements().length;
					for(var l=0;l<c3;l++) {
						var lvl3Node = lvl2Node.getElements()[l];
						if (lvl3Node.getAttribute('showOnSitemap').toLowerCase() == 'true') {
							tempHtml += '<tr valign="top"><td style="padding:10px 5px 0px 6px;"><img src="/common/images/common/pt_gray.gif" width="3" height="3" /></td><td width="100%" class="leftnav"><a href="' + lvl3Node.getAttribute('link') + '" class="leftnav" target="' + lvl3Node.getAttribute('target') + '">' + unescape(lvl3Node.getAttribute('name')) + '</a></td></tr>';
						}
					}
					tempHtml += '</table></td></tr></table></td></tr></table></td>';
										
				}
				
				// Check to see if this is the last row and if there are any lvl 2 sections with no show on sitemap children and if they can be displayed on current row.
				if(j == Math.ceil(showOnSitemapLvl2.length/3)-1 && showOnSitemapLvl2NoChild.length > 0 && showOnSitemapLvl2.length % 3 > 0) {
					tempHtml += noChildHtml;
				}
				
				tempHtml += '</tr>';
				displayedCount -= 3;
			}

			// Check to see if are any lvl 2 sections with no show on sitemap children and if they need to be displayed on a new row.
			if(showOnSitemapLvl2NoChild.length > 0 && showOnSitemapLvl2.length % 3 == 0) {
				tempHtml += '<tr valign="top">'+noChildHtml+'</tr>';
			}
				
			tempHtml += '</table></td></tr></table></td></tr>';
		}
	} catch (err) {
		tempHtml = '<tr><td style="padding:15px 15px 0px 10px; border-bottom:#E0E0E0 1px solid;">Unable to retrieve sitemap information...</td></tr>';
	}
	
	tempHtml += '</table><!-- Sitemap End -->';
	
	document.getElementById('divSitemap').innerHTML = tempHtml;
}


function genCards() {

	var tempHtml = '<!-- Card Start --><table cellpadding="0" cellspacing="0" border="0"><tr><td align="center"><table width="166" border="0" cellspacing="0" cellpadding="2">';

	try {
		var lvl4Node = objDom.selectNode('/section/*[@id="' + level1 + '"]/*[@id="' + level2 + '"]/*[@id="' + level3 + '"]/*[@id="' + level4 + '"]');
		
		tempHtml += '<tr><td colspan="2" class="title" style="padding:10px 10px 5px 3px; border-bottom:#E0E0E0 1px solid;">' + unescape(lvl4Node.getAttribute('name')) + '</td></tr>';	
		
		var d1 = lvl4Node.getElements().length;
		for(var i=0;i<d1;i++) {
			var lvl5Node = lvl4Node.getElements()[i];
			if (lvl5Node.getAttribute('showOnDropdown').toLowerCase() == 'true') {
				tempHtml += '<tr valign="top"><td width="1%" align="center" style="padding:10px 5px 2px 5px;"><img src="/common/images/common/pt_purple.gif" width="3" height="3"></td><td><a href="' + lvl5Node.getAttribute('link') +'" class="content">' + unescape(lvl5Node.getAttribute('name')) +'</a></td></tr>';
			}
		}
	} catch (err) {
		tempHtml += '<tr valign="top"><td width="1%" align="center" style="padding:10px 5px 2px 5px;"><img src="/common/images/common/pt_purple.gif" width="3" height="3"></td><td>Unable to retrieve cards...</td></tr>';
	}
	
	tempHtml += '<tr><td align="right" colspan="2" class="title" style="padding:5px 3px 5px 10px; border-top:#E0E0E0 1px solid;"><a href="/'+lang+'/html/credit_card/cardinfo/cardinfo.html" class="title">&gt;';
	if (lang=='tc') {
		tempHtml += '更多';
	} else if(lang=='en') {
		tempHtml += 'More';
	}
	tempHtml += '</a></td></tr></table></td></tr></table><!-- Card End -->';
	
	document.getElementById('divCards').innerHTML = tempHtml;
}

function genPromoMenu(menu) {
	if (document.getElementById(menu).innerHTML.length > 0){return false;}
	var tempHtml = '<!-- Promo Start --><table width="100%" border="0" cellspacing="0" cellpadding="0">';

	// Grab promotion items for site navigation.
	try {	
		var curNode = objDom.selectNode('/section[@name="promotion"]');
		if (curNode) {
			var a7 = curNode.getElements().length-1;
			for(var i=0;i<a7;i++) {
				var name = curNode.getElements()[i].getAttribute('name');
				var image = curNode.getElements()[i].getAttribute('image');

				if (image.length>0) {
					var link = curNode.getElements()[i].getAttribute('link');
					var target = curNode.getElements()[i].getAttribute('target');
					tempHtml += '<tr valign="top"><td width="53" style="padding:5px; background:url(/common/images/common/shadow.gif) repeat-x bottom;"><a href="' + link + '" target="' + target + '"><img src="' + image + '" width="53" height="40" border="0" alt="' + unescape(name) + '" /></a></td><td width="136" style="padding:5px; background:url(/common/images/common/shadow.gif) repeat-x bottom;"><a href="' + link + '" target="' + target + '" class="subnav">' + unescape(name) + '</a></td></tr>';
				} else {
					tempHtml += '<tr><td colspan="2" style="padding:5px;" class="purple" height="40">' + unescape(name) + '</td></tr>';
				}
				
				tempHtml += '<tr><td colspan="2" bgcolor="#CCCCCC"><img src="/common/images/common/spacer.gif" width="189" height="1" /></td></tr>';
			}
			
			var name = curNode.getElements()[a7].getAttribute('name');			
			var image = curNode.getElements()[a7].getAttribute('image');
			
			if (image.length>0) {
				var link = curNode.getElements()[a7].getAttribute('link');
				var target = curNode.getElements()[a7].getAttribute('target');
				tempHtml += '<tr valign="top"><td width="53" style="padding:5px; background:url(/common/images/common/shadow.gif) repeat-x bottom;"><a href="' + link + '" target="' + target + '"><img src="' + image + '" width="53" height="40" border="0" alt="' + unescape(name) + '" /></a></td><td style="padding:5px; background:url(/common/images/common/shadow.gif) repeat-x bottom;"><a href="' + link + '" target="' + target + '" class="subnav">' + unescape(name) + '</a></td></tr>';
			} else {
				tempHtml += '<tr><td colspan="2" style="padding:5px;" class="purple" height="40">' + unescape(name) + '</td></tr>';
			}
				
		} else {
			throw('Node not found');
		}
	} catch (err) {
		tempHtml += '<tr><td colspan="2" style="padding:5px;" class="content" height="40">Unable to retrieve Promotion items...</td></tr>';
	}

	tempHtml += '</table><!-- Promo End -->';
	document.getElementById(menu).innerHTML = tempHtml;
}

function genToolsMenu(menu) {
	if (document.getElementById(menu).innerHTML.length > 0){return false;}
	var tempHtml = '<!-- Tools Start --><div style="position:relative;"><table width="100%" border="0" cellspacing="0" cellpadding="0">';
	
	try {	
		var curNode = objDom.selectNode('/section[@name="tools"]');
		if (curNode) {
			var a8 = curNode.getElements().length;
			for(var i=0;i<a8;i++) {
				var name = curNode.getElements()[i].getAttribute('name');				
				var image = curNode.getElements()[i].getAttribute('image');

				if (image.length>0) {
					var link = curNode.getElements()[i].getAttribute('link');
					var target = curNode.getElements()[i].getAttribute('target');
					tempHtml += '<tr valign="bottom"><td style="border:#DEDEDE 1px solid;"><a href="' + link + '" target="' + target + '"><img src="' + image + '" border="0" alt="' + unescape(name) + '" /></a></td></tr><tr><td bgcolor="#CCCCCC" style="border-top:#FFFFFF 1px solid; border-bottom:#FFFFFF 1px solid;"><img src="/common/images/common/spacer.gif" width="1" height="1" /></td></tr>';
				} else {
					tempHtml += '<tr><td colspan="2" style="padding:5px;" class="purple" height="40">' + unescape(name) + '</td></tr>';
				}
			}
				
		} else {
			throw('Node not found');
		}
	} catch (err) {
		tempHtml += '<tr><td style="border:#DEDEDE 1px solid;">Unable to retrieve Tools items...</td></tr>';
	}

	tempHtml += '</table></div><!-- Tools End -->';
	document.getElementById(menu).innerHTML = tempHtml;
}

function genTopMenu(menu) {
	if (!document.getElementById('subnav_'+menu)) {return false;}
	if (document.getElementById('subnav_'+menu).innerHTML.length > 0){return false;}
	var tempHtml = '';
	
	var lvl1Node = objDom.selectNode('/section[@name="section"]/section[@id="'+ menu +'"]');
	var showAtTopLvl2 = new Array();
	var showAtTopLvl2NoChild = new Array();
	var noChildHtml = '';
	var col_counter = 0;
	var border = '';

	if (lang=="en") {
		switch(menu) {
			case '143':
				border = '<img src="/common/images/common/section_top_1_en.png" alt="*"/>';
				break;
			case '144':
				border = '<img src="/common/images/common/section_top_3_en.png" alt="*"/>';
				break;
			case '145':
				border = '<img src="/common/images/common/section_top_2_en.png" alt="*"/>';
				break;
			case '146':
				border = '<img src="/common/images/common/section_top_4_en.png" alt="*"/>';
				break;
			default:
				break;
		}
	} else {
		switch(menu) {
			case '143':
				border = '<img src="/common/images/common/section_top_1_tc.png" alt="*"/>';
				break;
			case '144':
				border = '<img src="/common/images/common/section_top_3_tc.png" alt="*"/>';
				break;
			case '145':
				border = '<img src="/common/images/common/section_top_2_tc.png" alt="*"/>';
				break;
			case '146':
				border = '<img src="/common/images/common/section_top_4_tc.png" alt="*"/>';
				break;
			default:
				break;
		}
	}
		if (lang != 'en'){ // for chinese site
			tempHtml += '<!-- Top Section Start -->' + border + '<table width="593" border="0" cellspacing="0" cellpadding="0" bgcolor="#FFFFFF" height="279"><tr valign="top"><td width="3" style="background:url(/common/images/common/bg_layer_l.gif) repeat-y left;"><img src="/common/images/common/spacer.gif" width="3" height="1"></td><td width="587" style="padding:5px 10px 0px 15px;"><table width="100%" border="0" cellspacing="0" cellpadding="0">';
		} else {	// for english site
			tempHtml += '<!-- Top Section Start -->' + border + '<table width="593" border="0" cellspacing="0" cellpadding="0" bgcolor="#FFFFFF" height="285"><tr valign="top"><td width="3" style="background:url(/common/images/common/bg_layer_l.gif) repeat-y left;"><img src="/common/images/common/spacer.gif" width="3" height="1"></td><td width="587" style="padding:5px 10px 0px 15px;"><table width="100%" border="0" cellspacing="0" cellpadding="0">';
		}
	var t1 = lvl1Node.getElements().length;
	for(var j=0;j<t1;j++) {
		var lvl2ID = lvl1Node.getElements()[j].getAttribute('id');
		if(lvl1Node.getElements()[j].getAttribute('showAtTop').toLowerCase() == 'true') {
			
			if (objDom.selectNode('/section/section/section[@id="' + lvl2ID +'"]/section[@showAtTop="true"]')) {
				// Add lvl 2 subsections where the attribute "showAtTop" equals true inside this section and has at
				// least one child with attribute "showAtTop" equals true.
				showAtTopLvl2.push(lvl2ID);
			} else {
				// Add lvl 2 subsections where the attribute "showAtTop" equals true inside this section and has no children
				// with attribute "showAtTop" equals true.
				showAtTopLvl2NoChild.push(lvl2ID);
			}
		}
	}
	// Prepare the html for lvl 2 sections with no children to be displayed at the top && less than 5 items.
	if (showAtTopLvl2NoChild.length > 0 && showAtTopLvl2NoChild.length <= 4) {
			noChildHtml += '<td width="183" style="padding:5px 0px 13px 0px;" height="100%"><table width="100%" border="0" cellspacing="0" cellpadding="0" height="100%"><tr valign="top"><td style="padding:0px 0px 5px 0px;"><table width="100%" border="0" cellspacing="0" cellpadding="2">';
			var display_new_colume = 4;
			var additional_col = 0;
			
			for (var j=0; j<showAtTopLvl2NoChild.length;j++) {
				var lvl2Node = objDom.selectNode('/section/section/section[@id="' + showAtTopLvl2NoChild[j] + '"]');
				noChildHtml += '<tr valign="top"><td colspan="2"><a class="purple" href="' + lvl2Node.getAttribute('link') + '" target="' + lvl2Node.getAttribute('target') + '"><strong>' + unescape(lvl2Node.getAttribute('name')) + '</strong></a></td></tr>';
				display_new_colume--;
			}
			noChildHtml += '</table></td></tr></table></td>';			
	}
	
	var displayedCount = showAtTopLvl2.length;
	var printNoChildHtml = true;
	var used_col = 0;
	// Generate a new table row for every 3 items.
	for(var j=0;j<Math.ceil(showAtTopLvl2.length/3);j++) {
		tempHtml += '<tr valign="top">';
		for(var k=0;k<Math.min(3,displayedCount);k++) {
			var lvl2Node = objDom.selectNode('/section/section/section[@id="' + showAtTopLvl2[k+j*3] + '"]');
			var lvl2Name = lvl2Node.getAttribute('name');
			used_col++;
			// Do not show bottom border if this is the last row and the no child section does not require a new row.
			if (j <Math.ceil(showAtTopLvl2.length/3)-1 || (showAtTopLvl2NoChild.length > 0 && showAtTopLvl2.length % 3 == 0) || (showAtTopLvl2NoChild.length > 8 && showAtTopLvl2.length % 3 == 1) || (showAtTopLvl2NoChild.length > 4 && showAtTopLvl2.length % 3 == 2)) {
				tempHtml += '<td width="183" style="padding:0px 0px 17px 0px; border-bottom:#C2C2C2 1px solid;" height="100%">';								
			} else {
				tempHtml += '<td style="padding:5px 0px 17px 0px;" height="100%">';
			}
			tempHtml += '<table width="100%" border="0" cellspacing="0" cellpadding="0" height="100%"><tr valign="top"><td style="padding:0px 0px 5px 0px;"><table width="100%" border="0" cellspacing="0" cellpadding="2"><tr valign="top"><td colspan="2"><strong><a class="purple" href="' + lvl2Node.getAttribute('link') + '" target="' + lvl2Node.getAttribute('target') + '">' + unescape(lvl2Name) + '</a></strong></td></tr>';
			
			// Add the lvl 3 children that needs to be shown at the top to an array.
			var showAtTopLvl3 = new Array();
			var z1 = lvl2Node.getElements().length;
			for (var l=0;l<z1;l++) {
				if (lvl2Node.getElements()[l].getAttribute('showAtTop').toLowerCase() == 'true')
					showAtTopLvl3.push(lvl2Node.getElements()[l].getAttribute('id'));
			}
			
			// Display the level 3 children.
			var z2 = showAtTopLvl3.length;
			for (var l=0;l<Math.min(3,z2);l++) {
				var lvl3Node = objDom.selectNode('/section/section/section/section[@id="' + showAtTopLvl3[l] + '"]');
				
				tempHtml += '<tr valign="top"><td width="4" style="padding:8px 0px 0px 0px;"><img src="/common/images/common/arrow_gray.gif" /></td><td><div style="width:170px;padding-left:5px;"><a href="' + lvl3Node.getAttribute('link') + '" target="' + lvl3Node.getAttribute('target') + '" class="subnav">' + unescape(lvl3Node.getAttribute('name')) + '</a></div></td></tr>';
			}
			tempHtml += '</table></td></tr>';
			
			// Display more button if there are more than 3 children that needs to be shown at the top.
			// More button links to lvl2 section front page.						
			if (z2>3) {
				var lvl2ID = lvl2Node.getAttribute('id');
				tempHtml += '<tr><td height="15"><a href="' + lvl2Node.getAttribute('link') + '" target="' + lvl2Node.getAttribute('target') + '" onMouseOut="MM_swapImgRestore();" onMouseOver="MM_swapImage(\'more_' + lvl2ID + '\',\'\',\'' + langPath + 'images/common/btn_more_f2.gif\',1);"><img src="' + langPath + 'images/common/btn_more.gif" border="0" name="more_' + lvl2ID + '"></a></td></tr>';
			}
			tempHtml += '</table></td><td><img src="/common/images/common/spacer.gif" width="1" height="1" /></td>';
			col_counter++;
		}
		
	
	var do_print_dump_col = false;
	if ((col_counter % 3 == 1) && (menu == '146')){
		do_print_dump_col = true;
		//tempHtml += '<td><img src="/common/images/common/spacer.gif" width="1" height="1" /></td><td width="183" style="padding:5px 0px 13px 0px;" height="100%"><table width="100%" border="0" cellspacing="0" cellpadding="0" height="100%"><tr valign="top"><td style="padding:0px 0px 5px 0px;">xxxxxxxxxxxxxxxxxxx</td></tr></table></td>';
	}
		// Check to see if this is the last row and if there are any lvl 2 sections with no show at top children and if they can be displayed on current row.
		if(j == Math.ceil(showAtTopLvl2.length/3)-1 && showAtTopLvl2NoChild.length > 0 && showAtTopLvl2.length % 3 > 0 && showAtTopLvl2NoChild.length <= 4) {
			tempHtml += noChildHtml;
			printNoChildHtml = false;
		}
		if (!printNoChildHtml){
			if (do_print_dump_col){
				tempHtml += '<td><img src="/common/images/common/spacer.gif" width="1" height="1" /></td><td width="183" style="padding:5px 0px 13px 0px;" height="100%"><table width="100%" border="0" cellspacing="0" cellpadding="0" height="100%"><tr valign="top"><td style="padding:0px 0px 5px 0px;">&nbsp;</td></tr></table></td>';
			}
			tempHtml += '</tr>';
		}
		// Decrease displayedCount by 3.
		displayedCount -= 3;
	}
	
	// Check to see if are any lvl 2 sections with no show at top children and if they need to be displayed on a new row.
	if(showAtTopLvl2NoChild.length > 0 && showAtTopLvl2.length % 3 == 0) {
		tempHtml += '<tr valign="top">' + noChildHtml + '</tr>';
	} else if (printNoChildHtml) {		// add by tim @ 20080229
		// Prepare the html for lvl 2 sections with no children to be displayed at the top && more than 4 items.
		
		if (showAtTopLvl2NoChild.length > 4) {
			var additional_col = 0;
			var j = 0;
			var k = 0;
			var nextline = true;
			var show_bottom = true;
			noChildHtml = '';
				switch (used_col % 3){
					case 1:
						additional_col = 2;
    					show_bottom = false;		//special case =.=
						break;
					case 2:
						additional_col = 1;
						break;
					default:
						additional_col = 3;
						break;
				}
				for(var k=additional_col; k>0; k--){
					used_col++;
					nextline = true;
					if (show_bottom){
						noChildHtml += '<td width="183" style="padding:5px 0px 0px 0px; border-bottom:#C2C2C2 1px solid;" height="100%">';
					} else {
						noChildHtml += '<td width="183" style="padding:5px 0px 0px 0px;" height="100%">';
					}
					noChildHtml += '<table width="100%" border="0" cellspacing="0" cellpadding="0" height="100%"><tr valign="top"><td style="padding:0px 0px 0px 0px;"><table width="100%" border="0" cellspacing="0" cellpadding="2">';

					do{
						var lvl2Node = objDom.selectNode('/section/section/section[@id="' + showAtTopLvl2NoChild[j] + '"]');
						if (!lvl2Node) {j++;continue;}
						noChildHtml += '<tr valign="top"><td colspan="2"><a class="purple" href="' + lvl2Node.getAttribute('link') + '" target="' + lvl2Node.getAttribute('target') + '"><strong>' + unescape(lvl2Node.getAttribute('name')) + '</strong></a></td></tr>';
						j++;
						if (j%4==0 && j!=0){
							nextline = false;
						}
					} while (nextline && j<=40);
					noChildHtml += '</table></td></tr></table></td><td><img src="/common/images/common/spacer.gif" width="1" height="1" /></td>';
					col_counter++;
				} 
				noChildHtml += '</tr><tr valign="top">';
				
				noChildHtml += '<td width="183" style="padding:5px 0px 0px 0px;" height="100%"><table width="100%" border="0" cellspacing="0" cellpadding="0" height="100%"><tr valign="top"><td style="padding:0px 0px 0px 0px;"><table width="100%" border="0" cellspacing="0" cellpadding="2">';

	//edit by tim @ 20080516	=============    Start    ===============

				var jj = 0;
				var jj1 = showAtTopLvl2NoChild.length;
				for (j; j<jj1;j++) {
					var lvl2Node = objDom.selectNode('/section/section/section[@id="' + showAtTopLvl2NoChild[j] + '"]');
					noChildHtml += '<tr valign="top"><td colspan="2"><a class="purple" href="' + lvl2Node.getAttribute('link') + '" target="' + lvl2Node.getAttribute('target') + '"><strong>' + unescape(lvl2Node.getAttribute('name')) + '</strong></a></td></tr>';
					
					if (jj % 3 == 0 && jj != 0){
						noChildHtml += '</table></td></tr></table></td><td><img src="/common/images/common/spacer.gif" width="1" height="1" /></td><td width="183" style="padding:5px 0px 0px 0px;" height="100%"><table width="100%" border="0" cellspacing="0" cellpadding="0" height="100%"><tr valign="top"><td style="padding:0px 0px 0px 0px;"><table width="100%" border="0" cellspacing="0" cellpadding="2">';
					}
					jj++;
				}

	//edit by tim @ 20080516	=============    End    ===============
				
				noChildHtml += '</table></td></tr></table></td></tr>';			
	
		}

		tempHtml += noChildHtml;		

		
	}
	
	tempHtml += '</table></td><td width="3" style="background:url(/common/images/common/bg_layer_r.gif) repeat-y right;"><img src="/common/images/common/spacer.gif" width="3" height="1"></td></tr><tr><td height="2"><img src="/common/images/common/layer_l.gif" width="3" height="2"></td><td style="background:url(/common/images/common/bg_layer_b.gif) repeat-x;"><img src="/common/images/common/spacer.gif" width="3" height="1"></td><td><img src="/common/images/common/layer_r.gif" width="3" height="2"></td></tr></table></div><!-- Top Section End -->';

	document.getElementById('subnav_'+menu).innerHTML = tempHtml;
	//	document.getElementById('subnav_'+menu).style.visibility = "hidden";
}
/*
function showTopMenu(menu){
	document.getElementById('subnav_'+menu).style.visibility = "visible";
}
*/

function change_stock(){
var code = document.getElementById('STOCKCODE').value;
alert(code);
stock_link = 'http://gateway.etnet.com.hk/DahSing/eng/public-DLSS.html?STOCKCODE=' + code;
}

function genRightPanel() {
	//if (document.getElementById('divRightPanel').innerHTML.length > 0){return false;}
	var rightpanel = objDom.selectNode('/section[@name=\"rightpanel\"]');
	var nodecount = 96;
	for (var i=0; i<nodecount;i++) {
		var labelImage = "";
		var labelTitle = "";
		var labelHtml = "";
		var nodeLink = "";
		var labelTarget = "";
		var node;
		
		switch(i) {
			case 0 :
				node = objDom.selectNode('/section/section[@name="wealth_management"]/section[@name="Fund_Search"]');
				labelName = "lblWMFundSearch";
				break;
			case 1 :
				node = objDom.selectNode('/section/section[@name="wealth_management"]/section[@name="Fund_Price"]');
				labelName = "lblWMFundPrice";
				break;
			case 2 :
				node = objDom.selectNode('/section/section[@name="wealth_management"]/section[@name="Stock_Quote"]');
				labelName = "lblWMStockQuote";
				break;
			case 3 :
				node = objDom.selectNode('/section/section[@name="wealth_management"]/section[@name="Company_Info"]');
				labelName = "lblWMCompanyInfo";
				break;
			case 4 :
				node = objDom.selectNode('/section/section[@name="wealth_management"]/section[@name="Company_Chart"]');
				labelName = "lblWMCompanyChart";
				break;
			case 5 :
				node = objDom.selectNode('/section/section[@name="wealth_management"]/section[@name="Branches"]');
				labelName = "lblWMBranches";
				break;
			case 6 :
				node = objDom.selectNode('/section/section[@name="wealth_management"]/section[@name="Enquiry_Hotline"]');
				labelName = "lblWMEnquiryHotline";
				break;
			case 7 :
				node = objDom.selectNode('/section/section[@name="credit_card"]/section[@name="Application_Hotline"]');
				labelName = "lblCCApplicationHotline";
				break;
			case 8 :
				node = objDom.selectNode('/section/section[@name="credit_card"]/section[@name="Fax_Application"]');
				labelName = "lblCCFaxApplication";
				break;
			case 9 :
				node = objDom.selectNode('/section/section[@name="credit_card"]/section[@name="APITA_Hotline"]');
				labelName = "lblCCAPITA";
				break;
			case 10 :
				node = objDom.selectNode('/section/section[@name="credit_card"]/section[@name="Gift_Card_Hotline"]');
				labelName = "lblCCGiftCard";
				break;
			case 11 :
				node = objDom.selectNode('/section/section[@name="credit_card"]/section[@name="JETSO_Hotline"]');
				labelName = "lblCCJETSO";
				break;
			case 12 :
				node = objDom.selectNode('/section/section[@name="credit_card"]/section[@name="Card_Benefits_Enquiry"]');
				labelName = "lblCCCardBenefitsEnq";
				break;
			case 13 :
				node = objDom.selectNode('/section/section[@name="credit_card"]/section[@name="Card_Benefits_Application"]');
				labelName = "lblCCCardBenefitsApp";
				break;
			case 14 :
				node = objDom.selectNode('/section/section[@name="credit_card"]/section[@name="DSB_Apply_Now"]');
				labelName = "lblCCDSBApplyNow";
				break;
			case 15 :
				node = objDom.selectNode('/section/section[@name="credit_card"]/section[@name="Application_Status_Enquiry"]');
				labelName = "lblCCAppStatusEnq";
				break;
			case 16 :
				node = objDom.selectNode('/section/section[@name="credit_card"]/section[@name="Card_Activation"]');
				labelName = "lblCCCardActivation";
				break;
			case 17 :
				node = objDom.selectNode('/section/section[@name="credit_card"]/section[@name="Application_Forms"]');
				labelName = "lblCCApplicationForm";
				break;
			case 18 :
				node = objDom.selectNode('/section/section[@name="credit_card"]/section[@name="Credit_Limit"]');
				labelName = "lblCCCreditLimit";
				break;
			case 19 :
				node = objDom.selectNode('/section/section[@name="credit_card"]/section[@name="Gift_Card_Balance_Enquiry"]');
				labelName = "lblCCGCBalEnq";			
				break;
			case 20 :
				node = objDom.selectNode('/section/section[@name="credit_card"]/section[@name="Gift_Card_FAQ"]');
				labelName = "lblCCGCFAQ";
				break;
			case 21 :
				node = objDom.selectNode('/section/section[@name="deposit"]/section[@name="Apply_Now"]');
				labelName = "lblDepApplyNow";
				break;
			case 22 :
				node = objDom.selectNode('/section/section[@name="deposit"]/section[@name="Deposit_Hotline"]');
				labelName = "lblDepHotline";				
				break;
			case 23 :
				node = objDom.selectNode('/section/section[@name="deposit"]/section[@name="Rate_Enquiry"]');
				labelName = "lblDepRateEnq";
				break;
			case 24 :
				node = objDom.selectNode('/section/section[@name="deposit"]/section[@name="Kiddie_ebank_thomas"]');
				labelName = "lblDepKiddieThomas";
				break;
			case 25 :
				node = objDom.selectNode('/section/section[@name="deposit"]/section[@name="FAQ"]');
				labelName = "lblDepFAQ";
				break;
			case 26 :
				node = objDom.selectNode('/section/section[@name="deposit"]/section[@name="Savings_Calculator"]');
				labelName = "lblDepSavings";
				break;
			case 27 :
				node = objDom.selectNode('/section/section[@name="ploan"]/section[@name="Application_Hotline"]');
				labelName = "lblPloanHotline";
				break;
				
			case 28 :
				node = objDom.selectNode('/section/section[@name="ploan"]/section[@name="Fax_Application"]');
				labelName = "lblPloanFax";
				break;
			case 29 :
				node = objDom.selectNode('/section/section[@name="ploan"]/section[@name="Apply_Now_1"]');
				labelName = "lblPloanApply1";
				break;
			case 30 :
				node = objDom.selectNode('/section/section[@name="ploan"]/section[@name="SMS_Application"]');
				labelName = "lblPloanSMS";
				break;
			case 31 :
				node = objDom.selectNode('/section/section[@name="ploan"]/section[@name="FlexiMoney_Application"]');
				labelName = "lblPloanFlexiMoney";
				break;
			case 32 :
				node = objDom.selectNode('/section/section[@name="ploan"]/section[@name="Ploan_EMoney_Calculator"]');
				labelName = "lblPloanEMoneyCalculator";
				break;	
			case 33 :
				node = objDom.selectNode('/section/section[@name="ploan"]/section[@name="Branches"]');
				labelName = "lblPloanBranches";
				break;
			case 34 :
				node = objDom.selectNode('/section/section[@name="mortgage"]/section[@name="Apply_Now"]');
				labelName = "lblMortApplyNow";
				break;
			case 35 :
				node = objDom.selectNode('/section/section[@name="mortgage"]/section[@name="Application_Hotline"]');
				labelName = "lblMortHotline";
				break;	
			case 36 :
				node = objDom.selectNode('/section/section[@name="mortgage"]/section[@name="Branches"]');
				labelName = "lblMortBranches";
				break;
				
			case 37 :
				node = objDom.selectNode('/section/section[@name="mortgage"]/section[@name="Online_Val"]');
				labelName = "lblMortOnlineVal";
				break;
			case 38 :
				node = objDom.selectNode('/section/section[@name="mortgage"]/section[@name="Repayment_cal"]');
				labelName = "lblMortRepayment";
				break;
				
	//======================= add by Tim @ 20080519 for download form =============================//				
		
			case 39 :
				node = objDom.selectNode('/section/section[@name="credit_card"]/section[@name="Form_DahSing_Credit_Card"]');
				labelName = "lblForm_Dahsing_credit_card";
				break;
			case 40 :
				node = objDom.selectNode('/section/section[@name="credit_card"]/section[@name="Form_VIP_Visa_Platinum_Credit_Card"]');
				labelName = "lblForm_VIP_Visa_Platinum_Credit_Card";
				break;
			case 41 :
				node = objDom.selectNode('/section/section[@name="credit_card"]/section[@name="Form_DahSing_Business_Card"]');
				labelName = "lblForm_Dahsing_Business_Card";
				break;
			case 42 :
				node = objDom.selectNode('/section/section[@name="credit_card"]/section[@name="Form_DreamHome_Credit_Card"]');
				labelName = "lblForm_DreamHome_Credit_Card";
				break;
			case 43 :
				node = objDom.selectNode('/section/section[@name="credit_card"]/section[@name="Form_Hello_Kitty_Credit_Card"]');
				labelName = "lblForm_Hello_Kitty_Credit_Card";
				break;
			case 44 :
				node = objDom.selectNode('/section/section[@name="credit_card"]/section[@name="Form_Snoopy_Credit_Card"]');
				labelName = "lblForm_Snoopy_Credit_Card";
				break;
			case 45 :
				node = objDom.selectNode('/section/section[@name="credit_card"]/section[@name="Form_My_Melody_Credit_Card"]');
				labelName = "lblForm_My_Melody_Credit_Card";
				break;
			case 46 :
				node = objDom.selectNode('/section/section[@name="credit_card"]/section[@name="Form_Gundum_Credit_Card"]');
				labelName = "lblForm_Gundum_Credit_Card";
				break;
			case 47 :
				node = objDom.selectNode('/section/section[@name="credit_card"]/section[@name="Form_Liverpool_Football_Club_Credit_Card"]');
				labelName = "lblForm_Liverpool_Football_Club_Credit_Card";
				break;
			case 48 :
				node = objDom.selectNode('/section/section[@name="credit_card"]/section[@name="Form_Arsenal_Football_Club_Credit_Card"]');
				labelName = "lblForm_Arsenal_Football_Club_Credit_Card";
				break;
			case 49 :
				node = objDom.selectNode('/section/section[@name="credit_card"]/section[@name="Form_DahSing_Mileage_Plus_MasterCard"]');
				labelName = "lblForm_Dah_Sing_mileage_Plus_MasterCard";
				break;
			case 50 :
				node = objDom.selectNode('/section/section[@name="credit_card"]/section[@name="Form_DahSing_Autotoll_Credit_Card"]');
				labelName = "lblForm_DahSing_Autotoll_Credit_Card";
				break;
			case 51 :
				node = objDom.selectNode('/section/section[@name="credit_card"]/section[@name="Form_DahSing_Apita_Uny_Credit_Card"]');
				labelName = "lblForm_DahSing_Apita_uny_Credit_Card";
				break;
			case 52 :
				node = objDom.selectNode('/section/section[@name="credit_card"]/section[@name="Form_DahSing_Bonjour_Credit_Card"]');
				labelName = "lblForm_Dahsing_Bonjour_Credit_Card";
				break;
			case 53 :
				node = objDom.selectNode('/section/section[@name="credit_card"]/section[@name="Form_DahSing_Acca_Credit_Card"]');
				labelName = "lblForm_DahSing_Acca_Credit_Card";
				break;
			case 54 :
				node = objDom.selectNode('/section/section[@name="credit_card"]/section[@name="Form_Jetso_Cashin"]');
				labelName = "lblForm_Jetso_Cashin";
				break;
			case 55 :
				node = objDom.selectNode('/section/section[@name="credit_card"]/section[@name="Form_Octopus_Aavs"]');
				labelName = "lblForm_Octopus_Aavs";
				break;
			case 56 :
				node = objDom.selectNode('/section/section[@name="credit_card"]/section[@name="Form_YearRound_Offers"]');
				labelName = "lblForm_YearRound_Offers";
				break;
			case 57 :
				node = objDom.selectNode('/section/section[@name="credit_card"]/section[@name="Form_Bonus_Point_Reward"]');
				labelName = "lblForm_Bonus_Point_Reward";
				break;
			case 58 :
				node = objDom.selectNode('/section/section[@name="credit_card"]/section[@name="Form_Star_Rewards"]');
				labelName = "lblForm_Star_Rewards";
				break;
			case 59 :
				node = objDom.selectNode('/section/section[@name="credit_card"]/section[@name="Form_Other"]');
				labelName = "lblForm_Other";
				break;
			case 60 :
				node = objDom.selectNode('/section/section[@name="wealth_management"]/section[@name="Enquiry_Insurance"]');
				labelName = "lblWMEnquiryInsurance";
				break;
			case 61 :
				node = objDom.selectNode('/section/section[@name="credit_card"]/section[@name="Branches"]');
				labelName = "lblCCBranches";
				break;
			case 62 :
				node = objDom.selectNode('/section/section[@name="deposit"]/section[@name="Branches"]');
				labelName = "lblDepBranches";
				break;
			case 63 :
				node = objDom.selectNode('/section/section[@name="ploan"]/section[@name="SME_Hotline"]');
				labelName = "lblPloanSMEHotline";
				break;
			case 64 :
				node = objDom.selectNode('/section/section[@name="ploan"]/section[@name="SME_Fax"]');
				labelName = "lblPloanSMEFax";
				break;
			case 65 :
				node = objDom.selectNode('/section/section[@name="ploan"]/section[@name="SME_Form"]');
				labelName = "lblPloanSMEForm";
				break;
			case 66 :
				node = objDom.selectNode('/section/section[@name="credit_card"]/section[@name="RMB_Apply_Now"]');
				labelName = "lblCCRMBApplyNow";
				break;
			case 67 :
				node = objDom.selectNode('/section/section[@name="credit_card"]/section[@name="DreamHome_Apply_Now"]');
				labelName = "lblCCDHApplyNow";
				break;
			case 68 :
				node = objDom.selectNode('/section/section[@name="credit_card"]/section[@name="HelloKitty_Apply_Now"]');
				labelName = "lblCCHKApplyNow";
				break;
			case 69 :
				node = objDom.selectNode('/section/section[@name="credit_card"]/section[@name="MyMelody_Apply_Now"]');
				labelName = "lblCCMMApplyNow";
				break;
			case 70 :
				node = objDom.selectNode('/section/section[@name="credit_card"]/section[@name="Sesame_Apply_Now"]');
				labelName = "lblCCSesameApplyNow";
				break;
			case 71 :
				node = objDom.selectNode('/section/section[@name="credit_card"]/section[@name="Gundam_Apply_Now"]');
				labelName = "lblCCGundamApplyNow";
				break;
			case 72 :
				node = objDom.selectNode('/section/section[@name="credit_card"]/section[@name="Liverpool_Apply_Now"]');
				labelName = "lblCCLiverpoolApplyNow";
				break;
			case 73 :
				node = objDom.selectNode('/section/section[@name="credit_card"]/section[@name="Arsenal_Apply_Now"]');
				labelName = "lblCCArsenalApplyNow";
				break;
			case 74 :
				node = objDom.selectNode('/section/section[@name="credit_card"]/section[@name="ANA_Apply_Now"]');
				labelName = "lblCCANAApplyNow";
				break;
			case 75 :
				node = objDom.selectNode('/section/section[@name="credit_card"]/section[@name="APITA_Apply_Now"]');
				labelName = "lblCCAPITAApplyNow";
				break;
			case 76 :
				node = objDom.selectNode('/section/section[@name="wealth_management"]/section[@name="Service_Hotline"]');
				labelName = "lblWMServiceHotline";
				break;
			case 77 :
				node = objDom.selectNode('/section/section[@name="ploan"]/section[@name="Form_Express_Money"]');
				labelName = "lblPloanFormExpressMoney";
				break;				
			case 78 :
				node = objDom.selectNode('/section/section[@name="ploan"]/section[@name="Form_Credit_Mastermind"]');
				labelName = "lblPloanFormCreditMastermind";
				break;
			case 79 :
				node = objDom.selectNode('/section/section[@name="ploan"]/section[@name="Form_FlexiMoney"]');
				labelName = "lblPloanFormFlexiMoney";
				break;
			case 80 :
				node = objDom.selectNode('/section/section[@name="ploan"]/section[@name="Form_Instalment_Loan"]');
				labelName = "lblPloanInstalmentForm";
				break;
			case 81 :
				node = objDom.selectNode('/section/section[@name="ploan"]/section[@name="Form_Revolving_Loan"]');
				labelName = "lblPloanRevolvingForm";
				break;
			case 82 :
				node = objDom.selectNode('/section/section[@name="deposit"]/section[@name="Kiddie_ebank_sesame"]');
				labelName = "lblDepKiddieSesame";
				break;
			case 83:
				node = objDom.selectNode('/section/section[@name="ploan"]/section[@name="Ploan_ECash_Calculator"]');
				labelName = "lblPloanECashCalculator";
				break;
			case 84:
				node = objDom.selectNode('/section/section[@name="wealth_management"]/section[@name="VIP_Hotline"]');
				labelName = "lblWMVIPHotline";
				break;
	//======================= add by Tim @ 20080709 for download form =============================//	
			case 85:
				node = objDom.selectNode('/section/section[@name="credit_card"]/section[@name="Apply_Online"]');
				labelName = "lblApplyOnline";
				break;
			case 86:
				node = objDom.selectNode('/section/section[@name="credit_card"]/section[@name="SMS_Hotline_Application"]');
				labelName = "lblSMSHotlineApplication";
				break;
			case 87:
				node = objDom.selectNode('/section/section[@name="ploan"]/section[@name="Apply_Now_2"]');
				labelName = "lblPloanApply2";
				break;
			case 88:
				node = objDom.selectNode('/section/section[@name="ploan"]/section[@name="Apply_Now_3"]');
				labelName = "lblPloanApply3";
				break;
			case 89:
				node = objDom.selectNode('/section/section[@name="ploan"]/section[@name="Apply_Now_4"]');
				labelName = "lblPloanApply4";
				break;
			case 90:
				node = objDom.selectNode('/section/section[@name="credit_card"]/section[@name="Smart_Choice_Phone"]');
				labelName = "lblSmartChoicePhone";
				break;
			case 91:
				node = objDom.selectNode('/section/section[@name="credit_card"]/section[@name="Smart_Choice_Fax"]');
				labelName = "lblSmartChoiceFax";
				break;
			case 92:
				node = objDom.selectNode('/section/section[@name="credit_card"]/section[@name="Smart_Choice_Form"]');
				labelName = "lblSmartChoiceForm";
				break;
			case 93:
				node = objDom.selectNode('/section/section[@name="credit_card"]/section[@name="Batman_Apply_Now"]');
				labelName = "lblBatmanApplyNow";
				break;
			case 94:
				node = objDom.selectNode('/section/section[@name="credit_card"]/section[@name="Form_Batman"]');
				labelName = "lblFormBatman";
				break;
			case 95:
				node = objDom.selectNode('/section/section[@name="credit_card"]/section[@name="Form_Jetso_Instalment"]');
				labelName = "lblFormJetsoInstalment";
				break;
			default:
				break;
		}
		
		var label = document.getElementById(labelName);
		if (label) {
		
		try {
		labelImage = node.getAttribute('image');
		labelImageAlt = node.getAttribute('image_alt');
		labelTitle = node.getAttribute('title_image');
		labelTitle = labelTitle.replace(/&gt;/gi,">");
		labelTitle = labelTitle.replace(/&lt;/gi,"<");
		labelTarget = node.getAttribute('target');
		nodeLink = node.getAttribute('link');
		} catch (err) {
		}
		
		if (labelImageAlt ==undefined){
			labelImageAlt = "";
		}
		
		var sms_tc = "<a href=\"#\" onMouseOut=\"MM_swapImgRestore();showDialog('dialog',0);\" onMouseOver=\"MM_swapImage('icon_phone_popup','','/common/images/common/icon_phone_popup_f2.gif',1);showDialog('dialog',1);\"><img src=\"/common/images/common/icon_phone_popup.gif\" border=\"0\" name=\"icon_phone_popup\" style=\"vertical-align:text-bottom;\"></a><div style=\"position: relative;\"><div id=\"dialog\" style=\"position: absolute; background-color:#FFFFFF; border:#C0C0C0 1px solid; width:205px; padding:11px; left:-157px; visibility:hidden;\" class=\"content\">請順序輸入(1)姓名,(2)貸款額及(3)還款期（例如:林小文、50000、24）。本行將於確認收妥短訊後的下一個工作天安排專人致電發送短訊之手機號碼與客戶跟進申請。個別電訊網絡供應將收取發送手機短訊之費用，收費金額將按電訊網絡供應商而定。</div></div>";
		var sms_en = "<a href=\"#\" onMouseOut=\"MM_swapImgRestore();showDialog('dialog',0);\" onMouseOver=\"MM_swapImage('icon_phone_popup','','/common/images/common/icon_phone_popup_f2.gif',1);showDialog('dialog',1);\"><img src=\"/common/images/common/icon_phone_popup.gif\" border=\"0\" name=\"icon_phone_popup\" style=\"vertical-align:text-bottom;\"></a><div style=\"position: relative;\"><div id=\"dialog\" style=\"position: absolute; background-color:#FFFFFF; border:#C0C0C0 1px solid; width:205px; padding:11px; left:-157px; visibility:hidden;\" class=\"content\">Input (1) Name (2) Loan Amount and (3) Repayment Tenure (if applicable) (e.g. Lam Siu Man, 50000, 24). Our bank will have a designated staff member to follow up with the customer by calling the number from which the SMS was sent on the next working day after receiving the SMS. The individual telephone network provider will charge a fee for the SMS in accordance with their fee charging schedules.<div></div>";
		
		//var stock_quote_tc = '<form action="/tc/html/wealth_management/stockquote.html" method="GET" style="padding:0;"><table cellpadding="0" cellspacing="0"><tr><td valign="middle">股票報價:</td><td valign="middle">&nbsp;<input id="STOCKCODE" type="text" name="STOCKCODE" class="inputfield" style="width:40px;height:22px;" maxlength="5" onkeyup="allow_numeric(this);"></td><td valign="middle" style="padding-top:1px;">&nbsp;<input type="image" src="/tc/images/common/btn_search.gif" value="查詢" alt="查詢" border="0" /></td></tr></table></form>';
		//var stock_quote_en = '<form action="/en/html/wealth_management/stockquote.html" method="GET"><table cellpadding="0" cellspacing="0"><tr><td valign="middle">Stock Quote:</td><td valign="middle">&nbsp;<input id="STOCKCODE" type="text" name="STOCKCODE" class="inputfield" style="width:40px;height:22px;" maxlength="5" onkeyup="allow_numeric(this);"></td><td valign="middle" style="padding-top:1px;">&nbsp;<input type="image" src="/en/images/common/btn_search.gif" value="Search" alt="Search" border="0" /></td></tr></table></form>';
//		var stock_quote_tc = '<form action="/tc/html/wealth_management/stockquote.html" method="GET" style="padding:0;"><table cellpadding="0" cellspacing="0"><tr><td valign="middle">股票報價:</td><td valign="middle">&nbsp;<input id="STOCKCODE" type="text" name="STOCKCODE" class="inputfield" style="width:40px;height:22px;" maxlength="5" onkeyup="allow_numeric(this);"></td><td valign="middle" style="padding-top:1px;">&nbsp;<input type="image" src="/tc/images/common/btn_search.gif" value="查詢" alt="查詢" border="0" /></td></tr></table></form>';
        var stock_quote_tc = '<table cellpadding="0" cellspacing="0"><tr><td valign="middle" nowrap="nowrap">股票報價:</td><td valign="middle">&nbsp;<input id="STOCKCODE" nowrap="nowrap" type="text" name="STOCKCODE" class="inputfield" style="width:40px;height:22px;" maxlength="5" onkeyup="allow_numeric(this);" onkeypress="if (EnterPressed(event)) {callstock2(); return false}"></td><td nowrap="nowrap" valign="middle" style="padding-top:1px;">&nbsp;<img src="/tc/images/common/btn_search.gif" alt="Search" border="0" onclick="cchangeSource()" onclick="cchangeSource()" style="cursor:pointer"/></td></tr></table>';
		var stock_quote_en = '<table cellpadding="0" cellspacing="0" border="0"><tr><td valign="middle">Stock Quote:</td><td valign="middle"><input id="STOCKCODE" type="text" name="STOCKCODE" class="inputfield" style="width:40px;height:22px;" maxlength="5" onkeyup="allow_numeric(this);" onkeypress="if (EnterPressed(event)) {callstock(); return false}" ></td><td nowrap="nowrap" valign="middle" style="padding-top:1px;padding-left:5px"><img src="/en/images/common/btn_search.gif" alt="Search" border="0" onclick="changeSource()" onclick="cchangeSource()" style="cursor:pointer"/></td></tr></table>';
		//var stock_quote_en = '<table cellpadding="0" cellspacing="0"><tr><td valign="middle">Stock Quote:</td><td valign="middle">&nbsp;<input id="STOCKCODE" type="text" name="STOCKCODE" class="inputfield" style="width:40px;height:22px;" maxlength="5" onkeyup="allow_numeric(this);"></td><td valign="middle" style="padding-top:1px;">&nbsp;<a href = "' + stock_link + '" target = "stock_area" ><img src="/en/images/common/btn_search.gif" alt="Search" border="0" onclick="changeSource()"/></td></tr></table>';
		
		if (lang == "tc") {
			labelTitle = labelTitle.replace(/#sms#/i,sms_tc);
			labelTitle = labelTitle.replace(/#Stock_Quote#/i,stock_quote_tc);
		} else if(lang == "en") {
			labelTitle = labelTitle.replace(/#sms#/i,sms_en);
			labelTitle = labelTitle.replace(/#Stock_Quote#/i,stock_quote_en);
		}
		
			var tempHTML = "";
			
			if (labelImage != "" && labelTitle != "") {
				
				if (nodeLink != "") {
					labelTitle = '<a href="' + nodeLink +'" target="' + labelTarget + '">' + labelTitle + '</a>';
				}
			
				tempHTML = '<table cellpadding="0" cellspacing="0"><tr><td valign="top"><img src="' + labelImage + '" alt = "' + labelImageAlt + '" border="0" /></td><td valign="top" align="left" width="150" style="padding-left:10px;">' + labelTitle + '</td></tr></table>';
			} else if(labelImage != "" && labelTitle == "") {
				// Apply Now Buttons
				tempHTML = '<img src="' + labelImage + '" alt = "' + labelImageAlt + '" border="0" />';
				if (nodeLink != "") {
					tempHTML = '<a href="' + nodeLink +'" target="' + labelTarget + '">' + tempHTML + '</a>';
				}
			} else if(labelTitle != "") {
				tempHTML = labelTitle;
				if (nodeLink != "") {
					tempHTML = '<a href="' + nodeLink +'" target="' + labelTarget + '">' + tempHTML + '</a>';
				}
			}			
			
			label.innerHTML = tempHTML;
		}
	}
}

String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

function hideCCPullDown() {

	var pulldownTab = document.getElementById('cardPullDown');
	var pulldown = document.getElementById('cardJump');
	if (pulldownTab) {
		pulldownTab.style.display = "none";
	}
	
	if (pulldown) {
		pulldown.style.display = "none";
	}
}

function showCCPullDown() {
	var pulldownTab = document.getElementById('cardPullDown');
	var pulldown = document.getElementById('cardJump');
	if (pulldownTab) {
		pulldownTab.style.display ="";
	}
		if (pulldown) {
		pulldown.style.display = "";
	}
}


function changeSource()
{

var your_url = location.href;
var is_ok=your_url.indexOf('power_trade_securities_services');

//alert(url);
if (is_ok==-1){
 var url = 'http://gateway.etnet.com.hk/DahSing/eng/public-DLSS.html?STOCKCODE='+ (document.getElementById("STOCKCODE").value);
 if (navigator.appName == 'Microsoft Internet Explorer' )
  {window.frames["stock_area"].location.href = url;
  document.getElementById('STOCKCODE').value ="";}
 else
  { 
   //alert('firefox');
   var stock_url = location.href;
   var is_stockpage = stock_url.indexOf('wealth_management');
   var str_stock = stock_url.substring(0,is_stockpage);
   str_stock = str_stock + "wealth_management/stockquote.html?STOCKCODE=" + (document.getElementById('STOCKCODE').value) +"&x=8&y=9"
   window.location = str_stock;  
   //alert(str_stock);
  }
}

if (is_ok!=-1)
 {
  var str = your_url.substring(0,is_ok);
  str = str + "stockquote.html?STOCKCODE=" + (document.getElementById('STOCKCODE').value) +"&x=8&y=9"
  window.location = str;
  }
  
}

function cchangeSource()
{
//var url = 'http://gateway.etnet.com.hk/DahSing/big5/public-DLSS.html?STOCKCODE='+ (document.getElementById("STOCKCODE").value);
//window.frames["stock_area"].location.href = url;
var your_url = location.href;
var is_ok=your_url.indexOf('power_trade_securities_services');

if (is_ok==-1){
 var url = 'http://gateway.etnet.com.hk/DahSing/big5/public-DLSS.html?STOCKCODE='+ (document.getElementById("STOCKCODE").value);
 if (navigator.appName == 'Microsoft Internet Explorer' )
  {window.frames["stock_area"].location.href = url; document.getElementById('STOCKCODE').value ="";}
 else
  { 
   //alert('firefox');
   var stock_url = location.href;
   var is_stockpage = stock_url.indexOf('wealth_management');
   var str_stock = stock_url.substring(0,is_stockpage);
   str_stock = str_stock + "wealth_management/stockquote.html?STOCKCODE=" + (document.getElementById('STOCKCODE').value) +"&x=8&y=9"
   window.location = str_stock;  
   //alert(str_stock);
  }
}

if (is_ok!=-1)
 {
  var str = your_url.substring(0,is_ok);
  str = str + "stockquote.html?STOCKCODE=" + (document.getElementById('STOCKCODE').value) +"&x=8&y=9"
  window.location = str;
  }

}



function callstock() {
 //alert("xxx");

  var your_url = location.href;
  var is_ok=your_url.indexOf('power_trade_securities_services');
  /*
  if (is_ok==-1){
  var url = 'http://gateway.etnet.com.hk/DahSing/eng/public-DLSS.html?STOCKCODE='+ (document.getElementById("STOCKCODE").value);
  window.frames["stock_area"].location.href = url; 
  document.getElementById('STOCKCODE').value ="";
  }*/
  
  if (is_ok==-1){
   var url = 'http://gateway.etnet.com.hk/DahSing/eng/public-DLSS.html?STOCKCODE='+ (document.getElementById("STOCKCODE").value);
  if (navigator.appName == 'Microsoft Internet Explorer' )
  {window.frames["stock_area"].location.href = url;
   document.getElementById('STOCKCODE').value ="";}
  else
  { 
   //alert('firefox');
   var stock_url = location.href;
   var is_stockpage = stock_url.indexOf('wealth_management');
   var str_stock = stock_url.substring(0,is_stockpage);
   str_stock = str_stock + "wealth_management/stockquote.html?STOCKCODE=" + (document.getElementById('STOCKCODE').value) +"&x=8&y=9"
   window.location = str_stock;  
   //alert(str_stock);
  }
 }

  if (is_ok!=-1)
  {
  var str = your_url.substring(0,is_ok);
  str = str + "stockquote.html?STOCKCODE=" + (document.getElementById('STOCKCODE').value) +"&x=8&y=9"
  window.location = str;
  }
}


function callstock2() {
 //alert("xxx");

  var your_url = location.href;
  var is_ok=your_url.indexOf('power_trade_securities_services');
  /*
  if (is_ok==-1){
  var url = 'http://gateway.etnet.com.hk/DahSing/big5/public-DLSS.html?STOCKCODE='+ (document.getElementById("STOCKCODE").value);
  window.frames["stock_area"].location.href = url;
  document.getElementById('STOCKCODE').value ="";
  }*/
  
 if (is_ok==-1){
  var url = 'http://gateway.etnet.com.hk/DahSing/big5/public-DLSS.html?STOCKCODE='+ (document.getElementById("STOCKCODE").value);
  if (navigator.appName == 'Microsoft Internet Explorer' )
  {window.frames["stock_area"].location.href = url; document.getElementById('STOCKCODE').value ="";}
  else
  { 
   //alert('firefox');
   var stock_url = location.href;
   var is_stockpage = stock_url.indexOf('wealth_management');
   var str_stock = stock_url.substring(0,is_stockpage);
   str_stock = str_stock + "wealth_management/stockquote.html?STOCKCODE=" + (document.getElementById('STOCKCODE').value) +"&x=8&y=9"
   window.location = str_stock;  
   //alert(str_stock);
   }
 }

  if (is_ok!=-1)
  {
  var str = your_url.substring(0,is_ok);
  str = str + "stockquote.html?STOCKCODE=" + (document.getElementById('STOCKCODE').value) +"&x=8&y=9"
  window.location = str;
  }
  

}



function EnterPressed(e) {

  var characterCode
  if(e && e.which){           // NN4 specific code
    e = e
    characterCode = e.which
  }
  else {
    e = event
    characterCode = e.keyCode // IE specific code
  }
  if (characterCode == 13) return true   // Enter key is 13
  else return false
}
