﻿var p = 0;
$(document).ready(function() {
    $("#pageBottom").html("加载中...");
    //读取Domain
    AC.get(function(e) {
        //alert(e);
        $(".hddWebDomain").val(e);
        $.get("bottom.htm?_t=" + Math.random(), function(data, status) {
            $("#pageBottom").html(data.replace(/bbssite/g, $(".hddWebDomain").val()));
        });
    }, "GetDomain");


    //initFloatTips();
    loginUserType = parseInt($(".hddLoginUserType").val());
    if ($("#ctl00_TextBox1").val() == "输入歌手、歌曲名称或语言" || $("#ctl00_TextBox1").val() == "") {
        $("#ctl00_TextBox1").val("输入歌手、歌曲名称或语言");
        $("#ctl00_TextBox1").css("color", "#cccccc");
    }

    if ($("#ctl00_TextBox2").val() == "输入歌手、歌曲名称或语言" || $("#ctl00_TextBox2").val() == "") {
        $("#ctl00_TextBox2").val("输入歌手、歌曲名称或语言");
        $("#ctl00_TextBox2").css("color", "#cccccc");
    }
    RegLogin();
    openObj = location.href.request("group");
    var cateID = location.href.request("cateId");

    //绑定
    var openObjArry = openObj.split(',');
    for (i = 0; i < openObjArry.length; i++) {
        if (openObjArry[i].length > 0) {
            //绑定
            $("#menu-" + openObjArry[i]).css("display", "block");
            $("#mainMenu-" + openObjArry[i]).css("background", "url(images/iconplus.png) no-repeat 1% 45%");
        }
    }

    if (parseInt(cateID) > 0) {
        //设置选中颜色
        $("#menu-" + cateID).css("backgroundColor", '#f1f1f1');
    }
    $("#cateLeft").show();
    SelectTab();
    if (loginUserType == 0) {
        $(".btnCopy").hide();
    }
    GetLmLogo();
    GetLmAD();
    //showtopad();
});
var minTab = 0;
var loginUserType;


function gotoLmLink(url) {    
    location.href = 'http://' + $(".hddWebDomain").val() + url;
    return false;
}
function getLmLink(){
    return 'http://' + $(".hddWebDomain").val();
}
function ShowTip() {
   
    if (getCookie("thistip") != "close") {
        $("#thisTip").slideDown();
    }
}

function GetLmLogo() {
    AC.get(function(e) {
        if (e != "") {
            //$("#LogoImg").html("<img src=\"" + e + "\" style=\"width: 198px; height: 76px\" />");
            //$("#LogoImgIndex").css("background", "url(" + e + ")");
        }
    }, "GetLmInfo", "logo");
}

function GetLmAD() {
    AC.get(function(e) { if (e != "") { $("#LmAD").html(e.replace(/bbssite/g, $(".hddWebDomain").val())); } }, "GetLmInfo", "ad");
}

function hideTip() {
    setCookie("thistip", "close", "h1");
    $("#thisTip").slideUp();
}


function closead() {
    setCookie("topad", "close", "h1");
    $("#topAD").slideUp();
    return false;
}
function showtopad() {
    if (getCookie("topad") != "close") {
        $("#topAD").slideDown();
    }
}


function DoSearch() {
    var key = $("#ctl00_TextBox1").val();
    if (key == '输入歌手、歌曲名称或语言' || key=="") {
        alert("请输入关健字");
        return;
    }
    location.href = 'http://' + $(".hddWebDomain").val() + '/search.php?srchtxt=' +encodeURI($("#ctl00_TextBox1").val());
}

function SearchMusic() {
    if ($("#scbar_txt").val() == "请输入歌名或歌手" || $("#scbar_txt").val() == "" || $("#scbar_txt").val().replace(" ","") == "") {
        alert("请输入搜索关健字");
        return;
    }
    location.href = 'Search.aspx?update=1&keyword=' + encodeURI($("#scbar_txt").val());
}

function SearchBoxFocus() {
   // $("#scbar_btn").focus();
    if ($("#scbar_txt").val() == "请输入歌名或歌手") {
        $("#scbar_txt").val("");
    }
}

