
new function() {
       // $.fn.validate = validate() {};
    $.fn.validate = {
        init: function(o) {
          if(o.name == 'prop_titre')       { this.titre(o) };
          if(o.name == 'prop_lieu_ville')  { this.ville(o) };
        },
        titre: function(o) {
          var vtitre  = /(.)+/;
           if (o.value.match(vtitre)) {
              doSuccess(o);
            } else {
              doError(o,'Veuillez pr&eacute;ciser un nom<br>');
            };
        },
        ville: function(o) {
          var vville  = /(.)+/;
           if (o.value.match(vville)) {
              doSuccess(o);
            } else {
              doError(o,'Veuillez pr&eacute;ciser la ville<br>');
            };
        }
     };

     function doSuccess(o) {
              $('#' + o.id + '_msg').html("");
     }

     function doError(o,m) {
              $('#' + o.id + '_msg').html(m);
     }
};

$.fn.match = function(m) {
	if ($(this).get(0).val() == $(m.match).val()) {
          $('#' + this.get(0).id + '_msg').html("");
        } else {
          $('#' + this.get(0).id + '_msg').html("");
        };
};

$(document).ready(function()
{
	$("//[@class=validated]/input").blur(function() {
		$(this).validate.init(this);
	});

	$("#description_text").blur(function() {

		if(this.value.replace(/ /g,"").replace(/\n/g,"").length<300)
		{
			$("#description_msg").html("Veuillez fournir une description plus pr&eacute;cise<br/>");
			$("#error_form").html("<br />Veuillez fournir une description plus pr&eacute;cise<br />");
		}
		else
		{
			$("#description_msg").html("");
			$("#error_form").html("");
		}
	});

	$("#description_text").keyup(function()
	{
		var currentLength = this.value.replace(/ /g,"").replace(/\n/g,"").length;

		if(currentLength >= 300)
		{
			$("#description_msg").html("");
			$("#error_form").html("");
		}

		if(currentLength==0)
			currentLength="0";

		$("#charcount").html(currentLength);
	});

	$("#ann_prop_formulaire").submit(function()
	{

		if ($("#description_text").val().replace(/ /g,"").replace(/\n/g,"").length<300) {
			$("#error_form").html("<br />Veuillez fournir une description plus pr&eacute;cise<br />");
			return false;}

		if ($("#prop_titre").val()=='') {
			$("#error_form").html("<br />Veuillez remplir le champ nom<br />");
			return false;}

		if ($("#prop_lieu_ville").val()=='') {
			$("#error_form").html("<br />Veuillez remplir le champ ville<br />");
			return false;}

		if ( ($("#prop_dep").val()==('')) && ($("#prop_pays").val()==('')) ) {
			$("#error_form").html("<br />Veuillez s&eacute;lectionner un d&eacute;partement ou un pays<br />");
			return false;}

		$("#error_form").html("");
		return true;
	});

	$("#cmp_maj_formulaire").submit(function()
	{

		if ($("#description_text").val().replace(/ /g,"").replace(/\n/g,"").length<300) {
			$("#error_form").html("<br />Veuillez fournir une description plus pr&eacute;cise<br />");
			return false;}

		if ($("#prop_titre").val()=='') {
			$("#error_form").html("<br />Veuillez remplir le champ nom<br />");
			return false;}

		if ($("#prop_lieu_ville").val()=='') {
			$("#error_form").html("<br />Veuillez remplir le champ ville<br />");
			return false;}

		if ( ($("#prop_dep").val()==('')) && ($("#prop_pays").val()==('')) ) {
			$("#error_form").html("<br />Veuillez s&eacute;lectionner un d&eacute;partement ou un pays<br />");
			return false;}

		if ($("#prop_maj_commentaire").val()=='') {
			$("#error_form").html("<br />Merci de pr&eacute;ciser la nature des modifications dans le champ 'Commentaires'<br />");
			return false;}

		$("#error_form").html("");
		return true;
	});

});

