$(function() {
  $('.error').hide();
  $('input.text-input').css({backgroundColor:"#FFFFFF"});
  $('input.text-input').focus(function(){
    $(this).css({backgroundColor:"#FFDDAA"});
  });
  $('input.text-input').blur(function(){
    $(this).css({backgroundColor:"#FFFFFF"});
  });
});

  function sendForm(i) {
		// validate and process form
		// first hide any error messages
    $('.error').hide();
		
	  var name = $("input#cl_name"+i).val();
		if (name == "" || name == "Your name *") {
      $("label#name_error"+i).show();
      $("input#cl_name"+i).focus();
      return false;
    }
		var email = $("input#cl_email"+i).val();
		var location = $("input#cl_location"+i).val();
		var comments = $("textarea#cl_comments"+i).val();

		var phone = $("input#cl_pnumber"+i).val();
		if (phone == "" || phone == "Phone Number *") {
      $("label#phone_error"+i).show();
      $("input#cl_pnumber"+i).focus();
      return false;
    }
	 var listing_id = $("input#contact_left_listing_id"+i).val();
		
		var dataString = 'name='+ name + '&email=' + email + '&phone=' + phone + '&location=' + location + '&comments=' + comments + '&listing=' + listing_id;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "contact-left-send.php",
      data: dataString,
      success: function() {
        $('#contact_Left'+i).html("<div id='message"+i+"' style='background-color: #e4ebfd; min-height: 520px;'></div>");
        $('#message'+i).html("<img border='0' src='images/cl-thanks.gif' alt='' style='margin: 0 auto; padding-top: 30px; padding-right: 10px;' />")
        .append("")
        .hide()
        .fadeIn(1500, function() {
          $('#message'+i).append("<br /><img border='0' src='images/cl-check.gif' style='margin: 0 auto; padding-right: 10px;' /><br /><br /><div class='left-feedback-col' style='width: 200px; margin: 0 auto; text-align: center; font-family: Arial; font-size: 11px; padding-right: 10px;'><a href='javascript:collapse"+i+".slideit()'>[x] collapse this area.</a></div>");
        });
      }
     });
    return false;
	};

runOnLoad(function(){
  $("input#cl_name").select().focus();
});

