  var noajax = false;
  varformsuffix = "";

  function CheckLoginForm(formsuffixlocal)
  {
  	formsuffix = formsuffixlocal;
  	
    // disable submit button
    $('btnLoginSubmit'+formsuffix).disabled = true;

  	// encode password
  	//$('passwordmd5').value = hex_md5($('password').value);
  	// replace value of current password with ****
  	//$('password').value = $('password').value.replace(/./g,'*');
    
    if (!noajax)
    {
	    // get form parameters
	    var parameters = $('frmLogin'+formsuffix).serialize(true);
	    // add 'ajax' action parameter (to return JSON)
	    parameters['action'] = 'checkajax';
	 
	    // do ajax request
	    new Ajax.Request($('frmLogin'+formsuffix).action, 
	      { method: 'POST',
	    	  parameters: parameters,
	    	  onSuccess: LoginSuccessHandler,
	    	  onFailure: LoginFailureHandler
	    	}
	    );
    
      // empty password
      document.forms['frmLogin'+formsuffix].elements['password'].value = ''; 
      
      return false;
    } else 
    	return true;
  }
  
  // handles result of Ajax request when succeeded
  var LoginSuccessHandler = function(request,json) 
  {
  	// handle error messages
    if (json.status=='error')
    {
      ErrorDialog(json.errors);
    }
    
    // okay, go to confirmation page
    if (json.status=='success')
      document.location = json.redirect;

    // if we come here we should re-enable the submit button again
  	$('btnLoginSubmit'+formsuffix).disabled = false;
  	
    // focus field
  	document.forms['frmLogin'+formsuffix].elements[json.focusfield].focus();
  }
  
  // handles result of Ajax request when failed
  var LoginFailureHandler = function(request) 
  {
  	// submit via normal POST-request without ajax
  	noajax = true;
  	$('frmLogin'+formsuffix).submit();
  }
  
  // things that should happen when everything is loaded
  Event.observe(window, 'load', function (e)
  {
    // add event handlers
    Event.observe($('frmLogin'), 'submit', function(e) { ;if (!CheckLoginForm('')) Event.stop(e) } , false);
    try 
    {
      Event.observe($('frmLoginFull'), 'submit', function(e) { ;if (!CheckLoginForm('Full')) Event.stop(e) } , false);
    } catch (e) {}
    
  });