(function($) {

    
    $(function() {
        $(".required").find("input[type='text']").not("[name='dob']").blur(function() {
            var $this = $(this);
            if ("" == $.trim($this.val())) {
                $this.addClass("reg-error");
            }
            else {
                $this.removeClass("reg-error");
            }
        });
        
        $("#registrationform input[type='submit'], #registrationform button[type='submit']").click(function(e) {
            e.preventDefault();
            $("tr.required").find("input[type='text']").blur();
            var correct = true;
            $("tr.required").find("input[type='text']").each(function() {
                if ($(this).hasClass("reg-error")) {
                    correct = false;
                }
            });
            if (correct) {
                $("#registrationform").submit();
            }
        });  
        
        $("#edit-profile-form input[type='submit'], #edit-profile-form button[type='submit']").click(function(e) {
            $("tr.required").find("input[type='text']").blur();
            var correct = true;
            $("tr.required").find("input[type='text']").each(function() {
                if ($(this).hasClass("reg-error")) {
                    correct = false;
                }
            });
            if (correct) {
                $("#edit-profile-form").submit();
            }
        });          
        
        $("input[name='dob']").datepicker({
            changeMonth: true,
            changeYear: true,
            dateFormat: "yy-mm-dd",
            minDate: "1900-01-01",
            yearRange: "c-100:c"
        }); 
    });
})(jQuery);


