$(document).ready(function() {
    
    $.validator.addMethod("already_exist_god_name", function(value, element) {
        var return_val = true;
        var god_name = $('input[name="god_name"]').val();
        var id = $('input[name="hidden_id"]').val();
        $.ajax({
            async: false,
            url: base_url + 'god_name/god_name_exists',
            type: 'POST',
            data: {
                id: id,
                name: god_name
            },
            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="god_name_form"]').validate({
        errorElement: "li",
        errorLabelContainer:'.error_container',
        validClass: 'valid',
        focusInvalid: true,
        rules: {
            god_name: {
                required: true,
                already_exist_god_name: true
            },
            price: {
                required: true
            }
        },
        messages: {
            god_name: {
                required: 'Please enter God Name!',
                already_exist_god_name: 'God Name already exists!'
            },
            price: {
                required: 'Please enter Price!'
            }
        }
      });
});

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