/*
* requires that core.js has been loaded
*/

function HandleNavClick(item)
{

	switch(item.toLowerCase())
	{
	
		case 'loginclose':
			HandleLoginClose();
			break;
		case 'login':
			
			var LPanel = document.getElementById('ctl00_LoginPanel');
			if(LPanel == null){
				alert('Error getting User Panel');
				return;
			}
			if(LPanel.style.display == 'none'){
			//Show
				LPanel.style.display = 'block';
				
				//Give the UserName txt the Focus
				document.getElementById('txtUser').focus();
			}else{
				LPanel.style.display = 'none';
			}
			break;  
			
	    case 'logout':
	    
	        var LPanel2 = document.getElementById('ctl00_LogoutPanel');
			if(LPanel2 == null){
				alert('Error getting User Panel');
				return;
			}
			if(LPanel2.style.display == 'none'){
			//Show
				LPanel2.style.display = 'block';
				
				
			}else{
				LPanel2.style.display = 'none';
			}
			
	        break;
	    case 'logoutclose': 
	     HandleLogoutClose();
			break;
	
		case 'test':
			var UPanel = document.getElementById('ctl00_UserTestPanel');
			
			if(UPanel == null){
				alert('Error getting User Panel');
				return;
			}
			
			if(UPanel.style.display == 'none'){
				//Show
				UPanel.style.display = 'block';
			}else{
				//Hide
				UPanel.style.display = 'none';
			}
			break;
	}
}

function HandleLogin()
{
	var userName;
	var userPassword;
	var isLoginValid = true;
	
	try{
		//Check for Valid UserName and Passwords
		userName = $e('txtUser').value;
		userPassword = $e('txtPass').value;
		
		if(userName == "")
		{
			alert('Please Enter a Valid Username');
			isLoginValid = false;
		}
		
		if(userPassword == "")
		{
			alert('Please enter a valid Pasword');
			isLoginValid = false;
		}
		
		if(!isLoginValid) return false;
			//Handle the login
			isLoginValid = Login(userName, userPassword);
			
			if(!isLoginValid){
				alert(User.ErrorMessage);
			} else {
				UpdateUserDisplay();
			}
	} catch(ex){
		alert(ex.message + ':: in Login');
	}

}

function HandleLogout()
{

Logout();
$e.setInnerText('txtLoginName','');
	$e.setInnerText('txtBucks','');
	ShowUserInfo();
HandleLogoutClose()
ShowLoginButton()
window.location = '/atbhome.aspx'

}

function UpdateUserDisplay(){
	//Set the Greeting UserName
	$e.setInnerText('txtLoginName',User.UserName);
	$e.setInnerText('txtBucks',User.Bucks);
	
	//Show the Bucks
	HideLoginButton();
	ShowUserInfo();
	
	//Close the Login Overlay
	HandleLoginClose();
}
      
function HandleLoginClose(){
	$e.hide('ctl00_LoginPanel');
}

function HandleLogoutClose(){
	$e.hide('ctl00_LogoutPanel');
}

function HideLoginButton(){
//LoginButtonPanel
	$e.hide('LoginButtonPanel');
}

function ShowLoginButton(){
//LoginButtonPanel
	$e.show('LoginButtonPanel');
}

function ShowUserInfo(){
	$e.show('UserDataPanel');
}

function HideCreateUser(){
	$e.hide('ctl00_CreateUserPanel')
}

function ShowCreateUser(){
	HandleLoginClose();
	$e.show('ctl00_CreateUserPanel');
}