$(function() {
  $('.error').hide();
  $('input.text-input').css({backgroundColor:"#FFFFFF"});
  $('input.text-input').focus(function(){
    $(this).css({backgroundColor:"#FFF6BF"});
  });
  $('input.text-input').blur(function(){
    $(this).css({backgroundColor:"#FFFFFF"});
  });
  $('textarea.text-input').css({backgroundColor:"#FFFFFF"});
  $('textarea.text-input').focus(function(){
    $(this).css({backgroundColor:"#FFF6BF"});
  });
  $('textarea.text-input').blur(function(){
    $(this).css({backgroundColor:"#FFFFFF"});
  });  

  $('.button').click(function() {
		// validate and process form
		// first hide any error messages
    $('.error').hide();
		
	  var first = $('input#first').val();
		if (first == "") {
      $('label#name_error').show();
      $('input#first').focus();
      return false;
    }
	var maiden = $('input#maiden').val();
    var last = $('input#last').val();
		if (last == '') {
      $('label#name_error').show();
      $('input#last').focus();
      return false;
    }
	var email = $('input#email').val();
		if (email == '') {
      $('label#email_error').show();
      $('input#email').focus();
      return false;
    }
	var street = $('input#street').val();
		if (street == '') {
      $('label#street_error').show();
      $('input#street').focus();
      return false;
    }	
	var phone = $('input#daytime').val();
		if (phone == '') {
      $('label#phone_error').show();
      $('input#daytime').focus();
      return false;
    }
	var city = $('input#city').val();
		if (city == '') {
      $('label#city_error').show();
      $('input#city').focus();
      return false;
    }
	var state = $('input#state').val();
		if (state == '') {
      $('label#city_error').show();
      $('input#state').focus();
      return false;
    }
	var zip = $('input#zip').val();
		if (zip == '') {
      $('label#city_error').show();
      $('input#zip').focus();
      return false;
    }			
	var human = $('input#human').val();
		if (human == '') {
      		$('label#security_empty_error').show();
      		$('input#human').focus();
      		return false;
    	}
		if (human != 'priest') {
      		$('label#security_wrong_error').show();
      		$('input#human').focus();
      		return false;
    	}		
	
	
		
	var dataString = $('#join').serialize();
		
      $.ajax({
      type: 'POST',
      url: 'process/join_process.cfm',
      data: dataString,
      success: function(data)
	  {
	  	returndata = data.split('|');
        $('#registration_holder').html("<div id='message'></div>");
        $('#message').html(returndata[1])
		window.scrollTo(0,0);
		mailConfirmation(returndata[0]);
       }
     });
    return false;
	});
});
runOnLoad(function(){
  $("input#first").select().focus();
});

