// Browser detection 
	isIE = document.all;
	isNN = !document.all && document.getElementById;
	isN4 = document.layers;
	isNS6 = !document.all && document.getElementById;

// Popup Window Opener
function openPopUp(URL, w, h) {
		my_new_window = window.open(URL, "tool_popup", "height=" + h + ",width=" + w + ", resizable=1, statusbar=0, hotkeys=0,menubar=0,scrollbars=1,status=1,toolbar=0");
		my_new_window.resizeTo(w, h);
	   	my_new_window.focus();}

// Advances to next text field once max length is reached
function KeyPress(what,e,max,action) {
    if (document.layers) {
        if (e.target.value.length >= max)
            eval(action);
    }
    else if (document.all) {
        if (what.value.length > (max-1))
            eval(action);
    }
}
// toggles display/hide for a container
	function toggle(id){
	   if (document.all){
	     if(document.all[id].style.display == 'none'){
	       document.all[id].style.display = '';
	     } else {
	       document.all[id].style.display = 'none';
	     }
	  return false;
	   } else if (document.getElementById){
	     if(document.getElementById(id).style.display == 'none'){
	       document.getElementById(id).style.display = 'block';
	     } else {
	       document.getElementById(id).style.display = 'none';
	     }
	  return false;
	   }
	 }
// Inserts the sort parameters into a textarea field
function insertSortParam() {
 	if (document.qb.params_feed_sort_order[0].checked == true) {
		sort_order = document.qb.params_feed_sort_order[0].value;
	} else {
		sort_order = document.qb.params_feed_sort_order[1].value;
	}
	
	text = document.qb.params_feed.value + ' ' + sort_order + ', ';
	if (document.qb.sort_params.createTextRange && document.qb.sort_params.caretPos) {
		var caretPos = document.qb.sort_params.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == '' ? text + ' ' : text;
		document.qb.sort_params.focus();
	} else {
	document.qb.sort_params.value  += text;
	document.qb.sort_params.focus();
	}
}
// Validates fields to be all numeric
function validateNumeric(field) {
	var valid = "0123456789"
	var ok = "yes";
	var temp;
	for (var i=0; i<field.value.length; i++) {
		temp = "" + field.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") ok = "no";
	}
	if (ok == "no") {
		alert("Invalid entry!  Only numbers are accepted!");
		field.focus();
		field.select();
	   }
	}

	function move(AllItems, FaveItems) {
		var arrAllItems = new Array();
		var arrFaveItems = new Array();
		var arrLookup = new Array();
		var i;
		for (i = 0; i < FaveItems.options.length; i++) {
			arrLookup[FaveItems.options[i].text] = FaveItems.options[i].value;
			arrFaveItems[i] = FaveItems.options[i].text;
		}
		var fLength = 0;
		var tLength = arrFaveItems.length;
		for(i = 0; i < AllItems.options.length; i++) {
			arrLookup[AllItems.options[i].text] = AllItems.options[i].value;
			if (AllItems.options[i].selected && AllItems.options[i].value != "") {
				arrFaveItems[tLength] = AllItems.options[i].text;
				tLength++;
			} else {
			arrAllItems[fLength] = AllItems.options[i].text;
			fLength++;
		   }
		}
		
		arrAllItems.sort();
		arrFaveItems.sort();
		AllItems.length = 0;
		FaveItems.length = 0;
		var c;
		for(c = 0; c < arrAllItems.length; c++) {
			var no = new Option();
			no.value = arrLookup[arrAllItems[c]];
			no.text = arrAllItems[c];
			AllItems[c] = no;
		}
		
		for(c = 0; c < arrFaveItems.length; c++) {
			var no = new Option();
			no.value = arrLookup[arrFaveItems[c]];
			no.text = arrFaveItems[c];
			FaveItems[c] = no;
		   }
		}
	
	function selectAll(FormName, SelectBox){
	  temp = "document." + FormName + "." + SelectBox;
	  Source = eval(temp);
	
	  for(x=0; x<(Source.length); x++){
	    Source.options[x].selected = "true";
	    }
	}
	
	// Keeps form from being submitted twice
	function LockButtons(whichform) {
		ua = new String(navigator.userAgent);
		if (ua.match(/IE/g)) {
			for (i=1; i<whichform.elements.length; i++) {
				if (whichform.elements[i].type == 'submit') {
					whichform.elements[i].disabled = true;
				}
			}
		}
		whichform.submit();
	}
	
	function checkTAFForm() {
		if (tellafriend.sendToEmail.value.length < 6) 
			{ 
				return false;
				alert('Send Message To is a required field!');
				tellafriend.sendToEmail.focus();
			} else if (tellafriend.name.value.length < 2) 
			{ 
				return false;
				alert('From Name is a required field!');
				tellafriend.name.focus();
			} else if (tellafriend.emailAddress.value.length < 6) 
			{ 
				return false;
				alert('From Email Address is a required field!');
				tellafriend.emailAddress.focus();
			}


		else {
				return true;
			}
	}

	function noenter() {
	  return !(window.event && window.event.keyCode == 13); }
	  
	  
