/*
	Supplemental JavaScript file for Advocate Find a Doctor
*/

/*---------------------------------------------------------------------------------------------------------------*/
// Modular Params
this.thisscript = "";
this.thisScriptSecure = "";
this.action = "";
this.eventLoad = true;
this.x_accordionFile;
this.arrow_accordionFile;
this.caller_imgId;
this.autoDDL;
this.arrSpec = new Array();
this.defaultMiles;
this.fx = new Array();

Array.prototype.indexOf = function(strValue)
{
	// This method attaches to all Array objects for use in IE.  In Gecko browsers it is merely an overload.
	// A 2nd [boolean] parameter can be passed for a case-sensitive comparison. By default this is case-insensitive.
	var indexOfFound = -1;
	var bNumeric = (!isNaN(strValue));
	var bIgnoreCase = true;
	if (arguments.length == 2) bIgnoreCase = arguments[1];
	if (strValue.length == 0) return indexOfFound;
	for (var z=0;z<this.length&&indexOfFound<0;z++)
	{
		if (bNumeric)
		{
			// Handler for numeric
			indexOfFound = (parseFloat(strValue)==this[z] ? z : -1);
		}
		else
		{
			// Handler for strings
			if (bIgnoreCase)
			{
				indexOfFound = ((strValue.toLowerCase()==this[z].toLowerCase()) ? z : -1);
			}
			else
			{
				indexOfFound = (strValue==this[z] ? z : -1);
			}
		}
	}
	return indexOfFound;
};

/*---------------------------------------------------------------------------------------------------------------*/
// Onload
//var phys_onLoadBackup = null;
function setWithinMiles_onLoad() 
{
	//if (phys_onLoadBackup != null) phys_onLoadBackup();	
	var fld = document.getElementById("limit_within");
	var fldZip = document.getElementById("limit_cityzip");
	var rx = /^\d+/;
	var objPD = new Object();
	
	if (fld)
	{
		if (fldZip && rx.test(fldZip.value))
		{
			setValue = fld.value;
			fld.value = "-1";
			setWithinMiles(setValue);
		}
		else if (fld.value>0) 
		{
			this.defaultMiles = fld.value;
			fld.value = "-1";
			setWithinMiles(this.defaultMiles);
		}
		else if (this.defaultMiles>0)
		{
			fld.value = "-1";
			setWithinMiles(this.defaultMiles);
		}
	}
	if (fldZip)
	{
		objPD = document.getElementById("proximity_div");
		if(objPD){
		 	objPD.disabled=isNaN(parseInt(fldZip.value));
			if(isNaN(parseInt(fldZip.value))) 
			{
			 	if (document.all)
					{
						objPD.style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity=30);";	// This is supposed to work in IE
					}
					else objPD.style.opacity=0.3;
			}
			else 
			{
			 	if (document.all)
					{
						objPD.style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity=100);";	// This is supposed to work in IE
					}
					else objPD.style.opacity=1;
			}
		}

	}
}	// setWithinMiles_onLoad

function setAccordionShow_onLoad() 
{
	// For the list page, auto-open certian accordions.  
	// Age, gender & hospital always open, others only open when a filter is applied.
	if (this.action != "list") return false;
	if (arguments.length == 5)
	{
		// contentDiv, accImg, limitFld, ddlName, strAjaxUrl
		showHideAccordion(arguments[0], arguments[1], arguments[2]); 
		autoFill(arguments[3], arguments[4]);
	}
	return;
}	// setAccordionShow_onLoad
/*---------------------------------------------------------------------------------------------------------------*/

/*	BEGIN: Events and Posts	*/
function submitToList (btn)
{
	var rx = /^limit_/;
	var f = btn.form;
	var bSubmit = false;
	for (var z=0; z<f.elements.length; z++)
	{
		if (f.elements[z].type == "text" && rx.test(f.elements[z].id))
		{
			clearDefault(f.elements[z]);
			if (f.elements[z].value.length > 0) bSubmit = true;
		}
	}
	return true;
}	// submitToList

function onOffAppt ()
{
	// Changes style on the detail page for appointment heading
	var td1 = document.getElementById("requestAppt1");
	var td0 = document.getElementById("requestAppt0");
	var styleOff = "metasearchHeading";
	var styleOn = styleOff + "_on";
	if (td0 && td1)
	{
		td0.className = ((td0.className == styleOff) ? styleOn : styleOff);
		td1.className = ((td1.className == styleOff) ? styleOn : styleOff);
	}
}

function onPhysHover (phRef)
{
	/*	Do Highlighting	*/
	this.physIndex = this.arrPhys.indexOf(phRef);
	for (var z=0; z<this.arrPhys.length; z++)
	{
		var td1 = document.getElementById(this.arrPhys[z] + "_tdx");
		var td2 = document.getElementById(this.arrPhys[z] + "_tdy");
		if (td1 && td2)
		{
			if (this.physIndex==-1)
			{
				td1.className = "autosuggest";
				td2.className = "autosuggest";
			}
			else
			{
				td1.className = ((this.physIndex == z) ? "autosuggest_on" : "autosuggest");
				td2.className = ((this.physIndex == z) ? "autosuggest_on" : "autosuggest");
			}
		}
	}	
}	// onPhysHover

function onAnyHover (ev,fldId)
{
	var fld1 = document.getElementById(fldId);
	var rx = /_td1$/;
	if (rx.test(fld1.id)) 
	{
		var fld2 = document.getElementById(fldId.replace("_td1","_td2"));
	}
	else 
	{
		var fld2 = document.getElementById(fldId.replace("_td2","_td1"));
	}
	if (fld1 && fld2)
	{
		cssClass = ((ev.type == "mouseover") ? "accordionList_on" : "accordionList");
		fld1.className = cssClass;
		fld2.className = cssClass;
	}
}	// onAnyHover

