// Chained - jQuery non AJAX(J) chained selects plugin
$(function() {
    // Setup form validation on the #user_setup_form element
    $("#user_setup_form").validate({
        // Specify the validation rules user_setup_form add and update forms 
        rules: {
            name: {
                required: true,
                noSpace: true
            },
            password: {
                required: true,
                noSpace: true
            },
            email: {
                required:true,
                email: true
            },
            type: {
                required: true
            },
            profile: {
                required: true
            },
            role: {
                required: true
            }
        },
        // Specify the validation error messages
        messages: {
            name: {
                required: "<span class='label label-warning val_mes'>Please select a name </span>",
                noSpace: "<span class='label label-warning val_mes'>Spaces not allowed </span>"
            },
            password: {
                required: "<span class='label label-warning val_mes'>Please enter a password </span>",
                noSpace:  "<span class='label label-warning val_mes'>Spaces not allowed </span>"
            },
            email: {
                required: "<span class='label label-warning val_mes'>Please enter an  email  </span>",
                email: "<span class='label label-warning val_mes'>Please enter a  valid email  </span>"
            },
            type: "<span class='label label-warning val_mes'>Please select a type </span>",
            profile: "<span class='label label-warning val_mes'>Please select a profile </span>",
            role: "<span class='label label-warning val_mes'>Please select a role </span>"

        },
        errorElement : 'div',
        errorPlacement: function(error, element) {
            var placement = $(element).data('error');
            if (placement) {
                $(placement).append(error)
            } else {
                error.insertAfter(element);
            }
        },
        submitHandler: function(form) {
            form.submit();
        }
    });
});

jQuery.validator.addMethod("noSpace", function(value, element) {
    return value.indexOf(" ") < 0 && value != "";
}, "No space please and don't leave it empty");

// Chained - jQuery non AJAX(J) chained selects plugin
$(function() {
    // Setup form validation on the #product_controller_setup_form element
    $("#product_controller_setup_form").validate({
        // Specify the validation rules product_controller_setup_form add and update forms 
        rules: {
            pro_id: {
                required: true
            },
            apply: {
                required: true
            },
            value1: {
                required: true,
                maxlength:11,
                number: true
            },
            value_2: {
                required: false,
                maxlength: 11,
                number: true
            },
            value1age: {
                required: true,
                maxlength:11,
                number: true
            },
            value_2age: {
                required: true,
                maxlength: 11,
                number: true
            }
        },
        // Specify the validation error messages
        messages: {
            pro_id: "<span class='label label-warning val_mes'>Please select a product name </span>",
            apply:  "<span class='label label-warning val_mes'>Please select an apply on </span>",
            value1: {
                required:  "<span class='label label-warning val_mes'>Please enter a value </span>",
                maxlength:  "<span class='label label-warning val_mes'>Please enter a value </span>",
                number:  "<span class='label label-warning val_mes'>Please enter a value in digits</span>"
            },
            value_2: {
                maxlength:  "<span class='label label-warning val_mes'>Please enter a value </span>",
                number:  "<span class='label label-warning val_mes'>Please enter a value in digits</span>"
            },
            value1age: {
                required:  "<span class='label label-warning val_mes'>Please enter a value </span>",
                maxlength:  "<span class='label label-warning val_mes'>Please enter a value </span>",
                number:  "<span class='label label-warning val_mes'>Please enter a value in digits</span>"
            },
            value_2age: {
                required:  "<span class='label label-warning val_mes'>Please enter a value </span>",
                maxlength:  "<span class='label label-warning val_mes'>Please enter a value </span>",
                number:  "<span class='label label-warning val_mes'>Please enter a value in digits</span>"
            }
        },
        errorElement : 'div',
        errorPlacement: function(error, element) {
            var placement = $(element).data('error');
            if (placement) {
                $(placement).append(error)
            } else {
                error.insertAfter(element);
            }
        },
        submitHandler: function(form) {
            form.submit();
        }
    });
});



