
jQuery(document).ready(function() {
	$('#dialog').jqm(); //initializes our modal dialog
	
	//if the user clicks GO, the following will be executed
	$(".dialogGo").bind("click",
	  function() {
	    /* Send request to email new password */
	    var email = $("input[name='passwordresetemail']").val();
	    $('#passwordreset').css({'background-color' : ''}).text("making request...");
	    if(email.length > 0){
		    $.ajax({
						type: "POST",
						url: "/passwordreset",
						data: "email=" + email,
						timeout: 30000,
						success: function(data){
							//load our comments div with the data
							if(data){
								$("#passwordreset").text(data).css({'background-color':'yellow'});
							}else{
								$("#passwordreset").text("new password requested, check your email").css({'background-color':'yellow'});
							}
						},
						error: function(XMLHttpRequest, textStatus, errorThrown){
							//update our link which was clicked to get here
							if(textStatus){
								$("#passwordreset").text(textStatus);
							}else{
								$("#passwordreset").text("error resetting password, retype your email address");
							}
						}	
			});
	    	$('#dialog').jqmHide();
	    }else{
	    	alert("please enter your email address");
	    }
	  }
	);
		
});

function askforgotpassword(){
		user = $('#id_username').val();
		if(user){
			$('input[name="passwordresetemail"]').val(user);
		}
		$('#dialog').jqmShow();
}