/* Checkbox functions
//
//
*/

// HISTORY
// ------------------------------------------------------------------
// February 29, 2004: Fixed bug caused by LAST update, when control
//    checkbox is the first on checked. I hate when that happens.
// January 28, 2004: Fixed bug that occurred when checkbox was CHECKED
//    by default.
// December 16, 2002: Created
/* 
Original coding done by David Rogers - http://www.MrDaveR.com/

DESCRIPTION: This library lets you quickly and easily make multiple checkboxes
behave as a group by limiting the total number of boxes that can be checked
and/or have a master control checkbox. 

COMPATABILITY: Should work on all Javascript-compliant browsers.

USAGE:
// Create a new CheckBoxGroup object
var myOptions = new CheckBoxGroup();

// Tell the object which checkboxes exist in your group. You may make multiple
// calls to this function, and/or pass multiple arguments. You may specify
// field names exactly, or use a wildcard at the beginning or end of the 
// name.
myOptions.addToGroup("cb1","cb2","optionset*");
myOptions.addToGroup("*checkbox");

// Optionally set a "control" box which will effect all other boxes.
myOptions.setControlBox("masterCheckboxName");

// Specify how your control box will interact with the group. Options are
// either "some" or "all" ("all" is default).
// all: Checking the box will select all the other boxes. Unchecking it will
//      uncheck all the group checkboxes. Selecting all the checkboxes in
//      the group will automatically check the control box.
// some: Checking any checkbox in the group will check the control box. The
//       control box may not be unchecked if any option in the group is 
//       still checked. If no boxes in the group are checked, you may still
//       check the control box.
myOptions.setMasterBehavior("some");

// Optionally set the maximum number of boxes in the group which are allowed
// to be checked. You may pass a second argument which is an alert message to
// be displayed to the user if they exceed this limit.
myOptions.setMaxAllowed(3);
myOptions.setMaxAllowed(3,"You may only select 3 choices!");

// IMPORTANT: After defining the group and behavior, you must insert an action
// into EVERY checkbox's onClick event-handler. Just specify the name of the
// group object that the checkbox belongs to, and pass it 'this' as the argument.
<INPUT TYPE="checkbox" NAME="cb1" onClick="myOptions.check(this)">

// That's it! Your checkboxes will now behave as a group!

*/ 
function CheckBoxGroup() {
	this.controlBox=null;
	this.controlBoxChecked=null;
	this.maxAllowed=null;
	this.maxAllowedMessage=null;
	this.masterBehavior=null;
	this.formRef=null;
	this.checkboxWildcardNames=new Array();
	this.checkboxNames=new Array();
	this.totalBoxes=0;
	this.totalSelected=0;
	// Public methods
	this.setControlBox=CBG_setControlBox;
	this.setMaxAllowed=CBG_setMaxAllowed;
	this.setMasterBehavior=CBG_setMasterBehavior;	// all, some
	this.addToGroup=CBG_addToGroup;
	// Private methods
	this.expandWildcards=CBG_expandWildcards;
	this.addWildcardCheckboxes=CBG_addWildcardCheckboxes;
	this.addArrayCheckboxes=CBG_addArrayCheckboxes;
	this.addSingleCheckbox=CBG_addSingleCheckbox;
	this.check=CBG_check;
	}

