code: function login(type) {
  	
  	var input = getInput();
  	
  	var onDone = function (err, result) {
  		if (err) {
  			console.error(err);
  			// switch for various errors
  			switch (err) {				
  				case 'ACCOUNT_EXISTS':
  					alert(l_lang.err_exists);
  					break;
  				case 'INVALID_EMAIL':
  					alert(l_lang.err_email);
  					break;		
  				case 'INVALID_ACCOUNT':
  				case 'INVALID_PASSWORD_OR_TOKEN':
  					alert(l_lang.err_notfound);
  					break;					
  				case 'INVALID_DATA':
  				case 'UID_ERROR':
  				case 'DB_ERROR':
  				case 'GROUP_ERROR':
  				default:
  					alert(err);
  					break;
  			}
  			return;
  		}
  
  		// do not redirect if it's just to reset password or register
  		if (type === 'getpass')
  			return;
  		
  		// try to login if register success
  		if (type === 'register') {
  			alert(l_lang.register_success);
  			login('account');
  			return;
  		}
  		
  		alert(l_lang.login_success);
  		window.location = '/main';		
  	}
  	
  	switch (type) {
  		case 'register':
  			if (input.account === '' || input.password === '' || input.email === '') {
  				return alert(l_lang.err_incomplete);	
  			}
  			SR.API._ACCOUNT_REGISTER(input, onDone);
  			break;
  		case 'account':
  			console.log('calling _ACCOUNT_LOGIN');
  			SR.API._ACCOUNT_LOGIN(input, onDone);
  			break;
  		case 'getpass':
  			SR.API._ACCOUNT_RESETPASS(input, onDone);
  			break;
  		default:
  			alert('unknown login type');
  			break;
  	}
  }
docs: types: 'register' 'account' 'getpass'