$(function() {
  $('.error').hide();
  $('input.text-input').css({backgroundColor:"#FFFFFF"});
  $('input.text-input').focus(function(){
    $(this).css({backgroundColor:"#fff885"});
  });
  $('input.text-input').blur(function(){
    $(this).css({backgroundColor:"#FFFFFF"});
  });

  $(".button").click(function() {
		// validate and process form
		// first hide any error messages
    $('.error').hide();
		
	  var name = $("input#name").val();
		if (name == "") {
      $("label#name_error").show();
      $("input#name").focus();
      return false;
    }
    
    
        
		var age = $("input#age").val();
		if (age == "") {
      $("label#age_error").show();
      $("input#age").focus();
      return false;
    }    
    
    
     
    		var address = $("input#address").val();
		if (address == "") {
      $("label#address_error").show();
      $("input#address").focus();
      return false;
    }    
    
    		var city = $("input#city").val();
		if (city == "") {
      $("label#city_error").show();
      $("input#city").focus();
      return false;
    }    
    
    
		var email = $("input#email").val();
		if (email == "") {
      $("label#email_error").show();
      $("input#email").focus();
      return false;
    }
		var phone = $("input#phone").val();
		if (phone == "") {
      $("label#phone_error").show();
      $("input#phone").focus();
      return false;
    }
    

  
    
    
    
    	var fullmessage = $("textarea#fullmessage").val();
		if (fullmessage == "") {
      $("textarea#fullmessage").focus();
      return false;
    }



if($('input#option1').attr('checked'))
{ var option1 = $("input#option1").val(); }
else {
	var option1 = '';
}

if($('input#option2').attr('checked'))
{ var option2 = $("input#option2").val(); }
else {
	var option2 = '';
}

if($('input#option3').attr('checked'))
{ var option3 = $("input#option3").val(); }
else {
	var option3 = '';
}

if($('input#option4').attr('checked'))
{ var option4 = $("input#option4").val(); }
else {
	var option4 = '';
}

if($('input#option5').attr('checked'))
{ var option5 = $("input#option5").val(); }
else {
	var option5 = '';
}

if($('input#option6').attr('checked'))
{ var option6 = $("input#option6").val(); }
else {
	var option6 = '';
}

if($('input#option7').attr('checked'))
{ var option7 = $("input#option7").val(); }
else {
	var option7 = '';
}

		
		var dataString = 'name='+ name + '&email=' + email + '&phone=' + phone + '&age=' + age + '&address=' + address + '&city=' + city + '&fullmessage=' + fullmessage + '&option1=' + option1 + '&option2=' + option2 + '&option3=' + option3 + '&option4=' + option4 + '&option5=' + option5 + '&option6=' + option6 + '&option7=' + option7;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "/views/content/process.php",
      data: dataString,
      success: function() {
        $('#contact_form').html("<div id='message'></div>");
        $('#message')
        .hide()
        .fadeIn(1500, function() {
          $('#message')
        .html("<div id='checkmark'></div>")
        .append("<h3>Form successfully submitted!</h3>")
        .append("<p>We will be in touch soon.</p>");
        })
        
        
        
        
      }
     });
    return false;
	});
});
runOnLoad(function(){
  $("input#name").select().focus();
});

