/**
 * Simple jQuery validation plugin
 *
 * @author: Dariusz Pobożniak | http://pobozniak.pl
 * @date: 2010-02-22
 * @version: 1.0
 *
 */
 
(function($) {
    $.fn.validate = function(customOptions) {
        // Public defaults.
        var defaultOptions = {
            error: 'error',
            required: 'required'
        }
        // Set the options.
        var options = $.extend({}, defaultOptions, customOptions);
				
        // Go through the matched elements and return the jQuery object.
        return this.each(function() {
            var $this = $(this);
            $this.submit(function() {
                var isError = false;
                $this.find('.' + options.required).each(function() {
                    if (this.type == 'text' || this.type == 'textarea') {
                        if ($(this).val() == '') {
                            $(this).parent().addClass(options.error);
                            isError = true;
                        } else {
                            $(this).parent().removeClass(options.error);
                        }
                    }
                    if (this.type == 'radio' || this.type == 'checkbox') {
                        if ($('[name="'+$(this).attr('name')+'"]:checked').val() == undefined) {
                            $(this).parent().addClass(options.error);
                            isError = true;
                        } else {
                            $(this).parent().removeClass(options.error);
                        }
                    }
                })
                if (isError == true) {
                    $('#emptyflds').css({'display':'block'}).animate({opacity: 1.0}, 8000).fadeOut(600);
                    return false;
                }
            })
        });
    };
})(jQuery);