// Set the master control checkbox name
function CBG_setControlBox(name) { this.controlBox=name; }

// Set the maximum number of checked boxes in the set, and optionally
// the message to popup when the max is reached.
function CBG_setMaxAllowed(num,msg) {
	this.maxAllowed=num;
	if (msg!=null&&msg!="") { this.maxAllowedMessage=msg; }
	}

// Set the behavior for the checkbox group master checkbox
//	All: all boxes must be checked for the master to be checked
//	Some: one or more of the boxes can be checked for the master to be checked
function CBG_setMasterBehavior(b) { this.masterBehavior = b.toLowerCase(); }

// Add checkbox wildcards to the checkboxes array
function CBG_addToGroup() {
	if (arguments.length>0) {
		for (var i=0;i<arguments.length;i++) {
			this.checkboxWildcardNames[this.checkboxWildcardNames.length]=arguments[i];
			}
		}
	}

// Expand the wildcard checkbox names given in the addToGroup method
function CBG_expandWildcards() {
	if (this.formRef==null) {alert("ERROR: No form element has been passed.  Cannot extract form name!"); return false; }
	for (var i=0; i<this.checkboxWildcardNames.length;i++) {
		var n = this.checkboxWildcardNames[i];
		var el = this.formRef[n];
		if (n.indexOf("*")!=-1) { this.addWildcardCheckboxes(n); }
		else if(CBG_nameIsArray(el)) { this.addArrayCheckboxes(n); }
		else { this.addSingleCheckbox(el); }
		}
	}


// Add checkboxes to the group which match a pattern
function CBG_addWildcardCheckboxes(name) {
	var i=name.indexOf("*");
	if ((i==0) || (i==name.length-1)) {
		searchString= (i)?name.substring(0,name.length-1):name.substring(1,name.length);
		for (var j=0;j<this.formRef.length;j++) {
			currentElement = this.formRef.elements[j];
			currentElementName=currentElement.name;
			var partialName = (i)?currentElementName.substring(0,searchString.length) : currentElementName.substring(currentElementName.length-searchString.length,currentElementName.length);
			if (partialName==searchString) {
				if(CBG_nameIsArray(currentElement)) this.addArrayCheckboxes(currentElement);
				else this.addSingleCheckbox(currentElement);
				}
			}
		}
	}

// Add checkboxes to the group which all have the same name
function CBG_addArrayCheckboxes(name) {
	if((CBG_nameIsArray(this.formRef[name])) && (this.formRef[name].length>0)) {
		for (var i=0; i<this.formRef[name].length; i++) { this.addSingleCheckbox(this.formRef[name][i]); }
		}
	}

function CBG_addSingleCheckbox(obj) {
	if (obj != this.formRef[this.controlBox]) {
		this.checkboxNames[this.checkboxNames.length]=obj;
		this.totalBoxes++;
		if (obj.checked) {
			this.totalSelected++;
			}
		}
	}

