// Happy Form Checker =======================================================================

/** 
 * Happy Form Checker
 * @author wiz - wiz@kerpc.ru
 * @version 1.2
 *
 */
	$( function() {

		$("form.happyform").submit( function() {
			errors = '';
			firstfound = null;
			$("form.happyform .required").each( function(i) {
				if (this.value == '') {
					//alert($("form.happyform label[for='"+this.id+"']").text());
					//label = $("form.happyform label[for='"+this.id+"']").text();
					errors += '<br />'+$("form.happyform label[for='"+this.id+"']").text();
					if (!firstfound) firstfound = this;
				}
			});
			if (errors) {
				$("div.error").html('<strong>Заполните следующие поля:</strong>'+errors);
				$("div.error").fadeIn("slow");
				firstfound.focus();
				return false;
			}
		});

		//фильтр нажатий кнопок в полях digits
		$("form.happyform .digits").bind("keypress", function(e) {
			var key = (typeof e.charCode == 'undefined' ? e.keyCode : e.charCode);
			if (e.ctrlKey || e.altKey || key < 32)
				return true;
			key = String.fromCharCode(key);
			return /\d/.test(key);
		});
	});
