﻿//选择所有音乐
function CheckAllMusic(form) {
  var temp = document.getElementById(form);
  for (var i = 0; i < temp.elements.length; i++) {
    var e = temp.elements[i];
    e.checked = true;
  }
}

//反选所有音乐
function CheckOhterMusic(form) {
  var temp = document.getElementById(form);
  for (var i = 0; i < temp.elements.length; i++) {
    var e = temp.elements[i];
    if (e.checked == false) {
      e.checked = true;
    }
    else {
      e.checked = false;
    }
  }
}

//频谱状态切换
function ChangePlayerEffectStatus() {
  if (document.getElementById("playerEffectStatus").value == "显示频谱") {
    document.getElementById("MusicPlayer").style.height = "150";
    document.getElementById("playerEffectStatus").value = "关闭频谱"
  }
  else {
    document.getElementById("MusicPlayer").style.height = "64";
    document.getElementById("playerEffectStatus").value = "显示频谱"
  }
}

//得到歌曲总数
var totalMusic;
function GetTotalMusic() {
  var musicList = document.getElementById("MusicList");
  if (!totalMusic) {
    totalMusic = musicList.options.length;
    document.getElementById("Playlist").style.display = "none";
    musicList.style.display = "block";
  } else {
    totalMusic++;
  }
}

//插入歌曲列表，此方法暂时未用到，发布版可以移除此段代码
function InsertMusicList(MusicName, Singer, Special, MusicUrl, LrcUrl) {
  var comboName = totalMusic + "." + MusicName + "**" + Singer + "**" + Special;
  if (comboName.length < 20) {
    comboName = comboName.replace("**", " - ");
  } else {
    comboName = comboName.replace("**", " - ");
    comboName = comboName.substr(0, 20) + "...";
  }
  var appendOption = new Option;
  appendOption.text = comboName;
  appendOption.value = MusicUrl;
  appendOption.lrcUrl = LrcUrl;
  appendOption.musicName = MusicName;
  appendOption.musicSinger = Singer;
  appendOption.special = Special;
  musicList.options[totalMusic - 1] = appendOption;
}

//控制按钮 上一首
function PrevMusic() {
  var musicList = document.getElementById("MusicList");
  if ((musicList.selectedIndex > 0) && (musicList.selectedIndex < totalMusic)) {
    musicList.options[musicList.selectedIndex - 1].selected = true;
    PlayMusic();
  }
}

//控制按钮 下一首
function NextMusic() {
  var musicList = document.getElementById("MusicList");
  if ((musicList.selectedIndex >= 0) && (musicList.selectedIndex < totalMusic - 1)) {
    musicList.options[musicList.selectedIndex + 1].selected = true;
    PlayMusic();
  } else {
    musicList.options[0].selected = true;
    PlayMusic();
  }
}
//}

//随机播放
function RandomMusic() {
  var musicList = document.getElementById("MusicList");
  if (musicList.selectedIndex >= 0) {
    var randomNum = Math.round(Math.random() * totalMusic - 1)
    musicList.options[Math.abs(randomNum)].selected = true;
    PlayMusic();
  }
}


//播放歌曲
function PlayMusic() {
  var musicList = document.getElementById("MusicList");
  if (musicList.selectedIndex < 0) {
    alert('请选择你要播放的曲目!');
  }
  else {
    var lrcUrl = musicList.options[musicList.selectedIndex].lrcUrl;
    document.getElementById("MusicPlayer").Url = musicList.options[musicList.selectedIndex].value;
    document.getElementById("MusicTitle").innerText = musicList.options[musicList.selectedIndex].musicName + "(" + musicList.options[musicList.selectedIndex].singer + ")";
    document.getElementById("Singer").innerText = musicList.options[musicList.selectedIndex].singer;
    document.getElementById("Style").innerText = musicList.options[musicList.selectedIndex].styles;
    document.getElementById("Language").innerText = musicList.options[musicList.selectedIndex].language;
    document.getElementById("IssusingDate").innerText = musicList.options[musicList.selectedIndex].issusingDate;
    document.getElementById("RecordCompany").innerText = musicList.options[musicList.selectedIndex].recordCompany;
    document.getElementById("Intro").innerText = musicList.options[musicList.selectedIndex].intro;
    try { IdDownload.startDownload(lrcUrl, LrcRun); } catch (hh) { }
    CheckPlayState();
  }
}

//检查播放状态
function CheckPlayState() {
  if (document.getElementById("MusicPlayer").PlayState == 1) {
    if (document.getElementById("randomMusic").checked) {
      RandomMusic()
    }
    else {
      NextMusic();
    }
  }
  setTimeout("CheckPlayState()", 3000);
}

//得到Cookie
function GetCookie(name) {
  if (document.cookie.length > 0) {
    cookieStart = document.cookie.indexOf(name + "=")
    if (cookieStart != -1) {
      cookieStart = cookieStart + name.length + 1
      cookieEnd = document.cookie.indexOf(";", cookieStart)
      if (cookieEnd == -1) cookieEnd = document.cookie.length
      return unescape(document.cookie.substring(cookieStart, cookieEnd))
    }
  }
  return ""
}

//写入Cookie

function SetCookie(name, value, expires, path, domain, secure) {
  var today = new Date();
  today.setTime(today.getTime());
  if (expires) {
    expires = expires * 1000 * 60 * 60 * 24;
  }
  var expires_date = new Date(today.getTime() + (expires)); document.cookie = name + '=' + escape(value) + ((expires) ? ';expires=' + expires_date.toGMTString() : '') + ((path) ? ';path=' + path : '') + ((domain) ? ';domain=' + domain : '') + ((secure) ? ';secure' : '');
}

//清除Cookie

function DeleteCookie(name, path, domain) {
  if (getCookie(name)) document.cookie = name + '=' + ((path) ? ';path=' + path : '') + ((domain) ? ';domain=' + domain : '') + ';expires=Thu, 01-Jan-1970 00:00:01 GMT';
}

