var maincat = 0;
var xmlHttp;
function GetXmlHttpObject()
{
	var xmlHttp=null;
	try{// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e){
		try{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e){
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}
// advertisement
function click_textad(val,val2){
	xmlHttp=GetXmlHttpObject();
	var url="/textad/click_textad.php";
	url=url+"?banner="+val;
	url=url+"&zone="+val2;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);		
}	
function view_textad(val,val2){
	xmlHttp=GetXmlHttpObject();
	var url="/textad/view_textad.php";
	url=url+"?banner="+val;
	url=url+"&zone="+val2;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);		
}
function PopUp(URL, width, height,scroll) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, 'infoPage', 'toolbar=0,scrollbars='+scroll+',location=0,statusbar=0,menubar=0,resizable=0,width=' + width + ',height=' + height + ',left = 100,top = 0');");
}
function click_banner(val,val2){
	xmlHttp=GetXmlHttpObject();
	var url="/banner/click_banner.php";
	url=url+"?banner="+val;
	url=url+"&zone="+val2;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);		
}	
function view_banner(val,val2){
	xmlHttp=GetXmlHttpObject();
	var url="/banner/view_banner.php";
	url=url+"?banner="+val;
	url=url+"&zone="+val2;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);		
}
function openflash(width,height,src){ 
	var text="<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\" width="+width+" height="+height+"><param name=movie value="+src+"><param name=quality value=high ><param name=wmode value=transparent><param name=menu value=false><embed src="+src+" quality=high  pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"application/x-shockwave-flash\" width="+width+" height="+height+"  wmode=transparent menu=false></embed></object>"; 
	document.write(text); 
} 
function openflash2(divid,width,height,src){ 
	var text="<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\" width="+width+" height="+height+"><param name=movie value="+src+"><param name=quality value=high ><param name=wmode value=transparent><param name=menu value=false><embed src="+src+" quality=high  pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"application/x-shockwave-flash\" width="+width+" height="+height+"  wmode=transparent menu=false></embed></object>"; 
	document.getElementById(divid).innerHTML=text;
} 

//ZhaiHao Modify
function write_editor(emailaddress) {
	window.location = 'mailto:'+emailaddress+'?subject=Reader Feedback&body=Dear Editor, %0D%0A%0D%0A';
}
//
function tagshow(val1,val2,topid,now){
	var getallnum = getObject(topid).getElementsByTagName("li") 
	var allnum = getallnum.length;
	for(i=0;i<allnum;i++){
		if(i==now){
			getObject(val1+i).style.display='block';
			getObject(val2+i).className='active';
		}else{
			getObject(val1+i).style.display='none';
			getObject(val2+i).className='';
		}
	}
}
function tag_show(val1,val2,allnum,now){
	for(i=1;i<=allnum;i++){
		if(i==now){
			getObject(val1+i).style.display='block';
			getObject(val2+i).className='active';
		}else{
			getObject(val1+i).style.display='none';
			getObject(val2+i).className='';
		}
	}
}
function hiddenpanel (val) {
	var isVisible = getObject(val).style.display;
	if (isVisible == "none") {
		getObject(val).style.display="block";
	}
	else {
		getObject(val).style.display="none";
	}
}

function getObject(objectId) {
	if(document.getElementById && document.getElementById(objectId)) {
	// W3C DOM
	return document.getElementById(objectId);
	} else if (document.all && document.all(objectId)) {
	// MSIE 4 DOM
	return document.all(objectId);
	} else if (document.layers && document.layers[objectId]) {
	// NN 4 DOM.. note: this won't find nested layers
	return document.layers[objectId];
	} else {
	return false;
	}
} // getObject