// Chained - jQuery non AJAX(J) chained selects plugin
$(function() {
    // Setup form validation on the #client_setup_form element
    $("#client_setup_form").validate({
        // Specify the validation rules client_setup_form add and update forms 
        rules: {
            client_name: {
                required: true
            },
            client_code : {
                required: true,
                minlength: 17
            },
            client_address: {
                required: true
            },
            client_telephone: {
                required: true
            },
            contact_person: {
                required: true
            },
            'branch[]': {
                required: true
            }
        },
        // Specify the validation error messages
        messages: {
            client_name: "<span class='label label-warning val_mes'>Please enter your name</span>",
            client_code: {
                required: "<span class='label label-warning val_mes'>Please enter your code</span>",
                minlength: "<span class='label label-warning val_mes'>Your code must be equal to 17 characters</span>"
            },
            client_address: "<span class='label label-warning val_mes'>Please enter your address</span>",
            client_telephone: "<span class='label label-warning val_mes'>Please enter telephone number</span>",
            contact_person: "<span class='label label-warning val_mes'>Please enter a contact person</span>",
            'branch[]': "<span class='label label-warning val_mes check_box'>Please check on any branch </span>"
        },
        errorElement : 'div',
        errorPlacement: function(error, element) {
            var placement = $(element).data('error');
            if (placement) {
                $(placement).append(error)
            } else {
                error.insertAfter(element);
            }
        },
        submitHandler: function(form) {
            form.submit();
        }
    });
});
// When the browser is ready...
$(function() {
    // Setup form validation on the #branch_setup_form element
    $("#branch_setup_form").validate({
        // Specify the validation rules for branch setup form . add and update forms 
        rules: {
            b_name: {
                required: true
            },
            b_code: {
                required: true,
                minlength: 8,
                maxlength:8
            },
            z_code: {
                required: true,
                minlength: 4,
                maxlength:4
            },
            b_address: {
                required: true
            },
            b_tele: {
                required: true
                //number: true
            },
            email: {
                required: true,
                email: true
            },
            ref_no: {
                required: true,
                number: true
            },
            location:{
                required: true

            },
            auth_limit:{
                required: true,
                number: true
            }
            //services_sales_tax: {
            //    required: true,
            //    number: true
            //},
            //FIF:  {
            //    required: true,
            //    number: true
            //},
            //stamp_duty:  {
            //    required: true,
            //    number: true
            //}
        },
        // Specify the validation error messages
        messages: {
            b_name: {
                required: "<span class='label label-warning val_mes'>Please enter branch name</span>"
            },
            b_code: {
                required: "<span class='label label-warning val_mes'>Please enter branch code</span>",
                minlength: "<span class='label label-warning val_mes'>Branch code must be 8 characters</span>",
                maxlength: "<span class='label label-warning val_mes'>Branch code must be 8 characters</span>",
            },
            z_code: {
                required: "<span class='label label-warning val_mes'>Please enter zip code</span>",
                minlength: "<span class='label label-warning val_mes'>Branch zip code must be 4 characters</span>",
                maxlength: "<span class='label label-warning val_mes'>Branch zip code must be 4 characters</span>",
            },
            b_address:  "<span class='label label-warning val_mes'>Please enter branch address</span>",
            b_tele: {
                required: "<span class='label label-warning val_mes'>Please enter branch telephone number</span>",
            },
            email: "<span class='label label-warning val_mes'>Please enter a valid email address</span>",
            ref_no: {
                required: "<span class='label label-warning val_mes'>Please enter a reference number</span>",
                number: "<span class='label label-warning val_mes'>Please enter number</span>"
            },
            auth_limit: {
                required: "<span class='label label-warning val_mes'>Please enter a authorization limit</span>",
                number: "<span class='label label-warning val_mes'>Please enter number</span>"
            },
            location: {
                required: "<span class='label label-warning val_mes'>Please enter a location</span>"

            }
            //services_sales_tax: {
            //    required: "<span class='label label-warning val_mes'>Please enter Sales Tax on Services </span>",
            //    number: "<span class='label label-warning val_mes'>Please enter number</span>"
            //    },
            //FIF:{
            //    required:  "<span class='label label-warning val_mes'>Please enter Federal Insurance Fee </span>",
            //    number: "<span class='label label-warning val_mes'>Please enter number</span>"
            //    },
            //stamp_duty: {
            //    required: "<span class='label label-warning val_mes'>Please enter stamp duty</span>",
            //    number: "<span class='label label-warning val_mes'>Please enter number</span>"
            //    }
        },
        errorElement : 'div',
        errorPlacement: function(error, element) {
            var placement = $(element).data('error');
            if (placement) {
                $(placement).append(error)
            } else {
                error.insertAfter(element);
            }
        },
        submitHandler: function(form) {
            form.submit();
        }
    });
});

// Chained - jQuery non AJAX(J) chained selects plugin
$(function() {
    // Setup form validation on the #co_setup_form element
    $("#co_setup_form").validate({
        // Specify the validation rules for development officers setup . add and update forms
        rules: {
            c_name: {
                required: true
            },
            c_code : {
                required: true,
                number: true
            },
            b_code: {
                required: true
            },
            ref_no: {
                required: true,
                minlength: 7,
                maxlength:7
            } ,
            'branch_id[]':{
                require_from_group: [1, ".branch_id"]
            },

            'settlelimit[]':{
                require_from_group: [1, ".settlelimit"],
                number: true
                //    max: true
            },
            location: {

                required: true
            }
        },
        // Specify the validation error messages
        messages: {
            c_name: "<span class='label label-warning val_mes'>Please enter claim officer name </span>",
            c_code: "<span class='label label-warning val_mes'>Please enter claim officer code</span>",
            b_code: "<span class='label label-warning val_mes'>Please select a branch </span>",
            location: "<span class='label label-warning val_mes'>Please enter a location </span>",
            'branch_id[]': "<span class='label label-warning val_mes'>Please select at least one branch </span>",
            'settlelimit[]':{
                required: "<span class='label label-warning val_mes'>Please enter settlement limit </span>"
                //    max:"<span class='label label-warning val_mes'>Branch authorized limit exceeded. </span>"
            },
            ref_no: {
                required: "<span class='label label-warning val_mes'>Please enter a reference number</span>",
                minlength:"<span class='label label-warning val_mes'>Your reference number must be 7 characters </span>",
                maxlength: "<span class='label label-warning val_mes'>Your reference number must be 7 characters </span>"
            }
        },
        errorElement : 'div',
        errorPlacement: function(error, element) {
            var placement = $(element).data('error');
            if (placement) {
                $(placement).append(error)
            } else {
                error.insertAfter(element);
            }
        },
        submitHandler: function(form) {
            form.submit();
        }
    });
});

