

    var timerID = 0;
    var quoteTimerID = 0;
    var tStart  = null;
    var timerPause = 1000;

    function UpdateTimer()
    {
        if(timerID)
        {
            clearTimeout(timerID);
        }

        if(!tStart)
        {
            tStart = new Date();
        }

        var tDate = new Date();
        var tDiff = tDate.getTime() - tStart.getTime();

        tDate.setTime(tDiff);
        
        var ParentTopPosition = 0;
        var ParentBottomPosition = 0;
        var vParent = document.getElementById('form1');
        if (vParent != null)
        {
            ParentTopPosition = FindYPos(vParent);
            ParentBottomPosition = vParent.offsetHeight;
        }
    }
    
    function Start()
    {
        tStart = new Date();

        // timer for keeping the nav in sight
//        timerID = setTimeout("UpdateTimer()", timerPause);
      
        // timer for keeping the quote up to date
//        quoteTimerID = setTimeout("TimerFired()", timerPause * 10);
        
        AutoSaveLoadPage();
        
        SetInitialInstanceVisibility();
        
		// call start on our children
		if (typeof expertStart == "function")
		{
			expertStart();
		}
    }
    
        
// -->

	// Dirty detection (incomplete)
	// works with the body tag having the following event handler: onkeydown="javascript:DirtyForm(event);"

	function DirtyForm(e)
	{
		var keynum;
 
		// IE
		if(window.event)
		{
			keynum = e.keyCode;
		}
		 // Firefox & Opera
		else if(e.which)
		{
			keynum = e.which;
		}
		
		// we don't treat return or tab as a value-changing key
		// stroke.  But arrow keys are since they can change drop lists
		if ((keynum != 13) && (keynum != 9))
		{			
			SetFormDirty();
		}
	}

	// ways the form gets dirty:
	// * Keypresses that aren't the return key (data entry, arror keys changing drop lists)
	// * Mouse presses that fire onchange drop list handlers or add/remove repeating sections
	function SetFormDirty()
	{
		var vC = document.getElementById("FormIsDirty");
		
		if (vC != null)
		{
			vC.value = "true";
		}
	}


    //
    // Auto Save code
    var idAutoSaveTimer; 
    var idAutoSaveCountdownTimer; 
    // this gets set from the initial string in the count down
    var initialCountdownValue;
    var currentCountdownValue;

    function AutoSaveLoadPage()
    {
		// if we are in read-only mode there will be no vAutoSaveTimerValue defined
		if (typeof(vAutoSaveTimerValue) != "undefined")
		{
			idAutoSaveTimer = self.setTimeout("AutoSaveTimerFired()", vAutoSaveTimerValue);
			initialCountdownValue = GetCountDownTime();
			Alerter("initial");
			Alerter("initial :" + initialCountdownValue);
        }
    }
    
	function ResetAutoSaveTimerOnActivity()
    {
		// clear the old timers
        self.clearTimeout(idAutoSaveTimer);
        self.clearTimeout(idAutoSaveCountdownTimer);
        
        ShowHideAutoSaveSection(false);
        
        // reset the countdown count
		var vCountDown = document.getElementById("AutoSavingValue");
		
		if (vCountDown != null)
		{
			if (initialCountdownValue == NaN)
			{
				Alerter("initialCountdownValue == NaN")
				DisplayCountDownTime(10);
				initialCountdownValue = 10;
			}
			else
			{
				Alerter("initialCountdownValue != NaN")
				DisplayCountDownTime(initialCountdownValue);
			}
		}
        
        // set it anew
        AutoSaveLoadPage();
    }
    
    function AutoSaveTimerFired()
    {
		// done with course timer
		self.clearTimeout(idAutoSaveTimer);
		
		// start fine timer
        idAutoSaveCountdownTimer = self.setTimeout("AutoSaveCountdownTimerFired()", 1000);
	}
	
	function ShowHideAutoSaveSection(bShow)
	{
		var vCountDownLabelPrefix = document.getElementById("AutoSavingLabelPrefix");
		var vCountDownLabelSuffix = document.getElementById("AutoSavingLabelSuffix");
		var vCountDown = document.getElementById("AutoSavingValue");
		
		if (vCountDownLabelPrefix != null)
		{
			vCountDownLabelPrefix.style.display = bShow ? "inline" : "none";
		}
		if (vCountDownLabelSuffix != null)
		{
			vCountDownLabelSuffix.style.display = bShow ? "inline" : "none";
		}
		if (vCountDown != null)
		{
			vCountDown.style.display = bShow ? "inline" : "none";
		}
	}
	
	function DisplayCountDownTime(vNewValue)
	{
		Alerter("DisplayCountDownTime incoming");
		Alerter("DisplayCountDownTime incoming: " + vNewValue);
		if (vNewValue == NaN)
		{
			Alerter("DisplayCountDownTime NaN ");
			Alerter("DisplayCountDownTime NaN 2 " + vNewValue);
		}
		
		var vCountDown = document.getElementById("AutoSavingValue");
		if (vCountDown != null)
		{
			vCountDown.innerText = vNewValue;
		}
	}
	
	function GetCountDownTime()
	{
		var vCountDown = document.getElementById("AutoSavingValue");
		var vCurrentCount = 10;
		if (vCountDown != null)
		{
			Alerter("GetCountDownTime innerText");
			Alerter("GetCountDownTime innerText " + vCountDown.innerText);
		
			vCurrentCount = parseInt(vCountDown.innerText, 10);
			
			Alerter("GetCountDownTime ");
			Alerter("GetCountDownTime " + vCurrentCount);
		}
		
		return vCurrentCount;
	}
    
    function AutoSaveCountdownTimerFired()
    {
		ShowHideAutoSaveSection(true);
		
		var vCountDown = document.getElementById("AutoSavingValue");
		
		if (vCountDown != null)
		{
			vCountDown.style.display = "inline";

			if (vCountDown.innerText != NaN)
			{
				currentCountdownValue = vCountDown.innerText;
			}
			else
			{
				currentCountdownValue = 10;
			}
			
			
			if ((initialCountdownValue == null) || (initialCountdownValue == NaN))
			{
				initialCountdownValue = currentCountdownValue;
			}
			
			currentCountdownValue = currentCountdownValue - 1;
			
			if (currentCountdownValue == 0)
			{
				self.clearTimeout(idAutoSaveCountdownTimer);
				
				ScrollToElement(vCountDown);

				// this is a hack that loads the animated gif late so it will be automated
				setTimeout('AutoSaveToggleView();', 200);

				ShowHideAutoSaveSection(false);
		        
				SaveForm();
			}
			else
			{
				if (currentCountdownValue == NaN)
				{
					currentCountdownValue = 10;
				}
				
				Alerter("currentCountdownValue != 0");
				DisplayCountDownTime(currentCountdownValue);
				
				// restart fine timer
				idAutoSaveCountdownTimer = self.setTimeout("AutoSaveCountdownTimerFired()", 1000);
			}
        }
    }
    
    function SaveForm()
    {
        var vSaveButton = document.getElementById("ButtonSave2");
        
        if (vSaveButton)
        {
            vSaveButton.click();
        }
    }

    function AutoSaveToggleView()
    {
        var vFormDiv = document.getElementById("ESCI_PreliminaryDiv");
        var vAutoSaveDiv = document.getElementById("autosavediv");
        
        if ((vFormDiv != null) && (vAutoSaveDiv != null))
        {
			// note how this code supports multiple classes
            if (vFormDiv.className.indexOf("activeform") != -1)
            {
                vFormDiv.className = vFormDiv.className.replace("activeform", "inactiveform");
                vAutoSaveDiv.className = "saving";
            }
            else
            {
                vFormDiv.className = vFormDiv.className.replace("inactiveform", "activeform");
                vAutoSaveDiv.className = "notsaving";
            }
        }
    }    
	
	// special script to handle "send anywhere" functionality
	function handleSendAnywhere()
	{
		var vUnderwriter = document.getElementById("ESCI_DCP_0_UnderwriterIDFK");
		
		if (vUnderwriter != null)
		{
			var vLabel = "Submit";
			var vToolTip = "Click here to submit this Preliminary Opinion to Attorneys Title";
			if (vUnderwriter.options[vUnderwriter.selectedIndex].text.toLowerCase() == "other")
			{
				vLabel = "Finalize";
				vToolTip = "Click here to promote this Preliminary Opinion to submitted status for your own tracking purposes";
			}
			
			// submit button becomes something else
			var vSubmitButton = document.getElementById("ESCI_ButtonSubmit");
			
			if (vSubmitButton != null)
			{
				vSubmitButton.value = vLabel;
				vSubmitButton.title = vToolTip;
			}
			
			var vSubmitButton2 = document.getElementById("ESCI_ButtonSubmit2");
			
			if (vSubmitButton2 != null)
			{
				vSubmitButton2.value = vLabel;
				vSubmitButton2.title = vToolTip;
			}
		}
	}
	
	function expertStart()
	{	
		checkForEmptyAttorneyDropList();
		
		// handle attorney change
		SpecialPreProcessingOfAttorneyDropList();
		// initial display
		AttorneyWarnings();
		
		collapseEmptyNotes();
		
		handleSendAnywhere();
		
		DisplayPriorDateFeedBack('ESCI_DCP_0_PD_PD_0_PriorIssueDate');
		
		// we are just about loaded so hide the wait section
		SetWaitVisibility(false);

        // now scroll to the position that last was in view based on custom mechanism
        var vC = document.getElementById("ScrollPosition"); 
        if ((vC != null) && (vC.value != ""))
        {
			var vFocus = document.getElementById(vC.value);
						 
			if (vFocus != null)
			{
				ScrollToElement(vFocus);
			}
		}		
	}
	
	function DisplayPriorDateFeedBack(priorDateControlID)
	{
		var vC = document.getElementById(priorDateControlID);
		
		if (vC != null)
		{
			var cutoffDate = new Date();
			cutoffDate.setFullYear(cutoffDate.getFullYear() - 15);
			cutoffDate.setDate(cutoffDate.getDate() - 1);
			
			var priorDate = Date.parse(vC.value);
			
			// if the feedback element doesn't exist, add it
			var vPriorIssueDateLI = document.getElementById("ESCI_DCP_0_PD_PD_0_PriorIssueDate_div");
			if (vPriorIssueDateLI != null)
			{
				var vFeedback = document.getElementById('ESCI_DCP_0_PD_PD_0_PriorIssueDate_Feedback_div');
				if (vFeedback == null)
				{
					vFeedback = document.createElement('div');
					var divID1 = 'ESCI_DCP_0_PD_PD_0_PriorIssueDate_Feedback_div';
					vFeedback.setAttribute('id',divID1);
					vFeedback.style.display = 'block';

					vPriorIssueDateLI.appendChild(vFeedback);
				}
			}	
				
			if (!isNaN(priorDate))
			{
				if (priorDate < cutoffDate)
				{
					vFeedback.innerHTML = 'This prior policy is available for tacking, but CANNOT be used to obtain a reissue rate.';
					vFeedback.className = 'errorClass';
				}
				else
				{
					vFeedback.innerHTML = 'This prior policy is available for tacking and can be used to obtain a reissue rate.';
					vFeedback.className = 'feedbackClass';
				}
			}
			else
			{
				// per logic description: treat a null value for date as a date older than 15 yrs
				vFeedback.innerHTML = 'This prior policy is available for tacking, but CANNOT be used to obtain a reissue rate.  If you provide a Policy Date, reissue credit might become available.';
				vFeedback.className = 'errorClass';
			}
		}
	}

	
	function AttorneyWarnings()
	{
		var vAtty = document.getElementById("ESCI_DCP_0_AttorneyUIDFK");
		
		if (vAtty != null)
		{
			var vSelectedOption = vAtty.options[vAtty.selectedIndex];
			
			var fragments = vSelectedOption.value.split(',');
			
			var veSigDiv = document.getElementById("ESCI_DCP_0_AttorneyUIDFK_Feedback_NoeSig_div");
			
			if (veSigDiv != null)
			{
				veSigDiv.style.display = (fragments[1] == '1') ? 'none' : 'block';
			}

			var vSubmitDiv = document.getElementById("ESCI_DCP_0_AttorneyUIDFK_Feedback_NoSubmit_div");
			
			if (vSubmitDiv != null)
			{
				vSubmitDiv.style.display = (fragments[2] == '1') ? 'none' : 'block';
			}
		}
	}

	function SpecialPreProcessingOfAttorneyDropList()
	{
		var vAtty = document.getElementById("ESCI_DCP_0_AttorneyUIDFK");
		
		if (vAtty != null)
		{
			vAtty.onchange = AttorneyWarnings;
			
			// add note child
			var vAttyLI = document.getElementById("ESCI_DCP_0_AttorneyUIDFK_div");
			
			if (vAttyLI != null)
			{
				var feedbackDiv1 = document.createElement('div');
				var divID1 = 'ESCI_DCP_0_AttorneyUIDFK_Feedback_NoeSig_div';
				feedbackDiv1.setAttribute('id',divID1);
				feedbackDiv1.className = 'feedbackClass';
				feedbackDiv1.style.display = 'none';
				feedbackDiv1.innerHTML = 'This attorney has not accepted eSignature agreement.';

				vAttyLI.appendChild(feedbackDiv1);

				var feedbackDiv2 = document.createElement('div');
				var divID2 = 'ESCI_DCP_0_AttorneyUIDFK_Feedback_NoSubmit_div';
				feedbackDiv2.setAttribute('id',divID2);
				feedbackDiv2.className = 'feedbackClass';
				feedbackDiv2.style.display = 'none';
				feedbackDiv2.innerHTML = 'This attorney has not granted you the privilege to submit their work online.';

				vAttyLI.appendChild(feedbackDiv2);
			}
		}
	}
	
	// custom code for attorney drop down list
	// if it's empty, tell the user why
	function checkForEmptyAttorneyDropList()
	{
		var vAtty = document.getElementById("ESCI_DCP_0_AttorneyUIDFK");
		
		if (vAtty != null)
		{
			// there is always the "blank" option
			if (vAtty.options.length <= 1)
			{
				// add note child
				var vAttyLI = document.getElementById("ESCI_DCP_0_AttorneyUIDFK_div");
				
				if (vAttyLI != null)
				{
					var feedbackDiv = document.createElement('div');
					var divID = 'ESCI_DCP_0_AttorneyUIDFK_Feedback_Empty_div';
					feedbackDiv.setAttribute('id',divID);
					feedbackDiv.className = 'feedbackClass';
					feedbackDiv.innerHTML = 'If no attorneys are available in this list it is because no users have granted you submit privileges on their work product.';

					vAttyLI.appendChild(feedbackDiv);
				}
			}
		}
	}
	
	function collapseEmptyNotes()
	{
		// prelim (all except loans)
		collapseEmptyNote('ESCI_DCP_0_PD_PD_0_BasicNote');
		collapseEmptyNote('ESCI_DCP_0_PD_PD_0_TaxNote');
		collapseEmptyNote('ESCI_DCP_0_PD_PD_0_RCNote');
		collapseEmptyNote('ESCI_DCP_0_PD_PD_0_PlatNote');
		collapseEmptyNote('ESCI_DCP_0_PD_PD_0_EasementNote');
		collapseEmptyNote('ESCI_DCP_0_PD_PD_0_ORDNote');
		collapseEmptyNote('ESCI_DCP_0_PD_PD_0_RightofWayNote');
		collapseEmptyNote('ESCI_DCP_0_PD_PD_0_EstatesNote');
		collapseEmptyNote('ESCI_DCP_0_PD_PD_0_MobileNote');
		collapseEmptyNote('ESCI_DCP_0_PD_PD_0_PriorNote');
		collapseEmptyNote('ESCI_DCP_0_PD_PD_0_DOTNote');
		collapseEmptyNote('ESCI_DCP_0_PD_PD_0_JudgmentNote');
		collapseEmptyNote('ESCI_DCP_0_PD_PD_0_UCCNote');
		collapseEmptyNote('ESCI_DCP_0_PD_PD_0_CertificationNote');
		collapseEmptyNote('ESCI_DCP_0_PD_PD_0_SurveyOccupancyAccessNote');

		// final
		collapseEmptyNote('ESCI_DCP_0_PD_PD_0_WarrantyDeedNote');
		collapseEmptyNote('ESCI_DCP_0_FinalMiscellaneousNote');
		collapseEmptyNote('ESCI_DCP_0_FinalDOTNote');


		// todo this method only supports N loans
		for (i = 0; i <= 6; i++)
		{
			// prelim
			collapseEmptyNote('ESCI_DCP_0_LN_LN_' + i + '_LoanNote');
		}
		collapseEmptyNote('ESCI_DCP_0_PD_PD_0_OwnersNote');
	}
	
	function collapseEmptyNote(idOfNote)
	{
		var vNote = document.getElementById(idOfNote);
		
		if (vNote != null)
		{
			// is note empty?
			if (vNote.value != "")
			{
				vNote.style.display = "inline";
			}
			else
			{
				vNote.style.display = "none";
			}
		}
	}
	
	function NoteShowHide(idOfNote)
	{
		var vNote = document.getElementById(idOfNote);
		
		if (vNote != null)
		{
			// is note empty?
			if (vNote.value != "")
			{
				vNote.style.display = "inline";
			}
			else 
			{
				// toggle visibility
				if (vNote.style.display == "inline")
				{
					vNote.style.display = "none";
				}
				else
				{
					vNote.style.display = "inline";
				}
			}
		}
	}
   