function onDivHover (ev, divId)
{
	var fld1 = document.getElementById(divId);
	if (fld1)
	{
		fld1.className = ((ev.type == "mouseover") ? "autosuggest_on" : "autosuggest");
	}
}	// onDivHover 

function onAccordionHover (theEvent,fName)
{
	// Fires for mouseover on accordion field titles.
	var ev = theEvent || theEvent;
	var fld0 = document.getElementById("labelfor_" + fName + "_img");
	var fld1 = document.getElementById("labelfor_" + fName + "_div");
	var fld2 = document.getElementById("labelfor_" + fName + "_td");
	if (fld0 && fld2)
	{
		if (ev.type == "mouseover")
		{
			bkColor = "#6B6AB4";
			fontColor = "#000080";
		}
		else	// mouseout
		{
			bkColor = "#D0D0E8";
			fontColor = "#49467F";
		}	
		fld0.style.backgroundColor=bkColor;
		fld0.style.color = fontColor;
		fld0.style.cursor = "pointer";
		fld2.style.backgroundColor=bkColor;
		fld2.style.color = fontColor;
		fld2.style.cursor = "pointer";
		if (this.action != "list" && fld1)
		{
			fld1.style.backgroundColor=bkColor;
			fld1.style.color = fontColor;
			fld1.style.cursor = "pointer";
		}
	}
}	// onAccordionHover

function setWithinMiles(n)
{
	// Sets limit_within filter on search page and highlights field colors (mimics checkbox behavior).
	// Overload arg will rePost on the list page.
	n = parseInt(n);
	var fld = document.getElementById("limit_within");
	var arrWithin = new Array(0,1,5,10,15,30,31);
	var td;
	var objCZ = new Object();

	if (arguments.length == 1 && (this.action != "list")){
		objCZ = document.getElementById("limit_cityzip");
		if(objCZ && isNaN(parseInt(objCZ.value))){
			for (var z=0; z<arrWithin.length;z++)
			{
				td = document.getElementById("withinMiles"+arrWithin[z]);
				bkground = "url(images/physbkgrd.gif)";
				fontColor = "#404040";
				td.style.backgroundImage=bkground;
				td.style.color=fontColor;
				fld.value=-1;
			}
			return false;
		}
	}
	if (fld)
	{
		n = (fld.value==n ? -1 : n);	// Deselect and reset if "unchecked".
		fld.value = n;
		for (var z=0; z<arrWithin.length;z++)
		{
			td = document.getElementById("withinMiles"+arrWithin[z]);
			bkground = (arrWithin[z]==n ? "url(images/physbkgrd_on.gif)" : "url(images/physbkgrd.gif)");
			fontColor = (arrWithin[z]==n ? "#FFFFFF" : "#404040");
			td.style.backgroundImage=bkground;
			td.style.color=fontColor;
		}
	}
	if (arguments.length == 2 && arguments[1])
	{
		var zFld = document.getElementById("limit_zip");
		if (zFld && zFld.value>0) 
		{
			fld.form.submit();
			return false;
		}
	}
}	// setWithinMiles

function clearDefault (tb)
{
	// Clear starting text from a textbox.
	var tbDef = document.getElementById(tb.id + "_default");
	var remove = true;
	if (arguments.length == 2) remove = arguments[1];
	if (tbDef && tb.value == tbDef.value) 
	{
		if (remove) tb.value = "";
		return true;
	}
	return false;
}

function replaceDefault (tb)
{
	// Replace starting text from a textbox.
	var tbDef = document.getElementById(tb.id + "_default");
	if (tbDef && tb.value.length==0) tb.value = tbDef.value;
}

function submitToDetail (ref)
{
	var theForm = document.getElementById("frmResults");
	if (arguments.length == 2) theForm = document.getElementById(arguments[1]);
	if (theForm) 
	{
		theForm.action = this.thisScriptSecure + "&action=detail&ref=" + ref;
		theForm.submit();
		return false;
	}
}	// submitToDetail

function submitToCompare ()
{
	var theForm = document.getElementById("frmResults");
	var theTable = document.getElementById("my_compare_table");
	if (theForm && theTable && theTable.rows.length>1) 
	{
		theForm.action = this.thisscript + "&action=compare";
		theForm.submit();
	}
	return false;
}	// submitToCompare

function repostCompare (cb)
{
	// Inverted checkboxes.
	var cbHid = document.getElementById(cb.id.replace(/my_/, "limit_"));
	var f = cb.form;
	if (cbHid) f.removeChild(cbHid);
	f.action = this.thisscript + "&action=compare";
	f.submit();
	return true;
}	// submitToCompare

function submitToAppointment (ref, formId, bx)
{
	var exAppt = document.getElementById("expandAppointment");
	if (exAppt) exAppt.value = bx;
	submitToDetail (ref,formId);
}	// submitToAppointment

