//main.js
var UpPath = "/uploadgbk/";
var liveSwitching = true;
function $(){
var Var1=new Array();
for(var i=0;i<arguments.length;i++){
var Var2=arguments[i];
if(typeof Var2=="string"){
Var2=document.getElementById(Var2);
}
if(arguments.length==1){
return Var2;
}
Var1.push(Var2);
}
return Var1;
}
var WinLoad={loadfuncs:new Array(),addFunc:function(ref){
}
};
//Media Link
function playmedia(playIcon, strID,strURL,intWidth,intHeight) {
	playIcon.replace(" ","%20");
	strID.replace(" ","%20");
	var objDiv=document.getElementById(strID);
	document.getElementById(playIcon).style.display='none';
	if (!objDiv) return false;
	if (objDiv.style.display!='none') {
		objDiv.innerHTML='';
		objDiv.style.display='none';
	} else {
		objDiv.innerHTML=makemedia(strURL,intWidth,intHeight);
		objDiv.style.display='block';
	}
}
//Media Build
function makemedia (strURL,intWidth,intHeight) {
	var strHtml;
	strHtml ="<object id='MediaPlayer1' width='"+ intWidth +"' height='"+ intHeight +"' classid='CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95' codebase='http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715' align='baseline' border='0' standby='Loading Microsoft Windows Media Player components...' type='application/x-oleobject'>";
	strHtml+="<param name='invokeURLs' value='0'>";
    	strHtml+="<param name='FileName' value=\""+ strURL +"\">";
    	strHtml+="<param name='ShowControls' value='1'>";
    	strHtml+="<param name='ShowPositionControls' value='0'>";
    	strHtml+="<param name='ShowAudioControls' value='1'>";
    	strHtml+="<param name='ShowTracker' value='1'>";
    	strHtml+="<param name='ShowDisplay' value='0'>";
    	strHtml+="<param name='ShowStatusBar' value='1'>";
    	strHtml+="<param name='AutoSize' value='0'>";
    	strHtml+="<param name='ShowGotoBar' value='0'>";
    	strHtml+="<param name='ShowCaptioning' value='0'>";
    	strHtml+="<param name='AutoStart' value='1'>";
    	strHtml+="<param name='PlayCount' value='20'>";
    	strHtml+="<param name='AnimationAtStart' value='0'>";
    	strHtml+="<param name='TransparentAtStart' value='0'>";
    	strHtml+="<param name='AllowScan' value='0'>";
    	strHtml+="<param name='EnableContextMenu' value='1'>";
    	strHtml+="<param name='ClickToPlay' value='0'>";
    	strHtml+="<param name='DefaultFrame' value='datawindow'>";
	strHtml+="<embed src=\""+ strURL +"\" align='baseline' border='0' width='"+ intWidth +"' height='"+ intHeight +"' type='application/x-mplayer2'";
        strHtml+=" pluginspage='http://www.microsoft.com/isapi/redir.dll?prd=windows&amp;sbp=mediaplayer&amp;ar=media&amp;sba=plugin&amp;'";
        strHtml+="name='MediaPlayer' showcontrols='1' showpositioncontrols='0' showaudiocontrols='1' showtracker='1' showdisplay='0' showstatusbar='1' autosize='0' showgotobar='0' showcaptioning='0' autostart='1' autorewind='0'";
        strHtml+="animationatstart='0' transparentatstart='0' allowscan='1' enablecontextmenu='1' clicktoplay='0' defaultframe='datawindow' invokeurls='0'> </embed></object>";
	return strHtml;
}

