jQuery(document).ready(function() {
   jQuery(":input[@type='text']").focus(function ()  {
   jQuery(this).removeAttr('rel');
   jQuery(this).attr({rel:'focus'}).css({backgroundColor: '#b2def7', border: '1px solid blue'});
   jQuery(this).parent().find(".exemple").css({display:"block"});
});
jQuery(":input[@type='text']").blur(function () {
	jQuery(this).removeAttr('rel');
    jQuery(this).attr({rel :'normal'}).css({backgroundColor: 'white', border: '1px solid #999999'});
	jQuery(this).parent().find(".exemple").css({display:"none"});
});
jQuery("#identifierOn").hide();
  jQuery('#contact-form .required, #Order-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>";
    jQuery('#contact-form .required, #Order-form .required').each(function(index) {
      if (!jQuery(this).val()) {
        /*select error input*/
        jQuery(this).css({backgroundColor: '#ffb5b5', border: '1px solid red'});
      	jQuery(this).next('.reqstar').fadeIn('slow').css({color: 'red', background: 'url(../img/important.png) no-repeat 0 50%', padding: '5px 5px 5px 25px'}).end();//.after(' <img src="{$_scripRootUrl}img/important.png" width="16px" height="16px" />');
      	jQuery(this).parent('div').addClass('error');
        errorMessage += '<li>' + jQuery(this).prev().text() + '</li>';
        errorCount++;
      } else {
        jQuery(this).parent('div').removeClass('error');
        jQuery(this).next('.reqstar').fadeOut('slow');
      }
    });
    var jQueryemail = jQuery('#Email');
    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;
      }
      jQuery('.log').show().html(errorMessage);
      return false;
    };
    jQuery("#identifierOn").show();
	jQuery("#identifierOff").hide();
  };
  jQuery('#contact-form').ajaxForm({
     type:       'post',
	 url:        'contact/send',
     clearForm: true,
	 beforeSubmit: validateForm,
     success: function(e) {
       jQuery("#identifierOn").hide();
	   jQuery("#identifierOff").show();
	   jQuery("div.msg").html(e).show().animate( { backgroundColor:'#008CFF', color:'#EFF8FF'}, 2000)
 .animate( { backgroundColor:'#fff', color:'#444'}, 2000);
        jQuery('#contact-form').slideUp('slow');
     }
  });
  jQuery('#Order-form').ajaxForm({
     type:       'post',
	 url:        'order/send',
     clearForm: true,
	 beforeSubmit: validateForm,
     success: function(e) {
       jQuery("#identifierOn").hide();
	   jQuery("#identifierOff").show();
	   jQuery("div.log").html(e).show('slow',function(){
		jQuery(this).animate({backgroundColor:'#008CFF', color:'#EFF8FF', borderLeftColor:'#000'}, 2000);
	},function() {
		jQuery(this).animate({backgroundColor:'#fff', color:'#444', borderLeftColor:'yellow'}, 2000);
	});
        jQuery('#Order-form').slideUp('slow');
     }
  });
});