// Chained - jQuery non AJAX(J) chained selects plugin
$(function() {
    // Setup form validation on the #do_setup_form element
    $("#renewal_decline_setup_form").validate({
        // Specify the validation rules for development officers setup . add and update forms 
        rules: {
            field_name: {
                required: true
            },
            field_value : {
                required: false
            }
        },
        // Specify the validation error messages
        messages: {
            field_name: "<span class='label label-warning val_mes'>Please select field name</span>",
            field_value: "<span class='label label-warning val_mes'>Please enter field value</span>"
        },
        errorElement : 'div',
        errorPlacement: function(error, element) {
            var placement = $(element).data('error');
            if (placement) {
                $(placement).append(error)
            } else {
                error.insertAfter(element);
            }
        },
        submitHandler: function(form) {
            form.submit();
        }
    });
});

// Chained - jQuery non AJAX(J) chained selects plugin
$(function() {
    // Setup form validation on the #register-form element
    $("#agent_setup_form").validate({
        // Specify the validation rules for agent setup . add and update forms 
        rules: {
            a_name: {
                required: true
            },
            d_code : {
                required: true
            },
            a_code: {
                required: false
            },
            ref_no: {
                required: true,
                minlength: 11,
                maxlength:11
            }
        },
        // Specify the validation error messages
        messages: {
            a_name: "<span class='label label-warning val_mes'>Please enter agent name </span>",
            d_code: "<span class='label label-warning val_mes'>Please select a development officer code</span>",
            a_code: "<span class='label label-warning val_mes'>Please select a development officer </span>",
            ref_no: {
                required: "<span class='label label-warning val_mes'>Please enter a iGIS Agency Code </span>",
                minlength:"<span class='label label-warning val_mes'>Your iGIS Agency Code must be 11 characters </span>",
                maxlength: "<span class='label label-warning val_mes'>Your iGIS Agency Code must be 11 characters </span>"
            }
        },
        errorElement : 'div',
        errorPlacement: function(error, element) {
            var placement = $(element).data('error');
            if (placement) {
                $(placement).append(error)
            } else {
                error.insertAfter(element);
            }
        },
        submitHandler: function(form) {
            form.submit();
        }
    });
});

// Chained - jQuery non AJAX(J) chained selects plugin
$(function() {
    // Setup form validation on the #product_setup_formelement
    $("#product_setup_form").validate({
        // Specify the validation rules for product setup . add and update forms 
        rules: {
            name: {
                required: true
            },
            weight: {
                required: true
            },
            unit:
            {
                required: true
            }
        },
        // Specify the validation error messages
        messages: {
            name: "<span class='label label-warning val_mes'>Please enter product name </span>",
            weight:"<span class='label label-warning val_mes'>Please enter weight</span>",
            unit:"<span class='label label-warning val_mes'>Please select unit </span>"
        },
        errorElement : 'div',
        errorPlacement: function(error, element) {
            var placement = $(element).data('error');
            if (placement) {
                $(placement).append(error)
            } else {
                error.insertAfter(element);
            }
        },
        submitHandler: function(form) {
            form.submit();
        }
    });

});

// Chained - jQuery non AJAX(J) chained selects plugin
$(function() {
    // Setup form validation on the #conditions_setup_formelement
    $("#condition_setup_form").validate({
        // Specify the validation rules for condition setup . add and update forms 
        rules: {
            p_name: {
                required: true
            },
            p_code : {
                required: false
            },
            c_code: {
                required: true
            },
            c_desc: {
                required:true
            }
        },
        // Specify the validation error messages
        messages: {
            p_name: "<span class='label label-warning val_mes'>Please enter pseudo name </span>",
            p_code:"<span class='label label-warning val_mes'>Please select a product code</span>",
            c_code:"<span class='label label-warning val_mes'>Please enter a condition code  </span>",
            c_desc:"<span class='label label-warning val_mes'>Please enter condition description </span>"
        },
        errorElement : 'div',
        errorPlacement: function(error, element) {
            var placement = $(element).data('error');
            if (placement) {
                $(placement).append(error)
            } else {
                error.insertAfter(element);
            }
        },
        submitHandler: function(form) {
            form.submit();
        }
    });
});

// Chained - jQuery non AJAX(J) chained selects plugin
$(function() {
    // Setup form validation on the #sub_make_setup_form element
    $("#sub_make_setup_form").validate({
        // Specify the validation rules sub_make_setup_form add and update forms 
        rules: {
            sub_make_name: {
                required: true
            },
            seating_capacity: {
                required: true
            },
            cubic_capacity: {
                required: true
            },
            make_id: {
                required: true
            },
            igis_sub_code: {
                required: true
            },
            coi_code: {
                required: true
            }
        },
        // Specify the validation error messages
        messages: {
            sub_make_name: "<span class='label label-warning val_mes'>Please enter a name </span>",
            seating_capacity: "<span class='label label-warning val_mes'>Please enter seating capacity </span>",
            cubic_capacity: "<span class='label label-warning val_mes'>Please enter seating capacity </span>",
            make_id: "<span class='label label-warning val_mes'>Please select a make name </span>",
            igis_sub_code: "<span class='label label-warning val_mes'>Please select iGIS code </span>",
            coi_code: "<span class='label label-warning val_mes'>Please select C.O.I type code </span>"

        },
        errorElement : 'div',
        errorPlacement: function(error, element) {
            var placement = $(element).data('error');
            if (placement) {
                $(placement).append(error)
            } else {
                error.insertAfter(element);
            }
        },
        submitHandler: function(form) {
            form.submit();
        }
    });
});


