﻿//Edit By JasonHuang 2007/04/03
//作業系統類型判斷
window.appVersion = window.navigator.appVersion;
if(window.appVersion!=null){
	window.appVersion = window.appVersion.toUpperCase();
	window.MacIE5 = ((window.appVersion.toUpperCase().indexOf("MSIE") >=0) && (window.appVersion.toUpperCase().indexOf("MACINTOSH") >=0) && (window.appVersion.indexOf("5.0") >=0));
}
window.OPR =(window.opera!=null)|| false;
window.IE = (document.all && (!window.OPR)) || false;
window.IE55 = (window.IE && window.createPopup!=null && document.createComment==null) || false;
window.MOZ = (window.outerWidth && !window.OPR && (window.navigator.product!=null)) || false;
window.IE50 = (window.IE && (document.createTextNode!=null) && (window.createPopup==null)) || false;
window.IE60 = (window.IE && document.createComment!=null ) || false;
window.IE40 = (document.all && !window.IE50 && !window.IE55 && !window.IE60 &&(window.opera==null) ) || false;
window.MS =( window.navigator.userAgent.toLowerCase().indexOf("windows") >= 0 ) || false ;
window.MAC =( window.navigator.appVersion.toLowerCase().indexOf("mac") >= 0 ) || false ;
window.CSS1 = (document.compatMode!=null)||false;
window.GDA = (( window.IE55 || window.IE50 || window.MOZ || window.IE60 ) && !window.MAC);
if(window.IE){
	window.WIN98 = (window.navigator.userAgent.toLowerCase().indexOf("windows 98")>=0); /* windows 98 has serous pronlem with DirectX when use filter, we need to remove that;*/
}
		
function getObj(ID){ //判別是否可使用document.getElementById,ID為表單id名稱
	if(document.getElementById == null){
		document.getElementById = document.all;
	}
	
	if(ID == null){
		return null;
	}
	return document.getElementById(ID); //回傳表單
}

function getTags(srcDocument, TagName){
	if(document.getElementsByTagName==null){
		return (new Array());
	}
	if(TagName==null){
		return (new Array());
	}
	return srcDocument.getElementsByTagName(TagName);
}

function getAttr(srcObj,attributeName){
	if(srcObj==null || attributeName==null){
		return null;
	}
	
	if(srcObj.getAttribute == null){
		return null;
	}
	
	attributeName = srcObj.getAttribute(attributeName);
	if(attributeName==""){
		attributeName=null
	}
	
	return attributeName;
}

function reSizeFix(){
	if(!window.IE|| window.Mac ){
		return;
	}
	
	if(!window.GDA){
		return;
	}
	
	if(window.baseFont1==null){
		window.baseFont1 = document.createElement("div");
		window.baseFont1.innerHTML="&nbsp;";
		window.baseFont1.style.cssText = "position:absolute;top:-5000px;font-size:16px;";
		document.body.insertAdjacentElement("AfterBegin", window.baseFont1);
	}
	
	if(window.baseFont2==null){
		window.baseFont2 = document.createElement("div");
		window.baseFont2.innerHTML="&nbsp;";
		window.baseFont2.style.cssText = "position:absolute;top:-5000px;font-size:100%;";
		document.body.insertAdjacentElement("AfterBegin", window.baseFont2);
		window.baseFont2.onresize = function(){
			reSizeFix();
		}
	}
	
	var ratio =window.baseFont2.offsetHeight / window.baseFont1.offsetHeight;
	getObj("main").style.width = Math.max( getObj("basewidth").offsetWidth, Math.ceil( ratio * getObj("basewidth").offsetWidth)) +"px"; window.pageWidth = getObj("main").style.width;
}

function PageLoad(){
	var sbtext=getObj("sbtext");
	SRBoxFox();
}

if(window.attachEvent){
	window.attachEvent("onload",PageLoad);
}else
if(window.addEventListener){
	window.addEventListener("load",PageLoad,false);
}else{
	window.onload = PageLoad;
}
	
function SRBoxFox(ev){
	if(self!=top){
		return;
	}
	try{
		getObj("sbtext").focus();
		document.body.scrollTop=0;
		document.documentElement.scrollTop=0;
	}
	catch(e){
	}
}

