
$j(function(){
	
	$j("#tell_a_friend_link").click(function(){
		showForm();
		$j(this).hide();
		return false;
	});
	
	$j("#tell_a_friend_cancel").click(function(){
		$j("#tell_a_friend_name, #tell_a_friend_email, #tell_a_friend_friends_email, #tell_a_friend_submit, #tell_a_friend_spacer, #tell_a_friend_header").hide();
		$j("#tell_a_friend_result").html('').hide();
		$j("#tell_a_friend_link").show();
		return false;
	});
	
	$j("#tell_a_friend_submit_button").click(function(){
		$j.ajax({
			async:		true,
			data:		$j("input", $j("#tell_a_friend_form")).serialize(),
			dataType:	'html',
			beforeSend:	function(){
							$j("#loading").show();
						},
			success:	showResponse,
			timeout:	10000,
			type:		'POST',
			url:		$j("#tell_a_friend_form").attr("action")
		});
	});
	
	hideForm();
	hideLoader();
});
function showResponse(responseText, statusText) {
	var result = $j("#tell_a_friend_result");
	var hideFormBool = true;
	
	if(responseText == 'true') {
		result.html('<strong>Cool.</strong> You just sent your friend a link to this program.');
		clearForm();
		setTimeout(function(){
			result.fadeOut("slow");
		}, 4000);
	}
	else if(responseText == 'false') {
		result.html('There was an error sending an email. Please contact your system administrator.');
	}
	else {
		hideFormBool = false;
		result.html(responseText);
	}
	
	// clearForm();
	if(hideFormBool) {
		hideForm();
		$j("#tell_a_friend_link").show();
	}
	else {
		
	}
	hideLoader();
	result.show();
	
}
function clearForm(){
	$j("#yourName, #yourEmail, #yourFriendsEmail").val('');
}
function hideForm(){
	$j("#tell_a_friend_name, #tell_a_friend_email, #tell_a_friend_friends_email, #tell_a_friend_submit, #tell_a_friend_spacer, #tell_a_friend_header, #tell_a_friend_result").hide();
}
function hideLoader(){
	$j("#loading").hide();
}
function showForm(){
	$j("#tell_a_friend_name, #tell_a_friend_email, #tell_a_friend_friends_email, #tell_a_friend_submit, #tell_a_friend_spacer, #tell_a_friend_header").show();
}