<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Admin_DPPopularGame.aspx.cs" Inherits="TW.UI.Admin.Admin_DPPopularGame" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<link href="css/default.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../js/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="../js/public.js"></script>
<script type="text/javascript" src="../js/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript" src="../js/artDialog/artDialog.js?skin=default"></script>
<script type="text/javascript" src="../js/artDialog/plugins/iframeTools.js"></script>
<script type="text/javascript" src="../js/kindeditor/kindeditor-min.js"></script>
<script type="text/javascript" src="/js/FancyZoom/FancyZoom.js"></script>
<script type="text/javascript" src="/js/FancyZoom/FancyZoomHTML.js"></script>
<script type="text/javascript">
    function addpopulgm() {
        var addidx = $("input[type='text'][name='<%=mainpara %>tit']").length+1;
        var htmlstr = "";
        htmlstr += "<tr><td>"+addidx+"</td><td><input type=\"text\" name=\"<%=mainpara %>tit\" /></td><td valign=top class=\"pplbox\" id=\"<%=mainpara %>box" + addidx + "\"></td>";
        htmlstr += "<td><table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" class=\"lsttbiftb\"><tr><th>商品：</th>";
        htmlstr += "<td><div id=\"<%=mainpara %>" + addidx + "\"></div>";
        htmlstr += "<input type=\"button\"  onclick=\"KyoWin('添加商品','/admin/Admin_ProductList.aspx?act=addpplpro&inhtml='+$(this).prev().attr('id')+'');\" value=\"添加商品\" class=\"btnbig\" />";
        htmlstr += "</td></tr><tr><th>大图：</th><td>建议尺寸：像素-900x300<br />";
        htmlstr += "<input type=\"hidden\" id=\"hidThumb" + addidx + "\" name=\"hidThumb\" />";
        htmlstr += "<iframe src=\"/inc/upload.aspx?dir=image&input=hidThumb" + addidx + "\" id=\"Iframe1\" width=\"96%\" height=\"25\" scrolling=\"no\" frameborder=\"0\" allowtransparency=\"true\"></iframe>";
        htmlstr += "<span id=\"hidThumb" + addidx + "_Preview\"></span></td></tr><tr><th></th><td>";
        htmlstr += "<input type=\"button\" value=\"添加\" class=\"depclrbtn\" onclick=\"addpopulproinfo(this);\" /></td>";
        htmlstr += "</tr></table></td><td width=\"50px;\"><a class=\"probtn\" onclick=\"delthetr(this);\">删除</a></td></tr>";
        $("#clsprotab").append(htmlstr);
        ratippgmidx();
    }
    function remvpopu(obj) {
        $(obj).parent().remove();
    }
    function showprothumb(obj) {
        $(".imgshow").find("img").attr("src", "/uploads/?"+$(obj).next().children("input[type='hidden']").val()+"_900x300.jpg");
        $('.imgzoom').show();
        $('.imgshow').show();
    }
    function delthetr(obj) {
        $(obj).parent().parent().remove();
        ratippgmidx();
    }
    function addpopulproinfo(obj) {
        var tidxprolen = $(obj).parent().parent().parent().parent().parent().prev().find(".populprobox").length;
        if (tidxprolen >= 4) {
            alert("最多添加4个商品");
            return false;
        }

        var tbtnixd = $(obj).index("table#clsprotab input[type='button'].depclrbtn") + 1;

        var prohtml = $(obj).parent().parent().prev().prev().find("td div").html();
        if (prohtml == "") {
            alert("请添加商品");
            return false;
        }
        var proid = $(obj).parent().parent().prev().prev().find("td div input[type='hidden']").val();
        var tpeolen = $(obj).parent().parent().parent().parent().parent().prev().find("input[type='hidden'][value='" + proid + "']").length;
        if (tpeolen > 0) {
            alert("该商品已存在");
            return false;
        }
        var protit = $(obj).parent().parent().prev().prev().find("td div a.probtn").html();
        var prothumb = $(obj).parent().parent().prev().find("td input[type='hidden'][name='hidThumb']").val();
        if (prothumb == "") {
            alert("请上传大图");
            return false;
        }

        var strhtml = "";
        strhtml += "<span class=\"populprobox\">";
        strhtml += "<a onclick=\"remvpopu(this)\" id=\"pro" + proid + "\" class=\"popupro fwbld\">" + protit + "</a>";
        strhtml += "<input type=\"hidden\" name=\"<%=mainpara %>_id" + tbtnixd + "\" value=\"" + proid + "\">";
        strhtml += "<img src=\"images/tu1.gif\" border=\"0\" onclick=\"showprothumb(this);\" class=\"mglr10px\">";
        strhtml += "<a onclick=\"KyoWin('修改图片','/admin/Admin_GmLstHotThumb.aspx?idx='+$(this).attr('idx')+'&id=" + proid + "&act=pplgmpic');\" idx=\"" + tbtnixd + "\" id=\"thumb" + proid + "\" class=\"popumdpic\">";
        strhtml += "<input type=\"hidden\" name=\"<%=mainpara %>_thumb" + tbtnixd + "\" value=\"" + prothumb + "\">";
        strhtml += "修改图片";
        strhtml += "</a>";
        strhtml += "</span>";
        $(obj).parent().parent().parent().parent().parent().prev().append(strhtml);

        $(obj).parent().parent().prev().prev().find("td div").html("");
        $(obj).parent().parent().prev().find("td input[type='hidden'][name='hidThumb']").val("");
        $(obj).parent().parent().prev().find("td #hidThumb" + tbtnixd + "_Preview").html("");
    }
    function ratippgmidx() {
        var ii = 1;
        $("input[type='text'][name='<%=mainpara %>tit']").each(function () {
            $(this).parent().prev().html(ii);
            $(this).parent().next().attr("id", "<%=mainpara %>box" + ii);

            $(this).parent().next().find(".populprobox .popupro.fwbld").attr("id", "pro" + ii);
            $(this).parent().next().find(".populprobox .popupro.fwbld").next().attr("name", "<%=mainpara %>_id" + ii);
            $(this).parent().next().find(".populprobox .popumdpic").attr("idx", ii);
            $(this).parent().next().find(".populprobox .popumdpic input[type='hidden']").attr("name", "<%=mainpara %>_thumb" + ii);

            $(this).parent().next().next().find("table.lsttbiftb td div").attr("id", "<%=mainpara %>" + ii);
            $(this).parent().next().next().find("table.lsttbiftb td input[type='hidden'][name='hidThumb']").attr("id", "hidThumb" + ii);
            $(this).parent().next().next().find("table.lsttbiftb td input[type='hidden'][name='hidThumb']").next().attr("src", "/inc/upload.aspx?dir=image&input=hidThumb" + ii);
            $(this).parent().next().next().find("table.lsttbiftb td input[type='hidden'][name='hidThumb']").next().next().attr("id", "hidThumb" + ii+"_Preview");
            ii++;
        });
    }
    function chksub() {
        var ret = true;

        var ii = 1;
        var titstr = "";
        $("input[type='text'][name='<%=mainpara %>tit']").each(function () {
            var titv = $.trim($(this).val());
            if (titv == "") {
                alert("第" + ii + "行名称不能为空");
                $(this).focus();
                ret = false;
                return false;
            }
            var thisprolen = $(this).parent().next().find("input[type='hidden'][name='<%=mainpara %>_id" + ii + "']").length;
            if (thisprolen == 0) {
                alert("第" + ii + "行商品不能为空");
                ret = false;
                return false;
            }
            ii++;
            titstr += titv + ",";
        });
        if (ret == false) {
            return ret;
        }
        titstr = titstr.substr(0, titstr.length - 1);

        var titary = titstr.split(",");
        for (var i = 0; i < titary.length; i++) {
            var oprttitary = titstr.split(",");
            oprttitary.splice(i, 1);
            for (var j = 0; j < oprttitary.length; j++) {
                if (oprttitary[j] == titary[i]) {
                    alert(oprttitary[j] + "=" + titary[i] + "i:" + i+"j:"+j);
                    alert("名称第行" + (j + 2) + "与第" + (i + 1) + "行重复");
                    $("input[type='text'][name='<%=mainpara %>tit']:eq(" + (j + 1) + ")").focus();
                    ret = false;
                    return false;
                }
            }
        }
        if (ret == false) {
            return ret;
        }

        return ret;
    }