function ChangeColor(type, obj) {
    if (type == "over") {
        $(obj).css("background-color", '#fffacd').css("border", "solid 1px #adff2f");
    }
    else {
        $(obj).css("background-color", '#ffffff').css("border", "solid 1px #cccccc");
    }
}
function getName(url) {
    url = url || window.location.href;
    url = url.match(/(?!=\/)[^\/]*(?=\.aspx)/);
    return url ? url[0] : null;
}
function DivMouseEvent(obj, type, elementId) {
    if (type == "click") {
        obj.style.backgroundColor = '#f1f1f1';
        //打开与折叠
        var ID = parseInt(elementId);
        if (ID > 0) {
            if ($("#menu-" + elementId).css("display") == "none") {
                $(obj).css("background", "url(images/iconplus.png) no-repeat 1% 45%");
                $("#menu-" + elementId).show();
                //添加打开的
            }
            else {
                $(obj).css("background", "url(images/iconAdd.png) no-repeat 1% 45%");
                $("#menu-" + elementId).hide();
            }
        }
    }
    else if (type == "over") {
        currentcolor = obj.style.backgroundColor; obj.style.backgroundColor = '#FFFF99', obj.style.fontWeight = '';
    }
    else if (type == "out") {
        obj.style.backgroundColor = currentcolor, obj.style.fontWeight = '';
    }
}
function PicChange(obj) {
    if ($(obj).attr("checked") == true) {
        currentcolor = "#FFFF99";
        $(obj).parent().parent().css("backgroundColor", "#FFFF99");
    }
    else {
        currentcolor = "#ffffff";
        $(obj).parent().parent().css("backgroundColor", "#ffffff");
    }
}
function RegLogin() {
    $("#thisLogin").click(function() {
        OpenLogin();
    });
}

function OpenLogin() {
    $("#thisLogin").ShowDialog({
        id: -1,
        Width: "520",
        Height: "400",
        Title: "用户登陆",
        skin: "blue",
        FrameURL: "member/member.aspx?p=" + p,
        ContentFlag: "0",
        Contents: $("#temp3").html(),
        mask: 1
    });
}


function PackMouseEvent(obj, type, elementId,picID) {
    if (type == "click") {
        //打开与折叠
        if ($("#pack-" + elementId).css("display") == "none") {
            $(obj).css("background", "url(images/iconplus.png) no-repeat 1% 45%");
            $("#pack-" + elementId).show();
            $("#pack-" + elementId + "-a").text("折叠列表");
            $("#pack-" + elementId + "-b").attr("style", "background-color:#cccccc;");
            //添加打开的           
            if ($("#pack-" + elementId).html() == "" || $("#pack-" + elementId).html()== "正在加载中...") {
                $("#pack-" + elementId).html("正在加载中...");
                $.get("ajaxAblum.aspx?aid=" + elementId + "&tab="+picID+"&_t=" + new Date().getTime(), function(txt, state) { $("#pack-" + elementId).html(txt); });
            }
        }
        else {
            $(obj).css("background", "url(images/iconAdd.png) no-repeat 1% 45%");
            $("#pack-" + elementId).hide();
            $("#pack-" + elementId + "-a").text("展开列表");
        }
    }
}



