<!--
//Define global variables
var menu_timerID=null;
var menu_timerOn=false;
var menu_timeOut=300;
var menu_check=false;
var menu_count=8;
var h='http' + '://' ;
var d=new String(parent.document.location.host);
var sc=false;

var re = /sc.hangseng.com/i;
if (re.test(d)) 		//detect simplified chinese
	sc=true;
	
function activateMenu() {
	menu_check=true;
	hideAll();
}

function hideAll() {
	for (var i=0;i<menu_count;i++) hideLayer('layernav'+i);
}

function showLayer(l) {
	if (!menu_check) return;
	document.getElementById(l).style.visibility="visible";
}

function hideLayer(l) {
	if (!menu_check) return;
	document.getElementById(l).style.visibility="hidden";
}

function startTime() {
	if (!menu_timerOn) {
		menu_timerID=setTimeout("hideAll()", menu_timeOut);
		menu_timerOn=true;
	}
}

function stopTime() {
	if (menu_timerOn) {
		clearTimeout(menu_timerID);
		menu_timerID=null;
		menu_timerOn=false;
	}
}

function overColor(obj) {	obj.style.backgroundColor='#A3C27C'; }
function normColor(obj) {	obj.style.backgroundColor='#EAFCCC'; }





function initMenu() {
	//check = true;
	//hideAll();
}




function menuKeyPress(e) {
	var keynum;
	if(window.event) { // IE
		keynum = e.keyCode;
	}
	else if(e.which) {// Netscape/Firefox/Opera
		keynum = e.which;
	}

	if (keynum == 13) { // Enter pressed
 		menuSubmitSearch('c');
	}

} 


function submitSearch() {
	var v,x;
	v=document.forms[0].search_fld.value;
	if (v!='') {
		x='http://main.hangseng.com/cgi-bin/AT-hsb_search.cgi?search='+v;
		if (x!='')
			document.location.href=x;
	}
	return false;
}

function goURL(URL) {
	location.href=URL;
}
/*
function writeMenu(menu,idx) {
	html="";
	tempArray=eval(menu+"["+idx+"]");

	if (!isNetscape4) {
		html+='<div id="layer'+menu+idx+'" style="position:absolute; top:'+tempArray[0].top+'px; left:'+tempArray[0].left+'px; z-index:110; visibility:hidden;" onMouseOver="stopTime();" onMouseOut="startTime();">\n';
		if (tempArray.length>1) {
			if (what=="ie") {
				html+='<table cellspacing=0 cellpadding=0 border=0>\n';
				html+='<tr><td bgcolor=black><img src="/hsb/com/spacer.gif" width=1 height=1 border=0></td></tr>\n';
				for (i=1;i<tempArray.length;i++) {
					html+='<tr><td id="'+menu+idx+i+'" class='+menu+'Box onMouseOver=\''+menu+idx+i+'.style.backgroundColor="'+tempArray[0].overcolor+'"\'; onMouseOut=\''+menu+idx+i+'.style.backgroundColor="'+tempArray[0].color+'"\'><a href=';
					tempArray[i].url.indexOf("javascript:") != -1?html+='"javascript:;" onclick="'+tempArray[i].url.substr(11,tempArray[i].url.length-11)+'"':html+='"'+tempArray[i].url+'"';
					if (tempArray[i].target=="secWin") {
						html+=' target="secWin" onclick="eFinetComPopUp(\'cPDM\')"';
					}
					else if (tempArray[i].target!="") {
						html+=' target="'+tempArray[i].target+'"';
					}
					html+=' onMouseOver="stopTime();" onMouseOut="startTime();" class="subnav">'+tempArray[i].name+'</a></td></tr>\n';
				}
				html+='</table>\n';
			}
			else {
				html+='<div style="background-Color:black"><img src="/hsb/com/spacer.gif" width=1 height=1 border=0></div>';
				for (i=1;i<tempArray.length;i++) {
					html+='<div id="'+menu+idx+i+'" class='+menu+'Box onMouseOver="document.getElementById(\''+menu+idx+i+'\').style.backgroundColor=\''+tempArray[0].overcolor+'\'" onMouseOut="document.getElementById(\''+menu+idx+i+'\').style.backgroundColor=\''+tempArray[0].color+'\'"><a href="'+tempArray[i].url+'" onMouseOver="stopTime();" onMouseOut="startTime();" class="subnav"';
					if (tempArray[i].target=="secWin") {
						html+=' target="secWin" onclick="eFinetComPopUp(\'cPDM\')"';
					}
					else if (tempArray[i].target!="") {
						html+=' target="'+tempArray[i].target+'"';
					}
					html+='>'+tempArray[i].name+'</a></div>';
				}
			}
		}
		html+='</div>\n';
	}
	else {
		html+='<layer name="layer'+menu+idx+'" top='+tempArray[0].top+'px left='+tempArray[0].left+'px z-index=110 visibility=hide onMouseOver="stopTime();" onMouseOut="startTime();">\n';
		if (tempArray.length>1) {
			html+='<table cellspacing=0 cellpadding=0 border=0 bgcolor=black><tr>\n';
			html+='<td><table cellspacing=1 cellpadding=2 border=0 bgcolor="'+tempArray[0].color+'">\n';
			for (i=1;i<tempArray.length;i++) {
				html+='<tr><td nowrap><img src="/hsb/com/spacer.gif" width=8 height=1 border=0><a href="'+tempArray[i].url+'" class="subnav"';
				if (tempArray[i].target=="secWin") {
					html+=' target="secWin" onclick="eFinetComPopUp(\'cPDM\')"';
				}
				else if (tempArray[i].target!="") {
					html+=' target="'+tempArray[i].target+'"';
				}
				html+='>'+tempArray[i].name+'</a><img src="/hsb/com/spacer.gif" width=8 height=1 border=0></td></tr>\n';
			}
			html+='</table></td>\n';
			html+='</tr></table>\n';
		}
		html+='</layer>\n';
	}

	document.write(html);
}
*/


