function SelectOption(SelectField,Value)
{
	for(so=0;so<SelectField.options.length;so++)
	{
		if(SelectField.options[so].value==Value)
			SelectField.options[so].selected=true;
	}
}
function WindowFocus(myLink,windowName,features)
{
	if(! window.focus)return;
	var myWin=window.open(myLink,windowName,features);
	myWin.focus();
	myLink.target=windowName;
}

function hideObj(what)
{
	what.style.visibility="hidden"
	what.style.display="none";
}

function showObj(what)
{
	what.style.visibility=""
	what.style.display="block";
}

function UpdateHTMLData(divname,HTMLData)
{
	document.getElementById(divname).innerHTML=HTMLData;
}	

function LoadInPostBack(URL, divname)
{
    if(URL.indexOf("?")>0)
    {
        divname="&UpdateDivWithData=" + divname;
    }
    else
    {
        divname="?UpdateDivWithData=" + divname;
    }
    PostBack.location.href=URL+divname;
}	
/*
New functions for Hide & Show
works with all browsers..(IE5+, NS7+, Opera7+, Mozilla)
RS - 25/09/2003

*/
function newHideObj(what)
{
	document.getElementById(what).style.visibility="hidden";
	document.getElementById(what).style.display="none";
}

function newShowObj(what)
{
	document.getElementById(what).style.visibility="";
	document.getElementById(what).style.display="inline";
}
function HideShow2(what)
{
	if(document.getElementById(what).style.visibility=="hidden")
	{
		document.getElementById(what).style.visibility="";
		document.getElementById(what).style.display="inline";
	}
	else
	{
		document.getElementById(what).style.visibility="hidden";
		document.getElementById(what).style.display="none";
	}
}
function OpenModalWindow(URL,NameParameters,windowHeight,windowWidth)
{
	if(window.showModalDialog && UseDialogBox)
	{
		showModalDialog(URL,NameParameters,"dialogHeight:"+windowHeight+";dialogWidth:"+windowWidth+";help:no;status:yes;");
	}
	else
	{
		if(!window.focus) return;
		windowHeight=parseInt(windowHeight)-47;
		windowWidth=parseInt(windowWidth)-9;
		windowName= NameParameters.name + (Math.round((Math.random()*9)+1)).toString(); //Generate a Random Window name
		var myWin=window.open(URL,windowName,"height="+windowHeight+",width="+windowWidth+",dependent=yes,scrollbars=yes,toolbar=no,location=no,directories=no,status=no,resizable=no,copyhistory=no,modal=yes");
		myWin.focus();
		URL.target=windowName;
	}
}

function expandcollapse(com,what)
{
	document.getElementById("com"+com+"_0").style.visibility="hidden";
	document.getElementById("com"+com+"_1").style.visibility="hidden";
	document.getElementById("com"+com+"_0").style.display="none";
	document.getElementById("com"+com+"_1").style.display="none";
											
	document.getElementById("com"+com+"_"+what).style.visibility="visible";
	document.getElementById("com"+com+"_"+what).style.display="inline";
											
}


//Script used in Tabs and in Onloads
isMac = (navigator.appVersion.indexOf("Mac")!=-1) ? true : false;
NS4 = (document.layers) ? true : false;
IEmac = ((document.all)&&(isMac)) ? true : false;
IE4plus = (document.all) ? true : false;
IE4 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 4.")!=-1)) ? true : false;
IE5 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 5.")!=-1)) ? true : false;
ver4 = (NS4 || IE4plus) ? true : false;
NS6 = (!document.layers) && (navigator.userAgent.indexOf('Netscape')!=-1)?true:false;

