dim cookiestr
cookiestr=getmenustr(trim(document.cookie))

function getmenustr(coo)
	dim tt
	' 三个*号为播放列表数据的存储区域
	getmenustr=""
	tt=split(coo,"***")
	if ubound(tt)>0 then
		if instr(tt(1),"#")>0 and instr(tt(1),"|")>0 then
			getmenustr=tt(1)
		end if
	end if
end function

function Insertsong(songstr)
cookiestr=""
dim tstr
ttstr=split(songstr,",")
for i=lbound(ttstr) to ubound(ttstr)
tstr=split(trim(ttstr(i)),"|")
if tstr(0)<>"" then
if instr(cookiestr,tstr(0) & "|" & tstr(1))>0 then
	'msgbox "你己经选择了这首歌曲!",,"错误"
else
	cookiestr=cookiestr+"#"+ttstr(i)
	Modified=true
end if	
end if 	
next	
call InitList
end function

'	'	'	'	'	'	'

dim serverurl
dim RealInstalled	'安装了Realplayer?
dim PlayState	'播放状态
dim AutoLoop	'自动循环
dim TotalSongs	'歌曲总数
dim Modified	'清单改变
dim Progress_Draging	'拖动中?
dim Clip_Length		'播放长度
dim Play_Mode	'播放模式'0:顺序;1:随机
dim Progress_Interval	'播放进度刷新的Interval ID
dim Progress_bar_len	'进度指示条总长
dim Volume	'音量(取值范围：1->10,ActiveX控件音量取值范围：Max=99,Min=0,实际音量=Volume*10-1)
'dim ActualWidth		'窗口实际宽度
'dim ActualHeight	'窗口实际高度
const MaxVolume=10
dim IsListDbclick

'	'	'	'	'	'	'
'保存列表
sub Savelist()
	document.cookie= "***"& cookiestr & "***;Expires=Wednesday, 27-April-08 00:00:00 GMT;"
	Modified=false
end sub



'是否变更播放列表
function checklist()

	if Modified then
	
			call Savelist
	
	end if
end function

'初始化页面(列表和变量)
sub Init
	if RealInstalled<>true then exit sub
	call Initvars
	
	call Initlist
	call Resetctl
	call InitVolume
	call play
end sub

'初始化变量
sub Initvars	
serverurl="http://61.172.246.14/rmq191888/"
        Play_Mode=0
	Volume=int(MaxVolume)
	dim len1,len2
	len1=progress_bar.style.width
	len1=left(len1,instr(len1,"px")-1)
	len2=progress_block.width
	Progress_bar_len=cint(len1)-cint(len2)
end sub

'初始化列表
sub InitList()
	dim selectedindex
	dim songarray
	dim html
	dim i,j
	dim tarr
	dim OptionStrLen
	dim tstr
	if totalsongs>0 then selectedindex=songitem.selectedindex
	html="<select size=5 id='songitem' name='songitem' style='width:0;background:#000000;color:#ffffff;' ondblclick='vbscript:if songitem.selectedindex>=0 then call play'>"
	songarray=split(cookiestr,"#")
	TotalSongs=0
	for i=1 to ubound(songarray)
		tarr=split(songarray(i),"|")
		if ubound(tarr)=4 then
			TotalSongs=TotalSongs+1
			html=html & "<option value='" & songarray(i) & "'>" & vbcrlf
			tstr= TotalSongs & "." & trim(tarr(1)) & "**" & trim(tarr(2))
			
			OptionStrlen=len(tstr)
				if OptionStrlen<20 then
					tstr=replace(tstr,"**"," - ")
				else
					tstr=replace(tstr,"**"," - ")
					tstr=getleft(tstr,20) & "..."
				end if
			html=html & tstr & "</option>" & vbcrlf
		end if
	next
	html=html &"</select>" & vbcrlf
	playlist.innerHTML=html
	if TotalSongs=1 then
		songitem.selectedindex=0 
	else if selectedindex<totalsongs then
		songitem.selectedindex=TotalSongs-TotalSongs
	else
		songitem.selectedindex=selectedindex-1
	end if
	end if
end sub

