var domain = document.domain;
var isIndex = false;
var locate = window.location.toString();
	
if(locate.length == (locate.lastIndexOf("/") + 1) ||
	locate.indexOf("/index.") != -1 ){
	isIndex = true;
}

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g, "");
}

function getCookie(name){
var cname = name + "=";
var dc = document.cookie;
if (dc.length != 0) 
{
	begin = dc.indexOf(cname);
	if(begin != -1) 
	{
		begin += cname.length;
		end = dc.indexOf(";", begin);
		if(end == -1) end = dc.length;
		return unescape(dc.substring(begin, end));
	}
}
return null;
}

function setCookie(name, value, expires) {
	document.cookie = name + "=" + escape(value) + ((expires == null) ? "" : "; expires=" + expires.toGMTString()) + "; path=/";
}

function setActiveStyleSheet(title, reset) {
  var i, a, main, j;
  j=0
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
			a.disabled = true;
			j++;
			if (title == null && j==1) a.disabled = false;
      if(a.getAttribute("title") == title) {
				a.disabled = false;
			}
		}
	}
  //document.all.HideTextSize.value = title;
	//alert(title);
  if (reset == 1) {
		//alert("W->" + title);
		setCookie("wstyle", title , null);
	
	  //createCookie("wstyle", title, 365);
  }
}

function fontline(name)
{
var cname1 = name + "=";
var dc1 = document.cookie;
var tt="";
if (dc1.length != 0) 
{
	begin = dc1.indexOf(cname1);
	if(begin != -1) 
	{
		begin += cname1.length;
		end = dc1.indexOf(";", begin);
		if(end == -1) end = dc1.length;
		
	   tt=unescape(dc1.substring(begin, end));
	}
}


 if (tt=='') tt='SmallText';
 	var fss = document.getElementById("fss");
	var fsm = document.getElementById("fsm");
	var fsl = document.getElementById("fsl");
       fss.src='images/font_s.gif';
       fsm.src='images/font_m.gif';
       fsl.src='images/font_l.gif';

       if (tt=='SmallText')
           fss.src='images/font_s_on.gif';
		if (tt=='MediumText')
           fsm.src='images/font_m_on.gif';
		if (tt=='LargeText')
           fsl.src='images/font_l_on.gif';
		   
    
return null;

}



function Sfontline(name,t1)
{
var cname1 = name + "=";
var dc1 = document.cookie;
var tt="";
var tt1=t1;
if (dc1.length != 0) 
{
	begin = dc1.indexOf(cname1);
	if(begin != -1) 
	{
		begin += cname1.length;
		end = dc1.indexOf(";", begin);
		if(end == -1) end = dc1.length;
		
	   tt=unescape(dc1.substring(begin, end));
	}
}
//alert(tt);
if  (tt1=='小')
{       if (tt=='SmallText')
             return '<u>小</u>';
	else
	     return '小';
}

if  (tt1=='中')
{       if (tt=='MediumText')
	     return '<u>中</u>';
	else
	     return '中';
}

if  (tt1=='大')
{       if (tt=='LargeText')
	     return '<u>大</u>';
	else
	     return '大';
}
    
return null;

}

// JavaScript Document
var rNum; 
rNum = Math.random();
rNum = Math.round(rNum*2);

function showImgArea(randNum){
	if(randNum != 0 ){
		document.getElementById("img_area0").style.display = "none";
		document.getElementById("img_area"+randNum).style.display = "block";
	}
}

function showStandingBar(sid){
	if(sid == 1){
		document.getElementById("standingBar2").style.display = "none";
		document.getElementById("standingBar1").style.display = "block";
	}else{
		document.getElementById("standingBar1").style.display = "none";
		document.getElementById("standingBar2").style.display = "block";
	}
}

function hideThis(divId){
	document.getElementById("columnText"+divId).style.display = "none";
	document.getElementById("columnHide"+divId).style.display = "block";
}

