var su_id = 0; // used for autoselect on autocomplete, off by default

function HideDIV(d) { document.getElementById(d).style.display = "none"; }
function DisplayDIV(d) { document.getElementById(d).style.display = "block"; }

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function display_help() {
	window.open('help/help-resources.html');
}

function display_feedback() {
	window.open('feedback.php', "WindowR", "left=0,top=0,height=600,width=800,scrollbars=yes,resizable=yes");
	//document.forms[0].action='feedback.php';
	//document.forms[0].submit();
}


/*
function display_resources() {
	window.open('resources_window.php', "WindowR", "width=800,height=600,scrollbars=yes,resizable=yes");
}
*/

function resourcer_external(url) {
	dhhswin = window.open(url, "Window1", "width=800,height=600,scrollbars=yes,resizable=yes"); 
	if (window.focus) {dhhswin.focus()}
}

function resource_window(url,anchor) { 
	if(anchor != '') anchor = "?anchor="+anchor;
	dhhswin = window.open('resources/'+url+anchor, "Window1", "width=800,height=600,scrollbars=yes,resizable=yes"); 
	if (window.focus) {dhhswin.focus()}
}

function resourcer_window(url,anchor) {
	resource_window(url+"/index.php",res_anchor(url,anchor));
}

function resourcer_window_out(url,anchor) {
	//if(anchor != '') anchor = "#"+anchor;
	dhhswin = window.open(url+anchor, "Window1", "width=800,height=600,scrollbars=yes,resizable=yes"); 
	if (window.focus) {dhhswin.focus()}
}

function resource_inline(url,anchor) {
	if(anchor != '') anchor = "?anchor="+anchor;
	document.getElementById('resources').innerHTML = '<center><a href="#" onClick="document.resourcesfrm.submit()">Return to Resource List</a></center><br><iframe src="resources/'+url+anchor+'" width=765 height=500></iframe>';;
}

function resourcer_inline(url,anchor) {
	resource_inline(url,anchor);
}

function resourcer(title) { 
	resource_window(title+"/index.php",''); 
}

function resourcer2(title) { 
	resource_inline(title+"/index.php",''); 
}

function resourcerp(title) { 
	resource_window(title+"/index.php?print=1",''); 
}

function resourcerpdf(title,pdffile) { 
	//resource_window(title+'/index.php',pdffile+'.pdf');
	resource_window(title+'/'+pdffile+'.pdf','');
}

function resourcer2pdf(title,pdffile) { 
	//resource_inline(title+'/index.php',pdffile+'.pdf');
	resource_inline(title+'/'+pdffile+'.pdf','');
}

function resourcerfile(title,fn) { 
	resource_window(title+'/'+fn,'');
}

function resourcer2file(title,fn) { 
	resource_inline(title+'/'+fn,'');
}


function res_anchor(title,anchor) {
if (anchor) {
  anchor=leftTrim(anchor);
	s = anchor.indexOf('#');
	if(s>=0) {
		page = anchor.substr(0,s)+"POUND"+anchor.substr(s+1);
	}
	else page = anchor+"POUND";
	return page;
  }
else return "";
}

function leftTrim (InString)  {
 OutString=InString;
 for (Count=0; Count < InString.length; Count++)  {
  TempChar=InString.substring (Count, Count+1);
  if (TempChar!=" ") {
   OutString=InString.substring (Count, InString.length)
   break;
  }
 }
 return (OutString);
}

function resourcer_anchor(title,anchor) {
	resource_window(title+"/index.php",res_anchor(title,anchor));
}

function resourcer2_anchor(title,anchor) {
	resource_inline(title+"/index.php",res_anchor(title,anchor));
}

//var DHHSdoc = "DHHS/DHHS2005OctAdult_guide.htm";

function DHHS(anchor) { 
	resource_window("DHHS-HTML/index.php","POUND"+anchor); 
}

function DHHSR(anchor) { 
	resource_inline("DHHS-HTML/index.php","POUND"+anchor);
}

function DHHS2004(anchor) { 
	DHHS(anchor);
}

function DHHS2005A(anchor) { 
	DHHS(anchor);
}

function DHHS2005A2(anchor) { 
	DHHS(anchor);
}

function oitx(anchor) { 
	resource_window("oitx/index.php","POUND"+anchor); 
}

function oitx2(anchor) { 
	resource_inline('oitx/index.php',"POUND"+anchor);
}

function OIProphylaxis(anchor) { 
	resource_window("OIProphylaxis/index.php","POUND"+anchor); 
}

function mono(drug) { 
	monowin = window.open('inc/mono.php?a='+drug, "Window1", "width=800,height=600,scrollbars=yes"); 
	if (window.focus) {monowin.focus()}
}

function mono2(drug) { 
	document.getElementById('drugs').innerHTML = '<center><a href="#" onClick="document.resourcesfrm.submit()">Return to Resource List</a></center><br><iframe src="/mono/'+drug+'.html" width=765 height=500></iframe>';
}

function verify_order(theform) {
  err=0;
  if(!have_form) {
//	a = document.getElementById('theLayerBubble6');
//	a.style.top =toptag + 75;
	hideBubble(7);
	hideBubble(8);
	showBubble(6);
	err=1;
	}
  else if(!have_dose) { 
//	a = document.getElementById('theLayerBubble7');
//	a.style.top =toptag - 30;
	showBubble(7);
	hideBubble(6);
	hideBubble(8);
	err=1;
	}
  else if(!have_freq) {
//	a = document.getElementById('theLayerBubble8');
//	a.style.top =toptag + 75;
	hideBubble(6);
	hideBubble(7);
	showBubble(8);
	err=1;
	}
if (err==0)return 1;
else return 0;
}

function getAbsLeft(obj) {
  var ol = obj.offsetLeft;
  while((obj = obj.parentNode) && obj != document) ol += obj.offsetLeft;
  return ol;
}

