$(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"});
  });

  $(".button").click(function() {
		// validate and process form
		// first hide any error messages
    $('.error').hide();
	
	

    		
	  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 who = $("input:checked[type='radio'][name='applicant']").val(); 
	
	var other = $("input#other").val();
	
	var address1 = $("input#address1").val();
		if (address1 == "") {
      $("label#address1_error").show();
      $("input#address1").focus();
      return false;
    }	
	
	var address2 = $("input#address2").val();
			
	var city = $("input#city").val();
		if (city == "") {
      $("label#city_error").show();
      $("input#city").focus();
      return false;
    }
	
	var state = $("input#state").val();
		if (state == "") {
      $("label#state_error").show();
      $("input#state").focus();
      return false;
    }
	
		var email = $("input#email").val();
		if (email == "") {
      $("label#email_error").show();
      $("input#email").focus();
      return false;
    }
		var homePhone = $("input#homePhone").val();
		
		var cellPhone = $("input#cellPhone").val();
		
		var workPhone = $("input#workPhone").val();
		
		var property_type = $("input:checked[type='radio'][name='property_type']").val(); 
		
		var propValue = $("input#propValue").val();
		if (propValue == "") {
      $("label#propValue_error").show();
      $("input#propValue").focus();
      return false;
    }
	
	var mortgageBalance = $("input#mortgageBalance").val();
		if (mortgageBalance == "") {
      $("label#mortgageBalance_error").show();
      $("input#mortgageBalance").focus();
      return false;
    }
	
	var cashDesired = $("input#cashDesired").val();
		if (cashDesired == "") {
      $("label#cashDesired_error").show();
      $("input#cashDesired").focus();
      return false;
    }

	var over62 = $("input:checked[type='checkbox'][name='over62']").val(); 
	
	var reasons = $("input:checked[type='checkbox'][name='reasons']").val(); 
	
	var comments = $("input#comments").val(); 

	var applyCheck = $("input:checked[type='checkbox'][name='applyCheck']").val(); 
		
		
		var dataString = 'firstName='+ firstName + '&lastName=' + lastName + '&who=' + who + '&other=' + other + '&address1=' + address1 + '&address2=' + address2 + '&city=' + city + '&state=' + state + '&email=' + email + '&homePhone=' + homePhone  + '&cellPhone=' + cellPhone  + '&workPhone=' + workPhone + '&property_type=' + property_type + '&propValue=' + propValue + '&mortgageBalance=' + mortgageBalance + '&cashDesired=' + cashDesired + '&over62=' + over62 + '&reasons=' + reasons + '&comments=' + comments + '&applyCheck=' + applyCheck;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "bin/process.php",
      data: dataString,
      success: function() {
        $('#contact_form').html("<div id='message'></div>");
        $('#message').html("<h2>Your information has been submitted!</h2>")
        .append("<p>A reverse mortgage agent will contact you soon.</p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message').append("<img id='checkmark' src='images/check.png' />");
        });
      }
     });
    return false;
	});
});
/*
runOnLoad(function(){
  $("input#firstName").select().focus();
});
*/

$(".other").click(function() {
  $("input#other").select().focus();
	});

$(".other2").click(function() {
  $("input#other2").select().focus();
	});







<!--

/* 

function get_radio_value()
{
for (var i=0; i < document.contact.applicant.length; i++)
   {
   if (document.contact.applicant[i].checked)
      {
      var rad_val = document.contact.applicant[i].value;
      }
   }
}

*/

//-->




