if (!kanhanDomain)	var kanhanDomain = "investedsc.intra.hksfc.org.hk/gb/"; 
if (!investDomain)	var investDomain = "http://invested.intra.hksfc.org.hk"; 


var isIE = navigator.appName.indexOf("Microsoft") > -1;
if (isIE && document.execCommand)	document.execCommand('BackgroundImageCache', false, true);
if (window.name == '')	window.name = 'investedWin';


window.unload = function()
{
	if (briefcaseWin)
	{
		briefcaseWin.close();
	}
}


function GetParam(name)
{
	var start=location.search.indexOf("?"+name+"=");
	if (start<0) start=location.search.indexOf("&"+name+"=");
 	if (start<0) return '';
 	start += name.length+2;
 	var end=location.search.indexOf("&",start)-1;
 	if (end<0) end=location.search.length;
 	var result=location.search.substring(start,end);
 	var result='';
 	for(var i=start;i<=end;i++)
 	{
 		var c=location.search.charAt(i);
 		result=result+(c=='+'?' ':c);
 	}
 	//alert(unescape(result));
 	return unescape(result);
}

function getSharpParam()
{
	var str = location.toString();
	var result = str.split('#')[1];
	
	if (str.indexOf('?')!=-1)
		{
			result = str.split('?')[1];
		}
	//alert(result);
 	return unescape(result);
}

function getInnerText(obj)
{
	return document.all?obj.innerText:obj.textContent;
}

function addLoadEvent(func)
{
	var oldonload = window.onload;
	if (typeof window.onload != 'function')
	{
		window.onload = func;
	}
	else
	{
		window.onload = function()
		{
		  if (oldonload)
		  {
			oldonload();
		  }
		  func();
		}
	}
}

function checkURL(array)
{
	var url = window.top.location.href;
	var id;
	var va = [["/", "/"], ["=", ""]];
	
	for (var item=0; item<va.length; item++)
	{
		for (var i=0; i<array.length; i++)
		{
			if (url.indexOf((va[item][0] + array[i] + va[item][1])) >= 0)
			{
				id = array[i];
				break;
			}
		}
	}
	
	return id;
}

function checkLang()
{
	var url = window.top.location.href;
	var array = new Array("en", "tc", "sc");
	var id;
	var va = [["/", "/"], ["=", ""]];
	
	for (var item=0; item<va.length; item++)
	{
		for (var i=0; i<array.length; i++)
		{
			if (url.indexOf((va[item][0] + array[i] + va[item][1])) >= 0)
			{
				id = i;
				break;
			}
		}
	}
	
	return id;
}

function langTxt(array)
{
	var langNum = checkLang();
	return array[langNum];
}

function kanhanLink(url)
{
	window.location.href = investDomain + "/invested/jsp/sc/disclaimer.jsp?page=" + escape("http") + "://"+ kanhanDomain + investDomain.substring(7, investDomain.length) + url;
}

function changeLanguage(target) 
{ 
   var array = new Array("en", "tc", "sc"); 
   var nowL = checkURL(array); 
   var va = [["/", "/"], ["=", ""]]; 
   var url = window.top.location.href; 
   for (var item=0; item<va.length; item++) 
    { 
        if (url.indexOf((va[item][0] + nowL + va[item][1])) >= 0) 
         { 
             url = url.replace((va[item][0] + nowL + va[item][1]), 
(va[item][0] + target 
+ va[item][1])); 
              break; 
         } 
    } 
   if (url.substring((url.length-1), url.length) == '#')      url = 
url.substring(0, 
(url.length-1)) 
   if (target == "sc") 
    { 

        if (url.indexOf("https") != -1) 
         { 
             url = investDomain + "/invested/jsp/sc/disclaimer.jsp?page=" + 
"https://"+ kanhanDomain + url.substring(8,url.length);               
         }else 
         { 
             url = investDomain + "/invested/jsp/sc/disclaimer.jsp?page=" + 
escape("http") + "://"+ kanhanDomain + url.substring(7,url.length); 
         } 
    }else 
    { 
        if (url.indexOf(kanhanDomain) != -1) 
         { 
             url = url.replace(kanhanDomain,""); 
         } 
    }
	
	url = url.replace(window.top.location.hash, "");
	
	window.top.location.href = url; 
} 

if (!newPopup)	var newPopup;

function NewWindow(mypage, myname, w, h, scroll,resizable) {
	if (isIE)
	{
		w = w - 4;
		h = h - 4;
	}
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable='+resizable+','
	if (lang == "sc")	mypage = escape("http") + "://"+ kanhanDomain + investDomain.substring(7, investDomain.length) + mypage;
	
	if (newPopup)	newPopup.close();
	newPopup = window.open(mypage, myname, winprops);
	newPopup.self.focus();
	if (parseInt(navigator.appVersion) >= 4) { newPopup.window.focus(); }
}