// Runs whenever a checkbox in the group is clicked
function CBG_check(obj) {
	var checked=obj.checked;
	if (this.formRef==null) {
		this.formRef=obj.form;
		this.expandWildcards();
		if (this.controlBox==null || obj.name!=this.controlBox) {
			this.totalSelected += (checked)?-1:1;
			}
		}
	if (this.controlBox!=null&&obj.name==this.controlBox) {
		if (this.masterBehavior=="all") {
			for (i=0;i<this.checkboxNames.length;i++) { this.checkboxNames[i].checked=checked; }
			this.totalSelected=(checked)?this.checkboxNames.length:0;
			}
		else {
			if (!checked) {
				obj.checked = (this.totalSelected>0)?true:false;
				obj.blur();
				}
			}
		}
	else {
		if (this.masterBehavior=="all") {
			if (!checked) {
				this.formRef[this.controlBox].checked=false;
				this.totalSelected--;
				}
			else { this.totalSelected++; }
			if (this.controlBox!=null) {
				this.formRef[this.controlBox].checked=(this.totalSelected==this.totalBoxes)?true:false;
				}
			}
		else {
			if (!obj.checked) { this.totalSelected--; }	
			else { this.totalSelected++; }
			if (this.controlBox!=null) {
				this.formRef[this.controlBox].checked=(this.totalSelected>0)?true:false;
				}
			if (this.maxAllowed!=null) {
				if (this.totalSelected>this.maxAllowed) {
					obj.checked=false;
					this.totalSelected--;
					if (this.maxAllowedMessage!=null) { alert(this.maxAllowedMessage); }
					return false;
					}
				}
			}
		}
	}

function CBG_nameIsArray(obj) {
	return ((typeof obj.type!="string")&&(obj.length>0)&&(obj[0]!=null)&&(obj[0].type=="checkbox"));
	}

/* Type-ahead combobox script */
/* **** ARRAY EXTENSION FOR NON-SUPPORTING BROWSERS **** */
if(typeof Array.prototype.push=='undefined') {
    Array.prototype.push = function () {
        var i=0,
            b=this.length,
            a=arguments;
        for(i;i<a.length;i++) {
            this[b+i]=a[i];
		}
        return this.length
    }
}
/* **** STRING EXTENSION FOR PUNCTUATION **** */
if (typeof(String.fromCharCode) == 'undefined') {
	String.fromCharCode = function () {
		if (arguments.length = 0) {
			return "";
		}
		var charCodeChars = new Array(32),
			returnString = "",
			i;
		charCodeChars[9] = '\t';
		charCodeChars[13] = '\n';
		charCodeChars.push(' ','!','"','#','$','%','',"'",'(',')','*','+',',','-','.','/','0','1','2','3','4','5','6','7','8','9',':',';','<','=','>','?','@');
		charCodeChars.push('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','[','\\',']','^','_','`');
		charCodeChars.push('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','{','|','}','~');
		for (i=0;arguments.length>i;i++) {
			returnString += charCodeChars[arguments[i]];
		}
		return returnString;
	}
}
String.fromKeyCode = function (keyCode,evtType) {
	if (!evtType || !evtType.length) {
		evtType = "keyDown";
	} else if (evtType.toLowerCase() == "keypress") {
		return String.fromCharCode(keyCode);
	}
	var keyDownChars = new Array(16);
		keyDownChars[8] = '[Bksp]';
		keyDownChars[9] = '[Tab]';
		keyDownChars[12] = '[N5+shift]';
		keyDownChars[13] = '[Enter]';
		keyDownChars.push('[Shift]','[Ctrl]','[Alt]','[Pause]','[CapsLock]');
		for (i=11;i;--i) {
			keyDownChars.push('undefined');
		}
		keyDownChars[27] = '[Esc]';
		keyDownChars.push(' ','[PgUp]','[PgDn]','[End]','[Home]','[Left]','[Up]','[Right]','[Down]');
		for (i=7;i;--i) {
			keyDownChars.push('undefined');
		}
		keyDownChars[45] = '[Ins]';
		keyDownChars[46] = '[Del]';
		keyDownChars.push(['0',')'],['1','!'],['2','@'],['3','#'],['4','$'],['5','%'],['6','^'],['7','&'],['8','*'],['9','(']);
		for (i=7;i;--i) {
			keyDownChars.push('undefined');
		}
		keyDownChars.push('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','[WinKey]');
		for (i=4;i;--i) {
			keyDownChars.push('undefined');
		}
		keyDownChars.push('0','1','2','3','4','5','6','7','8','9','*','+','undefined','-','.','/','[F1]','[F2]','[F3]','[F4]','[F5]','[F6]','[F7]','[F8]','[F9]','[F10]','[F11]','[F12]');
		for (i=62;i;--i) {
			keyDownChars.push('undefined');
		}
		keyDownChars[144] = '[NumLock]';
		keyDownChars[145] = '[ScrollLock]';
		keyDownChars.push([';',':'],['=','+'],[',','<'],['-','_'],['.','>'],['/','?'],['`','~']);
		for (i=26;i;--i) {
			keyDownChars.push('undefined')
		}
		keyDownChars.push(['[','{'],['\\','|'],[']','}'],["'",'"']);
	return keyDownChars[keyCode];
}