function addCompare (cb)
{
	// Adds/removes checked physician from compare list.  Checked values are cloned for consistency.
	var rx = /^limit_compare/;
	var f = cb.form;
	var theTable = document.getElementById("my_compare_table");
	if (rx.test(cb.id))
	{
		// Interaction with limit_compare 
		if (document.getElementById("my_compare_"+cb.value))
		{
			var myCb = document.getElementById("my_compare_"+cb.value);
			if (cb.checked)
			{
				myCb.checked = true;
			}
			else
			{
				// Terminate Clone
				var theRow = myCb.parentNode.parentNode;
				if (theTable && theRow) theTable.deleteRow(theRow.rowIndex);
			}
		}
		else
		{
			// Create Clone
			var myCb = document.createElement("input");
			if (theTable.rows.length == 5)
			{
				// Only 5 comparisons are allowed. Pop the last row and bubble them all upward.
				var myCbOld = theTable.rows[0].cells[1].childNodes[0];
				if (document.getElementById("limit_compare_"+myCbOld.value))
				{
					document.getElementById("limit_compare_"+myCbOld.value).checked = false;
				}				
				theTable.deleteRow(0);				
			}
			with (myCb)
			{
				type = "checkbox";
				id = "my_compare_"+cb.value;
				name = id;
				value = cb.value;
			}
			var theRow = theTable.insertRow(theTable.rows.length);
			var thePhys = document.getElementById("physName_"+cb.value).innerHTML;
			var td1 = theRow.insertCell(0);
			var td2 = theRow.insertCell(1);
			with (td1)
			{
				id = "my_compare_" + cb.value + "_td1";
				style.paddingLeft= "3px";
				style.fontSize="9pt";
				style.textAlign="left";
				style.verticalAlign="middle";
				style.whiteSpace="nowrap";
				style.width="90%";
				style.border="1px solid #ADAEDC";
				innerHTML="<label for='"+ myCb.id +"' class='autosuggest'>"+ thePhys +"</label>";
			}
			with (td2)
			{
				id = "my_compare_" + cb.value + "_td2";
				style.textAlign="center";
				style.verticalAlign="middle";
				style.width="10%";
				style.border="1px solid #ADAEDC";
				appendChild(myCb);
			}
			myCb.checked = true;
			myCb.onclick=function() {addCompare(myCb);};
		}
	}
	else
	{
		// Interaction with my_compare 
		var limitCb = document.getElementById("limit_compare_"+cb.value);
		if (limitCb)
		{
			limitCb.checked = cb.checked;
		}
		// Self-terminate
		var theRow = cb.parentNode.parentNode;
		if (theTable && theRow) theTable.deleteRow(theRow.rowIndex);
	}	

	// Reset style on rows
	for (var x=0; x<theTable.rows.length; x++)
	{
		theTable.rows[x].cells[0].style.backgroundColor = (x%2==0 ? "#D0D0E8" : "");
		theTable.rows[x].cells[1].style.backgroundColor = (x%2==0 ? "#D0D0E8" : "");
	}
	return true;
}

function rePostList (strAddFilter)
{
	var theForm = document.getElementById("frmResults");
	var af = strAddFilter.split("=");		// defines value pair filter
	if (af.length == 2)
	{
		document.getElementById(af[0]).value = af[1];
		if (theForm) 
		{
			theForm.action = this.thisscript + "&action=list";
			theForm.submit();
		}
	}
	else {alert("error in this function(rePostList) by caller " + strAddFilter)}
}	// rePostList

function showHideAccordion (containerId, imgId, lblText)
{
	var baseLblText = "";
	var theLabel = document.getElementById(lblText);
	var lblFor = document.getElementById("labelfor_" + containerId);
	if (this.action == "step3" || this.action == "review") return;
	if (arguments.length == 4) baseLblText = arguments[3];
	if (containerId.length > 0 && imgId.length > 0)
	{
		var img = document.getElementById(imgId);
		var imgSrc = img.src;
		if (imgSrc.search("/\//g"))
		{
			var arrSrc = img.src.split("/");
			imgSrc = img.src.split("/").pop();
		}
		this.caller_imgId = imgId;
		var theDiv = document.getElementById(containerId);
		var clearLink = document.getElementById(lblText+"_clear");
		if (imgSrc == this.x_accordionFile || (theDiv && theDiv.style.visibility == "visible" && imgSrc == this.arrow_accordionFile))
		{
			// Hide
			img.src = "images/" + this.arrow_accordionFile;
			if (clearLink) clearLink.className = "clearLink_off";
			showHideAny(containerId,false);
			
			// Show limit_within for zip code
			if (lblText == "limit_zip") showHideAny("within_div",false);
			if (lblText == "limit_cityzip") showHideAny("proximity_div",false);
		}
		else if (imgSrc == this.arrow_accordionFile)
		{
			// Show
			img.src = "images/" + this.x_accordionFile;
			if (clearLink) clearLink.className = "clearLink";
			showHideAny(containerId,true);
			
			// Show limit_within for zip code
			if (lblText == "limit_zip") showHideAny("within_div",true);
			if (lblText == "limit_cityzip") showHideAny("proximity_div",true);
		}
	}
	if (theLabel && theLabel.value.length &&  !clearDefault(theLabel,false) && this.action != "list")
	{
		// Reset this filter's label to the selected text.
		// omit 0 values
		var bIsNumeric = !isNaN(parseInt(theLabel.value));
		if (!bIsNumeric || parseInt(theLabel.value)>0)
		{
			if (theLabel.id == "limit_lstSpecialty")
			{
				lblFor.innerHTML = theLabel.value.replace(/,\s?/g,",<br>");
			}
			else
			{
				lblFor.innerHTML = theLabel.value.replace(/,\s?/g,", ");
			}
			if (this.action != "teaser") lblFor.style.fontSize="20px";
			var rx = /^\d+/;
			if (theLabel.id == "limit_cityzip" && rx.test(theLabel.value))
			{
				zipWithin = document.getElementById("limit_within");
				if (zipWithin && zipWithin.value>-1) lblFor.innerHTML += " within " + zipWithin.value + " miles";
			}
			if (document.getElementById("labelfor_" + containerId+"1"))
			{
				document.getElementById("labelfor_" + containerId+"1").className="metasearchHeading_on";
			}
		}
	}
	else if (baseLblText.length)
	{
		// Reset this filter's label to the dummy text.
		lblFor.innerHTML = baseLblText;
		if (this.action != "list")
		{
			if (document.getElementById("labelfor_" + containerId+"1"))
			{
				document.getElementById("labelfor_" + containerId+"1").className="metasearchHeading";
			}
		}
	}
	if (this.action == "" || this.action == "search" || this.action == "teaser")
	{
		if (document.getElementById(containerId).style.visibility == "visible" || (theLabel.value.length>0 && !clearDefault(theLabel,false)) )
		{
			lblFor.className="metasearchHeading_on";
			if (document.getElementById("labelfor_" + containerId+"1"))
			{
				document.getElementById("labelfor_" + containerId+"1").className="metasearchHeading_on";
			}
		}
		else
		{
			lblFor.className="metasearchHeading";
			if (document.getElementById("labelfor_" + containerId+"1"))
			{
				document.getElementById("labelfor_" + containerId+"1").className="metasearchHeading";
			}
		}
	}
}	// showHideAccordion