// Chained - jQuery non AJAX(J) chained selects plugin
$(function() {
    // Setup form validation on the #color_setup_form element
    $("#color_setup_form").validate({
        // Specify the validation rules color_setup_form add and update forms 
        rules: {
            color_name: {
                required: true
            },
            igis_color: {
                required: true
            }
        },
        // Specify the validation error messages
        messages: {
            color_name: "<span class='label label-warning val_mes'>Please enter a color name </span>",
            igis_color: "<span class='label label-warning val_mes'>Please enter a iGIS code </span>"
        },
        errorElement : 'div',
        errorPlacement: function(error, element) {
            var placement = $(element).data('error');
            if (placement) {
                $(placement).append(error)
            } else {
                error.insertAfter(element);
            }
        },
        submitHandler: function(form) {
            form.submit();
        }
    });
});




// Chained - jQuery non AJAX(J) chained selects plugin
$(function() {
    // Setup form validation on the #conditions_setup_formelement
    $("#warranties_setup_form").validate({
        // Specify the validation rules for condition setup . add and update forms 
        rules: {
            p_name: {
                required: true
            },
            p_code : {
                required: false
            },
            w_code: {
                required: true
            },
            w_desc: {
                required:true
            }
        },
        // Specify the validation error messages
        messages: {
            p_name: "<span class='label label-warning val_mes'>Please enter pseudo name </span>",
            p_code:"<span class='label label-warning val_mes'>Please select a product code</span>",
            w_code:"<span class='label label-warning val_mes'>Please enter a wararnty code  </span>",
            w_desc:"<span class='label label-warning val_mes'>Please enter wararnty description </span>"
        },
        errorElement : 'div',
        errorPlacement: function(error, element) {
            var placement = $(element).data('error');
            if (placement) {
                $(placement).append(error)
            } else {
                error.insertAfter(element);
            }
        },
        submitHandler: function(form) {
            form.submit();
        }
    });
});


// Chained - jQuery non AJAX(J) chained selects plugin
$(function() {
    // Setup form validation on the #user_profile_setup_form element
    $("#user_profile_setup_form").validate({
        // Specify the validation rules user_profile_setup_form add and update forms 
        rules: {
            p_name: {
                required: true
            },
            'product[]': {
                required: true
            },
            'branch[]': {
                required: true
            },
            'do[]': {
                required: true
            },
            'agent[]': {
                required:true
            },
            'client[]': {
                required:true
            },
            'payment[]': {
                required:true
            }
        },
        // Specify the validation error messages
        messages: {
            p_name: "<span class='label label-warning val_mes'>Please enter your name</span>",
            'product[]':  "<span class='label label-warning val_mes '>Please select any product </span>",
            'branch[]' :"<span class='label label-warning val_mes '>Please select any branch </span>",
            'do[]':"<span class='label label-warning val_mes '>Please select any DO </span>",
            'agent[]': "<span class='label label-warning val_mes '>Please select any agent </span>",
            'client[]': "<span class='label label-warning val_mes '>Please select any client </span>",
            'payment[]': "<span class='label label-warning val_mes '>Please select any payment mode </span>"


        },
        errorElement : 'div',
        errorPlacement: function(error, element) {
            var placement = $(element).data('error');
            if (placement) {
                $(placement).append(error)
            } else {
                error.insertAfter(element);
            }
        },
        errorContainer: $('#errorContainer'),
        errorLabelContainer: $('#errorContainer ul'),
        wrapper: 'li',
        submitHandler: function(form) {
            form.submit();
        }
    });
});

// Chained - jQuery non AJAX(J) chained selects plugin
$(function() {
    // Setup form validation on the #make_setup_form element
    $("#make_form").validate({
        // Specify the validation rules make_setup_form add and update forms 
        rules: {
            igis_code: {
                required: true
            },
            make_name: {
                required: true
            }
        },
        // Specify the validation error messages
        messages: {
            make_name: "<span class='label label-warning val_mes'>Please enter a name </span>",
            igis_code: "<span class='label label-warning val_mes'>Please enter iGIS code </span>"
        },
        errorElement : 'div',
        errorPlacement: function(error, element) {
            var placement = $(element).data('error');
            if (placement) {
                $(placement).append(error)
            } else {
                error.insertAfter(element);
            }
        },
        submitHandler: function(form) {
            form.submit();
        }
    });
});

