Ext.onReady(function(){

    Ext.QuickTips.init();
    
    // turn on validation errors beside the field globally
    Ext.form.Field.prototype.msgTarget = 'side';

   /*
    * ================  Password Verification =======================
    */
    login = new Ext.form.TextField({
				fieldLabel: 'Login',
				name:  'Login',
				id:    'Login',
				width:200,
				allowBlank:false
			});	
    password = new Ext.form.TextField({
				fieldLabel: 'Password',
				name:  'Password',
				id:    'Password',
				 inputType: 'password', 
				width:200,
				allowBlank:false
			});				

    login.on('specialkey',function(f,e){
        if (e.keyCode == 13){
            save();
        }
    });

    password.on('specialkey',function(f,e){
        if (e.keyCode == 13){
            save();
        }
    });
    
    
    
    var loginPanel = new Ext.FormPanel({
      labelWidth: 50,
      frame: true,
      title: 'Password Verification',
      bodyStyle:'padding:5px 5px 0',
      width: 300,
      height: 130,
      monitorValid:true,  // check validation
      applyTo: divLogin, 	      
      items: [
	      login,
	      password
      ],
      buttons: [{
            text: 'Login',
            handler: function() {

							save();
		            	
          	}	
            
        }]
    
    });

    login.focus();
    function save() {
    	var conn = new Ext.data.Connection();
		conn.request({
					    url: 'index.php',
					    method: 'POST',
					    params: { "action":"_login","password": password.getValue(),"login": login.getValue()},
						timeout: 10000000,
					    success: function(responseObject) {
					    	
					    	eval(responseObject.responseText);
					    	
					    	if (logged==1) {
					    		document.location.href='index.php?action=menu';
					    	} else {
								alert('Errore, login o pasword non corrette'),
					    		document.location.href='index.php?action=login';
					    	}
					    },
					    failure: function(responseObject){
					     		alert("ERROR: "+responseObject.responseText);
					    }
			})     
    }
 /*  var winPanel = new Ext.Panel({
      width: 500,
      height: 400,
      frame: true,
      applyTo: divLogin, 	      
      items: [
		loginPanel
      ]    
    });
*/
////////////// MAIL
//    

	emailPwd= new Ext.form.TextField({
		fieldLabel: 'Input your e-mail to receive your password',
		name:  'email',
		id:    'email',
		vtype: 'email',
		width:220,
		allowBlank:false
	});			


	emailPwd.on('specialkey',function(f,e){
        if (e.keyCode == 13){
        	sendMailPwd();
        }
    });


var emailPanel = new Ext.FormPanel({
labelWidth: 250,
frame: true,
labelAlign: 'top',
title: 'Password Forgotten?',
bodyStyle:'padding:5px 5px 0',
width: 300,
height: 120,
monitorValid:true,  // check validation
applyTo: divHelpMail, 	      
items: [
  emailPwd
],
buttons: [{
    text: 'Send',
    handler: function() {

					sendMailPwd();
            	
  	}	
    
}]

});


function sendMailPwd() {
	var conn = new Ext.data.Connection();
	conn.request({
			    url: 'index.php',
			    method: 'POST',
			    params: { "action":"sendMailPwd","emailPwd": emailPwd.getValue()},
				timeout: 10000000,
			    success: function(responseObject) {
			    	
			    	//eval(responseObject.responseText);
			    	
					alert(responseObject.responseText);

			    },
			    failure: function(responseObject){
			     		alert("ERROR: "+responseObject.responseText);
			    }
	})     
}    

   

});