function showHideAny (eid, bx)
{
	// Just like the name, it unhides and hides nodes (usually divs).
	var ce = document.getElementById(eid);
	if (ce)
	{
		ce.style.visibility = (bx ? "visible" : "hidden");
		ce.style.display = (bx ? "block" : "none");
		if (this.action == "detail" && ce.className == "accordion") resizeAccordion (ce.id, bx);
	}
}

function resizeAccordion (acId, bx)
{
	// Resets the height of a div accordion (it was clear this was only necessary in IE).
	var ac = document.getElementById(acId);
	if (ac) ac.style.height = (bx ? "100%" : "0px");
}	// resizeAccordion

function clearSearchFilter (fldId)
{
	var arrFldIds = fldId.split(",");	// can also be a list;
	for (var z=0; z<arrFldIds.length;z++)
	{
		var limitFld = document.getElementById(arrFldIds[z]);
		if (limitFld && limitFld.value.length > 0)
		{
			limitFld.value = ((isNaN(parseInt(limitFld.value))) ? "" : -1);
		}
	}
	limitFld.form.submit();
}

function postCBFilter (fld)
{	
	var fldId = fld.id.replace(/_[\da-zA-Z]+$/, "");
	var limitFld = document.getElementById(fldId);
	if (limitFld)
	{
		disableAllCbPost(fld.form);
		limitFld.value = (fld.checked ? fld.value : "");
		fld.form.submit();	
	}
}	// postCBFilter

function disableAllCbPost(f)
{
	// Helper function to disable checkboxes while the form is posting.
	for (var x=0; x<f.elements.length; x++)
	{
		var cb = f.elements[x];
		if (cb.type == "checkbox") cb.disabled = true;
	}
	return;
}
/*	END: Events and Posts	*/

/*---------------------------------------------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------------------------------------------*/

/*	BEGIN: Ajax Handlers	*/
function getAjax (strUrl)
{
	var fxCount = this.fx.length;
	this.fx[fxCount] = new smAjaxRequest();
	this.fx[fxCount].onreadystatechange = function(){doReload(fxCount);};
	this.fx[fxCount].open("GET", strUrl, this.eventLoad);
	this.fx[fxCount].send(null);
	return true;
}	// Handler to get data for any element

function smAjaxRequest()
{
	var activexmodes=["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"];
	if (window.ActiveXObject)	// IE
	{ 
		for (var i=0; i<activexmodes.length; i++)
		{
			try
			{
				return new ActiveXObject(activexmodes[i]);
			}
			catch(ex){}
		}
	}
	else if (window.XMLHttpRequest) // FF
	{
		FX = new XMLHttpRequest();
		FX._timeoutHang = setTimeout(function(){FX.abort()}, 3000);
		return FX;
	}
}	// smAjaxRequest

function doReload (fxCount)
{
	if (this.fx[fxCount].readyState == 4)
	{
		var xmlData = this.fx[fxCount].responseXML;
		try
		{
			var xmlRootNode = xmlData.documentElement.childNodes;
			var fldId = "";
			for (w=0;w<xmlRootNode.length && fldId.length==0;w++)
			{
				if (xmlRootNode[w].nodeType ==1)
				{
					/* Derives the filter name (set by the CF function) from the xml object 
						and then send all this off to the appropriate reload function. */
					fldId = xmlRootNode[w].nodeName;
					xmlContents = xmlRootNode[w].childNodes;
				}
			}
			switch(fldId)
			{
				case "limit_cityzip": {setCityZip(xmlContents); break;}
				case "limit_insurance": {setInsurances(xmlContents); break;}
				case "limit_lastname": {setPhysicians(xmlContents); break;}
				case "limit_specialty": {setSpecialtyBoxes(xmlContents); break;}
				default: {setDDL(xmlContents,fldId);}
			}
		}
		catch (ex) 
		{
			// Its possible that the query returns no results.  In this case just do nothing.
		}	
	}
}	// doReload
/*	END: Ajax Handlers	*/

/*---------------------------------------------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------------------------------------------*/

