Login = function(){
    var dialog, form;
    return{
        Init:function(){
					   
		   Ext.QuickTips.init();
            Ext.form.Field.prototype.msgTarget = 'side';
            dialog = new Ext.BasicDialog('loginDialogId', {
                autoCreate: true,
                width: 380,
                height: 210,
                modal: true,
                closable:false,
                resizable:false,
                draggable:false,
                collapsible:false,
                title:'Criminal Tracking Login'            
            });
            dialog.body.dom.innerHTML="<div id='loginFormId'></div>";
            
            form = new Ext.Form({
                labelAlign: 'right',
                labelWidth: 85,
                buttonAlign: 'right',
                url:'login.aspx',
                baseParams:{module:'login'}
            });
            form.add(
                new Ext.form.TextField({
                    fieldLabel: 'Username',
                    name: 'user',
                    //vtype: 'username',
                    allowBlank:false,
					validateOnBlur:false
                }),        
                new Ext.form.TextField({
                    fieldLabel: 'Password',
                    name: 'pass',
                    //vtype: 'password',
                    defaultAutoCreate : {tag: "input", type: "password", size: "20", autocomplete: "off"},
                    allowBlank:false,
					validateOnBlur:false
                }),
				new Ext.form.TextField({
                    fieldLabel: 'Account#',
                    name: 'account',
					id: 'account',
                    allowBlank:false,
					validateOnBlur:false
				})
            );
            
			
			form.fieldset(
						  {clear: true, hideLabels:true},
							new Ext.form.Checkbox({
								boxLabel:'I agree to the to the <a href="terms.html" target="_new" >terms and conditions!</a>',
								name:'terms',
								width:'auto',
								id:'terms'
							})
						  
						  );
			
			
			form.addButton('Login', function()
				{
                	//set account number
					var account = document.getElementById('account').value;
					var terms= document.getElementById('terms').checked;
					if (terms)
					{
						Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
						Ext.state.Manager.set('Account_',account);
						form.submit({
						waitMsg:'Please Wait...',
						reset:false,
						success:Login.Success,
						scope:Login
                		} );
					}
					else
					alert("You must agree to the Terms & Conditions Before Accessing the Application");
            }, form);
			form.end();
            form.render('loginFormId');
            dialog.on('show', function(){form.items.item(0).focus();});
            dialog.show(document.body.getElementsByTagName('div')[0]);            
        },
        Success: function(f,a){
            
            if(a && a.result && typeof a.result.level == "number"){
                Login.level=a.result.level;
                dialog.destroy(true); 
				Ext.state.Manager.set('Jurisdiction_',a.result.jurisdiction);
				location.href="criminallayout.aspx";
				
            }
        }
    }
}();

Ext.onReady(Login.Init, Login, true);  