
var form = function(){
		return {
			
			login :function(){
				var loginForm = new Ext.FormPanel({
									  id:'login-form',
									  labelWidth:75,
									  frame:false,
									  border:false,
									  buttonAlign:'center',
									  width:250,
									  items:[{
											xtype:'textfield',
											fieldLabel:'Username',
											name:'username',
											id:'username'
										  },{
											xtype:'textfield',	
											fieldLabel:'Password',
											name:'password',
											id:'password',
											inputType:'password'
										  }],
									  buttons:[{
										text:'Login',
										handler:function(){
											form.auth();
										}
									  }]
						});
						
					return loginForm;
			},
			
			auth : function(){
				
				
					Ext.getCmp('login-form').getForm().submit({
						waitMsg: "Please wait",
						waitTitle: "Validating...",
						url: base_url+"index.php/pica_pica/validate",
						method: "POST",
						success: function(){
							
									window.location.href = base_url+"index.php/pica_pica/order_form";	
						
							
						},
						failure: function (brokerForm, action) {
						   if (action.failureType == "server") {
							obj = Ext.util.JSON.decode(action.response.responseText); 
							
								Ext.MessageBox.show ({
								 title: "Error",
								 msg : obj.errors.reason,
								 buttons: Ext.MessageBox.OK,
								 icon: Ext.MessageBox.ERROR
								})
							
						   } else {
							Ext.MessageBox.show ({
							 title: "Error",
							 msg : "Please check all fields",
							 buttons: Ext.MessageBox.OK,
							 icon: Ext.MessageBox.ERROR
							})
						   }
						  }
						});
				
				
			}
			
		}
}()

