//分页
function goPage(type,iPage)
{
	if(type == 1){
		var url = '/music/inc/inc_rmd_music.php';
		var showdiv = 'rmd_music';
	}else if(type == 2){
		var url = '/music/inc/inc_friend_music.php';
		var showdiv = 'friend_music';
	}else if(type == 3){
		var url = '/music/inc/inc_ycmusic.php';
		var showdiv = 'div4_1';
	}else if(type == 4){
		var url = '/music/inc/inc_fcmusic.php';
		var showdiv = 'div4_2';
	}else if(type == 5){
		var url = '/music/inc/inc_bzmusic.php';
		var showdiv = 'div4_3';
	}else if(type == 6){
		var url = '/music/inc/inc_lyric.php';
		var showdiv = 'div4_4';
	}else if(type == 7){
		var url = '/music/inc/inc_sharemusic.php';
		var showdiv = 'div4_5';
	}else if(type == 8){
		var url = '/music/inc/inc_djmusic.php';
		var showdiv = 'div4_6';
	}
	$.get(url, {pages:iPage,t:Math.random()},function (data){
		$('#'+showdiv).html(data); 
	});	
}
//全选 和反选
function checkboxall(checkname){
	$("input[name="+checkname+"]").each(function(){
		if($(this).attr("checked") == false){
		 	$(this).attr("checked", true);
		}else{
			$(this).attr("checked", false);
		}
		
	}); 
}
//全选 
function checkall(checkname){
	$("input[name="+checkname+"]").each(function(){$(this).attr("checked", true);}); 
}

//反选 
function delcheckall(checkname){
	$("input[name="+checkname+"]").each(function(){$(this).attr("checked", false);});
}
//使用播放器播放音乐
 function playmusic(container)
 {
	var items=selectValue(container);
	if(items.length>0)
	{
		window.open('http://music.a8.com/ting/?id='+items,'A8playerboxObj');
	}
	else
	{
		alert("请选择您要播放的歌曲！");
	}
 }
 //使用播放器播放音乐
 function playAllMusic(albumid)
 {
	window.open('http://music.a8.com/ting/?aid='+albumid,'A8playerboxObj');
 }
   //返回已选择Checkbox的Value串.....   
 function selectValue(container)
 {
    var box;
    var reValue = "";
    var boxCollection = document.getElementById(container).getElementsByTagName("input");
    for(var i = 0;i < boxCollection.length;i++)
    {
        box = boxCollection[i];
        if(box.type == "checkbox" && box.checked)
        {
            reValue += box.value + ",";
        }
    }
    if(reValue.indexOf(',') > -1)
    {
        reValue = reValue.substring(0,reValue.lastIndexOf(','));
    }
    return reValue;
 }
    //选择歌曲类型  
 function changMusicType(url)
 {
 	var music_typeid = $("#music_typeid").val();
 	var url = url+"?music_type="+music_typeid+"&limit=10&"; 	
  	location.href = url;
 }
     //选择歌曲显示条数  
 function changLimit(url)
 {
 	var limitpage = $("#limitpage").val();	
 	var url = url+"?limit="+limitpage+"&"; 
  	location.href = url;
 }
      //选择歌曲显示条数  
 function changMusicLimit()
 {
 	var limitpage = $("#limitpage").val();
 	var url = "/admin/music/index.php?limit="+limitpage+"&"; 	
  	location.href = url;
 }
      //删除歌曲  
 function delMusic(id,musictype)
 {
 	var send_url = "/admin/music/index.php?doaction=delMusic&id="+id; 	
   if (!id) return;
	   $.post(send_url, function(data){
	       if (data != 'ok') {
	           alert('操作系统错误！');                
	           return;
	       }else{
	       		if(musictype == 2){
 					showpoint('delycmusic',300,200);  
			 	}else if(musictype == 1){
			 		showpoint('delfcmusic',300,200);  
			 	}else{
			 		alert('删除成功！'); 
			 	}  	        
	       }
	
	       $("#music_id_"+id).hide('slow',function(){
	           $(this).remove();         
	       })        
	   });
	   return false; 	
 }
       //参加活动  
 function joincollent(collect_id,music_id)
 {
 	var send_url = "/admin/music/join_collent.php?doaction=joincollent&music_id="+music_id+"&collect_id="+collect_id; 	
   if (!collect_id) return;
   if(confirm('确定要参加吗?')){
	   $.post(send_url, function(data){
	       /*if (data != 'ok') {
	           alert('操作系统错误！');                
	           return;
	       }else{
	       	   alert('参加成功！');       	        
	       } */     
		   alert(data);
	       //关闭弹窗
	       parent.wboxclosed();
	   });
	   return false; 
   }	
 }
   //移除歌曲  
 function rmMusic(url,id)
 {
 	var send_url = url+"&id="+id; 	
   if (!id) return;
   if(confirm('确定要移除吗?')){
	   $.post(send_url, function(data){
	       if (data != 'ok') {
	           alert('操作系统错误！');                
	           return;
	       }else{
	       	   alert('移除成功！');       	        
	       }
	
	       $("#music_id_"+id).hide('slow',function(){
	           $(this).remove();         
	       })        
	   });
	   return false;
   } 	
 }
 //删除下载日志
  function delDownMusic(id)
 {
 	var send_url = "/admin/music/down.php?doaction=deldown&id="+id; 	
   if (!id) return;
  if(confirm('确定要删除吗?')){   
	   $.post(send_url, function(data){
	       if (data != 'ok') {
	           alert('操作系统错误！');                
	           return;
	       }else{
	       	   alert('删除成功！');       	        
	       }
	
	       $("#down_id_"+id).hide('slow',function(){
	           $(this).remove();         
	       })        
	   });
	   return false; 	
   }
 }
 //删除专辑和音乐盒
  function delMusicAlbum(url,id)
 {
 	var send_url = url+id; 	
   if (!id) return;
   if(confirm('确定要删除吗?')){   
	   $.post(send_url, function(data){
	       if (data != 'ok') {
	           alert('操作系统错误！');                
	           return;
	       }else{
	       	   alert('删除成功！');       	        
	       }
	
	       $("#album_id_"+id).hide('slow',function(){
	           $(this).remove();         
	       })        
	   });
	   return false; 	
   }
 } 
