/********************************************************
104 AD Style 1	(一般(水平)跑馬燈)

使用說明：
function ad_1(m,t,count,ad_width,ad_height,ad_top,ad_left,speed)
m : 專區代號
t : 廣告代號
count : 顯示則數
ad_width : 寬
ad_height : 高
ad_top : 垂直起始點
ad_left : 水平起始點
speed : 跑馬燈速度
********************************************************/
var isNe = false;
if(navigator.userAgent.indexOf('Netscape')>=0){
	var timerONE=0;
	var pause_marquee=300;
	var marquee_text_width = document.getElementById('marquee_text').style.width;
	marquee_text_width = marquee_text_width.substring(0,marquee_text_width.length-2);
	var marquee_start_left = document.getElementById('marquee').style.width;
	marquee_start_left = marquee_start_left.substring(0,marquee_start_left.length-2);
	var marquee_left = marquee_start_left;
	var isNe = true;
}

function scroll(){
	marquee_left -= 10;
	document.getElementById('marquee_text').style.left = marquee_left;
	if (marquee_left<=-marquee_text_width)
		marquee_left = marquee_start_left;
	timerONE=window.setTimeout('scroll()',pause_marquee);
}

function ad_1(m,t,count,ad_width,ad_height,ad_top,ad_left,speed){
	var temp = '';
	var id = new Array();
	if(!speed)
	{
		speed=250;
	}
	id = check_date(m,t,count);
	if (id!=-1){
		for (i=0; i<id.length; i++){
			
		
			var link_action=link_url(m,t,id[i]);
			
			temp+="<a style='text-decoration:none;'"+link_action+"><span class=h>"+eval('ad_'+m+'_'+t+'_data_name['+id[i]+']')+"</span></a><img border=0 width=80 height=1 src=http://www.104.com.tw/upload1/ad/img/space.gif>";
		}
		
		if(navigator.userAgent.indexOf('Netscape')>=0){
			document.getElementById('marquee').style.width = ad_width;
			document.getElementById('marquee').style.height = ad_height;
			document.getElementById('marquee').style.top = ad_top;
			document.getElementById('marquee').style.left = ad_left;
			document.getElementById('marquee_text').innerHTML = temp;
			marquee_text_width = document.getElementById('marquee_text').style.width;
			marquee_text_width = marquee_text_width.substring(0,marquee_text_width.length-2);
			marquee_start_left = document.getElementById('marquee').style.width;
			marquee_start_left = marquee_start_left.substring(0,marquee_start_left.length-2);
			marquee_left = marquee_start_left;
			scroll();
		}else{
			document.write("<MARQUEE scrolldelay='"+speed+"'>"+temp+"</MARQUEE>");
		}
	}
}





/********************************************************
104 AD Style 2 (垂直跑馬燈)

使用說明：
function ad_2(m,t,count,ad_width,ad_height,ad_top,ad_left)
m : 專區代號
t : 廣告代號
count : 顯示則數
ad_width : 寬
ad_height : 高
ad_top : 垂直起始點
ad_left : 水平起始點
********************************************************/
function ss(){
window.status='';
return true;
}

function moveslide(){
	if (curpos>0){
		curpos = Math.max(curpos-degree,0);
		tempobj.style.top = curpos + "px";
	}
	else{
		clearInterval(dropslide)
		if (crossobj.filters)
			crossobj.filters.alpha.opacity = 100
		else if (crossobj.style.MozOpacity)
			crossobj.style.MozOpacity = 1;
		nextcanvas = (curcanvas=="canvas0")? "canvas0" : "canvas1";
		tempobj = ie4? eval("document.all."+nextcanvas) : document.getElementById(nextcanvas);
		tempobj.innerHTML = scrollercontent[curindex];
		nextindex=(nextindex<scrollercontent.length-1)? nextindex+1 : 0;
		setTimeout("rotateslide()",pause);
	}
}

