function lib_bwcheck() { //Browsercheck (needed)
	this.ver=navigator.appVersion
	this.agent=navigator.userAgent
	this.dom=document.getElementById?1:0
	this.opera5=this.agent.indexOf("Opera 5")>-1
	this.ie8=(this.ver.indexOf("MSIE 8")>-1 && this.dom && !this.opera5)?1:0;
	this.ie7=(this.ver.indexOf("MSIE 7")>-1 && this.dom && !this.opera5)?1:0;
	this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0;
	this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
	this.ie=this.ie4||this.ie5||this.ie6||this.ie7||this.ie8
	this.mac=this.agent.indexOf("Mac")>-1
	this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0;
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie8 || this.ie7 || this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5)
	return this
}
var bw=new lib_bwcheck()
var s1="";
var s2="";
var s3="";

//var displayType = "block";
var displayType = "inline";

//if(!bw.ie)
//	displayType = "table-row-group";

function MM_findObj(n, d) //v4.0
{
	var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function swapLang(cuLang, toLang)
{
	var thisURL = window.location.toString();
	var thisLang = cuLang;
	var nextLang = toLang;
	var newLocation = "";
	
	if(s1=="index")
	{
		if(thisLang=="b5")	thisLang = "index_b5.html";
		else if(thisLang=="gb")	thisLang = "index_gb.html";
		else if(thisLang=="en")	thisLang = "index.html";
		
		if(nextLang=="b5")	nextLang = "index_b5.html";
		else if(nextLang=="gb")	nextLang = "index_gb.html";
		else if(nextLang=="en")	nextLang = "index.html";
	}
	else 
	{
		thisLang = "/" + thisLang + "/";
		nextLang = "/" + nextLang + "/";
	}
	
	if(thisURL.indexOf("html") > -1)
	{
		newLocation = thisURL.replace(thisLang, nextLang);
	}
	else
	{
		if(s1=="index")
		{
			if(toLang == "b5")
				newLocation = thisURL + "index_b5.html";
			if(toLang == "gb")
				newLocation = thisURL + "index_gb.html";
		}
	}
	
	if(newLocation.indexOf("#")>-1)	
		window.location = newLocation.substring(0, newLocation.indexOf("#"));
	else
		window.location = newLocation;
}
/*
function swapLang(toLang)
{
	var thisURL = window.location.toString();
	var thisLang = "";
	var nextLang = "";
	
	if((s1=="index") && (toLang == "toB5"))
	{
		thisLang = "index.html";
		nextLang = "index_b5.html";
	}
	else if((s1!="index") && (toLang == "toB5"))
	{
		thisLang = "/en/";
		nextLang = "/b5/";
	}
	else if((s1=="index") && (toLang == "toEN"))
	{
		thisLang = "index_b5.html";
		nextLang = "index.html";
	}
	else if((s1!="index") && (toLang == "toEN"))
	{
		thisLang = "/b5/";
		nextLang = "/en/";
	}
	
	var newLocation = "";
	
	if(thisURL.indexOf("html") > -1)
		newLocation = thisURL.replace(thisLang, nextLang);
	else
		if((s1=="index") && (toLang == "toB5"))
			newLocation = thisURL + "index_b5.html";
	
	if(newLocation.indexOf("#") > -1)
		newLocation = newLocation.replace("#","");
	
	window.location = newLocation;
}
*/
function swapMenu(thisID, nextStatus)
{
	var thisObj = document.getElementById(thisID);
	var thisImg = thisObj.src.toString().substr(thisObj.src.toString().indexOf(thisID), (thisID.length+1))
	var nextImg = thisID;
	
	if(nextStatus == "on")
		nextImg += "b";
	else
		nextImg += "a";
		
	thisObj.src = thisObj.src.toString().replace(thisImg, nextImg);
}

function showNav()
{
	var i=0, j=0;
	var navObj, navLayerObj;
	
	var navArr = ["wealthMgt","assetMgt","corporateFinance",
		      "corporateFinance_ipo",
	              "corporateFinance_corporateMergers","corporateFinance_financialAdv","corporateFinance_capitalMarkets", 	              
			  "about", "about_overview","about_recognition", "about_shkco","mediaCentre", "sustainability",
			"careers","contactUs","about_wealth_management","about_asset_management","about_corporate_finance",
			"about_consumer_finance","about_principal_investments","wealthMgt_investment_service","wealthMgt_shkdirect"];
	
	for (i=0; i<navArr.length; i++)
	{
		navObj = document.getElementById(navArr[i]);

	   if(s1=="index" || s1=="")
		{
			if(navObj)
				navObj.style.display = displayType;
			
			navLayerObj = document.getElementById("wealthMgt_layer");
			
			if(navLayerObj)
				navLayerObj.style.display = displayType;
		}
		else
		{
			if(navObj.id==s1)
			{
				navObj.style.display = displayType;
				navLayerObj = document.getElementById(s1+"_layer");
				
				if(navLayerObj)
					navLayerObj.style.display = displayType;
			}
			else if(navObj.id==s2)
			{
				addClass(navObj,"nav_on");
				navLayerObj = document.getElementById(s2+"_layer");
				
				if(navLayerObj)
					navLayerObj.style.display = displayType;
			}
			else if(navObj.id==s3)
			{
				addClass(navObj,"nav_on");
			}
			else
			{
				//return;
			}
		}
	}
}

function addClass(ele, cname)
{
	if(!ele) return;
	if(!ele.className || ele.className=='') {
		ele.className=cname;
		return;
	}
	var re = new RegExp('\\b' + cname + '\\b', 'g');
	if(re.test(ele.className)) return;	//if already has this className
 	else ele.className += ' ' + cname;
}

function removeClass(ele, cname){
	if(!ele) return;
	if(ele.className && ele.className!=''){
		var re = new RegExp('\\b' + cname + '\\b', 'g');
		ele.className = ele.className.replace(re, '');
		re = new RegExp('\\s+', 'g');	//clear multiple spaces
		ele.className = ele.className.replace(re, ' ');
		re = new RegExp('^\\s+');	//clear leading spaces
		ele.className = ele.className.replace(re, '');
		re = new RegExp('\\s+$');	//clear ending spaces
		ele.className = ele.className.replace(re, '');
	}
}

function showNav2(thisStatus) 
{
	var showRowObj = document.getElementById('show_row');
	var closeRowObj = document.getElementById('close_row');
	var otherRowObj = document.getElementById('other_row');
	
	if (thisStatus=="show")
	{
		showRowObj.style.display = "none";
		closeRowObj.style.display = displayType;
		otherRowObj.style.display = displayType;
	}
	else if (thisStatus=="wealthMgt")	//at section "Wealth Management", hide "< More >" and "< Close >" link
	{
		showRowObj.style.display = "none";
		closeRowObj.style.display = "none";
		otherRowObj.style.display = displayType;
	}
	else
	{
		showRowObj.style.display = displayType;
		closeRowObj.style.display = "none";
		otherRowObj.style.display = "none";
	}
}

function swapAnswer(thisID, thisStatus)
{
	var thisObj = document.getElementById(thisID);
	
	if(thisStatus=="show")
		thisObj.style.display = "block";
	else
		thisObj.style.display = "none";
}

function swapContent(thisID)
{
	var headObjArr = new Array();
	var contentObjArr = new Array();
	headObjArr[0] = document.getElementById('head_loc_hk');
	headObjArr[1] = document.getElementById('head_loc_ml');
	headObjArr[2] = document.getElementById('head_loc_mc');
	headObjArr[3] = document.getElementById('head_loc_ms');
	contentObjArr[0] = document.getElementById('loc_hk');
	contentObjArr[1] = document.getElementById('loc_ml');
	contentObjArr[2] = document.getElementById('loc_mc');
	contentObjArr[3] = document.getElementById('loc_ms');
	
	for (var i=0; i<contentObjArr.length; i++)
	{
		if (contentObjArr[i].id == thisID)
		{
			addClass(headObjArr[i], "on");
//			contentObjArr[i].style.display = displayType;
//			contentObjArr[i].style.display = "table-row-group";
			if(!bw.ie)
				contentObjArr[i].style.display = "table-row-group";
			else
				contentObjArr[i].style.display = displayType;

		}
		else
		{
			removeClass(headObjArr[i], "on");
			contentObjArr[i].style.display = "none";
		}
	}
}

function showFlash(thisSrc, thisWidth, thisHeight) {
	document.write("<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0\" width=\"" + thisWidth + "\" height=\"" + thisHeight + "\" />");
	document.write("<param name=\"movie\" value=\"" + thisSrc + "\" />");
 	document.write("<param name=\"quality\" value=\"high\">");
	document.write("<embed src=\"" + thisSrc + "\" width=\"" + thisWidth + "\" height=\"" + thisHeight + "\" quality=\"high\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\">");
	document.write("</embed>");
	document.write("</object>");
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