// <!--
		var g_strFocusControl;
		var g_nWaitTimerID;
		
	function getElementTop(Elem)
	{
        if(document.getElementById)
        {    
            var elem = document.getElementById(Elem);
        }
        else if (document.all)
        {
            var elem = document.all[Elem];
        }

        var yPos = elem.offsetTop;
        tempEl = elem.offsetParent;
        while (tempEl != null)
        {
              yPos += tempEl.offsetTop;
              tempEl = tempEl.offsetParent;
        }
        
        return yPos;
    }
    
    function ElementCanAcceptFocus(vC)
    {
		var vCanTakeFocus = false;
		
		if (vC != null)
		{
			// switch logic
			var vParentageVisible = true;
			
			var vControlToTest = vC;
			
			while ((vControlToTest.parentNode != null) && (vParentageVisible))
			{
				if (vControlToTest.parentNode.currentStyle != null)
				{
					if (vControlToTest.parentNode.currentStyle.display == "none")
					{
						vParentageVisible = false;
					}
					else
					{
						// work our way upwards
						vControlToTest = vControlToTest.parentNode;
					}
				}
				else
				{
					// work our way upwards
					vControlToTest = vControlToTest.parentNode;
				}
			}
			
			if (vParentageVisible)
			{
				if ((vC.tagName.toLowerCase() == "input") || (vC.tagName.toLowerCase() == "select"))
				{
					vCanTakeFocus = true;
				}
			}
		}
		
		return vCanTakeFocus;
    }
    
    function FocusToNextTabIndex(elementID, elementIndex, indexLimit)
    {
		if (elementIndex == 0)
		{
			elementID = "ESCI_" + elementID;
		}
		
		var vC = document.getElementById(elementID); 
		if (vC != null)
		{
			if (ElementCanAcceptFocus(vC))
			{
				vC.focus();
			}
		}
	}
	
		function CustomizeWaitDiv(strMainMessage, strDetailMessage)
		{
			var vMsg = document.getElementById("ESCI_WaitMessage"); 
			if (vMsg != null)
			{
				vMsg.innerHTML = strMainMessage;
			}
			var vMsgDetail = document.getElementById("ESCI_WaitDetailMessage"); 
			if (vMsgDetail != null)
			{
				vMsgDetail.innerHTML = strDetailMessage;
			}
		}
   
		function MakeWaitVisible(strMainMessage, strDetailMessage)
		{
			// currently we only do this for the smart form URL
			if (location.href.toLowerCase().indexOf("smartform.aspx") != -1)
			{
				// must scroll to top to see wait div and to scroll above selects we don't hide
				var myElement = $(document.body);
				var myFx = new Fx.Scroll(myElement, {duration: 500, transition: Fx.Transitions.Sine.easeOut,
					offset: { 'x': 0, 'y': 0 } });
				myFx.toTop();
				
				CustomizeWaitDiv(strMainMessage, strDetailMessage);
				
				g_nWaitTimerID = window.setTimeout(ForceWaitVisible, 500);
			}
		}  		
    
		function MakeWaitVisibleOnSave()
		{
			MakeWaitVisible("Saving...", "Please wait while MyTitleLab saves any changes you have made.");
		}  		

		function MakeWaitVisibleOnSubmit()
		{
			MakeWaitVisible("Submitting...", "Please wait while MyTitleLab saves any changes you have made and submits your work product.");
		}  
				
		function MakeWaitVisibleOnRevise()
		{
			MakeWaitVisible("Preparing to revise...", "Please wait while MyTitleLab unlocks your work product in preparation for revision.");
		}
		  		
		function MakeWaitVisibleOnReviseMore()
		{
			MakeWaitVisible("Expanding revision...", "Please wait while MyTitleLab loads your work product for full revision.");
		}  		

		function MakeWaitVisibleOnPreview()
		{
			MakeWaitVisible("Saving Changes and Generating Document...", "Please wait while MyTitleLab saves any changes you have made and generates the requested document.");
		}  		
		
		function MakeWaitVisibleOnReloadFromPrelim()
		{
			MakeWaitVisible("Transferring Key Fields from Work Product...", "Please wait while MyTitleLab transfers key fields from your work product to your form.");
		}  		
		
		function MakeWaitVisibleOnInstanceAdd()
		{
			MakeWaitVisible("Adding the requested section...", "Please wait while MyTitleLab adds the section you requested to your form.");
		}  		

		function ForceWaitVisible()
		{
			clearTimeout(g_nWaitTimerID);
			SetWaitVisibility(true);
		}  		
		
        function SetWaitVisibility(bVisible)
        {
            var vC = document.getElementById("ESCI_WaitDiv"); 
            if (vC != null)
            {
				if (bVisible)
				{
					vC.style.display = "block";
				}
				else
				{
					vC.style.display = "none";
				}
				
				var vBody = document.getElementById("preliminaryopinion");
				if (vBody != null)
				{
					vBody.className = bVisible ? "TurnTheLightsDown" : "PreliminaryBody";
				}
				
	        }
        }
        
        function NavBarDisplay(bDisplay)
        {
			if (bDisplay)
			{
				document.getElementById('preliminaryopinion').className='TurnTheLightsDown';
				document.getElementById('navigation_container').style.display = 'block';
			}
			else
			{
				document.getElementById('preliminaryopinion').className='PreliminaryBody';
				document.getElementById('navigation_container').style.display = 'none';
			}
			return false;
       }
 
         function RegisterFocus(strFocusID)
        {
	        g_strFocusControl = strFocusID;
	        
            var vC = document.getElementById("ScrollPosition"); 
            if (vC != null)
            {
				vC.value = strFocusID;
			}
			
			// we assume focus change means that the user made a change
			// TODO -- clicking the save button shouldn't cause trouble here but make sure
			ResetAutoSaveTimerOnActivity();
        }
        