// Chained - jQuery non AJAX(J) chained selects plugin
$(function() {
    // Setup form validation on the #customer_workflow_form element
    $("#customer_workflow_form").validate({
        // Specify the validation rules customer_workflow_form add and update forms
        rules: {
            name: {
                required: true
            }
        },
        // Specify the validation error messages
        messages: {
            name: "<span class='label label-warning val_mes'>Please enter customer workflow name</span>"
            //igis_code: "<span class='label label-warning val_mes'>Please enter iGIS code </span>"
        },
        errorElement : 'div',
        errorPlacement: function(error, element) {
            var placement = $(element).data('error');
            if (placement) {
                $(placement).append(error)
            } else {
                error.insertAfter(element);
            }
        },
        submitHandler: function(form) {
            form.submit();
        }
    });
});

// Chained - jQuery non AJAX(J) chained selects plugin
$(function() {
    // Setup form validation on the #customer_claimtype_form element
    $("#customer_claimtype_form").validate({
        // Specify the validation rules customer_workflow_form add and update forms
        rules: {
            name: {
                required: true
            },
            customer_workflow_id: {
                required: true
            }
        },
        // Specify the validation error messages
        messages: {
            name: "<span class='label label-warning val_mes'>Please enter customer claim type name</span>",
            customer_workflow_id: "<span class='label label-warning val_mes'>Please select workflow</span>"
        },
        errorElement : 'div',
        errorPlacement: function(error, element) {
            var placement = $(element).data('error');
            if (placement) {
                $(placement).append(error)
            } else {
                error.insertAfter(element);
            }
        },
        submitHandler: function(form) {
            form.submit();
        }
    });
});

// Chained - jQuery non AJAX(J) chained selects plugin
$(function() {
    // Setup form validation on the #survey_workflow_form element
    $("#survey_workflow_form").validate({
        // Specify the validation rules survey_workflow_form add and update forms
        rules: {
            name: {
                required: true
            }
        },
        // Specify the validation error messages
        messages: {
            name: "<span class='label label-warning val_mes'>Please enter survey workflow name</span>"
            //igis_code: "<span class='label label-warning val_mes'>Please enter iGIS code </span>"
        },
        errorElement : 'div',
        errorPlacement: function(error, element) {
            var placement = $(element).data('error');
            if (placement) {
                $(placement).append(error)
            } else {
                error.insertAfter(element);
            }
        },
        submitHandler: function(form) {
            form.submit();
        }
    });
});

// Chained - jQuery non AJAX(J) chained selects plugin
$(function() {
    // Setup form validation on the #survey_claimtype_form element
    $("#survey_claimtype_form").validate({
        // Specify the validation rules survey_workflow_form add and update forms
        rules: {
            name: {
                required: true
            },
            survey_workflow_id: {
                required: true
            }
        },
        // Specify the validation error messages
        messages: {
            name: "<span class='label label-warning val_mes'>Please enter survey claim type name</span>",
            survey_workflow_id: "<span class='label label-warning val_mes'>Please select workflow</span>"
        },
        errorElement : 'div',
        errorPlacement: function(error, element) {
            var placement = $(element).data('error');
            if (placement) {
                $(placement).append(error)
            } else {
                error.insertAfter(element);
            }
        },
        submitHandler: function(form) {
            form.submit();
        }
    });
});

// Chained - jQuery non AJAX(J) chained selects plugin
$(function() {
    // Setup form validation on the #notification_form element
    $("#notification_form").validate({
        // Specify the validation rules notification_form add and update forms 
        rules: {
            description: {
                required: true
            }
        },
        // Specify the validation error messages
        messages: {
            description: "<span class='label label-warning val_mes'>Please enter description </span>"
        },
        errorElement : 'div',
        errorPlacement: function(error, element) {
            var placement = $(element).data('error');
            if (placement) {
                $(placement).append(error)
            } else {
                error.insertAfter(element);
            }
        },
        submitHandler: function(form) {
            form.submit();
        }
    });
});

// Chained - jQuery non AJAX(J) chained selects plugin
$(function() {
    // Setup form validation on the #notification_form element
    $("#sms_config_form").validate({
        // Specify the validation rules notification_form add and update forms 
        rules: {
            customer_submission: {
                required: true
            },
            settlement: {
                required: true
            },
            surveyor_assigned: {
                required: true
            },
            reinspection: {
                required: true
            },
            surveyor_notification: {
                required: true
            }
        },
        // Specify the validation error messages
        messages: {
            customer_submission: "<span class='label label-warning val_mes'>Please enter customer submission text </span>",
            settlement: "<span class='label label-warning val_mes'>Please enter settlement text </span>",
            surveyor_assigned: "<span class='label label-warning val_mes'>Please enter surveyor assigned text </span>",
            reinspection: "<span class='label label-warning val_mes'>Please enter re-inspection text </span>",
            surveyor_notification: "<span class='label label-warning val_mes'>Please enter surveyor notification text </span>"
        },
        errorElement : 'div',
        errorPlacement: function(error, element) {
            var placement = $(element).data('error');
            if (placement) {
                $(placement).append(error)
            } else {
                error.insertAfter(element);
            }
        },
        submitHandler: function(form) {
            form.submit();
        }
    });
});


