Ext.SSL_SECURE_URL="resources/images/default/s.gif"; 
Ext.BLANK_IMAGE_URL="resources/images/default/s.gif";

Login = function(){

	return{
		Init:function(){
			Ext.QuickTips.init();
			
			var passwordField = new Ext.form.TextField({
            	fieldLabel: 'Password',
                name:'password',
                width:100,
                allowBlank:false,
				inputType:'password'//,
				//enableKeyEvents:true
           	});
			
			var frm = new Ext.form.FormPanel({
                bodyStyle:{
                    backgroundColor:'black',
                    color:'white',
                    padding:'15px',
                    paddingLeft:'120px',
                    paddingTop:'170px',
                    backgroundImage:'url(/images/LoginImageVenue.png)',
                    backgroundRepeat: 'no-repeat' 
                   
                    //paddingTop:'150px'
                },
                border:false,
                labelWidth:80,
                height:300,
                items:[
                    new Ext.form.TextField({
                        fieldLabel: 'User Name',
                        name:'username',
                        id:'username',
                        width:100,
                        allowBlank:false
                    }),
                    passwordField
				]
            });
             
			 var win = new Ext.Window({
                title:'Gaming Device Manager',
                width:510,
                height:300,
				//modal:true,
                closable:false,
                constrain:true,
				draggable:false,
                layout:'fit',
				items:frm,
                focus:function(){
                	try {
                		Ext.get('username').focus();
                	} catch(err){
                		
                	}
                }
            });
                        
           
            win.addButton({
                text: 'Login',
                tooltip:'Login to the Gaming Device Manager',
                disabled:false,
                handler: function(){
                	frm.form.submit({
                        url:'auth/LoginVenue', 
                        success : function(f,a){
                        	if (a.result.success) {
								win.close();
								window.location.reload();//='http://gdm.local/venues';
							} else {
								Ext.MessageBox.alert('Failed','Login Failed');
							}
                        },
                    	failure : function(f,a){ 
                        	if(a.failureType == 'server'){
                                if(a.result.error){
                                    Ext.Msg.show({
									   title:'Failure Server',
									   msg: a.result.error,
									   buttons: Ext.Msg.OK,
									   icon: Ext.MessageBox.ERROR
									});
                                }
                            } else {
                                Ext.MessageBox.alert('Failed Client','Validation Failed. Please make sure required fields are entered');
                            }
                        },
                    
                        reset : false
                    });
                }
            });
                       
            win.show();
			
			//Ext.getCmp('requestlogin').getEl().alignTo(win.body.id, "tr", [-135, 25]);
			
			var box = Ext.get(win.body.id); // the fancy gray box for masking
			frm.on({
				beforeaction: function(form, action){
					//alert('before action');
					var msg = action.type == 'load' ? 'Please Wait...' : 'Please Wait...';
					box.mask(msg, 'x-mask-loading');
				},

				actioncomplete: function(form, action){
					box.unmask();
					if(action.type == 'load'){
						//alert(action.result.data.partno);
					}
				},

				actionfailed: function(form, action){
					box.unmask();
				}
			});
			
			passwordField.on('specialkey', function(field, e){

				if(e.getKey() == e.ENTER){
					frm.form.submit({
                        url:'auth/LoginVenue', 
                        success : function(f,a){
                        	if (a.result.success) {
								win.close();
								window.location.reload();//='http://gdm.local/venues';
							} else {
								Ext.MessageBox.alert('Failed','Login Failed');
							}
                        },
                    	failure : function(f,a){ 
                        	if(a.failureType == 'server'){
                                if(a.result.errorMsg){
                                    Ext.MessageBox.alert('Failure server', a.result.errorMsg);
                                }
                            } else {
                                Ext.MessageBox.alert('Failed Client','Validation Failed. Please make sure required fields are entered');
                            }
                        },
                    
                        reset : false
                    });
				}
			},this);
			
			
		}

	};
}();



Ext.onReady(Login.Init, Login, true);
