Ext.ux.woos.Login=function()
{
	var langCombo, win;
	
	function checkLogin()
	{
		var lMask = new Ext.LoadMask(win.el, {msg: "Loading...", removeMask: true});
				lMask.show();
				Ext.QuickTips.init();		
				login_form.getForm().submit({
					success: function(form, a) {

			var path = window.location.pathname,
			path = path.substring(0, path.lastIndexOf('/') + 1);
			set_cookie('key', a.result.key, '', path, '', '' );
			set_cookie('user', a.result.user, '', path, '', '' );
			set_cookie('memberName', a.result.name, '', path, '', '' );
			set_cookie('memberType', a.result.type, '', path, '', '' );

			self.location.href = "index.php"; 
				},
				failure: function(form, response){
					lMask.hide();
					//Ext.Msg.show({title: "Error", msg: "Wrong username or password!", buttons: Ext.Msg.OK, icon: Ext.Msg.ERROR });
				}
			    });
	}
	
	
	langCombo = new Ext.form.ComboBox({
		fieldLabel: "Language",
		name: "language",
		store: new Ext.data.SimpleStore({
	        fields: ['language'],
	        data: ['English', 'Deutsch', 'Italiano'],
	        expandData: true
	    }),
	    displayField: 'language',
	    value: 'English',
	    triggerAction: 'all',
	    mode: 'local',
	    readOnly: true,
	    width: 200,
		style: "margin:0px 0px 0px 0px;",
		labelStyle: "margin: 0px 0px 0px 0px;"
	});

	var logoPanel = new Ext.Panel({
	        baseCls: 'x-plain',
	        height: 70,
	        id: 'login-logo',
                region: 'center'
	});
	
	var login_form = new Ext.FormPanel({
		frame: false,
		baseParams: {
		   module: 'login'
		},
		url: "./php/login.php",
		buttonAlign: "right",
                labelAlign: "right",
	        height: 70,
		id: 'login-form',
                 region: 'south',
		labelWidth:120,
		baseCls: 'x-plain',
		defaults: {
         	width: 200
		},
		defaultType: 'textfield',
		items: [
		{
			xtype: "textfield",
			fieldLabel: "Username",
			name: "user",
			width: 200,
			style: "margin:0px 0px 0px 0px;",
			labelStyle: "margin: 0px 0px 0px 0px;"
		},
		{
			xtype: "textfield",
			fieldLabel: "Password",
			name: "pass",
			inputType: "password",
			width: 200,
			style: "margin:0px 0px 0px 0px;",
			labelStyle: "margin: 0px 0px 0px 0px;"
		}
		//,langCombo
		],
		keys:({
              key: Ext.EventObject.ENTER,
              fn: checkLogin,
              scope: this
        })

		

	});
	
	
	

	
	
	 win = new Ext.Window({
		renderTo: Ext.getBody(),
		title: "Login",
		id: 'login-win',
		layout: 'border',
		draggable:true,
		closable:false,
		resizable:false,
		width: 480,
		height: 250,
		items: [logoPanel, login_form],
		buttons: [
		{
			xtype: "tbbutton",
			text: "Login",
			minWidth:80,
			minHeight:50,
			handler: function()
			{
				
				
				checkLogin();
			},
			icon: "./images/ok.png",
			cls: "x-btn-text-icon"
		}]
	});

			form = login_form.getForm();
			
			login_form.on('render', function(){
				var f = form.findField('user');
				
				if(f){
					f.focus();
				}
			}, this, {delay: 200});


	win.show();
	
};

Ext.BasicForm.prototype.afterAction=function(action, success){
	this.activeAction = null;
	var o = action.options;
	if(o.waitMsg){
		Ext.MessageBox.updateProgress(1);
		Ext.MessageBox.hide();
	}
	if(success){
		if(o.reset){
			this.reset();
		}
		Ext.callback(o.success, o.scope, [this, action]);
		this.fireEvent('actioncompleted', this, action);
	}else{
		Ext.callback(o.failure, o.scope, [this, action]);
		this.fireEvent('actionfailed', this, action);
	}
}
