﻿//打开模式窗口
function OpenModaldialog(path) {
    var strreturnval = window.showModalDialog(path, 'window', 'dialogWidth=700px;dialogHeight=600px');
    if ((strreturnval == undefined) || (strreturnval == "")) {
        alert("你没有选择任何值！");
        return false;
    }
    else {
        //alert(strreturnval);
        //window.document.getElementById("allvalue").value = strreturnval;
        window.document.all("songlist").value = strreturnval;
        alert(strreturnval);
        return true;
    }
}
//打开歌曲选择模式窗口
function OpenSongSeekM() {
    var strreturnval = window.showModalDialog('SongSeekModel.aspx', 'window', 'dialogWidth=700px;dialogHeight=600px');
    if ((strreturnval == undefined) || (strreturnval == "")) {
        alert("你没有歌曲！");
        return false;
    }
    else {
        //alert(strreturnval);
        //window.document.getElementById("allvalue").value = strreturnval;
        window.document.all("songlist").value = strreturnval;
        return true;
    }
}
function ChangeHref(path, DOMid) {
    $('#frmContent').src = path;
}
//全选
function select_allByName(ckbName) {
    str = document.getElementsByName(ckbName);
    for (var i = 0; i < str.length; i++) {
        str[i].checked = !str[i].checked;
    }
}

function select_allByRoot(obj) {
    for (var i = 0; i < obj.elements.length; i++)
        if (obj.elements[i].type == "checkbox") {
        obj.elements[i].checked = true;
    }
}
//根据复选框的名称,返回选中的复选框的值的组合
function returncheck(ckbName) {
    var vs = [];
    var obj = document.getElementsByName(ckbName);
    for (var i = 0; i < obj.length; i++) {
        if (obj[i].checked) {
            vs.push(obj[i].value);
        }
    }
    return vs;
}

//根据复选框的名称,返回选中的复选框的值的组合,并且该值在当前播放列表中不存在
function returncheckNew(ckbName) {
    var vs = [];
    var curPlaySongList = getCookie("myPlaySongList");
    var obj = document.getElementsByName(ckbName);
    var ckbValue;
    for (var i = 0; i < obj.length; i++) {
        if (obj[i].checked) {
            ckbValue = obj[i].value;
            if (curPlaySongList.indexOf(ckbValue, 0) == -1) {
                vs.push(obj[i].value);
            }
        }
    }
    return vs;
}

//千千单曲播放
function PlaySongOne(songid) {
    var listcur = getCookie("myPlaySongList");
    if (listcur.length > 0) {
        if (listcur.indexOf(songid, 0) != -1) {
            listcur = listcur.replace(songid, "");
            listcur = listcur.replace("--", "-");
            listcur = songid + "-" + listcur;
            if (listcur.lastIndexOf("-", 0) == listcur.length) {
                listcur = listcur.substr(0, listcur.length - 1);
            }
        }
    }
    else {
        listcur = songid;
    }
    //Playform.target="_blank";
    //Playform.action="/player/Simple.aspx";
    setTingCookie("myPlaySongList", listcur, 1);
    //Playform.submit();
    $('#Playform').get().submit();
}
function PlayMultiTest(ckbName) {
    var newList = returncheckNew(ckbName);
    var listcur = getCookie("myPlaySongList");
    if (newList.length > 0) {
        if (listcur.length > 0) {
            listcur = newList + "-" + listcur;
        }
        else {
            listcur = newList;
        }
    }
    if (listcur.length < 1) {
        alert("抱歉！\n请至少选择一首歌曲！");
    }
    else {
        setTingCookie("myPlaySongList", listcur, 1);
        window.open('player/Simple.aspx', '_1ting')
    }

}
function FormatSongList(sl) {
    sl = sl.replace("--", "-");
    if (sl.indexOf("-") == 0) {
        sl = sl.substr(1);
    }
    var slSubLength = sl.length - 1;
    if (sl.lastIndexOf("-") == slSubLength) {
        sl = sl.substr(0, slSubLength);
    }
    return sl;
}