function rotateslide(){
	if (ie4||dom){
		resetit(curcanvas);
		crossobj=tempobj=ie4? eval("document.all."+curcanvas) : document.getElementById(curcanvas);
		crossobj.style.zIndex++;
		if (crossobj.filters){
			document.all.canvas0.filters.alpha.opacity=document.all.canvas1.filters.alpha.opacity=20;
		}
		else if (crossobj.style.MozOpacity){
			document.getElementById("canvas0").style.MozOpacity=document.getElementById("canvas1").style.MozOpacity=0.2;
		}
		var temp='setInterval("moveslide()",50)';
		dropslide=eval(temp);
		curcanvas=(curcanvas=="canvas0")? "canvas1" : "canvas0";
	}
	else if (document.layers){
		crossobj.document.write(scrollercontent[curindex]);
		crossobj.document.close();
	}
	curindex=(curindex<scrollercontent.length-1)? curindex+1 : 0;
}

function resetit(what){
	curpos=parseInt(scroller_height)*(1)
	var crossobj=ie4? eval("document.all."+what) : document.getElementById(what)
	crossobj.style.top=curpos+"px"
}

function MarqueeA(){
	crossobj=ie4? eval("document.all."+curcanvas) : dom? document.getElementById(curcanvas) : document.tickernsmain.document.tickernssub
	if (ie4||dom){
		crossobj.innerHTML=scrollercontent[curindex]
		rotateslide()
	}
	else{
		document.tickernsmain.visibility='show'
		curindex++
		setInterval("rotateslide()",pause)
	}
}

var scroller_width='100%';
var scroller_height='100%';
var scroller_top='100%';
var scroller_left = '100%';
var x = 0;
var y = 0;

if (document.all)
{
	x = document.body.clientWidth - 721;
	y =  32 //11;
}

if (document.getElementById && !document.all)
{
	x = window.innerWidth - 721; //
	y = 28 //7;
}
if (x < 0)
	x = 0;
x = (x/2) + y;
scroller_left = x + 'px';
var bgcolor='#FCFCFC';
var pause=1000;
var curpos = scroller_height*(1);
var degree = 10;
var curcanvas = "canvas0";
var curindex  = 0;
var nextindex = 1;
var ie4 = document.all;
var dom = document.getElementById && navigator.userAgent.indexOf("Opera") == -1;
var scrollercontent=new Array();

function ad_2(m,t,count,ad_width,ad_height,ad_top,ad_left){
	var scroller_width=ad_width;
	var scroller_height=ad_height;
	var scroller_top=ad_top;
	var scroller_left=ad_left;
	var id = new Array();
	id = check_date(m,t,count);
	if (id!=-1)
	{
		for (i=0; i<id.length; i++)
		{
					
			var link_action=link_url(m,t,id[i]);				
				
			scrollercontent[i]="<a style='text-decoration:none'"+link_action+"><span class=h>"+eval('ad_'+m+'_'+t+'_data_name['+id[i]+']')+"</span></a>";
		}
		
		if (ie4||dom)
		{
			document.write('<div id=CanVasA style="position:absolute;top:' + scroller_top + ';left:' + scroller_left + ';width:' + scroller_width + ';height:' + scroller_height + ';overflow:hidden">');
			document.write('<div id="canvas0" style="position:absolute;background-color:' + bgcolor + ';left:' + scroller_left + ';height:' + scroller_height + ';top:' + scroller_height + ';filter:alpha(opacity=20);-moz-opacity:0.2;"></div>');
			document.write('<div id="canvas1" style="position:absolute;background-color:' + bgcolor + ';left:' + scroller_left + ';height:' + scroller_height + ';top:' + scroller_height + ';filter:alpha(opacity=20);-moz-opacity:0.2;"></div>');
			document.write('</div>');
		}
		else if (document.layers)
		{
			document.write('<ilayer id=tickernsmain visibility=hide width=' + scroller_width + ' height=' + scroller_height + ' bgColor=' + bgcolor + '>');
			document.write('<layer id=tickernssub width='+scroller_width+' height='+scroller_height+' left=0 top=0>' + scrollercontent[0] + '</layer>');
			document.write('</ilayer>');
		}
	
		if (document.all || document.getElementById || document.layers)
			window.onload=MarqueeA;
	}
}






