/*jshint asi: false, bitwise: true, boss: false, curly: true, debug: false, devel: false, eqeqeq: true, evil: false, forin: true, immed: true, laxbreak: false, newcap: true, noarg: true, noempty: true, nonew: true, nomen: true, onevar: true, plusplus: true, regexp: true, undef: true, sub: false, strict: true, white: false*/
/*global jQuery, console, window*/
(function ($) {
	"use strict";
	
	var requiredInput, initInput;
	
	requiredInput		=	function ( ) {
		var $this	=	$(this);
		
		$this.removeClass("invalid");
		if ($this.val()) {
			$this.addClass("valid");
		} else {	
			$this.removeClass("valid");
		}
	};
	
	initInput		=
	window.initInput	=	function ( ) {
		var $this	=	$(this);
		
		if ($this.data("required")) {
			$this
				.addClass("required")
				.bind("keyup change blur focus", requiredInput);
			
			requiredInput.apply(this);
		}
	};
	
	$("input, textarea").each(initInput);
	
	$("form").submit(function ( ) {
		var $this	=	$(this),
		    valid	=	true;
		
		$this.find("input.required").each(function ( ) {
			if (!$(this).hasClass("valid")) {
				valid	=	false;
				$(this).addClass("invalid");
			}
		});
		
		return valid;
	});
}(jQuery));

