﻿<!--//

//設定上方的 menu high-light
function highLight(menuName){
	var thisMenu1 = 'm' + (menuName+1);
//	document.title = thisMenu1;
//	document.title = menuName;
	var imgX = document.images[thisMenu1];
	if(imgX){
		swapImage(imgX,'on');
		imgX.onmouseout=null;
		if(thisMenu1!='m1'){
			showMenu(menuName+1);
		}
	}
}

var loginStatus = ' 你尚未登入 ';
var logined = false;
function chgLoginStatus(){
	var id , obj, loginArea, username, hasAlert;
//	logined = GetCookie('isLogined');
	if(logined=='Y'){
//		username = GetCookie('UserFullName');
//		hasAlert = GetCookie('hasAlert');
		loginArea = '<a href="/membership/logout.aspx"><img src="/pic/logout.gif" border="0"></a>';
//		loginStatus = ' 親愛的 ' + username + '你好' + ((hasAlert=='Y')? '~~你有警示...' : '') ;
	} else {
		loginArea = '<a href="/membership/login.aspx"><img src="/pic/login.gif" border="0"></a><a href="/membership/register.aspx"><img src="/pic/join.gif" border="0"></a>';
		loginStatus = ' 你尚未登入 ';
	}

	id = 'loginZone';
	obj = document.getElementById(id);
	if(obj){
		obj.innerHTML = loginArea;
	}

	id = 'loginStatus';
	obj = document.getElementById(id);
	if(obj){
		obj.innerHTML = loginStatus;
	}

//	resizefont();
	renewInvestHost();

}

var hostMy4='http://my4.fortunengine.com.tw';
function renewInvestHost()
{	
 	var anchors=document.getElementsByTagName('a')
	for(i=0;i< anchors.length; i++)
      	{
            	var obj= anchors[i];
            	var host=obj.href;
            	if( host.indexOf( hostMy4) >=0 )
            	{
            		obj.href= host.replace(hostMy4, investHost);
        	}
       	}
}


function findCategory(){
	for (var i=0; i<menus.length; i++) {
		for (var j=0; j<menus[i].length; j++) {
//			if ( queryString == menus[i][j][1]){	// cfm用
			if ( pathname == menus[i][j][1]){	//aspx 用
				menus[i][j][2] = markedLabel;
				category = i;
			}else{
					menus[i][j][2] = unmarkedLabel;
			}
			if(menus[i][j][1].indexOf(pathname)!=-1){
				category_pathname = i;
			}
		}
	}
	//找出目前的網頁屬於哪個group
	for (var i=0; i<menuGroup.length; i++) {
		if(category>=menuGroup[i][0]){
			menuGroupIdx = i;
		}
	}
}

function findMenu(){
	var pathname = location.pathname;
	var anchors = document.links;
	var imgName = null;
	for(var i=0; i<anchors.length; i++){
		if((anchors[i].pathname==pathname) || (('/'+anchors[i].pathname)==pathname)){
			var tmp = anchors[i].id.split("_");
			imgName = tmp[tmp.length-1];
			return imgName;
		}
	}
}


function showMenu(tmpIdx){
	clearTimeout(t);
	if(tmpIdx==1){
//		showUpperMenu(menuGroupIdx);
	} else if(tmpIdx!=null){
		tmpIdx = 0 + tmpIdx;
		showUpperMenu(tmpIdx);
	}
}

function swapImage(thisImg, act) { //new by Longson
	var prefix = '/pic/';
	act = (act=='on')?act:'up';
	var suffix = '_' + act + '.gif';
	if(thisImg){
		var src = prefix + thisImg.name + suffix;
		thisImg.src = src;
	}
	return null;
}

