/*jslint browser: true, devel: true, onevar: true, undef: true, nomen: true, eqeqeq: true, plusplus: true, bitwise: true, regexp: true, newcap: true, immed: true */

(function ( ) {
	"use strict";
	
	$("form.ajax").submit(function ( ) {
		var $this	=	$(this),
		    $inputs	=	$this.find("input"),
		    data	=	$this.serialize(),
		    url		=	$this.attr("action"),
		    method	=	$this.attr("method").toUpperCase(),
		    valid	=	true;
		
		$inputs.each(function ( ) {
			var $this	=	$(this),
			    error	=	$this.data("error"),
			    value	=	$this.val();
			
			if (error && (!value || value === error)) {
				$this.val($this.data("error")).addClass("error");
				valid	=	false;
				
				$this.bind("focus", function ( ) {
					$this.val("").unbind("focus").removeClass("error");
				});
			}
		});
		
		if (valid) {
			$.ajax({
				"url":		url,
				"data":		data,
				"type":		method,
				"dataType":	"html",
				"success":	function (data) {
					$this.html(data);
				}
			});
		}
		
		return false;
	});
}());