/* **** COMBOBOX CODE **** */
/**************************************************
Original Version (1.0):
Glenn G. Vergara
http://www21.brinkster.com/gver/
glenngv AT yahoo DOT com
Makati City, Philippines

Object-Based Version:
Eric C. Davis
http://www.10mar2001.com/
eric AT 10mar2001 DOT com
Atlanta, GA, US

(Keep the above intact if you want to use it! Thanks.)

Current Version: 2.5b
Last Update: 1 December 2003

********
Change Log:
New in version 2.5b:
	- Reversed selectItem() loop to prevent default IE6/Win rapid-change behaviour (skipped to second on match of first)
	- Outfitted for DOM2-style event handling; uses detection and falls back to DOM0 events
	- Resets immediately on ALT+TAB to prevent IE6/Win's loss of the reset timer.

New in version 2.4:
	- Added accepting of non-existent option
	- Added punctuation as acceptable input
	- Added setValueByValue() convenience method

New in version 2.2:
	- Many properties made private
	- Getters and setters for nearly all properties

New in version 2.0:
	- Object-oriented properties and methods using prototype
	- Constructor can accept a select element object or a select element object's ID string
	- Invocation reduced to single line of script: varName = new TypeAheadCombo('selectElementID');

New in version 1.4:
	- Allowable character set ranges use dynamic evaluation
	- Display of typed characters in status bar can be disabled

New in version 1.2:
	- Replaced major if/elseif/.../else statement with switch/case
	- Correction of characters typed on the numpad, reassigning to actual character values
********

********
API:
Constructor:
	new TypeAheadCombo(someSelectElement) // as an object or object reference
	new TypeAheadCombo('someSelectElementID') // as a string
	new TypeAheadCombobox('someSelectElementID', true) // to allow an undefined value

Privileged Methods: (these interact with private properties and act as helper functions)
	getTyped()
		- returns the string typed by the user since the last timeout
	setTyped(str)
		- argument "str" - string which will replace the value in the type buffer
	type(str)
		- argument "str" - string which will be appended to the type buffer
	resetTyped()
		- clears what has been typed from the buffer
	getIndex()
		- returns the location of the option currently selected
	setIndex(val)
		- stores the location of the option being selected
	getPrev()
		- returns the location of the option previously selected
	setPrev(val)
		- stores the location of the option previously selected
	setResetTime(val)
		- sets the timeout interval for the reset timers
	getResetTime()
		- returns the timeout interval for the reset timers
	setResetTimer()
		- sets the timeout for the reset of the typed buffer
	clearResetTimer()
		- clears the timeout of the reset of the typed buffer
	validChar(charCode)
		- validates that the charCode passed is acceptable to the typed buffer
	setDisplayStatus(bool)
		- set whether to display the typed buffer in the status bar
	getDisplayStatus()
		- returns the current setting for status bar display of the typed buffer

Public Methods:
	detectKey()
		- detects the keyCode, parses whether it is acceptable, and adds it to the typed buffer if so
	selectItem()
		- finds the first option that matches the typed buffer and selects it
	reset()
		- clears the typed buffer and the status display
	updateIndex()
		- handles the onclick and onblur events
	elementFocus()
		- handles the onfocus event
	elementKeydown()
		- handles the onkeydown event
********

***************************************************/
function TypeAheadCombo (anElement,acceptNewValue) {
	// DEGRADE UNSUPPORTED
	if (document.layers) {
		return;
	}
	// VALIDATION
	if (!anElement) {
		return false;
	}
	if (typeof anElement == "string") { // try for the ID
		anElement = document.getElementById ? document.getElementById(anElement) : document.all ? document.all[anElement] : anElement;
	}
	if (typeof anElement == "string") { // the grab failed: typeof null yields "object"
		return false;
	}
	// ASSOCIATION
	this.element = anElement;
	this.id = this.element.id + 'Combo';
	this.element.combo = this;
	// ELEMENT EVENT HANDLERS
	if (this.element.addEventListener) {
		// first try DOM2 methods
		this.element.addEventListener("keydown", this.elementKeydown, false);
		this.element.addEventListener("focus", this.elementFocus, false);
		this.element.addEventListener("click", this.updateIndex, false);
		this.element.addEventListener("blur", this.updateIndex, false);
	} else {
		// now try DOM0 methods
		this.element.onkeydown = this.elementKeydown;
		this.element.onfocus = this.elementFocus;
		this.element.onclick = this.updateIndex;
		this.element.onblur = this.updateIndex;
	}
	this.element.reset = this.reset;
	// PRIVATE PROPERTIES
	var self = this,	// corrects privatization bug
		typed = "",
		index = prev = 0,
		displayStatus = true,
		selector, resetter, nullStarter, acceptNew,
		//resetTime = 1600,
		resetTime = 4000,
		numberRangeStart = 48,
		numberRangeEnd = 57,
		charRangeStart = 65,
		charRangeEnd = 90,
		punctRangeStart = 146,
		punctRangeEnd = 223;
	if (this.element.options[0].text.length == 0 && (this.element.options[0].value.length == 0 || this.element.options[0].value == 0)) {
		nullStarter = true;
	} else {
		nullStarter = false;
	}
	if (typeof acceptNewValue != 'undefined' && acceptNewValue) {
		acceptNew = true;
		//resetTime = 2400;
		resetTime = 5000;
	} else {
		acceptNew = false;
	}
	// PRIVATE METHODS
	var getResetTime = function () {
		return resetTime;
	}
	var charInRanges = function (charCode) {
		if ((charCode >= numberRangeStart && charCode <= numberRangeEnd) || (charCode >= charRangeStart && charCode <= charRangeEnd) || (charCode >= punctRangeStart && charCode <= punctRangeEnd)) {
			return true;
		} else {
			return false;
		}
	}
	// PRIVILEDGED METHODS
	this.hasNullStarter = function () {
		return nullStarter;
	}
	this.getAcceptsNew = function () {
		return acceptNew;
	}
	this.getTyped = function () {
		return typed;
	}
	this.setTyped = function (str) {
		typed = str;
		return true;
	}
	this.resetTyped = function () {
		typed = "";
		return true;
	}
	this.type = function (str) {
		typed += str;
		return true;
	}
	this.getIndex = function () {
		return index;
	}
	this.setIndex = function (val) {
		if (!isNaN(val)) {
			index = val;
		}
	}
	this.getPrev = function () {
		return (prev ? prev : 0);
	}
	this.setPrev = function (val) {
		if (!isNaN(val)) {
			prev = val;
		}
	}
	this.setResetTime = function (val) {
		if (!isNaN(val)) {
			resetTime = val;
		}
	}
	this.setResetTimer = function () {
		resetter = setTimeout("document.forms['"+this.element.form.name+"'].elements['"+this.element.name+"'].reset();", getResetTime());
	}
	this.clearResetTimer = function () {
		clearTimeout(resetter);
	}
	this.delayedSelect = function () {
		selector = setTimeout("document.forms['"+this.element.form.name+"'].elements['"+this.element.name+"'].combo.selectItem();", 10);
	}
	this.cancelDelay = function () {
		clearTimeout(selector);
	}
	this.validChar = function (evt, charCode) {
		if ((evt.ctrlKey) || (evt.altKey)) {
			return false;
		} else if ((evt.shiftKey) && charInRanges(charCode)) {
			return true;
		} else if (evt.shiftKey) {
			return false;
		} else {
			return charInRanges(charCode);
		}
	}
	this.setDisplayStatus = function (bool) {
		if (bool == true || bool == false) {
			displayStatus = bool;
		}
	}
	this.getDisplayStatus = function () {
		return displayStatus;
	}
	this.cancel = function (evt) {
		if (evt) {
			evt.preventDefault();
		} else {
			window.event.returnValue = false;
		}
		return false;
	}
}