function RedirectUrl(url) {
    location.href = url;
    return false;
}
function SelectTab() {
    var locationUrl = location.href;
    s = getName(locationUrl) == null ? "default" : getName(locationUrl);
    var userTab = location.href.request("tab");
    $(".tab-nav li").attr("class", "");
    switch (s.toLowerCase()) {
        case "view":
        case "single":
            ShowTip();
            if ($("#ctl00_ContentPlaceHolder1_useUserGroup").val() == "9") {
                $("#SxDVD").css("background-image", "url(images/dc1_03.gif)");
            }
            if (s.toLowerCase() == "view") {
                $(".ckBll-1").each(function() {
                    $(this).attr("checked", true);
                })
            }           
            if (userTab != null && userTab != undefined && userTab != "") {
                $("#tabKey a").attr("class", "");
                $("#tabkey-" + userTab).attr("class", "cur");
            }
            else if (parseInt($(".hddLoginUserGroup").val()) > 0) {
                $("#tabKey a").attr("class", "");
                $("#tabkey-" + $(".hddLoginUserGroup").val()).attr("class", "cur");
            }
            $("#folder-label-single").attr("class", "current");
            break;
        case "singerv":
        case "singer":
            $("#folder-label-singer").attr("class", "current");
            if (s.toLowerCase() == "singerv") {
                $(".ckBll-1").each(function() {
                    $(this).attr("checked", true);
                })
            }
            break;
        case "default":
            $("#folder-label-default").attr("class", "current");           
            GetUserLoginState();
            break;
        case "rank":
            $("#folder-label-rank").attr("class", "current");
            if ($("#ctl00_hddLoginUserType").val() != "-11") {
                var currentLoginUserGroup = parseInt($(".hddLoginUserGroup").val());
                $(".ckBll-3").each(function(e) {
                    //alert($(this).attr("id"));
                    if (parseInt($(this).val()) > currentLoginUserGroup) {
                        $("#" + $(this).attr("id") + "-1").attr("disabled", "disabled");
                    }
                });
            }
            break;
        case "mylib":
        case "search":
            if ($("#ctl00_hddLoginUserType").val() != "-11") {
                var currentLoginUserGroup = parseInt($(".hddLoginUserGroup").val());
                $(".ckBll-3").each(function(e) {
                    //alert($(this).attr("id"));
                    if (parseInt($(this).val()) > currentLoginUserGroup) {
                        $("#" + $(this).attr("id") + "-1").attr("disabled", "disabled");
                    }
                });
            }
            break;
        case "packv":
            if (s.toLowerCase() == "packv") {
                $(".ckBll-1").each(function() {
                    if ($(this).attr("disabled") != true) {
                        $(this).attr("checked", true);
                    }
                })
            }
            $("#folder-label-pack").attr("class", "current");
            break;
        case "pack":
            if (s.toLowerCase() == "packv") {
                $(".ckBll-1").each(function() {
                    if ($(this).attr("disabled") != true) {
                        $(this).attr("checked", true);
                    }
                })
            }

            if (userTab != null && userTab != undefined && userTab != "") {
                $("#tabKey a").attr("class", "");
                $("#tabkey-" + userTab).attr("class", "cur");
            }
           // else if (parseInt($(".hddLoginUserGroup").val()) > 0 && parseInt($(".hddLoginUserGroup").val()) > minTab) {
              //  $("#tabKey a").attr("class", "");
                //$("#tabkey-" + $(".hddLoginUserGroup").val()).attr("class", "cur");
            //}
            else {               
                $("#tabKey a").attr("class", "");
                $("#tabkey-" + minTab).attr("class", "cur");
            }
            $("#folder-label-pack").attr("class", "current");
            break;
        case "mylib":
            $("#folder-label-mylib").attr("class", "current");
            break;
        case "search":
            var x = location.href.request("keyword");
            var oldKey = decodeURI(x); //原始值
            if (x != "" && x != null) {
                if (oldKey != encodeURI(oldKey) && x != encodeURI(oldKey)) {
                    location.href = "Search.aspx?keyword=" + encodeURI(oldKey);
                }
            }
            break;
    }
}
function OpenUrl(obj, pageName) {
    var group = GetCateGroup();
    window.location.href = pageName + '.aspx?cateId=' + obj + "&update=1&_t=" + new Date().getMilliseconds() + "&group=" + group;
}
function SelectUserGruop(tabID) {
    var pageName = getName(location.href);
    var cateID = location.href.request("cateId");
    var group = GetCateGroup();
    if (cateID != null && cateID != undefined) {
        window.location.href = pageName + '.aspx?cateId=' + cateID + "&update=1&_t=" + new Date().getMilliseconds() + "&tab=" + tabID + "&group=" + group;
    }
    else {
        window.location.href = pageName + '.aspx?update=1&_t=' + new Date().getMilliseconds() + "&tab=" + tabID + "&group=" + group;
    }
}

