Ext.onReady(function(){
	
    Ext.QuickTips.init();
	
    var admin_login = new Ext.FormPanel({
        labelWidth:80,
        url: "login_db.asp",
        frame:true,
        title:'Login Form',
        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:'Username',
			name:'loginUsername',
			allowBlank:false
		},{
			fieldLabel:'Password',
			name:'loginPassword',
			inputType:'password',
			allowBlank:false
		}],
		
		
        buttons:[{
			text:'Login',
			formBind: true,
			// Function that fires when user clicks the button
			handler:function(){
				admin_login.getForm().submit({
					method:'POST',
					waitTitle:'Connecting',
					waitMsg:'Sending data...',
					
					success:function(){ 
						Ext.Msg.alert('Status', 'Login Successful!', function(btn, text){
							if (btn == 'ok'){
								//var redirect = location.href;
								location.reload();
							}
						});
					},
					
					failure:function(form, action){ 
						if(action.failureType == 'server'){ 
							obj = Ext.util.JSON.decode(action.response.responseText); 
							Ext.Msg.alert('Login Failed!', obj.errors.reason); 
						}
						else{
							Ext.Msg.alert('Warning!', 'Authentication server is unreachable : ' + action.response.responseText); 
						}
						admin_login.getForm().reset();
					}
				});
			}
		},{
			text: "Cancel",
			handler:function(){
				admin_login.getForm().reset();
				history.go(-1);
			}
		}] 
	});
 
 
	// This just creates a window to wrap the login form. 
	// The login object is passed to the items collection.       
    var admin_login_win = new Ext.Window({
        layout:'fit',
        width:300,
        height: 150,
        closable: false,
        resizable: false,
        plain: true,
		modal: true,
        border: false,
        items: [admin_login]
	});
	admin_login_win.show();
	
	
});


