//member/detail_new.php
// BYC Main Menu
//
	
	Ext.QuickTips.init();
	
	var imagePath = '/images/';
	var scriptPath = '/components/';
	var keyVal = '`';

	// Get Location of images
	var loggedInUser = getCookie('lid');
	var userName = getCookie('firstName');
	var mid = getCookie('mid');
	var gid = getCookie('gid');
	
	var menuDisable = false;
	var lip = '';
	
	// Set Menu based on logon state 
	function menuState(state){
		// We are logged in
		if(state==true){
			// Setup the menu item state
    		Ext.getCmp('mnuCommittees').enable();
    		Ext.getCmp('mnuMembers').enable();
    		Ext.getCmp('mnuTreasurer').enable();
    		Ext.getCmp('mnuFleetCaptain').enable();
    		Ext.getCmp('mnuAnnual').enable();
    		Ext.getCmp('mnuFloatPlan').enable();
    		Ext.getCmp('mnuBylaws').enable();
			Ext.getCmp('mnuKnotical').enable();
    		Ext.getCmp('mnuTowline').enable();
    		Ext.getCmp('mnuPicnic').enable();
    		Ext.getCmp('mnuCruises').enable();
    		Ext.getCmp('mnuEmergency').enable();
    		Ext.getCmp('mnuBYCColumnists').enable();
    		Ext.getCmp('mnuGen').enable();
    		Ext.getCmp('mnuEComm').enable();
   		
    		// Setup the button State
    	    Ext.getCmp('logbutton').setText('Log-Off');
    	    Ext.getCmp('userName').setText('Welcome ' + getCookie('firstName'));
		}
		// We are not logged in
		else{
			// Set the menu item state
    		Ext.getCmp('mnuCommittees').disable();
    		Ext.getCmp('mnuMembers').disable();
    		Ext.getCmp('mnuTreasurer').disable();
    		Ext.getCmp('mnuFleetCaptain').disable();
    		Ext.getCmp('mnuAnnual').disable();
	   		Ext.getCmp('mnuFloatPlan').disable();
    		Ext.getCmp('mnuBylaws').disable();
			Ext.getCmp('mnuKnotical').disable();
    		Ext.getCmp('mnuTowline').disable();
    		Ext.getCmp('mnuPicnic').disable();
    		Ext.getCmp('mnuCruises').disable();
    		Ext.getCmp('mnuEmergency').disable();
    		Ext.getCmp('mnuBYCColumnists').disable();
    		Ext.getCmp('mnuGen').disable();
    		Ext.getCmp('mnuEComm').disable();
    		
    		// Set the button State
			Ext.getCmp('logbutton').setText('Log-in');
    	    Ext.getCmp('userName').setText('');
    	    
    	    Ext.getCmp('mnuAdmin').setVisible(false);
    		
    		// Shutdown any Priveleged Menus
    		privMenuShutdown;
		}
	};
	
	//=========================================================
	//====================== Sub Menus ========================
	//=========================================================

	// Menu for what's going on in the club
	var menuAbout = new Ext.menu.Menu({
		id: 'menuAbout',
		baseCls: 'x-menu',
		width: 190,
		items: [{
			text: 'Home',
			iconCls: 'bmenu',
			handler: function() {
				window.location='/index.html';
			}
		},{
			text: 'Contact BYC',
			iconCls: 'bmenu',
			handler: function() {
				window.location='/club/about.html';
			}
		},'-',{
			text: 'BYC By Year',
			iconCls: 'bmenu',
			handler: function() {
				window.location='/history/byyear.php';
			}
		},{
			text: 'History',
			iconCls: 'bmenu',
			handler: function() {
				window.location='/history/';
			},
			menu: {
				width: 180,
				items: [
				    {
					text: 'BYC',
					iconCls: 'bmenu',
					handler: function() {
						window.location='/history/';
					}
				},{
					text: 'Skipperettes',
					iconCls: 'bmenu',
					handler: function() {
						window.location='/skipperettes/history/skiphistory.html';
					}
				}]
			}
		},{
			text: 'Youth Program',
			iconCls: 'bmenu',
			handler: function() {
				window.location='/committees/sail/youth/';
			}
		},'-',{
			text: 'Reciprocal Clubs',
			iconCls: 'bmenu',
			handler: function() {
				window.location='/recip/';
			}
		},'-',{
			text: 'Apply For Membership',
			iconCls: 'bmenu',
			handler: function() {
				window.location='/committees/membership/newmembers.html';
			}
		},{
			text: 'Getting a Website login',
			iconCls: 'bmenu',
			handler: function() {
				window.location='/admin/newaccount.html';
			}
		}]
	});
	
	// Menu for the Outside Activities
	var menuFacilities = new Ext.menu.Menu({
		id: 'menuFacilities',
		width: 210,
		items: [{
			text: 'Clubhouse',
			iconCls: 'bmenu',
			handler: function() {
				window.location='/bycClubhouse.html';
			}
		},{
			text: 'Oro Bay',
			iconCls: 'bmenu',
			handler: function() {
				window.location='/orobay/';
			}
		},{
			text: 'Railway',
			iconCls: 'bmenu',
			handler: function() {
				window.location='/committees/rail/';
			}
		},{
			text: 'Waste Water',
			iconCls: 'bmenu',
			handler: function() {
				window.location='/committees/wastewater/';
			}
		},'-',{
			text: 'Emergency Response',
			iconCls: 'bmenu',
			id: 'mnuEmergency',
			disabled: menuDisable,
			handler: function() {
				window.location='/safety/intro.php';
			}
		}]
	});
	
	// Menu for Events
	var menuEvents = new Ext.menu.Menu({
		id: 'menuEvents',
		width: 250,
		items: [{
			text: 'Annual Lighted Boat Parade',
			iconCls: 'bmenu',
			handler: function() {
//				window.location='/events/lightedships/';
				window.location='/events/lightedships/11/index.html';
			}
		},{
			text: 'Special Peoples Cruise',
			iconCls: 'bmenu',
			handler: function() {
				window.location='/events/spc.html';
			}
		},{
			text: 'Youth Sailing',
			iconCls: 'bmenu',
			id: 'mnuYouthSailing',
			handler: function() {
				window.location='/committees/sail/youth/';
			}
		},'-',{
			text: 'Event Flyers',
			iconCls: 'bmenu',
			handler: function() {
				window.location='/events/';
			}
		},'-',{
			text: 'Awards Night',
			iconCls: 'bmenu',
			handler: function() {
				window.location='/events/awards/';
			}
		},{
			text: 'Calendar',
			iconCls: 'bmenu',
			handler: function() {
				window.location='/events/calendar/';
			}
		},{
			text: 'Cruises',
			iconCls: 'bmenu',
			id: 'mnuCruises',
			disabled: menuDisable,
			handler: function() {
				window.location='/committees/fleetcaptain/';		// Login Required
			}
		},{
			text: 'Heavy Weather',
			iconCls: 'bmenu',
			handler: function() {
				window.location='/heavy_weather/index.html';
			}
		},{
			text: 'Oktoberfest',
			iconCls: 'bmenu',
			handler: function() {
				window.location='/events/oktfest.php';
			}
		},{
			text: 'Opening Days',
			iconCls: 'bmenu',
			handler: function() {
				window.location='/photoalbum/main.php?cmd=album&var1=openingday/';
			}
		},{
			text: 'Picnics in the Park ',					// Login Required *
			iconCls: 'bmenu',
			id: 'mnuPicnic',
			disabled: menuDisable,
			handler: function() {
				window.location='/events/picnics/';
			},
			menu: {
				items: [{
					text: 'Picnics',					// Login Required *
					iconCls: 'bmenu',
					handler: function() {
						window.location='/events/picnics/';
					}
					},{
						text: 'Photos',					// Login Required *
						iconCls: 'bmenu',
						handler: function() {
							window.location='/photoalbum/main.php?cmd=album&var1=picnics/';
						}
				}]
			}
		}]
	});

	// Menu for Management
	var menuManagement = new Ext.menu.Menu({
		id: 'menuManagement',
		width: 190,
		items: [{
			text: 'Bridge Officers',
			iconCls: 'bmenu',
			handler: function() {
				window.location='/bridge/';
			}
		},{
			text: 'Secretary',
			iconCls: 'bmenu',
			handler: function() {
				window.location='/committees/secretary/';
			}
		},{
			text: 'Treasurer',
			iconCls: 'bmenu',
			id: 'mnuTreasurer',
			disabled: menuDisable,
			handler: function() {
				window.location='/committees/treasurer/';
			},
			menu: {
				width: 210,
				items: [{
					text: 'Manage Memberships',						// Login Required + Role Access
					id: 'mnuTresManageMember',
					hidden: true,
					iconCls: 'bmenu',
						handler: function() {
						window.location='/admin/treasure/trsmngmembers.php';
					}
				},{
					text: "Treasurer's Membership List",						// Login Required + Role Access
					iconCls: 'bmenu',
						handler: function() {
						window.location='/admin/treasure/memberlist.php';
					}
				},{
					text: 'List of Members',		// Login Required *
					iconCls: 'bmenu',
					handler: function() {
						window.location='/admin/treasure/members.php';
					}
				}]
			}
		},{
			text: 'Fleet Captain',		// Login Required *
			iconCls: 'bmenu',
			id: 'mnuFleetCaptain',
			disabled: menuDisable,
			handler: function() {
				window.location='/committees/fleetcaptain/';
			}
		},{
			text: 'Fleet Surgeon',
			iconCls: 'bmenu',
			handler: function() {
				window.location='/committees/fleetsurgeon/';
			}
		},{
			text: 'Fleet Chaplain',
			iconCls: 'bmenu',
			handler: function() {
				window.location='/committees/chaplain/';
			}
		}]
	});

	// Menu for Committees						// All Require Login
	var menuCommittees = new Ext.menu.Menu({	// Login Required *
		id: 'menuCommittees',
		width: 190,
		items: [{
			text: 'BYC Employees',				// Login Required *
			iconCls: 'bmenu',
			handler: function() {
				window.location='/club/ecomm/employees.php';
			}
		},{
			text: 'Corrosion Control',			// Login Required *
			iconCls: 'bmenu',
			handler: function() {
				window.location='/committees/corrosion';
			}
		},{
			text: 'E-Committee',				// Login Required *
			iconCls: 'bmenu',
			handler: function() {
				window.location='/committees/ecomm/';
			},
			menu: {
				width: 210,
				items: [
				    {
						text: 'E-Committee Minutes',	// Login Required *
						iconCls: 'bmenu',
						handler: function() {
							window.location='/committees/ecomm/index.php?loc=min';
					}
				},{
					text: 'Planning Committee',			// Login Required *
					iconCls: 'bmenu',
					handler: function() {
						window.location='/committees/planning/';
					}
				}]
			}
		},{
			text: 'Environmental',				// Login Required *
			iconCls: 'bmenu',
			handler: function() {
				window.location='/committees/environ/';
			}
		},{
			text: 'Float',						// Login Required *
			iconCls: 'bmenu',
			handler: function() {
				window.location='/committees/float/';
			}
		},{
			text: 'Historian',						// Login Required *
			iconCls: 'bmenu',
			handler: function() {
				window.location='/committees/historian/';
			}
		},{
			text: 'Membership',					// Login Required *
			iconCls: 'bmenu',
			handler: function() {
				window.location='/committees/membership/';
			}
		},{
			text: 'Railway',					// Login Required *
			iconCls: 'bmenu',
			handler: function() {
				window.location='/committees/rail/';
			}
		},{
			text: 'Regatta for Power',
			iconCls: 'bmenu',
			handler: function() {
				window.location='/committees/regattaforpower/';
			}
		},{
			text: 'Regatta for Sail',
			iconCls: 'bmenu',
			handler: function() {
				window.location='/committees/sail/';
			},
			menu: {
				width: 190,
				items: [
				    {
					text: 'Regatta For Sail',
					iconCls: 'bmenu',
					handler: function() {
						window.location='/committees/sail/';
					}
				},{
					text: 'Youth Program',
					iconCls: 'bmenu',
					handler: function() {
						window.location='/committees/sail/youth/';
					}
				}]
			}
		},{
			text: 'Special Projects',						// Login Required *
			iconCls: 'bmenu',
			handler: function() {
				window.location='/committees/specproj/';
			}
		},{
			text: 'Waste Water',				// Login Required *
			iconCls: 'bmenu',
			handler: function() {
				window.location='/committees/wastewater';
			}
		},{
			text: 'Web Team',
			iconCls: 'bmenu',
			handler: function() {
				window.location='/committees/web/';
			}
		},{
			text: 'Work Parties',				// Login Required *
			iconCls: 'bmenu',
			handler: function() {
				window.location='/committees/workparty/';
			}
		}]
	});

	// Menu for Members Only
	var menuMembers = new Ext.menu.Menu({		// All Require Login
		id: 'menuMembers',
		width: 190,
		items: [{
			text: 'BYC Photo Album',						// Login Required *
			iconCls: 'bmenu',
			handler: function() {
				window.location='/photoalbum/';
			}
		},{
			text: 'Crossing the Bar',
			iconCls: 'bmenu',
			handler: function() {
				window.location='/crossingbar.html';
			}
		},{
			text: 'Float Map',					// Login Required *
			iconCls: 'bmenu',
			handler: function() {
				window.location='/committees/float/floatmap.php';
			}
		},{
			text: 'Forms',						// Login Required *
			iconCls: 'bmenu',
			handler: function() {
				window.location='/club/forms.php';
			}
		},{
			text: 'Fuel',						// Login Required *
			iconCls: 'bmenu',
			handler: function() {
				window.location='/committees/environ/fuel/fuel.php';
			}
		},{
			text: 'Member Lists',					// Login Required *  
			iconCls: 'bmenu',
			handler: function() {
				window.location='/admin/treasure/memberlist.php';
			},
			menu: {
				width: 210,
				items: [
				    {
						text: "Treasurer's Membership List",		// Login Required *
						iconCls: 'bmenu',
						handler: function() {
							window.location='/admin/treasure/memberlist.php';
						}
					},{
						text: 'List of Members',		// Login Required *
						iconCls: 'bmenu',
						handler: function() {
							window.location='/admin/treasure/members.php';
						}
					},{
						text: 'List of Chairs',				// Login Required *
						iconCls: 'bmenu',
						handler: function() {
							window.location='/committees/chairs/';
				    	}
					}]
			}
		},{
			text: 'Parking',						// Login Required *
			iconCls: 'bmenu',
			handler: function() {
				window.location='/shipshape/parking.html';
			}
		},{
			text: 'Points',						// Login Required *
			iconCls: 'bmenu',
			handler: function() {
				window.location='/committees/float/points.php';
			}
		},{
			text: 'Skipperettes',				// Login Required *
			iconCls: 'bmenu',
			handler: function() {
				window.location='/skipperettes';
			},
		menu: {
			width: 190,
			items: [
			    {
					text: 'Main Page',				// Login Required *
					iconCls: 'bmenu',
					handler: function() {
						window.location='/skipperettes';
			    	}
				},{
					text: 'Skupperettes',				// Login Required *
					iconCls: 'bmenu',
					handler: function() {
						window.location='/skipperettes/history/skupps.html';
			    	}
				},'-',{
					text: 'History - Overview',		// Login Required *
					iconCls: 'bmenu',
					handler: function() {
						window.location='/skipperettes/history/skiphistory.html';
					}
				},{
					text: 'History - Detailed',		// Login Required *
					iconCls: 'bmenu',
					handler: function() {
						window.location='/skipperettes/history/skiphist.html';
					}
				},{
					text: 'History - Part I',		// Login Required *
					iconCls: 'bmenu',
					handler: function() {
						window.location='/skipperettes/history/skiphistI.html';
					}
				},{
					text: 'History - Part II',		// Login Required *
					iconCls: 'bmenu',
					handler: function() {
						window.location='/skipperettes/history/skiphistII.html';
					}
				},{
					text: 'History - Part III',		// Login Required *
					iconCls: 'bmenu',
					handler: function() {
						window.location='/skipperettes/history/skiphistIII.html';
					}
				},{
					text: 'History - Part IV',		// Login Required *
					iconCls: 'bmenu',
					handler: function() {
						window.location='/skipperettes/history/skiphistIV.html';
					}
				},{
					text: 'History - Part V',		// Login Required *
					iconCls: 'bmenu',
					handler: function() {
						window.location='/skipperettes/history/skiphistV.html';
					}
				},'-',{
					text: 'Past Presidents',		// Login Required *
					iconCls: 'bmenu',
					handler: function() {
						window.location='/skipperettes/history/skippres.html';
					}
				}]
			}
		},{
			text: 'Yachts',						// Login Required *
			iconCls: 'bmenu',
			handler: function() {
				window.location='/club/yachts.php';
			}
		},'-',{
			text: 'Edit Your Account',					// Login Required *
			iconCls: 'bmenu',
			handler: function() {
				window.location='/account/index.php';
			}
		},{
			text: 'Admin',						// Login Required *
			iconCls: 'bmenu',
			id: 'mnuAdmin',
			hidden: true,
			handler: function() {
				window.location='/admin/admin.php';
			},
			menu: {
				width: 190,
				items: [{
					text: 'Manage Users',						// Login Required *
					iconCls: 'bmenu',
						handler: function() {
						window.location='/admin/users.php';
					}
				},{
					text: 'instructions',						// Login Required *
					iconCls: 'bmenu',
						handler: function() {
						window.location='/admin/inst/index.php';
					}
				}]
			}
		}]
	});

	// Menu for Publications
	var menuPublications = new Ext.menu.Menu({
		id: 'mnuPublications',
		width: 250,
		items: [{
			text: 'General Member Business',					// Login Required *
			iconCls: 'bmenu',
			id: 'mnuGen',
			disabled: menuDisable,
			handler: function() {
				window.location='/club/genmeeting/index.html';
			},
			menu: {
					width: 210,
					items: [{
						text: 'Meeting Minutes',						// Login Required *
						iconCls: 'bmenu',
							handler: function() {
							window.location='/club/genmeeting/index.html#minutes';
						}
					},{
						text: 'Reports to Members',						// Login Required *
						iconCls: 'bmenu',
							handler: function() {
							window.location='/club/genmeeting/index.html#reports';
						}
					}]
				}
		},{
			text: 'E-Comm Meeting Minutes',						// Login Required *
			iconCls: 'bmenu',
			id: 'mnuEComm',
			disabled: menuDisable,
			handler: function() {
				window.location='/committees/ecomm/index.php?loc=min';
			}
		},"-",{
			text: 'Annual',						// Login Required *
			iconCls: 'bmenu',
			id: 'mnuAnnual',
			disabled: menuDisable,
			handler: function() {
				window.location='/annual/index.php';
			}
		},{
			text: 'Bylaws',						// Login Required *
			iconCls: 'bmenu',
			id: 'mnuBylaws',
			disabled: menuDisable,
			handler: function() {
				window.location='/bylaws/';
			}
		},{
			text: 'Knotical News',					// Login Required *
			iconCls: 'bmenu',
			id: 'mnuKnotical',
			disabled: menuDisable,
			handler: function() {
				window.location='/skipperettes/knotical/';
			}
		},{
			text: 'Towline',					// Login Required *
			iconCls: 'bmenu',
			id: 'mnuTowline',
			disabled: menuDisable,
			handler: function() {
				window.location='/towline/';
			}
		},{
			text: 'Float Plan',					// Login Required *
			iconCls: 'bmenu',
			id: 'mnuFloatPlan',
			disabled: menuDisable,
			handler: function() {
				window.location='/club/floats.php';
			}
		},'-',{
			text: 'BYC Columnists',				// Login Required *
			iconCls: 'bmenu',
			id: 'mnuBYCColumnists',
			disabled: menuDisable,
			handler: function() {
				window.location='/club/columnists/index.php';
			}
		},{
			text: 'BYC In The News',			// Login Required *
			iconCls: 'bmenu',
			id: 'mnuBYCNews',
			disabled: menuDisable,
			handler: function() {
				window.location='/press/inthenews.html';
			}
		},{
			text: 'Press Releases',
			iconCls: 'bmenu',
			handler: function() {
				window.location='/press/';
			}
		}]
	});

	// Menu for External Links
	var menuLinks = new Ext.menu.Menu({
		id: 'menuLinks',
		width: 190,
		items: [{
			text: 'Grand Fourteen',
			iconCls: 'bmenu',
			handler: function() {
				window.location='/recip/clubs.html';
			}
		},{
			text: 'Internet Resources',
			iconCls: 'bmenu',
			handler: function() {
				window.location='/bycLinks.html';
			}
		},{
			text: 'Tide Charts',
			iconCls: 'bmenu',
			handler: function() {
				window.location='/tides.html';
			}
		},{
			text: 'Weather Links',
			iconCls: 'bmenu',
			handler: function() {
				window.location='/weather.html';
			}
		},'-',{
			text: 'BYC Archives',
			iconCls: 'bmenu',
			handler: function() {
				window.location='/indexpage.html';
			}
		},{
			text: 'BYC Site Map',
			iconCls: 'bmenu',
			handler: function() {
				window.location='/sitemap.html';
			}
		},{
			text: 'Google BYC',
			iconCls: 'bmenu',
			handler: function() {
				window.location='/googlebyc.html';
			}
		},'-',{
			text: 'Sponsors',
			iconCls: 'bmenu',
			handler: function() {
				window.location='/ads/index.html';
			}
		}]
	});
	