function GetUserLoginState() {
    AC.get(function(e) {
        var obj = "";
        if (e == "-") {
            obj = "<div class=\"boxLeft1\" style=\"width:50px;cursor:pointer; color:#002280\"><a href=\"javascript:void(0)\" onclick=\"OpenLogin();return false;\">登 陆</a></div><div class=\"boxLeft1\"  style=\"width:80px\" id=\"thisReg1\"><a href=\"javascript:location.href='http://" + $(".hddWebDomain").val() + "/member.php?mod=register'\" target=_blank>免费注册</a></div>                    <div class=\"boxLeft1\"  style=\"width:80px\" id=\"Div1\"><a href=\"javascript:location.href='http://" + $(".hddWebDomain").val() + "/home.php?mod=spacecp&ac=credit'\" target=_blank>忘记密码？</a></div>";
        }
        else {
            obj = e;
        }
        $("#ctl00_UserLogin").html(obj);
        if (e == "-") {
            RegLogin();
        }
    }, "GetLoginState", "1");
}

function GetCateGroup() {
    var group = "";
    $(".thismenu").each(function() {
        if ($(this).css("display") == "block") {
            group += "," + $(this).find("input").val();
        }
    });
    return group;
}

//批量添加到候选
function AddToHx(objCss) {
    if ($("#ctl00_hddLoginUserType").val() == "-11") {
        ShowNoLoginPop();
        return;
    }
    var ids = GetSelectFiles(objCss);
    if (ids != null && ids != "") {
        var idsArry = ids.split(',');
        var kingTotal = 0;
        for (var j = 0; j < idsArry.length; j++) {
            if (idsArry[j] != "") {
                kingTotal += parseInt($("#KingCoin" + idsArry[j]).val());
            }
        }
        AC.get(function(e) {
            if (e > 0) {
                ShowPopMsg("歌曲已成功添加到侯选列表", "本次共添加" + idsArry.length + "首歌曲  合计：" + kingTotal + "金豆.<br><a href='mylib.aspx?cateId=2&update=1&_t=735&group=,1'>去候选列表</a>");
            } else {
                alert("错误:" + e + " 添加到侯选列表");
            }
        }, "AccAddHx", ids, "HX");
        //AC.get(function(e) { if (e > 0) { alert("添加到侯选列表成功"); } else { alert("错误:"+e+" 添加到侯选列表失败"); } }, "AccAddHx", ids,"HX");
    }
}

function btnClick(type, fileID, viewPerm) {
    //alert(type+" "+fileID+" "+viewPerm);
    var locationUrl = location.href;
    s = getName(locationUrl) == null ? "default" : getName(locationUrl);
    if (type == "fava") {
        AddToFava(fileID);
    }
    else if (type == "down") {
        if (viewPerm == "1") {
            //未登录状态下点免费资源则自动进入内容页，
            if ($("#ctl00_hddLoginUserType").val() == "-11") {
                //alert("1")
                location.href = 'view.aspx?id=' + fileID;
                return;
            }
            else {
                AC.get(function(e) {
                    //alert("2");
                    if (parseInt(e) > 0 || parseInt(e) == -2) {
                        if (s.toLowerCase() == "mylib" && location.href.request("cateId") == "3") {
                            //alert("3")
                            GetNoPayDownApply(fileID);
                        }
                        else {
                            //alert("4")
                            GetDownApply(fileID)
                        }
                    }
                    else if (parseInt(e) == -1) {
                    //alert("5")
                        ShowNoLoginPop();
                    }
                    else {
                        location.href = 'view.aspx?id=' + fileID;
                    }
                }, "GetKingCoin")
            }
        }
        else {

            if ($("#ctl00_hddLoginUserType").val() == "-11") {
                ShowNoLoginPop();
                return;
            }
            if (parseInt(viewPerm) > parseInt($(".hddLoginUserGroupIndex").val())) {
                ShowGroupPop("权限不足，请升级为为更高等级会员");
                return;
            }
            AC.get(function(e) {
                if (parseInt(e) > 0) {
                    if (s.toLowerCase() == "mylib" && location.href.request("cateId") == "3") {
                       // alert("6")
                        GetNoPayDownApply(fileID);
                    }
                    else {
                        //alert("7")
                        GetDownApply(fileID)
                    }
                }
                else if (parseInt(e) == -2) {
                    //包时会员
                    GetDownApply(fileID);
                } else if (parseInt(e) == -1) {
                    ShowNoLoginPop();
                }
                else if (parseInt(e) == -3) {
                    ShowGroupPop("你目前是普通会员暂不能下载此文件，请升级为扣点会员或VIP会员");
                }
                else {
                    ShowNoKingCoin();
                }
            }, "GetKingCoin");
        }
    }
    return false;
}

