


/**
 * Determine whether a value is empty. This is true when all characters in the
 * value are one of "\n, \t, ' '".
 */
function isEmpty(value) {

    for (var i= 0; i < value.length; i++) {
	var c = value.charAt(i);

	if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
    }

    return true;
}

function jq_form_validate(el) {
	f = this;	
	var valid = true;	
	$(f).find(".required").each(function(){	
		if (isEmpty($(this).val()) ) {
			valid= false;
			$(this).addClass("notvalid");
		}
	});
	if (!valid) {
		alert("Formulaire incomplet !");
	} else {
	    document.getElementById( 'button5' ).disabled = 'true';
    	document.getElementById( 'button6' ).disabled = 'true';
    	document.getElementById( 'waitMessage' ).style.display = 'block';
	}
	return valid;
}

jQuery(function(){
    
   $("form").bind("submit", jq_form_validate);
   $(":input.required").focus(function() {
		$(this).removeClass("notvalid");
	});
});
