$(function() {
  $('.c_error').hide();
  $('input.contact-text-input').css({backgroundColor:"#a1d8f5"});
  $('input.contact-text-input').focus(function(){
    $(this).css({backgroundColor:"#bae3f8"});
  });
  $('textarea').focus(function(){
    $(this).css({backgroundColor:"#bae3f8"});
  });
  $('input.contact-text-input').blur(function(){
    $(this).css({backgroundColor:"#bae3f8"});
  });

  $(".contact-button").click(function() {
		// validate and process form
		// first hide any error messages
    $('.c_error').hide();
	
	
	// rajout	
	  
	  var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;	
	
	  var c_name = $("input#c_name").val();
		if (c_name == "") {
      $("label#c_name_error").show();
      $("input#c_name").focus();
      return false;
    }
	//rajout
	  var c_email = $("input#c_email").val();
		if (c_email == "") {
			$("label#c_email_error").show();
      		$("input#c_email").focus();
			return false;
		} else if(!emailReg.test(c_email)) {	
			$("label#c_email_error").show();
      		$("input#c_email").focus();
			return false;
		}
	
	//
		//var email = $("input#email").val();
		//if (email == "") {
      //$("label#email_error").show();
      //$("input#email").focus();
      //return false;
    //}
		var c_comments = $("textarea#c_comments").val();
		if (c_comments == "") {
      $("label#c_comments_error").show();
      $("textarea#c_comments").focus();
      return false;
    }
		
		var dataString = 'c_name='+ c_name + '&c_email=' + c_email + '&c_comments=' + c_comments;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "request_info/comment.php",
      data: dataString,
      success: function() {
        $('#contact_form').html("<div id='contact-message'></div>");
        $('#contact-message').html("<h2>&nbsp;</h2><p>We will be in touch soon!</p>")
        .append("")
        .hide()
        .fadeIn(1500, function() {
          $('#contact-message').append("");
        });
      }
     });
    return false;
	});
});
runOnLoad(function(){
  $("input#c_name").select().focus();
});
