Ext.onReady(function() {
	win = new Ext.Window({
		el: 'viewport',
		layout: 'fit',
		constrain: true,
		closable: false,
		resizable: false,
		draggable: false,
		title: Settings.title,
		autoHeight: true,
		iconCls: 'headerIcons-appWindow',
		width:350,
		bodyStyle:'padding:20px;padding-left:35px;padding-right:35px;background-color:white',
		items: [
			loginForm = new Ext.form.FormPanel({
		        baseCls: 'x-plain',
				labelAlign: 'right',
		        defaultType: 'textfield',
				autoHeight: true,
		        items: [{
					id: 'usr',
		            fieldLabel: labels.username,
		            name: 'username',
					labelStyle: 'white-space:nowrap',
		           	width:150
		        },{
					id: 'pass',
		            fieldLabel: labels.password,
					labelStyle: 'white-space:nowrap',
		            name: 'password',
					inputType: 'password',
		            width:150
		        },{
					xtype: 'hidden',
		            name: 'redirectAfterLogin',
					value: redirectAfterLogin
		        },
				{
					id: 'lang',
					xtype: 'combo',
					fieldLabel: '&nbsp;',
					labelSeparator: '',
					autoCreate:true,
					mode: 'local',
					displayField:'n',
					valueField:'k',
					hiddenName:'language',
					name: 'language',
					editable: false,
					triggerAction:'all',
				 	disableKeyFilter: true,
					forceSelection:true,
					value: selectedLang,
					width:100,
					store: new Ext.data.SimpleStore({
						fields: ['n', 'k'],
						data: Languages
					}),
					listeners: {
						select: function(el) {
							usrName = Ext.getCmp('usr').getValue();
							if (!usrName || usrName.length == 0) {
								document.location.href = URLRoot+'/?language='+encodeURIComponent(el.getValue());
							}
						}
					}
				}
				]
		    })
		],
		buttons: [{
	    	text: '&laquo; '+labels.signup,
			hidden: !signUpEnabled,
			handler: function() {
				document.location.href = signUpURL+'&language='+encodeURIComponent(Ext.getCmp('lang').getValue());
			}
	    },{
			text: labels.login,
			handler: submitForm
		}]
	});
	function submitForm() {
		loginForm.getForm().submit({
			url:loginURL, 
			waitMsg: labels.waitMsg,
			waitTitle: labels.waitTitle,
			failure: function(frm, act) {
				Ext.Msg.show({
				   title:'',
				   msg: act.result.error,
				   buttons: Ext.Msg.OK,
				   modal: false
				});
			},
			success: function() {
				document.location.href = URLRoot;
			}
		});
	}
	win.show();
	win.anchorTo(Ext.get('theBODY'), 'c-c');
	new Ext.KeyMap("usr", {
	    key: Ext.EventObject.ENTER,
	    fn: submitForm
	});
	new Ext.KeyMap("pass", {
	    key: Ext.EventObject.ENTER,
	    fn: submitForm
	});
});
