function LabelKeyPress(field, e)
{
	switch (get_code(e))
	{
		case 32:
			var option = elementFromid(field.htmlFor);
			if (option.onclick != undefined)
				option.onclick();
			break;
	}
	return true;
}
function SelectKeyPress(field, e) 
{
	switch (get_code(e))
	{
		case 13:
			if (field.form != undefined)
			{
				if (field.form.onsubmit == null || field.form.onsubmit())
				{
					field.form.submit();
				}
				return false;
			}
			break;
		default:
			return SortDropDownList(this,false);
	}
}


function SortDropDownList(dropdownlist,caseSensitive) {
	if (dropdownlist.options == undefined)
		return true;
		
	// check the keypressBuffer attribute is defined on the dropdownlist 
	if (dropdownlist.keypressBuffer == undefined) 
	{ 
		dropdownlist.keypressBuffer = ''; 
	} 
	// get the key that was pressed 
	var key = String.fromCharCode(window.event.keyCode); 
	dropdownlist.keypressBuffer += key;
	if (!caseSensitive) 
	{
		// convert buffer to lowercase
		dropdownlist.keypressBuffer = dropdownlist.keypressBuffer.toLowerCase();
	}
	// find if it is the start of any of the options 
		
	var optionsLength = dropdownlist.options.length; 
	for (var n=0; n < optionsLength; n++) 
	{ 
		var optionText = dropdownlist.options[n].text; 
		if (!caseSensitive) 
		{
			optionText = optionText.toLowerCase();
		}
		if (optionText.indexOf(dropdownlist.keypressBuffer,0) == 0) 
		{ 
			dropdownlist.selectedIndex = n; 
			return false; // cancel the default behavior since 
						// we have selected our own value 
		} 
	} 
	// reset initial key to be inline with default behavior 
	dropdownlist.keypressBuffer = key; 
	return true; // give default behavior 
} 