//policy cancellation
$(function() {
    // Setup form validation on the #notification_form element
    $("#order_cancel_form").validate({
        // Specify the validation rules notification_form add and update forms
        rules: {
            policy_cancel: {
                required: true
            },
            order_cancel_date: {
                required: true
            },
            order_cancel_comment: {
                required: true
            }
        },
        // Specify the validation error messages
        messages: {
            policy_cancel: "<span class='label label-warning val_mes'>Select Cancel Policy</span>",
            order_cancel_date: "<span class='label label-warning val_mes'>Select Policy Cancel Date </span>",
            order_cancel_comment: "<span class='label label-warning val_mes'>Please enter Comment </span>"
        },
        errorElement : 'div',
        errorPlacement: function(error, element) {
            var placement = $(element).data('error');
            if (placement) {
                $(placement).append(error)
            } else {
                error.insertAfter(element);
            }
        },
        submitHandler: function (form) {
            $("#saveModal").modal('show');
            $('#SubForm').click(function () {
                form.submit();
            });
        }

    });
});

// Chained - jQuery non AJAX(J) chained selects plugin
$(function() {
    // Setup form validation on the #color_setup_form element
    $("#workshop_setup_form").validate({
        // Specify the validation rules color_setup_form add and update forms
        rules: {
            name: {
                required: true
            },
            code: {
                required: true
            },
            location: {
                required: true
            },
            city: {
                required: true
            },
            contactno: {
                required: true
            },
            auth_limit: {
                required: true
            }
        },
        // Specify the validation error messages
        messages: {
            name: "<span class='label label-warning val_mes'>Please enter workshop name </span>",
            code: "<span class='label label-warning val_mes'>Please enter iGIS code </span>",
            location: "<span class='label label-warning val_mes'>Please enter a location </span>",
            city: "<span class='label label-warning val_mes'>Please select a city</span>",
            contactno: "<span class='label label-warning val_mes'>Please enter a contact no </span>",
            auth_limit: "<span class='label label-warning val_mes'>Please enter a authorization limit </span>"
        },
        errorElement : 'div',
        errorPlacement: function(error, element) {
            var placement = $(element).data('error');
            if (placement) {
                $(placement).append(error)
            } else {
                error.insertAfter(element);
            }
        },
        submitHandler: function(form) {
            form.submit();
        }
    });
});

// Chained - jQuery non AJAX(J) chained selects plugin
$(function() {
    // Setup form validation on the #city_setup_form element
    $("#city_setup_form").validate({
        // Specify the validation rules city_setup_form add and update forms
        rules: {
            name: {
                required: true
            },
            code: {
                required: true
            }
        },
        // Specify the validation error messages
        messages: {
            name: "<span class='label label-warning val_mes'>Please enter city name </span>",
            code: "<span class='label label-warning val_mes'>Please enter iGIS code </span>"
        },
        errorElement : 'div',
        errorPlacement: function(error, element) {
            var placement = $(element).data('error');
            if (placement) {
                $(placement).append(error)
            } else {
                error.insertAfter(element);
            }
        },
        submitHandler: function(form) {
            form.submit();
        }
    });
});

// Chained - jQuery non AJAX(J) chained selects plugin
$(function() {
    // Setup form validation on the #co_setup_form element
    $("#so_setup_form").validate({
        // Specify the validation rules for development officers setup . add and update forms
        rules: {
            name: {
                required: true
            },
            code : {
                required: true,
                number: true
            },
            'address':{
                required: true
            },
            'contactno':{
                required: true,
                number: true
            },
            'cnic':{
                required: true
            },
            'license_date':{
                required: true
            },
            'branch_id[]':{
                require_from_group: [1, ".branch_id"]
            },

            'settlelimit[]':{
                require_from_group: [1, ".settlelimit"],
                number: true
                //    max: true
            },
            'workshop_id':{
                required: true
            },
            'city_id':{
                required: true
            },

            location: {

                required: true
            }
        },
        // Specify the validation error messages
        messages: {
            name: "<span class='label label-warning val_mes'>Please enter surveyor name </span>",
            code: "<span class='label label-warning val_mes'>Please enter IGIS code</span>",
            address: "<span class='label label-warning val_mes'>Please enter address </span>",
            cnic: "<span class='label label-warning val_mes'>Please enter cnic </span>",
            license_date: "<span class='label label-warning val_mes'>Please select a license date </span>",
            workshop_id: "<span class='label label-warning val_mes'>Please select a workshop </span>",
            city_id: "<span class='label label-warning val_mes'>Please select a city </span>",
            contactno: "<span class='label label-warning val_mes'>Please enter  cell # </span>",
            location: "<span class='label label-warning val_mes'>Please enter a location </span>",
            'branch_id[]': "<span class='label label-warning val_mes'>Please select at least one branch </span>",
            'settlelimit[]':{
                required:  "<span class='label label-warning val_mes'>Please enter settlement limit </span>"
                //    max:"<span class='label label-warning val_mes'>Branch authorized limit exceeded. </span>"
            },
            ref_no: {
                required: "<span class='label label-warning val_mes'>Please enter a reference number</span>",
                minlength:"<span class='label label-warning val_mes'>Your reference number must be 7 characters </span>",
                maxlength: "<span class='label label-warning val_mes'>Your reference number must be 7 characters </span>"
            }
        },
        errorElement : 'div',
        errorPlacement: function(error, element) {
            var placement = $(element).data('error');
            if (placement) {
                $(placement).append(error)
            } else {
                error.insertAfter(element);
            }
        },
        submitHandler: function(form) {
            form.submit();
        }
    });
});

