//
// Copyright (c) 2008 Beau D. Scott | http://www.beauscott.com
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//

/**
 * AutoComplete.js
 * Prototype/Scriptaculous based _suggest tool
 * @version 1.2
 * @requires prototype.js <http://www.prototypejs.org/>
 * @author Beau D. Scott <beau_scott@hotmail.com>
 * 6/5/2008
 */
var AutoComplete = Class.create({
	/**
	 * The select object
	 * @type {HTMLSelectElement}
	 */
	selector: null,
	/**
	 * The component that triggers the suggest
	 * @type {HTMLInputElement}
	 */
	input: null,
	/**
	 * The timeout between lookups
	 * @type {Number}
	 * @private
	 */
	_timeout: null,
	/**
	 * Visisbility status of the selector object
	 * @type {Boolean}
	 */
	visible: false,
	/**
	 * Flag indicating whether the components have been laid out
	 * @type {Boolean}
	 */
	drawn: false,

	/**
	 * Hide timeout
	 * @type {Number}
	 * @private
	 */
	_hideTimeout: null,

	/**
	 * The configuration options for the instance
	 * @type {AutoComplete.Options}
	 */
	options: null,

	/**
	 * @param {Object} input ID of form element, or dom element,  to _suggest on
	 * @param {String} URL of dictionary
	 * @param {Object} options
	 */
	initialize: function(input, action, options)
	{
		this.action = action;
		this.input = $(input);
		this.input.autocomplete = "off";
		this.options = new AutoComplete.Options(options || {});

		if(!this.input)
			alert('No input field/binding field given or found')

		if(!this.action)
			alert('No action url specified');

		this.selector = document.createElement('select');

		Event.observe(this.input, 'focus', this._onInputFocus.bindAsEventListener(this));
		//Event.observe(this.input, 'keyup', this._onInputKeyUp.bindAsEventListener(this));
		Event.observe(this.input, 'keydown', this._onInputKeyDown.bindAsEventListener(this));
		Event.observe(this.input, 'blur', this._onInputBlur.bindAsEventListener(this));
		Event.observe(this.selector, 'blur', this._onSelectorBlur.bindAsEventListener(this));
		Event.observe(this.selector, 'focus', this._onSelectorFocus.bindAsEventListener(this));
		Event.observe(this.selector, 'change', this._onSelectorChange.bindAsEventListener(this));

		Event.observe(window, 'resize', this._reposition.bind(this));
		Event.observe(window, 'scroll', this._reposition.bind(this));
	},

	/**
	 * The input fields focus event handler
	 */
	_onInputFocus: function(event)
	{
		this._onSelectorFocus(event);
	},

	/**
	 * The selector's blur event handler
	 * @param {Event} event
	 * @private
	 */
	_onSelectorBlur: function(event)
	{
		this._onInputBlur(event);
	},
	/**
	 * The input's blur event handler
	 * @param {Event} event
	 * @private
	 */
	_onInputBlur: function(event)
	{
		this._hideTimeout = setTimeout(this._checkOnBlur.bind(this), 100);
	},
	/**
	 * Complete's the blur event handlers. Used as a proxy to avoid event collisions when blurring from the input
	 * and focusing on the selector during a mouse navigation
	 * @private
	 */
	_checkOnBlur:function()
	{
		this._hideTimeout = null
		this.hide();
	},
	/**
	 * The input's key-up event handler
	 * @param {Event} event
	 * @private
	 */
	_onInputKeyUp: function(event)
	{
		this._suggest(event)
			&& Event.stop(event);
	},
	/**
	 * The input's key-down event handler
	 * @param {Event} event
	 * @private
	 */
	_onInputKeyDown: function(event)
	{
		this._suggest(event)
			&& Event.stop(event);
	},
	/**
	 * The selectors's focus event handler.
	 * @param {Event} event
	 * @private
	 */
	_onSelectorFocus: function(event)
	{
		if(this._hideTimeout)
		{
			clearTimeout(this._hideTimeout);
			this._hideTimeout = null;
		}
	},
	/**
	 * The selector's change event handler
	 * @param {Event} event
	 * @private
	 */
	_onSelectorChange: function(event)
	{
		this.select();
	},
	/**
	 * Lays the UI elements of the control out, sets interaction options
	 * @param {Object} event Event
	 */
	draw: function()
	{
		if(this.drawn) return;
		if(this.options.cssClass)
			this.selector.className = this.options.cssClass;
		Element.setStyle(this.selector, {
			display: 'none',
			position: 'absolute',
			width: this.input.offsetWidth + 'px'
		});
		this.selector.size = this.options.size;
		document.body.appendChild(this.selector);
		this.input.autocomplete = 'off';
		this.drawn = true;
	},

	/**
	 * Hides the option box
	 */
	hide: function()
	{
		if(!this.drawn || !this.visible) return;
		this.visible = false;
		if(window.Scriptaculous)
		{
			new Effect.BlindUp(this.selector, {
				duration: this.options.delay,
				queue: 'end',
				afterFinish: function(event){
					Element.setStyle(this.selector,{
						display: 'none'
					});
					this.selector.options.length = 0;
					setTimeout(this._restoreFocus.bind(this),50);
				}.bind(this)
			});
		}
		else
		{
			Element.setStyle(this.selector,{
				display: 'none'
			});
			this.selector.options.length = 0;
			// FF hack, wasn't selecting without this small delay for some reason
			setTimeout(this._restoreFocus.bind(this),50);
		}
	},
	/**
	 * Resores the focus to the input control to avoid the cursor getting lost somewhere.
	 * @private
	 */
	_restoreFocus: function() {
		this.input.focus();
	},
	/**
	 * Displays the select box
	 */
	show: function()
	{
		if(!this.drawn) this.draw();
		var trigger = null;
		if(this.selector.options.length)
		{
			if(window.Scriptaculous)
			{
				new Effect.BlindDown(this.selector,{
					duration: this.options.delay,
					queue: 'end'
				});
			}
			else
			{
				Element.setStyle(this.selector,{
					display: 'inline'
				});
			}
			this._reposition();
			this.visible = true;
		}
	},

	/**
	 * Removes the timeout function set by a suggest
	 * @private
	 */
	_cancelTimeout: function()
	{
		if(this._timeout)
		{
			clearTimeout(this._timeout);
			this._timeout = null;
		}
	},

	/**
	 * Triggers the suggest interaction
	 * @param {Object} event The interaction event (keyboard or mouse)
	 * @return {Boolean} Whether to stop the event
	 * @private
	 */
	_suggest: function(event)
	{
		this._cancelTimeout();
		var key = Event.keyPressed(event);
		var ignoreKeys = [
			20, // caps lock
			16, // shift
			17, // ctrl
			91, // Windows key
			121, // F1 - F12
			122,
			123,
			124,
			125,
			126,
			127,
			128,
			129,
			130,
			131,
			132,
			45, // Insert
			36, // Home
			35, // End
			33, // Page Up
			34, // Page Down
			144, // Num Lock
			145, // Scroll Lock
			44, // Print Screen
			19, // Pause
			93, // Mouse menu key
		];
		if(ignoreKeys.indexOf(key) > -1)
			return false;

		switch(key)
		{
			case Event.KEY_LEFT:
			case Event.KEY_RIGHT:
				return false;
				break;
			case Event.KEY_TAB:
//			case Event.KEY_BACKSPACE:
//			case 46: //Delete
				this.cancel();
				return false;
				break;
			case Event.KEY_RETURN:
				if(this.visible)
				{
					this.select();
					return true;
				}
				return false;
				break;
			case Event.KEY_ESC:
				this.cancel();
				return true;
				break;
			case Event.KEY_DOWN:
			case Event.KEY_UP:
				this._interact(event);
				return true;
				break;
			default:
				break;
		}

		if(this.input.value.length >= this.options.threshold - 1)
		{
			this._timeout = setTimeout(this._sendRequest.bind(this), 1000 * this.options.delay);
		}
		return false;
	},

	/**
	 * Sends the suggestion request
	 * @private
	 */
	_sendRequest: function()
	{
	    // this.action
//		this._request = new Ajax.Request(this.action + this.input.value, {

//        alert(this.action);
//        alert(this.action + "&landiata=" + document.Mainsearch_lei.selAAA.value+"&prefix=" + this.input.value);
//	    alert(this.input);

        var str = "";
        
        if (this.options.formObjectCurrent == "hotel") {
            str = document.Mainsearch_lei.selAAA.value;
        }
        if (this.options.formObjectCurrent == "hotelB") {
            str = document.Mainsearch_lei.selHOTB.value;
        }
        if (this.options.formObjectCurrent == "utf") {
            str = document.Mainsearch_lei.selUTF.value;
        }

		this._request = new Ajax.Request(this.action + "&landiata=" + str +"&prefix=" + this.input.value, {
			onComplete: this._process.bind(this),
			method: this.options.requestMethod
		});
	},

	/**
	 * Repositions the selector (if visible) to match the new
	 * coords of the input.
	 * @private
	 */
	_reposition: function()
	{
		if(!this.drawn) return;
		var pos = Position.cumulativeOffset(this.input);
		pos.push(pos[0] + this.input.offsetWidth);
		pos.push(pos[1] + this.input.offsetHeight);
		Element.setStyle(this.selector,{
			left: pos[0] + 'px',
			top: pos[3] + 'px'
		});
	},

	/**
	 * Processes the resulting  from a suggestion request, adds options to the suggestion box.
	 * @param {XMLHTTPRequest} objXML The XMLHTTPRequest created by _sendRequest
	 * @param {String} jsonHeader the string of json commands to execute if the return type is json
	 * @private
	 */
	_process: function(objXML, jsonHeader)
	{
		this.selector.options.length = 0;
		switch(this.options.resultFormat)
		{
			case AutoComplete.Options.RESULT_FORMAT_XML:
				this._parseXML(objXML.responseXML);
				break;
			case AutoComplete.Options.RESULT_FORMAT_JSON:
				if(!jsonHeader)
				{
//				alert( objXML.responseText );
					jsonHeader = objXML.responseText && objXML.responseText.isJSON() ?
						objXML.responseText.evalJSON() : null;
//					jsonHeader = objXML.responseText.evalJSON();
				}
				this._parseJSON(jsonHeader);
				break;
			case AutoComplete.Options.RESULT_FORMAT_TEXT:
				this._parseText(objXML.responseText);
				break;
			default:
				alert("Unable to parse result type. Make sure you've set the resultFormat option correctly");
				break;
		}

		if(this.selector.options.length > (this.options.size))
			this.selector.size = this.options.size;
		else
			this.selector.size = this.selector.options.length > 1 ? this.selector.options.length : 2;

		if(this.selector.options.length)
		{
			//none selected by default
			this.selector.selectedIndex = -1;
			this.show();
		}
		else
			this.cancel();
	},

	/**
	 * Parses the XML result, adds options
	 * @param {XML} xml the XML of suggestions to parse
	 */
	_parseXML: function(xml)
	{
		var suggestions = null;
		for(var i = 0; i < xml.childNodes.length; i++)
		{
			if(xml.childNodes[i].tagName)
			{
				suggestions = xml.childNodes[i].childNodes;
			}
		}
		if(!suggestions)
		{
			alert("Could not parse response XML.");
			return;
		}
		for(i = 0; i < suggestions.length; i++)
		{
			suggestion = suggestions.item(i).firstChild.nodeValue;
			this._addOption(suggestion);
		}
	},
	/**********************************************************************************************************************
	 * Parses the JSON result, adds options
	 * @param {String} json The json response to parse
	 */
	_parseJSON: function(json)
	{
		if(!json) json = [];
		// alert(json.length); sto -> 13
		
		for(i = 0; i < json.length; i++) 
			this._addOption2(json[i].value+" "+json[i].info+";"+ json[i].id, json[i].value+" "+json[i].info  );
		
	},


	/********************************** Lei test åäö
	 *
	 *
	*/
	_Leifunc: function (str) {

	if (str.indexOf('&acute;') > -1)
		str = str.replace(/&acute;/g, '´');
	if (str.indexOf('&Aring;') > -1)
		str = str.replace(/&Aring;/g, 'Å');
	if (str.indexOf('&aring;') > -1)
		str = str.replace(/&aring;/g, 'å');
	if (str.indexOf('&Auml;') > -1)
		str = str.replace(/&Auml;/g, 'Ä');
	if (str.indexOf('&auml;') > -1)
		str = str.replace(/&auml;/g, 'ä');
	if (str.indexOf('&AElig;') > -1)
		str = str.replace(/&AElig;/g, 'Æ');
	if (str.indexOf('&aelig;') > -1)
		str = str.replace(/&aelig;/g, 'æ');
	if (str.indexOf('&Aacute;') > -1)
		str = str.replace(/&Aacute;/g, 'Á');
	if (str.indexOf('&aacute;') > -1)
		str = str.replace(/&aacute;/g, 'á');
	if (str.indexOf('&Agrave;') > -1)
		str = str.replace(/&Agrave;/g, 'À');
	if (str.indexOf('&agrave;') > -1)
		str = str.replace(/&agrave;/g, 'à');
	if (str.indexOf('&Acirc;') > -1)
		str = str.replace(/&Acirc;/g, 'Â');
	if (str.indexOf('&acirc;') > -1)
		str = str.replace(/&acirc;/g, 'â');
	if (str.indexOf('&Atilde;') > -1)
		str = str.replace(/&Atilde;/g, 'Ã');
	if (str.indexOf('&atilde;') > -1)
		str = str.replace(/&atilde;/g, 'ã');
	if (str.indexOf('&Ccedil;') > -1)
		str = str.replace(/&Ccedil;/g, 'Ç');
	if (str.indexOf('&ccedil;') > -1)
		str = str.replace(/&ccedil;/g, 'ç');
	if (str.indexOf('&Eacute;') > -1)
		str = str.replace(/&Eacute;/g, 'É');
	if (str.indexOf('&eacute;') > -1)
		str = str.replace(/&eacute;/g, 'é');
	if (str.indexOf('&Egrave;') > -1)
		str = str.replace(/&Egrave;/g, 'È');
	if (str.indexOf('&egrave;') > -1)
		str = str.replace(/&egrave;/g, 'è');
	if (str.indexOf('&Ecirc;') > -1)
		str = str.replace(/&Ecirc;/g, 'Ê');
	if (str.indexOf('&ecirc;') > -1)
		str = str.replace(/&ecirc;/g, 'ê');
	if (str.indexOf('&Euml;') > -1)
		str = str.replace(/&Euml;/g, 'Ë');
	if (str.indexOf('&euml;') > -1)
		str = str.replace(/&euml;/g, 'ë');
	if (str.indexOf('&Iacute;') > -1)
		str = str.replace(/&Iacute;/g, 'Í');
	if (str.indexOf('&iacute;') > -1)
		str = str.replace(/&iacute;/g, 'í');
	if (str.indexOf('&Igrave;') > -1)
		str = str.replace(/&Igrave;/g, 'Ì');
	if (str.indexOf('&igrave;') > -1)
		str = str.replace(/&igrave;/g, 'ì');
	if (str.indexOf('&Icirc;') > -1)
		str = str.replace(/&WWW;/g, 'Î');
	if (str.indexOf('&icirc;') > -1)
		str = str.replace(/&icirc;/g, 'î');
	if (str.indexOf('&Iuml;') > -1)
		str = str.replace(/&Iuml;/g, 'Ï');
	if (str.indexOf('&iuml;') > -1)
		str = str.replace(/&iuml;/g, 'ï');
	if (str.indexOf('&Ntilde;') > -1)
		str = str.replace(/&Ntilde;/g, 'Ñ');
	if (str.indexOf('&ntilde;') > -1)
		str = str.replace(/&ntilde;/g, 'ñ');
	if (str.indexOf('&Oacute;') > -1)
		str = str.replace(/&Oacute;/g, 'Ó');
	if (str.indexOf('&oacute;') > -1)
		str = str.replace(/&oacute;/g, 'ó');
	if (str.indexOf('&Ograve;') > -1)
		str = str.replace(/&Ograve;/g, 'Ò');
	if (str.indexOf('&ograve;') > -1)
		str = str.replace(/&ograve;/g, 'ò');
	if (str.indexOf('&Ocirc;') > -1)
		str = str.replace(/&Ocirc;/g, 'Ô');
	if (str.indexOf('&ocirc;') > -1)
		str = str.replace(/&ocirc;/g, 'ô');
	if (str.indexOf('&Otilde;') > -1)
		str = str.replace(/&Otilde;/g, 'Õ');
	if (str.indexOf('&otilde;') > -1)
		str = str.replace(/&otilde;/g, 'õ');
	if (str.indexOf('&Ouml;') > -1)
		str = str.replace(/&Ouml;/g, 'Ö');
	if (str.indexOf('&ouml;') > -1)
		str = str.replace(/&ouml;/g, 'ö');
	if (str.indexOf('&Oslash;') > -1)
		str = str.replace(/&Oslash;/g, 'Ø');
	if (str.indexOf('&oslash;') > -1)
		str = str.replace(/&oslash;/g, 'ø');
	if (str.indexOf('&OElig;') > -1)
		str = str.replace(/&OElig;/g, 'Œ');
	if (str.indexOf('&oelig;') > -1)
		str = str.replace(/&oelig;/g, 'œ');
	if (str.indexOf('&szlig;') > -1)
		str = str.replace(/&szlig;/g, 'ß');
	if (str.indexOf('&Scaron;') > -1)
		str = str.replace(/&Scaron;/g, 'Š');
	if (str.indexOf('&scaron;') > -1)
		str = str.replace(/&scaron;/g, 'š');
	if (str.indexOf('&Uacute;') > -1)
		str = str.replace(/&Uacute;/g, 'Ú');
	if (str.indexOf('&uacute;') > -1)
		str = str.replace(/&uacute;/g, 'ú');
	if (str.indexOf('&Ugrave;') > -1)
		str = str.replace(/&Ugrave;/g, 'Ù');
	if (str.indexOf('&ugrave;') > -1)
		str = str.replace(/&ugrave;/g, 'ù');
	if (str.indexOf('&Ucirc;') > -1)
		str = str.replace(/&Ucirc;/g, 'Û');
	if (str.indexOf('&ucirc;') > -1)
		str = str.replace(/&ucirc;/g, 'û');
	if (str.indexOf('&Uuml;') > -1)
		str = str.replace(/&Uuml;/g, 'Ü');
	if (str.indexOf('&uuml;') > -1)
		str = str.replace(/&uuml;/g, 'ü');
	if (str.indexOf('&Yacute;') > -1)
		str = str.replace(/&Yacute;/g, 'Ý');
	if (str.indexOf('&yacute;') > -1)
		str = str.replace(/&yacute;/g, 'ý');
	if (str.indexOf('&Yuml;') > -1)
		str = str.replace(/&Yuml;/g, 'Ÿ');
	if (str.indexOf('&yuml;') > -1)
		str = str.replace(/&yuml;/g, 'ÿ');

	return str;
},
	
	



















	/**
	 * Parses the TEXT result, adds options
	 * @param {String} text The text response to parse
	 */
	_parseText: function(text)
	{
		var suggestions = (text||"").split(/\n/);
		for(i = 0; i < suggestions.length; i++)
			this._addOption(suggestions[i]);
	},
	/**
	 * Creates a suggestion option for the given suggestion,
	 * adds it to the selector object.
	 * @param {String} suggestion The suggestion
	 */
	_addOption: function(suggestion)
	{
		var opt = new Option(suggestion, suggestion);
		Prototype.Browser.IE ? this.selector.add(opt) : this.selector.add(opt, null);
	},
	_addOption2: function(suggestion, idsugg)
	{
		var opt = new Option(idsugg, suggestion);
		Prototype.Browser.IE ? this.selector.add(opt) : this.selector.add(opt, null);
	},

	/**
	 * Clears and hides the suggestion box.
	 */
	cancel: function()
	{
		this.hide();
	},

	/**
	 * Captures the currently selected suggestion option to the input field
	 */
	select: function()
	{
		if(this.selector.options.length)
		{
		    var fullvalue = this.selector.options[this.selector.selectedIndex].value;
		    var fullvaluearr = fullvalue.split(";");
		    //this.input.value = fullvaluearr[0];
			this.input.value = this._Leifunc(fullvaluearr[0]); 
		    
			//this.input.value = this.selector.options[this.selector.selectedIndex].value;
		
			//document.Mainsearch_lei.my_ac1_hidden.value = fullvaluearr[1];
			this.options.hiddeninput.value = fullvaluearr[1];
			
        if (this.options.formObjectCurrent == "hotel") {
            document.Mainsearch_lei.selAAA.value = fullvaluearr[1];
            
            makeRequestLoc("httpTransfer3.asp?type=selHotAreaList&code="+document.Mainsearch_lei.selAAA.value, "selHotLocDiv", document.Mainsearch_lei.selAAA.value);
        }
        if (this.options.formObjectCurrent == "hotelB") {
            document.Mainsearch_lei.selHOTB.value = fullvaluearr[1];
            
            makeRequestLoc("httpTransfer3.asp?type=selHotAreaBList&code="+document.Mainsearch_lei.selHOTB.value, "selHotLocDivB", document.Mainsearch_lei.selHOTB.value);
        }
        if (this.options.formObjectCurrent == "utf") {
            document.Mainsearch_lei.selUTF.value = fullvaluearr[1];
        }
	    
//		document.Mainsearch_lei.selAAA.value = fullvaluearr[1];
//		alert(this.options.hiddeninput.value);
		
//			alert(this.selector.options[this.selector.selectedIndex].id);
		}
		this.cancel();
		if(typeof this.options.onSelect == 'function')
		{
			this.options['onSelect'](this.input);
		}
	},

	/**
	 * Processes key interactions with the input field, including navigating the selected option
	 * with the up/down arrows, esc cancelling and selecting the option.
	 * @param {Event} event The interaction event
	 * @private
	 */
	_interact: function(event)
	{
		if(!this.visible) return;

		var key = Event.keyPressed(event);
		if(key != Event.KEY_UP && key != Event.KEY_DOWN) return;
		var mx = this.selector.options.length;

//		if(key == Event.KEY_DOWN) return;
		
		if(key == Event.KEY_UP)
		{
			if(this.selector.selectedIndex == 0)
				this.selector.selectedIndex = this.selector.options.length - 1;
			else
				this.selector.selectedIndex--;
		}
		else
		{
			if(this.selector.selectedIndex == this.selector.options.length - 1)
				this.selector.selectedIndex = 0;
			else
				this.selector.selectedIndex++;
		}
	}
});

