﻿/// <reference path="jquery-1.6.1.min.js" />
var SPAN_LOADING = "<img src='/areas/admin/content/images/admin_img/onload.gif' /><span class='gray'> 请稍候...</span>";
$(function () {


    $(".btnsubmit").button();
    //初始隐藏期刊摘要
    var count = 0;
    for (var i = 0; i <= $("input[id^='Hidden']").length; i++) {
        count = parseInt(count) + parseInt($("input[id^='Hidden']").val());
    }
    for (var i = 0; i < 10000; i++) {
        $("#show" + i).hide();
    }

    //点击展开/切换
    $("img[id^='view']").click(function (id) {
        var vid = this.id.slice(4)
        if ($("#show" + vid).is(":hidden")) {
            $("#show" + vid).show();
        }
        else {
            $("#show" + vid).hide();
        }
    });



    //翻阅期刊
    $("#linkp").click(function () {
        if ($("#linkp").attr("href") == "#") {
            alert("本期已是最早一期");
        }
    });
    $("#linkn").click(function () {
        if ($("#linkn").attr("href") == "#") {
            alert("本期已是最新一期");
        }
    });

    //搜索提醒
    $("#btnSearch").click(function () {
        if ($("#txtKeyword").val() == "") {
            $("#span_tips").html("请输入搜索内容");
            return false;
        } else {
            return true;
        }
    });
    $("#txtKeyword").click(function () {
        $("#span_tips").html("");
    });

    //期限
    $("#select_time").change(function () {
        if ($("#select_time").val() == 0.5) {
            $("#price").html("（3期）36元");
        } else if ($("#select_time").val() == 1) {
            $("#price").html("（6期）72元");
        } else {
            $("#price").html("");
        }
    });

    //其他来源
    $("#selsource").change(function () {
        if ($("#selsource").val() == "other") {
            $("#span_other").html("<input type='text' name='txtemail'  id='txtother'  value=''  maxlength='45'  size='45' />");
        } else {
            $("#span_other").html("");
        }
    });





    //问题建议
    $("#btnq").click(function () {
        var email = $("#txtemail").val();
        var content = $("#textcontent").val();
        if (email == "") {
            alert("请填写您的邮箱");
            return;
        };
        if (content == "") {
            alert("请填写您的问题或建议");
            return;
        };
        $.ajax({
            type: "POST",
            url: "/home/DoProposal",
            data: { "email": email, "content": content },
            success: function (data, type) {
                if (data == 1) {
                    alert("提交成功！");
                    location = "/home";
                } else {
                    alert("您的提交未成功");
                }
            }
        });

    });


    //新闻共享
    $("#btnshare").click(function () {
        var title = $("#txttitle").val();
        var source = $("#selsource").val();
        var url = $("#txturl").val();
        var email = $("#txtemail").val();
        var author = $("#txteauthor").val();
        var unit = $("#txtunit").val();
        var linkurl = $("#linkurl").val();
        var content = editor.html();
        if (title == "" || url == "" || email == "" || author == "" || unit == "" || content == "") {
            alert("请填写完整的新闻信息");
            return;
        };
        var other = "";
        if (source == "other") {
            other = $("#txtother").val();
        }
        $.ajax({
            type: "POST",
            url: "/article/DoShare",
            data: { "title": title, "source": source, "other": other, "url": url, "email": email, "author": author, "unit": unit, "linkurl": linkurl, "content": content },
            success: function (data, type) {
                if (data == 1) {
                    alert("提交成功！");
                    location = "/home";
                } else {
                    alert("您的提交未成功");
                }
            }
        });

    });

    //邮件订阅
    $("#submit1").click(function () {
        var realname = $("#realname").val();
        var phone = $("#txtphone").val();
        var address = $("#txtaddress").val();
        var postcode = $("#txtpostcode").val();
        // var issuecode = $("#txtissuecode").val();
        var select_time = $("#select_time").val();
        if (realname == "" || phone == "" || address == "" || postcode == "" || select_time == 0) {

            return false;
        }
        $.ajax({
            type: "POST",
            url: "/Message/Subscription",
            data: { "realname": realname, "phone": phone, "address": address, "postcode": postcode, "timelimit": select_time, "type": "0" },
            success: function (data, type) {
                if (data == 1) {
                    alert("订阅成功！");
                } else {
                    alert("您的账号或密码错误");
                }
            }
        });
    });
    $("#dosubmit").click(function () {
        var email = $("#txtemail").val();
        if (email == "") {
            alert("请输入邮箱")
            return;
        }
        $.ajax({
            type: "POST",
            url: "/Message/Subscription",
            data: { "email": email, "type": "1" },
            success: function (data, type) {
                if (data == 1) {
                    alert("订阅成功！");
                } else {
                    alert("您的账号或密码错误");
                }
            }
        });
    });

    //找回密码弹出层
    $("#findpwd").click(function () {
        $("#dialog_findpwd").dialog({
            modal: true,
            title: "<img src='/areas/admin/content/images/icon/icon_padlock.gif'>找回密码",
            buttons: {
                关闭: function () {

                    $("#dialog_findpwd").dialog('destroy');
                },
                找回密码: function () {
                    var email = $("#find_email").val();
                    if (email != "") {

                        $("#find_message").html(SPAN_LOADING);
                        $.get("/member/findpwd?email=" + email + "&n=" + (new Date().toString()), function (data) {
                            if (data == "1") {
                                $("#find_message").html("<span class='icon_dui'>新密码已经发送至您的邮箱,请注意查收</span>");
                                //$(".ui-button-text").hide();
                            } else {
                                $("#find_message").html("<span class='icon_cuo'>" + data + "</span>");
                                $("#find_email").focus();
                            }
                        });
                    } else {
                        $("#find_message").html("<span class='icon_gh'>(请输入)</span>");
                        $("#find_email").focus();
                    }
                }
            },
            show: 'scale',
            width: 350,
            height: 160
        });
    });

});
/*修改密码*/
function change_pwd() {
    var html_changepwd = "";
    $.get("/html/changepwd.htm", function (data) {
        window.top.art.dialog({ id: 'dialog_change_pwd', content: data, lock: true, width: '350', height: '200' }, function () {
            if ($("#change_password1").val() == "") {
                $("#changepwd_message").addClass("icon_gh").html("请输入旧密码");
                return false;
            }
            if ($("#change_password2").val() == "") {
                $("#changepwd_message").addClass("icon_gh").html("请输入新密码");
                return false;
            }
            if ($("#change_password3").val() == "") {
                $("#changepwd_message").addClass("icon_gh").html("请输入确认密码");
                return false;
            }
            if ($("#change_password3").val() != $("#change_password2").val()) {
                $("#changepwd_message").addClass("icon_gh").html("两次密码输入不匹配");
                return false;
            }
            $("#changepwd_message").html("正在验证,请稍候...");
            $.post($("form[name='changepwd_form']").attr("action"), $("form[name='changepwd_form']").serialize(), function (data2) {
                if (data2 == "1") {
                    $("#changepwd_message").removeClass("icon_gh");
                    $("#changepwd_message").addClass("icon_dui").html("密码更新成功");
                    setTimeout("closeDialog('dialog_change_pwd')", 2000);
                } else {
                    $("#changepwd_message").addClass("icon_gh").html("原密码错误");
                }
            });
            return false;
        }, function () {
        });
    });
}