//重新改写开始
function GetSongType(md5code)
{
	switch(md5code)
	{
		case "7d99bb4c7bd4602c342e2bb826ee8777":
			return ".wma";
			break;
		case "de4d2606f2f993fe603268aa6e6d54bc":
			return ".wma";
			break;
		case "25e4f07f5123910814d9b8f3958385ba":
			return ".Wma";
			break;
		case "51bbd020689d1ce1c845a484995c0cce":
			return ".WMA";
			break;
		case "652c2d9917079ddf03745220894f5f44":
			return ".mp3";
			break;
		case "b3a7a4e64bcd8aabe4cabe0e55b57af5":
			return ".mp3";
			break;
		case "d82029f73bcaf052be8930f6f4247184":
			return ".MP3";
			break;
		case "5fd91d90d9618feca4740ac1f2e7948f":
			return ".Mp3";
			break;
		default:
			return "";//8box
	}	
}
//Media Link
function playmedia1(playIcon, strID,strURL,intWidth,intHeight,type, Head) {
	playIcon.replace(" ","%20");
	strID.replace(" ","%20");
	var objDiv=document.getElementById(strID);
	document.getElementById(playIcon).style.display='none';
	if (!objDiv) return false;
	if (objDiv.style.display!='none') {
		objDiv.innerHTML='';
		objDiv.style.display='none';
	} else {
		objDiv.innerHTML=makemedia1(strURL,intWidth,intHeight, type, Head);
		objDiv.style.display='block';
	}
}
//Media Build

var chkArray=document.getElementsByName("chkSongID");
//全选反选,s 1全选,s 0反选
function selAll(s){
	if(chkArray.length){
		var sel=true;
		switch(s){
			case 1:
				for(i=0;i<chkArray.length;i++){
					if(!chkArray[i].checked){
						sel=false;
						break;
					}
				}
				for(i=0;i<chkArray.length;i++){
				   chkArray[i].checked=sel?false:true; 
				}
				break;
			case 0:
				for(i=0;i<chkArray.length;i++){
				   chkArray[i].checked=chkArray[i].checked?false:true; 
				}
				break;	
		}
	}
}

//判断是否有记录被选中
function sel(){
	var sel=false;
	if(chkArray.length){
		for(i=0;i<chkArray.length;i++){
			if(chkArray[i].checked){
				sel=true;
				break;
			}
		}
	}
	return sel;
}
function doMusicList(down){
	if(sel())
	{
		var id="";
		for(i=0;i<chkArray.length;i++)
		{
			if(chkArray[i].checked)
			{
				id+=chkArray[i].value+",";
        		}
		}
		id=id.substring(0,id.length-1);
		if(down=="1")
		window.open("/mm/user_songurl.php?song_id="+id+"","wodemp3","menubar=no,location=no,resizable=no,scrollbars=no,status=no,width=50,height=50");
		else
		window.open("/mm/play.php?song_id="+id+"","wodemp3","menubar=no,location=no,resizable=no,scrollbars=no,status=no,width=50,height=50");
	}
	else
	{
		alert("请选择歌曲");
	}
}

//批量删除推荐歌曲
function delSongBat(pageref){		
	if(sel())
	{
		var id="";
		for(i=0;i<chkArray.length;i++)
		{
			if(chkArray[i].checked)
			{
				id+=chkArray[i].value+",";
        		}
		}
		id=id.substring(0,id.length-1);
	
		if(confirm("确定要从推荐列表中删除该歌曲吗?"))
		{
			window.location="info_oper.php?tag=delsong_bat&songid="+id+"&pageref="+pageref;
		}
	}
	else
	{
		alert("请选择歌曲");
	}
}


function addBoxList(){
	if(sel())
	{
		var id="";
		for(i=0;i<chkArray.length;i++)
		{
			if(chkArray[i].checked)
			{
				id+=chkArray[i].value+",";
        		}
		}
		id=id.substring(0,id.length-1);
	
		window.open("/mm/info_oper.php?tag=addboxlist&song_id="+id+"","wodemp3","menubar=no,location=no,resizable=no,scrollbars=no,status=no,width=280,height=150,top=200,left=210");
	}
	else
	{
		alert("请选择歌曲");
	}
}





