﻿
var pos=0
var forward = true
function goScan(name,color,altcolor, offset){
		var t=document.getElementById(name).getElementsByTagName("TD");
		var len = t.length;
		
		for(i=offset-1;i<len;i++)
		{
			if(i==pos)
			{
				for(var j=0; j< offset; j++)
				{
					t[i-j].style.background = color;
				}		
				if(pos >offset-1)
					t[i-offset].style.background=altcolor
			}
			
			else
			{
				t[i].style.background=altcolor
				
			}
		
		}
		if(forward)
		{
			pos++;
			if(pos>=len-1)
				forward = false;       
		}    
		else
		{
			pos--;
			if(pos<offset)
				forward = true;
		}
			
		}
function createScanner(name,color,altcolor,length,offset,width,height,delay){
		var i=0;
		var outerWidth = parseInt(width)*parseInt(length) +200
		var rowheight = height* 3
		document.write('<table id="outer" border=1 cellpadding =1 cellspace=0 width ='+outerWidth+'px><tr height='+ rowheight +'><td align=center style="border-style:none; font-family:verdana">')
		document.write('問卷開啟中') 
		document.write('</td></tr><tr><td align=center style="border-style:none" >')
		document.write('<TABLE ID='+name+' CELLPADDING=0 CELLSPACING=5 BORDER=0>')
		document.write('<TR HEIGHT='+height+'>')
		for(i=0;i<length;i++) document.write('<TD  WIDTH="'+width+'" style="background:#CCCCCC"></TD>')
		document.write('</TR></TABLE>');
		document.write('</td></tr><tr><td align=center style="border-style:none">問卷開啟可能會花數秒鐘...')
		document.write('</td></tr></table>')
		setInterval("goScan('"+name+"','"+color+"','"+altcolor+"','"+offset+"')", delay)
}