//==========================================================
//======================== Login ===========================
//==========================================================

function loginWindow(win){
    
	// Validate User
	inputUserName = Ext.getCmp('username').getValue();

	inputPassword = Ext.getCmp('password').getValue();
	lip = inputPassword
	
	// Check Login information
	Ext.Ajax.request({
		waitMsg: 'Logging in...',
		showLoadIndicator: true,
		url: scriptPath + "authacc.php?action=login&username=" + inputUserName + "&password=" + inputPassword,
		success: loginsuccess,
		failure: logfailed
	})
	win.hide();
};

function loginsuccess(response){
	
	// Get returned message
	temp = response.responseText;
	
	// Get status of login attempt
	parStart = temp.search(':') + 1;
	parEnd = temp.search(keyVal);
	logStatus = temp.substring(parStart,parEnd);
	temp = temp.substring(parEnd+1);
	
	// See if we have a valid login
	if(logStatus == 'true') {
	
		//Setup for Successful Login
	    Ext.getCmp('logbutton').setText('Log-Off');
		
		// get users loginID
		parEnd = temp.search(keyVal);
		logName = temp.substring(0,parEnd);
		temp = temp.substring(parEnd+1);
		setCookie('lid', logName, 30);
		
		// get users First Name
		parEnd = temp.search(keyVal);
		firstName = temp.substring(0,parEnd);
		temp = temp.substring(parEnd+1);
		setCookie('firstName', firstName, 30);
		Ext.getCmp('userName').setText('Welcome ' + firstName);
		
		// get users Last Name
		parEnd = temp.search(keyVal);
		lastName = temp.substring(0,parEnd);
		temp = temp.substring(parEnd+1);
		setCookie('lastName', lastName, 30);
		
		// get users Role
		parEnd = temp.search(keyVal);
		role = temp.substring(0,parEnd);
		temp = temp.substring(parEnd+1);
		setCookie('rid', role, 30);
		
		// get members ID
		parEnd = temp.search(keyVal);
		memID = temp.substring(0,parEnd);
		temp = temp.substring(parEnd+1);
		setCookie('mid', memID, 30);
		
		// get membership (Group) ID
		parEnd = temp.search(keyVal);
		grpID = temp.substring(0,parEnd);
		temp = temp.substring(parEnd+1);
		setCookie('gid', grpID, 30);
		
		// Set Menu State
		if((role & 1) == 1){		// Admin Role
			Ext.getCmp('mnuAdmin').setVisible(true);
		}
		if((role & 4) == 4){		// Treasure Role
			Ext.getCmp('mnuTresManageMember').setVisible(true);
		}
		
		//Determine the state settings
		st = getCookie('st');
		if(Ext.getCmp('rdUsername').getValue()) st1 = '1';
		if(Ext.getCmp('rdPassword').getValue()) st1 = '2';
		if(Ext.getCmp('rdNone').getValue()) st1 = '';
		
//		if(st != st1){
			setCookie('st', st1, 90);
			if(st1 == '1'){
				setCookie('lid', logName, 90);
				setCookie('ep', '', 90);
			}
			else if(st1 == '2'){
				setCookie('lid', logName, 90);
				un = logName.toLowerCase();
				ep = doSecure(un, lip);
				setCookie('ep', ep, 90);
			}
			else{
				setCookie('lid', '', 90);
				setCookie('ep', '', 90);
			}
//		}
		lip = '';
	    
	    //Setup Menus for Login
	    menuState(true);
	}
	else{
		alert(temp);
		menuState(false);
		lip = '';
	}
		
};