/*	BEGIN: Drop down lists	*/
function autoFill (fldId, strUrl)
{
	var fld = document.getElementById(fldId);
	if (fld.rows.length==1)
	{
		this.autoDDL = fld;
		getAjax(strUrl);
    }
	else 
	{
		// Filter is already loaded, get out.
	}
	return;	
}	// autoFill

function setDDL (stt,fldId)
{
	// Called after the xml object is populated by Ajax.  Fills the accordions with data.
	var theTable = document.getElementById(fldId+"_table");
	var fldSelVal = "";
	var fld = document.getElementById(fldId);
	if (fld) fldSelVal = fld.value;

	if (theTable.rows.length>0)
	{
		// Purge Table
		while(theTable.rows.length) theTable.deleteRow(0);
	}
//	try{alert(fldId);} catch (ex) {alert(ex.message);}
	if (stt.length==0)
	{
		// Insert 0 results
		var row = theTable.insertRow(0);	
		td1 = row.insertCell(0);
		td1.className="accordionList";
		td1.innerHTML = "0 found...";
	}
	else
	{
		for(var y=0;y<stt.length;y++)
		{
			// Populate rows with checkboxes & labels;
			var sf = decodeURI(stt[y].firstChild.nodeValue);
			var sfRef = decodeURI(stt[y].getAttribute("ref"));
			var sfTot = decodeURI(stt[y].getAttribute("total"));
			var bChecked = fldSelVal.toLowerCase()==sf.toLowerCase();
			var chk = (bChecked ? " checked" : "");
			var row = theTable.insertRow(bChecked?0:y);	// Insert row
			
			td1 = row.insertCell(0);
			td2 = row.insertCell(1);
			xId = (y*23);
			with (td1)
			{				
				className="accordionList";
				title = sf;
				id = fldId + "_" +sfRef+ "_td1";
				style.padding="0px";
				style.fontSize="7px";
				style.width="220px";
				innerHTML = "<label onMouseOut='onAnyHover(event, this.parentNode.id);' onMouseOver='onAnyHover(event, this.parentNode.id);' for='" + fldId + "_" + xId + "' class='autosuggest'>" + (bChecked ? "<b>" : "") + (sf.length >35 ? sf.substr(0,35) + "..." : sf) + " (" + sfTot + ")" + (bChecked ? "</b>" : "") +"</label>";
			}
			with (td2)
			{
				className="accordionList";
				id = fldId + "_" +sfRef+ "_td2";
				style.lineHeight="5pt";
				style.wordSpacing="0pt";
				style.textAlign="center";
				style.width="30px";
				innerHTML = "<input onMouseOut='onAnyHover(event, this.parentNode.id);' onMouseOver='onAnyHover(event, this.parentNode.id);' type='checkbox' id='" + fldId + "_" + xId + "' value='"+ sf + "' onclick='postCBFilter(this);'" + chk + ">";
			}
		}		// inner for
	}

	// Lastly, resize the parent Div if necessary.
	if (theTable.parentNode) theTable.parentNode.style.height = ((theTable.rows.length<5) ? "100%" : "127px");
}	// setDDL (List Page Filters)

function autoGetCB (fldId, strUrl)
{
	// This function does basically the same thing as autoFill but for the Specialty checkboxes
	var fld = document.getElementById(fldId);
	if (fld)
	{
		this.autoDDL = fld;
		getAjax(strUrl);
    }
}	// autoGetCB

/*	END: Drop down lists	*/

/*---------------------------------------------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------------------------------------------*/

/*	BEGIN: Auto-suggesting text boxes	*/
function suggestSmartBox(ev, fld, strUrl)
{
	var input = "";
	var objPD = new Object();
	var objPHO = new Object();
	var kn = null;
	if(document.all)
	{
		kn = ev.keyCode;
		input = detectKeyUp(ev.keyCode);	// IE Support
	}
	else if (ev) 
	{
		kn = ev.which;
		input = detectKeyUp(ev.which);	// Every other browser
	}
	
	if (kn != 38 && kn != 40) 
	{
		var theSuggestionDiv;
		enableSearchButton();
		if (/_insurance$/.test(fld.id))
		{
			theSuggestionDiv = document.getElementById("insurance_suggestions");
			if (theSuggestionDiv) theSuggestionDiv.innerHTML = "";	// Clear Insurance repeater
		}
		else if (/_cityzip$/.test(fld.id))
		{
			theSuggestionDiv = document.getElementById("cityzip_suggestions");
			if (theSuggestionDiv) theSuggestionDiv.innerHTML = "";	// Clear cityZip repeater
			objPD = document.getElementById("proximity_div");
			if(objPD){
			 	objPD.disabled=isNaN(parseInt(fld.value));
				if(isNaN(parseInt(fld.value))) 
				{
					if (document.all)
					{
						objPD.style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity=30);";	// This is supposed to work in IE
					}
					else objPD.style.opacity=0.3;
					setWithinMiles(-1);
				}
				else 
				{
				 	if (document.all)
					{
						objPD.style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity=100);";	// This is supposed to work in IE
					}
					else objPD.style.opacity=1;
					var fldLW = document.getElementById("limit_within");
					if(fldLW && (isNaN(fldLW.value) || fldLW.value<0))
					{
						setWithinMiles(this.defaultMiles);
					}
				}
			}
		}
		
		// Clear Phys repeater
		if (/_lastname$/.test(fld.id))
		{
			var theTable = document.getElementById("physName_div_table");
			while(theTable.rows.length) theTable.deleteRow(0);
		}
		
		// Clear default "help text" or populate suggestions.
		if (fld.value.length == 0)
		{
			clearDefault(fld);
			if (theSuggestionDiv) theSuggestionDiv.innerHTML = "";
		}
		else
		{
			objPHO = document.getElementById("limit_pho");
			if (objPHO && objPHO.checked)
			{
			 	strUrl += "&pho=true";
			} else {
				strUrl += "&pho=false";
			}
			strUrl += "&subFilter=" + ( (fld.value.length>0) ? fld.value : input );
			getAjax(strUrl);
		}
	}
	return true;
}	// suggestSmartBox

