/**
 * 显示音乐好评，差评，推荐，评论的方框
 */
var gmPlayer={};
function nextElem (elem) {
	do {
		elem = elem.nextSibling;
	} while (elem && elem.nodeType != 1);
	return elem;
}
function showaction(o) {
	var oldW = o.offsetWidth;
	var oldH = o.offsetHeight;
//	alert(oldH);
	var W = oldW - 58;
	if (oldW > 66 ) {
		newW = oldW - W;
	} else {
		newW = oldW - 5;
	}
	if (oldH <= 16) {
		newH = -18;
	}
	if (oldH <= 36) {
		newH = -8;
	}
	if (oldH > 36) {
		newH = 2;
	}
	var o = nextElem(o);
    o.style.display = "block";
    o.style.left = newW+"px";
    o.style.top = newH+"px";
    o.onmouseover = function() {
    this.style.display = "block";
    }
}
/**
 *  隐藏音乐好评，差评，推荐，评论的方框
 */
function hideaction(o) {
var p = o.parentNode.parentNode;
var o = nextElem(o);
p.onmouseover = function() {
	o.style.display = "block";
}
p.onmouseout = function() {
	o.style.display = "none";
}
}

/**
 *  有多个tab时复选框全选和全部选的功能选项. (特殊)
 *
 */
function check_all()
{
    var boxes   = document.getElementsByTagName("input");
    var chkbox  = document.getElementById("chk");

    if(chkbox.checked==true)
    {
	for(var i=0; i<boxes.length; i++)
	{
	    if (boxes[i].type=='checkbox' )
	    {
		boxes[i].checked=true;
	    }
	}
    }

    else if(chkbox.checked==false)
    {
	for(var i=0; i<boxes.length; i++)
	{
	    if (boxes[i].type=='checkbox')
	    {
		boxes[i].checked=false;
	    }

	}
    }

}

function check_index_music(ctype)
{
	var checktype = ctype;
	jQuery("input[name='"+checktype+"']").each(function() {
		jQuery(this).attr("checked", true);
	});
}
/**
 * 选择了多首歌曲弹出的音乐播放器
 */
function sendMIds(ctype)
{
    var arr = jQuery(":checked[name*='"+ctype+"']");
    var idstr = '';
    var boxeslength = arr.length;

    for(var i=0; i<boxeslength; i++)
    {
		if(i == boxeslength-1)
		{
		    idstr += arr[i].value;
		    break;
		}
		else
		{
			idstr += arr[i].value+",";
		}
    }

    if(idstr == '')
    {
	alert("请选择歌曲");
	return false;
    }
    turnOnPlayer(idstr);
}

/**
 * 试听专辑
 */
function sendDisc(discid)
{

	jQuery.ajax({
		type: "get",
		dataType: "json",
		url: "music.php",
		data: "ac=getmusicbydisc&did="+discid,
		success: function (response) {
			var i = 0;
			var idstr = '';
			var musiclength = response.length
			for(i=0; i<musiclength; i++)
			{
				idstr += response[i]+",";
			}
			idstr = idstr.substring(0, idstr.length-1);
			turnOnPlayer(idstr);
		}
	});
}

/**
 * 试听专辑
 */
function sendDiscs(discid)
{

	jQuery.ajax({
		type: "get",
		dataType: "json",
		url: "http://music.gamefm.com",
		data: "ac=getmusicbydisc&did="+discid,
		success: function (response) {
			var i = 0;
			var idstr = '';
			var musiclength = response.length
			for(i=0; i<musiclength; i++)
			{
				idstr += response[i]+",";
			}
			idstr = idstr.substring(0, idstr.length-1);
			turnOnPlayer(idstr);
		}
	});
}


function ieload(idstr){
    if(!gmPlayer.document.body){
        setTimeout("ieload('"+idstr+"')",100);
    }else{
        gmPlayer.updateList(idstr);
    }
}

