﻿$(document).ready(function() {
    jQuery("#TextArea1").textlimit('#limt', 2000);
    $("#MediaNum").numeric();
    jQuery("#TextArea2").textlimit('#limt1', 2000);
    jQuery("#TextArea3").textlimit('#limt2', 2000);
    //报价计划提交第一步
    $("#MediaStep1").click(function() {
        //表单验证
        //媒体发布篇数
        if ($("#MediaNum").val() == "") {
            $("#vNumber").show();
        }
        //媒体列表和名称验证
        else if (document.getElementById("radioMediaName").checked == false && document.getElementById("radioMediaName1").checked == false) {
            $("#VmediaName").show();
        }
        else if (document.getElementById("Info_MediaContext").checked == false && document.getElementById("Info_MediaContext1").checked == false) {
            $("#VInfo").show();
        }
        //发布开始时间
        else if ($.trim($("#Info_PubDateStart").val()) == "") {
            $("#vstarDate").show();
        }
        //发布结束时间
        else if ($.trim($("#Info_PubDateEnd").val()) == "") {
            $("#vEndDate").show();
        }
        else if (form_Date() == false) {
            $("#vstarDate").show();
        }
        //如果通过 进行下一步
        else {
            //如果勾选媒体列表，判断媒体列表填写否
            if (document.getElementById("radioMediaName").checked) {
                if ($.trim($("#TextArea2").val()) == "") {
                    CenterPopup1();
                    LoadPopup1();
                    alert("请输入媒体名称");
                }
                else {
                    $("#vNumber").hide();
                    $("#vstarDate").hide();
                    $("#vEndDate").hide();
                    $("#VInfo").hide();
                    $("#step1").hide();
                    $("#step2").show();
                }
            }
            //如果勾选媒体描述，判断媒体列表填写否
            if (document.getElementById("radioMediaName1").checked) {
                if ($.trim($("#TextArea3").val()) == "") {
                    CenterPopup2();
                    LoadPopup2();
                    alert("请输入媒体描述");
                }
                else {
                    $("#vNumber").hide();
                    $("#vstarDate").hide();
                    $("#vEndDate").hide();
                    $("#step1").hide();
                    $("#step2").show();
                }
            }

        }
    });

    function form_Date() {
        var StateDate = document.getElementById("Info_PubDateStart");
        var EndDate = document.getElementById("Info_PubDateEnd");
        if (StateDate.value == "" || EndDate.value == "") {
            //StateDate.Focus();
            alert("请选择开始和结束日期");
            return false;
        }
        var arr = StateDate.value.split("-");
        var StateDate = new Date(parseInt(arr[0], 10), parseInt(arr[1], 10) - 1, parseInt(arr[2], 10));

        arr = EndDate.value.split("-");
        var EndDate = new Date(parseInt(arr[0], 10), parseInt(arr[1], 10) - 1, parseInt(arr[2], 10));

        today = new Date();
        var Day = new Date(today.getFullYear(), today.getMonth(), today.getDate() + 7);

        if (StateDate > EndDate) {
            //form_media_select.StateDate.focus();
            alert('起始日期大于结束日期！');
            return false;
        }
        else if (StateDate < Day) {
            //form_media_select.StateDate.focus();
            alert('起始日期应大于当前日期7天以上！');
            return false;
        }
        //	else if NaN(document.form_media_select)

    }

    //媒体咨询报价第二步
    $("#step2Submit").click(function() {
        //验证联系人不能为空
        if ($.trim($("#PRGustPlan_LinkName").val()) == "") {
            $("#VLinkName").show();
        }
        //验证联系人电话不能为空
        else if ($.trim($("#PRGustPlan_LinkPhone").val()) == "") {
            $("#vLinkPhone").show();

        }
        else if ($.trim($("#PRGustPlan_LinkEmail").val()) == "") {
            $("#vLinkEmail").show();
        }

        else {
            var Info_MediaPubType = 0;
            $("#VLinkName").hide();
            $("#vLinkPhone").hide();
            $("#vLinkEmail").hide();
            $("input[name='Info_MediaContext']").each(function() {
                if ($(this).attr('checked')) {
                    Info_MediaPubType = $(this).val()
                }
            });
            $.post("indexTool/InsertInfo.ashx", {
                Info_IndustryType: $("#Info_IndustryType").val(), //行业类型
                MediaNum: $("#MediaNum").val(), //发稿数量
                Info_ArticleContent: $("#TextArea1").val(), //稿件的内容
                Info_MediaContext: $("#TextArea2").val(), //媒体的名称列表
                Info_MediaArera: $("#TextArea3").val(), //媒体的描述内容
                Info_MediaPubType: Info_MediaPubType, //媒体发布类型
                Info_PubDateStart: $("#Info_PubDateStart").val(), //日期开始时间
                Info_PubDateEnd: $("#Info_PubDateEnd").val(), //日期结束时间
                PRGustPlan_LinkName: $("#PRGustPlan_LinkName").val(), //联系人姓名
                PRGustPlan_LinkSex: $("#PRGustPlan_LinkSex").val(), //联系人性别
                PRGustPlan_LinkCompany: $("#PRGustPlan_LinkCompany").val(), //联系人公司
                PRGustPlan_LinkPhone: $("#PRGustPlan_LinkPhone").val(), //联系人的电话
                PRGustPlan_LinkJobs: $("#PRGustPlan_LinkJobs").val(), //联系人的职务
                PRGustPlan_LinkEmail: $("#PRGustPlan_LinkEmail").val()//联系人信箱
            }, function() {

                $("#step2").hide();
                $("#step3").show();
                setTimeout(function() { $("#step3").hide(); $("#step1").show(); $("input[type='text']").val("") }, 60000);
            });
        }
    });

    //媒体报价咨询第二步返回第一步
    $("#step2ToStep1").click(function() {
        $("#step2").hide();
        $("#step1").show();
    });
    ///////////////////////////////////////////////////////////资料索取
    $("#GetInfoStepSubmit").click(function() {
        if ($.trim($("#PRGustPlan_LinkName1").val()) == "") {
            $("#VLinkName1").show();
        }
        else if ($.trim($("#PRGustPlan_LinkPhone1").val()) == "") {
            $("#vLinkPhone1").show();
        }
        else if ($.trim($("#PRGustPlan_LinkEmail1").val()) == "") {
            $("#vLinkEmail1").show();
        }
        else {
            $.post("indexTool/insertGetInfo.ashx", {
                Info_GetInfoName: $("#Info_GetInfoName").val(), //资料名称
                PRGustPlan_LinkName1: $("#PRGustPlan_LinkName1").val(), //联系人姓名
                PRGustPlan_LinkSex1: $("#PRGustPlan_LinkSex1").val(), //联系人性别
                PRGustPlan_LinkCompany1: $("#PRGustPlan_LinkCompany1").val(), //联系人公司
                PRGustPlan_LinkPhone1: $("#PRGustPlan_LinkPhone1").val(), //联系人的电话
                PRGustPlan_LinkJobs1: $("#PRGustPlan_LinkJobs1").val(), //联系人的职务
                PRGustPlan_LinkEmail1: $("#PRGustPlan_LinkEmail1").val()//联系人信箱
            }, function() {
                $("#VLinkName1").hide();
                $("#vLinkPhone1").hide();
                $("#vLinkEmail1").hide();
                $("#GetInfoStep1").hide();
                $("#GetInfoStep2").show();
                setTimeout(function() { $("#GetInfoStep2").hide(); $("#GetInfoStep1").show(); $("input[type='text']").val("") }, 5000);
            });
        }
    });
    ////////////////////////////////////////////////////////////////内容索取
    $("#GetInfoContentSubmit").click(function() {
        if ($.trim($("#Info_FaqContent").val()) == "") {
            $("#vFaqContent").show();
        }
        else if ($.trim($("#PRGustPlan_LinkName2").val()) == "") {
            $("#VLinkName2").show();
        }
        else if ($.trim($("#PRGustPlan_LinkPhone2").val()) == "") {
            $("#vLinkPhone2").show();
        }
        else if ($.trim($("#PRGustPlan_LinkEmail2").val()) == "") {
            $("#vLinkEmail2").show();
        }
        else {
            $.post("indexTool/insertGetContent.ashx", {
                Info_FaqContent: $("#Info_FaqContent").val(), //资料名称
                PRGustPlan_LinkName2: $("#PRGustPlan_LinkName2").val(), //联系人姓名
                PRGustPlan_LinkSex2: $("#PRGustPlan_LinkSex2").val(), //联系人性别
                PRGustPlan_LinkCompany2: $("#PRGustPlan_LinkCompany2").val(), //联系人公司
                PRGustPlan_LinkPhone2: $("#PRGustPlan_LinkPhone2").val(), //联系人的电话
                PRGustPlan_LinkJobs2: $("#PRGustPlan_LinkJobs2").val(), //联系人的职务
                PRGustPlan_LinkEmail2: $("#PRGustPlan_LinkEmail2").val()//联系人信箱
            }, function() {
                $("#vFaqContent").hide();
                $("#VLinkName2").hide();
                $("#vLinkPhone2").hide();
                $("#vLinkEmail2").hide();
                $("#GetInfoContentStep1").hide();
                $("#GetInfoContentStep2").show();
                setTimeout(function() { $("#GetInfoContentStep2").hide(); $("#GetInfoContentStep1").show(); $("input[type='text']").val("") }, 5000);
            });
        }
    });
});