function enableSearchButton ()
{
	var btnBeginSearch = document.getElementById("btnSubmit");
	var bDisable = true;
	if (btnBeginSearch)
	{
		var f = btnBeginSearch.form;
		for (var z=0; z<f.elements.length; z++)
		{
			if (f.elements[z].type == "text" && f.elements[z].value.length>0)
			{
				bDisable = false;
			}
			else if (f.elements[z].type == "checkbox" && f.elements[z].checked)
			{
				bDisable = false;
			}
		}
		btnBeginSearch.disabled = bDisable;
	}
}	// enableSearchButton

function setInsurances(stt)
{
	if (this.autoDDL)
	{
		// Handles the Drop-Down list called by the list page...no point to rewrite this.
		setDDL(stt,"limit_insurance");
		return;
	}
	
	if (this.arrIns) 
	{
		this.arrIns = new Array();
		this.InsIndex = -1;
	}

	// Completes list beneath the text box matching key entry (if any)
	var theDiv = document.getElementById("insurance_suggestions");
	var theField = document.getElementById("limit_insurance");
	if (this.action == "step3" || this.action == "review") theField = document.getElementById("eformField_21");
	if (theDiv)
	{
		theDiv.innerHTML = "";
		for(var y=0;y<stt.length;y++)
		{
			var ins = decodeURI(stt[y].firstChild.nodeValue);
			var insRef = y+1*106;
			var insBold = ins;
			if(theField)
			{
				var rx = new RegExp("("+theField.value+")","i");
				insBold = insBold.replace(rx,'<span class="autosuggestBold">$1</span>');
			}
			theDiv.innerHTML += "<div id='" + insRef + "_div' class='autosuggest' style='width:100%;' onMouseOut='onDivHover(event, this.id);' onMouseOver='onDivHover(event, this.id);' onClick='setInsurancesTb(" + insRef + ");'>"+ insBold + "<input type='Hidden' id='" + insRef + "_tb' value='" + ins + "'></div>";
			theDiv.innerHTML += "<br>";
			if (this.arrIns) this.arrIns.push(insRef);
		}
		showHideAny(theDiv.id, (theDiv.innerHTML.length>0));
	}
}	// setInsurances

function setSpecialty(fld)
{
	// Appends the value of the checkbox to the hidden field for use of the label.
	// Optional 2nd argument will repost the list page.
	var spec = document.getElementById("limit_lstSpecialty");
	var f = fld.form;
	enableSearchButton();
	if (spec)
	{
		var arrSpec = spec.value.split(",");
		spec.value = "";
		if (fld.checked)
		{
			// Set or append checkbox value to array.
			if (arrSpec.indexOf(fld.value)==-1) arrSpec.push(fld.value);
		}
		else
		{
			// Remove checkbox and delim value(s) from list.
			if (arrSpec.indexOf(fld.value)>-1)	arrSpec.splice(arrSpec.indexOf(fld.value),1);
		}
		arrSpec.sort();
		for (var x=0; x<arrSpec.length; x++)
		{
			spec.value += arrSpec[x] + (x!=arrSpec.length-1 ? "," : "");
		} 
		spec.value = spec.value.replace(/^(,| )+/, "");
	}

	if (arguments.length == 2 && arguments[1]) 
	{
		var cb = fld;
		if (!cb.checked) cb.value = "";
		disableAllCbPost(f);
		f.submit();
		return;
	}
}

function setSpecialtyBoxes (stt)
{
	var specTable = document.getElementById("spec_div_table");
	var arrSpec = this.arrSpec;
	if (specTable.rows.length>0)
	{
		// Purge Table
		while(specTable.rows.length) specTable.deleteRow(0);
	}
	
	if (stt.length==0)
	{
		// Insert 0 results
		var row = specTable.insertRow(0);	
		td1 = row.insertCell(0);
		td1.className="accordionList";
		td1.innerHTML = "0 found...";
	}
	else
	{
		var nInsCheckedAt = 0;
		for(var y=0;y<stt.length;y++)
		{
			// Populate rows with checkboxes & labels;
			var sp = decodeURI(stt[y].firstChild.nodeValue);
			var spRef = decodeURI(stt[y].getAttribute("ref"));
			var spTot = decodeURI(stt[y].getAttribute("total"));
			bChecked = arrSpec.length>0 && arrSpec.indexOf(spRef)>-1;
			if(bChecked){
				var row = specTable.insertRow(nInsCheckedAt);	// Insert row
				nInsCheckedAt++;
			} else {
				var row = specTable.insertRow(y);	// Insert row
			}
			chk = (bChecked ? " checked" : "");
			row.id = id="limit_specialty_" +spRef+ "_tr" + y;
			td1 = row.insertCell(0);
			td2 = row.insertCell(1);
			with (td1)
			{
				id = "limit_specialty_" + spRef + "_td1";
				className="accordionList";
				title=sp;
				style.padding="0px";
				style.fontSize="7px";
				style.width="220px";
				innerHTML = "<label onMouseOut='onAnyHover(event, this.parentNode.id);' onMouseOver='onAnyHover(event, this.parentNode.id);' for='limit_specialty_" + spRef + "' class='autosuggest'>" + (bChecked ? "<b>" : "") + (sp.length >35 ? sp.substr(0,35) + "..." : sp) + " (" + spTot + ")" + (bChecked ? "</b>" : "") + "</label>";
			}
			with (td2)
			{
				id = "limit_specialty_" + spRef + "_td2";
				className="accordionList";
				style.lineHeight="5pt";
				style.wordSpacing="0pt";
				style.textAlign="center";
				style.width="30px";
				innerHTML = "<input onMouseOut='onAnyHover(event, this.parentNode.id);' onMouseOver='onAnyHover(event, this.parentNode.id);' type='checkbox' name='limit_specialty_" + spRef + "' id='limit_specialty_" + spRef + "' value='"+ sp + "' onclick='setSpecialty(this,true);'" + chk + ">";
			}
		}
	}
	// adjust div height if necessary.
	if (specTable.parentNode)
	{
		// Specialty allows for 10 rows where other checklists allow only 5.
		specTable.parentNode.style.height = ((specTable.rows.length<10) ? "100%" : "127px");
		
	}
}	// setSpecialtyBoxes