function checkall(formname, selnum)   //选中或不选当前页面的所有选项
{
	if ( document.all("selall").checked ==1  )
	{
	    for ( var i = 0; i < selnum; i++ )
	    	formname.sel[i].checked = 1;
	}
	if ( document.all("selall").checked ==0  )
	{
	    for ( var i = 0; i < selnum; i++ )
	    	formname.sel[i].checked = 0;
	}
}

function delsong(songid, pageref)
{
	if(confirm("确定要从推荐列表中删除该歌曲吗?"))
	{
		window.location="/mm/info_oper.php?tag=delsong&songid="+songid+"&pageref="+escape(pageref);
	}
}
function delfavsong(songid, pageref)
{
	if(confirm("确定要从收藏列表中删除该歌曲吗?"))
	{
		window.location="/mm/info_oper.php?tag=delfavsong&songid="+songid+"&pageref="+escape(pageref);
	}
}
function delfavalbum(aid, pageref)
{
	if(confirm("确定要从收藏列表中删除该专辑吗?"))
	{
		window.location="/mm/info_oper.php?tag=delfavalbum&aid="+aid+"&pageref="+escape(pageref);
	}
}
function delfavsinger(sid, pageref)
{
	if(confirm("确定要从收藏列表中删除该歌手吗?"))
	{
		window.location="/mm/info_oper.php?tag=delfavsinger&sid="+sid+"&pageref="+escape(pageref);
	}
}
function delgrpfav(favid, grpid)
{
	if(confirm("确定要从小组收藏列表中删除该歌曲吗?"))
	{
		window.location="/mm/info_oper.php?tag=grp_delfav&favid="+favid+"&grpid="+grpid;
	}
}
function delfrd(frdid)
{
	if(confirm("确定要从好友列表中删除吗?"))
	{
		window.location="/mm/info_oper.php?tag=delfrd&frdid="+frdid;
	}
}
function delfavuser(favid)
{
	if(confirm("确定要从推荐列表中删除吗?"))
	{
		window.location="/mm/info_oper.php?tag=delfavuser&favid="+favid;
	}
}

function deltag(tagid)
{
	if(confirm("确定要删除该标签吗?"))
	{
		window.location="/mm/info_oper.php?tag=deltag&tagid="+tagid;
	}
}
function delupfile(fileid, pageref)
{
	if(confirm("确定要删除该文件吗?该操作不可恢复!"))
	{
		window.location="/mm/info_oper.php?tag=delupfile&fileid="+fileid+"&pageref="+escape(pageref);
	}
}


function delsonggrade(gradeid)
{
	if(confirm("确定要删除该条评分记录吗?该操作不可恢复!"))
	{
		window.location="/mm/info_oper.php?tag=delsonggrade&gradeid="+gradeid;
	}
}

function delalbumcmt(cmtid)
{
	if(confirm("确定要删除该条评价吗?该操作不可恢复!"))
	{
		window.location="/mm/info_oper.php?tag=del_albumcmt&cmtid="+cmtid;
	}
}
function imgcheck()
{
	var imgNum = document.images.length;
	
	for(i=0;i<imgNum;i++)
	{
		if(window.document.images[i].width > 670)
			window.document.images[i].width = 670;
	}
}


