var CurrentIndex=0;
function switchTab(index)
{
   
   document.getElementById("index"+CurrentIndex).style.display="none";
   document.getElementById("LinkIndex"+CurrentIndex).className="aa";
   CurrentIndex=index;
   //鼠标事件之后的模式
   document.getElementById("index"+index).style.display="inline";
   document.getElementById("LinkIndex"+index).className="";

}
//newshowTab
function newshowTab(index)
{
   
   document.getElementById("index"+CurrentIndex).style.display="none";
   document.getElementById("LinkIndex"+CurrentIndex).className="";
   CurrentIndex=index;
   //鼠标事件之后的模式
   document.getElementById("index"+index).style.display="inline";
   document.getElementById("LinkIndex"+index).className="aa";

}

//文本框得到與失去焦點
function clearTxt(id,txt) {
	if (document.getElementById(id).value == txt)
		document.getElementById(id).value="" ;
	return ;
}
function fillTxt(id,txt) {
	if ( document.getElementById(id).value == "" )
		document.getElementById(id).value=txt;
	return ;
}

//焦點圖片輪換
function $(id) { return document.getElementById(id); }

function addLoadEvent(func){
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function(){
			oldonload();
			func();
		}
	}
}

function addBtn() {
	if(!$('focus_turn')||!$('focus_pic')||!$('focus_tx')) return;
	var focusList = $('focus_pic').getElementsByTagName('li');
	if(!focusList||focusList.length==0) return;
	var btnBox = document.createElement('div');
	btnBox.setAttribute('id','focus_btn');
	var SpanBox ='';
	for(var i=1; i<=focusList.length; i++ ) {
		var spanList = '<span class="normal">'+i+'</span>';
		SpanBox += spanList;
	}
	btnBox.innerHTML = SpanBox;
	$('focus_turn').appendChild(btnBox);
	$('focus_btn').getElementsByTagName('span')[0].className = 'current';
}

function classNormal(){
	var focusList = $('focus_pic').getElementsByTagName('li');
	var btnList = $('focus_btn').getElementsByTagName('span');
	var txList = $('focus_tx').getElementsByTagName('li');
	for(var i=0; i<focusList.length; i++) {
		focusList[i].className='normal';
		btnList[i].className='normal';
		txList[i].className='normal';
	}
}

function classCurrent(n){
	var focusList = $('focus_pic').getElementsByTagName('li');
	var btnList = $('focus_btn').getElementsByTagName('span');
	var txList = $('focus_tx').getElementsByTagName('li');
	focusList[n].className='current';
	btnList[n].className='current';
	txList[n].className='current';
}

var autoKey = false;
function btnTurn() {
	if(!$('focus_turn')||!$('focus_pic')||!$('focus_tx') || !$('focus_btn')) return;
	$('focus_turn').onmouseover = function(){autoKey = true};
	$('focus_turn').onmouseout = function(){autoKey = false};	
	var focusList = $('focus_pic').getElementsByTagName('li');
	var btnList = $('focus_btn').getElementsByTagName('span');
	var txList = $('focus_tx').getElementsByTagName('li');
	for (var m=0; m<btnList.length; m++){
		btnList[m].onmouseover = function() {
			classNormal();
			this.className='current';
			var n=this.childNodes[0].nodeValue-1;
			focusList[n].className='current';
			txList[n].className='current';
		}
	}
}

addLoadEvent(addBtn);
addLoadEvent(btnTurn);
addLoadEvent(setautoturn);

function setautoturn() {
	setInterval('autoTurn()', 5000);
}

function autoTurn() {
	if(!$('focus_turn')||!$('focus_pic')||!$('focus_tx')) return;
	if (autoKey) return;
	var focusList = $('focus_pic').getElementsByTagName('li');
	var btnList = $('focus_btn').getElementsByTagName('span');
	var txList = $('focus_tx').getElementsByTagName('li');
	for(var i=0; i<focusList.length; i++) {
		if (focusList[i].className == 'current') {
			var currentNum = i;
		}
	}
	if (currentNum==focusList.length-1 ){
		classNormal();
		classCurrent(0);
	} else {
		classNormal();
		classCurrent(currentNum+1);
	}

}

//相冊焦點圖片切換
function imageFocus(){
	if(!$('image_focus')||!$('image_focus_big')||!$('image_focus_small')) return;
	var imageSmallLists= $('image_focus_small').getElementsByTagName('li');
	var imageBigLists= $('image_focus_big').getElementsByTagName('li');
	for(var i=0; i<imageSmallLists.length; i++){
		imageSmallLists[i].setAttribute('nodeNo',i);
	}
	for(var i=0; i<imageSmallLists.length; i++){
		imageSmallLists[i].onmouseover= function() {
			var n= this.getAttribute('nodeNo');
			for(var m=0; m<imageBigLists.length; m++){
				imageBigLists[m].className='';	
			}
			imageBigLists[n].className='current';		
		}
	}
}
addLoadEvent(imageFocus);

