define(['jquery', 
    'underscore', 
    'knockout',
    'views/forms/base',
    'views/forms/sections/validation',
    'views/forms/sections/branch-list',
    'bootstrap-datetimepicker',
    'summernote'],
    function ($, _, ko, BaseForm, ValidationTools, BranchList, datetimepicker, summernote) {
        
        var vt = new ValidationTools;
    
        //modified version of code from http://stackoverflow.com/questions/6177975/how-to-validate-date-with-format-mm-dd-yyyy-in-javascript
        function isValidDate(dateString){
            
            console.log("validating: "+dateString);
            justDate = dateString.split("T")[0]
            
            // Change to acceptable db format
            var replaceDate = justDate.replace(/\//g,"-");
            
            // Create output array
            var output = new Array(
                false,
                replaceDate
            );       
            
            // Deal with empty dates (they're ok!)
            if(output[1] == ""){
                output[0] = true;
                console.log("blank date ok");
                return output;
            }
            
            // First check for the pattern
            if(!/^\d{4}\-\d{1,2}\-\d{1,2}$/.test(replaceDate)){
                console.log("pattern fail");
                return output;
            }

            // Parse the date parts, rebuild replaceDate
            var parts = replaceDate.split("-");
            for (i=1; i==2; i++) {
                console.log(i);
                if (parts[i].length == i) {
                    parts[i] = "0"+parts[i];
                }
            }
            replaceDate = parts.join("-");
            
            // make parts into integers for processing
            var day = parseInt(parts[2], 10);
            var month = parseInt(parts[1], 10);
            var year = parseInt(parts[0], 10);

            // Check the ranges of month and year
            if(year > 3000 || month == 0 || month > 12){
                return output;
            }
            var monthLength = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ];

            // Adjust for leap years
            if(year % 400 == 0 || (year % 100 != 0 && year % 4 == 0)){
                monthLength[1] = 29;
            }
                
            // Check the range of the day
            output[0] = day > 0 && day <= monthLength[month - 1];
            output[1] = replaceDate;
            console.log(output);
            return output;
        };

        return BaseForm.extend({

            initialize: function() {
                
                BaseForm.prototype.initialize.apply(this);
                var self = this;
                
                //date picker code
                var date_picker = $('.datetimepicker').datetimepicker({pickTime: false});
                date_picker.on('dp.change', function(evt){
                    $(this).find('input').trigger('change'); 
                });

                this.addBranchList(new BranchList({
                    el: this.$el.find('#function-section')[0],
                    data: this.data,
                    dataKey: 'PHASE_TYPE_ASSIGNMENT.E17',
                    validateBranch: function (nodes) {
                        var chk1 = vt.isValidDate(nodes, 'FROM_DATE.E49');
                        var chk2 = vt.isValidDate(nodes, 'TO_DATE.E49');
                        var chk3 = vt.nodesHaveValues(nodes, ['FUNCTION.E62','FUNCTION_PERIOD.E55']);
                        return chk1 == true && chk2 == true && chk3 == true;
                    }
                }));
                
                this.addBranchList(new BranchList({
                    el: this.$el.find('#current-use-section')[0],
                    data: this.data,
                    dataKey: 'HERITAGE_ASSET_REPORT.E3',
                    validateBranch: function (nodes) {
                        var chk1 = vt.isValidDate(nodes, 'HERITAGE_ASSET_REPORT_DATE.E49');
                        var chk2 = vt.nodesHaveValues(nodes, ['CURRENT_USER.E55','CURRENT_OPERATION_STATUS.E55','HERITAGE_ASSET_REPORT_DATE.E49']);
                        return chk1 == true && chk2 == true;
                    }
                }));
            }
        });
    }
);
        

@@ -345,2191 +345,8 @@
 ls;%0A
-    %0A        //modified version of code from http://stackoverflow.com/questions/6177975/how-to-validate-date-with-format-mm-dd-yyyy-in-javascript%0A        function isValidDate(dateString)%7B%0A            %0A            console.log(%22validating: %22+dateString);%0A            justDate = dateString.split(%22T%22)%5B0%5D%0A            %0A            // Change to acceptable db format%0A            var replaceDate = justDate.replace(/%5C//g,%22-%22);%0A            %0A            // Create output array%0A            var output = new Array(%0A                false,%0A                replaceDate%0A            );       %0A            %0A            // Deal with empty dates (they're ok!)%0A            if(output%5B1%5D == %22%22)%7B%0A                output%5B0%5D = true;%0A                console.log(%22blank date ok%22);%0A                return output;%0A            %7D%0A            %0A            // First check for the pattern%0A            if(!/%5E%5Cd%7B4%7D%5C-%5Cd%7B1,2%7D%5C-%5Cd%7B1,2%7D$/.test(replaceDate))%7B%0A                console.log(%22pattern fail%22);%0A                return output;%0A            %7D%0A%0A            // Parse the date parts, rebuild replaceDate%0A            var parts = replaceDate.split(%22-%22);%0A            for (i=1; i==2; i++) %7B%0A                console.log(i);%0A                if (parts%5Bi%5D.length == i) %7B%0A                    parts%5Bi%5D = %220%22+parts%5Bi%5D;%0A                %7D%0A            %7D%0A            replaceDate = parts.join(%22-%22);%0A            %0A            // make parts into integers for processing%0A            var day = parseInt(parts%5B2%5D, 10);%0A            var month = parseInt(parts%5B1%5D, 10);%0A            var year = parseInt(parts%5B0%5D, 10);%0A%0A            // Check the ranges of month and year%0A            if(year %3E 3000 %7C%7C month == 0 %7C%7C month %3E 12)%7B%0A                return output;%0A            %7D%0A            var monthLength = %5B 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 %5D;%0A%0A            // Adjust for leap years%0A            if(year %25 400 == 0 %7C%7C (year %25 100 != 0 && year %25 4 == 0))%7B%0A                monthLength%5B1%5D = 29;%0A            %7D%0A                %0A            // Check the range of the day%0A            output%5B0%5D = day %3E 0 && day %3C= monthLength%5Bmonth - 1%5D;%0A            output%5B1%5D = replaceDate;%0A            console.log(output);%0A            return output;%0A        %7D;%0A%0A
     

remove unused function