/**
 * Helper class for defining options for the AutoComplete object
 * @version 1.2
 * @requires prototype.js <http://www.prototypejs.org/>
 * @author Beau D. Scott <beau_scott@hotmail.com>
 * 6/5/2008
 */
AutoComplete.Options = Class.create({
	/**
	 * Number of options to display before scrolling
	 * @type {Number}
	 */
	size: 10,
	/**
	 * CSS class name for autocomplete selector
	 * @type {String}
	 */
	cssClass: null,
	/**
	 * JavaScript callback function to execute upon selection
	 * @type {Function}
	 */
	onSelect: null,
	/**
	 * Minimum characters needed before an suggestion is executed
	 * @type {Number}
	 */
	threshold: 1,
	/**
	 * Time delay between key stroke and execution
	 * @type {Number}
	 */
	delay: .2,
	/**
	 * The request method to use when getting the suggestions
	 * @type {String}
	 */
	requestMethod: 'GET',  
	/**
	 * The format of the results retrieved (xml, text or json)
	 * @type {String}
	 */
	resultFormat: 'xml',
	formObjectCurrent: 'hotel',
	/**
	 * Constructor
	 * @type {Object} overrides Overriding properties
	 */
	initialize: function(overrides)
	{
		Object.extend(this, overrides || {});
	}
});
Object.extend(AutoComplete.Options, {
	/**
	 * Enumeration for XML result format
	 * Be sure your response type is application/xml or text/xml
	 * @static
	 */
	RESULT_FORMAT_XML: 'xml',
	/**
	 * Enumeration for JSon result format
	 * @static
	 */
	RESULT_FORMAT_JSON: 'json',
	/**
	 * Enumeration for text result format
	 * @static
	 */
	RESULT_FORMAT_TEXT: 'text'
});

