/*  OPTIONIZE Password JS
    Copyright 2009
*/

$(document).ready(function(){
	
	$("#forgot_your_password").bind('submit',function(){ resetPassword(); return false; });
	$("#button_send_password").bind('click',function(){ resetPassword(); return false; });

});

function resetPassword(){
	
	var $email = $("#email");
	var $dt = $("#forgot_your_password").find("dt");

	$email.removeClass("error").parent().find("label.error").fadeOut(200,function(){ $(this).remove(); });

	$.postJSON('/ajax/password.php',
		{ email: $email.val() },function(ret){
			if (ret == "true") {
//				$dt.removeClass("error");
				$("#button_send_password").addClass("disabled").unbind('click').bind('click',function(){ return false; })
					.before('<div class="saved">Password sent</div>');
				$("#forgot_your_password").unbind('submit');
			} else {
				$email.addClass("error").before('<label class="error">Sorry, there&#8217;s no account with that email!</label>');
//				$dt.addClass("error");
			}
			
		})
	
}

