function Auth() { }

Auth.authorizedUser;
Auth.RESPONSE_ERRTYPE_USER_ROLE_MISSING = 1;
Auth.switchCustomerListeners = new Array();

Auth.logout = function() {
  AuthCtrl.logout(Auth.handleLogout);
  authorizedUser = null;
}

Auth.handleLogout = function() {
  document.location.reload(true);
}


Auth.loadUser = function() {
  AuthCtrl.getUser(Auth.handleGetUser);
}

Auth.handleGetUser = function(user) {
  Auth.authorizedUser = user;
}


Auth.check = function(response) {
	if (!response.authorized) {
		if (response.errorType != Auth.RESPONSE_ERRTYPE_USER_ROLE_MISSING) {
			document.location.reload(true);
			return false;
		}
	}
	return true;
}


Auth.switchCustomer = function(ev) {
	g_lookupCallback = function(seqno) { 
		Auth.selectedCustomerSeqno = seqno; 
		window.setTimeout("Auth.delayedSwitchCustomer()", 0); 
	}
	Util.showPopupWindow("/TelWeb/lookup/customer_lookup.jsp");
	return false;
}
Auth.delayedSwitchCustomer = function() {
	AuthCtrl.switchCustomer(Auth.selectedCustomerSeqno, Auth.handleSwitchCustomer);
}
Auth.handleSwitchCustomer = function(data) {
	var listeners = Auth.switchCustomerListeners;
	for (var i=0; i<listeners.length; i++) {
		listeners[i]();
	}
}

Auth.addSwitchCustomerListener = function(listener) {
	var listeners = Auth.switchCustomerListeners;
	listeners[listeners.length] = listener;
}