</script>
</head>
<body onload="setupZoom();">
<form id="form1" runat="server">
<div class="imgzoom"></div>
<div class="imgshow"><img src="/silitu/rmyxglsl.png" onclick="$('.imgzoom').hide();$('.imgshow').hide();"></div>
<div class="nav"><h1>热门游戏</h1></div>

<div class="cont">

<div class="opera">
    <table class="seletable">
        
        <tr>
            <td>
            </td>
            <td><font color=red>注：该功能用于首页热门游戏管理，示例图：<a href="/silitu/rmyxglsl.png"><img src="images/tu1.gif" /></a></font>
            </td>
        </tr>
        <tr>
            <td>
            </td>
            <td>
                <input id="Button3" type="button" value="查看前台页面" onclick="window.open('/');" class="btn1 btn111" />
                <asp:Button ID="btnSave" runat="server" Text="批量保存" CssClass="btn1 btn111" OnClientClick="return chksub();" onclick="btnSave_Click" />
            </td>
        </tr>
    </table>
</div>


<input type="button" id="btnaddpopulgm" class="btn1 btn111" value="添加热门游戏" onclick="addpopulgm();" /><font color=red>注：每条热门游戏记录最多添加4个商品</font><br /><br />
<table class="table1" id="clsprotab">
    <tr>
        <td>序号</td>
        <td>名称</td>
        <td width="50%">商品</td>
        <td width="350">添加商品</td>
        <td>删除</td>
    </tr>
    <asp:Literal ID="litPopularGame" runat="server"></asp:Literal>
</table>



</div>

</form>

<script type="text/javascript">
    var oTab = $('.table1')[0];
    var oldBgColor = '';
    var i = 0;
    for (i = 0; i < oTab.tBodies[0].rows.length; i++) {
        oTab.tBodies[0].rows[i].style.background = i % 2 ? '#ffffff' : 'url(images/line2.png) repeat-x';
        oTab.tBodies[0].rows[i].onmouseover = function () {
            oldBgColor = this.style.background;
            this.style.background = '#ffffd4 url(images/line.png) repeat-x';
        };
        oTab.tBodies[0].rows[i].onmouseout = function () {
            this.style.background = oldBgColor;
        };
    }
</script>
</body>
</html>
