$(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"});
  });

  $("#ri_button").click(function() {
		// validate and process form
		// first hide any error messages
		
		 $('.error').hide();
  	  var gender = $("select#gender").val();
  //	if (gender == "") {
    //   $("label#gender_error").show();
       $("select#gender").focus();
    //    return false;
    //  }
	  

  	  var firstname = $("input#firstname").val();
  	//	if (firstname == "") {
     //   $("label#firstname_error").show();
        $("input#firstname").focus();
     //   return false;
     // }
  		var lastname = $("input#lastname").val();
  		//if (lastname == "") {
      //  $("label#lastname_error").show();
        $("input#lastname").focus();
      //  return false;
    //  }
	  
	  var address1 = $("input#address1").val();
  	//	if (address1 == "") {
     //   $("label#address1_error").show();
        $("input#address1").focus();
      //  return false;
     // }
	   var city = $("input#city").val();
  	//	if (city == "") {
     //   $("label#city_error").show();
        $("input#city").focus();
     //   return false;
     // }
	  
	  var state = $("select#state").val();
  	//	if (state == "") {
     //   $("label#state_error").show();
        $("select#state").focus();
     //   return false;
     // }
	  
	  var zip = $("input#zip").val();
  		//if (zip == "") {
       // $("label#zip_error").show();
        $("input#zip").focus();
      //  return false;
     // }
	  
	   
	  var phone = $("input#phone").val();
  //	if (phone == "") {
  //     $("label#phone_error").show();
        $("input#phone").focus();
   //   return false;
 //    }
	
	
  		var email = $("input#email").val();
  		if (email == "") {
        $("label#email_error").show();
        $("input#email").focus();
        return false;
      }
	  
	  
	   var salesemail = $("input#salesemail").val();
  		if (salesemail == "") {
        $("label#salesemail_error").show();
        $("input#salesemail").focus();
        return false;
      }
	  
	    var prop = $("input#prop").val();
  		if (prop == "") {
        $("label#prop_error").show();
        $("input#prop").focus();
        return false;
      }
	  
	  
	  var dtime = $("input#dtime").val();
  		if (dtime == "") {
        $("label#dtime_error").show();
        $("input#dtime").focus();
        return false;
      }
	  
	    var dataString = 'gender='+ gender + '&firstname='+ firstname + '&lastname='+ lastname + '&address1='+ address1 + '&city='+ city + '&state='+ state + '&zip='+ zip + '&phone=' + phone +'&email=' + email + '&prop=' + prop + '&salesemail=' + salesemail + '&dtime=' + dtime;
  //alert (dataString);return false;
  $.ajax({
      type: "POST",
      url: "reg_insert.php",
      data: dataString,
      success: function() {
        $('#contact_ri').html("<div id='message_ri'><div id='riDiv'></div></div>");
        $('#message_ri').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('riDiv','','hide')\">Return To Site &raquo;</a></span>")
        .hide()
        .fadeIn(500, function() {
          $('#message_ri').append("");
        });
      }
     });
    return false;
	});
});


