					// ########### change text size javascript ###########
					var DEFAULT_SIZE = "70%";
					var LARGER_SIZE = "80%";
					
					function toggle_text_size(text_link) {
						if (document.documentElement.style.fontSize == LARGER_SIZE) decrease_text(text_link);
						else increase_text(text_link);
						
					}
					
					function increase_text(text_link) {
					
							var text_node = document.createTextNode("Increase/Decrease Text Size");
							document.documentElement.style.fontSize = LARGER_SIZE;
							text_link.className = "decrease";
							text_link.setAttribute("title", "Decrease Text Size");
							text_link.removeChild(text_link.firstChild);
							text_link.appendChild(text_node);
					
					}
					
					function change_link_text() {
					
							var text_link = document.getElementById("page_toolbar_text").getElementsByTagName("a")[0];
							var text_node = document.createTextNode("Increase/Decrease Text Size");
							text_link.className = "decrease";
							text_link.setAttribute("title", "Decrease Text Size");
							text_link.removeChild(text_link.firstChild);
							text_link.appendChild(text_node);
							
					
					}
					
					function decrease_text(text_link) {
					
							var text_node = document.createTextNode("Increase/Decrease Text Size");
							document.documentElement.style.fontSize = DEFAULT_SIZE;
							text_link.className = "increase";
							text_link.setAttribute("title", "Increase Text Size");
							text_link.removeChild(text_link.firstChild);
							text_link.appendChild(text_node);
					
						
					}
					function check_text_size() {
						var cookie = get_cookie("text_size");
						var current_text_size = cookie ? cookie : get_default_text_size();
						return set_current_text_size(current_text_size);
					}
					
					
					function text_size_unload() {
						var current_text_size = get_current_text_size();
						make_cookie("text_size", current_text_size);
					}

					addUnloadEvent(text_size_unload);
					
					function set_current_text_size(current_text_size) {
						if (current_text_size == LARGER_SIZE) {
							document.documentElement.style.fontSize = LARGER_SIZE;
							return true;
						}
						return false;
					}
					
					function get_default_text_size() { return DEFAULT_SIZE; }
					
					function get_current_text_size() {
					
						if (document.documentElement.style.fontSize == LARGER_SIZE) return LARGER_SIZE;
						else return DEFAULT_SIZE;
						
					}
					
					function make_cookie(name, val) {
  						var expires = "";
  						document.cookie = name+"="+val+expires+"; path=/";
					}
					
					function get_cookie(name) {
					
						var n = name + "=";
						var cookieArray = document.cookie.split(';');
					
						for( var h = 0; h < cookieArray.length; h++ ) {
					
							var c = cookieArray[h];
					
							while (c.charAt(0)==' ') c = c.substring(1,c.length);
					
							if (c.indexOf(n) == 0) return c.substring(n.length,c.length);
					
						}
					
						return null;

					}


					// ##### END CHANGE TEXT SIZE JAVASCRIPT ##########################

					// ##### FUNCTION: addUnloadEvent
					// #####  PURPOSE: appends a function to the window.unonload event handler 
					function addUnloadEvent(func) {
						var oldonunload = window.onunload;
						if (typeof window.onunload != 'function') {
							window.onunload = func;
						} else {
							window.onunload = function() {
								if (oldonunload) {
									oldonunload();
								}
								func();
							}
						}
					}

					// ##### FUNCTION: addLoadEvent
					// #####  PURPOSE: appends a function to the window.onload event handler 
					function addLoadEvent(func) {
						var oldonload = window.onload;
						if (typeof window.onload != 'function') {
							window.onload = func;
						} else {
							window.onload = function() {
								if (oldonload) {
									oldonload();
								}
								func();
							}
						}
					}
			
			
					// ######################################################################
					// ##### SMART NAVIGATION VARIABLE DECLARATIONS
			
					// ##### ALLOW_REFRESH: set to true for back-button compatibility.  set to false for fastest response time. ##### 
					var ALLOW_REFRESH = true;
			
					// ##### VISIBILITY_CLASS_NAME: the class for the list items that will be shown by default.  This class is
					// ##### predefined by smart_navigation.  It is also used within the css.
					var VISIBILITY_CLASS_NAME = "show";
			
					// ##### MORE_LINK_LASS_NAME: the class of the list item which the user clicks on to show all the links.
					var MORE_LINK_CLASS_NAME = "more";
			
					// ##### MORE_LINK_TEXT: the text displayed for the "more" links.
					var MORE_LINK_TEXT = "More ...";
			
					// ##### BACK_LINK_CLASS_NAME: the class of the anchor tag which the user click on to return back to the main content.
					var BACK_LINK_CLASS_NAME = "back";
			
					// ##### BACK_LINK_TEXT: the text displayed for the "back" link.
					var BACK_LINK_TEXT = "Back";
			
					// ##### CONTENT_MAIN_ID: the ID of the parent node to the content body.
					var CONTENT_MAIN_ID = "content_main";
			
					// ##### CONTENT_BODY_ID: the ID of the actual content which is displayed on the page.
					var CONTENT_BODY_ID = "content_body";
			
					// ##### SMART_NAVIGATION_ID: the ID of the smart_navigation element.
					var SMART_NAVIGATION_ID = "smart_navigation";
					var STAYWELL_NAVIGATION_ID = "staywell_navigation";
			
					// ##### SUBLIST_CLASS_NAME: the class name of the sublists inside each list-item of the main smart_navigation list.
					var SUBLIST_CLASS_NAME= "sub";
			
					// ##### VISIBLE_SMART_CLASS_NAME: the class name of the element which holds the visible smart nav links for the current "more" section.
					var VISIBLE_SMART_CLASS_NAME = "visible_smart";
			
			
					// ######################################################################
					// ##### SMART NAVIGATION FUNCTION DECLARATIONS
			
					// ##### show_content_body: displays the content body area of the page.
					function show_content_body() { 
						document.getElementById(CONTENT_BODY_ID).style.display = "block"; 
						var graph_wrapper = document.getElementById('content_graph_wrapper');
						if (graph_wrapper != null) {
							graph_wrapper.style.display = "block"; 
						}
					}
			
					// ##### hide_content_body: hides the content body area of the page.
					function hide_content_body() { 
						document.getElementById(CONTENT_BODY_ID).style.display = "none"; 
						var graph_wrapper = document.getElementById('content_graph_wrapper');
						if (graph_wrapper != null) {
							graph_wrapper.style.display = "none"; 
						}
					}
			
					// ##### check_smart_navigation: checks to see if any "more" links need to be created for the smart navigation lists.
					function check_smart_navigation() {
			
						var list = document.getElementById(SMART_NAVIGATION_ID).getElementsByTagName("ul");
						for (var i = 0; i < list.length; i++) if (list[i].className == SUBLIST_CLASS_NAME) create_more_link(list[i], list[i].parentNode.getAttribute("id"));
						if($(STAYWELL_NAVIGATION_ID)){
							list = document.getElementById(STAYWELL_NAVIGATION_ID).getElementsByTagName("ul");
							for (i = 0; i < list.length; i++) if (list[i].className == SUBLIST_CLASS_NAME) create_more_link(list[i], list[i].parentNode.getAttribute("id"));
						}

					}
			
					// ##### remove_visible_links: deletes any elements within the main content area that were created by a "more" link.
					function remove_visible_links() { 
			
						var divs = document.getElementById(CONTENT_MAIN_ID).getElementsByTagName("div");
						for (var i = 0; i < divs.length; i++) if (divs[i].className == VISIBLE_SMART_CLASS_NAME) document.getElementById(CONTENT_MAIN_ID).removeChild(divs[i]); 
					
					}
			
					// ##### create_more_link: checks for hidden links in a list, creates the a more link at the end of a list of hidden links.
					function create_more_link(sublist, category_id) {
			
						var has_hidden_links = false;
						var items = sublist.getElementsByTagName("li");
			
						// ##### Assume that any links without the VISIBILITY_CLASS_NAME are hidden.
						// ##### if any links without the visibility class name are found, then assume
						// ##### that a more link is required.
						for (var i = 0; i < items.length; i++) {
							if (items[i].className != VISIBILITY_CLASS_NAME) {
								has_hidden_links = true;
							}
						}
			
						// ##### if there are any hidden links,
						// ##### create a new list-item for the more link.
						if (has_hidden_links) {
			
							var more_link = document.createElement("a");
							var more_text = document.createTextNode(MORE_LINK_TEXT);
			
							// ##### create the URL for the more link
							var more_link_href = build_more_link(category_id);
							more_link.setAttribute("href", more_link_href);
			
							// ##### GLOBAL BEHAVIOR SWITCH #####
							// ##### if ALLOW_REFRESH is false, NO back-button functionality
							if (ALLOW_REFRESH == false) more_link.onclick = function() {
									hide_content_body();
									remove_visible_links();
									show_more(category_id);
									return false;
							}
			
							// ##### Add the text inside the anchor tag.
							more_link.appendChild(more_text);
			
							// ##### create the list item parent for the anchor tag.
							var more_list_item = document.createElement("li");
							more_list_item.appendChild(more_link);
							more_list_item.className = MORE_LINK_CLASS_NAME;
			
							// ##### attach the more link list item to the end of the list.
							sublist.appendChild(more_list_item);
						}
			
					}
			
					// ##### show_more: displays a duplicate list of links in the main content area
					// ##### includes creation of the back anchor tag which is used to revert back to the original document state.
					function show_more(category_id) {
			
						// ##### create dynamic visible id
						var visible_id = category_id + "_visible";
			
						// ##### create a duplicate set of related links.
						var links = document.getElementById(category_id).getElementsByTagName("ul")[0].cloneNode(true);
			
						// ##### remove the existing "more" link from the clone.
						links.removeChild(links.lastChild);
			
						// ##### create the division which will be used to house the duplicate list.
						var visible_smart = document.createElement("div");
						visible_smart.setAttribute("id", visible_id);
						visible_smart.appendChild(links);
						visible_smart.className = VISIBLE_SMART_CLASS_NAME;
			
						// ##### create the back link
						var back_link = document.createElement("a");
						var back_text = document.createTextNode(BACK_LINK_TEXT);
						back_link.appendChild(back_text);
						back_link.className = BACK_LINK_CLASS_NAME;
						var back_link_href = build_back_link(category_id);
						back_link.setAttribute("href", back_link_href);
			
						// ##### GLOBAL BEHAVIOR SWITCH #####
						// ##### if ALLOW_REFRESH is false, NO back-button functionality
						if (ALLOW_REFRESH == false) back_link.onclick = function() {
								remove_visible_links();
								show_content_body();
								return false;
						}
			
						// ##### attach the back link just below the duplicate list inside the housing division.
						visible_smart.appendChild(back_link);
			
						// ##### attach the housing division to the bottom of the main content area.
						document.getElementById(CONTENT_MAIN_ID).appendChild(visible_smart);

						var content_divisions = document.getElementById(CONTENT_MAIN_ID).getElementsByTagName("div");

						for (var i = 0; i < content_divisions.length; i++) {
							if (content_divisions[i].className == "content_sub") {
								document.getElementById(CONTENT_MAIN_ID).appendChild(visible_smart);
								document.getElementById(CONTENT_MAIN_ID).appendChild(content_divisions[i]);
								i = content_divisions.length;
							}
						}

						
					}
			
					// ##### check_query: parse the current query string and search for the "more" parameter.
					// ##### if found, perform basic functions for displaying the more links.
					function check_query() {
			
						// ##### grab the query string (everything from "?...." in the URL)
						var searchString = document.location.search;
			
						// ##### strip off the leading '?'
						searchString = searchString.substring(1);
						var nvPairs = searchString.split("&");
			
						// ##### Loop through all name=value pairs
						for (i = 0; i < nvPairs.length; i++) {
			
							// ##### split up the pairs and assign variables
							var nvPair = nvPairs[i].split("=");
							var name = nvPair[0];
							var value = nvPair[1];
			
							// ##### look for the pair with the name == "more"
							if (name == "more") {
			
								// ##### perform basic functions for displaying the
								// ##### more links.
								hide_content_body();
								remove_visible_links();
								show_more(value);
								
								// ##### end the loop
								i = nvPairs.length;
							}
						}
					}
			
					// ##### rebuild_original_query: takes in a query string
					// ##### returns query string without: "more=...."
					// ##### WORKS FOR BOTH STATIC AND DYNAMIC PUBLISHING
					function rebuild_original_query(existingQuery) {
			
						// ##### initialize original query place holder.
						var original_query = "";
			
						if (existingQuery == "") return original_query;
						else {
			
							// ##### remove question mark.
							existingQuery = existingQuery.substring(1);
			
							// ##### split up query string into name=value pairs
							var nvPairs = existingQuery.split("&");
			
							// ##### Rebuild the query string WITHOUT more parameter.
							for (i = 0; i < nvPairs.length; i++) {
			
								// ##### split the pair and assign the variables.
								var nvPair = nvPairs[i].split("=");
								var name = nvPair[0];
								var value = nvPair[1];
			
								// ##### exclude "more" parameter in the rebuild.
								if (name != "more") {
									original_query += name+"="+value+"&";
								}
							}
						
							// ##### return original query without trailing ampersand.
							if (original_query != "") return "?" + original_query.substring(0, original_query.length-1);
							else return "";
			
						}
			
					}
			
					// ##### build_back_link: returns the original link to the document without "more" query string parameters.
					// ##### WORKS FOR BOTH STATIC AND DYNAMIC PUBLISHING
					function build_back_link() {
			
						// ##### create place holder for final url
						var myURL = "";
			
						// ##### split the URL in half at the question mark
						var splitURL = document.URL.split("?");
			
						// ##### if no question mark, this means there's no query string to worry about.
						// ##### so, set the final url to the current url.
						if (splitURL.length == 1) myURL = document.URL;
						else {
			
							// ##### grab the original query, minus any pre-existing "more" parameters.
							var myQuery = rebuild_original_query(document.location.search);
							
							// ##### set up the rest of the URL including the any sort of original query string.
							myURL = splitURL[0] + myQuery;
			
						}
			
						return myURL;
					}
			
					// ##### build_more_link: returns the more link including dynamic query string with "more" parameter.
					// ##### WORKS FOR BOTH STATIC AND DYNAMIC PUBLISHING
					function build_more_link(more) {
			
						// ##### create place holder for final url
						var myURL = "";
			
						// ##### split the URL in half at the question mark
						var splitURL = document.URL.split("?");
			
						// ##### if no question mark, the length of the split array will be one.
						// ##### this means there's no query string to worry about.
						// ##### so, set the final url to the current url and append a small query string to invoke the more link.
						if (splitURL.length == 1) myURL = document.URL+"?more="+more;
						else {
			
							// ##### grab the original query, minus any pre-existing "more" parameters.
							var myQuery = rebuild_original_query(document.location.search);
			
							// ##### set up the rest of the URL.
							myURL = splitURL[0];
			
							// ##### If there still isn't any query string, append the single parameter
							// ##### (The only time this would happen is if the original URL ended in only a question mark.)
							if (myQuery == "") myURL += "?more="+more;
			
							// ##### append the query string to the url, including the additional parameter
							else myURL += myQuery+"&more="+more;
			
						}
			
						// ##### return the final url
						return myURL;
					}
			

					function popupEmailWindow(pagename, pageurl, sitename) {
    						top.thisWin= window.open("/EmailPage/email_this_page.jsp?siteName=" + escape(sitename) + "&pageDisplayName=" + pagename + "&pageURL=" + escape(pageurl),"thisPage","scrollbars=1,resizable=1,menubar=0,toolbar=0,width=640,height=500");
    						if(!top.thisWin.closed) top.thisWin.focus();
					}

					function popUp(URL, x, y) {
						day = new Date();
						id = day.getTime();
						options = "toolbar=no, scrollbars=no, location=no, statusbar=no, menubar=no, resizable=no, width=" + x + ", height=" + y + ", left=570, top=150";
						window.open(URL, id, options);
					}

					function eHA_escapeSingleQuote(strVal) {
						sRetVal = new String(strVal);
						sRetVal = sRetVal.replace(/'/g,"\\'");
						return sRetVal;
					}

					function eHA_escapeDoubleQuote(strVal) {
						sRetVal = new String(strVal);
						sRetVal = sRetVal.replace(/\"/g,/\\"/);
						return sRetVal;
					}

					function clearField(theField, defaultText) {
						if (theField.value == defaultText) {
							theField.value = "";
						}
					}

					function revertField(theField, defaultText) {
						if (theField.value == "") {
							theField.value = defaultText;
						}
					}

					function returnPageURL() {
						// alert(document.location.href);
						return document.location.href
					}

		
					// used with greystone newsletters.
					function rotateNodes() {
		         			var x = document.getElementsByTagName("div");
         					var i;
         					for (i = 0; i < x.length; i++) {
		            			    if (x[i].className == "news_online_section") {
        	      				       var theNodeInQuestion = x[i];
	            				    }
						}
		
	        				if (theNodeInQuestion != null) {
							theNodeInQuestion.parentNode.parentNode.appendChild(theNodeInQuestion);
        					}
						
					}

					function bookmarkPage(bookmarkURL,bookmarkTitle){
						try{
							window.external.AddFavorite(bookmarkURL, bookmarkTitle);
						}catch(e){
							alert("To bookmark this page please type Ctrl+D on your keyboard.");
						}
					}

					
					function page_toolbar() {
						var text_link = document.getElementById("page_toolbar_text").getElementsByTagName("a")[0];
						var print_link = document.getElementById("page_toolbar_print").getElementsByTagName("a")[0];
						
						var bookmark_link = $$("#page_toolbar_bookmark a")[0];
						
						bookmark_link.onclick = function(){
							var thisURL = document.location.href;
							var thisTitle = document.title;
							bookmarkPage(thisURL,thisTitle);
							return false;
						}

						text_link.onclick = function () {
							toggle_text_size(this);
							return false;
						}

						print_link.onclick = function () {
							window.print();
							return false;
						}
					}

/* ##### GLOBAL VARIABLES ##### */
var SPOTLIGHT_RANDOM = false;
var SPOTLIGHT_NEXT_LINK_CLASSNAME = "next";
var SPOTLIGHT_NEXT_LINK_TEXTNODE = "Next";
var SPOTLIGHT_PREV_LINK_CLASSNAME = "previous";
var SPOTLIGHT_PREV_LINK_TEXTNODE = "Previous";
var SPOTLIGHT_VISIBLE_CLASSNAME = "visible_spotlight";
var SPOTLIGHT_HIDDEN_CLASSNAME = "hidden_spotlight";
var SPOTLIGHT_NAV_CLASSNAME = "spotlight_nav";

function hide_node(e) { e.className = SPOTLIGHT_HIDDEN_CLASSNAME; }
function show_node(e) { e.className = SPOTLIGHT_VISIBLE_CLASSNAME; }

// function setup_arrows(spotlight_id) {

// 	var spotlight_nav_id = spotlight_id+"_nav";
// 	var content_spotlight = document.getElementById(spotlight_id);
// 	var content_spotlight_nav = document.createElement("ul");
// 	var next = document.createElement("li");
// 	var prev = document.createElement("li"); 
// 	var next_link = document.createElement("a");
// 	var prev_link = document.createElement("a");
// 	var next_text = document.createTextNode(SPOTLIGHT_NEXT_LINK_TEXTNODE);
// 	var prev_text = document.createTextNode(SPOTLIGHT_PREV_LINK_TEXTNODE);
// 	
// 	prev_link.appendChild(prev_text);
// 	prev.appendChild(prev_link);

// 	next_link.appendChild(next_text);
// 	next.appendChild(next_link);

// 	content_spotlight_nav.appendChild(next);
// 	content_spotlight_nav.appendChild(prev);
// 	content_spotlight_nav.setAttribute("id", spotlight_nav_id);
// 	content_spotlight_nav.className = SPOTLIGHT_NAV_CLASSNAME;

// 	next_link.className = SPOTLIGHT_NEXT_LINK_CLASSNAME;
// 	next_link.setAttribute("href", '#');

// 	prev_link.className = SPOTLIGHT_PREV_LINK_CLASSNAME;
// 	prev_link.setAttribute("href", '#');
// 	
// 	next_link.onclick = function() {
// 		go_forward(spotlight_id);
// 		return false;
// 	}
// 	
// 	prev_link.onclick = function() {
// 		go_backward(spotlight_id);
// 		return false;
// 	}
// 	
// 	hide_spotlights(content_spotlight);
// 	content_spotlight.appendChild(content_spotlight_nav);
// 						
//}


// required prototype
function setup_arrows(spotlight_id){
	var numSpotlights = $$("#"+spotlight_id+" ul li").length;
	
	var ul = new Element('ul', { 'id':spotlight_id+'_nav','class': 'spotlight_nav' });
	
	for(i=0;i<numSpotlights;i++){
		var li = new Element('li',{'id':"spotlight_nav_"+(i+1)});
		var a = new Element('a', { href:'#'}).update(i+1);
		li.appendChild(a);
		ul.appendChild(li);
	}
	
	$$("#"+spotlight_id+" ul li h4 a").each(function(element){
		var moreLink = new Element('a',{ 'class':'spotlight_more_link', href:element.href });
		moreLink.update("more");
		element.up("li").appendChild(moreLink);
	});
	
	
	hide_spotlights($(spotlight_id),false);
	$(spotlight_id).appendChild(ul);
	$("spotlight_nav_1").addClassName("sel");
	$$("#"+spotlight_id+" .spotlight_nav li").each(function(element){
		element.onclick = function(){
			hide_spotlights($(spotlight_id),true);
			show_spotlight(element.id.replace("nav_",""));
			
			clearTimeout(theInterval);
			start_intervals();
			
			return false;
		}
	});
	
}

function show_spotlight(this_spotlight_id){
	show_node($(this_spotlight_id));
	select_button(this_spotlight_id.replace("_","_nav_"));
}

function select_button(button_id){
	var buttons = $(button_id).up("ul").getElementsByTagName("li");
	for(i=0;i<buttons.length;i++){
		buttons[i].removeClassName("sel");
	}
	$(button_id).addClassName("sel");
}


function hide_spotlights(e,no_show) {

	var spotlights = e.down("ul").getElementsByTagName("li");

	if ((spotlights != null) && (spotlights.length > 0)) {

		for (var i = 0; i < spotlights.length; i++){
			spotlights[i].id = "spotlight_"+(i+1);
			hide_node(spotlights[i]);
		}
		if (SPOTLIGHT_RANDOM) var current_spotlight = get_rand_node(spotlights[0]);
		else var current_spotlight = spotlights[0];

		if(no_show==false){
			show_node(current_spotlight);
		}
	
	}

}
	
function get_visible_spotlight(spotlight_id) {

	var result = false;
	var content_spotlight = document.getElementById(spotlight_id);
	var spotlights = content_spotlight.getElementsByTagName("ul")[0].getElementsByTagName("li");

	if ((spotlights != null) && (spotlights.length > 0)) {

		for (var i = 0; i < spotlights.length; i++) {
			var spotlight = spotlights[i];
			if (spotlight.className == "visible_spotlight") {
				var result = spotlight;
				i = spotlights.length+1;
			}
		}

		if (result) return result;
		return spotlights[0];
	
	} 

	return false;

}

function get_next_node(e) {

	if (SPOTLIGHT_RANDOM) return get_rand_node(e);

	var spotlights = e.parentNode.getElementsByTagName("li");

	if ((spotlights != null) && (spotlights.length > 0)){
		for (var i = 0; i < spotlights.length; i++){
			if (spotlights[i] == e) {
				if (i == spotlights.length-1) i = -1;
				var result = spotlights[i+1]; 
				i = spotlights.length+1;
			}
		}
	
	}else{
		var result = e.parentNode.firstChild;
	}
	
	return result;

}

function get_prev_node(e) {

	if (SPOTLIGHT_RANDOM) return get_rand_node(e);

	var spotlights = e.parentNode.getElementsByTagName("li");

	if ((spotlights != null) && (spotlights.length > 0)){
		for (var i = spotlights.length-1; i >= 0; i--){
			if (spotlights[i] == e) { 
				if (i == 0) i = spotlights.length;
				return spotlights[i-1]; 
			}
		}
	}
	return e.parentNode.firstChild;

}

function get_rand_node(e) {

	var result = e;
	var spotlights = e.parentNode.getElementsByTagName("li");

	if ((spotlights != null) && (spotlights.length > 0)) {

		while (result == e) {
			var ran_unrounded = Math.random() * spotlights.length;
			var random_node = Math.floor(ran_unrounded);
			result = spotlights[random_node];
		}

		return result;

	}
						
	return false;

}

function go_forward(spotlight_id) {
	var current_node = get_visible_spotlight(spotlight_id);
	hide_node(current_node);
	show_node(get_next_node(current_node));
	if($(spotlight_id).down(".spotlight_nav .sel").next("li")){
		$(spotlight_id).down(".spotlight_nav .sel").next("li").addClassName("sel");
		$(spotlight_id).down(".spotlight_nav .sel").removeClassName("sel");
	}else{
		$(spotlight_id).down(".spotlight_nav li").addClassName("sel");
		$(spotlight_id).down(".spotlight_nav .sel").next("li.sel").removeClassName("sel");
	}
}

function go_backward(spotlight_id) {
	var current_node = get_visible_spotlight(spotlight_id);
	hide_node(current_node);
	show_node(get_prev_node(current_node));
	if($(spotlight_id).down(".spotlight_nav .sel").previous("li")){
		$(spotlight_id).down(".spotlight_nav .sel").previous("li").addClassName("sel")
		$(spotlight_id).down(".spotlight_nav .sel").next("li").removeClassName("sel");
	}else{
		$(spotlight_id).down(".spotlight_nav li:last-child").addClassName("sel")
		$(spotlight_id).down(".spotlight_nav .sel").removeClassName("sel");
	}
}
var theInterval = '';
var all_interval_expressions = '';
function start_intervals() {
	theInterval = window.setInterval(all_interval_expressions, 10000); 
}
addLoadEvent(start_intervals);



/*##############################################
############ js for dropdown Lists  ############
############ 11/21/2008 (bug 536)   ############
################################################
*/

addLoadEvent(dropdownEvents);

var dropdownHeight = 250;

function dropdownEvents(){
	$$(".dropdown_list_wrapper h4").each(function(element){
		element.onclick = function(){
			dropdownRelease();
			if(element.offsetTop+dropdownHeight-document.viewport.getScrollOffsets().top+220>document.viewport.getDimensions().height){
				element.next("ul").style.top = "auto";
				element.next("ul").style.bottom = "15px";
			}else{
				element.next("ul").style.top = "15px";
				element.next("ul").style.bottom = "auto";
			}
			element.next("ul").addClassName("sel");
			element.up(".dropdown_list_wrapper").style.position = "relative";
			if(element.next("ul").offsetHeight>dropdownHeight){
				element.next("ul").style.height = dropdownHeight+"px";
			}
		}
	});
}

function dropdownRelease(){
	$$(".dropdown_list_wrapper ul").invoke("removeClassName","sel");
	$$(".dropdown_list_wrapper").each(function(element){
		element.style.position = "static";
	});
}

function dropdownClickHandler(e){
	var releaseLists = true;
	if(Event.element(e).up(".dropdown_list_wrapper")){
		releaseLists = false;
	}
	if(releaseLists){
		dropdownRelease();
	}
}


function createNewsButtons(featured_news_id){
	if($(featured_news_id)){
		var newsButtonUL = new Element('ul', { 'class': 'featured_news_nav' });
		var i = 1;
		var newsLIs = $$("#"+featured_news_id+" ul li h3 a").each(function(element){
			element.up("li").id = "featured_news_"+i;
			var thisLI = new Element('li', { 'id':"featured_news_nav_"+i });
			var thisA = new Element('a', { href:'#' });
			thisA.update(element.innerHTML);
			i++;
			thisLI.appendChild(thisA);
			newsButtonUL.appendChild(thisLI);
		});
		
		$$(".featured_news")[0].insertBefore(newsButtonUL,$$(".featured_news ul")[0]);
		
		$$("#"+featured_news_id+" .featured_news_nav a").each(function(element){
			element.onclick = function(){
				clearNewsSelect(featured_news_id);
				this.up("li").addClassName("sel");
				$(this.up("li").id.replace("_nav_","_")).addClassName("sel");
				return false;
			}
		});
		
		var firstLI = $$("#"+featured_news_id+" .featured_news_nav li")[0];
		firstLI.addClassName("sel");
		$(firstLI.id.replace("_nav_","_")).addClassName("sel");
	}
}

function clearNewsSelect(featured_news_id){
	$$("#"+featured_news_id+" ul li").invoke("removeClassName","sel");
}










function setup_location_page(){
	// to kill error
}





function Calendar_filter(event_category){
	if(event_category=="null"){
		$$("#calendar table div.event").each(function(element){
			element.show();
		});
	}else{
		$$("#calendar table div.event").each(function(element){
			if(event_category.indexOf(":")!=-1){
				if(element.hasClassName("event_category_"+event_category.replace(/ /g,"_"))){
					element.show();
				}else{
					element.hide();
				}
			}else{
				var showThisEvent = false;
				// this event_category is a "parent" category
				$w(element.className).each(function(thisClass){
					if(thisClass.indexOf(event_category.replace(/ /g,"_"))!=-1){
						showThisEvent = true;
					}
				});
				if(showThisEvent){
					element.show();
				}else{
					element.hide();
				}
			}
		});
	}
}



function Calendar_addCalendarToolsEvents(){
	if($('calendar_tools')){
		$('event_filter').onchange = function(){
			Calendar_filter(this.options[this.options.selectedIndex].value);
			return false;
		}
	}
}







var LandingPageSpotlightLimit = 4;
LandingPageSpotlightLimit--;

var LandingPageSpotlightPosition = 0;

function LandingPageSpotlights_HideAll(elementID){
	$(elementID).down("ul").childElements().invoke("hide");
}

function LandingPageSpotlights_Previous(el){
	var elementID = el.up("div").id;
	LandingPageSpotlights_HideAll(elementID);
	var spotlightLIs = $(elementID).down("ul").childElements();
	//var spotlightLIs = $$("#"+elementID+" ul li");
	
	LandingPageSpotlightPosition--;
	if(LandingPageSpotlightPosition<0){
		LandingPageSpotlightPosition = 0;
	}
	
	for(i=LandingPageSpotlightPosition;i<spotlightLIs.length;i++){
		if(i<=(LandingPageSpotlightLimit+LandingPageSpotlightPosition)){
			spotlightLIs[i].show();
		}
	}
}

function LandingPageSpotlights_Next(el){
	var elementID = el.up("div").id;
	LandingPageSpotlights_HideAll(elementID);
	var spotlightLIs = $(elementID).down("ul").childElements();
	
	LandingPageSpotlightPosition++;
	if(LandingPageSpotlightPosition>(spotlightLIs.length-LandingPageSpotlightLimit-1)){
		LandingPageSpotlightPosition = spotlightLIs.length-LandingPageSpotlightLimit-1;
	}
	
	for(i=LandingPageSpotlightPosition;i<spotlightLIs.length;i++){
		if(i<=(LandingPageSpotlightLimit+LandingPageSpotlightPosition)){
			spotlightLIs[i].show();
		}
	}
}

function LandingPageSpotlights_MakeNav(elementID){
	if($(elementID)){
		var spotlightLIs = $$("#"+elementID+" ul li");
		for(i=0;i<spotlightLIs.length;i++){
			if(i>LandingPageSpotlightLimit){
				spotlightLIs[i].hide();
			}
		}
		
		var ul_nav = new Element('ul', { 'id':elementID+'_nav','class': 'spotlight_nav' });

		var li_prev = new Element('li',{'id':elementID+"spotlight_nav_prev",'class':'prev'});
		var a_prev = new Element('a', { href:'#','title':'previous'}).update("previous");
		li_prev.appendChild(a_prev);
		ul_nav.appendChild(li_prev);
				
		var li_next = new Element('li',{'id':elementID+"spotlight_nav_next",'class':'next'});
		var a_next = new Element('a', { href:'#','title':'next'}).update("next");
		li_next.appendChild(a_next);
		ul_nav.appendChild(li_next);

		$(elementID).appendChild(ul_nav);
		
		$(elementID+'spotlight_nav_prev').down("a").onclick = function(element){
			LandingPageSpotlights_Previous(this);
			return false;
		};
		
		$(elementID+'spotlight_nav_next').down("a").onclick = function(element){
			LandingPageSpotlights_Next(this);
			return false;
		};
		
	}
	return false;
}









/*
The following addLoadEvent command should be in Common/javascript


*/

/*
addLoadEvent(function(){
	FindADoctor_addSearchPageEvents("includes/typeahead.php");
});
*/



var FindADoctor_loadingImage = $CE("img",{'src':'/eHA_files/images/ajax/big.gif','alt':'Please Wait.'});
FindADoctor_loadingImage.addClassName("ajax_loading");


function FindADoctor_typeAheadJSON(FindADoctor_TypeAheadURL,typeAheadTextID,typeAheadDivID){
	var FindADoctor_dataArray = new Array();
	new Ajax.Request(FindADoctor_TypeAheadURL,
	  {
	    method:'get',
	    parameters: "postName="+typeAheadTextID,
	    onCreate: function(){
			//$(typeAheadDivID).update("<img src='/eHA_files/images/ajax/big.gif' alt='Please Wait.' class='ajax_loading' />");
	    },
	    onSuccess: function(transport){
		    FindADoctor_dataArray = (transport.responseText).evalJSON(true);
	    	// begin local autocomplete
	    	new Autocompleter.Local(typeAheadTextID,typeAheadDivID,FindADoctor_dataArray,{fullSearch:true,partialChars:2});
	    },
	    onFailure: function(){ 
			// alert('Something went wrong...');
		}
	  });
}



function FindADoctor_addSearchPageEvents(){
	if(window.location.hash && $("quick_search") && $("advanced_search") && $("advanced_more_options")){
		var hashArray = window.location.hash.substring(1).toQueryParams();
		FindADoctor_replaceSearchForm(FindADoctor_FindADoctorSubTemplateURL,hashArray)
		return true;
	}
	
	if($("advanced_more_options") && $("advanced_more_options_button") && $("quick_search_text") && $("advanced_search_lastname_text") && $("advanced_search_condition_text")){
		$('advanced_more_options').hide();
		$('more_options').childElements().each(function(element){
			element.style.position = 'static';
			element.style.left = 'auto';
		});
		
		
		/*
		These Autocompleter calls must be replaced with straight Ajax.Request calls.  The transport.responseText must be parsed as a JSON array and then searched with findAll.
		The only variable that should be passed to the URL is postName, with one of 3 (or 4?) values.  This will give us only 4 cached pages to search (rather than the infinite
		possibilities for cached pages that may occur with the current configuration.
		The searching will be client-side with findAll.
		*/
		
		
		FindADoctor_typeAheadJSON(FindADoctor_TypeAheadURL,"quick_search_text","quick_search_text_typeAhead");
		FindADoctor_typeAheadJSON(FindADoctor_TypeAheadURL,"advanced_search_lastname_text","advanced_search_lastname_text_typeAhead");
		FindADoctor_typeAheadJSON(FindADoctor_TypeAheadURL,"advanced_search_firstname_text","advanced_search_firstname_text_typeAhead");
		FindADoctor_typeAheadJSON(FindADoctor_TypeAheadURL,"advanced_search_condition_text","advanced_search_condition_text_typeAhead");
				
				
		$("advanced_more_options_button").onclick = function(){
			if($("advanced_more_options_button").value.indexOf("More")!=-1){
				$("advanced_more_options_button").value = "Less";
			}else{
				$("advanced_more_options_button").value = "More";
			}
			Effect.toggle('advanced_more_options', 'slide',{duration:0.5});
		}
		
		$("quick_search_submit").onclick = function(){
			FindADoctor_executeSearchForm($("quick_search_submit"));
			return false;
		}
		
		$("advanced_search_submit").onclick = function(){
			FindADoctor_executeSearchForm($("advanced_search_submit"));
			return false;
		}
		
		$("quick_search_text").onfocus = function(){
			var thisForm = this.up("form");
			var thisValue = this.value;
			thisForm.reset();
			this.value = thisValue;
			return false;
		}

		$("advanced_search_lastname_text").onfocus = function(){
			$("quick_search_text").value = "";
			$("advanced_search_condition_text").value = "";
			return false;
		}
		
		$("advanced_search_condition_text").onfocus = function(){
			$("quick_search_text").value = "";
			$("advanced_search_lastname_text").value = "";
			return false;
		}
		
		if($('specialty_list_link')){
			$('specialty_list_content').hide();
			
			new Ajax.Request(FindADoctor_TypeAheadURL,
			  {
			    method:'get',
			    parameters: "postName="+"advanced_search_condition_text",
			    onCreate: function(){
					//$(typeAheadDivID).update("<img src='/eHA_files/images/ajax/big.gif' alt='Please Wait.' class='ajax_loading' />");
			    },
			    onSuccess: function(transport){
				    condition_array = (transport.responseText).evalJSON(true);
			    	// begin local autocomplete
					var thisUL = $CE("ul");
					for(i=0;i<condition_array.length;i++){
						var thisLI = $CE("li");
						var thisA = $CE("a",{'href':'#'});
						thisA.update(condition_array[i]);
						thisLI.appendChild(thisA);
						thisUL.appendChild(thisLI);
					}
					$('specialty_list_content').appendChild(thisUL);
					$$('#specialty_list_content a').each(function(element){
						element.onclick = function(){
							$('advanced_search_condition_text').value = this.innerHTML;
							return false;
						}
					});

			    },
			    onFailure: function(){ 
					// alert('Something went wrong...');
				}
			  });

			$('specialty_list_link').onclick=function(){
				$('specialty_list_content').toggle();
				return false;
			};
		}
	}
}


function FindADoctor_TypeAheadCallback(autoCompleteInput,element){
	//autoCompleteInput.value = element.innerHTML;
	//console.log(element.innerHTML);
	//console.log(autoCompleteInput.value);
	if(element.id && $("assettype") && $("assetid")){
		var assettype = element.id.split("~")[0];
		var assetid = element.id.split("~")[1];
		
		$("assettype").value = assettype;
		$("assetid").value = assetid;
		
		return true;
	}
}
	
function randomInt(startInt,endInt){
	// startInt can be positive or negative or zero
	// endInt is incremented so that the range is inclusive
	endInt++;
	var result = Math.floor(Math.random()*endInt);
	result = result + startInt;
	return result;
}












	
	
	
	
	
	
/*	
the following addLoadEvent and addEvents function should run when the search results are loaded

maybe place them in the subtemplate? template?

what about FindADoctor_readHash?


-- will use these 3 commands in the Common/javascript element

*/
/*
addLoadEvent(FindADoctor_addSearchResultsEvents);

addLoadEvent(FindADoctor_readHash);

addLoadEvent(FindADoctor_loadFavorites);

var FindADoctor_SearchResultsURL = "includes/AJAX_physician.php";
*/

function FindADoctor_addSearchResultsEvents(){

	if($("results") && $("filters")){
		if(window.location.hash){
			// do nothing
		}else{
			FindADoctor_readFilters();
			FindADoctor_writeHash(FindADoctor_searchFilters);
		}
	}
		
	
	if($$("#results .actions .email a")){	
		$$("#results .actions .email a").each(function(element){
			var thisTitle = element.up("div").previous("h3").down("a").innerHTML.replace(/(<([^>]+)>)/ig,"");
			var thisLink = element.up("div").previous("h3").down("a").href;
			if(thisLink.indexOf("http://")==-1){
				thisLink = "http://"+document.domain+thisLink;
			}
			//console.log(thisTitle);
			//console.log(thisLink);
			var sharethis_object = SHARETHIS.addEntry(
				{
					title:thisTitle,
					url:thisLink
				},{
					button:false,
					embeds:true
				}
			);
			sharethis_object.attachButton(element);
		});
	}
	

	if($('results') && window.location.hash){
		if($$("#results ul li h3 a")){
			$$("#results ul li h3 a").each(function(element){
				element.href = element.href+window.location.hash;
			});
		}
		if($$("#results ul li .thumbnail a")){
			$$("#results ul li .thumbnail a").each(function(element){
				element.href = element.href+window.location.hash;
			});
		}
		if($$("#bread_crumbs .sel a")){
			$$("#bread_crumbs .sel a").each(function(element){
				element.href = element.href+window.location.hash;
			});
		}
	}
		
	
	if($$("#results .result h4 a")){
		var result_a_tags = $$("#results .result h4 a");
	
		for(i=0;i<result_a_tags.length;i++){
			if(result_a_tags[i].id.indexOf("extraButton")!=-1){
				result_a_tags[i].onclick = function(){
					var result_id = this.id.replace("extraButton","");
					Effect.toggle(result_id+"extra", 'blind', {duration:0.5});
					if($(result_id+"extraButton").innerHTML.indexOf("More")!=-1){
						$(result_id+"extraButton").innerHTML = "Less";
					}else{
						$(result_id+"extraButton").innerHTML = "More";
					}
					return false;
				}
			}
		}
	}
	if($$("#results .pagination ul li a")){
		$$("#results .pagination ul li a").each(function(element){
			element.onclick = function(){
				if($("startindex")){
					var startindex = this.innerHTML.replace(/ /g,"");
					var hashArray = window.location.hash.substring(1).toQueryParams();
					if(startindex.indexOf("previous")!=-1){
						if(hashArray["startindex"]){
							startindex = parseInt(hashArray["startindex"],10) - 1;
							if(startindex==0){
								startindex = 1;
							}
						}else{
							startindex = 1;
						}
					}else{
						if(startindex.indexOf("next")!=-1){
							if(hashArray["startindex"]){
								startindex = parseInt(hashArray["startindex"],10) + 1;
							}else{
								var hasTwo = false;
								var pageArray = $$("#results .pagination ul li a");
								for(i=0;i<pageArray.length;i++){
									if(pageArray[i].innerHTML.indexOf("2")!=-1){
										hasTwo = true;
									}
								}
								if(hasTwo){
									startindex = 2;
								}else{
									startindex = 1;
								}
							}
						}
					}
					$("startindex").value = startindex;
					FindADoctor_loadResults(startindex);
				}
				return false;
			}
		});
	}
	
	if($$("#results .back_link a")){
		$$("#results .back_link a").each(function(element){
			element.onclick=function(){
				FindADoctor_back();
				return false;
			}
		});
	}
}


function FindADoctor_back(){
	if(window.location.hash){
		window.location.hash = "";
	}
	if(window.location.hash != ""){
		// ie6 doesn't clear the hash properly
		window.location.href = window.location.href.replace("#","");
	}else{
		FindADoctor_replaceSearchForm(FindADoctor_FindADoctorSubTemplateURL,"");
	}
	
}


function $CE(tagName, attributes, styles){ //short for create element
	var el = document.createElement(tagName);
	if (attributes)
		$H(attributes).each(function(pair){
		      eval("el." + pair.key + "='" + pair.value + "'");
		});
	if (styles)
		$H(styles).each(function(pair){
		      el.style[pair.key] = pair.value;
		});
		
	return $(el);
}



function FindADoctor_readDetailHash(){
    if(window.location.hash){
	    if(window.location.hash.indexOf("email")!=-1 || window.location.hash.indexOf("print")!=-1){
	        var hash_value = window.location.hash.substring(1);
	        $$("body")[0].addClassName(hash_value+"_detail");
	        if(hash_value.indexOf("print")!=-1){
	            window.print();
	        }
        }else{
			if($$("#bread_crumbs .sel a")){
				$$("#bread_crumbs .sel a").each(function(element){
					element.href = element.href+window.location.hash;
					element.up("ul").previous("a").href = element.up("ul").previous("a").href+window.location.hash;
				});
			}
        }
        return true;
    }
    
}



function FindADoctor_addToFavorites(resultID){
	if($('favorites')){
		$(resultID).addClassName("favorite");
		Effect.Appear('favorites_wrapper');
		if($(resultID)){
			if(!$("favorite_"+resultID)){
				// add to favorites
				
				var newDIV = $CE("div",{id:"favorite_"+resultID},{display:"none"});
				
					var newH4 = $CE("h4");
						
						var newH4_A = $$("#"+resultID+" h3 a")[0].cloneNode(true);
					
// 						var newH4_A = $CE("a",{href:"physician_detail.php"});
// 						newH4_A.appendChild(document.createTextNode($$("#"+resultID+" h3 a")[0].innerHTML));
						
						newH4.appendChild(newH4_A);
				
					var newUL = $CE("ul");
						
						if($$("#"+resultID+" .specialty p") && $$("#"+resultID+" .specialty p").length>0){
							var newLI1 = $CE("li",{className:"specialty"});
							newLI1.appendChild(document.createTextNode($$("#"+resultID+" .specialty p")[0].innerHTML));
							newUL.appendChild(newLI1);
						}
						
						if($$("#"+resultID+" .affiliation p") && $$("#"+resultID+" .affiliation p").length>0){
							var newLI2 = $CE("li",{className:"affiliation"});
							newLI2.appendChild(document.createTextNode($$("#"+resultID+" .affiliation p")[0].innerHTML));
							newUL.appendChild(newLI2);
						}
						
						if($$("#"+resultID+" .phone p") && $$("#"+resultID+" .phone p").length>0){
							var newLI3 = $CE("li",{className:"phone"});
							newLI3.appendChild(document.createTextNode($$("#"+resultID+" .phone p")[0].innerHTML));
							newUL.appendChild(newLI3);
						}
					
//					var onclickA = "Effect.Fade(\"favorite_"+resultID+"\",{duration:0.2}); return false;";
//					var onclickA = "return FindADoctor_removeFavorite(this);";
						
					var newA = $CE("a",{href:"#",className:"delete",title:"Remove this from Favorites"});
					newA.appendChild(document.createTextNode("Remove this from Favorites"));
//					newA.setAttribute("onclick",onclickA);
				
				newDIV.appendChild(newH4);
				newDIV.appendChild(newA);
				newDIV.appendChild(newUL);
				
				
				
				
				$('favorites').appendChild(newDIV);
				Effect.Appear("favorite_"+resultID,{duration:0.5});
				
				var currentFavoritesCookie = getCookie("eHA_FindADoctor_Favorites");
				if(currentFavoritesCookie){
					if(currentFavoritesCookie.length>0){
						currentFavoritesCookie = currentFavoritesCookie+"-"+resultID;
					}else{
						// happens to be there but empty -- probably because favorites were removed
						currentFavoritesCookie = resultID;
					}
					setCookie("eHA_FindADoctor_Favorites",currentFavoritesCookie,365);
				}else{
					setCookie("eHA_FindADoctor_Favorites",resultID,365);
				}
			}else{
				// this is already a favorite (maybe it has been hidden)
				Effect.Appear("favorite_"+resultID,{duration:0.5});
			}
		}
		

		
	}
	FindADoctor_addFavoriteEvents();
	
	return false;
}

function FindADoctor_addFavoriteEvents(){
	if($('favorites')){
		$$("#favorites a.delete").each(function(element){
			element.onclick=function(){
				return FindADoctor_removeFavorite(this.up("div"));
			}
		});
	}
}

function FindADoctor_checkFavorites(){
	if($("favorites").down()==undefined){
		// has no children
		Effect.BlindUp("favorites_wrapper",{duration:0.2});
	}
}

function FindADoctor_removeFavorite(thisFavorite){
	Effect.Fade(thisFavorite.id,{duration:0.2});
	setTimeout("$('"+thisFavorite.id+"').up().removeChild($('"+thisFavorite.id+"'))",200);
	setTimeout("FindADoctor_checkFavorites()",220);
	
	$(thisFavorite.id.replace("favorite_","")).removeClassName("favorite");
	
	var currentFavoritesCookie = getCookie("eHA_FindADoctor_Favorites");
	if(currentFavoritesCookie){
		var resultID = thisFavorite.id.replace("favorite_","");
		// this string manipulation may leave a trailing hyphen. that is acceptable
		currentFavoritesCookie = currentFavoritesCookie.replace(resultID,"").replace(/--/g,"-");
		setCookie("eHA_FindADoctor_Favorites",currentFavoritesCookie,365);
	}else{
		// an error has occured.  if there is a favorite, there should be a cookie
		// unless user agent will not allow cookies
		
	}
	
	return false;
}

var FindADoctor_searchFilters = new Hash();

function FindADoctor_readHash(){
	if(window.location.hash){
		var old_hash = window.location.hash.substring(1);
		return old_hash.split("&");
	}
}

function FindADoctor_writeHash(hash){
	window.location.hash = hash.toQueryString();
}

// reads the values from the filters section inputs & select boxes,
// writes these values into the "FindADoctor_searchFilters" Hash object
function FindADoctor_readFilters(){
	var hashArray = FindADoctor_readHash();
	if(hashArray){
		for(i=0;i<hashArray.length;i++){
			var key = hashArray[i].split("=")[0];
			var value = unescape(hashArray[i].split("=")[1]);
			FindADoctor_searchFilters.set(key,value);
		}
	}
	$$('#filters select').each(function(element){
		if(element.selectedIndex!=0){
			FindADoctor_searchFilters.set(element.name,element[element.selectedIndex].value.replace(" ","_"));
		}else{
			// if it's 0, then "No Preference": unset it
			FindADoctor_searchFilters.unset(element.name);
		}
	});
	$$('#filters input').each(function(element){
		switch(element.type){
			case "hidden":
				if(element.value && element.value!=""){
					FindADoctor_searchFilters.set(element.name,element.value.replace(" ","_"));
				}else{
					// it's blank, unset it
					FindADoctor_searchFilters.unset(element.name);
				}
			break;
			case "text":
				if(element.value && element.value!=""){
					FindADoctor_searchFilters.set(element.name,element.value.replace(" ","_"));
				}else{
					// it's blank, unset it
					FindADoctor_searchFilters.unset(element.name);
				}
			break;
			case "checkbox":
				if(element.checked){
					if(FindADoctor_searchFilters.get(element.name)){
						if(FindADoctor_searchFilters.get(element.name).indexOf(element.value)==-1){
							// there is already a value
							if(FindADoctor_searchFilters.get(element.name)==","){
								// it's just a comma, clear it.
								FindADoctor_searchFilters.set(element.name,element.value.replace(" ","_"));
							}else{
								// it's more than a comma, add to it
								FindADoctor_searchFilters.set(element.name,FindADoctor_searchFilters.get(element.name).replace(",,",",")+","+element.value.replace(" ","_"));
							}
						}
					}else{
						FindADoctor_searchFilters.set(element.name,element.value);
					}
				}else{ // element is not checked
					if(FindADoctor_searchFilters.get(element.name) && FindADoctor_searchFilters.get(element.name)!="" && FindADoctor_searchFilters.get(element.name)!=","){
						if(FindADoctor_searchFilters.get(element.name).indexOf(element.value)!=-1){
							// element is found, must be removed (first try with comma), then try alone
							FindADoctor_searchFilters.set(element.name,FindADoctor_searchFilters.get(element.name).replace(",,",",").replace(element.value+",","").replace(element.value,""));
						}
					}
					if(FindADoctor_searchFilters.get(element.name)!=null && (FindADoctor_searchFilters.get(element.name)=="" || FindADoctor_searchFilters.get(element.name)==",")){
						// value is blank ("") or just a comma (","), unset it
						FindADoctor_searchFilters.unset(element.name);
					}
					if(FindADoctor_searchFilters.get(element.name)!=null && FindADoctor_searchFilters.get(element.name).lastIndexOf(",")==FindADoctor_searchFilters.get(element.name).length-1){
						FindADoctor_searchFilters.set(element.name,FindADoctor_searchFilters.get(element.name).slice(0,-1));
					}
				}
			break;
		}
	});
}


// need to write this function
// use Ajax, update
function FindADoctor_updateResults(FindADoctor_SearchResultsURL,hash){
	new Ajax.Request(FindADoctor_SearchResultsURL,
	  {
	    method:'get',
	    parameters: hash,
	    onCreate: function(){
			$("results").update(FindADoctor_loadingImage);
	    },
	    onSuccess: function(transport){
	    	$('results').update(transport.responseText);
	    },
	    onComplete: function(){
		    FindADoctor_addSearchResultsEvents();
	    },
	    onFailure: function(){ 
			// alert('Something went wrong...');
		}
	  });
}

var delayTimeout;

function FindADoctor_delay(functionName,delayTime){
	
	clearTimeout(delayTimeout);
	
	delayTimeout = setTimeout(functionName,delayTime);
	
	return false;
}


function FindADoctor_loadResults(startindex){
	$("startindex").value = startindex;
	FindADoctor_readFilters();
	FindADoctor_writeHash(FindADoctor_searchFilters);
	FindADoctor_updateResults(FindADoctor_SearchResultsURL,FindADoctor_searchFilters);
}

function FindADoctor_changeFilters(){
	FindADoctor_loadResults(1);
}



function FindADoctor_loadFavorites(){
	// cookie is being populated and depopulated correctly.  must load cookie and initiate AJAX request to load favorites values?
	// need new subtemplate for this?
	// begin here.
	
}

			
		
function getCookie(c_name){
	if(document.cookie.length>0){
		c_start=document.cookie.indexOf(c_name + "=");
		if(c_start!=-1){
			c_start=c_start + c_name.length+1; 
			c_end=document.cookie.indexOf(";",c_start);
			if(c_end==-1){
				c_end=document.cookie.length;
			}
			return unescape(document.cookie.substring(c_start,c_end));
		}else{
			//this cookie name not found
			return false;
		}
	}
	//no cookies
	return flase;
}
		
function setCookie(c_name,value,expiredays){
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value) + ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

























function FindADoctor_switchToTab(tab_id,tab_link_id){
	if($$("#physician_profile .tab") && $$("#profile_tab_links li")){
		try{
			var tabs = $$("#physician_profile .tab");
			var tab_links = $$("#profile_tab_links li");
			for(i=0;i<tabs.length;i++){
				tabs[i].removeClassName("on");
			}
			for(i=0;i<tab_links.length;i++){
				tab_links[i].removeClassName("on");
			}
			$(tab_id).addClassName("on");
			$(tab_link_id).addClassName("on");
		}catch(err){
	//		console.log("ERROR: "+err.description);
		}
	}
	
	return false;
}

	




/*
js to replace the search forms with the search results & filters:

*/
function FindADoctor_executeSearchForm(el){
	var inputValue = "";
	try{
		$("randomnumber").value = randomInt(0,20);
		if(el.up("fieldset").id=="quick_search"){
			inputValue = $("quick_search_text").value;
		}
		
		if(el.up("fieldset").id=="advanced_search"){
			if($("advanced_more_options_button").value=="More"){
				// ignore the "More Options"
				if($("advanced_search_lastname_text").value!=undefined && $("advanced_search_lastname_text").value!=""){
					// ignore "specialty, disease, or expertise"
					inputValue = $("advanced_search_lastname_text").value;
				}else{
					// use "specialty, disease, or expertise"
					inputValue = $("advanced_search_condition_text").value;
				}
			}else{
				// deal with ALL the "More Options"
				
			}
		}
	}catch(err){
	//	console.log("ERROR: "+err);
	}
	// execute AJAX to replaceSearchForm using inputValue
	FindADoctor_replaceSearchForm(FindADoctor_FindADoctorSubTemplateURL,el.up("form").serialize(true));
	
	return false;
}


function FindADoctor_replaceSearchForm(FindADoctor_FindADoctorSubTemplateURL,hash){
	var thisHash = hash;
	
	new Ajax.Request(FindADoctor_FindADoctorSubTemplateURL,
	{
		method:'get',
		parameters: hash,
	    onCreate: function(){
		    $("content_body").update(FindADoctor_loadingImage);
	    },
		onSuccess: function(transport){
			$('content_body').update(transport.responseText);
		},
	    onComplete: function(){
			FindADoctor_addSearchResultsEvents();
			if(hash===""){
				FindADoctor_addSearchPageEvents();
			}
	    },

		onFailure: function(){ 
			// alert('Something went wrong...');
		}
	});
}



function setup_location_page(){
	// to kill error
}





function Calendar_filter(event_category){
	if(event_category=="null"){
		$$("#calendar table div.event").each(function(element){
			element.show();
		});
	}else{
		$$("#calendar table div.event").each(function(element){
			if(event_category.indexOf(":")!=-1){
				if(element.hasClassName("event_category_"+event_category.replace(/ /g,"_"))){
					element.show();
				}else{
					element.hide();
				}
			}else{
				var showThisEvent = false;
				// this event_category is a "parent" category
				$w(element.className).each(function(thisClass){
					if(thisClass.indexOf(event_category.replace(/ /g,"_"))!=-1){
						showThisEvent = true;
					}
				});
				if(showThisEvent){
					element.show();
				}else{
					element.hide();
				}
			}
		});
	}
}



function Calendar_addCalendarToolsEvents(){
	if($('calendar_tools')){
		$('event_filter').onchange = function(){
			Calendar_filter(this.options[this.options.selectedIndex].value);
			return false;
		}
	}
}