//ajax开始
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
try {
  xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
  try {
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (e2) {
    xmlHttp = false;
  }
}
@end @*/
var xmlHttp = false;
if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
  xmlHttp = new XMLHttpRequest();
}
function createQueryString()
{
	 var lyric=document.getElementById("lyric").value;
	 var songid=document.getElementById("songid").value;
	 var queryString="tag=lyric&lyric=" + lyric + "&songid="+songid;
	 return queryString;
}
function ListenLog(songid, userid) {
	  var url = "/mm/info_oper.php?tag=listen_song&songid="+songid+"&uid="+userid;
	  xmlHttp.open("GET", url, true);
	  xmlHttp.send(null);

}
function UpdateSong() {
	  var url = "/mm/info_oper_sina.php";
	  xmlHttp.open("GET", url, true);
	  xmlHttp.send(null);
}
function nextsong(songid, next_or_pre) {
	if(getcookie('playnext')||next_or_pre!==''){
		self.location="/mm/song_norand.php?tag=nextsong&songid="+songid+"&next_type="+next_or_pre;
	}
}
function hissong() {
	window.open('/mm/song_norand.php?tag=hissong');
}
function AddTitleer(songid) {
	  var url = "/mm/info_oper.php?tag=addtitleer&songid="+songid;
	  xmlHttp.open("GET", url, true);
	  xmlHttp.send(null);
}
function DelTitleer(songid) {
	  var url = "/mm/info_oper.php?tag=deltitleer&songid="+songid;
	  xmlHttp.open("GET", url, true);
	  xmlHttp.send(null);
}
function AddRecSong(songid) {
	  var url = "/mm/info_oper.php?tag=addrecsong&songid="+songid;
	  xmlHttp.open("GET", url, true);
	  xmlHttp.send(null);
}
function AddFavSong(songid) {
	  var url = "/mm/info_oper.php?tag=addfavsong&songid="+songid;
	  xmlHttp.open("GET", url, true);
	  xmlHttp.send(null);
}
function FixSongUrl(songid) {
	  var url = "/mm/info_oper.php?tag=fixsongurl&songid="+songid;
	  xmlHttp.open("GET", url, true);
	  xmlHttp.send(null);
}
function AddVideoShare(sid,uid,sharename) {
	  var url = "/mm/info_oper.php?tag=addrecvideo&videoid="+sid+"&uid="+uid+"&videoname="+sharename;
	  xmlHttp.open("GET", url, true);
	  xmlHttp.send(null);
}
function Song_ID3(songid, media_size, MediaTitle, Artist, Copyright, MediaDescription, Duration, Bitrate, Album, Genre) {
	  var url = "/mm/info_oper.php?tag=song_id3&songid="+songid+"&media_size="+media_size+"&Title="+encodeURI(MediaTitle)+"&Artist="+encodeURI(Artist)+"&Copyright="+encodeURI(Copyright)+"&Description="+encodeURI(MediaDescription)+"&Duration="+encodeURI(Duration)+"&Bitrate="+Bitrate+"&Album="+encodeURI(Album)+"&Genre="+encodeURI(Genre);
	  xmlHttp.open("GET", url, true);
	  xmlHttp.send(null);
}
function clear_id3(songid) {
	  var url = "/mm/info_oper.php?tag=clear_id3&songid="+songid;
	  xmlHttp.open("GET", url, true);
	  xmlHttp.send(null);
}
function delboxsong(songid) {
	  var url = "/mm/info_oper.php?tag=delboxsong&songid="+songid;
	  xmlHttp.open("GET", url, true);
	  xmlHttp.send(null);

}
function editLyric() {
	  var lyric = document.getElementById("lyric").value;
	  if ((lyric == null) || (lyric == "")) return;
	
	  var url = "/mm/info_oper.php";
	
	  xmlHttp.open("POST", url, true);
	
	  xmlHttp.onreadystatechange = updatePage;
	
	  var queryString=createQueryString();
	  xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	  xmlHttp.send(queryString);
}
function updatePage() {
	   document.getElementById('lyric_form').style.display = "none";
	   document.getElementById('info').style.display = "block";
	  if (xmlHttp.readyState == 4)
	  {
		setTimeout("Response()",1000)
	  }
}
function Response()
{
	document.getElementById('old_lyric').style.display = "block";
	document.getElementById('info').style.display = "none";
	var response = xmlHttp.responseText;
	document.getElementById("old_lyric").innerHTML = response;
}
function calledit1()
{
	document.getElementById('lyric_form').style.display = "block";
	document.getElementById('old_lyric').style.display = "none";
}
function calledit2()
{
	document.getElementById('lyric_form').style.display = "block";
	document.getElementById('no_lyric').style.display = "none";
}
function CancelEdit()
{
	document.getElementById('lyric_form').style.display = "none";
	document.getElementById('old_lyric').style.display = "block";
	document.getElementById('no_lyric').style.display = "block";
}