function CopyToBoard(objcss) {
    if ($("#ctl00_hddLoginUserType").val() == "-11") {
        ShowNoLoginPop();
        return;
    }
}

function AddToFava(ids) {
    if ($("#ctl00_hddLoginUserType").val() == "-11") {
        ShowNoLoginPop();
        return;
    }
    var idsArry = ids.split(',');
    var kingTotal = 0;
    for (var j = 0; j < idsArry.length; j++) {
        if (idsArry[j] != "") {
            kingTotal += parseInt($("#KingCoin" + idsArry[j]).val());
        }
    }
    AC.get(function(e) {
        if (e > 0) {
            ShowPopMsg("歌曲已成功添加到收藏列表", "本次共添加" + idsArry.length + "首歌曲  合计：" + kingTotal + "金豆<br><a href='mylib.aspx?cateId=2&update=1&_t=735&group=,1'>去候选列表</a>");
        } else {
            alert("错误:" + e + " 添加到收藏失败");
        }
    }, "AccAddHx", ids, "FAVA");
}

function ShowNoLoginPop() {
    // ShowPopMsg("温馨提示", "你还没有登陆，无法进行此操作,请登陆后重试", "");
    //$("#thisLogin").click();
    OpenLogin();
}

function ShowNoKingCoin() {
    ShowPopMsg("温馨提示", "你的金豆为0，无法进行下载,请先充值. <a href='http://bbs." + $(".hddWebDomain").val() + "/home.php?mod=spacecp&ac=credit'>点此充值</a>", "");
}

function ShowGroupPop(msg) {
    ShowPopMsg("温馨提示", msg, "<div style='padding-top:5px;padding-right:20px;'><input id=\"Button3\" type=\"button\" onclick='location.href=\"http://bbs.comktv.com/home.php?mod=spacecp&ac=usergroup&do=buy&groupid=20&perms=upgrade&handlekey=buygrouphk\"' value=\"立即升级\" />&nbsp;<input id=\"Button3\" type=\"button\" onclick='$(\"#closewin\").click();' value=\"我再逛逛\" /></div>");
}

function ShowNoKingCoin2() {
    ShowPopMsg("您的金豆余额不足或权限不足!", "您可以选择充值或升级会员，体验便捷的高速下载", "<div style='padding-top:5px;padding-right:20px;'><input id=\"Button3\" type=\"button\" onclick='location.href=\"http://bbs.comktv.com/portal.php?mod=topic&topicid=2\"' value=\"了解资费\" />&nbsp;<input id=\"Button3\" type=\"button\" onclick='$(\"#closewin\").click();' value=\"我再逛逛\" /></div>");
}

function ShowSearchZero(msg) {
    ShowPopMsg("你难到我啦", msg, "<div style='padding-top:5px;padding-right:20px;'><input id=\"Button3\" type=\"button\" onclick='location.href=location.href+\"&update=1\"' value=\"重置\" /></div>");
}
function ShowSearchZero2(msg) {
    ShowPopMsg("你难到我啦", msg, "<div style='padding-top:5px;padding-right:20px;'><input id=\"Button3\" type=\"button\" onclick='location.href=location.href+\"?update=1\"' value=\"重置\" /></div>");
}

