

var CONTAINER_HEIGHT = 120;

var Error = new Object();
Error.NO_MATCH = "That email does not exist in our database.  Please go <a href='register.php'>here</a> to register.";
Error.BLOCKED = "That account has either not been verified, or has been blocked.  If your account is not verified, you may <a href='#' onClick='sendVerifyEmail(); return false;' >click here to resend your verification email</a>.";
Error.GENERIC = "There was a error.  If the problem persists, please contact the administrator.";

var last_email;

$(document).ready(function() {
	$('#user_container').height(CONTAINER_HEIGHT);
	$('.hidden').hide();
});

function sendReset(){
	var email = $('#email').val();
	last_email = email;
	if(email == '' || email == null){
		return false;
	}

	$.ajax({
		type: 'POST',
		url: 'ajax/sendReset.php',
		data: {email:email},
		dataType: 'json',
		success: function(data){
			if(data.error.length >= 1){
				showError(Error[data.error]);
			}else{
				showSuccess();
			}
		},
		failure: function(){
			showError(Error.GENERIC);
		}
	});
}


function sendVerifyEmail(){
	$.ajax({
		type: 'POST',
		url: 'ajax/resendVerification.php',
		data: {email: last_email},
		dataType: "json",
		success: function(data){
			if(data.error == ''){
					alert('An email has been sent, please follow the instructions in the email to verify your account.');
			}else if(data.error=='BLOCKED'){
					alert('This account is blocked.  If you would like to know why please contact the administrator.');
			}else{
					alert('There was an error sending the email.  If the problem persists please contact the administrator.');
			}
		}
	});
}

function showError(error){
	$('#error_message').html(error);
	$('#user_container').height(CONTAINER_HEIGHT+50);
}

function clearError(){
	$('#error_message').html('');
	$('#user_container').height(CONTAINER_HEIGHT);
}

function showSuccess(){
	$('#user_container').hide();
	$('#success_container').height(120).show();
}