//滚动图片
	var Obj;  
	var amount;
	var speed;
	var num = 0;	
	var moving = true;
	var target;
	var autos;
	var pho_limit=6;
	function move(val,picture_space,show){
		if(autos) clearTimeout(autos);
		if(moving){
			Obj = document.getElementById(show);
			if(val==2){ 
				moving = false;					
				if(num<pho_limit){					
					amount = (num+1)*picture_space;
					target = -1*picture_space*(num+1);
					go_right();
					num++;
				}else{
					num=0;
					Obj.style.left = "0px";
					amount = (num+1)*picture_space;
					target = -1*picture_space*(num+1);
					go_right();
					num++;				
				}		
			}else{		
				moving = false;		
				if(num>0){ 
					
					amount = (num-1)*picture_space;
					target = -1*picture_space*(num-1);
					go_left();
					num--;
				}else{
					num=pho_limit;
					Obj.style.left = -169*num+"px";
					amount = (num-1)*picture_space;
					target = -1*picture_space*(num-1);
					go_left();
					num--;					
				}	
			}
		}	
		var shownum=num+1;
		if(shownum>pho_limit)shownum=1;
		if(shownum==0)shownum=pho_limit+2;
	}
	function go_left(){
		if(Obj.style.left=="") Obj.style.left = "-1px";
		var current_pos = parseInt(Obj.style.left.substring(0,Obj.style.left.indexOf('px')));
		speed = -1*parseInt((current_pos+amount)/3)+8;
		
		Obj.style.left = current_pos + speed + "px";
		var sss = window.setTimeout("go_left()",100);
		if(current_pos>(target-11)){ 
			clearTimeout(sss);
			Obj.style.left = target+"px";
			moving = true;
		}			
	}	
	function go_right(){
		if(Obj.style.left=="") Obj.style.left = "-1px";
		var current_pos = parseInt(Obj.style.left.substring(0,Obj.style.left.indexOf('px')));
		speed = parseInt((current_pos+amount)/3)+8;
		Obj.style.left = current_pos - speed + "px";
		var sss = window.setTimeout("go_right()",100);
		if(current_pos<(target+12)){ 
			clearTimeout(sss);
			Obj.style.left = target+"px";
			moving = true;
		}			
	}
function tag_change(val1,val2,allnum,now){
	for(i=1;i<=allnum;i++){
		if(i==now){
			getObject(val1+i).style.display='block';
			getObject(val2+i).className='active';
			getObject('tab').className = 'tabbg'+i;
		}else{
			getObject(val1+i).style.display='none';
			getObject(val2+i).className='';
		}
	}
}
function tag_change2(val1,val2,allnum,now){
	for(i=1;i<=allnum;i++){
		if(i==now){
			getObject(val1+i).style.display='block';
			getObject(val2+i).className='active';
		}else{
			getObject(val1+i).style.display='none';
			getObject(val2+i).className='';
		}
	}
}
//login and register 2009/11/26 Samuel
function loginpanel () {
	var isVisible = document.getElementById("loginpanel").style.visibility;
	if (isVisible == "hidden") {
		document.getElementById("loginpanel").style.visibility="visible";
	}
	else {
		document.getElementById("loginpanel").style.visibility="hidden";
	}
}
function dologin() {
	var btcu = document.getElementById("login_username").value;
	var btcp = document.getElementById("login_password").value;
	if (btcu == "" || btcp == "") {
		alert("用戶名或密碼未輸入");
	}else {
		var chkSave = "";
		if (document.getElementById("login_remember").checked) {
			chkSave = document.getElementById("login_remember").value;
		}else {
			chkSave = "";
		}
		var params = "username=" + btcu + "&password=" + btcp + "&chkSave=" + chkSave + "&ajaxlogin=1";
		var xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null) {
			alert ("登陸失敗，請升級你的瀏覽器");
			return;
		}
		var url="/member/login.php";
		xmlHttp.onreadystatechange= function() {
			if (xmlHttp.readyState==4) { 
				if (xmlHttp.status == 200) {
					if (xmlHttp.responseText == "Okay") {
						location.reload();
					}else {
						alert("用戶名或密碼不正確");
					}
				}
			}
		};
		xmlHttp.open("POST", url, true);
		xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;"); 
		xmlHttp.send(params);
	}
}
function dologout() {
	location.assign("/member/loginout.php?backurl=" + location.href);
}
function usernamefocus () {
	document.getElementById("login_username").value="";
}
function passwordfocus () {
	document.getElementById("login_password").value="";
}
function dokeylogin(evt) {
	if (evt.keyCode == 13) {
	dologin();
	}
}
//Investment Menu Bar 2009/12/10
function hidpanel (val,val2,allnum) {
	for(i=1;i<=allnum;i++){
		if(i==val){
			getObject(val2+i).style.display='block';
		}else{
			getObject(val2+i).style.display='none';
		}
	}

}
function switch_cate(val){
	var isBlock = document.getElementById("category_s"+val).style.display;
	if (isBlock == "none") {
		document.getElementById("category_s"+val).style.display="block";
	}
	else {
		document.getElementById("category_s"+val).style.display="none";
	}
}
function clickurl(){
	var url = new Array("http://www.enagic.com","http://www.kangen3695.h2origin.com")
	var i=Math.floor(Math.random()*2);
	var a= url[i];
	window.open(a);
}