//千千播放歌曲-复选播放
function PlaySongMulti(ckbName) {
    var newList = returncheckNew(ckbName);
    var listcur = "";
    listcur = getCookie("myPlaySongList");
    if (newList.length > 0) {
        if (listcur.length > 0) {
            listcur = newList.join('-') + "-" + listcur;
        }
        else {
            listcur = newList.join('-');
        }
    }
    if (listcur.length < 1) {
        alert("抱歉！\n请至少选择一首歌曲！");
    }
    else {
        if (newList.length > 0) {
            setTingCookie("myPlaySongList", orderPSL(listcur), 1);
        }
        //        Playform.target="_blank";
        //        Playform.action="../player/Simple.aspx";
        //window.open('../player/Simple.aspx','_T8c8Player')
        //Playform.submit();火狐有问题
        var jobj = $("#Playform");
        $("#Playform").submit();
    }
}
//千千播放歌曲-复选播放
function PlaySongMulti2(ckbName,url) {
    var newList = returncheckNew(ckbName);
    var listcur = "";
    listcur = getCookie("myPlaySongList");
    if (newList.length > 0) {
        if (listcur.length > 0) {
            listcur = newList.join('-') + "-" + listcur;
        }
        else {
            listcur = newList.join('-');
        }
    }
    if (listcur.length < 1) {
        alert("抱歉！\n请至少选择一首歌曲！");
    }
    else {
        if (newList.length > 0) {
            setTingCookie("myPlaySongList", orderPSL(listcur), 1);
        }
        //        Playform.target="_blank";
        //        Playform.action="../player/Simple.aspx";
        window.open(url, '_T8c8Player')
    }
}
function orderPSL(listcur) {
    listcur = FormatSongList(listcur);
    var newList = listcur.split("-");
    var vector;
    var vector2;
    for (var i = 0; i < newList.length; i++) {
        for (var i2 = 0; i2 < newList.length; i2++) {
            vector = parseInt(newList[i]);
            vector2 = parseInt(newList[i2]);
            if (vector2 > vector) {
                newList[i] = vector2;
                newList[i2] = vector;
            }
        }
    }
    return newList.join("-");
}
//添加复选歌曲进播放列表
function addPlayList(ckbName) {
    var newList = returncheckNew(ckbName);
    if (newList.length > 0) {
        setTingCookie("myPlaySongListNewAdd", newList.join('-'), 1);
    }
}

//取消
function unslect(chk) {
    str = document.getElementsByName(chk);
    for (var i = 0; i < str.length; i++) {
        str[i].checked = false;
    }
}
//反选
function oppslect(chk) {
    str = document.getElementsByName(chk);
    for (var i = 0; i < str.length; i++) {
        if (str[i].checked) {
            str[i].checked = false;
        }
        else {
            str[i].checked = true;
        }
    }
}
function Add_Allvalue() {

    var SelValue = "";

    for (var i = 0; i < form1.elements.length; i++) {
        var e = form1.elements[i];
        if (e.type == 'checkbox')
            if (SelValue == "") {
            SelValue = e.value; //值的拼凑 .. 具体处理看你的需要, 				
        }
        else {
            SelValue = SelValue + "," + e.value; //值的拼凑 .. 具体处理看你的需要, 				
        }
    }

    if (SelValue != "") {
        window.open("/music/palysongs.aspx?id=" + SelValue, "", "width=600,height=540,top=50,left=100,scrollbars=0,resizable=0,status=1')");
    }
    else {
        alert("你还没有选择歌曲！");
    }
}


function Add_value(obj_name) {

    var SelValue = "";
    var aa = document.getElementsByName(obj_name);
    if (aa.length > 0) {
        for (var i = 0; i < aa.length; i++) {
            if (aa[i].checked)//判断复选框是否选中
            {

                if (SelValue == "") {
                    SelValue = aa[i].value; //值的拼凑 .. 具体处理看你的需要, 				
                }
                else {
                    SelValue = SelValue + "," + aa[i].value; //值的拼凑 .. 具体处理看你的需要, 				
                }
            }
        }
    }
    if (SelValue != "") {
        window.open("/music/haoting.aspx?id=" + SelValue, "", "width=600,height=540,top=50,left=100,scrollbars=0,resizable=0,status=1')");
    }
    else {
        alert("你还没有选择歌曲！");
    }
}