'删除歌曲
sub song_delete_onclick
	dim i
	i=songitem.selectedindex
	if i<0 then
		msgbox "请选择你要删除的歌曲!",,"请选择"
		exit sub
	end if
	dim cursong
	cursong=songitem.options(songitem.selectedindex).value
	cookiestr=replace(cookiestr,cursong,"")
	call InitList
	'if i>ubound(songitem.options) then i=ubound(songitem.options)
	'songitem.options(i).selected=true
	Modified=true
end sub

'全部删除
sub song_deleteall_onclick
	dim resp
	resp=msgbox("真的要删除吗?",1,"确认")
	if (resp=1) then
		cookiestr=""
		Modified=true
		call InitList
	end if
end sub
	
'保存按钮的处理脚本
sub song_save_onclick
	Call Savelist
	msgbox "你的播放清单己经成功保存",,"保存成功"
end sub

'播放歌曲
sub play()
	if songitem.selectedindex<0 then
		msgbox "请选择你要播放的曲目,至少1首以上才可以连续播放",,"请选择"
		exit sub
	end if
	if PlayState<>0 and PlayState<>4 then real.dostop:IsListDbclick=true
	dim var
	dim person,collect,song,url

	var=split(songitem.options(songitem.selectedindex).value,"|")
	url=var(0)
	song=var(1)
	collect=var(2)
	person=var(3)
	musicid=var(4)
	if lenb(person)>14 then
		info_person.innerHTML=leftb(person,12)&"..."
	else
		info_person.innerHTML=person
	end if
	if lenb(collect)>20 then
		info_collect.innerHTML=leftb(collect,12)&"..."
	else
		info_collect.innerHTML=collect
	end if
	if lenb(song)>14 then
		info_song.innerHTML=leftb(song,12)&"..."
	else
		info_song.innerHTML=song
	end if
	www98777com.location="../geci/q1/" & musicid & ".rm.htm"
	real.setsource(serverurl& trim(url))
	real.doPlay
