
var Login = Class.create(); 

Login.prototype = {

  initialize :  
  function (_name,_loginCompView,_loginBoxHtml,_forgotPasswordHtml)
  {
    this.name = _name;
    this.loginCompView = _loginCompView;    
    this.loginBoxHtml = JSON.parse(_loginBoxHtml);
    this.forgotPasswordHtml = JSON.parse(_forgotPasswordHtml);
  },


  showLoginForm :
  function ()
  {
    $(this.loginCompView).innerHTML =  this.loginBoxHtml;
  },

  showForgotPasswordForm :
  function ()
  {
    $(this.loginCompView).innerHTML =  this.forgotPasswordHtml;
  },

  submitForgotPassword :
  function ()
  {
    //AJAX submit
    new Ajax.Request(URL_AJAX_CALL, 
      { 
         onSuccess : this.submitForgotPasswordResp.bind(this), 
         onFailure : function(resp) { 
           alert("Oops, there's been an error."); 
         }, 
         onException : function(resp,exc) { 
           alert("Oops, there's been an exception." + exc + resp.responseText); 
         },       
         parameters : 'action=login&mode=forgot&' +Form.serialize($('forgotpassword')) 
      }    
    );  
  },
  
 
  submitForgotPasswordResp:
  function (_resp)
  {
    //alert(_resp.responseText);
    this.showLoginForm();
    var resp = JSON.parse(_resp.responseText);

    if (resp.success)
    {
      new Insertion.Bottom(this.loginCompView, 
       '<span class="loginemph-nofloat">login details sent to your email address</span>');
    }
    else
    {
      new Insertion.Bottom(this.loginCompView, 
       '<span class="loginemph-nofloat">error: ' + resp.errormsg + '</span>' );    
    }  
    setTimeout(this.showLoginForm.bind(this),2000);  

  }



}