var isIe=(document.all)?true:false;
//设置select的可见状态
function setSelectState(state)
{
var objl=document.getElementsByTagName('select');
for(var i=0;i<objl.length;i++)
{
objl[i].style.visibility=state;
}
}
function mousePosition(ev)
{
if(ev.pageX || ev.pageY)
{
return {x:ev.pageX, y:ev.pageY};
}
return {
x:587 + document.body.scrollLeft - document.body.clientLeft,y:223 + document.body.scrollTop - document.body.clientTop
};
}
//弹出方法
function showMessageBox(wTitle,content,pos,wWidth)
{
closeWindow();
var bWidth=parseInt(document.documentElement.scrollWidth);
var bHeight=parseInt(document.documentElement.scrollHeight);
if(isIe){
setSelectState('hidden');}
var back=document.createElement("div");
back.id="back";
var styleStr="top:0px;left:0px;position:absolute;background:#666;width:"+bWidth+"px;height:"+bHeight+"px;";
styleStr+=(isIe)?"filter:alpha(opacity=0);":"opacity:0;";
back.style.cssText=styleStr;
document.body.appendChild(back);
var mesW=document.createElement("div");
mesW.id="mesWindow";
mesW.className="mesWindow";
mesW.innerHTML="<div class='mesWindowTop'><table width='100%' height='100%'><tr><td>"+wTitle+"</td><td style='width:1px;'><input type='button' onclick='closeWindow();' title='关闭窗口' class='close' value='关闭' /></td></tr></table></div><div class='mesWindowContent' id='mesWindowContent'>"+content+"</div><div class='mesWindowBottom'></div>";
styleStr="left:"+(((pos.x-wWidth)>0)?(pos.x-wWidth):pos.x)+"px;top:"+(pos.y)+"px;position:absolute;width:"+wWidth+"px;";
mesW.style.cssText=styleStr;
document.body.appendChild(mesW);
}
//关闭窗口
function closeWindow()
{
if(document.getElementById('back')!=null)
{
document.getElementById('back').parentNode.removeChild(document.getElementById('back'));
}
if(document.getElementById('mesWindow')!=null)
{
document.getElementById('mesWindow').parentNode.removeChild(document.getElementById('mesWindow'));
}
if(isIe){
setSelectState('');}
}
//测试弹出
function MessageBox(ev,click_num,love_num,recommend_num,down_num,comment_num)
{
	var objPos = mousePosition(ev);
	messContent ="<style>.mesWindow .close{height:15px;width:28px;border:none;cursor:pointer;text-decoration:underline;background:#fff}.mesWindow{border:#666 1px solid;background:#fff;} .mesWindowTop{border-bottom:#eee 1px solid;margin-left:4px;padding:3px;font-weight:bold;text-align:left;font-size:12px;} .mesWindowContent{margin:4px;font-size:12px;}</style>";	
	messContent +="<div style='padding:20px 0 20px 0;text-align:center'>点击("+click_num+")次&nbsp;收藏("+love_num+")次&nbsp;推荐("+recommend_num+")次&nbsp;下载("+down_num+")次&nbsp;评论"+comment_num+"条&nbsp;</div>";
	showMessageBox('歌曲情况',messContent,objPos,350);
}
//添加歌曲
function createnewplaylist()
{
    $('#boxname').val(this.parent.document.getElementById("boxname").value);
    $('#boxpre').val(this.parent.document.getElementById("boxpre").value);
    $('#photourl').val(this.parent.document.getElementById("photourl").value);
    $('#boxlabel').val(this.parent.document.getElementById("boxlabel").value);
    $('#boxid').val(this.parent.document.getElementById("boxid").value);  
     $('#type').val(this.parent.document.getElementById("boxtype").value);	
	var elements = document.getElementById("add_music").elements;
	var sellist = "";
   for (var i = 0; i < elements.length; i++) 
   {
        var ele = elements[i];
        if (ele.type == "checkbox" && ele.name=="checkname")
        {
        	if(ele.checked)
            	sellist+=ele.value+",";
        }
   }
   if(sellist.length>0)
   {
   		$('#musicids').val(sellist.substring(0,sellist.length-1));
   }		
	document.getElementById("add_music").submit();
}
//添加歌曲
function album_addmusic()
{
	var elements = document.getElementById("add_music").elements;
	var sellist = "";
   for (var i = 0; i < elements.length; i++) 
   {
        var ele = elements[i];
        if (ele.type == "checkbox" && ele.name=="checkname")
        {
        	if(ele.checked)
            	sellist+=ele.value+",";
        }
   }
   if(sellist.length>0)
   {
   		$('#musicids').val(sellist.substring(0,sellist.length-1));
   }		
	document.getElementById("add_music").submit();
}
//添加音乐到音乐盒
 function addmusictobox(container,obj,width,height,url,title)
 {
   if(!checkLogin()){
    	openframe(obj,240,138,'/common/login.php','登陆');
    	return false;    
   } 
	var items = selectValue(container);
	if(items.length<=0)
	{
		alert("请选择您要添加的歌曲！");
		$("#"+obj).stop();
		return ;
	}
	else
	{
		var url = url+'t='+Math.random()+'&musicids='+items;
		openframe(obj,width,height,url,title);	
		//document.getElementById(obj).click();
	}
 }
  //添加一首音乐到音乐盒
  function addonemusictobox(musicid,obj,width,height,url,title)
 {
   if(!checkLogin()){
    	openframe(obj,240,138,'/common/login.php','登陆');
    	return false;    
   } 
	if(musicid<=0)
	{
		alert("请选择您要添加的歌曲！");
		return false;
	}
	var url = url+'musicids='+musicid;
	openframe(obj,width,height,url,title);	
 }
   //添加一首音乐到音乐盒
  function add_extlinks(obj,width,height,url,title)
 {
   if(!checkLogin()){
    	openframe(obj,240,138,'/common/login.php','登陆');
    	return false;    
   } 
	openframe(obj,width,height,url,title);	
 }
 //推荐多首歌曲
  function sharemusic(container,obj,width,height,url,title)
 {
	var items = selectValue(container);
	if(items.length<=0)
	{
		alert("请选择您要分享的歌曲！");

		return false;
	}
	if(items.indexOf(",") != -1)
	{
		alert("每次只能分享一首歌曲！");
		return false;
	}
	var url = url+'musicids='+items;
	openframe(obj,width,height,url,title);	
 }
  //推荐一首歌曲
  function shareonemusic(musicid,obj,width,height,url,title)
 {
	if(musicid<=0)
	{
		alert("请选择您要分享的歌曲！");
		return false;
	}
	var url = url+'musicids='+musicid;
	openframe(obj,width,height,url,title);	
 }
 //提交分享