function setCityZip (stt)
{
	// Completes list beneath the text box matching key entry (if any)
	var theDiv = document.getElementById("cityzip_suggestions");
	var theField = document.getElementById("limit_cityzip");
	
	if (this.arrCityZip) 
	{
		this.arrCityZip = new Array();
		this.CityZipIndex = -1;
	}
	
	if (theDiv)
	{
		theDiv.innerHTML = "";
		for(var y=0;y<stt.length;y++)
		{
			var cityZip = decodeURI(stt[y].firstChild.nodeValue);
			var cityZipBold = cityZip;
			if(theField)
			{
				var rx = new RegExp("("+theField.value+")","i");
				cityZipBold = cityZipBold.replace(rx,'<span class="autosuggestBold">$1</span>');
			}
			with (theDiv)
			{
				innerHTML += "<div class='autosuggest' id='" + y + "_div' style='width:100%;' onMouseOut='onDivHover(event, this.id);' onMouseOver='onDivHover(event, this.id);' onClick='setCityZipTb(" + y + ");'>"+ cityZipBold + "<input type='Hidden' id='" + y + "_tb' value='" + cityZip + "'></div><br>";
			}
			if (this.arrCityZip) this.arrCityZip.push(y);
		}
		showHideAny(theDiv.id, (theDiv.innerHTML.length>0));
	}
}	// setCityZip

function setPhysicians(stt)
{
	// Completes list beneath the text box matching key entry (if any)
	var theDiv = document.getElementById("physName_suggestions");
	var theTable = document.getElementById("physName_div_table");
	var theField = document.getElementById("limit_lastname");
	if (theDiv && theTable)
	{
		if (this.arrPhys) 
		{
			this.arrPhys = new Array();
			this.physIndex = -1;
		}
		document.getElementById('limit_physicianRef').value = "";
		while(theTable.rows.length) theTable.deleteRow(0);
		for(var y=0;y<stt.length;y++)
		{
			var phys = decodeURI(stt[y].firstChild.nodeValue);
			var spec = decodeURI(stt[y].getAttribute("specialty"));
			var phRef = decodeURI(stt[y].getAttribute("ref"));
			var physBold = phys;
			var physTitle = phys;
			if(theField && phRef>0)
			{
				var rx = new RegExp("("+theField.value+")","i");
				physBold = physBold.replace(rx,'<span class="autosuggestBold">$1</span>');
			}
			var row = theTable.insertRow(y);	// Insert row
			var td1 = row.insertCell(0);
			var td2 = row.insertCell(1);			
			if (this.arrPhys) this.arrPhys.push(phRef);
			with (td1)
			{				
				title=physTitle;
				className="autosuggest";
				style.width="83%";
				id = phRef + "_tdx";
				innerHTML = "<div style='padding-left:4px;' onClick='setPhysicianTb("+ phRef +");' onMouseOver='onPhysHover("+phRef+");'>"+ physBold +(spec.length>0 ? " - "+spec : "&nbsp;") + "</div>";
			}
			with (td2)
			{
				title=physTitle;
				className="autosuggest";
				style.textAlign="center";
				style.width="17%";
				id = phRef + "_tdy";
				if (phRef > 0)
				{
					innerHTML = "<div style='padding-left:4px;' onClick='setPhysicianTb(" + phRef + ");' onMouseOver='onPhysHover("+phRef+");'>View Profile</div>";
					innerHTML += "<input type='Hidden' id='" + phRef + "_tb' value='" + phys + "'>";
				}
				else innerHTML = "&nbsp;";
			}
		}
		showHideAny(theDiv.id, (theTable.rows.length>0));
	}
}	// setPhysicians