//搜索
function searchBox(){
	if(!$('more_search')||!$('search_box')) return;
	$('more_search').onclick=function(){
		$('search_box').className= '';
		$('more_search').style.display='none';
		$('close_search').style.display='block';
	}
	
	$('close_search').onclick=function(){
		$('search_box').className= 'fixoneline';
		$('more_search').style.display='block';
		$('close_search').style.display='none';
	}

}
addLoadEvent(searchBox);

function addseccode() {
	
	if(noseccode != 0) return;
	
	$('login_authcode_input').style.display = 'block';
	if($('login_authcode_img').style.display == 'block') {
		$('login_authcode_img').style.display='none';
	} 
	$('login_showclose').style.display = 'block';
	$('user_login_position').className = 'current';
}

function showseccode() {
	$('login_authcode_img').style.display='block';
	updateseccode();
}

function hidesec() {
	$('login_authcode_input').style.display = 'none';
	$('login_showclose').style.display = 'none';
	$('login_authcode_img').style.display = 'none';
	$('user_login_position').className = '';
}

//alt美化
var sPop = null;
var postSubmited = false;
document.write("<style type='text/css'id='defaultPopStyle'>");
document.write(".cPopText { font-family: Verdana, Tahoma; background-color: #DDEEFF; border: 1px #8899AA dashed; font-size: 12px; padding-right: 4px; padding-left: 4px; height: 20px; padding-top: 2px; padding-bottom: 2px; visibility: hidden; filter: Alpha(Opacity=80)}");

document.write("</style>");
document.write("<div id='popLayer' style='position:absolute;z-index:1000;' class='cPopText'></div>");



function showPopupText(event) {
        if(event.srcElement) o = event.srcElement; else o = event.target;
        if(!o) {
                return;
        }
        MouseX = event.clientX;
        MouseY = event.clientY;
        if(o.alt != null && o.alt != '') {
                o.pop = o.alt;
                o.alt = '';
        }
        if(o.title != null && o.title != '') {
                o.pop = o.title;
                o.title = '';
        }
        if(o.pop != sPop) {
                sPop = o.pop;
                if(sPop == null || sPop == '') {
                        $('popLayer').style.visibility = "hidden";
                } else {
                        popStyle = o.dyclass != null ? o.dyclass : 'popupmenu_popup';
                        $('popLayer').style.visibility = "visible";
                        showIt();
                }
        }
}

function showIt() {
        $('popLayer').className = popStyle;
        $('popLayer').innerHTML = sPop.replace(/</g,"<").replace(/>/g,">").replace(/\n/g,"<br>");
               
        var bodySL, bodyST;
        if(window.pageXOffset){
                bodySL=window.pageXOffset;
        }else if(document.documentElement&&document.documentElement.scrollLeft){
                bodySL=document.documentElement.scrollLeft;
        }else if(document.body){
                bodySL=document.body.scrollLeft; //author: meizz
        }
        
        if(window.pageYOffset){
                bodyST=window.pageYOffset;
        }else if(document.documentElement&&document.documentElement.scrollTop){
                bodyST=document.documentElement.scrollTop;
        }else if(document.body){
                bodyST=document.body.scrollTop;
        }
        
        var bodyCW, bodyCH;
        if(window.innerWidth){
                bodyCW=window.innerWidth;
        }else if(document.documentElement&&document.documentElement.clientWidth){
                bodyCW=document.documentElement.clientWidth;
        }else if(document.body){
                bodyCW=document.body.clientWidth; //author: meizz
        }
        
        if(window.innerHeight){
                bodyCH=window.innerHeight;
        }else if(document.documentElement&&document.documentElement.clientHeight){
                bodyCH=document.documentElement.clientHeight;
        }else if(document.body){
                bodyCH=document.body.clientHeight;
        }

        if($('popLayer').clientWidth>300){
                var popWidth = 300;
        }else{
                var popWidth = $('popLayer').clientWidth;
        }
        
        var popWidth = $('popLayer').clientWidth;
        var popHeight = $('popLayer').clientHeight;
        var popLeftAdjust = MouseX + 12 + popWidth > bodyCW ? -popWidth - 24 : 0;
        var popTopAdjust = MouseY + 12 + popHeight > bodyCH ? -popHeight - 24 : 0;
        $('popLayer').style.left = (MouseX + 12 + bodySL + popLeftAdjust) + 'px';
        $('popLayer').style.top = (MouseY + 12 + bodyST + popTopAdjust) + 'px';
}

if(!document.onmouseover) {
        document.onmouseover = function(e) {
                var event = e ? e : window.event;
                showPopupText(event);
        };
}


