
var strNextUrl = "";
var strPrevUrl = "";

/** Move on to the next item/page **/
function doNext(strUrl)
{
	if (strUrl && strUrl.length>0)
	{
		strNextUrl = strUrl;	
	}
	if (strNextUrl.length<1 || !bNextButton) { return; }
	document.pageForm.action = strNextUrl;
	document.pageForm.submit();
}

/** Move on to the previous item/page **/
function doPrevious()
{
	if (strPrevUrl.length<1) { return; }
	document.pageForm.action = strPrevUrl;
	document.pageForm.submit();
}

/** Move back to preview item/page **/
function doBack()
{
	history.back();
}

/** Go to top of page **/
function doTop()
{
	document.location.href="#top";
}


/** 
	Anything to be done once we've finished loading 
**/
function doOnLoad()
{
	self.focus();
	initializePageState();
	if (self.floatMenu) { floatMenu(); } //navigation.jsp /* MedPrep Custom */
	if (self.pageOnLoad) { pageOnLoad(); }
}

/** Prepare a page's runtime state **/
function initializePageState()
{
	strNextUrl = strNextInternalUrl;
	strPrevUrl = strPreviousInternalUrl;
	if (strNextUrl.length<1) { strNextUrl=strNextExternalUrl; }
	if (strPrevUrl.length<1) { strPrevUrl=strPreviousExternalUrl; }
		
	if (strNextUrl.length>0)
	{
		if (document.getElementById("localnav-next-anchor"))
			document.getElementById("localnav-next-anchor").style.visibility="visible";
	}

	if (strPrevUrl.length>0)
	{
		if (document.getElementById("localnav-previous-anchor"))
			document.getElementById("localnav-previous-anchor").style.visibility="visible";
	}
	
	if (nBackTopLinks>0)
	{
		if (nBackTopLinks>=2)
		{
			if (document.getElementById("localnav-back-anchor"))
				document.getElementById("localnav-back-anchor").style.visibility="visible";
		}
		
		if (nBackTopLinks==1 || nBackTopLinks==3)
		{
			if (document.getElementById("localnav-top-anchor"))
				document.getElementById("localnav-top-anchor").style.visibility="visible";			
		}
	}
}


/** Submit an online form **/
function doFormSubmit(strUrl, ctrl)
{
	ctrl.disabled = true;
	document.pageForm.action = strUrl;
	document.pageForm.target = "innerFrame";
	
	// check that all required fields have been answered
	for (i=0;i<document.pageForm.elements.length;i++)
	{
		if (document.pageForm.elements[i].name.indexOf("frmR")==0 && !(document.pageForm.elements[i].selectedIndex>=0 || document.pageForm.elements[i].value.length>0))
		{
			// try to get the caption, otherwise use the name in the field name
			var strCaption;
			if (document.pageForm.elements["cap"+document.pageForm.elements[i].name.substring(3)])
			{ 
				strCaption = document.pageForm.elements["cap"+document.pageForm.elements[i].name.substring(3)].value;
			}
			else
			{
				strCaption = document.pageForm.elements[i].name.substring(document.pageForm.elements[i].name.lastIndexOf("_")+1);	
			}
			if (strCaption.length<1) 
			{ 
				alert("One or more required fields have not been answered.");
			}
			else
			{
				alert("\"" + strCaption + "\" is required.");
			}
			document.pageForm.elements[i].focus();
			ctrl.disabled = false;
			return false;
		}
	}
	document.pageForm.submit();
	document.pageForm.target = "_self";
	return false; // always return false here
}