/*
PUBLIC METHODS
*/

TypeAheadCombo.prototype.detectKey = function (evt){
	this.clearResetTimer();
	this.cancelDelay();
	var combo_letter = "";
	var combo_code = (evt) ? evt.keyCode : window.event ? window.event.keyCode : evt.which;
	var event = (evt) ? evt : window.event;
	if (combo_code <= 105 && combo_code >= 96) { // make up for numPad typing
		combo_code = combo_code - 48;
	}
	switch (combo_code) {
		case 27:	//ESC key
			this.reset();
			this.setIndex(this.getPrev());
			// Put a little delay to override NS6/Mozilla's built-in behavior of ESC inside select element
			setTimeout("document.forms['"+this.element.form.name+"'].elements['"+this.element.name+"'].selectedIndex = document.forms['"+this.element.form.name+"'].elements['"+this.element.name+"'].index",0);
			return false;
			break;
		case 13:	//ENTER key
		case 9:		//TAB key
			this.reset();
			if (this.element.onchange) {
				// set timer to prevent stack overflow in IE.
				setTimeout("document.forms['" + this.element.form.name + "'].elements['" + this.element.name + "'].onchange()", 1);
			}
			return true;
			break;
		case 8:		//BACKSPACE key
			this.setTyped(this.getTyped().substring(0,this.getTyped().length-1));
			if (this.getAcceptsNew() && this.getIndex() == 0) {
				this.makeNewValue();
			}
			if (this.getTyped() == "") {
				this.reset();
				this.setIndex(this.getPrev());
				this.element.selectedIndex = this.getIndex();
				if (evt) {
					evt.preventDefault();
				} else {
					window.event.returnValue = false;
				}
				return false;
			} else {
				this.setResetTimer();
			}
			break;
		case 33:	//PAGEUP key
		case 34:	//PAGEDOWN key
		case 35:	//END key
		case 36:	//HOME key
		case 38:	//UP arrow
		case 40:	//DOWN arrow
			this.reset();
			return true;
			break;
		case 37:	//LEFT arrow	(translates to %)
		case 39:	//RIGHT arrow	(translates to ')
			this.reset();
			return false;
			break;
		case 32:	//SPACE key	(not in accepted ranges)
			combo_letter = " ";
			this.setResetTimer();
			break;
		default:
			if (this.validChar(event, combo_code)) {
				combo_letter = String.fromKeyCode(combo_code);
				if (combo_letter.length > 1) {
					if (event.shiftKey) {
						combo_letter = combo_letter[1];
					} else {
						combo_letter = combo_letter[0];
					}
				}
				this.setResetTimer();
			} else {
				return true;
			}
			break;
	}
	this.type(combo_letter);
	if (this.getDisplayStatus()) {
		window.status = this.getTyped();
	}
	if (document.all) {
		return this.selectItem();
	} else {
		return this.delayedSelect();
	}
}

