
//////////////////////////////////
// Sends ajax to check if an account name is available
// If it is, a link is provided to create an account
// If it is not available, the form field is displayed again.
// jQuery doesn't handle the errors quite as well as YAHOO does.
// But man, it takes about 10% of the code.
//////////////////////////////////

$(document).ready(function(){
	$("#checkNameForm").submit(function(e){
		removeErrors("checkNameForm");
		jQuery.getJSON("ajaxCheckName.tm",{"authenticatingUser.account.accountName":e.target.elements['authenticatingUser.account.accountName'].value},function(data){
			if(data.success){
				var successMessage = data.actionMessage;
				$("#checkNameForm").children("div").hide("normal",function(e){
					$(this).remove();
				});
				setTimeout(function(){
					var message = $('<div class="hidden"><p class="actionMessage">'+successMessage+'</p><h3><a href="checkName.tm?authenticatingUser.account.accountName='+data.accountName+'">Click here to create your ReferenceVault</a></h3></div>');
					$("#checkNameForm").append(message);
					showhide(message);//message.show("normal");//
				},1000);
			}else{
				showError("checkNameForm", data.errorMessage);
			}
		});
		return false;
	});
});