/********************************************************
104 AD Style 3	(靜態文字列)
Style 0 縱
Style 1 橫
Style 2 左右

使用說明：
function ad_3(m,t,s,count,css,h)
m : 目錄
t : 廣告代號
s : 0 = 縱
	1 = 橫
	2 = 左右
count : 顯示則數
css : css style
height : 表格高度

********************************************************/
function ad_3(m,t,s,count,css,h){
	var num=0;
	var target="";
	var id = new Array();
	id = check_date(m,t,count);

	if (id!=-1){
		icss="";if(css){icss="class='"+css+"'";};
		iheight="";if(h){iheight="height='"+h+"'";}
	
		document.write("<table border=0>");
		document.write("<tr>");
		for(i=0;i<id.length;i++){
			if (id[i]!=-1){
				
				
				var link_action=link_url(m,t,id[i]);			
								
				document.write("<td "+icss+" "+iheight+">•<a"+link_action+" >"+eval("ad_"+m+"_"+t+"_data_name")[id[i]]+"</a></td>");
				
				if(s>=2){
						if(num==eval(s-1)){
							document.write("</tr>");
							num=0;
						}else{
							num++;
						}
				}else if(s==0){			
					document.write("</tr>");
				}
			}
		}
		if(s==1)document.write("</tr>");
		document.write("</table>");
	}
}

/********************************************************
104 AD Style 4	浮水印
使用說明：
function ad_4(m,t){
m : 目錄
t : 廣告代號

********************************************************/


function setVals(){
	barW = 0;
	barH = 0;
	if (isNe){
		if (document.height > innerHeight)
			barW = 20;
		if (document.width > innerWidth)
			barH = 20;
	}
	else{
		innerWidth = document.body.clientWidth;
		innerHeight = document.body.clientHeight;
	}
	posX = innerWidth/2 + contentW/2 + space;
	posY = ((innerHeight - markH)-barH) * (markY/100);
}

function wRefresh(){
	var wMark = document.getElementById("waterMark").style;
	wMark.left = posX;
	wMark.top = posY + (isNe?window.pageYOffset:document.body.scrollTop);
}

function markMe(){
	setVals();
	window.onresize=setVals;
	markID = setInterval ('wRefresh()',markRefresh);
}

function ad_4(m,t){
	
	var wMark = document.getElementById("waterMark").style;
	
	if (document.getElementById || document.all){
		if (screen.width > 900)
			contentW = 670;
		else
			contentW = 600;
		space = 20;
		markW = 65;
		markH = 0;
		markY = 60;
		markRefresh = 20;		
		wMark.display = '';
		wMark.width = markW;
		wMark.height = markH;	
	}

	var id = check_date(m,t,1);
	
	if (id!=-1){
				
		var link_action=link_url(m,t,id);			

		if(ImageCheck(eval("ad_"+m+"_"+t+"_data_name")[id])==1){

			var temp="";			

			if (get_app()!=3&&get_app()!=4)
				temp +="<button style='border:none;background:transparent;' "+link_action+" width="+eval("ad_"+m+"_"+t+"_width")+" height="+eval("ad_"+m+"_"+t+"_height")+" hidefocus>";
			temp += "<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='"+eval("ad_"+m+"_"+t+"_width")+"' height='"+eval("ad_"+m+"_"+t+"_height")+"'>";
			temp += "<param name='movie' value='"+ad_domain_name+"/upload1/ad/"+m+"/"+eval("ad_"+m+"_"+t+"_data_name")[id]+"'>";
			temp += "<param name='quality' value='high'>";
			temp += "<param name='wmode' value='Opaque'>";
			if (get_app()==3||get_app()==4)
				temp += "<embed src='"+ad_domain_name+"/upload1/ad/"+m+"/"+eval("ad_"+m+"_"+t+"_data_name")[id]+"' quality='high' pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash' width='"+eval("ad_"+m+"_"+t+"_width")+"' height='"+eval("ad_"+m+"_"+t+"_height")+"'></embed></object>";
			else{
				temp += "<embed src='"+ad_domain_name+"/upload1/ad/"+m+"/"+eval("ad_"+m+"_"+t+"_data_name")[id]+"' quality='high' pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash' width='"+eval("ad_"+m+"_"+t+"_width")+"' height='"+eval("ad_"+m+"_"+t+"_height")+"' wmode='Opaque' style='margin:-1;'></embed></object>";		
				temp += "</button>";	
			}
			document.getElementById('waterMark').innerHTML=temp;							
		}else{
			document.getElementById('waterMark').innerHTML = "<a title='"+eval("ad_"+m+"_"+t+"_data_alt")[id]+"' "+link_action+"><img src="+ad_domain_name+"/upload1/ad/"+m+"/"+eval("ad_"+m+"_"+t+"_data_name")[id]+" width="+eval("ad_"+m+"_"+t+"_width")+" height="+eval("ad_"+m+"_"+t+"_height")+" border=0></a>";
		}		
		if (document.getElementById || document.all){
			markMe();
		}
	}else{
		return false;
	}
}