var secWin;
function eFinetComPopUp(p) {
	var features = "scrollbars=yes,resizable=yes,top=0,left=0,width=790,height=530";
	var theURL = "";
		
	secWin = open(theURL,"secWin",features);
	if ((document.window != null) && (!secWin.opener)){
		secWin.opener = document.window;
	}
	secWin.focus();
	secWin = true;
}

var invWin;
function eInvcComPopUp() {
	var features = "toolbar=yes,scrollbars=yes,resizable=yes,top=0,left=0,width=700,height=550";
	var theURL = "";
		
	invWin = open(theURL,"eINVCWeb",features);
	if ((document.window != null) && (!invWin.opener)){
		invWin.opener = document.window;
	}
	invWin.focus();
	invWin = true;
}

function eInvcComPopUp2(theURL) {
	var features = "toolbar=yes,scrollbars=yes,resizable=yes,top=0,left=0,width=700,height=550";
		
	invWin = open(theURL,"eINVCWeb",features);
	if ((document.window != null) && (!invWin.opener)){
		invWin.opener = document.window;
	}
	invWin.focus();
	invWin = true;
}

function menuSubmitSearch(lang) {
	var f=document.forms[0];
 	if (validateQuery(lang, f, f.menuSearchInput)) {
	 	f.search.value = trim(f.menuSearchInput.value).substring(0,50);
	if(lang.length==3){
		f.action='http://www.hangseng.com/search/html/'+(lang=='eng'?'eng':'chi')+'/index.asp';
	}
	else{
		f.action='http://www.hangseng.com/search/html/'+(lang=='e'?'eng':'chi')+'/index.asp';
	}
		f.target='_top';
		f.method='post';

		if (f.pageno)
			f.pageno.value=1;

		f.submit();
	}
}

