 $('#changepassword').bootstrapValidator({
            // Only disabled elements are excluded
            // The invisible elements belonging to inactive tabs must be validated
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            submitHandler: function (validator, form, submitButton) {
                // Do nothing
            },
            fields: {
               
                password1: {
                    validators: {
                        notEmpty: {
                            message: 'Old Password is required'
                        }
                    }
                },
                 password2: {
                    validators: {
                           notEmpty: {
                                    message: 'New Password is required'
                                },
                        identical: {
                            field: 'password3',
                            message: 'The new password and its confirm are not the same'
                        }
                    }
                },
                password3: {
                    validators: {
                         notEmpty: {
                                    message: 'Confirm Password is required'
                                },
                        identical: {
                            field: 'password2',
                            message: 'The password and its confirm are not the same'
                        }
                    }
                }
                
            }
        });


$('#userform').bootstrapValidator({
            // Only disabled elements are excluded
            // The invisible elements belonging to inactive tabs must be validated
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            submitHandler: function (validator, form, submitButton) {
                // Do nothing
            },
            fields: {
               
                name: {
                    validators: {
                        notEmpty: {
                            message: 'Name is required'
                        }
                    }
                },
                password: {
                    validators: {
                        identical: {
                            field: 'c_password',
                            message: 'The password and its confirm are not the same'
                        }
                    }
                },
                c_password: {
                    validators: {
                        identical: {
                            field: 'password',
                            message: 'The password and its confirm are not the same'
                        }
                    }
                },
//              card: {
//                    validators: {
//                        notEmpty: {
//                            message: 'Card is required'
//                        }
//                    }
//              },

                  role: {
                    validators: {
                        notEmpty: {
                            message: 'Role is required'
                        }
                    }
                }
            }
        });


 $('#companyinfo').bootstrapValidator({
            // Only disabled elements are excluded
            // The invisible elements belonging to inactive tabs must be validated
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            submitHandler: function (validator, form, submitButton) {
                // Do nothing
            },
            fields: {
               
              
                 postal: {
                        validators: {
                            digits: {
                                message: 'numeric value is valid'
                            }
                        }
                    },
                      phone1: {
                        validators: {
                            digits: {
                                message: 'numeric value is valid'
                            },
                            stringLength: {
                        max: 10,
                        message: 'The phone number should be 10 characters long'
                    }
                        }
                    },
                      phone2: {
                        validators: {
                            digits: {
                                message: 'numeric value is valid'
                            },
                         stringLength: {
                        max: 10,
                        message: 'The phone number should be 10 characters long'
                    }
                        }
                    },
                      fax: {
                        validators: {
                            digits: {
                                message: 'numeric value is valid'
                            }
                        }
                    },
                     email: {
                validators: {
                    emailAddress: {
                        message: 'The input is not a valid email address'
                    }
                }
            },
          
        }
 
        });


$('form#salereport').submit(function(e) {

    var form = $(this);

    e.preventDefault();

    $.ajax({
        type: "POST",
        url: base_url+"sales/salereport/getproductsale",
        data: form.serialize(), // <--- THIS IS THE CHANGE
        dataType: "html",
        success: function(data){
            //alert(data);
           $('#salereporthtml').html(data);
        },
        error: function() { $('#salereporthtml').html('data not found'); }
   });

});


$('form#popularproducts').submit(function(e) {

    var form = $(this);

    e.preventDefault();

    $.ajax({
        type: "POST",
        url: base_url+"sales/popularproducts/getpopularproducts",
        data: form.serialize(), // <--- THIS IS THE CHANGE
        dataType: "html",
        success: function(data){
            //alert(data);
           $('#salereporthtml').html(data);
        },
        error: function() { $('#salereporthtml').html('data not found'); }
   });

});


/*$('form#popularproducts').submit(function(e) {
    
    var form = $(this);

    e.preventDefault();

     $('#editabledatatable').dataTable( {
         "destroy": true,
        "ajax": "http://webin.sites.posics.com/webin_new/sales/popularproducts/getpopularproducts",
        "data": form.serialize(), // <--- THIS IS THE CHANGE
        "columns": [
            { "data": "id",
              render: function (data, type, row, meta) {
               return meta.row + meta.settings._iDisplayStart + 1;
              } 
            },
           { "data": "DATENEW" },
            { "data": "HOST" },
            { "data": "HOSTSEQUENCE" },
              { "data": "PAYMENT" },
            { "data": "NOTES" },
            { "data": "TOTAL" }
        ]
    } );
    

});*/



