/**
 * check.js
 *
 * Created By Benoît Durand on 08/10/2008
 * 
 * @author Benoît Durand
 * @version $Id: check.js 417 2008-12-12 11:45:22Z bdurand $
 */

/**
 * When the window has finished to load
 */
$(document).ready(function() {
	// Check required fields before to submit
	$('#message').submit(function() {
		// Metacharacters # ! ^ $ ( ) [ ] { } ? + * . \
		var re = /([A-Za-z]+) \* :/; // Pattern for regexp
		var isValid = true;

		$('#message label[for]').each(function() {
			var field = $(this).attr('htmlFor');
			if (re.test($(this).html()) && $('#' + field).val() == '' || ($('#antispam').val() != $('#equal').val())) {
				$.getJSON('/forum/JsonController.php?format=json', function(obj) {
					var wording = obj.json.champs_oblig + "\n";
					if ($('#antispam').val() != $('#equal').val()) wording += obj.json.anti_spam_faux + "\n";
					wording += obj.json.merci;
					alert(wording);
				});
				isValid = false;
				$('#' + field).focus();
				return false; // = break
			}
		});

		return isValid;
	});
});