function validateQuery(lang, f, searchField) {
	var query = trim(searchField.value);
	
	if (query == ''){
		searchField.focus();
		if(lang.length==3){
			alert(lang=='eng'?'Please enter search query':'\u8ACB\u8F38\u5165\u641C\u5C0B\u5B57\u4E32');
		}else{
			alert(lang=='e'?'Please enter search query':'\u8ACB\u8F38\u5165\u641C\u5C0B\u5B57\u4E32');
		}
		return;
	}

	var re=/[\"\<\>\'\(\)\%\[\]\\\{\}\.\^\$\*\+\?\|]/;
	if (re.test(query)){
		searchField.focus();
		if(lang.length==3){
			alert(lang=='eng'?'Invalid search query':'\u7121\u6548\u641C\u5C0B\u5B57\u4E32');
		}else{
			alert(lang=='e'?'Invalid search query':'\u7121\u6548\u641C\u5C0B\u5B57\u4E32');
		}
		return;
	}
	
	if (query.length > 50) {
		searchField.focus();
		if(lang.length==3){
			alert(lang=='eng'?'Maximum 50 characters are allowed':'\u6700\u591A\u53EA\u53EF\u8F38\u5165%2050%20\u500B\u5B57');
		}else{
			alert(lang=='e'?'Maximum 50 characters are allowed':'\u6700\u591A\u53EA\u53EF\u8F38\u5165%2050%20\u500B\u5B57');
		}
		return;
	} else {
		// submit the first 50 characters only
		searchField.value = searchField.value.substring(0,50);
	}
	
	return true;	
}

function ltrim(x) {
  return x.replace(/^\s*/,'');
}

function rtrim(x) {
  return x.replace(/\s*$/,'');
}

function trim(x) {
  return ltrim(rtrim(x));
}

function createSubMenu() {
	for (x=0;x<nav.length;x++) {
		writeMenu("nav",x);
	}
}


function goURL(URL) {
	location.href=URL;
}

function writeMenu(menu,idx) {
	html="";
	tempArray=eval(menu+"["+idx+"]");

	if (!isNetscape4) {
		html+='<div id="layer'+menu+idx+'" style="position:absolute; top:'+tempArray[0].top+'px; left:'+tempArray[0].left+'px; z-index:110; visibility:hidden;" onMouseOver="stopTime();" onMouseOut="startTime();">\n';
		if (tempArray.length>1) {
			if (what=="ie") {
				html+='<table cellspacing=0 cellpadding=0 border=0>\n';
				html+='<tr><td bgcolor=black><img src="/hsb/spacer.gif" width=1 height=1 border=0></td></tr>\n';
				for (i=1;i<tempArray.length;i++) {
					html+='<tr><td id="'+menu+idx+i+'" class='+menu+'Box onMouseOver=\''+menu+idx+i+'.style.backgroundColor="'+tempArray[0].overcolor+'"\'; onMouseOut=\''+menu+idx+i+'.style.backgroundColor="'+tempArray[0].color+'"\' onclick="';
					tempArray[i].url.indexOf("javascript:") != -1?html+=tempArray[i].url.substr(11,tempArray[i].url.length-11)+'"><a href="javascript:;"':html+='"><a href="'+tempArray[i].url+'"';
					tempArray[i].target==""?html+=' ':html+=' target="'+tempArray[i].target+'" ';
					html+='onmousedown="return clk(\'' + tempArray[i].sect + '\', \'' +  tempArray[i].to + '\')" onMouseOver="stopTime();" onMouseOut="startTime();" class="subnav">'+tempArray[i].name+'</a></td></tr>\n';
				}
				html+='</table>\n';
			}
			else {
				html+='<div style="background-Color:black"><img src="/hsb/com/spacer.gif" width=1 height=1 border=0></div>';
				for (i=1;i<tempArray.length;i++) {
					html+='<div id="'+menu+idx+i+'" class='+menu+'Box onMouseOver="document.getElementById(\''+menu+idx+i+'\').style.backgroundColor=\''+tempArray[0].overcolor+'\'" onMouseOut="document.getElementById(\''+menu+idx+i+'\').style.backgroundColor=\''+tempArray[0].color+'\'"><a href="'+tempArray[i].url+'" target="'+tempArray[i].target+'" onmousedown="return clk(\'' + tempArray[i].sect + '\', \'' +  tempArray[i].to + '\')" onMouseOver="stopTime();" onMouseOut="startTime();" class="subnav">'+tempArray[i].name+'</a></div>';
				}
			}
		}
		html+='</div>\n';
	}
	else {
		html+='<layer name="layer'+menu+idx+'" top='+tempArray[0].top+'px left='+tempArray[0].left+'px z-index=110 visibility=hide onMouseOver="stopTime();" onMouseOut="startTime();">\n';
		if (tempArray.length>1) {
			html+='<table cellspacing=0 cellpadding=0 border=0 bgcolor=black><tr>\n';
			html+='<td><table cellspacing=1 cellpadding=2 border=0 bgcolor="'+tempArray[0].color+'">\n';
			for (i=1;i<tempArray.length;i++) {
				html+='<tr><td nowrap><img src="/hsb/com/spacer.gif" width=8 height=1 border=0><a href="'+tempArray[i].url+'" target="'+tempArray[i].target+'" class="subnav" onmousedown="return clk(\'' + tempArray[i].sect + '\', \'' +  tempArray[i].to + '\')">'+tempArray[i].name+'</a><img src="/hsb/com/spacer.gif" width=8 height=1 border=0></td></tr>\n';
			}
			html+='</table></td>\n';
			html+='</tr></table>\n';
		}
		html+='</layer>\n';
	}

	document.write(html);
}


function switchTradition() {
	var 	x='';
	var 	s=new	String(parent.document.location);
	var	b='/hsc.html';
	var	p=s.indexOf(b);
	var	d='http' + '://' ;
	var 	h=new String(parent.document.location.host);
	var	e=h+'/gb/'
	var	len=0;

	if (s.length>0) {
		if (p>0) { 
			len = p - (d.length+e.length);
			x=d+s.substr(d.length+e.length,len)+'/hsc.html?From=\'scHome_Tab\'&To=\'cHome\'';
		} else {
			x=d+s.substr(d.length+e.length)+'/hsc.html?From=\'scHome_Tab\'&To=\'cHome\'';
		}
	}

	if (x!='')
		parent.location.href=x;
	//return false;
}

function switchSCEng() {
	var 	x='';
	var 	s=new	String(parent.document.location);
	var	b='/hsc.html';
	var	p=s.indexOf(b);
	var	d='http' + '://' ;
	var 	h=new String(parent.document.location.host);
	
	var	e=h+'/gb/'
	var	len=0;
	
	if (s.length>0) {
		if (p>0) { 
			len = p - (d.length+e.length);
			x=d+s.substr(d.length+e.length,len)+'/hse.html?From=\'scHome_Tab\'&To=\'eHome\'';
		} else {
			x=d+s.substr(d.length+e.length)+'/hse.html?From=\'scHome_Tab\'&To=\'eHome\'';
		}
	}

	if (x!=''){
		x=x.replace("chi","eng");
		parent.location.href=x;
	}
	//return false;
}



function switchTCEng() {
	var 	x='';
	var 	h=new String(parent.document.location.host);
	//var 	h='main.hangseng.com';
	var 	s=new String(parent.document.location);
	var 	b='http' + '://';
	var	sc='';

	if(s.length>0)
		x=b+h+'/hse.html?From=\'cHome_Tab\'&To=\'eHome\'';

	if (x!='')
		parent.location.href=x;
	//return false;
}

function switchEng(){
	var 	h=new String(parent.document.location.host);
	var 	re = /sc.hangseng.com/g;
        if (re.test(h)){
        	switchSCEng();
        }else{
        	switchTCEng();
        } 
		
	
	
}
function switchSC() {
	var 	x='';
	var 	h=new String(parent.document.location.host);
	//var 	h='main.hangseng.com';
	var 	s=new String(parent.document.location);
	var 	b='http' + '://'
	var	sc='';

	var 	re = /main.hangseng.com/i;
        if (re.test(h)) 
		sc = 'sc.hangseng.com';
	else
		sc = 'sc.hangseng.com';
	
	if(s.length>0)
		x=b+sc+'/gb/'+h+'/hsc.html?From=\'cHome_Tab\'&To=\'scHome\'';

	if (x!='')
		parent.location.href=x;
	//return false;
}

//-->
