/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
*/
$(function() {
	$("input#email").select().focus();
    $(".button").click(function() {
	  
	  $("input#submit_btn").hide();
      document.getElementById( "sendingform" ).innerHTML =  "<br><p>Sending Request<p>";
      
      
      $.post("/trade/forgot/js" , { 'email': $("input#email").val()},
      function(data){
    	  $("input#submit_btn").show();
    	  document.getElementById( "sendingform" ).innerHTML =  "";
        if(data.result === true){
        	 document.getElementById( "reset_form" ).innerHTML =  "Your new password has been emailed to you. <br><a href=\"/trade/login\">Log in</a>";
             
        } else {
        	try {
				if (data.message != undefined) document.getElementById( "form_error" ).innerHTML =  data.message;
			} catch (e) {
				// TODO: handle exception
			}
        	
            for ( var i in data.fields )
            {
                document.getElementById(data.fields[i]+"_label").innerHTML = '<span class="alert">' +data.errors[i] + '</span>';
            }
        }
        
        
      }, "json");
    return false;
	});

});