// Chained - jQuery non AJAX(J) chained selects plugin
$(function() {
    // Setup form validation on the #login_form element
    $("#login_form").validate({
        // Specify the validation rules for development officers setup . add and update forms
        rules: {
            uname: {
                required: true
            },
            pwd: {
                required: true
            }

        },
        // Specify the validation error messages
        messages: {
            uname: "<span class='label label-warning val_mes'>Please enter username </span>",
            pwd: "<span class='label label-warning val_mes'>Please enter password</span>"

        },
        errorElement : 'div',
        errorPlacement: function(error, element) {
            var placement = $(element).data('error');
            if (placement) {
                $(placement).append(error)
            } else {
                error.insertAfter(element);
            }
        },
        submitHandler: function (form) {
            form.submit();
        }
    });
});

$(function() {
    // Setup form validation on the #login_form element
    $("#bank_setup_form").validate({
        // Specify the validation rules for development officers setup . add and update forms
        rules: {
            name: {
                required: true
            },
            bank_account_number: {
                required: true
            }

        },
        // Specify the validation error messages
        messages: {
            name: "<span class='label label-warning val_mes'>Please enter Bank Name </span>",
            bank_account_number: "<span class='label label-warning val_mes'>Please enter Bank Account Number</span>"

        },
        errorElement : 'div',
        errorPlacement: function(error, element) {
            var placement = $(element).data('error');
            if (placement) {
                $(placement).append(error)
            } else {
                error.insertAfter(element);
            }
        },
        submitHandler: function (form) {
            form.submit();
        }
    });
});

$(function() {
    // Setup form validation on the #login_form element
    $("#customer_category_setup_form").validate({
        // Specify the validation rules for development officers setup . add and update forms
        rules: {
            name: {
                required: true
            }

        },
        // Specify the validation error messages
        messages: {
            name: "<span class='label label-warning val_mes'>Please enter Customer Category Name </span>"
        },
        errorElement : 'div',
        errorPlacement: function(error, element) {
            var placement = $(element).data('error');
            if (placement) {
                $(placement).append(error)
            } else {
                error.insertAfter(element);
            }
        },
        submitHandler: function (form) {
            form.submit();
        }
    });
});

$(function() {
    // Setup form validation on the #login_form element
    $("#customer_setup_form").validate({
        // Specify the validation rules for development officers setup . add and update forms
        rules: {
            name: {
                required: true
            },
            location: {
                required: true
            },
            contact: {
                required: true
            },

        },
        // Specify the validation error messages
        messages: {
            name: "<span class='label label-warning val_mes'>Please enter Customer Category Name </span>",
            location: "<span class='label label-warning val_mes'>Please enter Customer Category Name </span>",
            contact: "<span class='label label-warning val_mes'>Please enter Customer Category Name </span>",
        },
        errorElement : 'div',
        errorPlacement: function(error, element) {
            var placement = $(element).data('error');
            if (placement) {
                $(placement).append(error)
            } else {
                error.insertAfter(element);
            }
        },
        submitHandler: function (form) {
            form.submit();
        }
    });
});

// Chained - jQuery non AJAX(J) chained selects plugin
$(function() {
    // Setup form validation on the #change_pass_form element
    $("#change_pass_form").validate({
        // Specify the validation rules for change password setup. add and update forms
        rules: {
            old_pwd: {
                required: true
            },
            new_pwd: {
                required: true,
                minlength: 5
            },
            c_pwd: {
                required: true,
                minlength: 5,
                equalTo: "#new_pwd"
            }

        },
        // Specify the validation error messages
        messages: {
            old_pwd: "<span class='label label-warning val_mes'>Please provide a current password</span>",
            new_pwd: {
                required: "<span class='label label-warning val_mes'>Please provide a password</span>",
                minlength: "<span class='label label-warning val_mes'>Your password must be at least 5 characters long</span>"
            },
            c_pwd: {
                required: "<span class='label label-warning val_mes'>Please provide a password</span>",
                minlength: "<span class='label label-warning val_mes'>Your password must be at least 5 characters long</span>",
                equalTo: "<span class='label label-warning val_mes'>Please enter the same password as above</span>"
            }

        },
        errorElement : 'div',
        errorPlacement: function(error, element) {
            var placement = $(element).data('error');
            if (placement) {
                $(placement).append(error)
            } else {
                error.insertAfter(element);
            }
        },
        submitHandler: function (form) {
            form.submit();
        }
    });
});




//Customer Web Admin
// Chained - jQuery non AJAX(J) chained selects plugin
$(function() {
    // Setup form validation on the #authentication_form element
    $("#authentication_form").validate({
        // Specify the validation rules for authentication form. add and update forms
        rules: {
            name: {
                required: true
            },
            mobile_no: {
                required: true
            }

        },
        // Specify the validation error messages
        messages: {
            name: "<span class='label label-warning val_mes'>Please enter your name</span>",
            mobile_no: "<span class='label label-warning val_mes'>Please your mobile number</span>"

        },
        errorElement : 'div',
        errorPlacement: function(error, element) {
            var placement = $(element).data('error');
            if (placement) {
                $(placement).append(error)
            } else {
                error.insertAfter(element);
            }
        },
        submitHandler: function (form) {
            form.submit();
        }
    });
});