function Add_value1(obj_name) {

    var SelValue = "";
    var aa = document.getElementsByName(obj_name);
    if (aa.length > 0) {
        for (var i = 0; i < aa.length; i++) {
            if (aa[i].checked)//判断复选框是否选中
            {

                if (SelValue == "") {
                    SelValue = aa[i].value; //值的拼凑 .. 具体处理看你的需要, 				
                }
                else {
                    SelValue = SelValue + "," + aa[i].value; //值的拼凑 .. 具体处理看你的需要, 				
                }
            }
        }
    }
    if (SelValue != "") {
        window.open("http://www.t8c8.com/music/haoting.aspx?id=" + SelValue, "", "width=600,height=540,top=50,left=100,scrollbars=0,resizable=0,status=1')");
    }
    else {
        alert("你还没有选择歌曲！");
    }
}

function Add_value3(obj_name) {

    var SelValue = "";
    var aa = document.getElementsByName(obj_name);
    if (aa.length > 0) {
        for (var i = 0; i < aa.length; i++) {
            if (aa[i].checked)//判断复选框是否选中
            {

                if (SelValue == "") {
                    SelValue = aa[i].value; //值的拼凑 .. 具体处理看你的需要, 				
                }
                else {
                    SelValue = SelValue + "," + aa[i].value; //值的拼凑 .. 具体处理看你的需要, 				
                }
            }
        }
    }
    if (SelValue != "") {
        window.open("music/mp3zhuda.aspx?id=" + SelValue, "", "width=600,height=540,top=50,left=100,scrollbars=0,resizable=0,status=1')");
    }
    else {
        alert("你还没有选择歌曲！");
    }
}

function Add_value4(obj_name) {

    var SelValue = "";
    var aa = document.getElementsByName(obj_name);
    if (aa.length > 0) {
        for (var i = 0; i < aa.length; i++) {
            if (aa[i].checked)//判断复选框是否选中
            {

                if (SelValue == "") {
                    SelValue = aa[i].value; //值的拼凑 .. 具体处理看你的需要, 				
                }
                else {
                    SelValue = SelValue + "," + aa[i].value; //值的拼凑 .. 具体处理看你的需要, 				
                }
            }
        }
    }
    if (SelValue != "") {
        window.open("http://www.t8c8.com/music/mp3zhuda.aspx?id=" + SelValue, "", "width=600,height=540,top=50,left=100,scrollbars=0,resizable=0,status=1')");
    }
    else {
        alert("你还没有选择歌曲！");
    }
}

function Add_value10(obj_name) {

    var SelValue = "";
    var aa = document.getElementsByName(obj_name);
    if (aa.length > 0) {
        for (var i = 0; i < aa.length; i++) {
            if (aa[i].checked)//判断复选框是否选中
            {

                if (SelValue == "") {
                    SelValue = aa[i].value; //值的拼凑 .. 具体处理看你的需要, 				
                }
                else {
                    SelValue = SelValue + "," + aa[i].value; //值的拼凑 .. 具体处理看你的需要, 				
                }
            }
        }
    }
    if (SelValue != "") {
        window.open("http://www.t8c8.com/music/palysongs.aspx?id=" + SelValue, "", "width=600,height=540,top=50,left=100,scrollbars=0,resizable=0,status=1')");
    }
    else {
        alert("你还没有选择歌曲！");
    }
}

function setTab(name, cursel, n, sy1, sy2) {
    for (i = 1; i <= n; i++) {
        var menu = document.getElementById(name + i);
        var con = document.getElementById("con_" + name + "_" + i);
        menu.className = i == cursel ? sy1 : sy2;
        con.style.display = i == cursel ? "block" : "none";
    }
}


function killErrors() {
    return true;
}