end sub
'''                     /*  1连接3播放0停止4暂停2缓冲  */

'ActiveX控件的事件处理脚本
sub real_OnPlayStateChange(newstate)
	dim src
	dim converttext
	PlayState=newstate
	select case PlayState
	case 0
	converttext="己停止"
	case 1
	converttext="正在连接"
	case 2
	converttext="缓冲数据"
	case 3
	converttext="播放中"
	case 4
	converttext="己暂停"
	case else
	converttext="Unknown"
	end select
	'if Playstate=1 or Playstate=2 then window.focus
	info_play_state.innerHTML=converttext
	if real.canplay then
		ctl_play.src=replace(ctl_play.src,"-2.gif","-1.gif")
	else
		ctl_play.src=replace(ctl_play.src,"-1.gif","-2.gif")
'		ctl_play.disabled=true
	end if
	if real.canstop then
		ctl_stop.src=replace(ctl_stop.src,"-2.gif","-1.gif")
	else
		ctl_stop.src=replace(ctl_stop.src,"-1.gif","-2.gif")
	end if
	if real.canplaypause then
		ctl_pause.src=replace(ctl_pause.src,"-2.gif","-1.gif")
	else
		ctl_pause.src=replace(ctl_pause.src,"-1.gif","-2.gif")
	end if

end sub

'同上
sub real_OnClipOpened(clipname,clipurl)
'	Clip_Playing=true
	Clip_Length=real.GetLength
	Progress_Interval=setInterval ("call Progress_Change",1000)	'开始移动指示条
end sub

'同上
sub real_onClipClosed
    dim i
	Rndnum=songitem.selectedindex
	clearInterval Progress_Interval	'停止移动指示条
	if IsListDbclick<>true then
	   if Play_Mode=0 then
	     i=songitem.selectedindex
	     if i<TotalSongs-1 then
		    songitem.options(i+1).selected=true
	     else
		    songitem.options(0).selected=true
	     end if
	   else
		 randomize
		 while Rndnum=songitem.selectedindex
			 Rndnum=int(rnd()*TotalSongs)
		 wend
		 songitem.options(Rndnum).selected=true
		 
	   end if 	 
	
	 if TotalSongs>1 then call play
	end if 
	IsListDbclick=false 
end sub

sub Resetctl
	Progress_block.style.left="0px"
	info_postion.innerHTML="00:00"
	info_speed.innerHTML="0kbps"
	info_Play_state.innerHTML="准备播放"
end sub

'播放时每一定时间移动指示条
sub Progress_Change
	dim Current_Length,offset
	Current_Length=real.GetPosition
	offset=int((Current_Length/Clip_length)*Progress_bar_len)	'偏移量=己播放的百分比*进度指示条总长
	'偏移量=己播放的百分比*进度指示条总长'偏移量=己播放的百分比*进度指示条总长'偏移量=己播放的百分比*进度指示条总长'msgbox "当前偏移量"&offset
	Progress_block.style.left=offset&"px"
	info_postion.innerHTML=FormatClipTime(Current_Length)
	info_speed.innerHTML=int(real.GetBandWidthAverage/10)/100 &"k"
end sub

function FormatClipTime(timestr)
	dim min,sec
	timestr=int(timestr/1000)
	min=int(timestr/60)
	if len(cstr(min))<2 then FormatClipTime=FormatClipTime & "0"
	FormatClipTime=FormatClipTime & min & ":"
	sec=timestr mod 60
	if len(cstr(sec))<2 then FormatClipTime=FormatClipTime & "0"
	FormatClipTime=FormatClipTime & sec
end function

sub ctl_last_onclick
	if songitem.selectedindex>0 and songitem.selectedindex<TotalSongs then
		songitem.options(songitem.selectedindex-1).selected=true
		call play
	end if
end sub

sub ctl_play_onclick
	call play
end sub

sub ctl_stop_onclick
    IsListDbclick=true
	real.dostop
end sub

sub ctl_pause_onclick
	real.dopause
end sub

sub ctl_next_onclick
        
	if songitem.selectedindex>=0 and songitem.selectedindex<TotalSongs-1 then
		songitem.options(songitem.selectedindex+1).selected=true
		call play
	end if
end sub

sub ctl_mute_onclick
	Real.SetMute Not Real.GetMute
	dim src
	src=ctl_mute.src
	if instr(src,"1.gif")>0 then
		src=replace(src,"1.gif","2.gif")
	else
		src=replace(src,"2.gif","1.gif")
	end if
	ctl_mute.src=src
end sub
'------------------音量控制

'增加音量按钮的处理脚本
sub Volume_Raise_onclick
	if Volume<MaxVolume then
		Volume=Volume+1
		call InitVolume
	end if
end sub

'减小音量按钮的处理脚本
sub Volume_Down_onclick
	if Volume>1 then
		Volume=Volume-1
		call InitVolume
	end if
end sub

sub InitVolume
	'RealPlayer音量控制的说明:读取音量与设置音量之间的时间间隔若小于约75-78毫秒,读出的将是上一次的音量值
	dim i
	dim html
	html="<table border=0 cellspacing=0 cellpadding=0>" & vbcrlf
	for i=1 to MaxVolume-Volume
		html=html & "<tr><td><img src='player-images/volumn-dark.gif' width='4' height='4'></td></tr>" & vbcrlf
	next
	for i=1 to Volume
		html=html & "<tr><td><img src='player-images/volumn-bright.gif' width='4' height='4'></td></tr>" & vbcrlf
	next
	html=html & "<tr><td height=4></td></tr>" & vbcrlf
	html=html & "</table>" & vbcrlf
	Volume_Show.innerHTML=html
	real.SetVolume int(Volume*int(100/MaxVolume)-1)
	
end sub


'改变播放模式按钮的ALT属性
sub getmode
	if Play_Mode=0 then
		ctl_loop.alt="播放模式:顺序" 
	else
		ctl_loop.alt="播放模式:随机" 
	end if
end sub

'改变播放模式
sub ChangeMode
	Play_Mode=abs(Play_Mode-1)
	'-----
	dim src
	src=ctl_loop.src
	if instr(src,"1.gif")>0 then
		src=replace(src,"1.gif","2.gif")
	else
		src=replace(src,"2.gif","1.gif")
	end if
	ctl_loop.src=src
end sub

sub AddLocal_onclick
	dim S
	S=showmodaldialog ("gangall.asp",,"dialogWidth:800;dialogHeight:600;center:1")
	if len(S)>6 then Insertsong S
end sub

'
function getleft(str,length)
	dim ret
	dim i,j
	dim s
	i=1:j=1
	while j<length
		s=mid(str,i,1)
		ret=ret & s
		if isnumeric(s)  then
			j=j+0.5
		else
			j=j+1
		end if
		i=i+1	
	wend
	getleft=ret
end function
