﻿

var SEARCH = {

	data: {
		relatedSpecialties: 'RelatedSpecID',
		specialties: 'SpecID',
		selectedRelated: 'selectedRelSpec',
		refineSearch: 'RefineSearch',
		keyword: 'keyword'
	},

	init: function() {
		this.data.specialties = document.getElementById(this.data.specialties);
		this.data.relatedSpecialties = document.getElementById(this.data.relatedSpecialties);
		this.data.selectedRelated = document.getElementById(this.data.selectedRelated);
		this.data.refineSearch = document.getElementById(this.data.refineSearch);
		this.data.keyword = document.getElementById(this.data.keyword);

		Event.addListener(this.data.specialties, 'change', this.doChange_relatedSpecialties, this, true);
		if (this.data.refineSearch) {
			this.doChange_relatedSpecialties();
		}


		//Hide advanced search fields
		var d = document.getElementById('AdvancedSearch');
		if (d) {
			d.style.overflow = 'hidden';
			d.style.visibility = 'hidden';
			var h = document.getElementById('hideOptions');
			h.style.visibility = 'hidden';
		}
	},


	doChange_relatedSpecialties: function() {
		var specID = this.data.specialties,
		kw = this.data.keyword.value,
		url = '/getSpecialtiesByService.asp';

		if (specID.options) {
			specID = specID.options[specID.selectedIndex].value;
		} else {
			specID = specID.value;
		}
		specID = parseInt(specID, 10);

		if (kw.length > 0) {
			//Just move along.
		} else {
			if (isNaN(specID)) {
				this.data.relatedSpecialties.selectedIndex = 0;
				this.data.relatedSpecialties.options.length = 1;
				this.data.selectedRelated = null;
				return;
			}
		}

		url += '?specID=' + encodeURIComponent(specID) + '&keyword=' + encodeURIComponent(kw);

		YAHOO.util.Connect.asyncRequest('GET', url, {
			scope: this,
			success: this.setRelatedSpecialties
		});

	},

	setRelatedSpecialties: function(o) {

		var specs = o.responseText,
		select = this.data.relatedSpecialties,
		current, x, found = false;

		specs = Lang.JSON.parse(specs);

		current = this.data.selectedRelated;
		if (current) {
			current = parseInt(current.value, 10);
		}
		select.selectedIndex = 0;
		select.options.length = 1;

		if (specs.length > 0) {
			for (x = 0; x < specs.length; x++) {
				select[select.options.length] = new Option(specs[x].text, specs[x].id);

				if (specs[x].id === current) {
					select.selectedIndex = select.options.length - 1;
					found = true;
				}
			}

			if (!found) {
				this.data.selectedRelated = null;
			}
		} else {
			select.selectedIndex = select.options.length - 1;
			select[select.options.length] = new Option('No related specialties available.', '');
			select.selectedIndex = 1;
		}

	},

	setAdvancedSearch: function() {
		var d, h, s;
		d = document.getElementById('AdvancedSearch');
		d.style.height = '225px';
		d.style.overflow = 'visible';
		d.style.visibility = 'visible';
		s = document.getElementById('showOptions');
		s.style.visibility = 'hidden';
		h = document.getElementById('hideOptions');
		h.style.visibility = 'visible';
	},
	hideAdvancedSearch: function() {
		var d, h, s;
		d = document.getElementById('AdvancedSearch');
		d.style.height = '0px';
		d.style.visibility = 'hidden';
		d.style.overflow = 'hidden';
		s = document.getElementById('showOptions');
		s.style.visibility = 'visible';
		h = document.getElementById('hideOptions');
		h.style.visibility = 'hidden';
	},
	clearForm: function() {
		var t = document.getElementsByTagName('input'), s = document.getElementsByTagName('select'), i;
		for (i = 0; i < t.length; i++) {
			if (t[i].type === 'text') {
				t[i].value = '';
			}
		}
		for (i = 0; i < s.length; i++) {
			s[i].selectedIndex = 0;
		}

	},

	newwindow: function(href) {
		var top, left;
		top = screen.availWidth / 3;
		left = 0;
		window.open(href, 'resource', 'width=800,height=800,resizable=1,scrollbars=1, top=' + top + ', left=' + left + '');
	},

	closewindow: function(href) {
		href.close();
	},

	redirectParent: function(pageID) {
		window.opener.parent.location = 'Default.asp?PageID=' + pageID + '&P=Y';
	},

	displayBio: function(e, id, photoid) {
		var x = Event.getPageX(e), y = Event.getPageY(e), d, i, s;

		d = document.createElement('div');
		d.id = 'bioPopup-' + id;
		d.style.height = '150px';
		d.style.width = '335px';
		d.style.top = 15 + y + 'px';
		d.style.left = 35 + x + 'px';
		d.style.zIndex = '100';
		d.style.position = 'absolute';
		//d.style.whiteSpace = 'nowrap';
		d.style.overflow = 'hidden';
		d.style.backgroundColor = '#EEECDD';

		if (photoid) {
			i = document.createElement('img');
			i.setAttribute('src', '/images/physicians/' + id + '.jpg');
			i.setAttribute('style', 'float: left'); //Normal browsers
			i.style.styleFloat = 'left'; //IE
			i.style.height = '75px';
			i.style.width = '60px';
		}

		s = document.createElement('span');
		s.setAttribute('style', 'float: right'); //Normal browsers
		s.style.styleFloat = 'right'; //IE
		s.style.width = '275px';
		s.style.height = '75px';
		s.innerHTML = document.getElementById('text-' + id).value;

		if (photoid) {
			d.appendChild(i);
		}
		d.appendChild(s);

		document.body.appendChild(d);
	},

	hideBio: function(id) {
		var d;
		d = document.getElementById('bioPopup-' + id);
		document.body.removeChild(d);
	}

};
Event.onDOMReady(SEARCH.init, SEARCH, true);








/*YAHOO.widget.Tooltip.prototype.doShow = function(e, context) {
	
	var yOffset = 25,
        me = this;

	if (YAHOO.env.ua.opera && context.tagName &&
        context.tagName.toUpperCase() == "A") {
		yOffset += 12;
	}

	return setTimeout(function() {

		var txt = me.cfg.getProperty("text");

		// title does not over-ride text
		if (me._tempTitle && (txt === "" || YAHOO.lang.isUndefined(txt) || YAHOO.lang.isNull(txt))) {
			me.setBody(me._tempTitle);
		} else {
			me.cfg.refireEvent("text");
		}

		me.moveTo(me.pageX + 50, me.pageY + yOffset);

		if (me.cfg.getProperty("preventoverlap")) {
			me.preventOverlap(me.pageX + 50, me.pageY);
		}

		YAHOO.util.Event.removeListener(context, "mousemove", me.onContextMouseMove);

		me.contextTriggerEvent.fire(context);

		me.show();

		me.hideProcId = me.doHide();

	}, this.cfg.getProperty("showdelay"));
};

function initToolTip() {
	myTooltip = new YAHOO.widget.Tooltip("bioTooltip", {
	context: "PhysName",
		text: "<p align='left'><strong>Why are we asking you this?</strong><br />Bloomington Hospital wishes to respect your religious/spiritual needs, so we need to be aware of any affiliations you may have.</p>",
		width: "300px",
		showDelay: 200
	});
}

YAHOO.util.Event.onDOMReady(initToolTip); */