function ShowDownState() {
    ShowPopMsg("温馨提示[请勿刷新或关闭浏览器]", "<div>正在处理下载流程<img src='images/loading.gif' /></div><div><a target='_blank' href='" + getLmLink() + "/forum.php?mod=viewthread&tid=181243&extra=page%3D1'> 如何免费下载</a></div>", "&nbsp;");
}



function XunLeiDown(objCss) {
    var locationUrl = location.href;
    s = getName(locationUrl) == null ? "default" : getName(locationUrl);

    if (s.toLowerCase() == "mylib" && location.href.request("cateId") == "3") {
        XunLeiNoPayDown(objCss);
    }
    else {
        var ids = GetSelectFiles(objCss);
        if (ids != null && ids != "") {
            GetDownApply(ids);
        }
    }
}


function XunLeiNoPayDown(objCss) {
    var ids = GetSelectFiles(objCss);
    if (ids != null && ids != "") {
        GetNoPayDownApply(ids);
    }
}

function GetJlDownApply(ids) {
    AC.get(function(e) { JLDown(e); }, "GetjlAddress", parseInt(ids));
}

function JLDown(URL) {
    if (URL == "masttime") {
        alert("今日免费下载次数已到，你可以选择迅雷下载");
        return;
    }
    //ShowPopMsg("温馨提示", "您没有正确安装《MTV分享精灵》软件或者没有启动《MTV分享精灵》软件，无法正确下载！\r\n<a href='http://www.baidu.com'  target='_blank'>点此立即下载</a>。", "");
    var obj;
    try {
        obj = new ActiveXObject("IE2EM.IE2EMUrlTaker");
    } catch (e) {
        ShowPopMsg("温馨提示", "您没有正确安装《MTV分享精灵》软件或者没有启动《MTV分享精灵》软件，无法正确下载！\r\n<a href='http://www.mtv-ktv.com/soft.htm' target='_blank'>点此立即下载</a>。", "");
    }
    if (obj != null) {
        try {
            obj.SendUrl(URL, '', '');
        }
        catch (e) {
            alert(e.message);
        }
    }
}


function GetSelectFiles(objCss) {
    var fileList = $("." + objCss + "[checked]");
    if (fileList.length == 0) {
        alert("请先选择你操作的文件");
        return;
    }
    var ids = "";
    for (i = 0; i < fileList.length; i++) {
        ids += $(fileList[i]).val() + ",";
    }
    return ids;
}



function ShowPopMsg(msgTitle, msgContent, msgBottom) {    
    $("#thisLogin").ShowWindow({
        id: 1,
        Width: "520",
        Height: "400",
        Title: "用户登陆",
        skin: "blue",
        FrameURL: "member/member.aspx",
        ContentFlag: "1",
        Contents: $(".popDialog").html(),
        mask: 1
    });

    $(".popDialogContent").html(msgContent);
    $(".popDialoTitle").text(msgTitle);
    if (msgBottom != null && msgBottom != undefined && msgBottom.length > 0) {
        $(".popDialogBottom").html(msgBottom);
    }
    else {
        $(".popDialogBottom").html("<div style='padding-top:5px;padding-right:20px;'><input id=\"Button3\" type=\"button\" onclick='$(\"#closewin\").click();' value=\"知道了\" /></div>");
    }
}

function CheckBox1(objID, ContainerID) {
    if ($("#" + objID).attr("checked") == true) {
        $("." + ContainerID).each(function() {
            if ($(this).attr("disabled") != true) {
                $(this).attr("checked", true);
                $(this).parent().parent().css("backgroundColor", "#FFFF99");
            }
        })
    }
    else {
        $("." + ContainerID).each(function() {
            $(this).attr("checked", false);
            $(this).parent().parent().css("backgroundColor", "#ffffff");
        })
    }
}

