function staffLogin() {
	function goIntranet(resp) {
		function forceNewPW(){
			var pwform = new Ext.form.FormPanel({
				id: 'forcepwform',
				width: 330,
				autoHeight: true,
				bodyStyle: 'padding: 10px;',
				border: false,
				frame: false,
				labelWidth: 150,
				items: [
				    new Ext.form.TextField({
				    	name: 'pw1',
				    	inputType: 'password',
				    	maxLength: 10,
				    	fieldLabel: 'Enter new password',
				    	minLength: 5
				    }),
				    new Ext.form.TextField({
				    	name: 'pw2',
				    	inputType: 'password',
				    	maxLength: 10,
				    	fieldLabel: 'Re-enter password',
				    	minLength: 5
				    })
				],
		        keys: [{
		        	key: [10,13],
		        	scope: this,
		        	handler: function(t, e){
		        		var target = Ext.EventObject.getTarget();
		        		Ext.EventObject.stopEvent();
		        		win.buttons[0].handler.call();
		        	}
		        }]
			});
			var win = new Ext.Window({
				title: 'New password required',
				width: 350,
				form: pwform,
				closable: false,
				closeAction: 'close',
				modal: true,
				autoHeight: true,
				items: [ 
				    new Ext.Panel({
				    	width: 330,
				    	autoHeight: true,
				    	border: false,
				    	bodyStyle: 'padding: 5px;',
				    	style: 'text-align: left;',
				    	frame: false,
				    	html: 'Welcome to ICCI\'s User Management System.  Since this is your '
				    		+'first time logging in you must change your password from the default '
				    		+'asigned when your account was created.  Please select something you '
				    		+'can remember.  It must be at between 5 and 10 characters in length and should '
				    		+'contain at least one number.'
				    }),
				    pwform
				],
				buttons: [{
				    xtype: 'button',
				    text: 'Save password',
				    handler: function(btn, e){
						var f = Ext.getCmp('forcepwform').getForm();
						if(f.isValid()) {
							var vals = f.getValues();
							if(vals.pw1 == vals.pw2){
								win.close();
								var updateData = {
									msg: json.msg,
									url: json.url,
									usernumber: json.usernumber,
									pw: vals.pw1
								};
								Ext.Ajax.request({
									url: "changePW.php",
									params: updateData,
									success: goIntranet,
									failure: function(resp){
										alert("Error occurred");
									}
								});
							} else {
								alert("Passwords do not match.  Please try again.");
								f.findField('pw1').focus(true, 250);
							}
						}
					},
					scope: win
				}],
				listeners: {
					show: function(){
						this.form.getForm().findField('pw1').focus(false, 250);
					}
				}
			});
			win.show();
		}
		var json = Ext.util.JSON.decode(resp.responseText);
		if(json.success) {
			user.number = json.usernumber;
			panel.close();
			if(json.forcepw) {
				forceNewPW();
			} else {
				Ext.Ajax.request({
					url: json.url,
					success: function(resp) {
						var json = Ext.util.JSON.decode(resp.responseText);
						switch(json.whatnow){
							case "managerspanel":
								var nextfunc = "managerPanel";
								if(Ext.isIE){
									window.open("intranet.php?panel="+nextfunc+"&usernum="+user.number, '', 'width=1084,height=798,scrollbars=1,menubar=1,location=0');
								} else {
									window.open("intranet.php?panel="+nextfunc+"&usernum="+user.number, '', 'width=1071,height=770,scrollbars=1,menubar=1,location=0');
								}
							break;
							case "intranetpanel":
								var nextfunc = "intranetPanel";
								if(Ext.isIE){
									window.open("intranet.php?panel="+nextfunc+"&usernum="+user.number, '', 'resizable=1, menubar=1,location=0');
								} else {
									window.open("intranet.php?panel="+nextfunc+"&usernum="+user.number, '', 'resizable=1, menubar=1,location=0');
								}
							break;
							case "adminpanel":
								var nextfunc = "adminPanel";
								window.open("intranet.php?panel="+nextfunc+"&usernum="+user.number, '', 'resizable=1, scrollbars=1, menubar=1,location=0');
							break;
							case "dataentry":
								var nextfunc = "dataEntryPanel";
								window.open("intranet.php?panel="+nextfunc+"&usernum="+user.number, '', 'width=836,height=670,menubar=1,location=0');
							break;
						}
					},
					failure: function(resp) {
						Ext.MessageBox.show({
							title: "Error Encountered",
							msg: "We have encountered an unexpected error and cannot proceed.  Contact Concepte and report this event.",
							buttons: Ext.MessageBox.OK
						});
					}
				});
			}
		} else {
			Ext.MessageBox.show({
				title: "Login Incorrect",
				msg: 'The login information you have provided is incorrect.  Please try again.',
				buttons: Ext.MessageBox.OK
			});
		}
		// submit.enable();
	}

	function submitLogin() {
		submit.disable();
		var f = Ext.getCmp('loginform').getForm();
		Ext.Ajax.request({
			url: 'validateLogin.php',
			form: 'logform',
			success: goIntranet,
			failure: function(response) {
				submit.enable();
				Ext.MessageBox.show({
					title: "Communcation Error",
					msg: 'Unable to communicate with remote server.  Check your internet connection and/or server status.',
					buttons: Ext.MessageBox.OK
				});
			}
		});
	}

	function winclose() {
		panel.close();
	}

	function formreset() {
		loginform.getForm().setValues({loginid: '', passwd: ''});
		loginform.getForm().findField('loginid').focus(true, 250);
	}

	var submit = new Ext.Button({
        text: "Login",
        scope: this,
		handler: submitLogin
	});
	
	var placeFocus = function(item){
		switch(item){
			case "loginid":
				loginform.getForm().findField('passwd').focus(true, 250);
			break;
			default:
				submitLogin();
			break;
		}
	}
        	
	var loginform = new Ext.form.FormPanel({
        id: 'loginform',
		formId: 'logform',
        border: false,
        frame: true,
        height: 125,
		defaults: {
			validationEvent: false
		},
        buttons: [submit],
        items: [{
			xtype: 'textfield',
            id: 'loginid',
            fieldLabel: 'Login ID',
            maxLength: 20,
			width: 140,
            itemCls: 'loginform',
            allowBlank: false,
            labelWidth: 200
        },{
            id: 'passwd',
			xtype: 'textfield',
            fieldLabel: 'Password',
            maxLength: 10,
			width: 140,
            itemCls: 'loginform',
            labelWidth: 200,
            allowBlank: false,
            inputType: 'password'
        }],
        keys: [{
        	key: [10,13],
        	scope: this,
        	handler: function(t, e){
        		var target = Ext.EventObject.getTarget();
        		Ext.EventObject.stopEvent();
        		placeFocus(target.name)
        	}
        }]
    });
    var panel = new Ext.Window({
        height: 150,
        width: 275,
        shadow: 'drop',
        shadowOffset: 20,
        resizable: false,
        title: 'ICCI System Login',
        closeAction: 'close',
        items: [loginform]
    });
    panel.on({
    	'close': {
    		fn: function() {
    			login.enable();
    		}
    	},
    	'show' : {
    		fn: function() {
    			login.disable();
    		}
    	}
    })
    panel.show();
    loginform.getForm().findField('loginid').focus(true, 250);
}