function openWindow() {

    var type = document.getElementById("selectValue").value;

    var key = document.getElementById("tbKey").value.replace("'", "''");

    if (key == "") {

        alert("请输入要搜索的内容");
        return;
    }

    //	var openUrl = "http://www.t8c8.com/music/select.aspx?type="+type+"&key="+ key;
    var openUrl = "http://www.baidu.com/s?tn=hahaboy_pg&wd=site:www.t8c8.com " + key;
    window.open(openUrl);
}

function openWindow3() {
    var type = document.getElementById("selectValue").value;
    var key = document.getElementById("tbKey").value;
    if (key == "") {
        alert("请输入要搜索的内容");
        return;
    }
    var page = "musiclist.aspx";
    if (type == "mv") {
        var openMV = "http://www.t8c8.com/movie/selectmtv.aspx?key=" + key;
        window.open(openMV);
        return;
    }
    if (type == "flash") {
        var openMV = "http://www.t8c8.com/movie/selectflash.aspx?key=" + key;
        window.open(openMV);
        return;
    }
    if (type == "songName")
        page = "select.aspx";
    if (type == "singer")
        page = "select.aspx";
    var openUrl = "http://www.t8c8.com/music/" + page + "?type=" + type + "&key=" + key;
    window.open(openUrl);
}

function UserAjax() {
    var array = document.getElementsByName("expires");
    if (array.length == 0) {
        alert("Error");
        return;
    }
    for (var i = 0; i < array.length; i++) {
        if (array[i].checked) {
            var times = array[i].value;
        }

    }
    if (check_l(document.getElementById("topusername"))) {
        if (check_l(document.getElementById("toppassword"))) {
            top0803.myLogin(document.getElementById("topusername").value, document.getElementById("toppassword").value, times, UserAjax_callback);
        }
    }
}
function UserAjax_callback(res) {
    var p = res.value;
    if (navigator.appName.indexOf("Explorer") > -1) {
        //document.getElementById("top_helpd").innerHTML=p ;
        if (res.value == "false") {
            document.getElementById("ntform").innerHTML = "<div align='center'>登陆失败，用户名不存在</div>";
            document.getElementById("top_helpd").innerHTML = "<h1 class='sy'>你好,欢迎来到好歌网！ <span class='dl'>[<A onclick=openNewDiv('divFlyBar');return false; href='#'>登陆</A>] [<a href='http://bbs.t8c8.com/register.aspx' target='_blank'>免费注册</a>]</span>&nbsp; <span class='ht12'><a href='http://www.t8c8.com/music/ser.htm' target='_blank'>客服</a> <a href='http://www.t8c8.com/aboutus/tg.aspx' target='_blank'>帮助</a></span></h1>";
        }

        else if (res.value == "false2") {
            document.getElementById("ntform").innerHTML = "<div align='center'>登陆失败，密码错误</div>";
            document.getElementById("top_helpd").innerHTML = "<h1 class='sy'>你好,欢迎来到好歌网！ <span class='dl'>[<A onclick=openNewDiv('divFlyBar');return false; href='#'>登陆</A>] [<a href='http://bbs.t8c8.com/register.aspx' target='_blank'>免费注册</a>]</span>&nbsp; <span class='ht12'><a href='http://www.t8c8.com/music/ser.htm' target='_blank'>客服</a> <a href='http://www.t8c8.com/aboutus/tg.aspx' target='_blank'>帮助</a></span></h1>";
        }

        else {
            document.getElementById("ntform").innerHTML = "<div align='center'>登陆成功,欢迎您回来</div>";
            document.getElementById("top_helpd").innerHTML = p;
            Islogin();
        }
    }

    else {
        //document.getElementById("ntform").style.display="none";
        if (res.value == "false") {
            document.getElementById("ntform").innerHTML = "<div align='center'>登陆失败，用户名不存在</div>";
            document.getElementById("top_helpd").textContent = "<h1 class='sy'>你好,欢迎来到好歌网！ <span class='dl'>[<A onclick=openNewDiv('divFlyBar');return false; href='#'>登陆</A>] [<a href='http://bbs.t8c8.com/register.aspx' target='_blank'>免费注册</a>]</span>&nbsp; <span class='ht12'><a href='http://www.t8c8.com/music/ser.htm' target='_blank'>客服</a> <a href='http://www.t8c8.com/aboutus/tg.aspx' target='_blank'>帮助</a></span></h1>";
        }

        else if (res.value == "false2") {
            document.getElementById("ntform").innerHTML = "<div align='center'>登陆失败，密码错误</div>";
            document.getElementById("top_helpd").innerHTML = "<h1 class='sy'>你好,欢迎来到好歌网！ <span class='dl'>[<A onclick=openNewDiv('divFlyBar');return false; href='#'>登陆</A>] [<a href='http://bbs.t8c8.com/register.aspx' target='_blank'>免费注册</a>]</span>&nbsp; <span class='ht12'><a href='http://www.t8c8.com/music/ser.htm' target='_blank'>客服</a> <a href='http://www.t8c8.com/aboutus/tg.aspx' target='_blank'>帮助</a></span></h1>";
        }

        else {
            document.getElementById("ntform").innerHTML = "<div align='center'>登陆成功,欢迎您回来</div>";
            document.getElementById("top_helpd").textContent = p;
            Islogin();
        }
    }
    //document.body.removeChild(ntform);
    //document.body.removeChild(docEle(m));
    return false;

}