function sharelib(userid){
	var musicid = $('#musicid').val();
	var sharecontent = $('#sharecontentid').val();
	if(userid!=null) {
		var cmdusername = $('#cmdusernameid').val();
	}
	var send_url = '/music/sharemusic.php'; 	
	if (!musicid){
		alert('请选择歌曲！');
		return false;
	}
	if (!sharecontent){
		alert('分享语不能为空！');
		return false;
	}	
	$.post(send_url,{musicid:musicid,share_desc:sharecontent,cmdusername:cmdusername,action:'sharemusic'}, function(data){
		if (data == '1') {
			alert('你已经分享过此歌曲，不能重复分享了！');   
			parent.wboxclosed();              
		}else if(data != 'ok'){
			alert('操作系统错误！');                
			return;			
		}
		else{
			$("#cmdmusicid").hide();
			$("#cmdsuccid").show();	       	        
		}
		 	       
	});
}
 //添加歌曲到专辑
function add_album(){
	var albumid = $('#albumid').val();
	var musicids = $('#musicids').val();
	var send_url = '/admin/music/musictobox.php'; 	
	if (!musicids){
		alert('请选择歌曲！');
		return false;
	}
	if (!albumid){
		alert('请选择专辑！');
		return false;
	}
	$.post(send_url,{albumid:albumid,musicids:musicids,action:'addmusic'}, function(data){
		if (data == '1') {
			alert('请选择歌曲！');                
		}else if(data == 'ok'){
			alert('添加成功！');       	        
		}else{
			alert('操作系统错误！');                
		}
		parent.wboxclosed();    	       
	});
}

