$(document).bind("reveal.facebox",
	function ()
	{
		$("#button_requestpassword").click(button_requestpassword_click)
	}
);

$(document).bind("enter.facebox", function() {} );
   
function button_requestpassword_click()
{ 
      if (check_form_requestpassword())
      {
      		var form_data = $("#email").serialize();
      		
      		//doregistration
			$.post("/modules/requestpassword/dorequest.php", form_data, function(data){
																if (data.status == 1)
																{
																	var email = $("#email").val();
																	$("#requestpassword_content").replaceWith( '<h2 style="font-size:16px;">Uw wachtwoord is verstuurd naar '+email+'</h2>' );
																}
																else
																	show_requestpassword_error_text("Het ingevevoerd e-mail adres komt niet voor in ons bestand.");
															},"json");
      }
}
   


/* Check user input */
function check_form_requestpassword(){
    var email = $('#email');

    if(!email.val()) {
    	show_requestpassword_error_text('U heeft geen e-mail adres ingevuld.');
        email.focus();
        return false;
    }

    if(!email.val().match(/^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$/))
    {
        show_requestpassword_error_text('Het e-mail adres is ongeldig.');
        email.focus();
        return false;
    }
    return true;
}

function show_requestpassword_error_text(errortext)
{
	$("#div_requestpassword_text > h2").text("Help?");
	$("#div_requestpassword_text > p").text(errortext);
	$("#div_requestpassword_text > p").css("color","red");
}