function clearuser() {
    top0803.myClear("t", clear_callback);
    /* if(document.getElementById("username").value!=null)
    {
    document.getElementById("username").value="好歌网网友";
    }*/
}

function clear_callback(res) {
    var p = res.value;
    //alert(p);
    if (navigator.appName.indexOf("Explorer") > -1) {
        document.getElementById("top_helpd").innerHTML = p;
    }
    else {
        document.getElementById("top_helpd").textContent = p;
    }
    return false;
}

function check_l(which) {
    if (which.value.length == 0) {
        alert("用户名或密码不能为空");
        return false;
    }
    return true;
}

var docEle = function() {
    return document.getElementById(arguments[0]) || false;
}

function openNewDiv(_id) {
    var m = "mask";
    if (docEle(_id)) document.removeChild(docEle(_id));
    if (docEle(m)) document.removeChild(docEle(m));
    // 新激活图层
    var newDiv = document.createElement("div");
    newDiv.id = _id;

    //newDiv.onMouseDown="catchFlyBar()";
    //newDiv.onMouseUp="releaseFlyBar()";
    //newDiv.style.visibility="visible";

    //newDiv.style.cursor="move";
    newDiv.style.position = "absolute";
    newDiv.style.zIndex = "9999";
    newDiv.style.width = "400px";
    newDiv.style.height = "200px";
    newDiv.style.top = "180px";
    newDiv.style.left = (parseInt(document.body.scrollWidth) - 300) / 2 + "px"; // 屏幕居中
    newDiv.style.background = "#EFEFEF";
    newDiv.style.border = "1px solid #860001";
    newDiv.style.padding = "5px";
    newDiv.innerHTML = "<div class=ntforumbox id=ntform><div class=titlebar><h3>用户登录</h3></div><div class=forumform><table cellpadding=0 cellspacing=0 border=0><tbody><tr class=list><th class=formlabel>用户名:</th><td class=formbody><input name=topusernam type=text id=topusername size=20 class=colorblue onfocus=this.className='colorfocus';onblur=this.className='colorblue'; value=''  />&nbsp; <a href=http://bbs.t8c8.com/register.aspx tabindex=-1 accesskey=r title=立即注册(ALT + R)>立即注册</a></td></tr></tbody><tbody><tr class=list><th class=formlabel>密码:</th><td class=formbody><input name=password type=password id=toppassword size=20 class=colorblue onfocus=this.className='colorfocus'; onblur=this.className='colorblue'; /> &nbsp;<a href=http://bbs.t8c8.com/getpassword.aspx tabindex=-1 accesskey=g title=忘记密码 (ALT + G)>忘记密码</a></td></tr></tbody><tbody><tr class=list><th class=formlabel>有效时间:</th><td class=formbody><input name='expires' type=radio value='43200' />一个月  <input type=radio name='expires' value='1440' />一天<input type=radio name='expires' value='60' checked />一小时</td></tr></tbody><tbody></tbody><tbody><tr class=list><td colspan=2 class=formarea><input name=login type=submit id=login value=登录 onclick='UserAjax();return false;' class=sbutton /></td></tr></tbody></table></div></div>";
    document.body.appendChild(newDiv);
    // mask图层
    var newMask = document.createElement("div");
    newMask.id = m;
    newMask.style.position = "absolute";
    newMask.style.zIndex = "1";
    newMask.style.width = document.body.scrollWidth + "px";
    newMask.style.height = document.body.scrollHeight + "px";
    newMask.style.top = "0px";
    newMask.style.left = "0px";
    newMask.style.background = "#000";
    newMask.style.filter = "alpha(opacity=0)";
    newMask.style.opacity = "0.40";
    document.body.appendChild(newMask);

    // 关闭mask和新图层
    var newA = document.createElement("a");
    newA.href = "#";
    newA.innerHTML = "<br><div align='center' style='color:red;'>[关闭]</div>";
    newA.onclick = function() {
        document.body.removeChild(docEle(_id));
        document.body.removeChild(docEle(m));
        return false;
    }
    newDiv.appendChild(newA);
}

