PHYSEARCH = {

	key: null,

	data: {
		row:       'search_proximity',
		addy:      'search_address',
		button:    'search_geocode',
		latitude:  'latitude',
		longitude: 'longitude',
		image:     'search_image',
		form:      'PHYSEARCH_form',
		clear:     'PHYSEARCH_clear',
		width:     null,
		height:    null,
		geocoder:  null
	},

	init: function () {
	
		this.resolve(this.data);

		this.data.geocoder = new PB.Geocode(
			this.data.latitude,
			this.data.longitude);
			
		this.data.row.style.display = '';

		this.data.width  = Dom.getStyle(this.data.image, 'width');
		this.data.height = Dom.getStyle(this.data.image, 'height');
		this.data.width  = parseInt(this.data.width,  10);
		this.data.height = parseInt(this.data.height, 10);

		this.data.geocoder.onChange.subscribe(this.doChange, this, true);
		Event.addListener(this.data.button, 'click', this.search, this, true);
		Event.addListener(this.data.form, 'reset', this.doReset, this, true);
		Event.addListener(this.data.clear, 'click', this.doReset, this, true);
		this.doChange();

	},

	resolve: function (o) {
		for (var x in o) {
			if (o.hasOwnProperty(x) && Lang.isString(o[x])) {
				o[x] = $(o[x]);
			}
		}
	},

	search: function () {
		var s = this.data.addy.value;
		s = Lang.trim(s);

		if (s.length) {
			this.data.geocoder.search(s);
		} else {
			this.data.geocoder.open();
		}
	},

	doChange: function () {
		var w = this.data.width,
		h     = this.data.height,
		src   = this.data.geocoder.staticURL(w, h, this.key),
		img   = this.data.image;

		img.style.backgroundImage = 'none';
		img.style.display = 'none';
// The following lines were commented out on 2009-03-17 by BNabors per MFlynn.
// This change was made in order to remove the map from the physician search pages.

//		if (src === null) {
//			img.style.backgroundImage = 'none';
//			img.style.display = 'none';
//		} else {
//			img.style.display = '';
//			img.style.backgroundImage = "url('" + src + "')";
//		}
	},

	doReset: function (e) {
		Event.stopEvent(e);
		$('familyName').value = '';
		$('specialty').selectedIndex=0;
		$('practice').selectedIndex=0;
		$('keyword').value = '';
		$('search_address').value = '';
		

		dropdown_menu_hack($('practice'));
		dropdown_menu_hack($('specialty'));
		
		var o = document.createElement("option");
		o.value = $('practice').contentOptions[0].value;
		o.innerHTML = $('practice').contentOptions[0].text;
		while ($('practice').options.length > 0) {
			$('practice').remove(0);
		}
		$('practice').appendChild(o);
		$('practice').title = o.innerHTML;
		
		var p = document.createElement("option");

		p.value = $('specialty').contentOptions[0].value;
		p.innerHTML = $('specialty').contentOptions[0].text;
		while ($('specialty').options.length > 0) {
			$('specialty').remove(0);
		}
		$('specialty').appendChild(p);
		$('specialty').title = p.innerHTML;


	}

};

Event.onDOMReady(PHYSEARCH.init, PHYSEARCH, true);