function getAbsTop(obj) {
  var ot = obj.offsetTop;
  while((obj = obj.parentNode) && obj != document) ot += obj.offsetTop;
  return ot;
}

function addEvent(obj,event_name,func_name){
	if (obj.attachEvent){
		obj.attachEvent("on"+event_name, func_name);
	}else if(obj.addEventListener){
		obj.addEventListener(event_name,func_name,true);
	}else{
		obj["on"+event_name] = func_name;
	}
}
function removeEvent(obj,event_name,func_name){
	if (obj.detachEvent){
		obj.detachEvent("on"+event_name,func_name);
	}else if(obj.removeEventListener){
		obj.removeEventListener(event_name,func_name,true);
	}else{
		obj["on"+event_name] = null;
	}
}
function stopEvent(evt){
	evt || window.event;
	if (evt.stopPropagation){
		evt.stopPropagation();
		evt.preventDefault();
	}else if(typeof evt.cancelBubble != "undefined"){
		evt.cancelBubble = true;
		evt.returnValue = false;
	}
	return false;
}
function getCaretEnd(obj){
	if(typeof obj.selectionEnd != "undefined"){
		return obj.selectionEnd;
	}else if(document.selection&&document.selection.createRange){
		var M=document.selection.createRange();
		try{
			var Lp = M.duplicate();
			Lp.moveToElementText(obj);
		}catch(e){
			var Lp=obj.createTextRange();
		}
		Lp.setEndPoint("EndToEnd",M);
		var rb=Lp.text.length;
		if(rb>obj.value.length){
			return -1;
		}
		return rb;
	}
}
function getCaretStart(obj){
	if(typeof obj.selectionStart != "undefined"){
		return obj.selectionStart;
	}else if(document.selection&&document.selection.createRange){
		var M=document.selection.createRange();
		try{
			var Lp = M.duplicate();
			Lp.moveToElementText(obj);
		}catch(e){
			var Lp=obj.createTextRange();
		}
		Lp.setEndPoint("EndToStart",M);
		var rb=Lp.text.length;
		if(rb>obj.value.length){
			return -1;
		}
		return rb;
	}
}
function setCaret(obj,l){
	obj.focus();
	if (obj.setSelectionRange){
		obj.setSelectionRange(l,l);
	}else if(obj.createTextRange){
		m = obj.createTextRange();		
		m.moveStart('character',l);
		m.collapse();
		m.select();
	}
}
function setSelection(obj,s,e){
	obj.focus();
	if (obj.setSelectionRange){
		obj.setSelectionRange(s,e);
	}else if(obj.createTextRange){
		m = obj.createTextRange();		
		m.moveStart('character',s);
		m.moveEnd('character',e);
		m.select();
	}
}
String.prototype.addslashes = function(){
	return this.replace(/(["\\\.\|\[\]\^\*\+\?\$\(\)])/g, '\\$1');
}
String.prototype.trim = function () {
    return this.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1");
};
function curTop(obj){
	toreturn = 0;
	while(obj){
		toreturn += obj.offsetTop;
		obj = obj.offsetParent;
	}
	return toreturn;
}
function curLeft(obj){
	toreturn = 0;
	while(obj){
		toreturn += obj.offsetLeft;
		obj = obj.offsetParent;
	}
	return toreturn;
}
function replaceHTML(obj,text){
	while(el = obj.childNodes[0]){
		obj.removeChild(el);
	};
	obj.appendChild(document.createTextNode(text));
}

function actb(obj,ca,cg,dofind){
	// ---- Public Variables ---- * /
	this.actb_timeOut = -1; // Autocomplete Timeout in ms (-1: autocomplete never time out)
	this.actb_lim = 25;    // Number of elements autocomplete can show (-1: no limit)
	this.actb_firstText = false; // should the auto complete be limited to the beginning of keyword?
	this.actb_mouse = true; // Enable Mouse Support
	this.actb_delimiter = new Array(';',',');  // Delimiter for multiple autocomplete. Set it to empty array for single autocomplete
	this.actb_startcheck = 1; // Show widget only after this number of characters is typed in.
	// ---- Public Variables ---- * /

	// --- Styles --- * /
	this.actb_bgColor = actb_bgColor;
	this.actb_textColor = '#000';
	this.actb_textHColor = '#fff';
	this.actb_hColor = '#35689B'; //'F3DC5B';
	this.actb_fFamily = 'Verdana';
	this.actb_fSize = actb_fSize;
	this.actb_hStyle = 'text-decoration:underline;font-weight:bold';
	// --- Styles --- * /

	// ---- Private Variables ---- * /
	var actb_delimwords = new Array();
	var actb_cdelimword = 0;
	var actb_delimchar = new Array();
	var actb_display = false;
	var actb_pos = 0;
	var actb_total = 0;
	var actb_curr = null;
	var actb_rangeu = 0;
	var actb_ranged = 0;
	var actb_bool = new Array();
	var actb_pre = 0;
	var actb_toid;
	var actb_tomake = false;
	var actb_getpre = "";
	var actb_mouse_on_list = 1;
	var actb_kwcount = 0;
	var actb_caretmove = false;
	var actb_indelete = false;
        var actb_bingo = 0;
        var actb_restore = "";
	this.actb_keywords = new Array();
	this.actb_keywords2 = new Array();
	// ---- Private Variables---- * /
	
	this.actb_keywords = ca;
	this.actb_keywords2 = cg;
	var actb_self = this;
    if(typeof myactb != "undefined") myactb=actb_self;
	myactb = function(){actb_mouse_on_list=0;actb_removedisp();}

	actb_curr = obj;
	addEvent(actb_curr,"focus",actb_setup);
	function actb_setup(){
		addEvent(document,"keydown",actb_checkkey);
		addEvent(document,"keyup",actb_checkmatch);
		addEvent(actb_curr,"blur",actb_clear);
		addEvent(document,"keypress",actb_keypress);
	}

	function actb_clear(evt){
		if (!evt) evt = event;
		removeEvent(document,"keydown",actb_checkkey);
		removeEvent(actb_curr,"blur",actb_clear);
		removeEvent(document,"keypress",actb_keypress);
		actb_removedisp();
		if(dofind) findit();
	}
	function actb_parse(n,actbbool){
		var tobuild = '';
		if (actb_self.actb_delimiter.length > 0){
			var t = actb_delimwords[actb_cdelimword].trim().addslashes();
			var plen = actb_delimwords[actb_cdelimword].trim().length;
		}else{
			var t = actb_curr.value.addslashes();
			var plen = actb_curr.value.length;
		}
		var i;

		if (actb_self.actb_firstText){
			var re = new RegExp("^" + t, "i");
		}else{
			var re = new RegExp(t, "i");
		}

	var p = n.search(re);

	if(p>0 || actbbool==1) {
		tobuild += n.substr(0,p) + "<font style='"+(actb_self.actb_hStyle)+"'>" + n.substr(p,plen) + "</font>" + n.substr(plen+p,n.length);
	}
	else tobuild=n;
	if (tobuild != '') hide_combos();
	return tobuild;
	}
	function actb_generate(){
		if (document.getElementById('tat_table')){ actb_display = false;document.body.removeChild(document.getElementById('tat_table')); } 
		a = document.createElement('table');
		a.cellSpacing='1px';
		a.cellPadding='2px';
		a.style.position='absolute';
		a.style.top = eval(curTop(actb_curr) + actb_curr.offsetHeight) + "px";
		a.style.left = curLeft(actb_curr) + "px";
		a.style.backgroundColor=actb_self.actb_bgColor;
		a.style.color=actb_self.actb_textColor;
		a.id = 'tat_table';
		document.body.appendChild(a);
		if (actb_kwcount == 0){
			r = a.insertRow(-1);
			r.style.backgroundColor = actb_self.actb_bgColor;
			r.style.color = actb_self.actb_textColor;
			c = r.insertCell(-1);
			c.style.fontFamily = 'arial narrow';
			c.style.fontSize = actb_self.actb_fSize;
			c.align='center';
			c.innerHTML = actb_parse("--- no matches ---",0);
//			actb_display = false;
			return;
		}
		var i;
		var first = true;
		var j = 1;
		if (actb_self.actb_mouse){
			a.onmouseout = actb_table_unfocus;
			a.onmouseover = actb_table_focus;
		}
		var counter = 0;
		var good=goodi=0;
		for (i=0;i<actb_self.actb_keywords.length;i++){
			if (actb_bool[i] && j <= actb_self.actb_lim){
				counter++;
				r = a.insertRow(-1);
				if (first && !actb_tomake){
					r.style.backgroundColor = actb_self.actb_hColor;
					r.style.color = actb_self.actb_textHColor;
					first = false;
					actb_pos = counter;
				}else if(actb_pre == i){
					r.style.backgroundColor = actb_self.actb_hColor;
					r.style.color = actb_self.actb_textHColor;
					first = false;
					actb_pos = counter;
				}else{
					if (counter % 2) r.style.backgroundColor = actb_self.actb_bgColor; //actb_hColor;
					else r.style.backgroundColor = actb_self.actb_bgColor2;
					r.style.color = actb_self.actb_textColor;
				}
				r.id = 'tat_tr'+(j);
				c = r.insertCell(-1);
				c.style.fontFamily = actb_self.actb_fFamily;
				c.style.fontSize = actb_self.actb_fSize;
				c.innerHTML = actb_parse(actb_self.actb_keywords[i],actb_bool[i]);
				if (actb_self.actb_keywords[i].substr(0,2) != '--') { good++; goodi=i; }
				c.id = 'tat_td'+(j);
				c.setAttribute('pos',j);
				if (actb_self.actb_mouse){
					c.style.cursor = 'pointer';
					c.onclick=actb_mouseclick;
					c.onmouseover = actb_table_highlight;
				}
				j++;
			}
			if (j - 1 == actb_self.actb_lim && j < actb_total){
				r = a.insertRow(-1);
				r.style.backgroundColor = actb_self.actb_bgColor;
				r.style.color = actb_self.actb_textColor;
				c = r.insertCell(-1);
				c.style.fontFamily = 'arial narrow';
				c.style.fontSize = actb_self.actb_fSize;
				c.align='center';
				replaceHTML(c,'\\/');
				if (actb_self.actb_mouse){
					c.style.cursor = 'pointer';
					c.onclick = actb_mouse_down;
				}
				break;
			}
		}
		actb_rangeu = 1;
		actb_ranged = j-1;
		actb_display = true;
		if (actb_pos <= 0) actb_pos = 1;
		if (actb_indelete && counter == 2) actb_godown();
		if (su_id && good == 1 && (counter == 2 || counter == 1) && !actb_indelete) {
			actb_insertword(actb_self.actb_keywords[goodi]);
			actb_mouse_on_list = 0;
			actb_removedisp();
			actb_pos=0;
			var tDate = new Date();
			actb_bingo=tDate.getTime();
			actb_restore = actb_self.actb_keywords[goodi];
		}
		if (!counter && !good) {
			r = a.insertRow(-1);
			r.style.backgroundColor = actb_self.actb_bgColor;
			r.style.color = actb_self.actb_textColor;
			c = r.insertCell(-1);
			c.style.fontFamily = 'arial narrow';
			c.style.fontSize = actb_self.actb_fSize;
			c.align='center';
			c.innerHTML = actb_parse("--- no matches ---",0);
		}
	}
	function actb_remake(){
		document.body.removeChild(document.getElementById('tat_table'));
		a = document.createElement('table');
		a.cellSpacing='1px';
		a.cellPadding='2px';
		a.style.position='absolute';
		a.style.top = eval(curTop(actb_curr) + actb_curr.offsetHeight) + "px";
		a.style.left = curLeft(actb_curr) + "px";
		a.style.backgroundColor= actb_self.actb_bgColor;
		a.style.color= actb_self.actb_textColor;
		a.id = 'tat_table';
		if (actb_self.actb_mouse){
			a.onmouseout= actb_table_unfocus;
			a.onmouseover=actb_table_focus;
		}
		document.body.appendChild(a);
		var i;
		var first = true;
		var j = 1;
		if (actb_rangeu > 1){
			r = a.insertRow(-1);
			r.style.backgroundColor = actb_self.actb_bgColor;
			r.style.color = actb_self.actb_textColor;
			c = r.insertCell(-1);
			c.style.fontFamily = 'arial narrow';
			c.style.fontSize = actb_self.actb_fSize;
			c.align='center';
			replaceHTML(c,'/\\');
			if (actb_self.actb_mouse){
				c.style.cursor = 'pointer';
				c.onclick = actb_mouse_up;
			}
		}
		for (i=0;i<actb_self.actb_keywords.length;i++){
			if (actb_bool[i]){
				if (j >= actb_rangeu && j <= actb_ranged){
					r = a.insertRow(-1);
					if (j % 2) r.style.backgroundColor = actb_self.actb_bgColor; //actb_hColor;
					else r.style.backgroundColor = actb_self.actb_bgColor2;
					r.style.color = actb_self.actb_textColor;
					r.id = 'tat_tr'+(j);
					c = r.insertCell(-1);
					c.style.fontFamily = actb_self.actb_fFamily;
					c.style.fontSize = actb_self.actb_fSize;
					c.innerHTML = actb_parse(actb_self.actb_keywords[i],actb_bool[i]);
					c.id = 'tat_td'+(j);
					c.setAttribute('pos',j);
					if (actb_self.actb_mouse){
						c.style.cursor = 'pointer';
						c.onclick=actb_mouseclick;
						c.onmouseover = actb_table_highlight;
					}
					j++;
				}else{
					j++;
				}
			}
			if (j > actb_ranged) break;
		}
		if (j-1 < actb_total){
			r = a.insertRow(-1);
			r.style.backgroundColor = actb_self.actb_bgColor;
			r.style.color = actb_self.actb_textColor;
			c = r.insertCell(-1);
			c.style.fontFamily = 'arial narrow';
			c.style.fontSize = actb_self.actb_fSize;
			c.align='center';
			replaceHTML(c,'\\/');
			if (actb_self.actb_mouse){
				c.style.cursor = 'pointer';
				c.onclick = actb_mouse_down;
			}
		}
	}
	function actb_goup(){
		if (!actb_display) return;
		if (actb_pos == 1) return;
		if (actb_pos % 2) document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_self.actb_bgColor;
		else document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_self.actb_bgColor2; //actb_self.actb_bgColor;
		document.getElementById('tat_tr'+actb_pos).style.color = actb_self.actb_textColor;
		actb_pos--;
		if (actb_pos < actb_rangeu) actb_moveup();
		document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_self.actb_hColor;
		document.getElementById('tat_tr'+actb_pos).style.color = actb_self.actb_textHColor;
		if (actb_toid) clearTimeout(actb_toid);
		if (actb_self.actb_timeOut > 0) actb_toid = setTimeout(function(){actb_mouse_on_list=0;actb_removedisp();},actb_self.actb_timeOut);
	}
	function actb_godown(){
		if (!actb_display) return;
		if (actb_pos == actb_total) return;
		if (actb_pos % 2) document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_self.actb_bgColor;
		else document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_self.actb_bgColor2; //actb_self.actb_bgColor;
		document.getElementById('tat_tr'+actb_pos).style.color = actb_self.actb_textColor;
		actb_pos++;
		if (actb_pos > actb_ranged) actb_movedown();
		document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_self.actb_hColor;
		document.getElementById('tat_tr'+actb_pos).style.color = actb_self.actb_textHColor;
		if (actb_toid) clearTimeout(actb_toid);
		if (actb_self.actb_timeOut > 0) actb_toid = setTimeout(function(){actb_mouse_on_list=0;actb_removedisp();},actb_self.actb_timeOut);
	}
	function actb_movedown(){
		actb_rangeu++;
		actb_ranged++;
		actb_remake();
	}
	function actb_moveup(){
		actb_rangeu--;
		actb_ranged--;
		actb_remake();
	}

	// Mouse * /
	function actb_mouse_down(){
		if (actb_pos % 2) document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_self.actb_bgColor;
		else document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_self.actb_bgColor2;
		document.getElementById('tat_tr'+actb_pos).style.color = actb_self.actb_textColor;
		actb_pos++;
		actb_movedown();
		document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_self.actb_hColor;
		document.getElementById('tat_tr'+actb_pos).style.color = actb_self.actb_textHColor;
		actb_curr.focus();
		actb_mouse_on_list = 0;
		if (actb_toid) clearTimeout(actb_toid);
		if (actb_self.actb_timeOut > 0) actb_toid = setTimeout(function(){actb_mouse_on_list=0;actb_removedisp();},actb_self.actb_timeOut);
	}
	function actb_mouse_up(evt){
		if (!evt) evt = event;
		if (evt.stopPropagation){
			evt.stopPropagation();
		}else{
			evt.cancelBubble = true;
		}
		if (actb_pos % 2) document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_self.actb_bgColor;
		else document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_self.actb_bgColor2; 
		document.getElementById('tat_tr'+actb_pos).style.color = actb_self.actb_textColor;
		actb_pos--;
		actb_moveup();
		document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_self.actb_hColor;
		document.getElementById('tat_tr'+actb_pos).style.color = actb_self.actb_textHColor;
		actb_curr.focus();
		actb_mouse_on_list = 0;
		if (actb_toid) clearTimeout(actb_toid);
		if (actb_self.actb_timeOut > 0) actb_toid = setTimeout(function(){actb_mouse_on_list=0;actb_removedisp();},actb_self.actb_timeOut);
	}
	function actb_mouseclick(evt){
		if (!evt) evt = event;
		if (!actb_display) return;
		actb_mouse_on_list = 0;
		actb_pos = this.getAttribute('pos');
		actb_penter();
	}
	function actb_table_focus(){
		actb_mouse_on_list = 1;
	}
	function actb_table_unfocus(){
		actb_mouse_on_list = 0;
		if (actb_toid) clearTimeout(actb_toid);
		if (actb_self.actb_timeOut > 0) actb_toid = setTimeout(function(){actb_mouse_on_list = 0;actb_removedisp();},actb_self.actb_timeOut);
	}
	function actb_table_highlight(){
		actb_mouse_on_list = 1;
		if (actb_pos % 2) document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_self.actb_bgColor;
		else document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_self.actb_bgColor2;
		document.getElementById('tat_tr'+actb_pos).style.color = actb_self.actb_textColor;
		actb_pos = this.getAttribute('pos');
		while (actb_pos < actb_rangeu) actb_moveup();
		while (actb_pos > actb_ranged) actb_movedown();
		document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_self.actb_hColor;
		document.getElementById('tat_tr'+actb_pos).style.color = actb_self.actb_textHColor;
		if (actb_toid) clearTimeout(actb_toid);
		if (actb_self.actb_timeOut > 0) actb_toid = setTimeout(function(){actb_mouse_on_list = 0;actb_removedisp();},actb_self.actb_timeOut);
	}
	// ---- * /

	function actb_insertword(a){
		if (actb_self.actb_delimiter.length > 0){
			str = '';
			l=0;
			for (i=0;i<actb_delimwords.length;i++){
				if (actb_cdelimword == i){
					prespace = postspace = '';
					gotbreak = false;
					for (j=0;j<actb_delimwords[i].length;++j){
						if (actb_delimwords[i].charAt(j) != ' '){
							gotbreak = true;
							break;
						}
						prespace += ' ';
					}
					for (j=actb_delimwords[i].length-1;j>=0;--j){
						if (actb_delimwords[i].charAt(j) != ' ') break;
						postspace += ' ';
					}
					str += prespace;
					str += a;
					l = str.length;
					if (gotbreak) str += postspace;
				}else{
					str += actb_delimwords[i];
				}
				if (i != actb_delimwords.length - 1){
					str += actb_delimchar[i];
				}
			}
			actb_curr.value = str;
			setCaret(actb_curr,l);
		}else{
			actb_curr.value = a;
		}
		if(dofind) findit();
		actb_mouse_on_list = 0;
		actb_removedisp();
	}
	function actb_penter(){
		if (!actb_display) return;
		actb_display = false;
		var word = '';
		var c = 0;
		for (var i=0;i<=actb_self.actb_keywords.length;i++){
			if (actb_bool[i]) c++;
			if (c == actb_pos){
				word = actb_self.actb_keywords[i];
				break;
			}
		}
		actb_insertword(word);
		l = getCaretStart(actb_curr);
	}
	function actb_removedisp(){
		if (actb_mouse_on_list==0){
			actb_display = 0;
			if (document.getElementById('tat_table')){ document.body.removeChild(document.getElementById('tat_table')); }
			if (actb_toid) clearTimeout(actb_toid);
		}
	}
	function actb_keypress(e){
		if (actb_caretmove) stopEvent(e);
		return !actb_caretmove;
	}
	function actb_checkmatch(evt){
		var   tDate = new Date();
		if ((tDate.getTime() - actb_bingo) < 3000) {
			actb_curr.value=actb_restore;
			}
		}
	function actb_checkkey(evt){
		if (!evt) evt = event;
		a = evt.keyCode;
		if (su_id) {
			var   tDate = new Date();
			if ((tDate.getTime() - actb_bingo) < 1500) { return false; }
		}
		caret_pos_start = getCaretStart(actb_curr);
		actb_caretmove = 0;
		switch (a){
			case 38:
				actb_goup();
				actb_caretmove = 1;
				return false;
				break;
			case 40:
				actb_godown();
				actb_caretmove = 1;
				return false;
				break;
			case 13: case 9:
				if (actb_display){
					actb_caretmove = 1;
					actb_penter();
					return false;
				}else{
					return true;
				}
				break;
			default:
				setTimeout(function(){actb_tocomplete(a)},50);
				break;
		}
	}

	function actb_tocomplete(kc){
		if (kc == 38 || kc == 40 || kc == 13) return;
		var i;
		if (actb_display){ 
			var word = 0;
			var c = 0;
			for (var i=0;i<=actb_self.actb_keywords.length;i++){
				if (actb_bool[i]) c++;
				if (c == actb_pos){
					word = i;
					break;
				}
			}
			actb_pre = word;
		}else{ actb_pre = -1};		
		if (actb_curr.value == ' '){
			actb_curr.value = '';
			return;
		}
		if (actb_curr.value == ''){
			actb_mouse_on_list = 0;
			actb_removedisp();
			return;
		}
		if (actb_self.actb_delimiter.length > 0){
			caret_pos_start = getCaretStart(actb_curr);
			caret_pos_end = getCaretEnd(actb_curr);
			
			delim_split = '';
			for (i=0;i<actb_self.actb_delimiter.length;i++){
				delim_split += actb_self.actb_delimiter[i];
			}
			delim_split = delim_split.addslashes();
			delim_split_rx = new RegExp("(["+delim_split+"])");
			c = 0;
			actb_delimwords = new Array();
			actb_delimwords[0] = '';
			for (i=0,j=actb_curr.value.length;i<actb_curr.value.length;i++,j--){
				if (actb_curr.value.substr(i,j).search(delim_split_rx) == 0){
					ma = actb_curr.value.substr(i,j).match(delim_split_rx);
					actb_delimchar[c] = ma[1];
					c++;
					actb_delimwords[c] = '';
				}else{
					actb_delimwords[c] += actb_curr.value.charAt(i);
				}
			}

			var l = 0;
			actb_cdelimword = -1;
			for (i=0;i<actb_delimwords.length;i++){
				if (caret_pos_end >= l && caret_pos_end <= l + actb_delimwords[i].length){
					actb_cdelimword = i;
				}
				l+=actb_delimwords[i].length + 1;
			}
			var ot = actb_delimwords[actb_cdelimword].trim(); 
			var t = actb_delimwords[actb_cdelimword].addslashes().trim();
		}else{
			var ot = actb_curr.value;
			var t = actb_curr.value.addslashes();
		}
		if (ot.length == 0){
			actb_mouse_on_list = 0;
			actb_removedisp();
		}
		if (ot.length < actb_self.actb_startcheck) return this;
		if (actb_self.actb_firstText){
			var re = new RegExp("^" + t, "i");
		}else{
			var re = new RegExp(t, "i");
		}

		actb_total = 0;
		actb_tomake = false;
		actb_kwcount = 0;
		last_sep= -1;
		for (i=0;i<actb_self.actb_keywords.length;i++){
			actb_bool[i] = 0;
			k1 = re.test(actb_self.actb_keywords[i]);
			k2 = re.test(actb_self.actb_keywords2[i]);
			k3 = (actb_self.actb_keywords[i].substr(0,4) == "----");  //match sep
			if (k1||k2||k3){
				if ((k1||k2) && !k3) last_sep= -1;
				actb_total++;
				if(k1) actb_bool[i] = 1;
				else if (k2) actb_bool[i] = 2;
				if (k3) {
					if (last_sep >= 0){
						actb_bool[last_sep]=0;
						actb_total--;
					}
					actb_bool[i] = 3;
					last_sep=i;
				}
				actb_kwcount++;
				if (actb_pre == i) actb_tomake = true;
			}
		}
		if (last_sep >=0) {
			actb_total--;  // so we don't draw the down arrow
			actb_bool[last_sep]=0;
		}
		if (actb_toid) clearTimeout(actb_toid);
		if (actb_self.actb_timeOut > 0) actb_toid = setTimeout(function(){actb_mouse_on_list = 0;actb_removedisp();},actb_self.actb_timeOut);
		if (kc == 8)  actb_indelete = true;
		actb_generate();
		if (kc == 8)  actb_indelete = false;
	}
	return this;
}


function actualstyle(el, cssproperty){
if (el.currentStyle)
return el.currentStyle[cssproperty]
else if (window.getComputedStyle){
var elstyle=window.getComputedStyle(el, "")
return elstyle.getPropertyValue(cssproperty)
}
}


function collectElementbyClass(){
collectElementbyClassname('glidetext');
}

function collectElementbyClassname(classname){
glidearray=new Array()
var inc=0
var alltags=document.all? document.all : document.getElementsByTagName("*")
for (i=0; i<alltags.length; i++){
 if (alltags[i].className==classname) {
  glidearray[inc++]=alltags[i];
 }
}
if (glidearray.length>0)
onebyoneglide()
}

function onebyoneglide(){
if (curobjindex<glidearray.length)
glidetimer=setInterval("glideroutine()",5);
}


var zwk=0;
function glideroutine(){
if (parseInt(glidearray[curobjindex].offsetLeft)>500) glidearray[curobjindex].style.left=100;
if (parseInt(glidearray[curobjindex].offsetLeft)>glideleft+10) {
glidearray[curobjindex].style.left=parseInt(glidearray[curobjindex].offsetLeft, "left")-4;
if (zwk < 1) zwk = zwk + 0.05;
glidearray[curobjindex].style.opacity=zwk; 
glidearray[curobjindex].style.filter='alpha(opacity=' + zwk*100 + ')';

}
else{
glidearray[curobjindex].style.left=glideleft
curobjindex++
clearInterval(glidetimer)
setTimeout("onebyoneglide()", pausebetweenmsg)
}
}


var starz=new Array();
function starson(star1,star) {
for (i=star1; i <= star; i++) {
    document.getElementById('str'+i).src="images/star2.gif";
        }
for (i=star + 1; i <= star1+4; i++) {
    document.getElementById('str'+i).src="images/star1.gif";
        }
}
function starsoff(star1,star) {
if(starz[star1]) starlevel=starz[star1];
else starlevel=star1;
for (i=star1+4; i >= starlevel; i--) document.getElementById('str'+i).src="images/star1.gif";
if(starz[star1]) starlevel=starz[star1];
else starlevel=star1 - 1;
for (i=star1; i <= starlevel; i++) document.getElementById('str'+i).src="images/star3.gif";
}
function addstarval(star) {
document.forms[0].starvals.value+=','+star;
}
function starscl(star1,star) {
starz[star1]=star;
addstarval(star);
for (i=star1; i <= star; i++) {
    document.getElementById('str'+i).src="images/star3.gif";
        }
}

var xmlHttp,ajax_target;
function GoAjax(url,params,stateChangedFunc) { 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null) {alert ("Browser does not support HTTP Request");return;}
xmlHttp.onreadystatechange=stateChangedFunc;
xmlHttp.open("POST",url+".php",true);
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
//xmlHttp.setRequestHeader("Content-length", params.length); // makes safari complain
xmlHttp.setRequestHeader("Connection", "close");
xmlHttp.send(params);
}

function GoNow(url,params) { 
	GoAjax(url,params,stateChanged);
}

var jscodestuff='';
var oldtarget='';
var params='';
// params and ajax_target are set in scrippad.js function go_to
function stateChanged() { 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
		document.getElementById("XCommentz").innerHTML=xmlHttp.responseText;
	}
}

function GoRules(url,params) {
	GoAjax(url,params,stateChangedRules);
}

function GoRules2(url,params) {
	GoAjax(url,params,stateChangedRules2);
}

function stateChangedRules() { 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
		if(ajax_target!=null && ajax_target!='') {
    if (ajax_target.substring(0,6) == 'scrip_')
	  {
//alert (ajax_target + " * " + xmlHttp.responseText);
	  jscodestuff= xmlHttp.responseText;
	  oldtarget=ajax_target;
	  // Launch the html next
	  target='action=scrip'+ajax_target.substring(6);
	  ajax_target='XScripz';
	  GoRules('ajxorders',target+params);
	  }
    else 
	  {
	  document.getElementById(ajax_target).innerHTML=xmlHttp.responseText;
	  // Need HTML before js can act on it
	  if (oldtarget.substring(0,5) == 'scrip')
		{
	 	if (oldtarget.substring(6) == '3')
			{
			var headID = document.getElementsByTagName("head")[0];         
			var script = document.createElement('script');
			script.type = 'text/javascript';
			addpart='';
			if (formulary != 0) addpart='_'+formulary;
			script.src = 'js/add_narvs'+addpart+'.js';
			headID.appendChild(script);
			}
		script = document.createElement('script');
		script.type = 'text/javascript';
		browser = navigator.userAgent;
		x = browser.indexOf("Safari");
		if (x > 0)  // Safari needs this
		  {
	  	  var text = document.createTextNode(jscodestuff);
	      script.appendChild(text);
	      }
	    else script.text = jscodestuff;
	    document.body.appendChild(script);
		}
	  else oldtarget=ajax_target;
		ajax_target='';
	  }
		}
		else {
			var t = xmlHttp.responseText;
			var i = t.indexOf(']');
			document.getElementById("cgresponse").innerHTML=t.substring(i+1);
			var loc = t.substring(0,i);
			if(loc) {
				GoDataUpdate(loc);
			}
		}
	}
}

