$(function () {

    showTab($("#templateCode_Tab"));

    //提交判断
    $("form").submit(function () {
        $("input[type='text'],input[type='password'],textarea").trigger("blur");
        $("select").trigger("change");

        ///新增方法填写在此///

        /////

        if ($("form span").hasClass("ico-error")) {
            $("input:submit").attr("disabled", false);
            $("input:submit").next("span").attr("class", "point ico-error R");
            $("input:submit").next("span").text("请按照提示正确操作，检查各项填写");
            setInterval(delSubmitBtnMsg, 3000);
            return false;
        } else {
            $("input:submit").attr("disabled", true);
            $("input:submit").next("span").attr("class", "Q");
            $("input:submit").next("span").html("<img src=\"Images/Loading.gif\" align=\"middle\" /> 正在保存…");
        }
    });

    //站点信息
    $("input[rel='commonBtn']").click(function () {
        var obj = $(this);
        var codeText = $("#commonCode_text");

        codeText.text(obj.attr("code"));
        codeText.next("span").attr("class", "point ico-via Q").html("（" + obj.prev().text() + "） 获取时间 <span class=R>" + new Date().toLocaleTimeString() + "</span>，已自动复制");
        window.clipboardData.setData("Text", obj.attr("code"));
        codeText.focus();
        codeText.select();
        return false;
    })

    //公司信息
    $("input[rel='corpBtn']").click(function () {
        var obj = $(this);
        var codeText = $("#corpCode_text");

        codeText.text(obj.attr("code"));
        codeText.next("span").attr("class", "point ico-via Q").html("（" + obj.prev().text() + "） 获取时间 <span class=R>" + new Date().toLocaleTimeString() + "</span>，已自动复制");
        window.clipboardData.setData("Text", obj.attr("code"));
        codeText.focus();
        codeText.select();
        return false;
    })

    //幻灯数据
    //导航信息
    $("input[rel='slideDatBtn']").click(function () {
        var obj = $(this);
        var selectobj = obj.prev("select");
        var codeText = $("#slideCode_text");
        var showCode = "";

        if (selectobj.val() == "-1") {
            showCode += "<% foreach (System.Data.DataRow item in _slideListDat(naviid).Rows) %>\r";
            showCode += "<% { %>\r";
            showCode += "   <%=item[\"title\"].ToString()%><%=item[\"picpath\"].ToString()%>\r";
            showCode += "<% } %>\r";
        } else {
            showCode += "<% foreach (System.Data.DataRow item in _slideListDat(\"" + selectobj.val() + "\").Rows) %>\r";
            showCode += "<% { %>\r";
            showCode += "   <%=item[\"title\"].ToString()%><%=item[\"picpath\"].ToString()%>\r";
            showCode += "<% } %>\r";
        }

        codeText.text(showCode);

        codeText.next("span").attr("class", "point ico-via Q").html("（幻灯循环数据） 获取时间 <span class=R>" + new Date().toLocaleTimeString() + "</span>，已自动复制");

        window.clipboardData.setData("Text", showCode);
        codeText.focus();
        codeText.select();
        return false;
    })

    //导航信息
    $("input[rel='naviDatBtn']").click(function () {
        var obj = $(this);
        var selectobj = obj.prev("select");
        var codeText = $("#naviCode_text");
        var showCode = "";

        if (selectobj.val() == "0") {
            showCode += "<% foreach (System.Data.DataRow item in getParentNavi.Rows) %>\r";
            showCode += "<% { %>\r";
            showCode += "   <%=item[\"name\"].ToString()%>\r";
            showCode += "<% } %>\r";
        } else {
            showCode += "<% foreach (System.Data.DataRow item in getSubNavi(\"" + selectobj.val() + "\").Rows) %>\r";
            showCode += "<% { %>\r";
            showCode += "   <%=item[\"name\"].ToString()%>\r";
            showCode += "<% } %>\r";
        }

        codeText.text(showCode);

        codeText.next("span").attr("class", "point ico-via Q").html("（导航循环数据） 获取时间 <span class=R>" + new Date().toLocaleTimeString() + "</span>，已自动复制");

        window.clipboardData.setData("Text", showCode);
        codeText.focus();
        codeText.select();
        return false;
    })
    $("input[rel='naviBtn']").click(function () {
        var obj = $(this);
        var selectobj = obj.prev("select");
        var codeText = $("#naviCode_text");

        codeText.text(selectobj.val());
        codeText.next("span").attr("class", "point ico-via Q").html("（" + selectobj.prev().text() + "） 获取时间 <span class=R>" + new Date().toLocaleTimeString() + "</span>，已自动复制");
        window.clipboardData.setData("Text", selectobj.val());
        codeText.focus();
        codeText.select();
        return false;
    })
    //单页相关
    $("#pageBtn").click(function () {
        var obj = $(this);
        var selectobj = $("#pageNaviSelect");
        var codeText = $("#pageCode_text");

        var showCode = "<%=_getPage(\"naviid=" + selectobj.val() + "\"," + $("#pageCutStr").val() + ")%>";

        codeText.text(showCode);
        codeText.next("span").attr("class", "point ico-via Q").html("（单页内容） 获取时间 <span class=R>" + new Date().toLocaleTimeString() + "</span>，已自动复制");
        window.clipboardData.setData("Text", showCode);
        codeText.focus();
        codeText.select();
        return false;
    })
    //图册相关
    $("#picBtn").click(function () {
        var obj = $(this);
        var selectobj = $("#picNaviSelect");
        var codeText = $("#picCode_text");

        var where = "naviid=" + selectobj.val() + "";

        if ($("input[name='picRange_rad']:checked").val() != "0") {
            where += " and attribute" + $("input[name='picRange_rad']:checked").val() + "=1";
        }
        var order = "\"" + $("#picorder2_select").val() + $("#picorder_select").val() + "\"";

        var showCode = "";
        showCode += "<% foreach (System.Data.DataRow item in _getPic(" + $("#picCount").val() + ",\"" + where + "\"," + order + ").Rows) %>\r";
        showCode += "<% { %>\r";
        showCode += "   <%=item[\"id\"].ToString()%>\r";
        showCode += "<% } %>\r";



        codeText.text(showCode);
        codeText.next("span").attr("class", "point ico-via Q").html("（图册调用） 获取时间 <span class=R>" + new Date().toLocaleTimeString() + "</span>，已自动复制");
        window.clipboardData.setData("Text", showCode);
        codeText.focus();
        codeText.select();
        return false;
    })
    //文章相关
    $("#articleBtn").click(function () {
        var obj = $(this);
        var selectobj = $("#articleNaviSelect");
        var codeText = $("#articleCode_text");

        var where = "naviid=" + selectobj.val() + "";

        if ($("input[name='articleRange_rad']:checked").val() != "0") {
            where += " and attribute" + $("input[name='articleRange_rad']:checked").val() + "=1";
        }
        var order = "\"" + $("#articleorder2_select").val() + $("#articleorder_select").val() + "\"";

        var showCode = "";
        showCode += "<% foreach (System.Data.DataRow item in _getArticle(" + $("#articleCount").val() + ",\"" + where + "\"," + order + ").Rows) %>\r";
        showCode += "<% { %>\r";
        showCode += "   <%=item[\"title\"].ToString()%>\r";
        showCode += "   <%=item[\"url\"].ToString()%>\r";
        showCode += "<% } %>\r";



        codeText.text(showCode);
        codeText.next("span").attr("class", "point ico-via Q").html("（文章调用） 获取时间 <span class=R>" + new Date().toLocaleTimeString() + "</span>，已自动复制");
        window.clipboardData.setData("Text", showCode);
        codeText.focus();
        codeText.select();
        return false;
    })
    //产品相关
    $("#proBtn").click(function () {
        var obj = $(this);
        var selectobj = $("#proNaviSelect");
        var codeText = $("#proCode_text");

        var where = "naviid=" + selectobj.val() + "";

        if ($("input[name='proRange_rad']:checked").val() != "0") {
            where += " and attribute" + $("input[name='proRange_rad']:checked").val() + "=1";
        }
        var order = "\"" + $("#proorder2_select").val() + $("#proorder_select").val() + "\"";

        var showCode = "";
        showCode += "<% foreach (System.Data.DataRow item in _getProduct(" + $("#proCount").val() + ",\"" + where + "\"," + order + ").Rows) %>\r";
        showCode += "<% { %>\r";
        showCode += "   <%=item[\"title\"].ToString()%>\r";
        showCode += "   <%=item[\"url\"].ToString()%>\r";
        showCode += "<% } %>\r";



        codeText.text(showCode);
        codeText.next("span").attr("class", "point ico-via Q").html("（产品调用） 获取时间 <span class=R>" + new Date().toLocaleTimeString() + "</span>，已自动复制");
        window.clipboardData.setData("Text", showCode);
        codeText.focus();
        codeText.select();
        return false;
    })
    //下载相关
    $("#downBtn").click(function () {
        var obj = $(this);
        var selectobj = $("#downNaviSelect");
        var codeText = $("#downCode_text");

        var where = "naviid=" + selectobj.val() + "";

        if ($("input[name='downRange_rad']:checked").val() != "0") {
            where += " and attribute" + $("input[name='downRange_rad']:checked").val() + "=1";
        }
        var order = "\"" + $("#downorder2_select").val() + $("#downorder_select").val() + "\"";

        var showCode = "";
        showCode += "<% foreach (System.Data.DataRow item in _getDownload(" + $("#downCount").val() + ",\"" + where + "\"," + order + ").Rows) %>\r";
        showCode += "<% { %>\r";
        showCode += "   <%=item[\"title\"].ToString()%>\r";
        showCode += "   <%=item[\"url\"].ToString()%>\r";
        showCode += "<% } %>\r";



        codeText.text(showCode);
        codeText.next("span").attr("class", "point ico-via Q").html("（下载调用） 获取时间 <span class=R>" + new Date().toLocaleTimeString() + "</span>，已自动复制");
        window.clipboardData.setData("Text", showCode);
        codeText.focus();
        codeText.select();
        return false;
    })
    //视频相关
    $("#videoBtn").click(function () {
        var obj = $(this);
        var selectobj = $("#videoNaviSelect");
        var codeText = $("#videoCode_text");

        var where = "naviid=" + selectobj.val() + "";

        if ($("input[name='videoRange_rad']:checked").val() != "0") {
            where += " and attribute" + $("input[name='videoRange_rad']:checked").val() + "=1";
        }
        var order = "\"" + $("#videoorder2_select").val() + $("#videoorder_select").val() + "\"";

        var showCode = "";
        showCode += "<% foreach (System.Data.DataRow item in _getVideo(" + $("#videoCount").val() + ",\"" + where + "\"," + order + ").Rows) %>\r";
        showCode += "<% { %>\r";
        showCode += "   <%=item[\"title\"].ToString()%>\r";
        showCode += "   <%=item[\"url\"].ToString()%>\r";
        showCode += "<% } %>\r";



        codeText.text(showCode);
        codeText.next("span").attr("class", "point ico-via Q").html("（视频调用） 获取时间 <span class=R>" + new Date().toLocaleTimeString() + "</span>，已自动复制");
        window.clipboardData.setData("Text", showCode);
        codeText.focus();
        codeText.select();
        return false;
    })
})