﻿var EmployeeSearchForm = {
	_Element: null,
	AppendElement: function(___Element) {
		this._Element.appendChild(___Element);
	},
	initialize: function(__Keywords, __County, __City, __Position) {
		this._Element = document.getElementById("EmployeeSearchForm");
		
		// Keywords.
		this.Keywords.element = this._Element.elements[0];
		this.Keywords.element.value = __Keywords;
		
		// County.
		this.County._Element = this._Element.elements[1];
		this.County._Element.value = __County;
		this.County.SuggestionList = new SuggestionList.List(this, this.County, "suggestions-1");
		
		// City.
		this.City._Element = this._Element.elements[2];
		this.City._Element.value = __City;
		this.City.SuggestionList = new SuggestionList.List(this, this.City, "suggestions-2");
		
		// Position.
		this.Position.element = this._Element.elements[3];
		Select.SelectedValue(this.Position.element, __Position);
	},
	Keywords: {
		element: null
	},
	Position: {
		element: null
	},
	County: {
		_Element: null,
		_Timer: null,
		SuggestionList: null,
		ObjectPath: function() {
			return "EmployeeSearchForm.County";
		},
		Value: function(__Value) {
			if(__Value == null) {
				return this._Element.value;
			} else {
				this._Element.value = __Value;
			}
		},
		OnBlur: function() {
			this._Timer = setTimeout("EmployeeSearchForm.County.SuggestionList.Hide();EmployeeSearchForm.County._Timer = null;", 1000);
		},
		OnFocus: function() {
			if(this._Timer != null) {
				clearTimeout(this._Timer);
				
				this._Timer = null;
			}
			
			if(this._Element.value.length > 0) {
				this.SuggestionList.Load("/!Controls/EmployeeSearchForm.ascx.County.aspx?Name=" + this._Element.value);
				
				if(this.SuggestionList.Items.length > 0) {
					this.SuggestionList.Show();
				}
			}
		},
		OnKeyUp: function(__Event) {
			if(__Event.keyCode == 38) {
				this.SuggestionList.Previous();
			} else if(__Event.keyCode == 40) {
				this.SuggestionList.Next();
			} else {
				if(this._Element.value.length > 0) {
					this.SuggestionList.Load("/!Controls/EmployeeSearchForm.ascx.County.aspx?Name=" + this._Element.value);
					
					if(this.SuggestionList.Items.length > 0) {
						this.SuggestionList.Show();
					}
				} else {
					this.SuggestionList.Hide();
				}
			}
		}
	},
	City: {
		_Element: null,
		_Timer: null,
		SuggestionList: null,
		ObjectPath: function() {
			return "EmployeeSearchForm.City";
		},
		Value: function(__Value) {
			if(__Value == null) {
				return this._Element.value;
			} else {
				this._Element.value = __Value;
			}
		},
		OnBlur: function() {
			this._Timer = setTimeout("EmployeeSearchForm.City.SuggestionList.Hide();EmployeeSearchForm.City._Timer = null;", 1000);
		},
		OnFocus: function() {
			if(this._Timer != null) {
				clearTimeout(this._Timer);
				
				this._Timer = null;
			}
			
			if(this._Element.value.length > 0) {
				this.SuggestionList.Load("/!Controls/EmployeeSearchForm.ascx.City.aspx?County=" + EmployeeSearchForm.County.Value(null) + "&Name=" + this._Element.value);
				
				if(this.SuggestionList.Items.length > 0) {
					this.SuggestionList.Show();
				}
			}
		},
		OnKeyUp: function(__Event) {
			if(__Event.keyCode == 38) {
				this.SuggestionList.Previous();
			} else if(__Event.keyCode == 40) {
				this.SuggestionList.Next();
			} else {
				this.SuggestionList._SelectedItem = -1;
				
				if(this._Element.value.length > 0) {
					this.SuggestionList.Load("/!Controls/EmployeeSearchForm.ascx.City.aspx?County=" + EmployeeSearchForm.County.Value(null) + "&Name=" + this._Element.value);
					
					if(this.SuggestionList.Items.length > 0) {
						this.SuggestionList.Show();
					}
				} else {
					this.SuggestionList.Hide();
				}
			}
		}
	}
};
