function validate_menu_name(form) {
    if ($('select[name="menu_id"]').val() == '') {
        show_alert('Please select Menu name!');
        focus_element = $('select[name="menu_id"]');
        return false;
    }
}

$(document).ready(function() {
    //float_value();
    
    $.validator.addMethod("exist_service_name", function(value, element) {
        var return_val = true;
        var menu_id = $('select[name="menu_id"]').val();
        var service = $('input[name="service_name"]').val();
        var id = $('input[name="hidden_service_id"]').val();
        $.ajax({
            async: false,
            url: base_url + 'service/service_name_exists',
            type: 'POST',
            data: {
                menu_id: menu_id,
                service: service,
                id: id
            },
            dataType: "json"
        })
        .done(function(data) {
            if(data == 1) {
                return_val = false;
            }
        })
        .fail(function(jqXHR, status_code, error_thrown) {
            console.log(jqXHR.responseText);
        });
        
        return return_val;
    });
    
    $('form[name="service_form"]').validate({
        errorElement: "li",
        errorLabelContainer:'.error_container',
        validClass: 'valid',
        focusInvalid: true,
        rules: {
            menu_id: {
                required: true
            },
            service_name: {
                required: true,
                exist_service_name: true,
            }/* ,
            amount: {
                required: true
            } */
        },
        messages: {
            menu_id: {
                required: 'Please select Menu Name!'
            },
            service_name: {
                required: 'Please enter Service Name!',
                exist_service_name: 'Service Name is already exists for this Menu Name!'
            }/* ,
            amount: {
                required: 'Please enter Amount!'
            } */
        }
      });
});

function goBack() {
    window.history.back();
}