Ext.onReady(function(){
	Ext.QuickTips.init();
  	var redirect ="php/forms/GaravotBackend.php"; 	 
    var login = new Ext.FormPanel({ 
        labelWidth: 80
        ,url: "php/forms/Login.php" 
        ,frame: true
        ,title: "Autenticazione Garavot" 
        ,defaultType: "textfield"
		,monitorValid: true
        ,items:[{ 
                fieldLabel: "Username"
                ,name: "loginUsername"
                ,allowBlank: false 
            },{ 
                fieldLabel: "Password"
                ,name: "loginPassword"
                ,inputType: "password"
                ,allowBlank: false 
            }]  
        ,buttons:[{ 
                text: "Login",
                formBind: true,	 
                handler:function(){ 
                    login.getForm().submit({ 
                        method: "POST"
                        ,waitTitle: "Connessione"
                        ,waitMsg: "Invio dati..."
                        ,success:function(){window.location = redirect;}
                        ,failure:function(form, action){ 
                            if(action.failureType == "server"){ 
                                obj = Ext.util.JSON.decode(action.response.responseText); 
                                Ext.Msg.alert("Errore!", obj.errors.reason); 
                            }else{ 
                                Ext.Msg.alert("Attenzione!", "Server di autenticazione è non raggiungibile!"); 
                            } 
                            login.getForm().reset(); 
                        } 
                    }); 
                } 
            }] 
    });      
    var win = new Ext.Window({
        layout: "fit"
        ,width: 300
        ,height: 150
        ,closable: false
        ,resizable: false
        ,plain: true
        ,border: false
        ,items: [login]
	});
	win.show();
});
