var userName;
var password;

function controlsInit()
{
	userName = new Ext.form.TextField(
	{
		allowBlank : false,
		applyTo: userNameID,
		tabIndex: 1,
		vtype: 'email',
		width: 200
	});
	Ext.form.FormPanel.controls.add('userName', userName);
	
	password = new Ext.form.TextField(
	{
		allowBlank : false,
		applyTo: passwordID,
		enableKeyEvents: true,
		tabIndex : 2,
		width: 200
	});
	Ext.form.FormPanel.controls.add('password', password);
	
	password.on('blur', trimPassword);
	password.on('keypress', checkCapsLock);
	
	userName.focus();
}

function trimPassword()
{
	password.setValue(Ext.util.Format.trim(password.getValue()));
}

function checkCapsLock(el, e)
{
	var keyCode = e.getKey();
	var isShiftPressed = e.shiftKey;
   
	// Upper case letters are seen without depressing the Shift key
	// OR Lower case letters are seen while depressing the Shift key, therefore Caps Lock is on
	if ((keyCode >= 65 && keyCode <= 90 && !isShiftPressed)
		|| (keyCode >= 97 && keyCode <= 122 && isShiftPressed)) 
	{
		password.markInvalid('CAPS LOCK key is on! This may cause your password to be entered incorrectly.');
	}
	else
	{
		password.clearInvalid();
	}
}