//
// Various Prototype Event extensions
//
Object.extend(Event, {
	/**
	 * Enumeration for the backspace key code
	 * @type {Number}
	 * @static
	 */
	KEY_BACKSPACE: 8,
	/**
	 * Enumeration for the tab key code
	 * @static
	 */
	KEY_TAB:       9,
	/**
	 * Enumeration for the return/enter key code
	 * @static
	 */
	KEY_RETURN:   13,
	/**
	 * Enumeration for the escape key code
	 * @static
	 */
	KEY_ESC:      27,
	/**
	 * Enumeration for the left arrow key code
	 * @static
	 */
	KEY_LEFT:     37,
	/**
	 * Enumeration for the up arrow key code
	 * @static
	 */
	KEY_UP:       38,
	/**
	 * Enumeration for the right arrow key code
	 * @static
	 */
	KEY_RIGHT:    39,
	/**
	 * Enumeration for the down arrow key code
	 * @static
	 */
	KEY_DOWN:     40,
	/**
	 * Enumeration for the delete key code
	 * @static
	 */
	KEY_DELETE:   46,
	/**
	 * Enumeration for the shift key code
	 * @static
	 */
	KEY_SHIFT:    16,
	/**
	 * Enumeration for the cotnrol key code
	 * @static
	 */
	KEY_CONTROL:  17,
	/**
	 * Enumeration for the capslock key code
	 * @static
	 */
	KEY_CAPSLOCK: 20,
	/**
	 * Enumeration for the space key code
	 * @static
	 */
	KEY_SPACE:	  32,

	/**
	 * A simple interface to get the key code of the key pressed based, browser sensitive.
	 * @param {Event} event They keyboard event
	 * @return {Number} the key code of the key pressed
	 */
	keyPressed: function(event)
	{
		return Prototype.Browser.IE ? window.event.keyCode : event.which;
	}
});

