﻿"use strict";

var PB = {

	loader: null,
	autocomplete: null,
	autocomplete2: null,
	autocomplete3: null,
	data: null,
	keywords: null,
	datasource: null,
	datasource2: null,
	datasource3: null,
	init: function()
	{
		Dom.addClass(document.body, 'yui-skin-sam');
		showHide($('showHide'), 'advanceSearch');

		this.build();

		/* this.loader = new YAHOO.util.YUILoader();

		this.loader.insert({
			require: ['autocomplete', 'json', 'connection'],
			onFailure: function() { alert('Failed to Initialize'); },
			scope: this,
			onSuccess: this.build
		}); */

	},

	build: function()
	{
		var callback =
		{
			scope: this,

			success: function(o)
			{
				if (o.responseText !== null)
				{
					this.keywords = YAHOO.lang.JSON.parse(o.responseText);

					// Use a LocalDataSource
					this.datasource3 = new YAHOO.util.LocalDataSource(this.keywords);


					// Optional to define fields for single-dimensional array
					this.datasource3.responseSchema = { fields: ["Keyword"] };

					// Instantiate the AutoComplete 
					this.autocomplete3 = new YAHOO.widget.AutoComplete("keyword", "keywordContainer", this.keywords);
					this.autocomplete3.prehighlightClassName = "yui-ac-prehighlight";
					this.autocomplete3.useShadow = true;
					this.autocomplete3.useIFrame = true;					
					this.autocomplete3.allowBrowserAutocomplete = false;
				}
			}
		};

		var callback2 =
		{
			scope: this,

			success: function(o)
			{
				if (o.responseText !== null)
				{
					this.data = YAHOO.lang.JSON.parse(o.responseText);

					// Use a LocalDataSource
					this.datasource = new YAHOO.util.LocalDataSource(this.data);
					this.datasource2 = new YAHOO.util.LocalDataSource(this.data);

					// Optional to define fields for single-dimensional array
					this.datasource.responseSchema = { fields: ["last"] };
					this.datasource2.responseSchema = { fields: ["first"] };

					// Instantiate the AutoComplete 
					this.autocomplete = new YAHOO.widget.AutoComplete("last", "lastNameContainer", this.datasource);
					this.autocomplete.prehighlightClassName = "yui-ac-prehighlight";
					this.autocomplete.useShadow = true;
					this.autocomplete.useIFrame = true;
					this.autocomplete.allowBrowserAutocomplete = false;

					this.autocomplete2 = new YAHOO.widget.AutoComplete("first", "firstNameContainer", this.datasource2);
					this.autocomplete2.prehighlightClassName = "yui-ac-prehighlight";
					this.autocomplete2.useShadow = true;
					this.autocomplete2.useIFrame = true;
					this.autocomplete2.allowBrowserAutocomplete = false;


				}
			}
		};

		var cObj = YAHOO.util.Connect.asyncRequest('POST', '/load.asp?action=physicians', callback2);
		var cObj2 = YAHOO.util.Connect.asyncRequest('POST', '/load.asp?action=keywords', callback);
	}
};

Event.onDOMReady(PB.init, PB, true);