//        var vCancellationHandlerExposed = false;
        
        function CancellationHandler()
        {
			var vbProceedWithPostBack = true;  // assume success
			
	        var vC = document.getElementById("PrelimTerminationPanel");
	        if (vC != null)
	        {
				if (vC.style.display == "none") 
				{
					vC.style.display = "block";
//					vCancellationHandlerExposed = true;

					// since we just display this part of the form we have to give the user a change to fill it out!
					vbProceedWithPostBack = false;
	            }
	            else
	            {
					// debugger;
					
					// validation
					var vReasonDropList = document.getElementById("ESCI_DCP_0_WorkProductTerminationReasonIDFK");
					var vReasonOtherTextBox = document.getElementById("ESCI_DCP_0_TerminationReasonOther");
					// note lack of instance root name
					var vFeedback = document.getElementById("PrelimTerminationFeedback");
					if ((vReasonDropList != null) && (vReasonOtherTextBox != null ) && (vFeedback != null ))
					{
						vFeedback.style.display = "none";
						if (vReasonDropList.selectedIndex < 0)
						{
							vFeedback.innerText = "You must select a reason for canceling this transaction.";
							vFeedback.style.display = "inline";
							vbProceedWithPostBack = false;
						}
						else if (vReasonDropList.options[vReasonDropList.selectedIndex].text == "")
						{
							vFeedback.innerText = "You must select a reason for canceling this transaction.";
							vFeedback.style.display = "inline";
							vbProceedWithPostBack = false;
						}
						else  if (vReasonDropList.options[vReasonDropList.selectedIndex].text.toLowerCase() == "other")
						{
							if (vReasonOtherTextBox.value.trim() == "")
							{
								vFeedback.innerText = "For the option 'Other' you must provide a reason for canceling this transaction.";
								vFeedback.style.display = "inline";
								vbProceedWithPostBack = false;
							}
						}
					}
	            }
	        }
	        
	        return vbProceedWithPostBack;
        }
       
        function DoIt(source)
        {
	        var t1 = document.getElementById("ExpertSystemControl_TextBoxCommand");
	        if (t1 != null)
	        {
	            t1.value = source;
	        }
        }
        
        function Alerter(strOutput)
        {
	        //alert(strOutput);
        }
        
        function JumpToSectionWithWildCard(strJumpPoint)
        {
            var strStartFragment = "";
            var strEndFragment = "";
            var vFirstWildCard = strJumpPoint.indexOf("*");
            var vLastWildCard = strJumpPoint.lastIndexOf("*");
            
            if (vFirstWildCard != -1)
            {
                strStartFragment = strJumpPoint.substr(0, vFirstWildCard);
            }
            if (vLastWildCard != -1)
            {
                strEndFragment = strJumpPoint.substr(vLastWildCard + 1, strJumpPoint.length - vLastWildCard - 1);
            }

            for (i = 0; i < document.all.length; i+=1)
            {
                if ((document.all[i].id.length >= strJumpPoint.length) &&
                        (-1 != document.all[i].id.indexOf(strStartFragment)) &&
                        (-1 != document.all[i].id.indexOf(strEndFragment)))
                {
                    ScrollToElement(document.all[i]);
                    break;
                }
            }
        }

        function JumpToNextSection(strJumpPoint)
        {
            var vJumpPoint = document.getElementById(strJumpPoint);
            if (null != vJumpPoint)
            {
                for (i = 0; i < document.all.length; i+=1)
                {
                    if (document.all[i].id == strJumpPoint)
                    {
                        var bFound = false;
                        var j = i + 1;
                        while ((!bFound) && (j < document.all.length))
                        {
                            var theElement = document.all[j];
                            if ((theElement.id != null) && (theElement.className != null) &&
                                 (theElement.className == vJumpPoint.className))
                            {
                                bFound = true;
                                ScrollToElement(theElement);
                            }
                            else
                            {
                                j += 1;
                            }
                        }
                        break;
                    }
                }
            }
        }
        function JumpToPreviousSection(strJumpPoint)
        {
            var vJumpPoint = document.getElementById(strJumpPoint);
            if (null != vJumpPoint)
            {
                for (i = 0; i < document.all.length; i+=1)
                {
                    if (document.all[i].id == strJumpPoint)
                    {
                        var bFound = false;
                        var j = i - 1;
                        while ((!bFound) && (j < document.all.length))
                        {
                            var theElement = document.all[j];
                            if ((theElement.id != null) && (theElement.className != null) &&
                                 (theElement.className == vJumpPoint.className))
                            {
                                bFound = true;
                                ScrollToElement(theElement);
                            }
                            else
                            {
                                j += -1;
                            }
                        }
                        break;
                    }
                }
            }
        }
        
        function ButtonClick(strButtonID)
        {
		    var btn = document.getElementById(strButtonID);
		    if (btn)
		    {
		        btn.click();
		    }
        }
        
		function FindYPosOfNamedElement(theNamedElement)
        {
			var selectedPosY = 0;
			
		    var vC = document.getElementById(theNamedElement);
		    if (vC)
		    {
				selectedPosY = FindYPos(vC);
		    }
            
            return selectedPosY;
        }

        function FindYPos(theElement)
        {
            var selectedPosY = 0;
                  
            while(theElement != null)
            {
                selectedPosY += theElement.offsetTop;
                theElement = theElement.offsetParent;
            }
            
            return selectedPosY;
        }
        
		function FindXPosOfNamedElement(theNamedElement)
        {
			var selectedPosX = 0;
			
		    var vC = document.getElementById(theNamedElement);
		    if (vC)
		    {
				selectedPosX = FindXPos(vC);
		    }
            
            return selectedPosX;
        }

        function FindXPos(theElement)
        {
            var selectedPosX = 0;
                  
            while(theElement != null)
            {
                selectedPosX += theElement.offsetLeft;
                theElement = theElement.offsetParent;
            }
            
            return selectedPosX;
        }
   
        function getScrollY()
        {
            var scrOfX = 0, scrOfY = 0;
            if( typeof( window.pageYOffset ) == 'number' )
             {
            //Netscape compliant
            scrOfY = window.pageYOffset;
            }
             else if( document.body && ( document.body.scrollTop ) )
              {
            //DOM compliant
            scrOfY = document.body.scrollTop;
            }
             else if( document.documentElement && ( document.documentElement.scrollTop ) )
              {
            //IE6 standards compliant mode
            scrOfY = document.documentElement.scrollTop;
            }
            return scrOfY;
        }   
        
        function getWindowHeight()
        {

            var y;
            if (self.innerHeight) // all except Explorer
            {
	            y = self.innerHeight;
            }
            else if (document.documentElement && document.documentElement.clientHeight)
	            // Explorer 6 Strict Mode
            {
	            y = document.documentElement.clientHeight;
            }
            else if (document.body) // other Explorers
            {
	            y = document.body.clientHeight;
            }
            
            return y;
         }
        
        
        function ScrollToElement(theElement)
        {
			if (typeof(theElement) == "string")
			{
				theElement = document.getElementById(theElement);
			}
			
			if (theElement == null)
			{
				theElement = document.getElementById('ESCI_' + theElement);
			}
			
			var myElement = $(document.body);
			// note how we prevent horizontal scrolling
			var myFx = new Fx.Scroll(myElement, {duration: 1000, transition: Fx.Transitions.Sine.easeOut,
				offset: { 'x': -1 * FindXPos(theElement), 'y': -200 } });
			myFx.toElement(theElement);
        }
        
        function SetInitialInstanceVisibility()
        {
			astrEfficientExpandersArray = vstrEfficientExpanders.split(',');
            for (i = 0; i < astrEfficientExpandersArray.length; i+=1)
            {
                if (astrEfficientExpandersArray[i] != null)
                {
					vstrExpanderID = "ESCI_" + astrEfficientExpandersArray[i];
					
					var vEfficientExpander = document.getElementById(vstrExpanderID);
					if (vEfficientExpander != null)
					{
//						alert(vstrExpanderID);
						
						var vstrInstanceID = vstrExpanderID.replace("_Expanded", "_instance");
						
						var vSection = document.getElementById(vstrInstanceID);
						if (vSection != null)
						{
							vSection.style.display = vEfficientExpander.checked ? "inline" : "none";
							
							if (!vEfficientExpander.checked)
							{
								// all children that are validators need to be disabled
								PropagateVisibilityToValidators(vSection, false);
							}
						}
					}
                }
            }
        }

		// note: vstrAddDeleteEventSource is not an absolute reference to a control ID, rather it contains
		//	 a regular expression of the form \d+ in which instance count substitutions are made until
		//   FindTargetElement either finds a collapsed instance that can be opened efficiently or 
		//   forces a postback to generate a new instance server-side
		function EfficientExpand(vstrAddDeleteEventSource, vnChildCount, vbExpand, bScroll)
		{
			var vbPostBack = false;
			
			// if expanding, see if we have an inactive element in this group that we could use
			// to "create" a new instance via exposure, if none, then we must roundtrip to create one
			if (vbExpand)
			{
				var vaFound = FindTargetElement(vstrAddDeleteEventSource, "Expanded", vnChildCount, false);
				
				var vInActiveActiveIndicator = vaFound[0];
				var vnActiveIndex = vaFound[1];
								
				if (vInActiveActiveIndicator != null)
				{
					var vstrResolvedID = vstrAddDeleteEventSource.replace('\d+', vnActiveIndex) + "instance";
					
					var vInActiveElement = document.getElementById(vstrResolvedID);
					if (vInActiveElement != null)
					{
//						alert("showing " + vstrResolvedID + " based on " + vInActiveActiveIndicator.id);

						vInActiveElement.style.display = "inline";
						vInActiveActiveIndicator.checked = true;
						
						// all children that are validators need to be enabled
						PropagateVisibilityToValidators(vInActiveElement, vbExpand);
						
						if (bScroll)
						{
							ScrollToElement(vInActiveElement);
						}
						
						vbPostBack = false;
					}
				}
				else
				{
					// tell the form to scroll to the new element that will be there after post back
					var vNewTarget = vstrAddDeleteEventSource.replace('\d+', vnChildCount) + "instance";
					RegisterFocus(vNewTarget);
					vbPostBack = true;
				}
			}
			else
			{
				var vstrExanderResolvedID = vstrAddDeleteEventSource + "Expanded";
				var vstrInstanceResolvedID = vstrAddDeleteEventSource + "instance";
				
				var vActiveElementExpander = document.getElementById(vstrExanderResolvedID);
				var vActiveElementInstance = document.getElementById(vstrInstanceResolvedID);
				if ((vActiveElementExpander != null) && (vActiveElementInstance != null))
				{
//					alert("hiding " + vstrInstanceResolvedID + " based on " + vstrExanderResolvedID);

					vActiveElementInstance.style.display = "none";
					vActiveElementExpander.checked = false;

					// all children that are validators need to be disabled
					PropagateVisibilityToValidators(vActiveElementInstance, vbExpand);
					
					// clear all inputs since we are collapsing
					ClearAllChildren(vActiveElementInstance);
					
					vbPostBack = false;
				}
			}
			
			return vbPostBack;
		}
		
		// e.g. root = "DCP_0_PD_PD_0_RestrictiveCovenant", 
		// suffix = "expanded", returns vElement
		function FindTargetElement(strRootName, strKeySuffix, nChildCount)
		{
			// init
			var vElement = null;
			var vVisibleElement = null;
			var vInvisibleElement = null;
			var vnMatchIndex = -1;

			// simple but inefficient for now
            var nElementIndex = 0;
            while (nElementIndex < nChildCount)
            {
				var vstrResolvedID = strRootName.replace('\d+', nElementIndex) + strKeySuffix;
				vstrResolvedID = vstrResolvedID.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
				vElement = document.getElementById(vstrResolvedID);
//				vElement = document.getElementById("ESCI_DCP_0_PD_PD_0_RC_RC_0_Expanded");
				
//				debugger;
				
                if (vElement != null)
                {
					if (vElement.checked)
					{
						vVisibleElement = vElement;
						vInvisibleElement = null;
						vnMatchIndex = -1;
					}
					else if (vInvisibleElement == null)
					{
						vInvisibleElement = vElement;
						vnMatchIndex = nElementIndex;
					}
                }
                else
                {
                }
                
                nElementIndex += 1;
            }
            
            // find first invisible after last visible
            if (vInvisibleElement != null)
            {
            }

			
			return [vInvisibleElement, vnMatchIndex];
		}
		

		function PropagateVisibilityToValidators(node, vbExpand)
		{
//			alert(node.id + " has " + node.children.length + " children");
			
			var vIndex = 0;
			for (;vIndex < node.children.length; vIndex += 1)
			{
				if (node.children[vIndex].id.indexOf("_Validator_") != -1)
				{
					// todo
//					alert(node.children[vIndex].id + " " + vbExpand);
					
					node.children[vIndex].enabled = vbExpand;
				}
				
				PropagateVisibilityToValidators(node.children[vIndex], vbExpand);
			}
		}
		
		function ClearAllChildren(node)
		{
			// alert(node.id + " has " + node.children.length + " children");
			
			var vIndex = 0;
			for (;vIndex < node.children.length; vIndex += 1)
			{
				if (node.children[vIndex].tagName.toLowerCase() == 'input')
				{
					node.children[vIndex].value = "";
				}
				else if (node.children[vIndex].tagName.toLowerCase() == 'select')
				{
					node.children[vIndex].selectedIndex = 0;
					
					// if this is a county, then set it to the form default
					if (node.children[vIndex].id.indexOf("ocale") != -1)
					{
						var vMasterCounty = document.getElementById('ESCI_DCP_0_PD_PD_0_LocaleIDFK'); 
					    
						if (null != vMasterCounty)
						{
							node.children[vIndex].selectedIndex = vMasterCounty.selectedIndex;
						}
					}
				}
				
				ClearAllChildren(node.children[vIndex]);
			}
		}
		

		// note: this should support two strControlChains formats:
		//		the more common: 'ESCI_DCP_0_UnderwriterIDFK-3892~0:ESCI_DCP_0_OtherUnderwriterCompanyName_div-2'
		//		the less common (no parentage): 'ESCI_DCP_0_RequirementsNotMet_div-1'
		// the less common is broken but you can hack around this by simply saying the controller is controlled by a label and setting the enable value s to #,0!
        function ToggleControl(strEventControl, strControlChains)
        {
// for debugging todo
//            if (strEventControl.indexOf("ntent") != -1)
//            {
//                w[6] = 0;
//            }

// debugger;
           
	        // strControlChains is of the form:  A_B_C_D1-1~2:A_B_C_D2_div-1~2[:A_B_C_D3_div-1~2],repeated....
	        Alerter("ToggleControl: Controller is " + strEventControl + "  controls chains are " + strControlChains);
        	
//	        var vP = document.getElementById(strParent); 
	        var strControlChainArray = strControlChains.split(",");
	        var nIndex = 0;
            // for every control chain, process visibility based on the event on the parent control
            while (nIndex < strControlChainArray.length)
            {
//	            var vController = vP;
//	            var strControlled = strControlChainArray[nIndex];
//	            Alerter("Processing control of " + strControlled);
//        		
	            var strControlArray = null;
	            // are there explicitly specified controller(s)?		
//	            if (-1 != strControlChainArray[nIndex].indexOf(':'))
//	            {
//                Alerter("sub controllers specified in " + strControlChainArray[nIndex]);
	            
                // in this case we walk the chain of controller(s) to determine status of child
                strControlArray = strControlChainArray[nIndex].split(":");
                // now split controller(s) and their enabling values
                var i = 0;
                var bVisible = true;
                // the logic applied is that if any control in the chain is disabled the child is
                // disabled too (remember, last item in array is the target, not a parent!)
                if (strControlArray.length > 1)
                {
                    var aChildAndEnablingValues = strControlArray[0].split("-");
                    Alerter("controller is " + aChildAndEnablingValues[0]);
                    var vGenerationalController = document.getElementById(aChildAndEnablingValues[0]);
                   
                    for(i = 1; (i < strControlArray.length) && (bVisible); i+=1)
                    {
	                    var aChildAndEnablingValues = strControlArray[i].split("-");
	                    var aControlEnablingArray = aChildAndEnablingValues[1].split("~");
            			
	                    // check values
	                    bVisible = IsEnabled(vGenerationalController, aControlEnablingArray);

	                    Alerter("parent: at index of " + i - 1 + ": " + vGenerationalController.ID + " computed visibility of " + bVisible);
	                    
    		            
	                    vGenerationalController = document.getElementById(aChildAndEnablingValues[0]);
                    }

                    var strTempTargetArray = strControlArray[strControlArray.length - 1].split("-");
                    Alerter("Setting " + strTempTargetArray[0] + " to visibility of " + bVisible);
                    SetVisibility(strTempTargetArray[0], bVisible);

					// collapse parent objects in effort to remove vertical space
					var vChild = document.getElementById(strTempTargetArray[0]);
                    if ((vChild != null) && (vChild.parentNode != null))
                    {
						if ((vChild.parentNode.tagName.toLowerCase() == 'li'))
						{
							vChild.parentNode.style.display = bVisible ? "list-item" : "none";
						}
						else
						{
							if ((vChild.parentNode.parentNode.tagName.toLowerCase() == 'li'))
							{
								vChild.parentNode.parentNode.style.display = bVisible ? "list-item" : "none";
							}
						}
                    }


                }

                nIndex = nIndex + 1;
            }
        }

	    function PropagateCountyChange()
	    {
		    var vController= document.getElementById('ESCI_DCP_0_PD_PD_0_LocaleIDFK'); 
		    
		    if (null != vController)
		    {
				var vSelectedIndex = vController.selectedIndex;

				var aSels = document.body.getElementsByTagName("select");

				for (i = 0; i < aSels.length; i += 1)
				{
					if (-1 != aSels[i].id.indexOf("ocale"))
					{
						aSels[i].selectedIndex = vSelectedIndex;
					}
				}
		    }
	    }	


        
        function IsEnabled(vController, strControlEnablingArray)
        {
	        var vIsEnabled = false;
        	
	        if (vController == null)
	        {
	            Alerter("Incoming controller to IsEnabled was null.");
	            return vIsEnabled;
	        }
       	
	        if ((vController.type == "checkbox"))
	        {
		         Alerter("Controller type is bool ");
	            // booleans can only have one enabling value
                Alerter(" comparing: " + vController.checked + " to " + strControlEnablingArray[0]);
	            if (vController.checked == strControlEnablingArray[0])
	            {
		            vIsEnabled = true;
	            }
	        }
	        else
	        {
	            // non-boolean so potentially more complex
	            var j = 0;
	            for (j = 0; (j < strControlEnablingArray.length) && (vIsEnabled == false); j += 1)
	            {
		            if (vController.selectedIndex != -1)
		            {
 		                Alerter(" comparing: " + vController.options[vController.selectedIndex].value + " to " + strControlEnablingArray[j]);
		                vIsEnabled = (vController.options[vController.selectedIndex].value == strControlEnablingArray[j])
    		            
			            Alerter(vIsEnabled);
		            }
	            }
	        }
        	
	        return vIsEnabled;        
        }
        
        function SetVisibility(strControl, bVisible)
        {
    	    Alerter(strControl + " visible: " + bVisible);
    	    // we may have a containing table row
            var vC = document.getElementById(strControl.replace(/div$/, "tr")); 
            // well, we didn't so go for the expected div
            if (vC == null)
            {
	            var vC = document.getElementById(strControl); 
                if (vC == null)
                {
	                Alerter("couldn't bind " + strControl + " or " + strControl.replace(/div$/, "tr"));
	            }
                else
                {
	                if (bVisible)
	                {
                        vC.style.display = "block";
	                }
	                else
	                {
                        vC.style.display = "none";
	                }
	           }
	        }
           else
            {
                if (bVisible)
                {
                    vC.style.display = "block";
                }
                else
                {
                   vC.style.display = "none";
                }
            }
        }
        
        function DLNavigate(strControlID, strURL)
        {
            Alerter ("strURL before: " + strURL);
            
            if (strURL.indexOf('{0}') != -1)
            {
	            var vDL = document.getElementById(strControlID); 
	            if (vDL != null)
	            {
                    Alerter(vDL.options[vDL.selectedIndex].value);
                    strURL = strURL.replace("\{0\}", vDL.options[vDL.selectedIndex].value);

                }
            }
            
            Alerter ("strURL after: " + strURL);

            // redirect
             window.location = strURL;
        }
        
        function Populate()
        {
            var nElementIndex = 0;
            while (nElementIndex < document.all.length)
            {
                if ((document.all[nElementIndex].tagName == "INPUT") && (document.all[nElementIndex].type == "text"))
                {
                    var strCurrentValue = "";
                    if (typeof(document.all[nElementIndex].value) != "undefined")
                    {
                        strCurrentValue = document.all[nElementIndex].value + " ";
                    }
                    
                    document.all[nElementIndex].value = strCurrentValue + nElementIndex;
                }
                
                nElementIndex += 1;
            }
        }
        
        function DisplayHelp(strInputControlID, strHelpRootID, bActivated)
        {
            // get the input control's position
            var cInput = document.getElementById(strInputControlID);
            var cHelpDiv = document.getElementById('ESCI_HelpDiv');
            
            if ((cInput != null) && (cHelpDiv != null))
            {
				// clear old help
				cHelpDiv.innerText = "";
				            
                var nTop = FindYPos(cInput);
 
                var vCombo = nTop + cHelpDiv.offsetHeight;
               
                // ideally we offset down the page since the help div is above the expert control
                if (cHelpDiv != null)
                {
                    nTop = nTop + cHelpDiv.offsetHeight;
                }
                
                Alerter("nTop = " + nTop);
                
                // we suppress display of help (e.g. for empty help items) by passing in an empty string
                // for the help id
                if (strHelpRootID != "")
                {
					var helpText = "";
					// set the top of this help div
					switch(strHelpRootID)
					{
						case "522":
						helpText = "Underwriter or agency name that issued the prior policy.";
						break;
						case "487":
						helpText = "Coverage amount of prior policy.  If there are multiple policies, enter the amount of the one with the highest coverage if it is within the 10 year period of issuance in order to be considered for a reissue rate.";
						break;
						case "521":
						helpText = "Please provide either policy number or file ID of the prior policy.";
						break;
						case "389":
						helpText = "Please indicate the current access method of the property, if known.";
						break;
						case "498":
						helpText = "If secured amount if not yet known, choose Yes.  NOTE: This does effect premium calculation for this preliminary.";
						break;
						case "881":
						helpText = "If you select Other then you will not be able to submit this work product online.  However, you can generate a PDF which you can print or electronically send to any title company you like.";
						break;
case "1324":
						helpText = "Populate this field in order to track who you have sent this work product to or leave blank but forefoot the ability to know who is underwriting this item.";
						break;
case "530":
						helpText = "Use this field to link your internal filing system with this work item.";
						break;
case "576":
						helpText = "This is the primary or sole county in which the property under consideration if located.  Future releases of MyTitleLab will offer support for multiple properties/multiple counties.";
						break;
case "586":
						helpText = "Enter the name(s) of the current vested owner here.";
						break;
case "497":
						helpText = "For short, easily typed or electronically available legal descriptions that can be copied and pasted, please provide the legal description herein.  Otherwise you can choose to provide the legal separately and simply scan and email or fax the legal to your local branch.";
						break;
case "541":
						helpText = "Please provide the full legal description of the property associated with this transaction.";
						break;
case "542":
						helpText = "Please provide the actual street address of the property associated with this transaction.";
						break;
case "639":
						helpText = "Click to add additional Restrictive Covenant(s)";
						break;
case "848":
						helpText = "This field may be edited for easy reference.";
						break;
case "660":
						helpText = "Click to delete additional Restrictive Covenant(s) ";
						break;
case "662":
						helpText = "Click to delete additional recordings of Restrictive Covenant";
						break;
case "574":
						helpText = "Click to add additional Plat";
						break;
case "842":
						helpText = "This field may be edited for easy reference.";
						break;
case "641":
						helpText = "Click to add additional easement(s)";
						break;
case "552":
						helpText = "Please provide name of entity for which easement is granted.";
						break;
case "619":
						helpText = "Please enter those instruments remaining on record and are considered a lien to the property for which you are certifying title.";
						break;
case "642":
						helpText = "Click to add additional Deed of Trust(s)";
						break;
case "843":
						helpText = "This field may be edited for easy reference.";
						break;
case "534":
						helpText = "Please provide name of lender for which this instrument is in favor of";
						break;
case "491":
						helpText = "Please provide the amount secured by this instrument";
						break;
case "1100":
						helpText = "Delete this instance of recordings";
						break;
case "498":
						helpText = "If secured amount if not yet known, choose Yes.  NOTE: This does effect premium calculation for this preliminary.";
						break;
case "643":
						helpText = "Click to add additional judgment(s)";
						break;
case "658":
						helpText = "Click to delete additional judgment(s)";
						break;
case "520":
						helpText = "Please provide the name or entity for which the judgment is in favor of";
						break;
case "645":
						helpText = "Click to add additional UCC Filing(s)";

						break;
case "661":
						helpText = "Click to delete additional UCC Filing(s)";
						break;
case "501":
						helpText = "Please choose.  Should the survey be attached, please email along with Preliminary.";
						break;
case "580":
						helpText = "Please indicate the current occupancy status of the property, if known.";
						break;
case "638":
						helpText = "Click to add additional Loan Coverage, if required, for this property";
						break;
case "655":
						helpText = "Click to delete loan coverage";
						break;
case "490":
						helpText = "Please complete with the secured amount of this loan";
						break;
case "492":
						helpText = "Please indicate if the funds will be fully disbursed.  If the answer is no, it will be assumed that the loan is construction and applicable exceptions will be added to the title commitment.";
						break;
case "600":
						helpText = "Please choose which best describes the borrower's financing";
						break;
case "614":
						helpText = "Please select ALTAs the lender requires by checkign the appropriate box(es)";
						break;
case "488":
						helpText = "Amount of coverage required by the buyer or sales price for this property";
						break;
case "499":
						helpText = "If amount is not yet known, choose TBD.  NOTE:  This does effect premium calculation for this preliminary.";
						break;
case "523":
						helpText = "Enter the name of the deceased person here.";
						break;
case "531":
						helpText = "Buyer if transaction is a sale and Borrower if this is a refinance and owners coverage is desired.";
						break;
case "593":
						helpText = "Please choose the use of the insured property, if known.";
						break;
case "644":
						helpText = "Click to add additional Delivery Instructions";
						break;
case "515":
						helpText = "Please complete with the email address or fax number of recipient";
						break;
case "514":
						helpText = "Recipient's Name";
						break;
case "656":
						helpText = "Click to delete routing instructions";
						break;
case "1220":
						helpText = "Use this section to include recorded documents such as agreements";
						break;
case "533":
						helpText = "Page Full Help";
						break;
case "509":
						helpText = "Entering page ranges (i.e. 45-50) is acceptable";
						break;
						case "833":
						helpText = "This field may be edited for easy reference.";
						break;
case "1346":
						helpText = "This field may be edited for easy reference.";
						break;
case "840":
						helpText = "This field may be edited for easy reference.";
						break;
case "549":
						helpText = "Entering page ranges (i.e. 45-50) is acceptable";
						break;
case "551":
						helpText = "Entering page ranges (i.e. 45-50) is acceptable";
						break;
case "1349":
						helpText = "Entering page ranges (i.e. 45-50) is acceptable";
						break;
case "705":
						helpText = "Entering page ranges (i.e. 45-50) is acceptable";
						break;
case "523":
						helpText = "Enter the name of the deceased";
						break;



						


					}
					
					if ((bActivated == true) && (helpText != ""))
					{
						cHelpDiv.innerText = helpText;
						cHelpDiv.style.display = "inline";
						cHelpDiv.style.position = "absolute";
						cHelpDiv.style.top = nTop;
						
//						// alert('Your resolution is '+screen.width+'x'+screen.height);
//						var nHelpAlignment = 885;
//						switch (screen.width)
//						{
//							case 800:
//								nHelpAlignment = 700;
//							break;
//							case 1024:
//								nHelpAlignment = 750;
//							break;
//							case 1152:
//								nHelpAlignment = 820;
//							break;
//							case 1280:
//								nHelpAlignment = 885;
//							break;
//							default:
//								// wild guess
//								nHelpAlignment = screen.width * 0.75;
//							break;
//						}
//						
//						cHelpDiv.style.left = nHelpAlignment;

						var vAlignmentDiv = document.getElementById('ESCI_DCP_0_UnboundDataCorePreliminaries2_div');
						if (vAlignmentDiv != null)
						{
							cHelpDiv.style.left = 10 + FindXPos(vAlignmentDiv) + vAlignmentDiv.offsetWidth;
						}
					}
					else
					{
						cHelpDiv.style.display = "none";
				    }
                }
            }
        }
        
        // called from valdiation summary error messages
        function HandleRelativeRedirect()
        {
            if (document.activeElement != null)
            {
                var realURL = document.activeElement.href;
                if (realURL != null)
                {
                    var nStartPos = realURL.indexOf('#');
                    if (nStartPos > -1)
                    {
                        realURL = realURL.substring(nStartPos + 1);
                    }
                    
                    var bBubble = false;
                    
                    if (realURL == "_top_")
                    {
                        window.scrollTo(0,0);
                    }
                    else if (realURL == "_bottom_")
                    {
                        window.scrollTo(0,document.body.offsetHeight);
                    }
                    else if (realURL == "_buttons_")
                    {
                        var vTarget = document.getElementById(realURL);
                        window.scrollTo(0, vTarget.offsetTop);
                    }
                    else
                    {
                        var bScroll = true;
                        var vTarget = document.getElementById(realURL);
                        if (vTarget == null)
                        {
                            vTarget = document.getElementById(realURL + "_div");
                        }
                        if (vTarget == null)
                        {
                            vTarget = document.getElementById(realURL + "_tr");
                        }
                        if (vTarget == null)
                        {
                            // this is expected when the tree nodes are expanded or collapsed
                            bScroll = false;
                            
                            if (realURL.indexOf("doPostBack") == -1)
                            {
                                bBubble = true;
                            }
                        }

                        if (bScroll)
                        {
                            ScrollToElement(vTarget);
                        }
                    }
                }
            }
            return bBubble;
        }
        
    
    
	function getCaretPosition (vCurrencyTextBox)
	{
		var vControlCurrencyTextBox = document.getElementById(vCurrencyTextBox);
		var nCaretPosition = 0;
		
		// ie
		if (document.selection)
		{
			vControlCurrencyTextBox.focus();
			var sel = document.selection.createRange();
			var nSelLength = document.selection.createRange().text.length;
			sel.moveStart('character', -vControlCurrencyTextBox.value.length);
			nCaretPosition = sel.text.length - nSelLength;
		}
		// other browser
		else
		{
			if (vControlCurrencyTextBox.selectionStart || vControlCurrencyTextBox.selectionStart == '0')
			{
				nCaretPosition = vControlCurrencyTextBox.selectionStart;
			}
		}
		
		return (nCaretPosition);
	}    
	
	function setCaretPosition(vCurrencyTextBox, nCaretPosition)
	{
		var vControlCurrencyTextBox = document.getElementById(vCurrencyTextBox);

		// ie
		if (document.selection)
		{
			// Set focus on the element
			vControlCurrencyTextBox.focus();

			// Create range
			var sel = document.selection.createRange();

			// reset selection scope else it is relative to last used
			sel.moveStart('character', -(vControlCurrencyTextBox.value.length));
			sel.moveEnd('character', -(vControlCurrencyTextBox.value.length));

			// Move selection start and end to desired position
			sel.moveStart('character', nCaretPosition);
			sel.moveEnd('character', 0);
			sel.select();
		}
		// other browser
		else
		{
			if (vControlCurrencyTextBox.selectionStart || vControlCurrencyTextBox.selectionStart == '0')
			{
				vControlCurrencyTextBox.selectionStart = nCaretPosition;
				vControlCurrencyTextBox.selectionEnd = nCaretPosition;
				vControlCurrencyTextBox.focus();
			}
		}
	}
    
	function OnKeyInCurrencyTextBox(vCurrencyTextBox, e)
	{
		var keynum = -1;
		// ie
		if (window.event)
		{
			keynum = e.keyCode;
		}
		// other
		else if (e.which)
		{
			keynum = e.which;
		}
		
		// if this is an arrow key just skip processing
		if ((keynum == 37) || (keynum == 39))
		{
			return;
		}
				
		var vControlCurrencyTextBox = document.getElementById(vCurrencyTextBox);
		
		var caretPos = getCaretPosition(vCurrencyTextBox);

		// remove all punctuation in order to determine actual root string value
		// commas.  Do this in a loop that lets us keep track of cursor position
		var strUserInput = vControlCurrencyTextBox.value;
		var nCurrentCharacter = 0;
		var bRemovedChar = false;
		while (nCurrentCharacter < strUserInput.length)
		{
			bRemovedChar = false;
			
			// dollar sign
			if ((strUserInput.charAt(nCurrentCharacter) != '0') &&
			    (strUserInput.charAt(nCurrentCharacter) != '1') &&
			    (strUserInput.charAt(nCurrentCharacter) != '2') &&
			    (strUserInput.charAt(nCurrentCharacter) != '3') &&
			    (strUserInput.charAt(nCurrentCharacter) != '4') &&
			    (strUserInput.charAt(nCurrentCharacter) != '5') &&
			    (strUserInput.charAt(nCurrentCharacter) != '6') &&
			    (strUserInput.charAt(nCurrentCharacter) != '7') &&
			    (strUserInput.charAt(nCurrentCharacter) != '8') &&
			    (strUserInput.charAt(nCurrentCharacter) != '9') &&
			    (strUserInput.charAt(nCurrentCharacter) != '.'))
			{
				strUserInput = strUserInput.substring(0, nCurrentCharacter) +
					strUserInput.substring(nCurrentCharacter + 1, strUserInput.length);
				bRemovedChar = true;
					
			}
			
			if (!bRemovedChar)
			{
				nCurrentCharacter += 1;
			}
			else
			{
				// adjust caret
				if (nCurrentCharacter < caretPos)
				{
					caretPos -= 1;
				}
			}
		}
		
		// make sure decimal part is two places long if there is one at all
	    var vDecimalPart = "";
		var vDecimalPosition = strUserInput.indexOf('.');
		if (-1 != vDecimalPosition)
		{
			// strip any additional decimal points
			vDecimalPart = strUserInput.substr(vDecimalPosition + 1);
			strUserInput = strUserInput.substr(0, vDecimalPosition);

			while (-1 != vDecimalPart.indexOf('.'))
			{
				var vDuplicateDecimalPosition = vDecimalPart.indexOf('.');
				if ((caretPos - strUserInput.length) > vDuplicateDecimalPosition)
				{
					caretPos -= 1;
				}
				vDecimalPart = vDecimalPart.replace(/\./, '');
			}

//			// process integer and fraction parts separately			
//			vDecimalPart = strUserInput.substr(vDecimalPosition);
//			strUserInput = strUserInput.substr(0, vDecimalPosition);

			vDecimalPart = '.' + vDecimalPart;
			
			// if we have too many digits after the decimal place then we must process
		    if (vDecimalPart.length = 3)
		    {
		        vDecimalPart = vDecimalPart.substr(0, 3);
		        
		        // caret will just be at end if we stripped off the char it was before
		        if (caretPos > (strUserInput.length + vDecimalPart.length))
		        {
					caretPos = strUserInput.length + vDecimalPart.length;
		        }
		    }
		    
		}	

		// now format as a dollar amount
		for(i = strUserInput.length - 3; i > 0 ; i -= 3)
		{
			strUserInput = strUserInput.substr(0, i) + ',' +
				strUserInput.substr(i, strUserInput.length - i);
				
			// adjust caret
			if (i < caretPos)
			{
				caretPos += 1;
			}
		} 

		// add currency symbol
		if ((strUserInput.length > 0) || (vDecimalPart.length > 0))
		{
			strUserInput = "$" + strUserInput + vDecimalPart;
			caretPos += 1;
		}
		
		// stuff back into the text box for the user to enjoy
		vControlCurrencyTextBox.value = strUserInput;
		
		// restore cursor
		setCaretPosition(vCurrencyTextBox, caretPos);
	}
	        
// -->

