$(document).ready(function() {
/*$(":input[@type!='submit']").focus(function ()  {
   $(this).removeClass();
   $(this).addClass("focus");
   $(this).parent().find(".exemple").css({display:"block"});
});
$(":input[@type!='submit']").blur(function () {
	$(this).removeClass();
	$(this).addClass("normal");
	$(this).parent().find(".exemple").css({display:"none"});
});*/
$(":input[@type='text']").focus(function ()  {
   $(this).removeAttr('rel');
   $(this).attr({rel:'focus'}).css({backgroundColor: '#b2def7', border: '1px solid blue'});
   $(this).parent().find(".exemple").css({display:"block"});
});
$(":input[@type='text']").blur(function () {
	$(this).removeAttr('rel');
   $(this).attr({rel :'normal'}).css({backgroundColor: 'white', border: '1px solid #999999'});
	$(this).parent().find(".exemple").css({display:"none"});
}); 
$("#identifierOn").hide();
  $('#contact-form .required, #soiree-form .required').prev('label')
  .css('fontWeight', 'bold').end().after(' <span class="reqstar">*obligatoire</span>');
  var emailFormat = /[-_\.a-zA-Z0-9]+@[-_\.a-zA-Z0-9]+(\.\w)+/i;
  function validateForm() {
    var errorCount = 0;
    var formatError = false;
    var errorMessage = "<p>S'il vous plaît entrer des informations dans les champs suivants: </p><ul>";
    $('#contact-form .required, #soiree-form .required').each(function(index) {
      if (!$(this).val()) {
        /*select error input*/
		$(this).css({backgroundColor: '#ffb5b5', border: '1px solid red'});
      	$(this).next('.reqstar').fadeIn('slow').css({color: 'red', background: 'url(img/important.png) no-repeat 0 50%', padding: '5px 5px 5px 25px'}).end();
      	$(this).parent('div').addClass('error');
        errorMessage += '<li>' + $(this).prev().text() + '</li>';
        errorCount++;
      } else {
        $(this).parent('div').removeClass('error');
        $(this).next('.reqstar').fadeOut('slow');
      }
    });
    var jQueryemail = $('#courriel');
    if (!emailFormat.test(jQueryemail.val())) {
		jQueryemail.css({backgroundColor: '#ffb5b5', border: '1px solid red'});
      formatError = '<p style="color:red;font-weight:bold;">'+ '<img src="img/file_alert.png" width="24px" height="24px" />' + "S'il vous plaît entrer l'adresse e-mail en utilisant le format correct (e.g. john@example.com)</p>";
      jQueryemail.parent('div').addClass('error');
      errorCount++;
    } else {
      jQueryemail.parent('div').removeClass('error');
    }
    if (errorCount > 0) {
      errorMessage += '</ul>';
      if (formatError) {
        errorMessage += formatError;
      }
      $('div.log').show().html(errorMessage);
      return false;
    };
    $("#identifierOn").show();
	$("#identifierOff").hide();
  };
  $('#contact-form').ajaxForm({
     type:       'post',
	 url:        'sendmail.php',
     clearForm: true,
	 beforeSubmit: validateForm,
     success: function(e) {
       $("#identifierOn").hide();
	   $("#identifierOff").show();
	   $("div.msg").html(e).show().animate( { backgroundColor:'#008CFF', color:'#EFF8FF'}, 2000)
 .animate( { backgroundColor:'#fff', color:'#444'}, 2000);
        $('#contact-form').slideUp('slow');
     }
  });
  $('#soiree-form').ajaxForm({
     type:       'post',
	 url:        'sendsoiree.php',
     clearForm: true,
	 beforeSubmit: validateForm,
     success: function(e) {
       $("#identifierOn").hide();
	   $("#identifierOff").show();
	   $("div.msg").html(e).show().animate( { backgroundColor:'#008CFF', color:'#EFF8FF'}, 2000)
 .animate( { backgroundColor:'#fff', color:'#444'}, 2000);
        $('#contact-form').slideUp('slow');
     }
  });
  $('#form-ref').ajaxForm({
     type:       'post',
	 url:        'sendformation.php',
     clearForm: true,
	 beforeSubmit: validateForm,
     success: function(e) {
       $("#identifierOn").hide();
	   $("#identifierOff").show();
	   $("div.msg").html(e).show().animate( { backgroundColor:'#008CFF', color:'#EFF8FF'}, 2000)
 .animate( { backgroundColor:'#fff', color:'#444'}, 2000);
        $('#form-ref').slideUp('slow');
     }
  });
});