function showThis(divId){
	for(var i =0 ; i <3 ; i ++){
		if(divId == i){
			document.getElementById("columnText"+i).style.display = "block";
			document.getElementById("columnHide"+i).style.display = "none";
		}else{
			hideThis(i);
		}
	}
}

function goQuery(){
	document.getElementById('queryForm').submit();
}

function goStanding(){
	var standOpt = document.getElementById('season_standing');
	var standPage = "standing.html";
	for(var z =0 ; z < standOpt.options.length ; z ++){
		if(standOpt.options[z].selected){
			standPage = standOpt.options[z].value;
		}
	}
	location.href = standPage;
}


var arr_currentLayer = new Array("guest1","hdn1","cell1");
//用來紀錄作用中頁籤的頁面ID 預設是第一個頁面
var arr_currentDiv = new Array("g1","hdna","d1");
//showLayer()函式，參數為觸發該函式的元素及所屬頁面ID
	
function arr_showLayer(obj,div,arr_id,cs_name){
	//若目前的currentLayer不等於obj.id 表示要換頁面
	if(arr_currentLayer[arr_id]!=obj.id) {
		//先改變上一個頁籤及頁面的樣式
		arr_showIt(arr_currentLayer[arr_id],arr_currentDiv[arr_id],false,cs_name);
		//重設currentLayer及currentDiv的值
		arr_currentLayer[arr_id] = obj.id;
		arr_currentDiv[arr_id] = div;
		//最後再改變目前頁籤及頁面的樣式
		arr_showIt(arr_currentLayer[arr_id],arr_currentDiv[arr_id],true,cs_name);
	}
}
//showIt()函式，參數為currentLayer、currentDiv及模式
//mode為true時 則表示目前作用中 所以要顯示
//mode為false時 則表示目前非作用中 所以要隱藏
function arr_showIt(o,d,mode,cs_name){
	var obj = document.getElementById(o);
	var div = document.getElementById(d);
	//改變className則表示改變該元素所用的class
	obj.className = (mode?"":"in")+cs_name;
	div.style.display = mode?"block":"none";
}


function changeTeam(tid){
	if(tid != ""){
		location.href="?s="+tid;
	}
}

function DrawImage(ImgID,FitWidth,FitHeight) {
  // sbl 首頁
  if (ImgID.indexOf('imgindex') != -1) {
	  FitWidth = 130;
	  FitHeight=97;
  }
  var ImgD= document.getElementById(ImgID);
  
  var image=new Image();image.src=ImgD.src;
  if(image.width>0 && image.height>0){
    if(image.width/image.height>= FitWidth/FitHeight){
      if(image.width>FitWidth){ ImgD.width=FitWidth;ImgD.height=(image.height*FitWidth)/image.width;
      }else{ ImgD.width=image.width;ImgD.height=image.height; }
    }else{
      if(image.height>FitHeight){ ImgD.height=FitHeight;ImgD.width=(image.width*FitHeight)/image.height;
      }else{ ImgD.width=image.width;ImgD.height=image.height; }
    }
	ImgD.style.marginTop = ((FitHeight - ImgD.height )/2)+"px";
  	ImgD.style.marginBottom = ((FitHeight - ImgD.height )/2)+"px";
  }
}

function resizeWidth(ImgID,FitWidth) {
  var ImgD= document.getElementById(ImgID);
  
  var image=new Image();image.src=ImgD.src;
  if(image.width>0 && image.height>0){
	
	if(image.width>FitWidth){ 
		ImgD.width=FitWidth;
		ImgD.height=(image.height*FitWidth)/image.width;
	}else{
		ImgD.width = image.width;
		ImgD.height = image.height;
	}
	/*
	ImgD.style.marginTop = ((FitHeight - ImgD.height )/2)+"px";
  	ImgD.style.marginBottom = ((FitHeight - ImgD.height )/2)+"px";
	*/
  }
}


function delayDo( func , sec){
	
	window.setTimeout(func,sec);
}

function goSeason(){
	var season = document.getElementById("seasonQuery");
	for(var i=0;i<season.length;i++){
		if(season.options[i].selected){
			location.href=season.options[i].value;
		}
	}
	
}