$(document).ready(function () {


  $("#rel_button").click(function() {
		// validate and process form
		// first hide any error messages
		
 $('.error').hide();
  	  var bfirstname = $("input#bfirstname").val();
  		if (bfirstname == "") {
        $("label#bfirstname_error").show();
        $("input#bfirstname").focus();
        return false;
      }
  		var blastname = $("input#blastname").val();
  		if (blastname == "") {
        $("label#blastname_error").show();
        $("input#blastname").focus();
        return false;
      }
	  
	    var bbroker = $("input#bbroker").val();
  		if (bbroker == "") {
        $("label#bbroker_error").show();
        $("input#bbroker").focus();
        return false;
      }
	  
	    var baddress = $("input#baddress").val();
  		if (baddress == "") {
        $("label#baddress_error").show();
        $("input#baddress").focus();
        return false;
      }
	  
	
	   var bcity = $("input#bcity").val();
  		if (bcity == "") {
        $("label#bcity_error").show();
        $("input#bcity").focus();
        return false;
      }
	  
	  var bstate = $("select#bstate").val();
  		if (bstate == "") {
        $("label#bstate_error").show();
        $("select#bstate").focus();
        return false;
      }
	  
	  var bzip = $("input#bzip").val();
  		if (bzip == "") {
        $("label#bzip_error").show();
        $("input#bzip").focus();
        return false;
      }
	  
	  var bemail = $("input#bemail").val();
  		if (bemail == "") {
        $("label#bemail_error").show();
        $("input#bemail").focus();
        return false;
      }
	  
	   
	  var bphone = $("input#bphone").val();
  		if (bphone == "") {
        $("label#bphone_error").show();
        $("input#bphone").focus();
        return false;
      }
	
	
  		
	    var bmobile = $("input#bmobile").val();
  		if (bmobile == "") {
        $("label#bmobile_error").show();
        $("input#bmobile").focus();
        return false;
      }
	  
	  
	  var btime = $("input#btime").val();
  		if (btime == "") {
        $("label#btime_error").show();
        $("input#btime").focus();
        return false;
      }
	  
	    var dataString = 'bfirstname='+ bfirstname + '&blastname='+ blastname + '&bbroker='+ bbroker + '&baddress='+ baddress + '&bcity='+ bcity + '&bstate='+ bstate + '&bzip='+ bzip + '&bemail=' + bemail + '&bphone=' + bphone + '&bmobile=' + bmobile + '&btime=' + btime;
  //alert (dataString);return false;
  $.ajax({
      type: "POST",
      url: "rel_insert.php",
      data: dataString,
      success: function() {
        $('#contact_rel').html("<div id='message_rel'><div id='reDiv'></div></div>");
        $('#message_rel').html("<br><br><br><br><p><img src=\"images/pinnicalhomes.png\"></p><h2>Thank You For Your Request. <br>Your Information Has Been Submitted!</h2>")
        .append("<p>We will be in touch soon.</p> <br><br><span class=\"dlink\"><a href=\"#\" onclick=\"MM_showHideLayers('reDiv','','hide')\">Return To Site &raquo;</a></span>")
        .hide()
        .fadeIn(500, function() {
          $('#message_rel').append("");
        });
      }
     });
    return false;
	});
});