function thumbThru (ev, tb)
{
	if (document.all)
	{
		var kn = ev.keyCode;
	}
	else
	{
		var kn =  ev.which;
	}
	if (kn != 38 && kn != 40) return true;
	
	// Determine Local Settings.  Lots of shared stuff.
	var lastRow = -1;
	if (tb.id == "limit_insurance" || tb.id == "eformField_21" || tb.id == "limit_cityzip")	// Settings for not last name
	{
		if (tb.id == "limit_cityzip")
		{
			var theTable = document.getElementById("cityzip_suggestions");
			var arrStuff = this.arrCityZip;
			var idx = this.CityZipIndex;
		}
		else 
		{
			var theTable = document.getElementById("insurance_suggestions");
			var arrStuff = this.arrIns;
			var idx = this.InsIndex;
		}	
		for (var x=0; x<theTable.childNodes.length;x++)
		{
			if (/^\d+_div$/.test(theTable.childNodes[x].id)) lastRow++;			
		}
	}
	else	// Settings for last name
	{
		var theTable = document.getElementById("physName_div_table");
		var arrStuff = this.arrPhys;
		var idx = this.physIndex;
		lastRow = theTable.rows.length-1;
	}
	if (theTable == null || theTable.childNodes.length==0 || arrStuff == null || arrStuff.length == 0) return;
	
	if (kn==40)	// up (descend)
	{
		if (idx<lastRow) idx++;
		else idx = lastRow;	// Set to last row.
	}
	if (kn==38)	if (idx>-1) idx--;	// down (ascend)

	if (tb.id == "limit_lastname")
	{		
		/*	Do Highlighting by changing css class	*/
		for (var z=0; z<arrStuff.length; z++)
		{
			var td1 = document.getElementById(arrStuff[z] + "_tdx");
			var td2 = document.getElementById(arrStuff[z] + "_tdy");
			if (td1 && td2)
			{
				if (idx==-1)
				{
					td1.className = "autosuggest";
					td2.className = "autosuggest";
				}
				else
				{
					td1.className = ((idx == z) ? "autosuggest_on" : "autosuggest");
					td2.className = ((idx == z) ? "autosuggest_on" : "autosuggest");
				}
			}
		}
		this.arrPhys = arrStuff;
		this.physIndex = idx;
	}
	else
	{
		/*	Do Highlighting	in-line	*/
		for (var x=0; x<theTable.childNodes.length;x++)
		{
			if (/^\d+_div$/.test(theTable.childNodes[x].id))
			{
				var fld1 = theTable.childNodes[x];
				fld1.className = ((fld1.id == arrStuff[idx] + "_div") ? "autosuggest_on" : "autosuggest");
			}
		}
		
		if (tb.id == "limit_cityzip")
		{
			this.arrCityZip = arrStuff;
			this.CityZipIndex = idx;
		}
		else
		{
			this.arrIns = arrStuff;
			this.InsIndex = idx;
		}		
	}
	
	tb.select();
	return false;
}	// thumbThru

function noenter (ev,tb) 
{
	if (document.all)
	{
		var kn =  window.event.keyCode;
	}
	else
	{
		var kn = ev.which;
	}
	if (kn == 13)
	{
		if (this.physIndex>-1)
		{
			setPhysicianTb(this.arrPhys[this.physIndex]);
			return false;
		}
		if (this.InsIndex>-1)
		{
			setInsurancesTb(this.arrIns[this.InsIndex]);
			return false;
		}
		if (this.CityZipIndex>-1)
		{
			setCityZipTb(this.arrCityZip[this.CityZipIndex]);
			return false;
		}
	}
	else return (kn != 13);
}	// noenter

function setPhysicianTb (tRef)
{
	// No longer selects the last name, now jumps to the detail page.
	var srcTb = document.getElementById(tRef+"_tb");
	var parentId = "physName_div";
	var urlPhys = this.thisscript;
	document.getElementById("limit_lastname").blur();
	if (tRef > 0)
	{
		document.getElementById("limit_lastname").value = srcTb.value;
		document.getElementById("limit_physicianRef").value = tRef;
		srcTb.parentNode.innerHTML = "";
		showHideAccordion (parentId, this.caller_imgId, "limit_lastname", srcTb.value);
		urlPhys += "&action=detail&ref=" + tRef;
	}
	else 
	{
		urlPhys += "&action=list&limit_lastname=" + document.getElementById("limit_lastname").value;
	}
	showHideAny("physName_suggestions",false);
	window.location = urlPhys;
}	// setPhysicianTb

function setCityZipTb (tRef)
{
	var srcTb = document.getElementById(tRef+"_tb");
	var parentId = "cityzip_div";
	document.getElementById("limit_cityzip").value = srcTb.value;
	srcTb.parentNode.innerHTML = "";
	// Attempt to collapse the accordion and set the section heading.
	//showHideAccordion (parentId, this.caller_imgId, "limit_cityzip", srcTb.value);
	
	// Necessary unless showHideAccordion is reactivated
	showHideAny("cityzip_suggestions",false);
	document.getElementById("limit_cityzip").blur();
}	// setCityZipTb

function setInsurancesTb (tRef)
{
	var srcTb = document.getElementById(tRef+"_tb");
	var theDiv = document.getElementById("insurance_suggestions");
	var parentId = "insurance_div";
	var strTbId = ((this.action == "step3" || this.action == "review") ? "eformField_21" : "limit_insurance");
	document.getElementById(strTbId).value = srcTb.value;
	theDiv.innerHTML = null;
	// Attempt to collapse the accordion and set the section heading.
	if (this.action == "step3" || this.action == "review") 
	{
		showHideAny("insurance_suggestions",false);
		document.getElementById(strTbId).blur();
	}
	else showHideAccordion (parentId, this.caller_imgId, strTbId, srcTb.value);
}	// setInsurancesTb

function detectKeyUp(kn)
{
	// Simple onKeyPress event.
	// arg "kn" is the key code number
	var ch = "";
	if (!(kn < 32 || (kn >= 33 && kn <= 46) || (kn >= 112 && kn <= 123)))
	{
		ch = String.fromCharCode(kn);
	}
	return ch;
}	// detectKeyUp

/*	END: Auto-suggesting text boxes	*/

/*---------------------------------------------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------------------------------------------*/