function MM_findObj(n, d) { //v4.01
  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 && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

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 MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function genFlash(file, width, height, id, vars) {
	var tempHtml = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="'+width+'" height="'+height+'" id="'+id+'" name="'+id+'">';
	tempHtml += '<param name="movie" value="'+file+'">';
	tempHtml += '<param name="quality" value="high">';
	tempHtml += '<param name="menu" value="false">';
	tempHtml += '<param name="wmode" value="opaque">';
	//tempHtml += '<param name="scale" value="noscale">';
	tempHtml += '<param name="salign" value="TL">';
	tempHtml += '<param name="allowScriptAccess" value="always">';
	
	//alert(vars);
	if (vars != null) {
		tempHtml += '<param name="flashVars" value="'+vars+'">';
		tempHtml += '<embed src="'+file+'" flashVars="'+vars+'" salign="TL" quality="high" allowScriptAccess="always" wmode="opaque" menu="false" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+width+'" height="'+height+'" id="'+id+'" name="'+id+'"></embed>';
	} else {
		tempHtml += '<embed src="'+file+'" salign="TL" quality="high" wmode="opaque" menu="false" allowScriptAccess="always" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+width+'" height="'+height+'" id="'+id+'" name="'+id+'"></embed>';
	}
	
	tempHtml += '</object>';
	
	document.write(tempHtml);
}

function mvqPDimension(elm)
{
    var top = 0;
    var height = 0;
    var width = 0;
    var left = 0;
    if(elm)
    {
        this.height = elm.offsetHeight;
        this.width = elm.offsetWidth;
        while(elm)
        {
            left += elm.offsetLeft;
            top += elm.offsetTop;
            elm = elm.offsetParent;
        }
        this.left = left;
        this.top = top;
    }
}


function mvqPVerifyOverlap(tbl, overlapElm)
{
    var p1 = new mvqPDimension(overlapElm);
    var p = new mvqPDimension(tbl);
    return ( ((p.left + p.width) > p1.left) && (p.left < (p1.left + p1.width)) && (p.top < (p1.top - overlapElm.offsetTop + p1.height)) && ((p.top + p.height) > (p1.top - overlapElm.offsetTop)) );
}


var pullTimeout0, pullTimeout1, pullTimeout2, pullTimeout3, pullTimeout4, pullTimeout5;

function navPulldownOver(i, over)
{
	if (!(d.getElementById('navPulldown_'+i) && d.getElementById('navPulldownMenu_'+i)))	return;
	var btn = d.getElementById('navPulldown_'+i);
	var menu = d.getElementById('navPulldownMenu_'+i);
//	var boxAlert = d.getElementById('boxAlert');
	var delay = 1000*60;
	
	if (over == 2)
	{
		if (btn.hidden)
		{
			btn.hidden = false;
			return;
		}
		clearTimeout(window["pullTimeout"+i]);
		menu.style.visibility = 'visible';
		btn.onclick = function() {navPulldownOver(i, 0)};
		btn.onmouseover = function() {btn.hit = true;};
		btn.onmouseout = function() {btn.hit = false; window["pullTimeout"+i] = setTimeout(function() {if (!btn.hit)	navPulldownOver(i, 0);}, delay)};
		menu.onmouseover = function() {btn.hit = true;};
		menu.onmouseout = function() {btn.hit = false; window["pullTimeout"+i] = setTimeout(function() {if (!btn.hit)	navPulldownOver(i, 0);}, delay)};
		//btn.onmouseover = function() {btn.hit = true; navPulldownOver(i, 1)};
		//btn.onmouseout = function() {btn.hit = false; setTimeout(function() {if (!btn.hit)	navPulldownOver(i, 0);}, delay)};
		//menu.onmouseover = function() {btn.hit = true; navPulldownOver(i, 1)};
		//menu.onmouseout = function() {btn.hit = false; setTimeout(function() {if (!btn.hit)	navPulldownOver(i, 0);}, delay)};
		//menu.onmouseout = function() {btn.hit = false; navPulldownOver(i, 0)};
		/*var li = menu.getElementsByTagName('*');
		for (var j=0; j<li.length; j++)
		{
			var liBtn = li[j];
			liBtn.onmouseover = function() {btn.hit = true; navPulldownOver(i, 1)};
			//liBtn.onmouseout = function() {btn.hit = false; setTimeout(function() {if (!btn.hit)	navPulldownOver(i, 0);}, delay)};
		}*/
	}
	else if (over == 1)
	{
		//btn.onmouseout = null;
		//btn.hit = true;
		menu.style.visibility = 'visible';
//		if (showMenu && i <=1)	boxAlert.getElementsByTagName('a')[0].style.visibility = 'hidden';
	}
	else
	{
		clearTimeout(window["pullTimeout"+i]);
		menu.style.visibility = 'hidden';
		btn.onclick = function() {navPulldownOver(i, 2)};
		btn.onmouseover = null;
		btn.onmouseover = null;
		btn.onmouseout = null;
		menu.onmouseover = null;
		menu.onmouseout = null;
	//	if (showMenu && i <=1)	boxAlert.getElementsByTagName('a')[0].style.visibility = 'visible';
	}
	
//	window.status = btn.hit;
}


function checkDivPos(div, type)
{
	var x = new mvqPDimension(div);
	var w = new mvqPDimension(d.getElementById('mainContainer')).width;
	var bw = d.body.clientWidth;
	var ww = (bw - (bw - w)/2);
	
	if ((x.left + x.width) > ww)
	{
		if (type == 1)
		{
			div.style.left = (ww - (x.left + x.width) - 20) + 'px';
		}
		else if (type == 2)
		{
			div.style.left = (-x.width - 2) + 'px';
		}
		else if (type == 3)
		{
			//alert(x.left + "  :  " + x.width + "  :  " + ww);
			//if (x.left > ww)	return;
			if (x.left < ww)
			{
				div.style.left = - ((x.left + x.width) - ww + 30) + 'px';
			}
			else
			{
				div.style.left = - (x.width - 50) + 'px';
			}
		}
	}
}


function navClick(i, total)
{
	var nav = d.getElementById(('nav_'+i));
	if (!d.getElementById(('menu_'+i)))	genMenu(nav, i, total);
	
	nav.hit = true;
	nav.clicked = true;
	navOver(i, 1, 1);
	nav.onmouseover = function() {navOver(i, 1, 1);};
	nav.onmouseout = function() {navOver(i, 0, 1);};
}


function navOver(i, over, pulldown, start)
{
	var nav = d.getElementById(('nav_'+i));
	if (d.getElementById(('menu_'+i)))	var layer = d.getElementById(('menu_'+i));
	if (d.getElementById(('navDash_'+i)))	var navDash = d.getElementById(('navDash_'+i));
	
	if (over)
	{
		nav.className = 'level1NavOn';
		if (navDash)	navDash.style.visibility = 'visible';
		if (layer && pulldown)	layer.style.visibility = 'visible';
		nav.hit = true;		
	}
	else
	{
		nav.hit = false;
		var delay;
		if (nav.clicked)	delay = 200;	else	delay = 0;
		setTimeout (
			function()
			{
				if (!nav.hit)
				{
					if (level2 != i && !start)
					{
						nav.className = 'level1Nav';
						if (navDash)	navDash.style.visibility = 'hidden';
					}
					if (layer)	layer.style.visibility = 'hidden';
					nav.onmouseover = function() {navOver(i, 1, 0);};
					nav.onmouseout = function() {navOver(i, 0, 0);};
					nav.clicked = false;
				}
			}, delay
		);
	}
}


function subNavOver(i, j, over, total2)
{
	var nav = d.getElementById(('nav_'+i+'_'+j));
	if (d.getElementById(('nav_'+i+'_'+j)))	var nav = d.getElementById(('nav_'+i+'_'+j));
	if (!d.getElementById(('menu_'+i+'_'+j)))	genSubMenu(nav, i, j, total2);
	if (d.getElementById(('menu_'+i+'_'+j)))	var layer = d.getElementById(('menu_'+i+'_'+j));
	if (d.getElementById(('navTxt_'+i+'_'+j)))	var navTxt = d.getElementById(('navTxt_'+i+'_'+j));
	
	if (over)
	{
		if (layer)
		{
			navTxt.className = 'pulldownOn';
			layer.style.visibility = 'visible';
		}
		nav.hit = true;
	}
	else
	{
		nav.hit = false;
		if (layer)	delay = 100;	else	delay = 0;
		setTimeout (
			function()
			{
				if (!nav.hit && layer)
				{
					navTxt.className = '';
					layer.style.visibility = 'hidden';
				}
			}, delay
		);
	}
}

function featuresOpen(i, total)
{
	if (!d.getElementById(('featuresNav_'+i)))	return;
	var nav = d.getElementById(('featuresNav_'+i));
	var mask = d.getElementById(('featuresMask_'+i));
	
	if (!nav.clicked)
	{
		featuresGo(i, 1);
		nav.clicked = true;
		nav.className = nav.className + 'On';
		
		for (var j=0; j<total; j++)
		{
			if (j == i)	continue;
			var nav = d.getElementById(('featuresNav_'+j));
			
			if (nav.clicked)
			{
				featuresGo(j, 0);
				nav.clicked = false;
				nav.className = nav.className.replace('On', '');
			}
		}
		
		if (d.getElementById('videoNav').clicked)	videoTipsOpen('video');
		if (d.getElementById('tipsNav').clicked)	videoTipsOpen('tips');
		infoOpen(true);
	}
	else
	{
		featuresGo(i, 0);
		nav.clicked = false;
		nav.className = nav.className.replace('On', '');
		infoOpen(false);
	}
}

function featuresGo(i, over)
{
	var nav = d.getElementById(('featuresNav_'+i));
	var mask = d.getElementById(('featuresMask_'+i));
	mask.layerHMotion = layerHMotion;
	
	if (over)
	{
		mask.tempHeight = mask.scrollHeight;
		mask.speed = 3;
		mask.layerHMotion(mask);
	}
	else
	{
		mask.tempHeight = 0;
		mask.speed = 3;
		mask.layerHMotion(mask);
	}
}

var timeOutSpeed = 25;
	
function layerHMotion(layer)
{
	if (isIE)
	{
		layer.objHeight = Number(layer.style.pixelHeight);
	}
	else
	{
		layer.objHeight = Number(layer.style.height.substring(0, (layer.style.height.toString().length-2)));
	}
	layer.goStep = (layer.tempHeight - layer.objHeight)/layer.speed;
	
	if (!(Math.abs(layer.objHeight - layer.tempHeight) < 1))
	{
		layer.objHeight += layer.goStep;
		var timeOut = setTimeout(function(){layer.layerHMotion(layer);}, timeOutSpeed);
	}
	else
	{
		layer.objHeight = layer.tempHeight;
		clearTimeout(timeOut);
	}
	
//	window.status = layer.objHeight;
	layer.style.height = layer.objHeight + 'px';
}

function videoTipsOpen(i)
{
	var nav = d.getElementById((i+'Nav'));
	var mask = d.getElementById((i+'Mask'));
	var navArray = new Array("video", "tips");
	var isClose = true;
	
	if (!nav.clicked)
	{
		videoTipsGo(i, 1);
		nav.clicked = true;
		nav.src = '/invested/common/images/others/leftbox_b_arrow_on.png';
		nav.className = 'pngImg';
		isClose = true;
		
		for (var j=0; j<navArray.length; j++)
		{
			if (navArray[j] == i)	continue;
			var nav = d.getElementById((navArray[j]+'Nav'));
			
			if (nav.clicked)
			{
				videoTipsGo(navArray[j], 0);
				nav.clicked = false;
				nav.src = '/invested/common/images/others/leftbox_b_arrow.png';
				nav.className = 'pngImg';
			}
		}
		
		var obj = sectionObj[107];
		for (var i=0; i<obj.length; i++)
		{
			if (d.getElementById(('featuresNav_'+i)).clicked)
			{
				featuresOpen(i, obj.length);
			}
		}
	}
	else
	{
		videoTipsGo(i, 0);
		nav.clicked = false;
		nav.src = '/invested/common/images/others/leftbox_b_arrow.png';
		nav.className = 'pngImg';
		isClose = false;
	}
	
	infoOpen(isClose);
}

function videoTipsGo(i, over)
{
	var nav = d.getElementById((i+'Nav'));
	var mask = d.getElementById((i+'Mask'));
	mask.layerHMotion = layerHMotion;
	
	if (over)
	{
		mask.tempHeight = mask.scrollHeight;
		mask.speed = 3;
		mask.layerHMotion(mask);
	}
	else
	{
		mask.tempHeight = 0;
		mask.speed = 3;
		mask.layerHMotion(mask);
	}
}

function infoOpen(isClose)
{	
	
	if (d.getElementById('navPulldownMenu_0'))
 	{
  		var pulldown = d.getElementById('navPulldownMenu_0');
  		if (pulldown.style.visibility == 'visible') pulldown.style.visibility = 'hidden';
 	}
	
	if (!infoMenuShow)	return;
	//alert(isClose)
	var mask = d.getElementById('infoMask');
	var select = d.getElementById('infoSelect');
	
	if (isClose)
	{
		select.style.visibility = 'visible';
		infoGo(1);
	}
	else
	{
		select.style.visibility = 'hidden';
		infoGo(0);
	}
}

function infoGo(over)
{
	var mask = d.getElementById('infoMask');
	mask.layerHMotion = layerHMotion;
	
	if (over)
	{
		mask.tempHeight = 27;
		mask.speed = 3;
		mask.layerHMotion(mask);
	}
	else
	{
		mask.tempHeight = mask.scrollHeight;
		mask.speed = 3;
		mask.layerHMotion(mask);
	}
}


function searchOver(over)
{
	var pulldown = d.getElementById('searchPulldown');
	
	if (over)
	{
		pulldown.style.visibility = 'visible';
	}
	else
	{
		pulldown.style.visibility = 'hidden';
	}
}


function selectAll(obj, isCheck)
{
	var input = d.getElementById(obj).getElementsByTagName('input');
	
	for (var i=0; i<input.length; i++)
	{
		if (input[i].type == "checkbox")
		{
			input[i].checked = isCheck;
		}
	}
}

function myBriefcase()
{
	var w = 487 + 20;
	var h = 500;
	var l = (screen.width - w) / 2;
	var t = (screen.height - h) / 2;
	
	//link += (lang == "sc")?kanhanDomain:"";
	var link = investDomain + path + 'html/section/others/my_briefcase.html';
	
//	alert(link + "  :  " + investDomain);
	var page = window.open(link, 'briefcaseWin', 'width='+w+', height='+h+', left='+l+', top='+t+', screenX=0, screenY=0, scrollbars=1, resizable=0');
	page.focus();
}

function printerManager()
{
	var w = 487 + 20;
	var h = 500;
	var l = (screen.width - w) / 2;
	var t = (screen.height - h) / 2;
	if (lang == "sc")
	{
		var link = escape('http')+'://' + kanhanDomainUtf + investDomain.substring(7, investDomain.length) + path + 'html/section/others/print_manager.html';
	}
	else
	{
		var link = investDomain + path + 'html/section/others/print_manager.html';
	}
	var page = window.open(link, 'briefcaseWin', 'width='+w+', height='+h+', left='+l+', top='+t+', screenX=0, screenY=0, scrollbars=1, resizable=0');
	page.focus();
}

function findGlossary()
{
	var tagArray = new Array("p", "h1", "li");	
	if (!glossObj)	return;
	var content = d.getElementById('content');
	
	function checkId(n, i, type)
	{
	//	alert("explanation:  "+glossObj[n][i].explanation)
		var explanObj = glossObj[n][i].explanation;
		for (var j=0; j<explanObj.length; j++)
		{
			if (explanObj[j].type == type)
			{
				//alert(explanObj[j].type + "  :  " + type + "  :  " + j);
				return j;
			}
		}
		return 0;
	}
	
	for (var n in glossObj)
	{
		for (var i in glossObj[n])
		{
			var keyword = glossObj[n][i].keyword.toLowerCase();
			//if (n == "d")	alert(keyword + "  :  " + n + "  :  " + i);
			
			if (glossObj[n][i].plural == '')
			{
				if (content.innerHTML.toLowerCase().indexOf(keyword) < 0)	continue;
			}
			else
			{
				//Check for position of keyword and plural
				var plural = glossObj[n][i].plural.toLowerCase();
				var index1 = content.innerHTML.toLowerCase().indexOf(keyword);
				var index2 = content.innerHTML.toLowerCase().indexOf(plural);
				if (index1 < 0 && index2 < 0)	continue;
				
				var index1 = -1;
				var index2 = -1;
				for (var j in tagArray)
				{
					var tag = content.getElementsByTagName(tagArray[j]);
					for (var k=0; k<tag.length; k++)
					{
						index1 = tag[k].innerHTML.toLowerCase().indexOf(keyword);
						index2 = tag[k].innerHTML.toLowerCase().indexOf(plural);
						if (index1 > -1 | index2 > -1)	break;
					}
					if (index1 > -1 | index2 > -1)	break;
				}
				//alert(keyword + "  :  " + index1 +  "  :  " + plural + "  :  " + index2);
				if (index1 >= index2 && index2 > -1)	keyword = plural;
			}
			
			//var tag = content.getElementsByTagName('*');
			for (var j in tagArray)
			{
				var tag = content.getElementsByTagName(tagArray[j]);
				for (var k=0; k<tag.length; k++)
				{
					//var id = checkId(i, level3);
					var id = 0;
					var hasGloss = false;
					var index = tag[k].innerHTML.toLowerCase().indexOf(keyword);
					if (index > -1)
					{
						//Check A Name
						/*var a = tag[k].getElementsByTagName('a');
						if (a.length > 0)
						{
							for (var m=0; m<a.length; m++)
							{
								if (a[m].toString().indexOf('glossName') > 0)
								{
									var name = a[m].href.replace('javascript:glossName(\'', '').replace('\');', '');
									id = checkId(i, '', name);
									break;
								}
							}
						}*/
						
						//Check SPAN CLASS Name
						var span = tag[k].getElementsByTagName('span');
						var isSpan = false;
						if (span.length > 0)
						{
							var glossOff = false;
							for (var m=0; m<span.length; m++)
							{
								if (!span[m].className)	continue;
								if (span[m].className == 'glossary_off')
								{
									glossOff = true;
									continue;
								}
								if (span[m].className.toString().indexOf('glossary_') >= 0)
								{
									var name = span[m].className.replace('glossary_', '');
									id = checkId(n, i, name);
									isSpan = true;
									
									//check is it the whole word of the SPAN CLASS
									if (!(span[m].innerHTML.substring(0, 1) == keyword.substring(0, 1) && span[m].innerHTML.substring((keyword.length + 1), (keyword.length + 2)) == keyword.substring((keyword.length + 1), (keyword.length + 2))))	glossOff = true;
									//if (!(span[m].innerHTML.substring(0, 1) == ">" && span[m].innerHTML.substring((keyword.length + 1), (keyword.length + 2)) == "<"))	glossOff = true;
									
									//alert(keyword + "  :  " + id)
									break;
								}
							}
							if (glossOff)	continue;
						}
						
						//Skip A Title Name
						var a = tag[k].getElementsByTagName('a');
						var glossSkip = false;
						if (a.length > 0)
						{
							for (var m=0; m<a.length; m++)
							{
								//alert(a[m].title + ' : ' + keyword);
								if (a[m].title.toLowerCase().indexOf(keyword) >= 0)
								{
									glossSkip = true;
									break;
								}
							}
							//if (glossSkip)	continue;
						}
						
						var keyTxt = tag[k].innerHTML.substring(index, (index + keyword.length));
						
						//Check is it the whole word
						if (lang == "en")
						{
							var notWord = false;
							var checkItems = new Array(' ', '<', ',', '.', '"', '\'');
							var checkName = tag[k].innerHTML.substring((index + keyword.length), (index + keyword.length + 1));
							for (var p in checkItems)
							{
								if (checkName == checkItems[p])
								{
									notWord = true;
									break;
								}
							}
							if (!notWord)	continue;
							notWord = false;
							var checkItems = new Array(' ', '>', ',', '.', '"', '\'');
							var checkName = tag[k].innerHTML.substring((index - 1), index);
							for (var p in checkItems)
							{
								if (checkName == checkItems[p])
								{
									notWord = true;
									break;
								}
							}
							if (!notWord)	continue;
						}
						
						//alert(keyword + "  :  " + n + "  :  " + i + "  :  " + id + "  :  " + glossSkip);
						
						var str = '';
						if (isSpan) str = ' ';
						var glossTxt = str + '<span class="glossTxt" onmouseover="glossaryOver(this, 1, \''+n+'\', '+i+', '+id+');" onmouseout="glossaryOver(this, 0);"><span>' + keyTxt + '</span></span>' + str;
						//var glossTxt = '<span class="glossTxt" onmouseover="glossaryOver(this, 1, \''+n+'\', '+i+', '+id+');" onmouseout="glossaryOver(this, 0);"></span>';
						//var array = tag[k].innerHTML.split(keyTxt);
						//tag[k].innerHTML = array.join(glossTxt);
						
						if (glossSkip)
						{
							var array = tag[k].innerHTML.split(keyTxt);
							var str = '';
							for (var m=0; m<array.length; m++)
							{
								str += array[m];
								
								if (m < (array.length-1))	str += (m == 0)?keyTxt:glossTxt;
							}
							
							tag[k].innerHTML = str;
						}
						else
						{
							//alert(tagArray[j] + "  :  " + keyTxt + "  :  " + glossTxt);
							tag[k].innerHTML = tag[k].innerHTML.replace(keyTxt, glossTxt);
						}
						hasGloss = true;
						break;
					}
				}
				if (hasGloss)	break;
			}
		}
	}
}

function glossName() {}

var z = 1;

function glossaryOver(obj, over, n, i, j)
{
	if (over)
	{
		if (!showMenu)	return;
		
		//Preserve 1 glossary popup will be shown
		if (d.getElementById('glossContainer'))	d.getElementById('glossContainer').style.display = 'none';
		
		var glossContainer = createDiv('glossContainer', 'glossContainer');
		var glossBgTop = createDiv('', 'glossBgTop');
		//var glossBgMid = createDiv('', 'glossBgMid', glossObj[n][i].explanation[j].explan);
		var glossBgMid = createDiv('', 'glossBgMid');
		glossBgMid.innerHTML = glossObj[n][i].explanation[j].explan;
		var glossBgBtm = createDiv('', 'glossBgBtm');
		glossContainer.appendChild(glossBgTop);
		glossContainer.appendChild(glossBgMid);
		glossContainer.appendChild(glossBgBtm);
		obj.appendChild(glossContainer);
		obj.style.zIndex = z ++;
		//if (glossObj[n][i].keyword != 'Investor Compensation Company')
		//{
			checkDivPos(glossContainer, 3);
		//}
		obj.hit = true;
	}
	else
	{
		if (obj.hit)
		{
			obj.removeChild(obj.lastChild);
			obj.hit = false;
		}
	}
}

function printFriendly()
{
	var w = 650 + 20;
	var h = 500;
	var l = (screen.width - w) / 2;
	var t = (screen.height - h) / 2;
	var page = window.open('', 'printPopup', 'width='+w+', height='+h+', left='+l+', top='+t+', screenX=0, screenY=0, scrollbars=1, resizable=0');
	var str = '';
	
	var container = d.createElement('div');
	container.innerHTML = d.getElementById('contentWrapper').innerHTML;
	var a = container.getElementsByTagName('a');
	for (var i=0; i<a.length; i++)
	{
		if (a[i].href.indexOf("#") > -1 | a[i].href.indexOf("javascript:") > -1 | a[i].target == "_blank")	continue;
		a[i].target = 'investedWin';
	}
	//window.name = 'investedWin'; 
	
	str += '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head>';
	
	str += langTxt(['<meta http-equiv="Content-Type" content="text/html; charset=big5"><title>InvestEd - SFC Investor Education Portal</title>', '<meta http-equiv="Content-Type" content="text/html; charset=big5"><title>學•投資</title>', '<meta http-equiv="Content-Type" content="text/html; charset=big5"><title>學•投資</title>']);
	
	var link = d.getElementsByTagName('link');
	for (var i=0; i<link.length; i++)
	{
		if(link[i].rel.toString().toLowerCase() == "stylesheet")
		{
			str += '<link type="text/css" rel="stylesheet" href="'+link[i].href+'">';
		}
	}
	
	str += '<link type="text/css" rel="stylesheet" href="'+path+'css/popup.css"><link type="text/css" rel="stylesheet" href="/invested/common/css/print.css"></head><script language="javascript" type="text/script">var showMenu = false</script><body><div id="mainContainer"><div id="topNavContainer"><div id="topMenuContainer" style="display:none;"></div><div id="mainNavContainer"><div id="sfcLogo"><a href="http://www.sfc.hk/" target="_blank"><img src="/invested/common/images/others/sfc_logo.gif" alt="'+langTxt(['SFC', '證監會', '證監會'])+'" width="27" height="61" border="0" /></a></div><div id="investedLogo"><a href="'+path+'html/section/index.html" target="investedWin"><img src="'+path+'images/invested_logo.gif" alt="'+langTxt(['inVestEd', '學•投資', '學•投資'])+'" width="122" height="54" border="0" /></a></div></div></div><div id="printBtns"><div class="btn" style="margin-right:3px;"><a href="javascript:window.print();"><div class="iconPrint">'+langTxt(['Print', '列印', '列印'])+'</div></a></div><div class="btn"><a href="javascript:window.close();"><div class="iconClose">'+langTxt(['Close', '關閉', '關閉'])+'</div></a></div></div><div id="topNavBg"><div id="topNavCornerL"></div><div id="topNavCornerR"></div></div><div id="contentContainer"><div class="popContent">';
//	str += '			<h1>"My Investment Story" Competition</h1>';
//	str += '			<hr id="hLine"/>';
	str += '<div>';
	str += container.innerHTML;
	str += '</div>';
//	str += '			<hr id="hLine"/>';
	str += '</div></div></div>';
	str += '<script type="text/javascript" language="javascript" src="/invested/common/js/global.js"></script>';
	str += '<script type="text/javascript" language="javascript" src="'+path+'/js/items.js"></script>';
	str += '<script type="text/javascript" language="javascript" src="/invested/common/js/print.js"></script></body></html>';

	page.document.open();
	page.document.write(str);
	page.document.close();
	page.focus();
}

function genLink(i)
{
	var link = (i)?i:"javascript:;";
	
	if (link.indexOf('{language}') >= 0)
	{
		link = link.replace('{language}', lang);
	}
	
	if (!(link.indexOf('http') > -1) && !(link.indexOf('javascript') > -1) && link.indexOf('/') != 0)
	{
		link = path + i;
	}
	
	return link;
}

function checkIEVersion(num)
{
	var ver = window.navigator.appVersion.toLowerCase();
	if (ver.indexOf('msie ' + num + '.0') >= 0)	return true;
	return false;
}

function checkOpenerLink(url)
{
	if (window.opener)
	{
		window.opener.location.href = url;
	}
	else
	{
		window.location.href = url;
	}
}

function genBtnOver()
{
	var d = document;
	var img = d.getElementsByTagName('body')[0].getElementsByTagName('img');
	
	for (var i=0; i<img.length; i++)
	{
		var btn = img[i];
		
		if (btn.className == 'btnOver')
		{
			btn.onmouseover = function()
			{
				if(this.src.toString().indexOf("_over") > -1)	return;
				this.btnText = this.src;
				//alert(this.src)
				var str1 = this.btnText.substring(0, (this.btnText.length-4));
				var str2 = this.btnText.substring((this.btnText.length-4), this.btnText.length);
				this.src = str1 + "_over" + str2;
			}
			
			btn.onmouseout = function()
			{
				if(!this.btnText)	return;
				if(this.clicked)	return;
				this.src = this.btnText;
			}
		}
	}
}

function toSFCHome()
{
	var url;
	if (lang == "sc")
	{
		url = sfckanhanDomain + sfcURL;
	}
	else
	{
		url = sfcURL;
	}
	var folder = (lang == "sc")?"tc":lang;
	window.open(escape("http") + "://" + url + "/html/" + folder.toUpperCase());
}

function genBanner()
{
	var img;
	if (level2 == 414)
	{
		img = '/invested/'+lang+'/images/intermed/banner.jpg';
	}
	else if (level2 == 415)
	{
		img = '/invested/'+lang+'/images/mrisk/banner.jpg';
	}
	else if (level2 == 146)
 	{
  		img = '/invested/'+lang+'/images/products/banner.jpg';
 	}
	else
	{
		return;
	}
	//if (isIE)
	//{
		//d.getElementById('content').style.paddingTop = '100px';
		//d.getElementById('content').style.background = 'url(' + img + ') no-repeat';
	/*}
	else
	{
		var spacing = 35;
		if (d.getElementById('titleContainer'))	spacing = d.getElementById('titleContainer').offsetHeight + 7;
		d.getElementById('content').style.paddingTop = (100 + spacing) + 'px';
		d.getElementById('content').style.background = 'url(' + img + ') no-repeat 0 ' + spacing + 'px';
	}*/
	
	//Edited at 2009/12/07
	var content = d.getElementById('content');
	content.style.paddingTop = '0px';
	var div = content.getElementsByTagName('div')[0];
	var imgTag = createImg(img);
	imgTag.style.marginBottom = '8px';
	content.insertBefore(imgTag, div);
}


function createImg(src, alt, w, h, link, t, className)
{
	var img = d.createElement('img');
	if (src)	img.setAttribute('src', src);
	if (alt)	img.setAttribute('alt', alt);
	if (w)	img.setAttribute('width', w);
	if (h)	img.setAttribute('height', h);
	if (className)	img.className = className;
	
	if (link)
	{
		img.setAttribute('border', 0);
		
		var a = d.createElement('a');
		a.setAttribute('href', link);
		if (t && typeof(t) != 'undefined')	a.setAttribute('target', t);
		a.appendChild(img);
		return a;
	}
	else
	{	
		return img;
	}
}

function createA(link, t, txt, id, className)
{		
	var a = d.createElement('a');
	if (link)	a.setAttribute('href', link);
	if (t && typeof(t) != 'undefined')	a.setAttribute('target', t);
	
	if (txt)	a.appendChild(d.createTextNode(txt));
	if (id)	a.setAttribute('id', id);
	if (className)	a.className = className;
	
	return a;
}

function createDiv(id, className, txt)
{		
	var div = d.createElement('div');
	if (id)	div.setAttribute('id', id);
	if (className)	div.className = className;
	if (txt)	div.appendChild(d.createTextNode(txt));
	return div;
}

function createTag(tag, id, className)
{		
	var div = d.createElement(tag);
	if (id)	div.setAttribute('id', id);
	if (className)	div.className = className;
	return div;
}

function createInput(name, type, value, className)
{		
	var input = d.createElement('input');
	if (name)
	{
		input.setAttribute('name', name);
		input.setAttribute('id', name);
	}
	if (type)	input.setAttribute('type', type);
	if (value)	input.setAttribute('value', value);
	if (className)	input.className = className;
	return input;
}