TypeAheadCombo.prototype.selectItem = function (){
	var i = this.element.options.length,
		match = false;
	do {
		if (this.element.options[--i].text.toUpperCase().indexOf(this.getTyped().toUpperCase()) == 0){
			this.element.selectedIndex = i;
			this.setIndex(i);	//remember selected index
			match = true;
		}
	} while (i > 0);
	if (match) {
		return false; // always return false;
	}
	if (this.getAcceptsNew()) {
		this.makeNewValue();
	} else {
		this.element.selectedIndex = this.getIndex();	//re-select previously selected option even if there's no match
	}
	return false;  //always return false
}

TypeAheadCombo.prototype.makeNewValue = function () {
	this.removeNewValue();
	var tmpText = this.getTyped(),tmpStart = tmpEnd = "",tmpArr,i;
	if (this.hasNullStarter()) {
		newOption = this.element.options[0];
	} else if (tmpText.length > 0) {
		newOption = document.createElement("option");
		this.element.insertBefore(newOption, this.element.firstChild);
		this.newOption = newOption;
	} else {
		this.newOption = null;
		return;
	}
	tmpArr = tmpText.split(" ");
	i = tmpArr.length;
	if (tmpText.indexOf(" ") >= 0) {
		do {
			tmpStart = tmpArr[--i].substring(0,1);
			tmpEnd = tmpArr[i].substring(1,tmpArr[i].length);
			tmpArr[i] = tmpStart.toUpperCase() + tmpEnd.toLowerCase();
		} while (i);
		tmpText = tmpArr.join(" ");
	} else {
		tmpStart = tmpText.substring(0,1);
		tmpEnd = tmpText.substring(1,tmpText.length);
		tmpText = tmpStart.toUpperCase() + tmpEnd.toLowerCase();
	}
	newOption.value = tmpText;
	newOption.text = tmpText;
	this.element.selectedIndex = 0;
	this.setIndex(0);
}

