$(document).ready(function()
{
	//////
	// Input default text
	//////
	$('input:text, textarea').each(function() {
		$(this).css("color","#d0d0d0");
		if(($(this).attr("tagName") == "INPUT" && $(this).val() == "") || ($(this).attr("tagName") == "TEXTAREA" && $(this).html() == ""))
			$(this).val($(this).attr("default"));
		else
			$(this).css("color","");
		$(this).focus(function(){
			if($(this).val() == $(this).attr("default")) $(this).val('').css("color","");
		}).blur(function(){
			if($(this).val() == "")  $(this).val($(this).attr("default")).css("color","#d0d0d0");
		});
	});
	
	$('#form input:submit').click(function() {
		var error = 0;
		
		$('.error').each(function() {
			$(this).remove();
		});
		
		var errors = new Array();
		
		$('#form select').each(function() {
			if($(this).attr("value") == "-1")
			{
				$(this).after("<div class='error'>"+$(this).attr("error")+"</span>");
				error++;
			}
		});
		
		$('#form input:text, #form textarea').each(function() {
			if((($(this).val() == "")&&(($(this).attr("required") == "true")||($(this).attr("required") == true)))
				||(($(this).val() == $(this).attr("default"))&&(($(this).attr("required") == "true")||($(this).attr("required") == true)))
				||(($(this).attr("validate") == "email")&&(!isValidEmailAddress($(this).val())))
				||(($(this).attr("validate") == "date")&&(!isValidDate($(this).val()))))
			{
				$(this).after("<div class='error'>"+$(this).attr("error")+"</span>");
				error++;
			}
		});
		
		if(error > 0)
		{
			//$('#form #error').html("<div class='error'>Veuillez corriger les champs marqu&eacute;s d'une &eacute;toile rouge.</div>");
			return false;
		}
	});
});
	
function isValidEmailAddress(emailAddress)
{
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
	return pattern.test(emailAddress);
}