Ext.onReady(function(){
    Ext.QuickTips.init();

    var login = new Ext.FormPanel({ 
        labelWidth:80,
	method:'POST',
        url:'/cgi-bin/login.pl', 
        frame:true, 
        title:'Logowanie do max.edysk.pl', 
        defaultType:'textfield',
	monitorValid:true,
//	keys: [{key: [10,13], fn: function(){ Ext.getCmp('loginbutton').fireEvent('click')}}],
        items:[{ 
                fieldLabel:'Login', 
                name:'loginUsername', 
                allowBlank:false,
		blankText:'Proszę wpisać login'
            },{ 
                fieldLabel:'Hasło', 
                name:'loginPassword', 
                inputType:'password', 
                allowBlank:false,
		blankText:'Proszę wpisać hasło'
            }, new Ext.Panel({html: '<center><a href="/zapomnialem_hasla.html">Zapomniałem hasła</a></center>'})],
 
        buttons:[{ 
		id: 'loginbutton',
                text:'Zaloguj',
                formBind: true,	
                handler:function(){ 
                    login.getForm().submit({ 
                        method:'POST', 
                        waitTitle:'Logowanie', 
                        waitMsg:'Proszę czekać...',
                        success:function(form, action){ 
				obj = Ext.util.JSON.decode(action.response.responseText);
//                        	Ext.Msg.alert('Logowanie', 'Kliknij aby przejść do max.edysk' , function(btn, text){
//				   if (btn == 'ok'){
		                        var redirect = 'http://maxnew.edysk.pl/cgi-bin/core.pl?z='+obj.ret.sid; 
		                        window.location = redirect;
//                                   }
//			        });
                        },
 
                        failure:function(form, action){ 
//                            if(action.failureType == 'server'){
//                                obj = Ext.util.JSON.decode(action.response.responseText); 
                                Ext.Msg.alert('Logowanie', 'Nieprawidłowy login lub hasło!');
				//window.location = "http://www.edysk.pl/service.html";
//                            }else{ 
//                                Ext.Msg.alert('Uwaga!', 'Serwer nie odpowiada: ' + obj.error.reason); 
//                            } 
                            login.getForm().reset(); 
                        } 
                    }); 
                }
	

            }],
	    keys: [{
		key: Ext.EventObject.ENTER,
		fn: function() { 
		    if(login.getForm().isValid()) {
			Ext.getCmp("loginbutton").handler.call(Ext.getCmp("loginbutton").scope); 
		    }
		}
	    }]
 
    });
 
 
    var win = new Ext.Window({
        layout:'fit',
        width:300,
        height:150,
	modal: true,
	closeAction: 'hide',
        closable: true,
        resizable: false,
        plain: true,
        border: false,
        items: [login]
	});



    var button = Ext.get('clickLogin');
//    var button2 = Ext.get('clickReg');
    button.on('click', function() {
	win.show();
    });

    if(document.location == "http://maxnew.edysk.pl/index.html") {
	win.show();
    }

    if(document.location == "http://maxnew.edysk.pl/index2.html") {
	win.show();
    }

});     			