function fEvent(sType, oInput) {
    switch (sType) {
        case "focus":
            oInput.isfocus = true;
            if (oInput == "txtPwd") {
                ShowVerify();
            }
            $("#" + oInput).attr('class', 'inputBox1');

            if (oInput == "TextBox1" && $("#ctl00_TextBox1").val() == "输入歌手、歌曲名称或语言") {
                $("#ctl00_TextBox1").val("");
                $("#ctl00_TextBox1").css("color", "#000000");
            }
            break;
        case "blur":
            oInput.isfocus = false;
            $("#" + oInput).attr('class', 'inputBox');
            if (oInput == "TextBox1" && ($("#ctl00_TextBox1").val() == "输入歌手、歌曲名称或语言" || $("#ctl00_TextBox1").val() == "")) {
                $("#ctl00_TextBox1").val("输入歌手、歌曲名称或语言");
                $("#ctl00_TextBox1").css("color", "#cccccc");
            }
            break;
    }
}
var GetDownApply = function(ids) {
    //检测迅雷
    if ($("#ctl00_hddLoginUserType").val() == "-11") {
        ShowNoLoginPop();
        return;
    }
    if (CheckThunder()) {
        var idsArry = ids.split(',');
        var kingTotal = 0;

        for (var j = 0; j < idsArry.length; j++) {
            if (idsArry[j] != "") {
                kingTotal += parseInt($("#KingCoin" + idsArry[j]).val());
            }
        }

        if ($(".hddLoginUserType").val() == "0") {
            if (kingTotal > 0) {

                if (!confirm("此次下载将扣除" + kingTotal + "金豆，您确定么？如需重复下载请点击进入“已下载列表”进行下载")) {
                    return;
                }

            }
        }
        ShowDownState();
        //检测ids 扣费
        AC.get(function(e) {
            $("#closewin").click();
            if (e.result == 0) {
                //下载               
                var downList = e.DownList.split('*');
                if (downList.length == 1) {
                    beginDownLoad('', downList[0].split('|')[0], '', downList[0].split('|')[1], '');
                }
                else {
                    batchDownload(downList);
                }
                //设置已下载文件的金豆为0;
                for (var j = 0; j < idsArry.length; j++) {
                    if (ids[j] != "") {
                        $("#KingCoin" + idsArry[j]).val("0");
                        //alert("aaa" + idsArry[j]);
                    }
                }

                return true;
            }
            else if (e.result == -1) {
                alert("VIP到期");
                return false;
            }
            else if (e.result == -2) {
                ShowNoKingCoin2();
                return false;
            }
            else if (e.result == -10) {
                alert("系统维护中，请联系管理员");
                return false;
            }
            else if (e.result == -11) {
                alert("你还未登陆，请先登陆");
                $("#thisReg").click();
                return false;
            }
        }, "AccPay", ids);


    }
}


var GetDownAllApply = function(ids) {
    //检测迅雷
    if ($("#ctl00_hddLoginUserType").val() == "-11") {
        ShowNoLoginPop();
        return;
    }
    if (CheckThunder()) {
        var idsArry = ids.split(',');
        var kingTotal = 0;
                
        ShowDownState();
        //检测ids 扣费
        AC.get(function(e) {
            $("#closewin").click();
            if (e.result == 0) {
                //下载               
                var downList = e.DownList.split('*');
                if (downList.length == 1) {
                    beginDownLoad('', downList[0].split('|')[0], '', downList[0].split('|')[1], '');
                }
                else {
                    batchDownload(downList);
                }
                //设置已下载文件的金豆为0;
                for (var j = 0; j < idsArry.length; j++) {
                    if (ids[j] != "") {
                        $("#KingCoin" + idsArry[j]).val("0");
                        //alert("aaa" + idsArry[j]);
                    }
                }

                return true;
            }
            else if (e.result == -1) {
                alert("VIP到期");
                return false;
            }
            else if (e.result == -2) {
                ShowNoKingCoin2();
                return false;
            }
            else if (e.result == -10) {
                alert("系统维护中，请联系管理员");
                return false;
            }
            else if (e.result == -11) {
                alert("你还未登陆，请先登陆");
                $("#thisReg").click();
                return false;
            }
        }, "AccPayAll", ids);


    }
}