String.prototype.trim = function() {
    var reExtraSpace = /^\s*(.*?)\s+$/;
    return this.replace(reExtraSpace, "$1");
}

function Islogin() {
    top0803.IsLogin(Islogin_callback);
}

function Islogin_callback(res) {
    var p = res.value;
    /*
    if(document.getElementById("username").value!=null)
    {
    document.getElementById("username").value=p.trim();
    }
    */
}



function addF() {
    if (navigator.appName == "Microsoft Internet Explorer")
        window.external.addFavorite(location.href, "好歌网");
    else
        alert("浏览器不支持该项功能");
}
function killYouErrors() {
    return true;
}

//1ting 设置Cookie值
function setTingCookie(name, value, hours) {
    var expire = "";
    if (hours != null) {
        expire = new Date((new Date()).getTime() + hours * 3600000);
        expire = "; expires=" + expire.toGMTString();
    }
    document.cookie = name + "=" + escape(value) + ";path=/" + expire;
}
//1ting 取得Cookie值
function getCookie(name) {
    var cookieValue = "";
    var search = name + "=";
    if (document.cookie.length > 0) {
        offset = document.cookie.indexOf(search);
        if (offset != -1) {
            offset += search.length;
            end = document.cookie.indexOf(";", offset);
            if (end == -1) end = document.cookie.length;
            cookieValue = unescape(document.cookie.substring(offset, end));
        }
    }
    return cookieValue;
}

function menuShow(root, divelement, count, index) {
    for (var i = 1; i <= count; i++) {
        var id1 = document.getElementById(divelement + i.toString());
        //var id2=document.getElementById(root + i.toString());
        if (i == index) {
            id1.style.display = "block";
            //id2.style = "background:url(/T8c8.Web/images/hover.gif); display:block;";
        }
        else {
            id1.style.display = "none";
            //id2.style = "";
        }
    }
}
//返回字符串长度,英文一个字符,中文两个字符
function sLength(s) {
    if (s.length == 0) return 0;
    var bytelen = 0;
    var re = /[^\x00-\xff]/g;
    re.compile();
    for (var i = 0; i < s.length; i++) {
        if (re.test(s.charAt(i))) {
            bytelen = bytelen + 2;
        } else {
            bytelen += 1;
        }
    }
    return bytelen;
}
//截取指定长度的字符串,英文一个字符,中文两个字符
function StringSub(s, len) {
    if (s.length < len) {
        return s;
    }
    var strSub;
    var length = 0;
    var strVector;
    var index = 0;
    var re = /[^\x00-\xff]/g;
    re.compile();
    while (len != length) {
        strVector = s.charAt(index);
        if (re.test(strVector)) {
            strSub += strVector;
            length += 2;
            index++;
        }
        else {
            strSub += strVector;
            length++;
            index++;
        }
    }
    return strSub;
}


