$.fn.copyTo = function(to) {
    var to = $(to);
    for ( var i = 1; i < arguments.length; i++ )
        to.set( arguments[i], this.get(0)[ arguments[i] ] );
    return this;
};
var chk_mail=0;
var chk_site=0;
//
new function() {
       	// $.fn.validate = validate() {};
     	// $.fn.validate = validate() {};
    $.fn.validate = {
        init: function(o) {
          if(o.name == 'email') { this.email(o) };
          if(o.name == 'dob') { this.dob(o) };
          if(o.name == 'site') { this.testsite(o) };
        },
        testsite: function(o) {
           var sit  =/^((http:\/\/){0,1})+((([a-zA-Z0-9\-])+\.){0,1})+(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})$/;              
           if (o.value.match(sit)) {
             doSuccess(o);
             chk_site=1;
            } else {
             doError(o,'adresse url non valide');
             chk_site=0;
            };
        },

        email: function(o) {
          var email  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
           if (o.value.match(email)) {
              doSuccess(o);
              chk_mail=1;
            } else {
              doError(o,'email non valide');
              chk_mail=0;
            };
        },
        dob: function(o) {
          var dob  = /(0[1-9]|1[012])+\/(0[1-9]|[12][0-9]|3[01])+\/(19|20)\d\d/;
            if (o.value.match(dob)) {
              doSuccess(o);
            } else {
              doError(o,'not a valid date');
            };
        }
     };
     function doSuccess(o) {    
               //$('#' + o.id + '_img').html('<img src="images/accept.gif" border="0" style="float:left;" />');
              //$('#' + o.id + '_li').removeClass("error");
              //$('#' + o.id + '_msg').html("");
              //$('#' + o.id + '_li').addClass("success");
               $('#' + o.id + '_err').html(" ");
     }

     function doError(o,m) {      
              //$('#' + o.id + '_img').html('<img src="images/exclamation.gif" border="0" style="float:left;" />');
              //$('#' + o.id + '_li').addClass("error");
              //$('#' + o.id + '_msg').html(m);
              //$('#' + o.id + '_li').removeClass("success");
               $('#' + o.id + '_err').html(m);
     }
     //private helper, validates each type after check
     
};
//
$(document).ready(function()
{
  $(".verif").each(function() {
          $(this).val("");
  });
  
  $(".verif").keyup(function() {
          $(this).validate.init(this);
  });
  
  $("#envoi").submit(function() {
     if(chk_mail==1 && chk_site==1 && $("#description").val()!=""){
      return true
   } else  {
      alert("Veuillez remplir correctement tous les champs");
      return false;
   }

  });
});