// Body onload utility (supports multiple onload functions)
var gSafeOnload = new Array();
function SafeAddOnload(f)
{
	if (IEmac && IE4)  // IE 4.5 blows out on testing window.onload
	{
		window.onload = SafeOnload;
		gSafeOnload[gSafeOnload.length] = f;
	}
	else if  (window.onload)
	{
		if (window.onload != SafeOnload)
		{
			gSafeOnload[0] = window.onload;
			window.onload = SafeOnload;
		}		
		gSafeOnload[gSafeOnload.length] = f;
	}
	else
		window.onload = f;
}
function SafeOnload()
{
	for (var i=0;i<gSafeOnload.length;i++)
		gSafeOnload[i]();
}
//Supply the URL and a IDToUpdate and it'll display everything from the URL in the IDToUpdate
function GetPage(URL,IDToUpdate)
{
	var xmlhttp=false;
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	// JScript gives us Conditional compilation, we can cope with old IE versions.
	// and security blocked creation of the objects.
	 try {
	  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	 } catch (e) {
	  try {
	   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (E) {
	   xmlhttp = false;
	  }
	 }
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') 
	{
	  xmlhttp = new XMLHttpRequest();
	}
	xmlhttp.open("GET", URL,true);
	xmlhttp.onreadystatechange=function() 
	{
	 if (xmlhttp.readyState==4) 
	 {
	  document.getElementById(IDToUpdate).innerHTML=xmlhttp.responseText;
	 }
	}
	xmlhttp.send(null)
}
/*
//Supply the URL and number of Parts as numParts
//The URL called should have xml structure of
//<response>
//	<response1 IDToUpdate="id1"><!--data for part1--></response1>
//	<response2 IDToUpdate="id2"><!--data for part2--></response2>
//</response>
//the ids passed in xml will be updated with the content inside
*/
function GetPage2(URL,numParts)
{
	var xmlhttp=false;
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	// JScript gives us Conditional compilation, we can cope with old IE versions.
	// and security blocked creation of the objects.
	 try {
	  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	 } catch (e) {
	  try {
	   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (E) {
	   xmlhttp = false;
	  }
	 }
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') 
	{
	  xmlhttp = new XMLHttpRequest();
	}
	xmlhttp.open("GET", URL,true);
	//document.getElementById("").
	xmlhttp.onreadystatechange=function() 
	{
	 if (xmlhttp.readyState==4) 
	 {
		
		try
		{
			objxml=xmlhttp.responseXML.documentElement;
//			alert(xmlhttp.responseText);
/*			xx="";
			for(x=0;x<objxml.childNodes.length;x++)
			{
				xx+=objxml.childNodes[x].tagName + "\n";
			}
			alert(xx);
			alert(xmlhttp.responseText);
*/
		}
		catch (er)
		{
			alert("There seems to be a problem with the action that you requested.\nPlease try again or contact Practice Manager Support.");
			if(ShowXMLErrors==true)
			{
				OpenWindowWithText(err.message, xmlhttp.responseText);
			}
			return;
		}
		try
		{
			if(objxml.getElementsByTagName("sourcetext").length>0) //only used in firefox when it doesnt get the full XML
			{
				alert("There seems to be a problem with the action that you requested.\nPlease try again or contact Practice Manager Support..");
				if(ShowXMLErrors==true)
				{
					OpenWindowWithText(err.message, xmlhttp.responseText);
				}
				return;
			}
			else
			{
				//Lets see if we have any errors
				ourobj=objxml.getElementsByTagName("error");
				if(ourobj.length>0)
				{
					alert(ourobj[0].childNodes[0].data);
				}
				else
				{
					for(n1=1;n1<=numParts;n1++)
					{
						ourobj=objxml.getElementsByTagName("response" + n1);
						if(ourobj.length>0)
						{
							if(ourobj[0].getAttribute("IDToUpdate")!=null)
							{
								document.getElementById(ourobj[0].getAttribute("IDToUpdate")).innerHTML=ourobj[0].childNodes[0].data;
							}
						}
					}
				}
			}
		}
		catch (err)
		{
			alert("There seems to be a problem with the action that you requested.\nPlease try again or contact Practice Manager Support...");
			if(ShowXMLErrors==true)
			{
				OpenWindowWithText(err.message, xmlhttp.responseText);
			}
			return;
		}
		
	 }
			
	}
	xmlhttp.send(null)
}

function OpenWindowWithText(ErrorTitle,HTMLError)
{
var OpenWindow=window.open("", "newwin", "");
OpenWindow.document.write("<TITLE>Error:" + ErrorTitle + "</TITLE>")
OpenWindow.document.write("<BODY>")
OpenWindow.document.write(HTMLError)
OpenWindow.document.write("</BODY>")
OpenWindow.document.close()
self.name="main"
}