// JavaScript Document
function $i(id){return document.getElementById(id);}

// tab切换
function tabswitch(c, config){
	this.config = config ? config : {start_delay:500, delay:500};
	this.container = $i(c);
	this.pause = false;
	this.nexttb = 1;
	this.tabs = this.container.getElementsByTagName('dt');
	var _this = this;
	if(this.tabs.length<1)this.tabs = this.container.getElementsByTagName('li');
	for(var i = 0; i < this.tabs.length; i++){
		var _ec = this.tabs[i].getElementsByTagName('span');
		if(_ec.length<1)_ec = this.tabs[i].getElementsByTagName('a');
		if(_ec.length<1){
			_ec = this.tabs[i]
		}else{
			_ec = _ec[0];
		}
		_ec.onmouseover = function(e) {
			_this.pause = true;
			var ev = !e ? window.event : e;
			_this.start(ev, false, null);
		};
		
		_ec.onmouseout = function() {
			_this.pause = false;
		};
		
		try{
			$i(this.tabs[i].id + '_body_1').onmouseover = function(){
				_this.pause = true;
			};
			
			$i(this.tabs[i].id + '_body_1').onmouseout = function(){
				_this.pause = false;
			};
		}catch(e){}
	}

	if ($i(c + '_sts')) {
		var _sts = $i(c + '_sts');
		var _step = _sts.getElementsByTagName('li');
		if(_step.length<1)_step = _sts.getElementsByTagName('div');
		_step[0].onclick = function() {
			if (_this.tabs[_this.tabs.length-1].className.indexOf('current') > -1) {
				_this.nexttb = _this.tabs.length + 1;
			};
			_this.nexttb = _this.nexttb - 2 < 1 ? _this.tabs.length : _this.nexttb - 2;
			//alert(_this.nexttb);
			_this.start(null, null, _this.nexttb);
		};
		
		_step[1].onclick = function() {
			_this.nexttb = _this.nexttb < 1 ? 1 : _this.nexttb;
			_this.start(null, null, _this.nexttb);
		};
	};
	
	this.start = function(e, r, n){
		if(_this.pause && !e)return;
		if(r){
			curr_tab = $i(_this.container.id + '_' + rand(4));
		}else{
			if(n){
				//alert(_this.container.id + '_' + _this.nexttb);
				curr_tab = $i(_this.container.id + '_' + _this.nexttb);
			}else{
				curr_tab = e.target ? e.target : e.srcElement;
				if(curr_tab.id=="")curr_tab = curr_tab.parentNode;
			}
		}
		
		var tb = curr_tab.id.split("_");
		for(var i = 0; i < _this.tabs.length; i++){
			if(_this.tabs[i]==curr_tab){
				_this.tabs[i].className="selected current";
				try{
					//alert(_this.tabs[i].id);
					$i(_this.tabs[i].id + '_body_1').style.display = "block";
				}catch(e){}
			}else{
				_this.tabs[i].className="";
				try{
					$i(_this.tabs[i].id + '_body_1').style.display = "none";
				}catch(e){}
			}
		}
		_this.nexttb = parseInt(tb[tb.length-1]) >= _this.tabs.length ? 1 : parseInt(tb[tb.length-1]) + 1;
	};
}
var banners,hots,sides,cooperater_run,limit_run;
function init_load(){
	if($i('sides')){
		sides = new tabswitch('sides', {});
		setInterval("sides.start(null, null, 1);", 3000);
	}	
    if ($i('banners')) {	
		banners = new tabswitch('banners', {});
		setInterval("banners.start(null, null, 1);", 3000);
	}	
}

if(window.attachEvent){
    window.attachEvent("onload",init_load);
}else if(window.addEventListener){
    window.addEventListener("load",init_load,false);
}

function setTab(a,b,d,c){
	c.t=setTimeout(function(){
					   for(i=1;i<=d;i++){
						   var f=document.getElementById(a+"tabs_"+i);
						   var e=document.getElementById(a+"Panel_"+i);
						   var g=document.getElementById(a+"PanelMore_"+i);
						   f.className=i==b?"selected":"";
						   e.style.display=i==b?"block":"none";
						   g.style.display=i==b?"block":"none";
						}
					},200);
	c.onmouseout=function(){
		clearTimeout(this.t)
	}
}

function setPic(a,b,d,c){
	c.t=setTimeout(function(){
					   for(i=1;i<=d;i++){
						   var f=document.getElementById(a+"_"+i);
						   var e=document.getElementById("bigpic_"+i);
						   f.className=i==b?"selected":"";
						   e.style.display=i==b?"block":"none";
						}
					},200);
	c.onmouseout=function(){
		clearTimeout(this.t)
	}
}

 
 function ItemPageClick(surl){
	window.location.href = surl + '&page=' + String(document.getElementById('ItemPage').value);
}

function checksearch(){
//	if(document.searchform.q.value==''){
//		alert('请输入您的搜索字词');
//		document.searchform.q.focus();
//		return false;	
//	}
		
}
function closemsg(){
	$i('notice').style.display='none';
	setCookie('noticeclose','1','168');
}

function setCookie(name,value,exptime)
{
   // var Days = 1;
    var exp  = new Date();    //new Date("December 31, 9998");
        //exp.setTime(exp.getTime() + Days*24*60*60*1000);
		exp.setTime(exp.getTime() + exptime*60*60*1000);
        document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
}
function getCookie(name)
{
    var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
        if(arr=document.cookie.match(reg)) return unescape(arr[2]);
        else return null;
}

//function setCookie(name, value, hours)
//{
//  var expire = "";
//  if(hours != null)
//  {
//  expire = new Date((new Date()).getTime() + hours * 3600000);
//  expire = "; expires=" + expire.toGMTString();
//  }
//  document.cookie = name + "=" + escape(value) + expire;
//}

//function getCookie(name)
//{
//	var cookieValue = "";
//	var search = name + "=";
//	if(document.cookie.length > 0)
//	{  
//		offset = document.cookie.indexOf(search);
//		if (offset != -1)
//		{  
//			offset += search.length;
//			end = document.cookie.indexOf(";", offset);
//			if (end == -1) end = document.cookie.length;
//			cookieValue = unescape(document.cookie.substring(offset, end))
//		}
//	}
//}

