$(function() {

    $(".lyydatepicker").lyydatepicker({"max_width": "300", });

    //支付按钮
    $('.formbuilder_submitpaybt').click(function() {
        $('#formbuilder_paynowactive').val('true');
        formbuilder_submitform($(this));
        return false;
    });

    //提交按钮
    $('.formbuilder_submitbt').click(function() {
        $('#formbuilder_paynowactive').val('false');
        formbuilder_submitform($(this));
        return false;
    });

    function formbuilder_submitform(buttonself) {
        var submit_act = true;
        //检查必填字段是否填写
        buttonself.parents("form").find('.required').each(function() {
            if ($(this).val() === '') {
                $(this).css({"border": "2px solid #a31022"});
                submit_act = false;
            }
        });
        //提交表单
        if (submit_act === true) {
            var $form = buttonself.parents("form");
            var data = $form.serialize();
            var url = $form.attr('action');

            $.ajax({
                type: "post",
                url: url,
                dataType: "json",
                async: true,
                data: data,
                success: function(json_data) {
                    if (json_data.name == 'go') {
                        window.location.href = json_data.msg;
                    } else {
                        alert(json_data.msg);
                    }
                },
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                    alert(errorThrown);
                }
            });
        }
        return false;
    }


});