$(function() {
    $('.error').hide();
    $(".send").click(function() {
      // validate and process form here
      
      $('.error').hide();
  	  var name = $("input#name").val();
  		if (name == "") {
        $("label#name_error").show();
        $("input#name").focus();
        return false;
      }
  	  var email = $("input#email").val();
  		if (email == "") {
        $("label#email_error").show();
        $("input#email").focus();
        return false;
      }
  	  var comments = $("textarea#comments").val();
	  if (comments == "") {
        $("label#comments_error").show();
        $("textarea#comments").focus();
        return false;
      }
  	  var group_id = $("input#group_id").val();
  	  var user_id = $("input#user_id").val();
  	  var group_type = $("input#group_type").val();
  	
  	  var dataString = 'data[ContactLead][name]='+ name + '&data[ContactLead][email]=' + email + '&data[ContactLead][comments]=' + comments + '&data[ContactLead][group_id]=' + group_id + '&data[ContactLead][group_type]=' + group_type + '&data[ContactLead][user_id]=' + user_id ;
  	  //alert (dataString);return false;
  	  
  	  $('#contact_form').html('<div id="status" style="text-align:center;"><br>...Processing request...<br>&nbsp;</div>');
  	  
  	$.ajax({
  	    type: "POST",
        url: "/contact_leads/add/",
        data: dataString,
        success: function() {
          $('#contact_form').html("<div id='message'></div>");
          $('#message').html('<img id="checkmark" src="/img/icons/check.png" style="float:left;margin:7px;" />')
          .append('<h3>Contact Form Submitted!</h3>')
          .append('<p>We will be in touch soon.</p>')
          .hide()
          .fadeIn(1500, function() {
            $('#message');
          });
        }
      });
      return false;

    });
    
  });