function ForgotPassword() {

  this.dialogID = "forgotPasswordDialog";
  this.dialogDiv = '<div class="ui-corner-all" id="forgotPasswordDialog"></div>';

  this.initDialogDiv = function() {
    if (undefined == $('#'+this.dialogID) || null == $('#'+this.dialogID).html()) {
      $('body').append(this.dialogDiv);
      $('#'+this.dialogID).dialog({
		autoOpen: true,
		bgiframe: true,
		height: 250,
		width: 350,
		resizable: false,
		draggable: false,
		modal: true,
		closeOnEscape: false,
		zIndex: 9999
	  });
      $(".ui-dialog-titlebar").hide();
    }
  }

  this.getDialog = function() {
    $('#'+this.dialogID).remove();
    this.initDialogDiv();
	$('#'+this.dialogID).dialog('open');
  }  

  this.show = function() {
    this.getDialog();
    $.get('/forgotPasswordDialog.jsp', function(data) {
      $('#'+forgot.dialogID).html($.trim(data));
    });
  }

  this.close = function() {
	$('#'+this.dialogID).dialog('close');
  }
  
  this.send = function() {
    this.check();
  }  

  this.formID = 'forgottenPasswordForm';
  this.emailFieldID = 'forgot_email';
  this.userNameFieldID = 'forgot_username';
  this.errorID = 'errorMsg';
  this.errorMessage = '<p><font class="text_label" style="color:red;font-weight:bold;">Please enter a valid email address!</font></p>';
  
  this.emailRegexp = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,4}$/;

  this.check = function() {
    this.resetError();
    var emailAddress = $('#'+this.emailFieldID).val();
    var userName = $('#'+this.userNameFieldID).val();
    if (this.testEmail(emailAddress)) {
    
      this.submit(emailAddress, userName);
    } else {
      this.setError();
    }
  }
  
  this.testEmail = function(emailAddress) {
    if (undefined == emailAddress || null == emailAddress || emailAddress.length == 0) {
      return false;
    }
    if(!this.emailRegexp.test(emailAddress)) {
      return false;
    }
    return true;
  }
  
  this.setError = function() {
    $('#'+this.errorID).html(this.errorMessage);
    $('#'+this.emailFieldID).focus();
  }
  
  this.resetError = function() {
    $('#'+this.errorID).html('');
  }
  
  this.submit = function(emailAddress, userName) {
    $.get('/forgotPasswordSendEmail.jsp?email='+emailAddress+'&userName='+userName, function(data) {
      if ($.trim(data) == 'emailError') {
       alert('emailError');
        $('#'+forgot.errorID).html('<p><font class="text_label" style="color:red;font-weight:bold;">There was is an error with you Email Address.</font></p>');
      } else if ($.trim(data) == 'userNameError') {
      alert('userNameError');
        $('#'+forgot.errorID).html('<p><font class="text_label" style="color:red;font-weight:bold;">There was is an error with you User Name.</font></p>');
      } else if ($.trim(data) == 'good'){
      alert('good');
        $('#'+forgot.errorID).html('<p><font class="text_label" style="color:green; font-weight:bold;">Email sent sucessfully.</font></p>');
      }   
    });
  }
}

function blank() {
  //
}

var forgot = new ForgotPassword();