/********************************************************
104 AD Style 5	Fade-in (左邊)
使用說明：
2006-8-16新增的 function
m : 目錄
t : 廣告代號

********************************************************/
function switch_fadein(v1,flg){
	if (!(document.all || document.getElementById))
		return false;
	if (flg == null)
		var flg = "close";
		if (flg == "close"+v1){
				if (document.getElementById("notice_open"+v1) != null){
					document.getElementById("notice_open"+v1).style.visibility = "hidden";
					document.getElementById("notice_close"+v1).style.visibility = "visible";
				}
				if (document.getElementById("ad_fadein104_open"+v1) != null){
					document.getElementById("ad_fadein104_open"+v1).style.visibility = "hidden";
					document.getElementById("ad_fadein104_close"+v1).style.visibility = "visible";
				}
		}else{
			if (flg == "open_ad"+v1){
				if (document.getElementById("ad_fadein104_open"+v1) != null){
					document.getElementById("ad_fadein104_open"+v1).style.left = "0px";
					document.getElementById("ad_fadein104_open"+v1).style.visibility = "visible";
					document.getElementById("ad_fadein104_close"+v1).style.visibility = "hidden";
				}
			}
			else if (flg == "open_notice"+v1){
				if (document.getElementById("notice_open"+v1) != null){
					document.getElementById("notice_open"+v1).style.left = "0px";
					document.getElementById("notice_open"+v1).style.visibility = "visible";
					document.getElementById("notice_close"+v1).style.visibility = "hidden";
				}
			}else {
				if (document.getElementById("ad_fadein104_open"+v1) != null){
					document.getElementById("ad_fadein104_open"+v1).style.left = "0px";
					document.getElementById("ad_fadein104_open"+v1).style.visibility = "visible";
					document.getElementById("ad_fadein104_close"+v1).style.visibility = "hidden";
				}
				if (document.getElementById("notice_open"+v1) != null ){
					document.getElementById("notice_open"+v1).style.left = "0px";
					document.getElementById("notice_open"+v1).style.visibility = "visible";
					document.getElementById("notice_close"+v1).style.visibility = "hidden";
				}
			}
		}
}

function init_fadein(v1){
	if ( (!(document.all || document.getElementById)) || (document.getElementById("notice_open"+v1) == null) )
		return false;
	
	var obj = document.getElementById("notice_open"+v1);
	var obj2 = document.getElementById("ad_fadein104_open"+v1);
	
	if (obj != null && obj2 != null){
		if (parseInt(obj.style.left,10) >= 0 && parseInt(obj2.style.left,10) >=0 )
			return false;
	}else{
		if (obj != null){
			if (parseInt(obj.style.left,10) >= 0 )
				return false;
		}
		if (obj2 != null){
			if (parseInt(obj2.style.left,10) >= 0 )
				return false;
		}
	}
	if (obj != null)
		if (parseInt(obj.style.left,10) < 0 )
			obj.style.left = parseInt(obj.style.left,10) + 25 + "px";
			if (obj2 != null)
				if (parseInt(obj2.style.left,10) < 0 )
					obj2.style.left = parseInt(obj2.style.left,10) + 25 + "px" ;
		setTimeout("init_fadein("+v1+")",10);
	setTimeout("switch_fadein("+v1+",'close"+v1+"')",5000);
}