function addcom(){
	var content = $('#content').val();
	var send_url = '/article/addcom.php?action=addcom'; 
	$.post(send_url,{content:content}, function(date){
		$('#boxcontent').load('/article/article_com.php'); 	       
	});
}

 //转移歌曲到专辑
function move_album(){
	var albumid = $('#albumid').val();
	var musicids = $('#musicids').val();
	var oldboxid = $('#oldboxid').val();
	var type = $('#type').val();
	var send_url = '/admin/music/movemusic.php'; 	
	if (!musicids){
		alert('请选择歌曲！');
		return false;
	}
	if (!albumid){
		alert('请选择专辑！');
		return false;
	}
	$.post(send_url,{albumid:albumid,musicids:musicids,oldboxid:oldboxid,type:type,action:'movemusic'}, function(data){
		if (data != 'ok') {
			alert('操作系统错误！');                
			return;
		}else{
			alert('添加成功！');       	        
		}
		parent.location.reload();  	       
	});
}
//按钮样式开始
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//按钮样式结束

function copyToClipBoard(){
    var clipBoardContent="";
    clipBoardContent =this.location.href;
    window.clipboardData.setData("Text",clipBoardContent);
    alert("复制成功，请粘贴到你的QQ/MSN上推荐给你的好友");
}
//分享
function sharecmdmusic(musicid){
	if(!musicid){
		alert('非法操作');
		return false;
	}
	
	var send_url = '/music/view.php';
	var sharecontent = $('#sharecontentid').val();	
	if(sharecontent == '分享歌曲，赚取乐豆。限45字…'){
		alert("评论不能为空");
		return false;
	}
	if(!sharecontent){
		alert("评论不能为空");
		return false;
	}
	var commenttxtlength = document.getElementById('sharecontentid').value.length;	
	if(commenttxtlength>45) {
		alert("评论不能多于45字");
		return false;
	}						
	$.post(send_url,{musicid:musicid,sharecontent:sharecontent,action:'sharecontent'}, function(data){
		if (data != 'ok') {
			alert('操作系统错误！');                
			return;
		}else{
			if(userid!=0){
				showpoint('comment',430,300);
			}else{
				alert('分享成功！');
			}      	        
		}
		$('#sharebtnid').attr({"disabled":"disabled"});
		$('#sharecontentid').val('');  	       
	});	
}
//评分
function markscore(score,comments_cnt,totalusercnt,musicid){
	var user_comments = '';
	if(!musicid){
		alert('非法操作');
		return false;
	}	
	if(!totalusercnt) var totalusercnt = 0; 
	if(!comments_cnt) var comments_cnt = 0; 
	var comments_cnt = parseInt(comments_cnt)+1;
	var addtotalusercnt = parseInt(totalusercnt)+1;
	var send_url = '/music/view.php';	
	var height = 100-(comments_cnt/(parseInt(totalusercnt)+1))*100;
	$.post(send_url,{musicid:musicid,score:score,action:'markscose'}, function(data){
		if (data != 'ok') {
			alert('操作系统错误！');                
			return;
		}else{
			if(userid!=0){showpoint('point',400,300);}      	        
		}
		$('#usercountid').html(addtotalusercnt);
		document.getElementById("marktitle"+score).title=comments_cnt+'人选此项';
		document.getElementById("mark"+score).style.cssText='height:'+height+'%';
		for(i=1; i<=5; i++){
			document.getElementById("markscore"+i).disabled=true; 								
		}  	       
	});		
} 
function showpoint(div,height,top){
	document.getElementById(div).style.display="block";
	$("#"+div).css("top",height);
	showpic(div,top);
}
function showpic(div,top){
	$("#"+div).css("opacity", ".1");
	$("#"+div).animate
	({top: top+"px", opacity: "1"}, 500, function(){
		$("#"+div).fadeOut(1500);
	});	
}
//打赏
function musicTips(){
	var regu = /^[0-9]*[1-9][0-9]*$/;
	var bean = $('#beanid').val();
	var musicid = $('#musicid').val();
	if(!musicid){
		alert('非法操作');
		return false;
	}	
	if(!regu.test(bean)){
		alert('请输入正整数');
		return false;
	}	
	var send_url = '/music/musictips.php';	
	$.post(send_url,{musicid:musicid,bean:bean,action:'musictips'}, function(data){
		if (data == '1') {
			alert('请先登录！');                
		}else if(data == '3'){
			alert('豆数不能为空！'); 
			return false;
		}else if(data == '4'){
			alert('您的豆数不足！'); 
			return false;
		}else if(data == 'ok'){
			alert('打赏成功！');  
		}else{
			alert('非法错误！');      	        
		}
		parent.wboxclosed();   	       
	});		
} 
//推荐到首页
function cmdMusicIndex(){
	var desc = $('#cmdtextid').val();
	var musicid = $('#musicid').val();
	var musicname = $('#musicname').val();
	if(!musicid){
		alert('非法操作');
		return false;
	}
	if(!desc){
		alert('请填写推荐理由');
		return false;
	}		
	var send_url = '/music/inc/uc_ca8.php';	
	$.post(send_url,{musicid:musicid,desc:desc,musicname:musicname,action:'cmdindex'}, function(data){
		if (data == '1') {
			alert('请填写推荐理由！');   
			return false;             
		}else{
			$("#cmdmusicid").hide();
			$("#cmdsuccid").show();		
		}   
	});		
} 
function gomusicPage(type,albumid,iPage)
{
	if(type == 1){
		var url = '/musicalbum/inc/inc_albummusic.php';
	}else if(type == 2){
		var url = '/musicbox/inc/inc_boxmusic.php';
	}
	$.get(url, {pages:iPage,albumid:albumid,t:Math.random()},function (data){
		$('#albummusic').html(data); 
	});	
}