function logoffsuccess(response){
	
	// Get returned message
	temp = response.responseText;
	
	// Get status of returned value
	returnStatus = temp.substring(temp.search(':')+1,temp.search(','));
	
	// Hide Menu Items
	Ext.getCmp('mnuAdmin').setVisible(false);
	Ext.getCmp('mnuTresManageMember').setVisible(false);
	if(returnStatus == 'true') {
		Ext.getCmp('userName').setText('');
	}
	lip = '';
	setCookie('rid', 0, 30);
	
	// Shutdown any Priveleged Menus
	privMenuShutdown;
};

function logfailed(response){
	
	// Get returned message
	temp = response.responseText;
	
	alert('Login Failed, please try again.');
	menuState(false);
	setCookie('rid', 0, 30);
	lip = '';
	
	// Shutdown any Priveleged Menus
	privMenuShutdown;
};

// Shutdown any priveleged Menus that may be exposed
function privMenuShutdown(){
	Ext.getCmp('mnuTresManageMember').setVisible(false);
	Ext.getCmp('mnuAdmin').setVisible(false);

}

	//================================================================
	//======================== Main Menu Bar =========================
	//================================================================

	// Create Main Menu Object
	var mainMenu = new Ext.Toolbar({
		baseCls: 'x-menu',
		autoWidth: true,
		id: 'mainMenu',
		items: [{
			text:'Our Club',
			iconCls: 'bmenu',
			arrowAlign: 'bottom',
			menu: menuAbout
			},'-',{
				text:'Facilities',
				iconCls: 'bmenu',
				arrowAlign: 'bottom',
				menu: menuFacilities  	// assign menu by instance
			},'-',{
				text:'Events',
				iconCls: 'bmenu',
				arrowAlign: 'bottom',
				menu: menuEvents  		// assign menu by instance
			},'-',{
				text:'Management',
				iconCls: 'bmenu',
				arrowAlign: 'bottom',
				menu: menuManagement  	// assign menu by instance
			},'-',{
				text:'Committees',
				id: 'mnuCommittees',
				iconCls: 'bmenu',
				arrowAlign: 'bottom',
				disabled: menuDisable,
				menu: menuCommittees  	// assign menu by instance
			},'-',{
				text:'Members',
				id: 'mnuMembers',
				iconCls: 'bmenu',
				arrowAlign: 'bottom',
				disabled: menuDisable,
				menu: menuMembers  		// assign menu by instance
			},'-',{
				text:'Publications',
				iconCls: 'bmenu',
				arrowAlign: 'bottom',
				menu: menuPublications  // assign menu by instance
			},'-',{
				text:'Links',
				iconCls: 'bmenu',
				arrowAlign: 'bottom',
				menu: menuLinks  		// assign menu by instance
			},'->',{
				xtype: 'label',
				id: 'userName',
				text:''
			},'-','-',{
				xtype: 'button',
				id: 'logbutton',
				iconCls: 'bmenu',
				text:'Log-in',
				arrowAlign: 'bottom',
				height: 35,
				width: 80,
				handler: function(){
					if (Ext.getCmp('logbutton').getText() == 'Log-in'){
						var win = new Ext.Window({
						    layout: 'absolute',
						    title: 'Please Login',
						    width: 270,
						    height: 325,
						    html: '<CENTER>Forgotten or misplaced<BR>your username or password<BR><A href="/password.html">click here</CENTER></A>',
						    closeAction: 'hide',
						    deferredRender: false,
							shadow: true,
							shadowOffset: 10,
						    border: true,
							items: [{
					            xtype: 'label',
					            text: 'Username:',
					            x: 50,
					            y: 68,
					            width: 150
							},{
					            xtype: 'textfield',
					            id: 'username',
					            emptyText: 'Enter Username',
					            name: 'user-name',
					            maskRe: /[^`^/^\\]/,
					            x: 50,
					            y: 85,
					            width: 150
							},{
					            xtype: 'label',
					            text: 'Password:',
					            x: 50,
					            y: 118,
						        width: 150
							},{
					            xtype: 'textfield',
					            id: 'password',
					            inputType: 'password',
					            name: 'password',
					            maskRe: /[^`^/^\\]/,
					            x: 50,
					            y: 135,
						        width: 150
							},{
					            xtype: 'radio',
					            id: 'rdUsername',
					            name: 'pwSave',
					            x: 50,
					            y: 170
							},{
					            xtype: 'label',
					            text: 'Only Save Username',
					            x: 67,
					            y: 173,
						        width: 150
							},{
					            xtype: 'radio',
					            id: 'rdPassword',
					            name: 'pwSave',
					            x: 50,
					            y: 190
							},{
					            xtype: 'label',
					            text: 'Save Both',
					            x: 67,
					            y: 193,
						        width: 150
							},{
					            xtype: 'radio',
					            id: 'rdNone',
					            name: 'pwSave',
					            checked: true,
					            x: 50,
					            y: 210
							},{
					            xtype: 'label',
					            text: 'Do Not Save',
					            x: 67,
					            y: 213,
						        width: 150
							}],
						    buttons: [{
						        text: 'Login',
						        id: 'btnLogin',
						        handler: function(){
						    		loginWindow(win);
					            	win.hide();
					        	}
						    },{
						        text: 'Cancel',
						        id: 'btnLogCancel',
						        handler: function(){
						            win.hide();
						        }
						    }]
						});
						win.show(this);
						
						// Setup Login based on Previous Settings
						st = getCookie('st');
						un = getCookie('lid');
						if( st == '1' ){		// Saved Username only
							Ext.getCmp('rdUsername').setValue(true);
							Ext.getCmp('username').setValue(un);
						}
						else if( st == '2'){	// Saved Username & Password
							Ext.getCmp('rdPassword').setValue(true);
							Ext.getCmp('username').setValue(un);
							un = un.toLowerCase();
							ep = getCookie('ep');
							pw = doUnsecure(un, ep);
							Ext.getCmp('password').setValue(pw);
						}
					}
					else{
						Ext.getCmp('logbutton').setText('Log-in');
						menuState(false);
						
						// Log-Off
						Ext.Ajax.request({
							waitMsg: 'Logging off...',
							showLoadIndicator: true,
							url: scriptPath + "authacc.php?action=logoff",
							success: logoffsuccess,
							failure: logfailed
						})
					}
				}
			}]
	});

	//================================================================
	//===================== Verify Login Status ======================
	//================================================================

	// Get Session Information from Server
	Ext.Ajax.request({
		url: scriptPath + "authacc.php?action=session&name=auth",
		success: function(response){
		
			// Define Variables explicitly	
			var role = new Number(0);
		
			// Get Authentication Response	
			temp = response.responseText;
		
			// Get Login State
			parEnd = temp.search(keyVal);
			logState = temp.substring(0,parEnd);
			temp = temp.substring(parEnd+1);
			
			// Get Role
			parEnd = temp.search(keyVal);
			role = temp.substring(0,parEnd);
			
			// Set Menu State
			if(logState=='yes'){
				loggedIn = true;
				menuState(true);
				Ext.getCmp('userName').setText('Welcome ' + getCookie('firstName'));
				if((role & 1) == 1){		// Admin Role
					Ext.getCmp('mnuAdmin').setVisible(true);
				}
				if((role & 4) == 4){		// Treasure Role
					Ext.getCmp('mnuTresManageMember').setVisible(true);
				}
			}
			else{
				menuState(false);
			}
    	},
    	failure:  function(response){ 
			menuState(false);
			setCookie('rid', 0, 30);
    	}
	})