var GetNoPayDownApply = function(ids) {
    //检测迅雷
    if ($("#ctl00_hddLoginUserType").val() == "-11") {
        ShowNoLoginPop();
        return;
    }
    if (CheckThunder()) {
        //检测ids 扣费
        AC.get(function(e) {
            if (e.result == 0) {
                //下载
                var downList = e.DownList.split('*');
                if (downList.length == 1) {
                    beginDownLoad('', downList[0].split('|')[0], '', downList[0].split('|')[1], '');
                }
                else {
                    batchDownload(downList);
                }
                return true;
            }
        }, "GetThAddress", ids);
    }
}

var thisTest = function(data, stat) {
    try {
        alert("aa");
        var fileList = $("input[type=checkbox][checked]");
        if (fileList.length == 0) {
            alert("请先选择你要下载的文件");
            return;
        }
        for (i = 0; i < fileList.length; i++) {
            addTask('', $(fileList[i]).val(), '', '', '');
        }
        commitTasks();
        return true;
    } catch (e) {
        alert(e.message);
        return false;
    }
}
//var Thunder = null;
// var download, addTask, commitTasks, batchDownload = null;
var Delegate = {
    create: function(obj, func) {
        var f = function() {
            var target = arguments.callee.target; var func = arguments.callee.func; return func.apply(target, arguments);
        };
        f.target = obj;
        f.func = func;
        return f;
    }
};
function CheckThunder() {
    TDDownLoad.Init();
    if (Thunder == null || Thunder == undefined) {
        alert("迅雷初始化失败!无法进行下载，出现这个提示,可能是你没有安装迅雷,或者您的浏览器兼容性问题，请更换为系统内置IE浏览器访问试试！");
        return false;
    }
    return true;
}
//单文件下载
function beginDownLoad(cid, url, refer, name, stat) {
    TDDownLoad.Init();
    TDDownLoad.download(cid, url, refer, name, stat);
}
//批量下载
function batchDownload(data) {
    TDDownLoad.Init();
    for (i = 0; i < data.length; i++) {
        TDDownLoad.addTask('', data[i].split('|')[0], '', data[i].split('|')[1], '');
    }
    TDDownLoad.commitTasks();
}
var Thunder = null;
var TDDownLoad = {
    DownType: 0,
    Init: function() {
        try {
            Thunder = new ActiveXObject("ThunderAgent.Agent.1");

            this.DownType = 1;
        }
        catch (e) {
            try {
                Thunder = new ActiveXObject("ThunderServer.webThunder.1");
                this.DownType = 2;
            }
            catch (e) {
                try {
                    Thunder = new ActiveXObject("ThunderAgent.Agent");
                    this.DownType = 3;
                }
                catch (e) {
                    Thunder = null;
                }
            }
        }
    },
    addTask: function(cid, url, refer, name, stat) {
        var _addTask = [
                                    Delegate.create(this, function() { Thunder.AddTask4(url, name, "", name, refer, -1, 0, -1, "", cid, stat); }),
                                    Delegate.create(this, function() { Thunder.AddTask3(url, name, "", name, refer, -1, 0, -1, "", cid); }),
                                    Delegate.create(this, function() { Thunder.AddTask2(url, name, "", name, refer, -1, 0, -1, ""); }),
                                    Delegate.create(this, function() { Thunder.AddTask(url, name, "", name, refer, -1, 0, -1); })];
        for (var i = 0; i < _addTask.length; i++) {
            try {
                _addTask[i]();
                return;
            } catch (e) { alert("错误：-1" + e.message); }
        }
    },
    commitTasks: function() {
        var _commitTasks = [Delegate.create(this, function() { Thunder.CommitTasks2(1); }),
                                            Delegate.create(this, function() { Thunder.CommitTasks(); })];
        for (var i = 0; i < _commitTasks.length; i++) {
            try {
                _commitTasks[i]();
                return;
            } catch (e) { alert("错误：-2" + e.message); }
        }
    },
    download: function(cid, url, refer, name, stat) {
        try {
            this.addTask(cid, url, refer, name, stat);
            this.commitTasks();
        } catch (e) {
            alert("错误：-3" + e.message);
        }
    }
}
