// JavaScript Document
var cookiestr;
var TotalSongs;
var varvar,person,collect,song,url,personID,SongID;
function Insertsong(songstr){
	 var tstr;
	 tstr = songstr.split("|");
	 if(tstr.length == 6){
		 if (cookiestr == null)
			 cookiestr = songstr;
		 else
			 cookiestr = cookiestr + "###" + songstr;
			 InitList();
	 }
}

//function killerror() {return true;}
//window.onerror = killerror;

function InitList(){
	 var songarray,htmlstr,i,j,tstr,ttstr,selectedindex,cc;
	 htmlstr = "<div id=\"musci_List_box\">";
	 songarray = cookiestr.split("###");
	 TotalSongs = 0;
	 for(i = 0;i < songarray.length;i++){
		tstr = songarray[i].split("|");
		if(i<9)
		{cc="0";}
		else
		{cc="";}
		if(tstr.length == 6){
			 TotalSongs += 1;
			 if(TotalSongs<10){cc="0";}
			 if (tstr[3].length>5)
			 {
				 presonLen=tstr[3].substr(0,5);
			 }else{
				 presonLen=tstr[3];
			 }
			 if (tstr[2].length>12)
			 {
				 songLen=tstr[2].substr(0,12);
			 }else{
				 songLen=tstr[2];
			 }
			 if(TotalSongs<10){cc="0";}
			 ttstr = cc + TotalSongs + "." + presonLen + "**" + songLen;
			 if(ttstr.length < 40){
				 ttstr = ttstr.replace("**"," - ");
			 }else{
				 ttstr = ttstr.replace("**"," - ");
				 ttstr = ttstr.substr(0,40) + "...";
			 }
			 htmlstr += "<div style=\"cursor:pointer\" id=\"" + i + "\" title=\"\" onmouseover=\"addClass(this)\" onmouseout=\"detachClass(this)\" ondblclick=\"xplay("+i+",this)\"><span>"+ttstr+"</span><img src=\"../Images/bf_list_close.gif\" alt=\"\" onclick=\"remove(this)\" /><img src=\"../Images/bf_list_down.gif\" alt=\"\" onclick=\"down(this)\" /><img src=\"../Images/bf_list_up.gif\" alt=\"\" onclick=\"up(this)\" /></div>";
		}
	 }
	 htmlstr += "</div>";
	 playlist.innerHTML = htmlstr;
}

function play(id,type,code)
{
	obj = document.getElementById("Player");
	obj.URL = "asx.php?id="+id+"&type="+type+"&code="+code;
/*
    if(obj!=0) setBG(obj);
	 if(str=="") alert('hjhj');
	 else{
		
		varvar = str.split("|");
		url = varvar[1];song = varvar[2];collect = varvar[4];person = varvar[3];SongID = varvar[0];personID = varvar[5];
		if(person.length > 8) person = person.substr(0,8) + "...";
		if(collect.length > 8) collect = collect.substr(0,8) + "...";
		if(song.length > 12) song = song.substr(0,12) + "...";
		//Music_gg.innerHTML = "< iframe scrolling=\"no\" width=\"365\" height=\"250\" src=\"http://ivrsend.moyu.com/p300x270_ivr.htm?uid=90241&mn="+song+"&a=&b=&c=&d=&e=&f=\" frameborder=\"no\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\" align=\"center\"></iframe>";
    	Music_gg.innerHTML = '<iframe name="" src="http://u.x-push.net/dg/360x180/index.asp?vip=90024&uid=&bid=166&song='+song+'" frameborder="0" scrolling="0" width="360" height="180" align="center"></iframe>';
		//Music_gg.innerHTML = '<iframe vspace="0" name="town" src="http://img2.uiuni.com/functioncode/fcode9/fcode9.html?uid=60&sid=&songName='+song+'" width="354" height="180" border="0" frameborder="0" scrolling="no"></iframe>';
		//MusicGeCi.innerHTML = "< iframe width=\"335\" height=\"162\" frameborder=\"0\" scrolling=\"auto\" src=\"http://www1.mtvtop.net/lrc/" + getLrc(SongID) + "/" + SongID + ".htm?" + SongID + "\"></iframe>"
        MusicGeCi.innerHTML = "< iframe width=\"335\" height=\"162\" frameborder=\"0\" scrolling=\"auto\" src=\"getLrc.asp?id=" + SongID + "\"></iframe>";
        gtitle.innerHTML = person+" - "+song;
        gename.innerHTML = song;
        gsname.innerHTML = person;
        geshoue1.innerHTML = person;
        geshoue2.innerHTML = person;
        geshoue3.innerHTML = person;
        geshoue4.innerHTML = person;
        geshoue5.innerHTML = person;
		document.title = person + "" + song + " - й";
        singerImg.src = "http://www.mtvtop.net/geshou_jpg/" + personID + ".jpg";
		Player.FileName ="http://219.151.1.51/010407/" + url + ".wma";
		Player.play();
		setTimeout("showTLab()",20000);
	 }
*/
	return false;
}

function Next_OneOK(){
    var nexto = o.nextSibling
    if (nexto == null)
    {
        nexto = o.parentNode.firstChild;
    }
    var i = nexto.id;
    xplay(i, nexto);
}

function showTLab(){
	 setTimeout("",2000);
	 if(document.Player.playState == 0) Next_OneOK();
	 setTimeout("showTLab()",5000);
}


var aa = null;
function setBG(obj)
{
    if (aa != null)
    {
        aa.className="";
    }
    obj.className="bg";
    aa=obj;
}

function getLrc(id)
{
    return parseInt(id/1000);
}
var o = null;
var ii = null;
function xplay(i,obj)
{
    
    songarray = cookiestr.split("###");
    if (i == null)
    {
        i = 0;
        obj = document.getElementById(i);
    }
    ii = i;
    o = obj;
    play(songarray[i],obj);
}
function down(obj)
        {
            event.cancelBubble=true;
            var li = obj.parentNode;
            var nextLi = li.nextSibling;
            if (nextLi == null)
            {
                alert("Ѿ");
            }
            else
            {
                nextLi.parentNode.insertBefore(nextLi,li);
            }
			detachClass(li);
        }
function up(obj)
{
	event.cancelBubble=true;
	var li = obj.parentNode;
	var prevLi = li.previousSibling;
	if (prevLi == null)
	{
		alert("Ѿ");
	}
	else
	{
		prevLi.parentNode.insertBefore(li,prevLi);
	}
	detachClass(li);
}
function remove(obj)
{
	event.cancelBubble=true;
	if (ii != obj.parentNode.id)
	{
		var li = obj.parentNode;
		li.parentNode.removeChild(li);
	}
	else
	{
		alert("ɾڲŵĸ");
	}
}

function addClass(obj)
{
	obj.className = obj.className + " bgx";
}
function detachClass(obj)
{
	obj.className = obj.className.replace(/ bgx/gi, "");
}
