﻿Type.registerNamespace('Redbook');

Redbook.QuickSearch = function(element) {
	this._msg = null;
	this._nameMsg = null;
	this._container = null;
	this._zip = null;
	this._distance = null;
	this._name = null;
	this._submit = null;
	Redbook.QuickSearch.initializeBase(this, [element]);
}
Redbook.QuickSearch.prototype =
{
	initialize: function() {
		Redbook.QuickSearch.callBaseMethod(this, 'initialize');

		this._container = this.get_element();
		this._zip = $get(this._container.id + '_zip');
		this._distance = $get(this._container.id + '_distance');
		this._name = $get(this._container.id + '_name');
		this._submit = $get(this._container.id + '_submit');
		$addHandlers(this._submit, { 'click': this._onSubmit }, this);
	},
	dispose: function() {
		if (this._submit != null)
			$clearHandlers(this._submit);
		Redbook.QuickSearch.callBaseMethod(this, 'dispose');
	},
	_onSubmit: function(element) {
		if (((this._zip.value == null) || (this._zip.value == '')) && ((this._name.value == null) || (this._name.value == ''))) {
			alert(this._msg);
			element.preventDefault();
			element.stopPropagation();
		}
		if ((this._name.value) && (this._name.value.length < 2)) {
			alert(this._nameMsg);
			element.preventDefault();
			element.stopPropagation();
		}
	}
}

Redbook.QuickSearch.registerClass('Redbook.QuickSearch', Sys.UI.Control);

if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();