function thisMovie(movieName){
	return navigator.appName.indexOf("Microsoft") != -1 ? window[movieName] : document[movieName];
}
function addSongs(idstr){
	if(thisMovie('trans012')){
		thisMovie('trans012').addSongs(idstr);
	}else{
		openMusicPlayer(idstr);
	}
}
function openMusicPlayer(idstr){
	if(jQuery && jQuery("#jquery_jplayer").length) jPlayerStop();
	window.win = window.open( "http://www.gamefm.com/player.php?cp=play&mid="+idstr, "gamefmMusicPlayer", "scrollbars=0,status=0,resizable=1,width=830,height=595");
	if (!window.win || !window.win.top) {
		alert("您的浏览器阻止了新窗口弹出,请修改相关设置");
	}else{
		window.win.focus();
	}
	return false;
}

function turnOnPlayer(idstr){
	addSongs(idstr);
}


/**
 * 点击歌曲名称弹出的音乐播放器
 */

function sendMId(idstr){
    turnOnPlayer(idstr);
}

/*
	*下载模块,不需要验证的.
	*@author                 yanghb2008@gmail.com
	*@date                   2009年7月17日
	*/
function download(url,musicId)
{
    url=url+Math.random();
    jQuery.getJSON(url,function(data){
	if(data.flag==1)
	{

	    var listens    = document.getElementById("hrefdown");
	    listens.href     ="gfmp://[CharSet=2][B]|1|3|"+data.musicName+"|"+data.singerName+"|"+data.discName+"|"+data.bps+"|"+data.md5+"|"+data.length+"|"+data.size+"|"+data.musicUrl+"|"+data.type+"|"+data.musicId+"|[E][S]";
	    //alert(listens.href);
	    listens.click();
	}
	else if(data.flag==2)
	{
	    alert("歌曲不存在!");
	}
    })
}

//推荐功能函数
function display_friend(value)
{
    var len = jQuery("#leftBox > select > option").length;
    for(i=0;i<len-1;i++)
    {
		$("friendList"+i).style.display = 'none';
    }
    $(value).style.display = '';
}
//推荐功能全选函数
function check_all_friend()
{
    var boxes   = document.getElementsByName("friend");
    var chkbox  = document.getElementById("chk_friend");

    if(chkbox.checked==true)
    {
	for(var i=0; i<boxes.length; i++)
	{
	    if (boxes[i].type=='checkbox' )
	    {
			boxes[i].checked=true;
	    }
	}
    }

    else if(chkbox.checked==false)
    {
	for(var i=0; i<boxes.length; i++)
	{
	    if (boxes[i].type=='checkbox')
	    {
		boxes[i].checked=false;
	    }

	}
    }

}

//推荐功能的处理函数
function musicshare(musicId)
{
    var boxes = jQuery(":checkbox");
    idstr = '';
    boxeslength = boxes.length;
    for(var i=0; i<boxeslength; i++)
    {
		if(boxes[i].checked)
		{
			idstr += boxes[i].value+",";
		}
    }
    if(!idstr)
    {
		alert("请至少选择一个好友");
    }
    else
    {
		var url="music.php?ac=collect&id="+musicId+"&tofid="+idstr;
		ajaxget(url,'commender_'+musicId);
    }
}

//批量收藏音乐的处理函数
function collectchecked(showid)
{
	var boxes = jQuery(":checkbox");
    idstr = '';
    boxeslength = boxes.length;
    for(var i=0; i<boxeslength; i++)
    {
		if(boxes[i].checked)
		{
			idstr += boxes[i].value+",";
		}
    }
    if(!idstr)
    {
		alert("请至少选择一首歌曲");
    }
    else
    {
		var aa = document.getElementById(showid);
		aa.href = "music.php?ac=collect&type=all&id="+idstr;
		ajaxmenu(event, showid, 0, 2000);
		aa.href= "#";
    }
}

function check_allfriend()
{
    var boxes   = document.getElementsByName("iconid[]");
    var chkbox  = document.getElementById("chk_friend");

    if(chkbox.checked==true)
    {
		for(var i=0; i<boxes.length; i++)
		{
			if (boxes[i].type=='checkbox' )
			{
				boxes[i].checked=true;
			}
		}
	}

	else if(chkbox.checked==false)
	{
		for(var i=0; i<boxes.length; i++)
		{
			if (boxes[i].type=='checkbox')
			{
			boxes[i].checked=false;
			}

		}
    }

}

function get_status(key)
{
	
if($("music_search_box").value == key)
 {
     $("music_search_box").value = '';
     $("music_search_box").style.color = "black";
 }
}


