www.gusucode.com > 仿51.com的php源码 1.1 > js/musicnewupload.js

    function checkAll() {
	var cbs=document.getElementsByName("cb1");
	//alert (cbs[0]);
	if(cbs.length)
	{
		for(var i=0;i<cbs.length;i++) {
			//alert (cbs.item(i));
			cbs.item(i).checked = true;
		}
	}
}
function clearAll() {
	var cbs=document.getElementsByName("cb1");
	if(cbs.length)
	{
		for(var i=0;i<cbs.length;i++) {
			cbs.item(i).checked = false;
		}
	}
}
function addPlayList() {
	var playlist = AppGetCookie('MusicPlayList1');
	//alert (playlist);
	if (playlist) {
		var lists = playlist.split('\\|');
	} else {
		var lists = '';
	}
	//alert (document.getElementsByName("cb"));
	var cbs   = document.getElementsByName("cb1");
	var mname = document.getElementsByName("musicTitle1");
	var playlist_num = lists.length;
	//alert (cbs);
	//alert (mname);
	
	var newmusic = '';
	var hasnew = false;
	//alert (cbs.length);
	if(cbs.length) {
		for(var i=0;i<cbs.length;i++) {
			if (cbs.item(i).checked == true) {
				playlist_num++;
				if (playlist_num > 20) {
					hasnew = true;
					alert('对不起,播放列表中最多可以存放20首歌曲。');
					return false;
				}
			}
		}
		var add_num = 0;
		for(var i=0;i<cbs.length;i++) {
			if (cbs.item(i).checked == true) {
				if (!inLists(cbs.item(i).value, lists)) {
					newmusic = cbs.item(i).value+','+mname.item(i).value;
					if (playlist == null) {
						playlist = newmusic;
						
					} else {
						playlist = playlist + '\\|' + newmusic;
					}
					//alert (playlist);
					add_num++;
					hasnew = true;
				} else {
					hasnew = true;
				}
			}
		}
	} else {
		alert('没有任何音乐!');
		return;
	}
	if (hasnew == true && add_num == 0) {
		alert('对不起,所选的音乐已经添加过!');
	} else if (add_num) {
		//AppSetCookie('MusicPlayList', playlist, 63072000,'/mysky/Music','gs02qbx.user.vnn.cn');
		AppSetCookie('MusicPlayList1', playlist, 63072000,'/Music','www.wu-liao.com');
		alert('添加成功!');
		refreshMusicListOptions();
	} else {
		alert('未选择音乐!');
	}
}
function inLists(d, arr) {
	if (!arr) return false;
		for (var i in arr) {
			var tmp = arr[i].split(',');
			if (tmp[0] == d) return true;
		}
	return false;
}
function loopPlay() {
	var playlist = AppGetCookie('MusicPlayList1');
	if (playlist == null) {
		alert('未选择任何音乐!');
		return;
	} else {
		window.open('MusicNewsPlayer.php','播放器','height=580,width=625,status=yes,toolbar=no');
	}
}
function deleteMusic() {
	if (confirm('确认要删除当前列表中选中的歌曲么?')) {
		var playlist = document.getElementById('playlist');
		var songid = playlist.options[playlist.selectedIndex].value;
		selectedmusic = AppGetCookie('MusicPlayList1');
		var updatedmusiclist = '';
		if (selectedmusic) {
			var musiclist = selectedmusic.split('\\|');
			for(i=0; i < musiclist.length;i++) {
				tmp = musiclist[i].split(',');
				if (parseInt(tmp[0]) == songid) {
					musiclist[i] = null;
					playlist.remove(playlist.selectedIndex);
				} else {
					updatedmusiclist += musiclist[i] + '\\|';
				}
			}
		}
		updatedmusiclist = updatedmusiclist.substring(0,(updatedmusiclist.length - 2));
		AppSetCookie('MusicPlayList1', updatedmusiclist, 63072000,'/Music', 'www.wu-liao.com');
		refreshMusicListOptions();
	}
}
function clearPlayList() {
	if (confirm('确认要清除播放列表吗?')) {
		AppDelCookieMusic('MusicPlayList1');
		refreshMusicListOptions();
	}
}
function refreshMusicListOptions() {
	var playlist = AppGetCookie('MusicPlayList1');
	//alert (playlist);
	var elm_playlist = document.getElementById('playlist');
	var clen = elm_playlist.length;
	if (clen) {
		while(clen--) {
			elm_playlist.removeChild(elm_playlist.options[clen]);
		}
	}
	if (playlist == null) {
		var option_node  =  document.createElement("OPTION");
		option_node.value='';
		option_node.innerText='暂无音乐';
		elm_playlist.appendChild(option_node);
	} else {
		var lists = playlist.split('\\|');
		for( var j in lists) {
			if(lists[j] == null || lists[j] == '') continue;
				else {
					var tmp = lists[j].split(',');
					var option_node  =  document.createElement("OPTION");
					option_node.value=tmp[0];
					option_node.innerText=tmp[1];
					elm_playlist.appendChild(option_node);
				}
		}
		elm_playlist.selected = 0;
	}
}
refreshMusicListOptions();
function GetCookieVal(offset)
	//获得Cookie解码后的值
	{
		var endstr = document.cookie.indexOf (";", offset);
		if (endstr == -1)
			endstr = document.cookie.length;
		return unescape(document.cookie.substring(offset, endstr));
	}
function SetCookie(name, value)
	//设定Cookie值
	{
		var expdate = new Date();
		var argv = SetCookie.arguments;
		var argc = SetCookie.arguments.length;
		var expires = (argc > 2) ? argv[2] : null;
		var path = (argc > 3) ? argv[3] : null;
		var domain = (argc > 4) ? argv[4] : null;
		var secure = (argc > 5) ? argv[5] : false;
		if(expires!=null) expdate.setTime(expdate.getTime() + ( expires * 1000 ))
			document.cookie = name + "=" + escape (value) +((expires == null) ? "" : ("; expires="+ expdate.toGMTString()))
		+((path == null) ? "" : ("; path=" + path)) +((domain == null) ? "" : ("; domain=" + domain))
		+((secure == true) ? "; secure" : "")
		delete value
	}
function DelCookie(name)
	//删除Cookie
	{
		var exp = new Date();
		exp.setTime (exp.getTime() - 1);
		var cval = GetCookie (name);
		SetCookie(name, '', exp,'/Music','www.wu-liao.com')
	}
function GetCookie(name)
	//获得Cookie的原始值
	{
		var arg  = name + "=";
		var alen = arg.length;
		var clen = document.cookie.length;
		var i = 0;
		while (i < clen)
		{
			var j = i + alen;
			if (document.cookie.substring(i, j) == arg)
				return GetCookieVal (j);
			i = document.cookie.indexOf(" ", i) + 1;
			if (i == 0) break;
		}
		return null;
	}
function AppJsMoveMusic(id)
{
	if (photo_class.length == 0){
		alert('无法移动到其他分类中,因为您的音乐中只有一个分类。');
		return ;
	}
	document.form1.id.value = id;
	AppOpenPOP('移动音乐', 'move_div', 400, 200);
}