function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

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_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_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_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_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 MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function hoverTag(who, lang){
	for(var i=1; i<=4; i++){
		MM_swapImage('tag'+i,'','/imgs/tag'+i+((i==now)? 'c' : ((i==who)? 'o' : ''))+'-'+lang+'.gif',1);
	}
}

function outTag(who, lang){
	if(who!=now){
		MM_swapImage('tag'+who,'','/imgs/tag'+who+'-'+lang+'.gif',1);
	}
}

function switchTagCT(who, lang){
	now=who;
	for(var i=1; i<=4; i++){
		MM_swapImage('tag'+i,'','/imgs/tag'+i+((i==now)? 'c' : '')+'-'+lang+'.gif',1);
		document.getElementById('tagCT'+i).style.display=(i==now)? "block" : "none";
	}
}


//============= Add by Ibson =======================================

var ROOT="/englishpage/";

// ]i]X Layer  JavaScript qo}l copy
runTimer=false;
interval=25; // 移動順暢度, 數字越小越順暢
speed=4;     // 移動速度, 數字越大越慢
ctW=200;    // 內容展開寬度
ctH=70;     // 內容高度
iniX=175;    // 內容初始 x 位置
iniY=126;    // 容器初始 y 位置
ctIniW=ctW-iniX;  // 內容縮回寬度
nowOpen=false;

function iniSetFunc(){
	document.getElementById("areaContainer").style.display="block";
	document.getElementById("areaContainer").style.position="absolute";
	document.getElementById("areaContainer").style.overflow="hidden";
	document.getElementById("areaContainer").style.zIndex=1; 
	document.getElementById("areaContainer").style.width=ctIniW+"px";
	document.getElementById("areaContainer").style.height=ctH+"px";
	document.getElementById("areaContainer").style.right=0+"px";
	document.getElementById("areaContainer").style.top=iniY+"px";
	document.getElementById("ct").style.position="absolute";
	document.getElementById("ct").style.width=ctW+"px";
	document.getElementById("ct").style.height=ctH+"px";
	document.getElementById("ct").style.left=0+"px";
	document.getElementById("ct").style.top=0+"px";
	MM_preloadImages('/imgs/sideTag2.gif');
	setSideMenuHeight();
}

function setSideMenuHeight(){
	
	if($("_sideMenuButton")==null){
		setTimeout("setSideMenuHeight()",100);
	}
	else{
		smHeight=$("_sideMenuButton").getHeight();
		Element.setStyle("areaContainer",{height: smHeight+"px"});
	}
}

var _dlTimer=null;

function toggleBtn(e){
	if(!nowOpen){
		nowOpen=true;	 
		document.getElementById("areaContainer").style.width=ctW+"px";
		document.getElementById("ct").style.left=iniX+"px";
		if(nowOpen&&(!runTimer)){clearTimeout(_dlTimer);moveLayer("ct", "out");}
	}
	else{
		if(!Position.within($("_sideMenuTable"),Event.pointerX(e),Event.pointerY(e))){
			if(!runTimer){
				_dlTimer=setTimeout("moveLayer(\"ct\")",380);
				nowOpen=false;
			}
		}
	}
}

function  moveLayer(who, x){
	if(x=="out"){
		var targetX=0;
	}else{
		var targetX=iniX;
	}
	if(runTimer){
		clearInterval(moveTimer);
	}
	moveObj=document.getElementById(who);
	moveTargetX=targetX;
	moveTimer=setInterval(moveFunc, interval);
	runTimer=true;
}
function convertToNum(str){
	var pxIndex=str.indexOf("px");
	var moveObjNowX=Number(str.substring(0, pxIndex));
	return moveObjNowX;
}
function moveFunc(){
	moveObjNowX=convertToNum(moveObj.style.left);
	tmpMoveValue=Math.ceil((moveTargetX-moveObjNowX)/speed);
	if(tmpMoveValue==0 && ((moveTargetX-moveObjNowX)<0)){
		tmpMoveValue=-1;
	}
	moveObjNowX+=tmpMoveValue;
	moveObj.style.left=moveObjNowX+"px";
	moveObjNowX=convertToNum(moveObj.style.left);
	//status=moveObjNowX;
	if(Math.abs(moveTargetX-moveObjNowX)<=1){
		moveObj.style.left=moveTargetX+"px";
		if(moveTargetX==iniX){
			document.getElementById("areaContainer").style.width=ctIniW+"px";
			document.getElementById("ct").style.left=0+"px";
		}
		clearInterval(moveTimer);
		runTimer=false;
	}
}

function getSideMenu(){
	var pars="",url=ROOT+"include/asp/getSideMenu.asp";
	var myAjax = new Ajax.Updater(
				"_sideMenu", 
				url, 
				{
					method: "post", 
					parameters: pars,
					onFailure: rptErr,
					evalScripts: true
				});
}

function getMenuItems(theSubjectID){
	var pars="id="+theSubjectID,url=ROOT+"include/asp/getMenuItems.asp";
	var myAjax = new Ajax.Updater(
				"_sideMenuItems", 
				url, 
				{
					method: "post", 
					parameters: pars,
					onFailure: rptErr,
					evalScripts: true
				});
}

