var vehicleMasterModule = (function () {
    var date_input=$('input[name="purchasedate"]'); //our date input has the name "date"
	var container=$('form-group >  .datepicker-purchase').length>0 ? $('form-group > .datepicker-purchase ').parent() : "body";
	date_input.datepicker({
		format: 'yyyy-mm-dd',container: container,todayHighlight: true,	autoclose: true
    });
    //$('input[name="purchasedate"]').datepicker( "setDate", new Date()); 

    var date_input1=$('input[name="ins_policyfrom"]'); //our date input has the name "date"
	var container=$('form-group >  .datepicker-policyfrom').length>0 ? $('form-group > .datepicker-policyfrom').parent() : "body";
	date_input1.datepicker({
	    format: 'yyyy-mm-dd',container: container,todayHighlight: true,	autoclose: true,
    });
    var date_input2=$('input[name="ins_policyto"]'); //our date input has the name "date"
	var container=$('form-group >  .datepicker-policyto').length>0 ? $('form-group > .datepicker-policyto').parent() : "body";
	date_input2.datepicker({
	    format: 'yyyy-mm-dd',container: container,todayHighlight: true,	autoclose: true,
    });
	
	var date_input2=$('input[name="ins_policyremindon"]'); //our date input has the name "date"
	var container=$('form-group >  .datepicker-policyto').length>0 ? $('form-group > .datepicker-policyto').parent() : "body";
	date_input2.datepicker({
	    format: 'yyyy-mm-dd',container: container,todayHighlight: true,	autoclose: true,
    });
    
    var date_input3=$('input[name="fcfrom"]'); //our date input has the name "date"
	var container=$('form-group >  .datepicker-fcfrom').length>0 ? $('form-group > .datepicker-fcfrom').parent() : "body";
	date_input3.datepicker({
	    format: 'yyyy-mm-dd',container: container,todayHighlight: true,	autoclose: true,
    });
    var date_input4=$('input[name="fcto"]'); //our date input has the name "date"
	var container=$('form-group >  .datepicker-fcto').length>0 ? $('form-group > .datepicker-fcto').parent() : "body";
	date_input4.datepicker({
	    format: 'yyyy-mm-dd',container: container,todayHighlight: true,	autoclose: true,
    });

var date_input2=$('input[name="fcremindon"]'); //our date input has the name "date"
	var container=$('form-group >  .datepicker-policyto').length>0 ? $('form-group > .datepicker-policyto').parent() : "body";
	date_input2.datepicker({
	    format: 'yyyy-mm-dd',container: container,todayHighlight: true,	autoclose: true,
    });


    var date_input5=$('input[name="permitfrom"]'); //our date input has the name "date"
	var container=$('form-group >  .datepicker-permitfrom').length>0 ? $('form-group > .datepicker-permitfrom').parent() : "body";
	date_input5.datepicker({
	    format: 'yyyy-mm-dd',container: container,todayHighlight: true,	autoclose: true,
    });
    var date_input6=$('input[name="permitto"]'); //our date input has the name "date"
	var container=$('form-group >  .datepicker-permitto').length>0 ? $('form-group > .datepicker-permitto').parent() : "body";
	date_input6.datepicker({
	    format: 'yyyy-mm-dd',container: container,todayHighlight: true,	autoclose: true,
    });
	
	var date_input2=$('input[name="permitremindon"]'); //our date input has the name "date"
	var container=$('form-group >  .datepicker-policyto').length>0 ? $('form-group > .datepicker-policyto').parent() : "body";
	date_input2.datepicker({
	    format: 'yyyy-mm-dd',container: container,todayHighlight: true,	autoclose: true,
    });
	
	
	
	var date_input5=$('input[name="pypermitfrom"]'); //our date input has the name "date"
	var container=$('form-group >  .datepicker-permitfrom').length>0 ? $('form-group > .datepicker-permitfrom').parent() : "body";
	date_input5.datepicker({
	    format: 'yyyy-mm-dd',container: container,todayHighlight: true,	autoclose: true,
    });
    var date_input6=$('input[name="pypermitto"]'); //our date input has the name "date"
	var container=$('form-group >  .datepicker-permitto').length>0 ? $('form-group > .datepicker-permitto').parent() : "body";
	date_input6.datepicker({
	    format: 'yyyy-mm-dd',container: container,todayHighlight: true,	autoclose: true,
    });
	
	var date_input2=$('input[name="pypermitremindon"]'); //our date input has the name "date"
	var container=$('form-group >  .datepicker-policyto').length>0 ? $('form-group > .datepicker-policyto').parent() : "body";
	date_input2.datepicker({
	    format: 'yyyy-mm-dd',container: container,todayHighlight: true,	autoclose: true,
    });
	

    var date_input7=$('input[name="taxfrom"]'); //our date input has the name "date"
	var container=$('form-group >  .datepicker-taxfrom').length>0 ? $('form-group > .datepicker-taxfrom').parent() : "body";
	date_input7.datepicker({
	    format: 'yyyy-mm-dd',container: container,todayHighlight: true,	autoclose: true,
    });
    var date_input8=$('input[name="taxto"]'); //our date input has the name "date"
	var container=$('form-group >  .datepicker-taxto').length>0 ? $('form-group > .datepicker-taxto').parent() : "body";
	date_input8.datepicker({
	    format: 'yyyy-mm-dd',container: container,todayHighlight: true,	autoclose: true,
    });

 var date_input8=$('input[name="taxremindon"]'); //our date input has the name "date"
	var container=$('form-group >  .datepicker-taxto').length>0 ? $('form-group > .datepicker-taxto').parent() : "body";
	date_input8.datepicker({
	    format: 'yyyy-mm-dd',container: container,todayHighlight: true,	autoclose: true,
    });


 var date_input7=$('input[name="pytaxfrom"]'); //our date input has the name "date"
	var container=$('form-group >  .datepicker-taxfrom').length>0 ? $('form-group > .datepicker-taxfrom').parent() : "body";
	date_input7.datepicker({
	    format: 'yyyy-mm-dd',container: container,todayHighlight: true,	autoclose: true,
    });
    var date_input8=$('input[name="pytaxto"]'); //our date input has the name "date"
	var container=$('form-group >  .datepicker-taxto').length>0 ? $('form-group > .datepicker-taxto').parent() : "body";
	date_input8.datepicker({
	    format: 'yyyy-mm-dd',container: container,todayHighlight: true,	autoclose: true,
    });

 var date_input8=$('input[name="pytaxremindon"]'); //our date input has the name "date"
	var container=$('form-group >  .datepicker-taxto').length>0 ? $('form-group > .datepicker-taxto').parent() : "body";
	date_input8.datepicker({
	    format: 'yyyy-mm-dd',container: container,todayHighlight: true,	autoclose: true,
    });

    //, 
    var date_input7=$('input[name="loanfrom"]'); //our date input has the name "date"
	var container=$('form-group >  .datepicker-loanfrom').length>0 ? $('form-group > .datepicker-loanfrom').parent() : "body";
	date_input7.datepicker({
	    format: 'yyyy-mm-dd',container: container,todayHighlight: true,	autoclose: true,
    });
    var date_input8=$('input[name="loanto"]'); //our date input has the name "date"
	var container=$('form-group >  .datepicker-loanto').length>0 ? $('form-group > .datepicker-loanto').parent() : "body";
	date_input8.datepicker({
	    format: 'yyyy-mm-dd',container: container,todayHighlight: true,	autoclose: true,
    });
var date_input8=$('input[name="loanremindon"]'); //our date input has the name "date"
	var container=$('form-group >  .datepicker-taxto').length>0 ? $('form-group > .datepicker-taxto').parent() : "body";
	date_input8.datepicker({
	    format: 'yyyy-mm-dd',container: container,todayHighlight: true,	autoclose: true,
    });

    $('body').on('change','select.brandtype_select',function(){
        var brandtype    =   $(this).val();
        //var quality_type    =   $(this).val();
        if(brandtype) {
            $.ajax({
                url: base_url+'fetchAjaxData/fetchSelectBrandName.php?btype='+brandtype,
                dataType: "json",
                type: 'GET',        
                success: function(data) {
                    
                   $("#brandname_select option").remove();
                    var selected='<option disabled selected>Please select your option </option>';
                    $(data).each(function(index,value) {
                      selected =selected+"<option value='"+value.id+"'>"+value.brand_name+"</option> ";
                    });
                    $("#brandname_select").append(selected);
                    $('#brandname_select').selectpicker('refresh');
                    
                },
                error: function() {
                    console.log('An error has occurred');
                }                
            });
        }
        

    });

    

   
    $('#vehicleMasterForm').bootstrapValidator({
        // To use feedback icons, ensure that you use Bootstrap v3.1.0 or later
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',//glyphicon glyphicon-ok
            invalid: 'glyphicon glyphicon-remove',//glyphicon glyphicon-remove
            validating: 'glyphicon glyphicon-refresh'//glyphicon glyphicon-refresh
        },
        fields: {
            vehicleno: {
                message: 'The vehicle number is not valid',
                validators: {
                    notEmpty: {
                        message: 'The vehicle number is required and cannot be empty'
                    },
                    stringLength: {
                        min: 3,
                        max: 50,
                        message: 'The vehicle number must be more than 9 and less than 50 characters long'
                    },
                    /*regexp: {
                        regexp: /^[a-zA-Z0-9]+$/,
                        message: 'The vehicle number can only consist of alphabetical and number'
                    }*/
                }
            },
            brandtype: {
                message: 'The brand type is not valid',
                validators: {
                    notEmpty: {
                        message: 'The brand type is required and cannot be empty'
                    }
                }
            },
            brandname: {
                message: 'The brand name is not valid',
                validators: {
                    notEmpty: {
                        message: 'The brand name is required and cannot be empty'
                    }
                }
            },
            model: {
                message: 'The model is not valid',
                validators: {
                    notEmpty: {
                        message: 'The model is required and cannot be empty'
                    }
                }
            },
            purchasedate: {
                validators: {
                    notEmpty: {
                        message: 'The purchase date is required and date format YYYY-MM-DD'
                    },
                    
                }
            },
            openingkm: {
                message: 'The opening km is not valid',
                validators: {
                    notEmpty: {
                        message: 'The opening km is required and cannot be empty'
                    },
                    regexp: {
                        regexp: /^[0-9]+$/,
                        message: 'The opening km can only consist of number'
                    }
                }
            },
            vehicletype: {
                message: 'The vehicle type is not valid',
                validators: {
                    notEmpty: {
                        message: 'The vehicle type is required and cannot be empty'
                    }
                }
            },
            ownership: {
                message: 'The vehicle ownership is not valid',
                validators: {
                    notEmpty: {
                        message: 'The vehicle ownership is required and cannot be empty'
                    }
                }
            },
            ins_policynumber: {
                message: 'The Insurance policy number not valid',
                validators: {
                    notEmpty: {
                        message: 'The Insurance policy number is required and cannot be empty'
                    }
                }
            },            
            ins_policyfrom: {
                message: 'The Insurance policy from not valid',
                validators: {
                    notEmpty: {
                        message: 'The Insurance policy from is required and cannot be empty'
                    },
                    
                   
                }
            },
            ins_policyto: {
                
                validators: {
                    notEmpty: {
                        message: 'The Insurance policy to is required and cannot be empty'
                    },
                    
                    different: {
                        field: 'ins_policyfrom',
                        message: 'The from and to date cannot be the same as each other'
                    }
                }
            },
            ins_policyremindon: {
                
                validators: {
                    notEmpty: {
                        message: 'The Insurance policy Remind is required and cannot be empty'
                    }
                }
            },
            fcnumber: {
                validators: {
                    notEmpty: {
                        message: 'The FC number is required and cannot be empty'
                    }
                }
            },            
            fcfrom: {
                validators: {
                    notEmpty: {
                        message: 'The FC from is required and cannot be empty'
                    },
                   
                    different: {
                        field: 'fcto',
                        message: 'The from and to date cannot be the same as each other'
                    }
                   
                }
            },
            fcto: {
                validators: {
                    notEmpty: {
                        message: 'The FC to date is required and cannot be empty'
                    },
                    
                    different: {
                        field: 'fcfrom',
                        message: 'The from and to date cannot be the same as each other'
                    }
                }
            },
            fcremindon: {
                
                validators: {
                    notEmpty: {
                        message: 'The FC Remind is required and cannot be empty'
                    }
                }
            },
            permitnumber: {
                
                validators: {
                    notEmpty: {
                        message: 'The permit number is required and cannot be empty'
                    }
                }
            },            
            permitfrom: {
                
                validators: {
                    notEmpty: {
                        message: 'The permit from date is required and cannot be empty'
                    },
                   
                   
                }
            },
            permitto: {
                message: 'The permit to date not valid',
                validators: {
                    notEmpty: {
                        message: 'The permit to date is required and cannot be empty'
                    },
                    
                    different: {
                        field: 'permitfrom',
                        message: 'The from and to date cannot be the same as each other'
                    }
                }
            },
            permitremindon: {
                message: 'The permit Remind   not valid',
                validators: {
                    notEmpty: {
                        message: 'The permit Remind is required and cannot be empty'
                    }
                }
            },
            taxnumber: {
                message: 'The tax  number not valid',
                validators: {
                    notEmpty: {
                        message: 'The tax  number is required and cannot be empty'
                    }
                }
            },            
            taxfrom: {
                message: 'The tax  from date not valid',
                validators: {
                    notEmpty: {
                        message: 'The tax  from date is required and cannot be empty'
                    },
                    
                   
                }
            },
            taxto: {
                message: 'The tax  to date not valid',
                validators: {
                    notEmpty: {
                        message: 'The tax  to date is required and cannot be empty'
                    },
                   
                    different: {
                        field: 'taxfrom',
                        message: 'The from and to date cannot be the same as each other'
                    }
                }
            },
            taxremindon: {
                message: 'The tax Remind   not valid',
                validators: {
                    notEmpty: {
                        message: 'The tax  Remind is required and cannot be empty'
                    }
                }
            },
           
           
            
        }
    });




    // $('[name="fcto"]')
    // .datepicker({
    //     format: 'mm/dd/yyyy'
    // }).on('changeDate', function(e) {
    //     // Revalidate the date field
    //     fv.revalidateField('date');
    // });
    
    

})();