function showUpperMenu(thisMenuGroupIdx){
	/*三件事要處理
	1.div 的 margin-left
	2.td(sm2) 的內容
	3.imgSmt 的 margin-left
	4.img('mN') change src
	*/
	var id = 'subMenus';
	var sm2 = 'sm2';
	var smt = 'ImgSmt';
	thisMenuGroupIdx = thisMenuGroupIdx -1; //配合前面的命名順序
	if( (thisMenuGroupIdx<=0) || (thisMenuGroupIdx > menuGroup.length-1) ){
		thisMenuGroupIdx = 0;
	}
	var startIdx = menuGroup[thisMenuGroupIdx][0];
	var endIdx = calEndIdx(thisMenuGroupIdx);
	var topImg = 'm'+(thisMenuGroupIdx+1); //配合 id, 要加1
	var separator = '　';
	var subMenusTD = document.getElementById(id);
	var obj = document.getElementById(sm2);
	var objSmt = document.getElementById(smt);
	var objTopImg = document.getElementById(topImg);
	var w;
	if(subMenusTD){
		subMenusTD.innerHTML = '';
		var s;
		for(var i=startIdx; i<endIdx; i++){
			s = '<a href="' + menus[i][0][1] + '" class="upperMenu"' 
				+ ((menus[i][0][0]=='決策工具')?' target="_myFortune"':'') 
				+ ((menus[i][0][0]=='基金')?' target="_myFortune"':'') 
				+ ((menus[i][0][0]=='股票')?' target="_myFortune"':'') 
				+ ((menus[i][0][0]=='期權')?' target="_myFortune"':'') 
				+ ((menus[i][0][0]=='期權平台')?' target="_option"':'') 
				+ '>';
			s += menus[i][0][0];
			s += separator;
			s += '</a> ';
			subMenusTD.innerHTML += s;
		}
	}
	if(obj){
		obj.style.width = menuGroup[thisMenuGroupIdx][1] + 'px';
		obj.style.marginLeft = menuGroup[thisMenuGroupIdx][2] + 'px';
		if(thisMenuGroupIdx==0){
			obj.style.visibility = 'hidden';
		} else {
			obj.style.visibility = 'visible';
		}
	}
	if(objSmt){
		objSmt.style.marginLeft = menuGroup[thisMenuGroupIdx][3] + 'px';
	}
	if(objTopImg){
		imgOvr(objTopImg);
	}
}

function calEndIdx(idx){
	var ei = '999';	//endInx
	if(idx == (menuGroup.length-1)){
		ei = menus.length;
	}else{
		ei = menuGroup[idx+1][0];
	}
	return ei;
}

function hideMenu(tmpIdx){
	t = setTimeout("showUpperMenu(menuGroupIdx)",500);
}


function imgOvr(img){
	var tmpIdx;
	if(img && img.src){
		img.src = img.src.replace('up','on');
	}
	imgStore = img;
}
function imgOut(img){
	var topImg = 'm'+menuGroupIdx;
	if(img && img.src && !(img == document.getElementById(topImg))){
		img.src = img.src.replace('on','up');
	}
}

//showHide txtIntro and replace the string
function showTxtIntro(s){
	var id = 'txtIntro';
	var obj = document.getElementById(id);
	if(obj){
		obj.style.display = 'block';
		obj.innerHTML =  s;
	}
}
function hideTxtIntro(){
	var id = 'txtIntro';
	var obj = document.getElementById(id);
	if(obj){
		obj.style.display = 'none';
	}
}
var isSubmit = false;
function beforeSubmit(s){
	showTxtIntro(s);
	isSubmit = false;
}
function afterSubmit(s){
	hideTxtIntro();
	isSubmit = true;
}

// for setting fontSize ----start 
function SetCookie(sName, sValue){
  var date = new Date();
  document.cookie = sName + "=" + escape(sValue) + "; expires=" + date.toLocaleString();
}

function GetCookie(sName){
  // cookies are separated by semicolons
  var aCookie = document.cookie.split("; ");
  for (var i=0; i < aCookie.length; i++)
  {
    // a name/value pair (a crumb) is separated by an equal sign
    var aCrumb = aCookie[i].split("=");
    if (sName == aCrumb[0]) 
      return unescape(aCrumb[1]);
  }

  // a cookie with the requested name does not exist
  return null;
}

function resizefont(fontStyle){
	doc = document;
	var cookieName = 'myftFontCookie';
	var fontDefaultSize ;
	curFontSize = eval(GetCookie(cookieName)==null?fontDefaultSize:GetCookie(cookieName));
	if(fontStyle==0) {
		curFontSize = null;
		doc.body.style.fontSize = curFontSize ;
		SetCookie(cookieName,curFontSize);
	}else if(fontStyle!=null) {
		curFontSize = fontDefaultSize + fontStyle*2;
		doc.body.style.fontSize = curFontSize +  "px";
		SetCookie(cookieName,curFontSize);
	} else {
		doc.body.style.fontSize = curFontSize +  "px";
	}
}
// for setting fontSize ----start 

var switchFlag = 0;
function MM_switchTrade(thisImg){
	if(!thisImg){	return false;	}
	var obj = document.getElementById('table_' + ( (thisImg)? thisImg.name: '' ) );
	if(obj){	obj.style.display = (switchFlag)?'none':'block';	}
	thisImg.src = (switchFlag)? thisImg.src.replace('up','down'): thisImg.src.replace('down','up');
	switchFlag = (switchFlag)?0:1;
}

function underConstruct(){
	alert('功能建置中，近期推出，敬請期待! ');
}
//-->