//lyrics.js

function lrcClass(tt)		//LRC歌词处理 类
{
  this.gsh="歌手:~1~\n曲名:~2~\n专辑:~3~\n编者:~4~";
  this.inr = [];		//行
  this.oTime = 0;		//余补时间
  this.hailang;
  this.dts = -1;		//当前行显示的s
  this.dte = -1;		//当前行显示的e
  this.dlt = -1;		//当前行
  this.ddh;		//当前行数据
  this.fjh;
  this.haohaiplay;
  this.oceanx;
  this.cnane;
//以上几个属性是为了判断是否还在上次显示的时间范围，以减少循环次数


  if(/\[offset\:(\-?\d+)\]/i.test(tt))		//取offset余补时间
    this.oTime = RegExp.$1/1000;
  tt = tt.replace(/\[\:\][^$\n]*(\n|$)/g,"$1");		//去掉注解
  tt = tt.replace(/\[[^\[\]\:]*\]/g,"");
  tt = tt.replace(/\[[^\[\]]*[^\[\]\d]+[^\[\]]*\:[^\[\]]*\]/g,"");
  tt = tt.replace(/\[[^\[\]]*\:[^\[\]]*[^\[\]\d\.]+[^\[\]]*\]/g,"");
  tt = tt.replace(/<[^<>]*[^<>\d]+[^<>]*\:[^<>]*>/g,"");
  tt = tt.replace(/<[^<>]*\:[^<>]*[^<>\d\.]+[^<>]*>/g,"");		//去掉除时间标签的其它标签
  tt = tt.replace(/\<br \/\>/g,"");		//去掉<br />
  tt = tt.replace(/&nbsp;/g," ");		//替换nbsp

  while(/\[[^\[\]]+\:[^\[\]]+\]/.test(tt))
  {
    tt = tt.replace(/((\[[^\[\]]+\:[^\[\]]+\])+[^\[\r\n]*)[^\[]*/,"\n");
    var zzzt = RegExp.$1;
    /^(.+\])([^\]]*)$/.exec(zzzt);
    var ltxt = RegExp.$2;
    var eft = RegExp.$1.slice(1,-1).split("][");
    for(var ii=0; ii<eft.length; ii++)
    {
      var sf = eft[ii].split(":");
      var tse = parseInt(sf[0],10) * 60 + parseFloat(sf[1]);
      var sso = { t:[] , w:[] , n:ltxt }
      sso.t[0] = tse-this.oTime;
      this.inr[this.inr.length] = sso;
    }
  }
  this.inr = this.inr.sort( function(a,b){return a.t[0]-b.t[0];} );

  for(var ii=0; ii<this.inr.length; ii++)
  {
    while(/<[^<>]+\:[^<>]+>/.test(this.inr[ii].n))
    {
      this.inr[ii].n = this.inr[ii].n.replace(/<(\d+)\:([\d\.]+)>/,"%=%");
      var tse = parseInt(RegExp.$1,10) * 60 + parseFloat(RegExp.$2);
      this.inr[ii].t[this.inr[ii].t.length] = tse-this.oTime;
    }
    lrcbc.innerHTML = "<font>"+ this.inr[ii].n.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/%=%/g,"</font><font>") +" </font>";
    var fall = lrcbc.getElementsByTagName("font");
    for(var wi=0; wi<fall.length; wi++)
      this.inr[ii].w[this.inr[ii].w.length] = fall[wi].offsetWidth;
    this.inr[ii].n = lrcbc.innerText;
  }


  this.print("");
  lrcwt1.innerText = "";
  lrcwt2.innerText = "";
  lrcwt3.innerText = "";
  lrcwt4.innerText = "";
  lrcwt5.innerText = "";
  lrcwt6.innerText = "";
  lrcwt7.innerText = "";
  //lrcwt8.innerText = "";
  //lrcwt9.innerText = "";

  lrcbc.style.width = 0;
}