$('form#saleslog').submit(function(e) {

    var form = $(this);

    e.preventDefault();

    $.ajax({
        type: "POST",
        url: base_url+"sales/saleslog/getsalelog",
        data: form.serialize(), // <--- THIS IS THE CHANGE
        dataType: "html",
        success: function(data){
            //alert(data);
           $('#salereporthtml').html(data);
        },
        error: function() { $('#salereporthtml').html('data not found'); }
   });

});


 $("#cashin").click( function() {      

            document.location.href=base_url+"payment/payments/newcashin";


        });
        $("#cashout").click( function() {

            document.location.href=base_url+"payment/payments/newcashout";


        });
        $("#customer").click( function() {

            document.location.href=base_url+"payment/payments/customerpayment";


        });
        $("#supplier").click( function() {

            document.location.href=base_url+"payment/payments/supplierpayment";


        });



 /*$(function(){
      // bind change event to select
      $('#chngroup').on('change', function () {
          var url = $(this).val(); // get selected value
          if (url == "clear") { // require a URL
              $.ajax({
        type: "POST",
        url: "http://webin.sites.posics.com/webin_new/payment/payments/getpayments",
        dataType: "html",
        success: function(data){
           $('#salereporthtml').html(data);
        },
        error: function() { $('#salereporthtml').html('data not found'); }
   });

          }

             if (url == "PAYMENT") { // require a URL
              $.ajax({
        type: "POST",
        url: "http://webin.sites.posics.com/webin_new/payment/payments/getpaymenttypes",
        dataType: "html",
        success: function(data){
           $('#salereporthtml').html(data);
        },
        error: function() { $('#salereporthtml').html('data not found'); }
   });

          }


            else { // require a URL
              $.ajax({
        type: "POST",
        url: "http://webin.sites.posics.com/webin_new/payment/payments/getpaymenthostname",
        dataType: "html",
        success: function(data){
           $('#salereporthtml').html(data);
        },
        error: function() { $('#salereporthtml').html('data not found'); }
   });

          }

        
      });
    });*/

    

$(function(){
      // bind change event to select
        $('#chngroup').on('change', function () {
            var url = $(this).val(); // get selected value
            if (url == "clear") { // require a URL
                $('#paymentstable').DataTable().destroy();
                var fromdate = $('#filter_begin').val();
                var todate = $('#filter_end').val();
                var table = $('#paymentstable').DataTable( {
                    "bProcessing": true,
                    "bServerSide": true,
                    "sAjaxSource": base_url+"payment/payments/getpayments?fromdate="+fromdate+"&todate="+todate,
                    "aLengthMenu": [[20, 50, 100], [20, 50, 100]],
                    "columnDefs" : [
                        
                    ],
                });
            }

             if (url == "PAYMENT") { // require a URL
                $('#paymentstable').DataTable().destroy();
                var fromdate = $('#filter_begin').val();
                var todate = $('#filter_end').val();
                var table = $('#paymentstable').DataTable( {
                    "bProcessing": true,
                    "bServerSide": true,
                    "sAjaxSource": base_url+"payment/payments/getpaymenttypes?fromdate="+fromdate+"&todate="+todate,
                    "aLengthMenu": [[20, 50, 100], [20, 50, 100]],
                    "columnDefs" : [
                ],
                "drawCallback": function ( settings ) {
                        var api = this.api();
                        var rows = api.rows( {page:'current'} ).nodes();
                        var last=null;
                        api.column(5, {page:'current'} ).data().each( function ( group, i ) {
                            if ( last !== group ) {
                                $(rows).eq( i ).before(
                                    '<tr class="group"><td colspan="8">'+group+'</td></tr>'
                                );
                                last = group;
                            }
                        });
                    }
                });
            }


            if (url == "HOST") {
                 var fromdate = $('#filter_begin').val();
                var todate = $('#filter_end').val();
                 $('#paymentstable').DataTable().destroy();
                var table = $('#paymentstable').DataTable( {
                    "bProcessing": true,
                    "bServerSide": true,
                    "sAjaxSource": base_url+"payment/payments/getpaymenthostname?fromdate="+fromdate+"&todate="+todate,
                    "aLengthMenu": [[20, 50, 100], [20, 50, 100]],
                    "columnDefs" : [
                ],
                "drawCallback": function ( settings ) {
                var api = this.api();
                var rows = api.rows( {page:'current'} ).nodes();
                var last=null;

                api.column(3, {page:'current'} ).data().each( function ( group, i ) {
                if ( last !== group ) {
                    $(rows).eq( i ).before(
                        '<tr class="group"><td colspan="8">'+group+'</td></tr>'
                    );

                    last = group;
                }
                } );
                }
                });
            }
            
            if (url == "ACCOUNT") {
                 var fromdate = $('#filter_begin').val();
                var todate = $('#filter_end').val();
                 $('#paymentstable').DataTable().destroy();
                var table = $('#paymentstable').DataTable( {
                    "bProcessing": true,
                    "bServerSide": true,
                    "sAjaxSource": base_url+"payment/payments/getpaymentaccount?fromdate="+fromdate+"&todate="+todate,
                    "aLengthMenu": [[20, 50, 100], [20, 50, 100]],
                    "columnDefs" : [
                ],
                "drawCallback": function ( settings ) {
                var api = this.api();
                var rows = api.rows( {page:'current'} ).nodes();
                var last=null;

                api.column(2, {page:'current'} ).data().each( function ( group, i ) {
                if ( last !== group ) {
                    $(rows).eq( i ).before(
                        '<tr class="group"><td colspan="8">'+group+'</td></tr>'
                    );

                    last = group;
                }
                } );
                }
                });
            }
            
      });
    });


  /* function expandable() {
        var table = $('#editabledatatable'). DataTable ();
        var tr = $(this).closest('tr');
        alert(tr);
        var row = table.row( tr );
        alert(row.data());
        if ( row.child.isShown() ) {
            // This row is already open - close it
            row.child.hide();
            tr.removeClass('shown');
        }
        else {
            // Open this row
            row.child( format(row.data()) ).show();
            tr.addClass('shown');
        }
    } */
 
$(".table-toolbar .btn-info").click(function() {
    $('#myModal form').find("input, textarea,select").val("");
});

