// Path to the blank image must point to a valid location on your server
Ext.BLANK_IMAGE_URL = 'js/ext-3.0.0/resources/images/default/s.gif';

// Main application entry point
Ext.onReady( function() {
	
	Ext.QuickTips.init();
	
	
	var msg = function(title, msg) {
	
		Ext.Msg.show({
			title: title,
			msg: msg,
			minWidth: 200,
			modal: true,
			icon: Ext.Msg.INFO,
			buttons: Ext.Msg.OK
		});
	};
	
	var loginForm = new Ext.form.FormPanel({
		frame:true,
		width:260,
		labelWidth:60,
		defaults: {
			width: 165
		},
		items: [
			new Ext.form.TextField({
				id:"username_",
				fieldLabel:"Username",
				allowBlank:false,
				blankText:"Inserire lo username"
			}),
		
			new Ext.form.TextField({
				id:"password_",
				fieldLabel:"Password",
				inputType: 'password',
				allowBlank:false,
				blankText:"Inserire la password"
			})
		],
		buttons: [{
			text: 'Login',
			handler: function(){
				if(loginForm.getForm().isValid()){
					var username = Ext.get('username_').getValue();
					var password = Ext.get('password_').getValue();
					utenteManagerDWR.userExists(username, password, {
						callback: function(exists){
							if(exists){
								document.frmLogin.username.value=username;
								document.frmLogin.password.value=password;
								document.frmLogin.submit();
							} else {
								Ext.MessageBox.alert('Error', '<span class=sfont>' + 'Username o password errati' + '</span>');
							}
						},
						errorHandler: function(errorString, exception){
							Ext.MessageBox.alert('Error', '<span class=sfont>' + 'Username o password errati' + '</span>');
						}
						
					});
					
					
					
				}
			}
		},{text:'Home page', 
		   handler:function(){
			window.location = 'index.jsp';
			
		}}]
	});
	
	var loginWindow = new Ext.Window({
		title: 'CondivisiHome Login',
		layout: 'fit',
		height: 140,
		width: 260,
		closable: false,
		resizable: false,
		draggable: false,
		modal:true,
		items: [loginForm]
	});
	
	loginWindow.show();
	
});// Ext.onReady

