var m_date = new Date();
var m_year = m_date.getFullYear();

$(document).ready(function () {

	$("input, textarea").focus(function () {
		$(this).css("background-color","#E0E0E0");
	});
	$("input, textarea").blur(function () {
		$(this).css("background-color","#FFF");
	});
	/**********************************************************/
	/*Gestion de la validation c�t� client*/
	$("form#professionnel").validate({	
		ignore: ".ignore",
		submitHandler: function(form) {
			form.submit();
		}
	});
	
	$("input:text[name='general[cp]']").rules("add", {
		digits : true,
		minlength: 5,
		maxlength: 5
	});

	$("input:text[name='general[telephone]']").rules("add", {
		digits : true,
		minlength: 10,
		maxlength: 10
	});
	
	$("input#pseudo, input#password, input#password2").rules("add", {
		minlength: 6
	});
	/*Fin gestion validation formulaire*/
	/**********************************************************/
	
	$("input:text[name='general[cp]']").keyup(function (){
		if ($(this).val().length == 5) {
			exp = new RegExp("[0-9]{5}$", "g");
			if (exp.test($(this).val())) {
				$.post("?eID=ville",{'mode' : 'ajax','cp': $(this).val()},
					function (data){
						$("select#ville").empty();
						$("select#ville").html(data);
					});
			}
		}
	});
	
	$("input#pseudo").keyup(function (){
		if ($(this).val().length > 5) {
			exp = new RegExp("[a-zA-Z0-9-_.]$", "g");
			if (exp.test($(this).val())) {
				$.post("?eID=pseudo",{'mode' : 'ajax','pseudo': $(this).val()},
					function (data){
						$("span#verif_pseudo").empty();
						$("span#verif_pseudo").append(data);
					});
			}
		}
	});
	
	$("input#password").keyup(function (){
		if ( $(this).val().length > 5) {
			var data = '<img src="typo3conf/ext/anet_dalalu_contactform/res/accept.png" alt="Correct" />';	
		} else {
			var data = '<img src="typo3conf/ext/anet_dalalu_contactform/res/remove.png" alt="Incorrect" />';	
		}
		$("span#verif_pass").empty();
		$("span#verif_pass").append(data);
	});
	
	$("input#password2").keyup(function (){
		if ( ($(this).val().length > 5)
		&& (  $("input#password").val() == $(this).val() )) {
			var data = '<img src="typo3conf/ext/anet_dalalu_contactform/res/accept.png" alt="Correct" />';	
		} else {
			var data = '<img src="typo3conf/ext/anet_dalalu_contactform/res/remove.png" alt="Incorrect" />';	
		}
		$("span#verif_pass2").empty();
		$("span#verif_pass2").append(data);
	});
});