// Chained - jQuery non AJAX(J) chained selects plugin
$(function() {
    // Setup form validation on the #selectsurveycustomerdetail element
    $("#invoice_create_form").validate({
        // Specify the validation rules for selectsurveycustomerdetail form. add and update forms
        rules: {
            customer_name: {
                required: true
            },
            invoice_date: {
                required: true
            },
            'qty[]': {
                required: true,
                min : 1,
                number: true
            },
            'unitcost[]': {
                required: true
            },
            'unitsale[]': {
                required: true
            }
        },
        // Specify the validation error messages
        messages: {
            customer_name: "<span class='label label-warning val_mes'>Please enter customer name</span>",
            invoice_date: "<span class='label label-warning val_mes'>Please enter invoice date</span>",
            'qty[]': {
                required:  "<span class='label label-warning val_mes'>Please enter quantity</span>",
                min:  "<span class='label label-warning val_mes'>Please enter atleast 1 Quantity</span>",
                number:  "<span class='label label-warning val_mes'>Please enter a value in digits</span>"
            },
            'qty[]': "<span class='label label-warning val_mes'>Please enter quantity</span>",
            'unitcost[]': "<span class='label label-warning val_mes'>Please enter cost price</span>",
            'unitsale[]': "<span class='label label-warning val_mes'>Please enter sale price</span>",
        },
        errorElement : 'div',
        errorPlacement: function(error, element) {
            var placement = $(element).data('error');
            if (placement) {
                $(placement).append(error)
            } else {
                error.insertAfter(element);
            }
        },
        submitHandler: function (form) {
            form.submit();
        }
    });
});

// Chained - jQuery non AJAX(J) chained selects plugin
$(function() {
    // Setup form validation on the #selectsurveycustomerdetail element
    $("#payment_create_form").validate({
        // Specify the validation rules for selectsurveycustomerdetail form. add and update forms
        rules: {
            customer_name: {
                required: true
            },
            payment_date: {
                required: true
            },
            'payment_type':"required",
            'amount': {
                required: true
            },
            'bank_name':"required",
        },
        // Specify the validation error messages
        messages: {
            customer_name: "<span class='label label-warning val_mes'>Please enter customer name</span>",
            payment_date: "<span class='label label-warning val_mes'>Please enter payment date</span>",
            'payment_type': "<span class='label label-warning val_mes'>Please select payment type</span>",
            'amount': "<span class='label label-warning val_mes'>Please enter payment amount</span>",
            'bank_name': "<span class='label label-warning val_mes'>Please select bank name</span>",
        },
        errorElement : 'div',
        errorPlacement: function(error, element) {
            var placement = $(element).data('error');
            if (placement) {
                $(placement).append(error)
            } else {
                error.insertAfter(element);
            }
        },
        submitHandler: function (form) {
            form.submit();
        }
    });
});

$(function() {
    // Setup form validation on the #selectsurveycustomerdetail element
    $("#purpayment_create_form").validate({
        // Specify the validation rules for selectsurveycustomerdetail form. add and update forms
        rules: {
            supplier_name: {
                required: true
            },
            payment_date: {
                required: true
            },
            'payment_type': {
                required: true
            },
            'amount': {
                required: true
            },
            'bank_name': {
                required: true
            }
        },
        // Specify the validation error messages
        messages: {
            supplier_name: "<span class='label label-warning val_mes'>Please enter supplier name</span>",
            payment_date: "<span class='label label-warning val_mes'>Please enter payment date</span>",
            'payment_type': "<span class='label label-warning val_mes'>Please select payment type</span>",
            'amount': "<span class='label label-warning val_mes'>Please enter payment amount</span>",
            'bank_name': "<span class='label label-warning val_mes'>Please select bank name</span>",
        },
        errorElement : 'div',
        errorPlacement: function(error, element) {
            var placement = $(element).data('error');
            if (placement) {
                $(placement).append(error)
            } else {
                error.insertAfter(element);
            }
        },
        submitHandler: function (form) {
            form.submit();
        }
    });
});

// Chained - jQuery non AJAX(J) chained selects plugin
$(function() {
    // Setup form validation on the #selectsurveycustomerdetail element
    $("#stock_setup_form").validate({
        // Specify the validation rules for selectsurveycustomerdetail form. add and update forms
        rules: {
            product_id: {
                required: true
            },
            qty: {
                required: true
            },
        },
        // Specify the validation error messages
        messages: {
            product_id: "<span class='label label-warning val_mes'>Please select product name</span>",
            qty: "<span class='label label-warning val_mes'>Please enter quantity</span>",
        },
        errorElement : 'div',
        errorPlacement: function(error, element) {
            var placement = $(element).data('error');
            if (placement) {
                $(placement).append(error)
            } else {
                error.insertAfter(element);
            }
        },
        errorElement : 'div',
        errorPlacement: function(error, element) {
            var placement = $(element).data('error');
            if (placement) {
                $(placement).append(error)
            } else {
                error.insertAfter(element);
            }
        },
        submitHandler: function (form) {
            form.submit();
        }
    });
});