function stateChangedRules2() { 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
		var t = xmlHttp.responseText;
		var i = t.indexOf(']');
		document.getElementById("cgresponse").innerHTML=t.substring(i+1);
		var loc = t.substring(0,i);
		if(loc) {
			GoDataUpdate2(loc);
		}
	}
}

function getajxurl(action) {
	var url;
	switch(action) {
	case 'listlaborders': url = 'ajxlaborders'; break;
	case 'listdiags': url = 'ajxdiagnosis'; break;
	case 'listtherapies': 
	case 'listorders': url = 'ajxorders'; break;
	}
	return url;
}

function GoDataUpdate(action) {
	GoAjax(getajxurl(action),'action='+action,stateChangedDataUpdate);
}

function GoDataUpdate2(action) {
	GoAjax(getajxurl(action),'action='+action,stateChangedDataUpdate2);
}

function stateChangedDataUpdate() { 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
		document.getElementById("datadiv").innerHTML=xmlHttp.responseText;
	}
}

function stateChangedDataUpdate2() { 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
		document.getElementById("datadiv2").innerHTML=xmlHttp.responseText;
	}
}

function GetXmlHttpObject() {
var xmlHttp2=null;
try {
 xmlHttp2=new XMLHttpRequest();
 }
catch (e) {
 try  {
  xmlHttp2=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)  {
  xmlHttp2=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp2;
}

/******************** END LOCALIZABLE **********************/

var gTagAttrs				= null;
var gQTGeneratorVersion		= 1.0;

function AC_QuickTimeVersion()	{ return gQTGeneratorVersion; }

function _QTComplain(callingFcnName, errMsg)
{
    errMsg = errMsg.replace("%%", callingFcnName);
	alert(errMsg);
}

function _QTAddAttribute(prefix, slotName, tagName)
{
	var		value;

	value = gTagAttrs[prefix + slotName];
	if ( null == value )
		value = gTagAttrs[slotName];

	if ( null != value )
	{
		if ( 0 == slotName.indexOf(prefix) && (null == tagName) )
			tagName = slotName.substring(prefix.length); 
		if ( null == tagName ) 
			tagName = slotName;
		return '' + tagName + '="' + value + '"';
	}
	else
		return "";
}

function _QTAddObjectAttr(slotName, tagName)
{
	// don't bother if it is only for the embed tag
	if ( 0 == slotName.indexOf("emb#") )
		return "";

	if ( 0 == slotName.indexOf("obj#") && (null == tagName) )
		tagName = slotName.substring(4); 

	return _QTAddAttribute("obj#", slotName, tagName);
}

function _QTAddEmbedAttr(slotName, tagName)
{
	// don't bother if it is only for the object tag
	if ( 0 == slotName.indexOf("obj#") )
		return "";

	if ( 0 == slotName.indexOf("emb#") && (null == tagName) )
		tagName = slotName.substring(4); 

	return _QTAddAttribute("emb#", slotName, tagName);
}


function _QTAddObjectParam(slotName, generateXHTML)
{
	var		paramValue;
	var		paramStr = "";
	var		endTagChar = (generateXHTML) ? ' />' : '>';

	if ( -1 == slotName.indexOf("emb#") )
	{
		// look for the OBJECT-only param first. if there is none, look for a generic one
		paramValue = gTagAttrs["obj#" + slotName];
		if ( null == paramValue )
			paramValue = gTagAttrs[slotName];

		if ( 0 == slotName.indexOf("obj#") )
			slotName = slotName.substring(4); 
	
		if ( null != paramValue )
			paramStr = '<param name="' + slotName + '" value="' + paramValue + '"' + endTagChar;
	}

	return paramStr;
}

function _QTDeleteTagAttrs()
{
	for ( var ndx = 0; ndx < arguments.length; ndx++ )
	{
		var attrName = arguments[ndx];
		delete gTagAttrs[attrName];
		delete gTagAttrs["emb#" + attrName];
		delete gTagAttrs["obj#" + attrName];
	}
}

		

// generate an embed and object tag, return as a string
function _QTGenerate(callingFcnName, generateXHTML, args)
{
	// is the number of optional arguments even?
	if ( args.length < 4 || (0 != (args.length % 2)) )
	{
		_QTComplain(callingFcnName, gArgCountErr);
		return "";
	}
	
	// allocate an array, fill in the required attributes with fixed place params and defaults
	gTagAttrs = new Object();
	gTagAttrs["src"] = args[0];
	gTagAttrs["width"] = args[1];
	gTagAttrs["height"] = args[2];
	gTagAttrs["classid"] = "clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B";
		//Impportant note: It is recommended that you use this exact classid in order to ensure a seamless experience for all viewers
	gTagAttrs["pluginspage"] = "http://www.apple.com/quicktime/download/";

	// set up codebase attribute with specified or default version before parsing args so
	//  anything passed in will override
	var activexVers = args[3]
	if ( (null == activexVers) || ("" == activexVers) )
		activexVers = "6,0,2,0";
	gTagAttrs["codebase"] = "http://www.apple.com/qtactivex/qtplugin.cab#version=" + activexVers;

	var	attrName,
		attrValue;

	// add all of the optional attributes to the array
	for ( var ndx = 4; ndx < args.length; ndx += 2)
	{
		attrName = args[ndx].toLowerCase();
		attrValue = args[ndx + 1];

		// "name" and "id" should have the same value, the former goes in the embed and the later goes in
		//  the object. use one array slot 
		if ( "name" == attrName || "id" == attrName )
			gTagAttrs["name"] = attrValue;

		else 
			gTagAttrs[attrName] = attrValue;
	}

	// init both tags with the required and "special" attributes
	var objTag =  '<object '
					+ _QTAddObjectAttr("classid")
					+ _QTAddObjectAttr("width")
					+ _QTAddObjectAttr("height")
					+ _QTAddObjectAttr("codebase")
					+ _QTAddObjectAttr("name", "id")
					+ _QTAddObjectAttr("tabindex")
					+ _QTAddObjectAttr("hspace")
					+ _QTAddObjectAttr("vspace")
					+ _QTAddObjectAttr("border")
					+ _QTAddObjectAttr("align")
					+ _QTAddObjectAttr("class")
					+ _QTAddObjectAttr("title")
					+ _QTAddObjectAttr("accesskey")
					+ _QTAddObjectAttr("noexternaldata")
					+ '>'
					+ _QTAddObjectParam("src", generateXHTML);
	var embedTag = '<embed '
					+ _QTAddEmbedAttr("src")
					+ _QTAddEmbedAttr("width")
					+ _QTAddEmbedAttr("height")
					+ _QTAddEmbedAttr("pluginspage")
					+ _QTAddEmbedAttr("name")
					+ _QTAddEmbedAttr("align")
					+ _QTAddEmbedAttr("tabindex");

	// delete the attributes/params we have already added
	_QTDeleteTagAttrs("src","width","height","pluginspage","classid","codebase","name","tabindex",
					"hspace","vspace","border","align","noexternaldata","class","title","accesskey");

	// and finally, add all of the remaining attributes to the embed and object
	for ( var attrName in gTagAttrs )
	{
		attrValue = gTagAttrs[attrName];
		if ( null != attrValue )
		{
			embedTag += _QTAddEmbedAttr(attrName);
			objTag += _QTAddObjectParam(attrName, generateXHTML);
		}
	} 

	// end both tags, we're done
	return objTag + embedTag + '></em' + 'bed></ob' + 'ject' + '>';
}

// return the object/embed as a string
function QT_GenerateOBJECTText()
{
	return _QTGenerate("QT_GenerateOBJECTText", false, arguments);
}

function QT_GenerateOBJECTText_XHTML()
{
	return _QTGenerate("QT_GenerateOBJECTText_XHTML", true, arguments);
}

function QT_WriteOBJECT()
{
	document.writeln(_QTGenerate("QT_WriteOBJECT", false, arguments));
}

function QT_WriteOBJECT_XHTML()
{
	document.writeln(_QTGenerate("QT_WriteOBJECT_XHTML", true, arguments));
}

function fontchanger(size) {
	document.getElementById('fontsize').value=size;
	size1 = 11;
	size2 = 16;
	if(size=='medium') {
		sizer = 3;
	}
	else if(size=='large') {
		sizer = 5;
	}
	else {
		sizer = 0;
	}
	size1 += sizer;
	size2 += sizer;
	document.getElementById('thebody').style.fontSize=size1+'px';
	tds = document.getElementById('thebody').getElementsByTagName('td');
	for(i=0; i<tds.length;i++) {
		switch(tds[i].className) {
		case 'intro_gray':
		case 'porf_head_txt':
		case 'dark_blue_strip_bold':
		case 'therapy_center_bg':
//dark_blue_strip_bold
//
			tds[i].style.fontSize=size2+'px';
			break;
//18
//blue_heading_18
//12
//dark_blue_strip
//green_text2
//14
//bluetextbold_14
		}
	}
}
function ShowHHover(hoveritem,txt)
{
//alert ( hoveritem.offsetTop + " ~ "  +hoveritem.offsetLeft + getAbsTop(hoveritem));
hp = document.getElementById("HHpop");
hp.style.top = eval(curTop(hoveritem) + hoveritem.offsetHeight) + "px";
hp.style.left = eval(curLeft(hoveritem)) + "px";

//hp.style.top = 499;
//getAbsTop(hoveritem) ;
//hp.style.left = 250;
//getAbsLeft(hoveritem) ;
hp2 = document.getElementById("HHtext");
hp2.innerHTML=txt;
hp.style.visibility = "Visible";
}

function HideHHover()
{
hp = document.getElementById("HHpop");
hp.style.visibility = "Hidden";
}