function ad_5(m,t,p,oimage,cimage,bcolor){
	
	var id = check_date(m,t,1);			
	
	if (id!=-1){		
	
		var ad5_id=Math.floor(Math.random()*1000000);
	
		if (typeof(p)=='undefined')
			p=1;
			
		if (typeof(oimage)=='undefined')
			oimage='/upload1/ad/img/fadein_open.gif';
		
		if (typeof(cimage)=='undefined')
			cimage='/upload1/ad/img/fadein_close.gif';
		
		if (typeof(bcolor)=='undefined')
			bcolor='FF9900';
						
		var file=ad_domain_name+'/upload1/ad/'+m+'/'+eval('ad_'+m+'_'+t+'_data_name')[id];
		
	  	var w=eval("ad_"+m+"_"+t+"_width");
		var h=eval("ad_"+m+"_"+t+"_height");
		var isflash=false;
		
	    if (ImageCheck(file)==1){
			isflash=true;
		}
			
				
		var w1=parseInt(w)+2;
		var h1=parseInt(h)+2;
		var w2=parseInt(w)+23;		
		var t1=(p-1)*h1;
		
		document.write('<div id=\"notice_open'+ad5_id+'\" style=\"position:absolute;z-index:99999;left:-200px;top:'+t1+'px;\">');
	
		document.write('<div id=\"content\" style=\"position:absolute;z-index:100000;\">');
		document.write('<table width='+w2+' border=0 cellspacing=0 cellpadding=0>');
		document.write('<tr>');	
		document.write('<td bgcolor='+bcolor+'><img src=/upload1/ad/img/space.gif border=0 width='+w1+' height='+h1+'></td>');
		document.write('<td width=21 valign=top><a href=# onclick=\"switch_fadein('+ad5_id+',\'close'+ad5_id+'\');return false;\"><img src='+cimage+' border=0></a></td>');
		document.write('</tr>');
		document.write('</table>');	
		document.write('</div>');	
		
		link_action=link_url(m,t,id);
			
		switch (get_app()){
			case 2:
				if (isflash){
					document.write('<div id=\"ad\" style=\"position:absolute;z-index:100001;left:-7px;top:1px;width='+w+'px;height='+h+'px\">');
				}else{
					document.write('<div id=\"ad\" style=\"position:absolute;z-index:100001;left:1px;top:1px;width='+w+'px;height='+h+'px\">');
				}	
				break;			
			case 3:
				document.write('<div id=\"ad\" style=\"position:absolute;z-index:100001;left:1px;top:2px;width='+w+'px;height='+h+'px\">');	
				break;							
			default:				
				document.write('<div id=\"ad\" style=\"position:absolute;z-index:100001;left:1px;top:1px;width='+w+'px;height='+h+'px\">');
		}
		
		
		if (isflash){
			if (get_app()!=3&&get_app()!=4)
				document.write('<button style=\"border:none;background:transparent;width='+w+'px;height='+h+'px\" '+link_action+' hidefocus>');
			document.write('<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=\"'+w+'\"  height=\"'+h+'\">');
			document.write('<param name=\"movie\" value=\"'+file+'\">');
			document.write('<param name=\"quality\" value=\"high\">');
			document.write('<param name=\"wmode\" value=\"Opaque\">');
			if (get_app()==3||get_app()==4)
				document.write('<embed src=\"'+file+'\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" wmode=\"Opaque\"  width=\"'+w+'\"  height=\"'+h+'\"></embed></object>');
			else{
				document.write('<embed src=\"'+file+'\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" wmode=\"Opaque\"  width=\"'+w+'\"  height=\"'+h+'\"  style="margin:-1;"></embed></object>');
				document.write('</button>');
			}
		}else{
			
			document.write('<a'+link_action+'><img src=\"'+file+'\" border=\"0\" width=\"'+w+'\"  height=\"'+h+'\" id=\"ad_img\"></a>');			
		}	
		document.write('<img src=\"\" border=0 width=0 height=0 id=\"ad_click_count\">');
		document.write('</div>');
		
		
		document.write('<div id=\"notice_close'+ad5_id+'\" style=\"position:relative;z-index:100000;left:0px;top:0px;visibility:hidden\">');
		document.write('<table border=0 cellspacing=0 cellpadding=0>');
		document.write('<tr>');
		document.write('<td valign=top><a href=# onclick=\"switch_fadein('+ad5_id+',\'open_notice'+ad5_id+'\');return false;\"><img src='+oimage+' border=0></a></td>');
		document.write('</tr>');
		document.write('</table>');
		document.write('</div>');		
		document.write('</div>');
		init_fadein(ad5_id);
		
	}else{
		return false;
	}
	
}