function RunForWN(mainObj,secs){ 
	if(mainObj && (window.IE || window.MOZ) && (!window.MAC)){ //判別非Mac版本
		//暫停判別
		mainObj.Hover = false;
		mainObj.onmouseover = function(){
			this.Hover = true;
		}
		mainObj.onmouseout = function(){
			this.Hover = false;
		}
		
		mainObj.style.display = "block";
		mainObj.divs = new Array();
		var divs = getTags(mainObj,"div"); //物件使用為div
		var tbs = getTags(mainObj,"table"); //物件使用為table
		var tds = getTags(mainObj,"td"); //物件使用為td
		
		for(i=0;i<tbs.length;i++){
			if(getAttr(tbs[i],"width")){
				tbs[i].removeAttribute("width");
			}
		}
		for(i=0;i<tds.length;i++){
			if(getAttr(tds[i],"width")){
				tds[i].removeAttribute("width");
			}
		}
		
		var scrolldelay = getAttr(mainObj,"delay") || 2.5;
		if(isNaN(scrolldelay )){
			mainObj.style.display="none";
			return;
		}
		scrolldelay = Math.max(parseFloat(scrolldelay) * 100 ,secs); //在此設定轉動的速度
		for(i=0;i<divs.length;i++){
			mainObj.divs[i] = divs[i];
			divs[i].style.backgroundColor="";
			divs[i].m = setTimeout("void(0)",0);
			divs[i].n = i;
			divs[i].o = 10;
			divs[i].style.top = mainObj.offsetHeight*2 + "px";
			if(divs[i].id==null || divs[i].id == ""){
				divs[i].id = "_marquee_" + i;
			}
			divs[i].flyin = function(){
				clearTimeout(this.m);
				this.style.visibility = "visible";
				var b = this.n-1;
				if(b<0){b = mainObj.divs.length-1;
			}
			if(this.o >0 ){
				if(this.parentNode.Hover == false){
					this.o +=-2;this.style.top = ((this.parentNode.offsetHeight * this.o/10))+ "px";
				}
				this.m = setTimeout("getObj('"+this.id+"').flyin()",100);
			}else{
				this.o = 0;
				var n = this.n+1;
				if(n > (mainObj.divs.length-1)){
					n =0;
				}
				n = getObj("_marquee_" + n);
				if(n.id !=this.id){
					this.m = setTimeout("getObj('"+this.id+"').flyout()",(scrolldelay));
					n.m = setTimeout("getObj('"+n.id+"').style.top='900px';getObj('"+n.id+"').flyin()",(scrolldelay-0));
				}
			}
		}
		divs[i].flyout = function(){
			clearTimeout(this.m);
			if(this.o < 10 ){
				if(this.parentNode.Hover == false){
					this.o+=2;
					this.style.top = ( -(this.o/10 * this.offsetHeight) -2) + "px";
				}
				this.m = setTimeout("getObj('"+this.id+"').flyout()",100);
			}else{
				this.o = 10;this.style.top = this.parentNode.offsetHeight*2 + "px";
			}
		}
	}
	if(divs.length >0){
		divs[0].style.top = "1px";
		divs[0].flyin();
	}
}else
	if(mainObj){
		mainObj.style.display="block";
		mainObj.style.overflow = "visible";
		mainObj.style.height="auto";
		var divs = getTags(mainObj,"div?");
		if( divs.length>=1){
			divs[0].style.position = "static";
			divs[0].style.visibility = "visible";
		}
	}
}

function RunForWN98(mainObj){
	mainObj.style.display = "block";
	var divs = getTags(mainObj,"div");
	var tbs = getTags(mainObj,"table");
	var tds = getTags(mainObj,"td");
	for(i=0;i<tbs.length;i++){
		if(getAttr(tbs[i],"width")){
			tbs[i].removeAttribute("width");
		}
	}
	for(i=0;i<tds.length;i++){
		if(getAttr(tds[i],"width")){
			tds[i].removeAttribute("width");
		}
	}
	divs = new Array();
	divs = getTags(mainObj,"div");
	var marquee = "";
	for(i=0;i<divs.length;i++){
		marquee+= "<div style='margin:0 0 0.2em 0;white-space:nowrap;display:block;visibility:visible;position:static;'>" + divs[i].innerHTML+ "</div>";
	}
	mainObj.innerHTML = "<marquee direction=up scrolldelay=200 scrollamount=1 onmouseover='this.stop()' onmouseout='this.start()'>" + marquee +"</marquee>" ;
}

function runMarquee(divname,secs){
	createCSS(divname);
	var mainObj = getObj(divname);
	if(secs == 0 || secs == '' || isNaN(secs) == true){
		secs = 2000;
	}else{
		secs = secs*1000
	}
	if(window.WIN98){
		RunForWN98(mainObj);
	}else{
		RunForWN(mainObj,secs);
	}
}

function createCSS(divname){
	document.write('<STYLE>')
	document.write('	#'+divname+' {')
	document.write('		DISPLAY: none; FONT-SIZE: 13px; MARGIN: 0px; OVERFLOW: hidden; POSITION: relative; HEIGHT: 25px')
	document.write('	}')
	document.write('	#'+divname+' DIV {')
	document.write('		PADDING-RIGHT: 0px; PADDING-LEFT: 5px; LEFT: 0px; VISIBILITY: hidden; PADDING-BOTTOM: 0px; PADDING-TOP: 0px; POSITION: absolute; TOP: 0px')
	document.write('	}')
	document.write('	#'+divname+' MARQUEE {')
	document.write('		DISPLAY: block; HEIGHT: 18px')
	document.write('	}')
	document.write('	#'+divname+' FONT {')
	document.write('		WHITE-SPACE: nowrap! important')
	document.write('	}')
	document.write('	</STYLE> ')
}
