Ext.onReady(function(){
	Ext.QuickTips.init();

	function submitSuccess() {
		ShowStatusGood('Login Successful');
		var redirect = 'index.php?mode=admin';
		window.location = redirect;
	}

	function submitFailure(form, action){
		if(action.failureType == 'server'){
			obj = Ext.util.JSON.decode(action.response.responseText);
			ShowStatusBad(obj.errors.reason); 
		}else{
			ShowStatusBad('Serer is unreachable: ' + action.response.responseText); 
		}
		login.getForm().reset();
	}
	
	// Create a variable to hold our EXT Form Panel.
	// Assign various config options as seen.
	var login = new Ext.FormPanel({
		labelWidth:80,
		//url:'http://www.mayflatl.org/index.php?mode=login',
		url:'index.php?mode=wtf2',
		frame:true,
		title:'Please Login',
		width:400,
		padding:200,
		defaultType:'textfield',
		monitorValid:true,

		// Specific attributes for the text fields for username / password.
		// The "name" attribute defines the name of variables sent to the server.
		items:[{
			fieldLabel:'Email',
			name:'email',
			allowBlank:false ,
			width:250
		},{
			fieldLabel:'Password',
			name:'password',
			inputType:'password',
			allowBlank:false
		}],
		// All the magic happens after the user clicks the button
		buttons:[{
			text:'Login',
			formBind: true,
			// Function that fires when user clicks the button
			handler:function(){
				login.getForm().submit({
					method:'POST',
					waitTitle:'Authenticating User',
					waitMsg:'Please Wait...',

					// Functions that fire (success or failure) when the server responds.
					// The one that executes is determined by the
					// response that comes from login.asp as seen below. The server would
					// actually respond with valid JSON,
					// something like: response.write "{ success: true}" or
					// response.write "{ success: false, errors: { reason: 'Login failed. Try again.' }}"
					// depending on the logic contained within your server script.
					// If a success occurs, the user is notified with an alert messagebox,
					// and when they click "OK", they are redirected to whatever page
					// you define as redirect.

					success:submitSuccess,
					failure:submitFailure
				});
			}
		}]
	});


	login.render('loginfrm');

});
