function followed() {
	$('.followform').html('Digital Business Coach is now following <b>' + $('#twitter_username').val() + '</b>');	
}
function failed() {
	$('#tfail').html('Could not follow user <b>' + $('#twitter_username').val() + '</b>. We may already be following you.');
	$("#twitter_username").attr("disabled", "");
	$("#follow").attr("disabled", "");
	$('#twitter_username').effect('highlight',1200);
}
function signedup(m) {
	$('#form_inner').html('<h3>Signed Up</h3><br /><p>Congratulations you have now signed up to Digital Business Coach, we have sent you a welcome message with more information.</p>'+m);	
}
$(document).ready(function() {
  $('.tweet_lists').load('/ajax/twitter');
  $('#follow').click(function() {
	$("#twitter_username").attr("disabled", "disabled");
	$("#follow").attr("disabled", "disabled");
	$.ajax({
	  type: 'POST',
	  url: '/ajax/follow',
	  data: 'twitter_username='+$('#twitter_username').val(),
	  success: followed,
	  error: failed
	});
  });
  $('#signup').click(function() {
	var fail = false;
	$('#first_name, #last_name, #email, #company, #position, #postcode, #mobile').removeClass('invalid').each(function() {
		if($(this).val() == '') {
			fail = true;
			$(this).effect('highlight', 2400).addClass('invalid');
		}
	});
	$('.radios_wrapper').removeClass('invalid');
	if ($("input[name=business_type]:checked").length == 0) {
		$('.radios_wrapper').addClass('invalid');
		fail = true;
	}
	
	if (!fail) {
		$("#signup").attr("disabled", "disabled");
		$.ajax({
		  type: 'POST',
		  url: '/ajax/signup',
		  data: 'first_name='+$('#first_name').val()+'&last_name='+$('#last_name').val()+'&company='+$('#company').val()+'&position='+$('#position').val()+'&email='+$('#email').val()+'&postcode='+$('#postcode').val()+'&mobile='+$('#mobile').val()+'&business_type='+$("input[name='business_type']:checked").val(),
		  success: signedup
		});
	}
  });
});