function rptErr(theReq){
	alert("Error occured !\nHTTP Status : "+theReq.status);
	return false;
	//document.write(theReq.responseText);
}

//================== Cookies funcitons ==========================

function GetCookie (name) {

	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;

	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
		return getCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	}

	return null;
}

function SetCookie (name, value) {

	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;

	document.cookie = name + "=" + escape (value) +
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
	((path == null) ? "" : ("; path=" + path)) +
	((domain == null) ? "" : ("; domain=" + domain)) +
	((secure == true) ? "; secure" : "");

}

function DeleteCookie (name) {

	var exp = new Date();
	exp.setTime (exp.getTime() - 1);
	var cval = GetCookie (name);
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();

}

var expDays = 30;
var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

function amt(){

	var count = GetCookie('count')

	if(count == null) {
		SetCookie('count','1')
		return 1
	}
	else {
		var newcount = parseInt(count) + 1;
		DeleteCookie('count')
		SetCookie('count',newcount,exp)
		return count
	}
}

function getCookieVal(offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
	endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

//================== Cookies funcitons ==========================

//================== Content font size funcitons ==========================

document.getElementsByClassName = function(cl) {
	var retnode = [];
	var myclass = new RegExp('\\b'+cl+'\\b');
	var elem = this.getElementsByTagName('*');
	for (var i = 0; i < elem.length; i++) {
		var classes = elem[i].className;
		if (myclass.test(classes)) retnode.push(elem[i]);
	}
	return retnode;
};

function changeFontSize(fsid){

	var contentBolcks=null;
	//var currFontSize=Element.getElementsByClassName("container","ct")==""?(Element.getElementsByClassName("container","ctM")==""?"L":"M"):"";
	var initFontSize=GetCookie("last_ftsz");
	var currFontSize=(initFontSize==""||initFontSize==null)?"":GetCookie("curr_ftsz");
	var origClasses=["tablebg1","tablew","tablebg2","title","sub","sub0","sub1","sub2","sub3","ps","ptname","ptw","link3","inputTextct","inputTextct1","ct","item","ptno","link2","link"];
	var newFontSize=fsid==2?"L":fsid==1?"M":"";

	for (i=0;i<origClasses.length;i++){
		contentBolcks=document.getElementsByClassName(origClasses[i]+currFontSize);
		//contentBolcks=Element.getElementsByClassName("container",origClasses[i]+currFontSize);
		if(contentBolcks){
			for(j=0;j<contentBolcks.length;j++){
				if(contentBolcks[j]){
					contentBolcks[j].className=origClasses[i]+newFontSize;
					//Element.removeClassName(contentBolcks[j],origClasses[i]+currFontSize);
					//Element.addClassName(contentBolcks[j],origClasses[i]+newFontSize);
				}
			}
		}
	}

	SetCookie("curr_ftsz",newFontSize);
	SetCookie("last_ftsz",newFontSize);

	var fsButton=[{btnId:"FS",imgsrc:"imgs/btn-fontS.gif",hoverimgsrc:"imgs/btn-fontSo.gif"},
		{btnId:"FM",imgsrc:"imgs/btn-fontM.gif",hoverimgsrc:"imgs/btn-fontMo.gif"},
		{btnId:"FL",imgsrc:"imgs/btn-fontL.gif",hoverimgsrc:"imgs/btn-fontLo.gif"}
	];

	var theImage="";

	for(i=0;i<fsButton.length;i++){
		if(fsid==i){
			theImage=ROOT+fsButton[i].hoverimgsrc;
			document._currFSImg=fsButton[i].btnId;
		}
		else theImage=ROOT+fsButton[i].imgsrc;
		$(fsButton[i].btnId).src=theImage;
	}
}

function initFontSize(){

	SetCookie("last_ftsz","");
	var lastfs=GetCookie("curr_ftsz");
	lastfs=lastfs=="L"?2:lastfs=="M"?1:0
	if(lastfs!=0) changeFontSize(lastfs);

}

//================== Content font size funcitons ==========================


function setTopMenu(){

	var loc=location.toString().toLowerCase();
	var topMenu=["\/about\/","\/businessopp\/","\/products\/","\/sitemap\/"];

	for(i=0;i<topMenu.length;i++){
		if(loc.indexOf(topMenu[i])!=-1){
			Element.removeClassName("tm"+i,"menu");
			Element.addClassName("tm"+i,"menunow");
			break;
		}
	}

}

function init(){
	Event.observe("_sideMenuTable", "mouseover", toggleBtn, false);
	Event.observe("_sideMenuTable", "mouseout", toggleBtn, false);
	MM_preloadImages(ROOT+"imgs/btn-fontSo.gif",ROOT+"imgs/btn-fontMo.gif",ROOT+"imgs/btn-fontLo.gif");
	initFontSize();
//	getLoginBlock();
//	setLeftMenu();
	setTopMenu();
	getSideMenu();
	iniSetFunc();
}

Event.observe(window, "load", init, false);

//============= Add by Ibson =======================================