lrcClass.prototype.run = function()
{
  try {
    if(this.oceanx==0)
      this.runing(this.haohaiplay.controls.currentPosition, this.haohaiplay.currentMedia.duration);
    else
      this.runing(this.haohaiplay.GetPosition()/1000, this.haohaiplay.GetLength()/1000);
  } catch(hh){}
}

lrcClass.prototype.runing = function(tme, plen)
{
  if(tme<this.dts || tme>=this.dte)
  {
    var ii;
    for(ii=this.inr.length-1; ii>=0 && this.inr[ii].t[0]>tme; ii--){}
    if(ii<0) return;
    this.ddh = this.inr[ii].t;
    this.fjh = this.inr[ii].w;
    this.dts = this.inr[ii].t[0];
    this.dte = (ii<this.inr.length-1)?this.inr[ii+1].t[0]:plen;

    lrcwt1.innerText = this.retxt(ii-3);
    lrcwt2.innerText = this.retxt(ii-2);
    lrcwt3.innerText = this.retxt(ii-1);
    lrcwt4.innerText = this.retxt(ii+1);
    lrcwt5.innerText = this.retxt(ii+2);
	lrcwt6.innerText = this.retxt(ii+3);
	lrcwt7.innerText = this.retxt(ii+4);
	
 //lrcwt8.innerText = this.retxt(ii+5);
 //lrcwt9.innerText = this.retxt(ii+6);
 
    this.print(this.retxt(ii));
    if(this.dlt==ii-1)
    {
      clearTimeout(this.hailang);
      this.golrcoll(0);
    }
    this.dlt = ii;
  }
  var bbw = 0;
  var ki;
  for(ki=0; ki<this.ddh.length && this.ddh[ki]<=tme; ki++)
    bbw += this.fjh[ki];
  var kt = ki-1;
  var sc = ((ki<this.ddh.length)?this.ddh[ki]:this.dte) - this.ddh[kt];
  var tc = tme - this.ddh[kt];
  bbw -= this.fjh[kt] - tc / sc * this.fjh[kt];
  if(bbw>lrcbox.offsetWidth)
    bbw = lrcbox.offsetWidth;
  lrcbc.style.width = Math.round(bbw);
}

lrcClass.prototype.retxt = function(i)
{
  return (i<0 || i>=this.inr.length)?"":this.inr[i].n;
}

lrcClass.prototype.print = function(txt)
{
  lrcbox.innerText = txt;
  lrcbc.innerText = txt;
}

lrcClass.prototype.golrcoll = function(s)
{
  lrcoll.style.top = 25-(s++)*3;
  lrcwt1.filters.alpha.opacity = 90-s*18;
  lrcwt5.filters.alpha.opacity = s*18+10;
  if(s<=5)
    this.hailang = setTimeout(this.cnane+".golrcoll("+s+")",120);
}

////////////////////////////////////////////////////////////////////

var lrcobj = null;
var lrcTxt = null;
var lrcTimer = null;
function geciplay()
{
  if(lrcTxt == null){
	  lrcTxt = document.getElementById("Lrcs").innerHTML.slice(4,-3);
  }
  lrcobj = new lrcClass(lrcTxt);
  lrcobj.cnane = "lrcobj";
  lrcobj.haohaiplay = MediaPlayer1;
  lrcobj.oceanx = 0;
  //0为使用 Media Player 控件，1为使用 Real Player 控件
  if (lrcTimer!=null) window.clearInterval(lrcTimer);
  lrcTimer = setInterval("lrcobj.run();",100);

}