TypeAheadCombo.prototype.removeNewValue = function () {
	if (this.hasNullStarter()) {
		this.element.options[0].text = '';
		this.element.options[0].value = '';
	} else if (this.newOption) {
		this.element.remove(this.newOption);
	}
}

TypeAheadCombo.prototype.setValueByValue = function (aValue) {
	var i = this.element.options.length;
	do {
		if (this.element.options[--i].value == aValue) {
			this.element.selectedIndex = i;
			break;
		}
	} while (i);
}

TypeAheadCombo.prototype.reset = function () {
	theCombo = this;
	if (this.combo) {
		theCombo = this.combo;
	}
	theCombo.element.selectedIndex = theCombo.getIndex();
	theCombo.resetTyped();
	if (theCombo.getDisplayStatus()) {
		window.status = window.defaultStatus ? window.defaultStatus : '';
	}
}

TypeAheadCombo.prototype.updateIndex = function (evt){
	var theCombo, theEl;
	if (evt && window.addEventListener) {
		// ready for handler with DOM2 event properties
		var e = new DOM2Event(evt, window.event, this);
		theEl = e.target;
	} else {
		theEl = this;
	}
	theCombo = theEl.combo;
	theCombo.setIndex(theEl.selectedIndex);
	theCombo.setPrev(theCombo.getIndex());
}

TypeAheadCombo.prototype.elementFocus = function (evt) {
	var theCombo;
	if (evt && window.addEventListener) {
		// ready for handler with DOM2 event properties
		var e = new DOM2Event(evt, window.event, this);
		theCombo = e.target.combo;
	} else {
		theCombo = this.combo;
	}
	theCombo.setIndex(theCombo.element.selectedIndex);
}

TypeAheadCombo.prototype.elementKeydown = function (evt) {
	var theCombo;
	if (evt && window.addEventListener) {
		// ready for handler with DOM2 event properties
		if (DOM2Event) {
			var e = new DOM2Event(evt, window.event, this);
		}
		theCombo = e.target.combo;
	} else {
		theCombo = this.combo;
	}
	if (!theCombo.detectKey(e)) {
		return theCombo.cancel(e);
	}
}

/* Inserts text at the cursor location in a textbox */

function insertAtCursor(myField, myValue) {
	// calling the function
	// insertAtCursor(document.formName.fieldName, ‘this value’);
	//IE support
	if (document.selection) {
		myField.focus();
		sel = document.selection.createRange();
		sel.text = myValue + "\r\n";
	}
	//MOZILLA/NETSCAPE support
	else if (myField.selectionStart || myField.selectionStart == '0') {
		var startPos = myField.selectionStart;
		var endPos = myField.selectionEnd;
		myField.value = myField.value.substring(0, startPos)
		+ myValue + "\r\n"
		+ myField.value.substring(endPos, myField.value.length);
	} else {
		myField.value += myValue + "\r\n";
	}
}

