//-------------------------
// InputLib.js
//-------------------------

var GCurrentElement;		//form element with focus


function SetFocusToFirstTextInput(AForm, ASelectText)
{
  var i = 0;
  
  if (AForm == undefined)
    AForm = document.forms[0];

  with (AForm)
    for (i=0; i < AForm.length; i++)
      if (elements[i].type == 'text' || elements[i].type == 'textarea' || elements[i].type == 'password')
      {
        try
        {
          elements[i].focus();
          SetCaretAtEnd(elements[i]);
        }
        catch (err)
        {
          continue;
        }
      
        if (ASelectText)
          elements[i].select();
          
        return;
      }

}       //SetFocusToFirstTextInput()


function SetFocusToEmptyTextInput(AForm)
{
  var i = 0;
  var sType;
  
  if (AForm == undefined)
    AForm = document.forms[0];

  with (AForm)
    for (i=0; i < AForm.length; i++)
    {
      sType = elements[i].type;
      if (sType == 'text' || sType == 'textarea' || sType == 'password')
        if (elements[i].value == '')
        {
          try
          {
            elements[i].focus();
          }
          catch (err)
          {
            continue;
          }
          
          return;
        }
      }

}       //SetFocusToEmptyTextInput()


function SetFocusToNextTextInput(AInputObject)
{
	var iNext;
	
	iNext = GetInputIndex(AInputObject) + 1;
	while (iNext < AInputObject.form.length)
	{
		with (AInputObject)
			if ((form[iNext].visibility != 'hidden' && form[iNext].display != 'none') && 
			    (elements[i].type == 'text' || elements[i].type == 'textarea' || elements[i].type == 'password'))
			{
				try
				{
					form[iNext].focus();
					form[iNext].select();
					return;
				}
				catch (Err)
				{
					iNext++;
				}
			}		
			else
				iNext++;
	}
	
}				//SetFocusToNextTextInput()


function SetFocusToFirstInput(AForm, ASelectText)
{
  var i = 0;
  
  if (AForm == undefined)
    AForm = document.forms[0];

  with (AForm)
    for (i=0; i < AForm.length; i++)
    {
      try
      {
        elements[i].focus();
      }
      catch (err)
      {
        continue;
      }
      
      if (ASelectText)
        if (elements[i].type == 'text' || elements[i].type == 'textarea')
          elements[i].select();

      break;          
    }

}       //SetFocusToFirstInput()


function SetFocusToNextInput(AInputObject)
{
	var iNext;
	
	iNext = GetInputIndex(AInputObject) + 1;
	while (iNext < AInputObject.form.length)
	{
		with (AInputObject)
			if (form[iNext].visibility != 'hidden' && form[iNext].style.display != 'none')
			{
				try
				{
					form[iNext].focus();
					try
					{
					  form[iNext].select();
					}
					catch (e)
					{
					}
					return;
				}
				catch (Err)
				{
					iNext++;
				}
			}		
			else
				iNext++;
	}
	
}				//SetFocusToNextInput()


function SetFocusToPreviousInput(AInputObject)
{
	var iPrevious;
	
	iPrevious = GetInputIndex(AInputObject) - 1;
	while (iPrevious > -1)
	{
		with (AInputObject)
			if (form[iPrevious].visibility != 'hidden' && form[iPrevious].display != 'none')
			{
				try
				{
					form[iPrevious].focus();
					form[iPrevious].select();
					return;
				}
				catch (Err)
				{
					iPrevious++;
				}
			}		
			else
				iPrevious++;
	}
	
}				//SetFocusToPreviousInput()


var GVerticalScrollOnFocus = 0;
function AttemptFocus(AInput, AVerticalScroll)
{

  if (isNaN(AVerticalScroll))
    AVerticalScroll = GVerticalScrollOnFocus;
    
	try
	{
		with (AInput)
		{
			focus();
			select();
			if (AVerticalScroll != 0)
			  window.scrollBy(0, AVerticalScroll);
		}
	}
	catch (err)
	{
	}
}


function GetFormDataString(AForm)
{
  //used to determine if a form's data has been modified by the user
  //See also IsFormEmpty()
  var i;
  var el = AForm.elements;
  var Result = '';
  
  function AddText(AInput)
  {
    Result += AInput.value;
  }
  
  function AddButton(AInput)
  {
    if (AInput.checked)
      Result += 'T';
  }
  
  function AddSelect(AInput)
  {
    if (AInput.length > 0)
      Result += string(AInput.selectedIndex) + string(AInput.length);
  }
  
  for (i = 0; i < el.length; i++)
    switch (el[i].type)
    {
      case 'text':
        AddText(el[i]);
        break;
      case 'textarea':
        AddText(el[i]);
        break;
      case 'file':
        AddText(el[i]);
        break;
      case 'checkbox':
        AddButton(el[i]);
        break;
      case 'radio':
        AddButton(el[i]);
        break;
      case 'select':
        AddSelect(el[i]);
        break;
    }
  
  
  return Result;

}       //GetFormDataString()
		
			
function IsFormEmpty(AForm)
{
  //used to determine if an initially empty form has been modified by the user
  //See also GetFormDataString()
  var i;
  var el = AForm.elements;
  
  for (i = 0; i < el.length; i++)
    switch (el[i].type)
    {
      case 'text':
        if (el[i].value > '')
          return false;
        break;
      case 'textarea':
        if (el[i].value > '')
          return false;
        break;
      case 'file':
        if (el[i].value > '')
          return false;
        break;
      case 'checkbox':
        if (el[i].checked)
          return false;
        break;
      case 'radio':
        if (el[i].checked)
          return false;
        break;
      case 'select':
        if (el[i].selectedIndex > -1)
          return false;
    }
  
  return true;

}       //IsFormEmpty()
		
			
function FormatCancelQuestion(AMainCaption)
{

  return '--- ' + AMainCaption + ' ---\n\n\n\nAre You Sure?\n\n';
}


function GetCancelQuestion()
{

  return FormatCancelQuestion("Cancel Editing");

}


function ConfirmCancelEditing(AOptionalFocusWindow)
{

  if (confirm(GetCancelQuestion()))
    CloseWindow();

}       //ConfirmCancelEditing()


function ClearInputs(AInputArray)
{

	for (var i=0; i < AInputArray.length; i++)
		if (AInputArray[i].value > '')
			AInputArray[i].value = '';
		
}					//ClearInputs()	


function DoDateOfBirthExit(ATextInput, ADaysInPastAllowed)
{
	//External Dependencies: DateTimeLib.js, StringLib.js, GeneralLib.js
	
	if (ADaysInPastAllowed == undefined)
	  ADaysInPastAllowed = 365.25 * 110;
	  
	with (ATextInput)
	{
		value = TrimSpaces(value);
		if (value > '')
		{
		  FormatInputDateOfBirth(ATextInput);
			if (ValidateDateString(value, ADaysInPastAllowed, 0) != errNone)
				HighlightBadInput(ATextInput)
			else
				UnHighlightInput(ATextInput);
		}
	}

}       //DoDateOfBirthExit()


function DoDateExit(ATextInput, ADaysInPastAllowed, ADaysInFutureAllowed)
{
	//External Dependencies: DateTimeLib.js, StringLib.js, GeneralLib.js

	with (ATextInput)
	{
		value = TrimSpaces(value);
		if (value > '')
		{
			FormatInputDate(ATextInput);
			if (ValidateDateString(value, ADaysInPastAllowed, ADaysInFutureAllowed) != errNone)
				HighlightBadInput(ATextInput)
			else
				UnHighlightInput(ATextInput);
		}
	}
}		//DoDateExit()


function DoPagerExit(AInputObject)
{
	with (AInputObject)
	{
		value = TrimSpaces(value);
		if (value > '')
		{
			AInputObject.value = FormatPager(AInputObject.value);
			if (IsValidPager(AInputObject.value))
				UnHighlightInput(AInputObject)
			else
				HighlightBadInput(AInputObject);
		}
	}
}				//DoPagerExit()


function DoZipCodeExit(AInputObject, ARequireExtendedZip)
{
	with (AInputObject)
	{
		value = TrimSpaces(value);
		if (value > '')
		{
			value = FormatZipCode(value);
			if (IsValidZip(value, ARequireExtendedZip))
				UnHighlightInput(AInputObject)
			else
				HighlightBadInput(AInputObject);
		}
	}
}


function DoSsnExit(AInput)
{
	with (AInput) 
	{
		value = TrimSpaces(value);
		if (AInput.value > '')
		{
			value = FormatSSN(value, true);
			if (IsValidSSN(value))
				UnHighlightInput(AInput)
			else
				HighlightBadInput(AInput);
		}
	}
}


function DoSfExtensionExit(AInput)
{
	with (AInput)
	{
		if (value > '')
		{
			value = FormatSfExtension(StripChar(value, ' '), true);
			if (IsValidSfExtension(value))
				UnHighlightInput(AInput)
			else
				HighlightBadInput(AInput);
		}
	}
}


function DoExtensionExit(AInput)
{
	with (AInput)
		if (value > '')
			value = FormatExtension(StripChar(value, ' '), true);
}


function DoNameExit(AInputObject)
{
	FormatMonoCaseToMixedCase(AInputObject);
}


function DoCompanyNameExit(AInputObject)
{
  with (AInputObject)
  {
    value = TrimSpaces(value);
    if (value > '' && ! IsMixedCase(value))
        value = GetCompanyNameCasing(value, 3);
  }
}


function DoJobTitleExit(AInputObject)
{
  with (AInputObject)
  {
    value = TrimSpaces(value);
    if (value > '' && ! IsMixedCase(value))
        value = GetJobTitleCasing(value);
  }
}


function DoSpecialtyExit(AInputObject)
{
  with (AInputObject)
  {
    value = TrimSpaces(value);
    if (value > '')
      if (! IsMixedCase(value))
        value = GetSpecialityCasing(value);
  }
}


function DoMedicalProcedureNameExit(AInputObject)
{

	with (AInputObject)
	{
		value = TrimSpaces(value);
		
		if (value > '')
		{
	    value = GetMedicalProcedureCasing(value);
	    if (Pos('.', value) > -1)
	      value = StripChar('.', value);
	  }
	}

}       //DoMedicalProcedureNameExit()


function DoMedicalProcedureNameExitLazy(AInputObject)
{

  with (AInputObject)
    if (value.toLowerCase() == value)
      DoMedicalProcedureNameExit(AInputObject)
    else
    {
      value = TrimSpaces(value);
      if (Pos('.', value) > -1)
        value = StripChar('.', value);
    }
    
}         //DoMedicalProcedureNameExitLazy()


function DoPersonalNameExit(AInputObject, AIsLastName)
{
  FormatPersonalNameToMixedCase(AInputObject, AIsLastName);
  
  with (AInputObject)
	  if (Pos('.', value) > -1)
	    value = StripChar(AInputObject.value, '.');
}


function DoPersonalNameExitConservative(AInputObject, AIsLastName)
{
  FormatMonoCasePersonalNameToMixedCase(AInputObject, AIsLastName);

	with (AInputObject)
	  if (Pos('.', value) > -1)
	    value = StripChar(AInputObject.value, '.');
}


function DoPersonalNameExitLazy(AInputObject, AIsLastName)
{
  FormatLowerCasePersonalNameToMixedCase(AInputObject, AIsLastName);

	with (AInputObject)
	  if (Pos('.', value) > -1)
	    value = StripChar(AInputObject.value, '.');
}


function DoPhysicianNameExit(AInputObject)
{
	if (AInputObject.value > '')
	{
	  DoPersonalNameExit(AInputObject, true);
	  AInputObject.value = GetUpperCaseMedicalCredentials(AInputObject.value);
	  AInputObject.value = GetDoctoralCasing(AInputObject.value, GetStandardDelimiters());
	}
}


function DoRequestedByExit(AInputObject)
{
  if (AInputObject.value > '')
    if (GetWordCount(AInputObject.value, ' .,;') > 1)
    {
	    DoPersonalNameExitConservative(AInputObject, true);
	    AInputObject.value = GetUpperCaseMedicalCredentials(AInputObject.value);
	  }
	  else
	    DoPersonalNameExitConservative(AInputObject, true);
} 


function DoNameExitMedical(AInputObject)
{
	with (AInputObject) 
		value = TrimSpaces(value);
		
	FormatLowerCaseToMixedCaseMedical(AInputObject);
}


function DoMedicalGroupNameExit(AInputObject)
{
	FormatMonoCaseToMedicalGroupNameCase(AInputObject);
}


function DoMedicalGroupNameExitLazy(AInputObject)
{
  FormatLowerCaseToMedicalGroupNameCase(AInputObject);
}

  
function DoPhoneExit(AInputObject, AAutoAreaCode)
{
	with (AInputObject)
	{
		value = FormatPhone(StripChar(value, ' '));
		
		if (value > '')
			if (value.length == 4 && IsDigitString(value))
			{
			  value = '1-' + value;
				UnHighlightInput(AInputObject);
			}
			else
			if (value.length == 5 && IsDigitString(value))
			{
			  value = value.substr(0, 1) + "-" + value.substr(1);
				UnHighlightInput(AInputObject);
			}
			else
			if (IsValidPhone(value) || IsValidSfExtension(value))
			{
				UnHighlightInput(AInputObject);
				if (AAutoAreaCode && value.length == 8)
				  value = '918-' + value;
			}
			else
				HighlightBadInput(AInputObject);
	}

}				//DoPhoneExit()


function DoNumericExit(AInputObject)
{

	with (AInputObject)
	{
		value = TrimSpaces(value);
		
		if (value > '')
			if (IsValidNumber(value))
				UnHighlightInput(AInputObject)
			else
				HighlightBadInput(AInputObject);
	}

}				//DoNumericExit()


function DoNumericExitRangeCheck(AInputObject, ARangeStart, ARangeEnd)
{
	DoNumericExit(AInputObject);
	with (AInputObject)
	  if (value > '')
	    if (Number(value) < Number(ARangeStart) || Number(value) > Number(ARangeEnd))
	      HighlightBadInput(AInputObject);
	    else
	      UnHighlightInput(AInputObject);
}


function DoAddressExit(AInputObject)
{
	FormatMonoCaseToMixedCase(AInputObject);
}


function DoCityExit(AInputObject)
{

  FormatMonoCaseToMixedCase(AInputObject);
  
  if (IsCityInOklahoma(AInputObject.value))
    AInputObject.value = GetMicroDictionaryCasing(AInputObject.value, GetOklahomaCities(), GetStandardDelimiters())
  else
	  AInputObject.value = ConvertLastNameCasingForSpecialCases(AInputObject.value);
}


function DoHelpListCityExit(AInputObject)
{
  FormatMonoCaseToMixedCase(AInputObject);
}


function DoStateExit(AInputObject)
{
	with (AInputObject)
	{
		value = TrimSpaces(value);
		if (value > '')
		  if (value.length == 2)
			  value = value.toUpperCase()
	    else 
	      if (value.length > 2)
	        value = value.charAt(0).toUpperCase() + value.substr(1).toLowerCase();
	}
}


function DoCostCenterExit(AInput)
{
	with (AInput) 
	{
		value = TrimSpaces(value);
		if (value > '')
		{
			value = FormatCostCenter(value);
			if (! IsValidCostCenter(value))
				HighlightBadInput(AInput)
			else
				UnHighlightInput(AInput);
		}
	}
}


function DisableObjectArray(AObjectArray)
{
	for (var i=0; i < AObjectArray.length; i++)
		AObjectArray[i].disabled = true;
}


function EnableObjectArray(AObjectArray)
{
	for (var i=0; i < AObjectArray.length; i++)
		AObjectArray[i].disabled = false;
}


function GetInputIndex(AInputObject)
{
	var i;
	
	with (AInputObject)
		for (i=0; i < form.length; i++)
			if (form[i] == AInputObject)
				return i;
				
	return -1;		//should never reach this point
}


function GetInputsPopulatedCount(AInputArray)
{
	var	iResult = 0;

	for (var i=0; i < AInputArray.length; i++)
		if (AInputArray[i].value > '')
			iResult++;	
		
	return iResult;			
}


function GetSelectedRadioButtonIndex(ARadioButtonArray)
{
	if (ARadioButtonArray[0])		//check to see if this is an array
	{
		for (var i=0; i < ARadioButtonArray.length; i++)
			if (ARadioButtonArray[i].checked)
				return i;
	}
	else
		return -2;			//call makes no sense when ARadioButton is not an array
	
	return -1;			//nothing is checked
}


function GetSelectedRadioButton(ARadioButtonArray)
{
	return ARadioButtonArray[GetSelectedRadioButtonIndex(ARadioButtonArray)];
}


function GetSelectedCheckBoxValues(ACheckBoxArray)
{
  var i;
  var Result = new Array;
  
  for (i = 0; i < ACheckBoxArray.length; i++)
    if (ACheckBoxArray[i].checked)
      Result[Result.length] = ACheckBoxArray;
      
  return Result;
}


function GetSelectedCheckBoxCount(ACheckBoxArray)
{
  var Result = 0;
  var i;
  
  for (i = 0; i < ACheckBoxArray.length; i++)
    if (ACheckBoxArray[i].checked)
      Result++;

  return Result;
}


function HasEntries(ATextControlArray)
{
	var i;
	
	for (i=0; i < ATextControlArray.length; i++)
		if (ATextControlArray[i].value > '')
			return true;
			
	return false;
}


function HasDuplicateEntry(ATextControlArray)
{
	return PosDuplicateEntry(ATextControlArray) > -1;
}


function PosDuplicateEntry(ATextControlArray)
{
	var arStrings = new Array(ATextControlArray.length);
	var i;
	
	for (i=0; i < arStrings.length; i++)
		arStrings[i] = ATextControlArray[i].value;
		
	return PosDuplicateString(arStrings, 0); 
}


function HighlightBadInput(ATextInput)
{
	with (ATextInput)
	{
		style.color = 'red';
		if (style.backgroundColor.toLowerCase() == 'red')
		  style.backgroundColor = 'white';
	}
}


function UnHighlightInput(ATextInput)
{	
	with (ATextInput)
	{
		style.color = 'black';
		if (style.backgroundColor.toLowerCase() == 'black')
		  style.backgroundColor = 'white';
	}
}


function UnHighlightInputx(ATextInput, ADefaultFontColor)
{
	ATextInput.style.color = ADefaultFontColor;
}


function FormatInputDate(AInputObject)
{
	//External Dependencies: DateTimeLib.js, StringLib.js
	
	var	sNewDate;
	sNewDate = DelimitDateString(AInputObject.value);
	
	if (sNewDate > '')
	{
		sNewDate = ExpandDateString(sNewDate);
		
		if (IsValidDateString(sNewDate))
			AInputObject.value = sNewDate;
	}
}


function FormatInputDateOfBirth(AInputObject)
{
	//External Dependencies: DateTimeLib.js, StringLib.js
	
	var	sNewDate;
	sNewDate = DelimitDateString(AInputObject.value);
	
	if (sNewDate > '')
	{
		sNewDate = ExpandDOBString(sNewDate);
		
		if (IsValidDateString(sNewDate))
			AInputObject.value = sNewDate;
	}
}					


function FormatToUpperCase(AInputObject)
{
	with (AInputObject)
		value = TrimSpaces(value).toUpperCase();
}       


function FormatPersonalNameToMixedCase(AInputObject, AIsLastName)
{
	with (AInputObject)
	{
		value = TrimSpaces(value);
		if (value > '') 
	    value = GetPersonalNameCasing(value, AIsLastName);
	}
}        

  
function FormatLowerCasePersonalNameToMixedCase(AInputObject, AIsLastName)
{
	with (AInputObject)
	{
		value = TrimSpaces(value);
		if (value > '') 
			if (value.toLowerCase() == value)
			  value = GetPersonalNameCasing(value, AIsLastName);
	}
}        

  
function FormatMonoCasePersonalNameToMixedCase(AInputObject, AIsLastName)
{
	with (AInputObject)
	{
		value = TrimSpaces(value);
		if (value > '') 
			if (! IsMixedCase(value))
			  value = GetPersonalNameCasing(value, AIsLastName);
	}
}      

  
function FormatLowerCaseToMixedCase(AInputObject)
{
	with (AInputObject)
	{
		value = TrimSpaces(value);
		if (value.toLowerCase() == value)
			value = GetCapitalizedWords(value);
	}
}


function FormatLowerCaseToMixedCaseMedical(AInputObject)
{
	with (AInputObject)
	{
		value = TrimSpaces(value);
		if (value.toLowerCase() == value)
			value = GetCapitalizedWordsMedical(value)
		else
			value = GetUpperCaseMedicalCredentials(value);
	}
}


function FormatMonoCaseToMixedCase(AInputObject)
{
	with (AInputObject)
	{
		value = TrimSpaces(value);
		
		if (value > '')
		  if (! IsMixedCase(value))		//don't mess with case, if string is already mixed case
			  value = GetCapitalizedWords(value);
	}
}


function FormatMonoCaseToTitleCase(AInputObject)
{
	with (AInputObject)
	{
		value = TrimSpaces(value);
		if (value > '')
		  if (! IsMixedCase(value))		  //don't mess with case, if string is already mixed case
			  value = GetTitleCasing(value);
	}
}


function FormatLowerCaseForDiagnosis(AInputObject)
{
	with (AInputObject)
	{
		value = TrimSpaces(value);
		if (value > '')
		  if (value == value.toLowerCase())		        //don't mess with case, unless it is all lower case
		    value = GetDiagnosisCasing(value);
	}
}


function FormatLowerCaseForLabTest(AInputObject)
{
	with (AInputObject)
	{
		value = TrimSpaces(value);
		if (value > '')
		  if (value == value.toLowerCase())		        //don't mess with case, unless it is all lower case
		    value = GetLabTestCasing(value);
	}
}


function FormatMonoCaseToMedicalGroupNameCase(AInputObject)
{
	with (AInputObject)
	{
		value = TrimSpaces(value);
		
		if (! IsMixedCase(value))		  //don't mess with case, if string is already mixed case
			value = GetMedicalGroupNameCasing(value);
	}
}


function FormatToInsuranceCasing(AInputObject, ACapFlags)
{
	//-- Except for the use of the micro dictionary, this is casing by word;
	//-- That is, words which are mono cased are candidates for capping, dependent upon ACapFlags
	//-- ACapFlags - 1=Lower Case Words, 2=Upper Case String, 3=Lower Case Words or Upper Case String
	
	if (AInputObject.value > '') 
	  with (AInputObject)
	    value = GetInsuranceCasing(value, ACapFlags);
}


function FormatLowerCaseToMedicalGroupNameCase(AInputObject)
{
	with (AInputObject)
	{
		value = TrimSpaces(value);
		
		if (value == value.toLowerCase())
			value = GetMedicalGroupNameCasing(value);
	}
}


function DoStreetAddressExit(AInputObject)
{
  var s = AInputObject.value;
  
  s = TrimSpaces(StripChar(s, '.'));
  
  if (s != AInputObject.value)
    AInputObject.value = s;
    
  FormatMonoCaseToStreetAddressCase(AInputObject);
}


function FormatMonoCaseToStreetAddressCase(AInputObject)
{
  with (AInputObject)
  {
    value = TrimSpaces(value);
    if (value > '' && ! IsMixedCase(value))
      value = GetStreetAddressCasing(value);
  }
}


function HandleOptionalBookmark(AOptionalBookmark)
//--------------------------------------------------------------------------------
// AOptionalBookmark can be:
//    1) the name or id of an anchor tag (book mark), in the form of a string. 
//    2) a control which is visible and enabled, in the form of an object reference.
//    3) null. The argument is optional.
//--------------------------------------------------------------------------------
{
	if (AOptionalBookmark)
	{
	  try
	  {
	    AOptionalBookmark.focus();
	  }
	  catch (err)
	  {
	    if (AOptionalBookmark.toString() > '')
	    {
        try
        {  	    
	        if (AOptionalBookmark.substr(0, 1) != '#')
	          AOptionalBookmark = '#' + AOptionalBookmark;

		      window.location.replace(AOptionalBookmark);
		    }
        catch (err)
        {
          return;
        }
        
		  }
	  }
	}       //if (AOptionalBookmark)
	
}         //HandleOptionalBookmark


function RequireInputNumber(AInputObject, AInputLabel, AMinimum, AMaximum, AOptionalBookmark)
{
//-------------------------------------------------------------------------------
// Range checking can be turned off by passing -1 in both AMinimum and AMaximum
// AInputObject

	with (AInputObject)
	{
	
	  value = TrimSpaces(AInputObject.value);
	  
	  if (value == '') 
	  { 
	    alert(AInputLabel + ' is a required data element. Please input this item.');
      HandleOptionalBookmark(AOptionalBookmark);

      if (AOptionalBookmark)
        AttemptFocus(AInputObject, 0)
      else								
        AttemptFocus(AInputObject);
        
	    return false;
	  }
	  else
	    return ValidateInputNumber(AInputObject, AInputLabel, AMinimum, AMaximum, AOptionalBookmark);
	    
	}       //with...

}       //RequireInputNumber()


function ValidateInputNumber(AInputObject, AInputLabel, AMinimum, AMaximum, AOptionalBookmark)
{
//-------------------------------------------------------------------------------
// Range checking can be turned off by passing -1 in both AMinimum and AMaximum
// AInputObject

	with (AInputObject)
	{

	  value = TrimSpaces(AInputObject.value);
	  
	  if (value == '') 
	    return true;
	  else
	  if (! IsValidNumber(value))
	  {
	    alert('Invalid number in input. Please correct ' + AInputLabel + '.');
      HandleOptionalBookmark(AOptionalBookmark);								
      
      if (AOptionalBookmark)
        AttemptFocus(AInputObject, 0)
      else								
        AttemptFocus(AInputObject);
	    
	    return false;
	  }
	  else
	  if (! (AMinimum == -1 && AMaximum == -1))
	  {
	    if (Number(value) < Number(AMinimum) || Number(value) > Number(AMaximum))
	    {
        alert('Number out of range. ' + AInputLabel + ' must be between ' +
          AMinimum + ' and ' + AMaximum + '.')
        HandleOptionalBookmark(AOptionalBookmark);
        
        if (AOptionalBookmark)
          AttemptFocus(AInputObject, 0)
        else								
          AttemptFocus(AInputObject);
	      
        return false;
      }
      else
        return true;
    }
    return true;
        
	}     //with...

}       //ValidateInputNumber()


function RequireEMailInput(AInputObject, AInputLabel, AOptionalBookmark)
{
  
  if (! RequireInputText(AInputObject, AInputLabel, 8, -1, AOptionalBookmark))
    return false
  else
  if (! IsValidEMail(AInputObject.value))
  {
    alert('Email Input is not valid.' + CrLfx(2) +
		  'The format of "' + AInputLabel + '" must be similar to this --> abc@xyz.com"' + CrLfx(2) +
		    'For Example: SammySample@gmail.com' + CrLfx(2));
    HandleOptionalBookmark(AOptionalBookmark);								
							
    if (AOptionalBookmark)
      AttemptFocus(AInputObject, 0)
    else								
      AttemptFocus(AInputObject);
		
		return false;
  }
  
  return true;

}           //RequireEMailInput()


function RequireInputText(AInputObject, AInputLabel, AMinimumLength, AExactLength, AOptionalBookmark)
{
  var Result;
  
	AInputObject.value = Trim(AInputObject.value);
	
	if (AMinimumLength > 0)
		Result = (AInputObject.value.length >= AMinimumLength)
	else
		Result = true;
		
	if (AExactLength > 0)
		Result = (AInputObject.value.length == AExactLength) && Result;

	Result = ((AInputObject.value) > '') && Result;
		
	if (Result)
		return true
	else
	{
		if (AInputObject.value > '' && AMinimumLength > 0)
			alert('A required input has too little data.' + CrLfx(2) +
							'"' + AInputLabel + '" must be at least ' + AMinimumLength + ' characters.' +
							CrLfx(2))
		else
		if (AInputObject.value > '' && AExactLength > 0)
			alert('A required input has an incorrect length.' + CrLfx(2) +
							'"' + AInputLabel + '" must be ' + AExactLength + ' characters.' +
							CrLfx(2))
		else
			alert('A required input is missing.' + CrLfx(2) +
							'"' + AInputLabel + '" is a required data element.' +
							CrLfx(2));
							
    
    HandleOptionalBookmark(AOptionalBookmark);
    
    if (AOptionalBookmark)
      AttemptFocus(AInputObject, 0)
    else								
      AttemptFocus(AInputObject);

		return false;
	} 
}				//RequireInputText()


function ValidateInputText(AInputObject, AInputLabel, AMinimumLength, AExactLength, AOptionalBookmark)
{
	//---------------------------------------------------------
	// This function validates non- required text input. If
	// the input is empty, validation is ok.
	//---------------------------------------------------------
	var Result;
	
	AInputObject.value = TrimSpaces(AInputObject.value);
	
	if (AMinimumLength > 0)
		Result = (AInputObject.value.length >= AMinimumLength)
	else
		Result = true;
		
	if (AExactLength > 0)
		Result = (AInputObject.value.length == AExactLength) && Result;
	
	Result = ((AInputObject.value) == '') || Result;
		
	if (Result)
		return true
	else
	{
		if (AMinimumLength > 0)
			alert('An input has too little data.' + CrLfx(2) +
							'"' + AInputLabel + '" must be at least ' + AMinimumLength + ' characters.' +
							CrLfx(2))
		else
		if (AExactLength > 0)
			alert('An input has an incorrect length.' + CrLfx(2) +
							'"' + AInputLabel + '" must be ' + AExactLength + ' characters.' +
							CrLfx(2));
							
    HandleOptionalBookmark(AOptionalBookmark);

    if (AOptionalBookmark)
      AttemptFocus(AInputObject, 0)
    else								
      AttemptFocus(AInputObject);

		return false;
	} 
}				//ValidateInputText()


function RequireInputDigits(AInputObject, AInputLabel, AMinimumLength, AExactLength, AOptionalBookmark)
{
	if (! RequireInputText(AInputObject, AInputLabel, AMinimumLength, AExactLength))
		return false
	else
	{
		if (AInputObject.value.length == 0)
			return true
		else
			if (! IsDigitString(AInputObject.value))
			{
				alert(AInputLabel + ' must be all digits. Please correct the ' +
						'entry.');
						
        HandleOptionalBookmark(AOptionalBookmark);

        if (AOptionalBookmark)
          AttemptFocus(AInputObject, 0)
        else								
          AttemptFocus(AInputObject);
          
				return false;
				
			}
			else
				return true;
	}
	
}			//RequireInputDigits()


function RequireSelect(ASelectObject, AObjectLabel, AOptionalBookmark)
{

	if (TrimSpaces(ASelectObject.value) == '')
	{
		try
		{
      HandleOptionalBookmark(AOptionalBookmark);
      ASelectObject.focus();
		}
		catch (Error)
		{
			//do nothing
		}
			
		alert(AObjectLabel + 
						' is a required input. Please make a selection from the list.' + CrLfx(2));
		return false;
	}
	else
		return true;
			
}				//RequireSelect()

	
function RequireRadioButtons(ARadioButtonArray, AButtonsLabel, AOptionalBookmark)
//------------------------------------------------------------------
// See HandleOptionalBookmark() AOptionalBookmark help.
//------------------------------------------------------------------
{
	for (i=0; i < ARadioButtonArray.length; i++)
	{
		if (ARadioButtonArray[i].checked)
			return true;
	}
	
	alert('Required Entry missing.' + CrLfx(2) + 
							'Please make a selection for "' + AButtonsLabel + '".' + CrLfx(2));

  HandleOptionalBookmark(AOptionalBookmark);
							
  if (AOptionalBookmark)
    AttemptFocus(ARadioButtonArray[0], 0)
  else								
    AttemptFocus(ARadioButtonArray[0]);

	return false;

}					//RequireRadioButtons()


function RequireRadioButtonsCB(ARadioButtonArray, AFunction, AArgument, AButtonsLabel, AOptionalBookmark)
//----------------------------------------------------------------------------------------
// AFunction is a function object
// AArgument is an argument to pass to AFunction; if there are no arguments, pass null
// AArgument can be of any type, including an array
// Example:
//  if (! RequireRadioButtonsCB(rbChooseTypePelvis, MyFunction, arg1, 'Choose Type - Pelvis', chkPelvis))
//----------------------------------------------------------------------------------------
{
	for (i=0; i < ARadioButtonArray.length; i++)
	{
		if (ARadioButtonArray[i].checked)
			return true;
	}
	
	//call back function invoked if no buttons are checked; called before other actions
	AFunction(AArgument);
	
	alert('Required Entry missing.' + CrLfx(2) + 
							'Please make a selection for "' + AButtonsLabel + '".' + CrLfx(2));

  HandleOptionalBookmark(AOptionalBookmark);
							
  if (AOptionalBookmark)
    AttemptFocus(ARadioButtonArray[0], 0)
  else								
    AttemptFocus(ARadioButtonArray[0]);

	return false;

}					//RequireRadioButtonsCB()


function RequireCheckBoxes(ACheckBoxArray, AButtonsLabel, AOptionalBookmark)
//------------------------------------------------------------------
// See HandleOptionalBookmark() AOptionalBookmark help.
//------------------------------------------------------------------
{

	for (i=0; i < ACheckBoxArray.length; i++)
	{
		if (ACheckBoxArray[i].checked)
			return true;
	}
	
	alert('Required Entry missing.' + CrLfx(2) + 
							'At least one check box must be selected for "' + AButtonsLabel + '".' + CrLfx(2));
					
  HandleOptionalBookmark(AOptionalBookmark);		
  
  if (AOptionalBookmark)
    AttemptFocus(ACheckBoxArray[0], 0)
  else								
    AttemptFocus(ACheckBoxArray[0]);
	
	return false;

}					//RequireCheckBoxes()


function SetGlobalFocusEvent(AForm, AFunction)
{
	var i;
	
	if (AForm == undefined)
	  AForm = document.forms[0];
	  
	with (AForm)
		for (i=0; i < length; i++)
			if (! elements[i].attachEvent('onfocus', AFunction))
				alert('attachEvent() failure: ' + elements[i].name);
			
}				//SetGlobalFocusEvent()


function SetRadioFocusEvent(AForm, AFunction)
{
	var i;
	
	with (AForm)
		for (i=0; i < length; i++)
			if (elements[i].type == 'radio')
				if (! elements[i].attachEvent('onfocus', AFunction))
					alert('attachEvent() failure: ' + elements[i].name);
			
}				//SetRadioFocusEvent()


function SetRadioBlurEvent(AForm, AFunction)
{
	var i;
	
	with (AForm)
		for (i=0; i < length; i++)
			if (elements[i].type == 'radio')
				if (! elements[i].attachEvent('onblur', AFunction))
					alert('attachEvent() failure: ' + elements[i].name);
			
}				//SetRadioFocusEvent()


function OnGlobalFocusEvent(AEvent)
{
	
	if (AEvent.srcElement)
		if (AEvent.srcElement != null)
			GCurrentElement = AEvent.srcElement;
		
}			//OnGlobalFocusEvent()


function RequireInputDate(AInputObject, AInputObjectLabel, ADaysInPastAllowed, ADaysInFutureAllowed, AOptionalBookmark)
{
	if (AInputObject.value == '')
	{
		sStatus = 'Please enter a date like MM/DD/YY.';
		ShowProblem(AInputObjectLabel, 'Date entry is blank.' + CrLfx(2) + sStatus);
		HandleOptionalBookmark(AOptionalBookmark);
		
    if (AOptionalBookmark)
      AttemptFocus(AInputObject, 0)
    else								
      AttemptFocus(AInputObject);
		
		return false;
	}
	else
		return ValidateInputDate(AInputObject, AInputObjectLabel, ADaysInPastAllowed, ADaysInFutureAllowed, AOptionalBookmark);

}				//RequireInputDate()


function RequireInputDateOfBirth(AInputObject, AInputObjectLabel, AOptionalBookmark)
{
	
	return RequireInputDate(AInputObject, AInputObjectLabel, 365.25 * 135, 0, AOptionalBookmark);

}       //RequireInputDateOfBirth()


function ValidateInputDate(AInputObject, AInputObjectLabel, ADaysInPastAllowed, ADaysInFutureAllowed, AOptionalBookmark)
{
	//External Dependencies: DateTimeLib.js, StringLib.js, GeneralLib.js
			
	function HandleRangeError(ARangeError)
	{
		var sOutOfRangeDesc, d, dLower, dUpper, sStatus;
		
		if (ARangeError == errBeforeRange)
			sOutOfRangeDesc = ' is before the required range.'
		else
			sOutOfRangeDesc = ' is after the required range.';
			
		d = Today();

	  if (ADaysInPastAllowed == -1)
		  dLower = new Date('01/01/1000')
	  else
		  dLower = DecDate(d, ADaysInPastAllowed);
				
	  if (ADaysInFutureAllowed == -1)
		  dUpper = new Date('12/31/9999')
	  else
		  dUpper = IncDate(d, ADaysInFutureAllowed);
	
		sStatus = 'Please enter a date between ' + GetDateString(dLower) + ' and ' + 
								GetDateString(dUpper) + '.'
    HandleOptionalBookmark(AOptionalBookmark);
		ShowProblem(AInputObjectLabel, DelimitDateString(AInputObject.value) + sOutOfRangeDesc +
									CrLfx(2) + sStatus);
									
    if (AOptionalBookmark)
      AttemptFocus(AInputObject, 0)
    else								
      AttemptFocus(AInputObject);
		
	}		//HandleRangeError()
	
	if (AInputObject.value == '')
		return true;

	switch (ValidateDateString(AInputObject.value, ADaysInPastAllowed, ADaysInFutureAllowed))
	{
		case errNone:
			return true;
		case errBadValue:
			sStatus = GetInvalidDateDescription(AInputObject.value);
			if (sStatus == '')
				sStatus = 'Please enter a date like MM/DD/YY.';
			
			ShowProblem(AInputObjectLabel, DelimitDateString(AInputObject.value) + ' is not a valid date.' + 
										CrLfx(2) + sStatus);
										
      HandleOptionalBookmark(AOptionalBookmark);
      
      if (AOptionalBookmark)
        AttemptFocus(AInputObject, 0)
      else								
        AttemptFocus(AInputObject);
      
			return false;
		case errBeforeRange:
			HandleRangeError(errBeforeRange);
			return false;
		case errAfterRange:
			HandleRangeError(errAfterRange);
			return false;
		default:
			alert('Unexpected return value from ValidateDateString(); Validation failure.');
			return false;
			
	}		//switch
		
}				//ValidateInputDate()


function RequireSSNInput(AInputObject, AInputLabel, AOptionalBookmark)
{
	if (AInputObject.value == '')
	{
		ShowProblem(AInputLabel, AInputLabel + ' is required.');
		return false;
	}
	else
		return ValidateSSNInput(AInputObject, AInputLabel);

}				//RequireSSNInput()


function ValidateSSNInput(AInputObject, AInputLabel, AOptionalBookmark)
{
	function RequireValid(ASSN)
	{
		if (! IsValidSSN(ASSN))
		{
			alert(GetBadSSNDescription(ASSN));
			
      HandleOptionalBookmark(AOptionalBookmark);

      if (AOptionalBookmark)
        AttemptFocus(AInputObject, 0)
      else								
        AttemptFocus(AInputObject);
			
			return false;
		}				
		else
			return true;
	}			
	
	if (AInputObject.value.length > 0)
		return RequireValid(AInputObject.value)
	else
		return true;

}					//ValidateSSNInput


function RequirePhoneInput(AInputObject, AInputLabel, AOptionalBookmark)
{
	if (! RequireInputText(AInputObject, AInputLabel, -1, -1, AOptionalBookmark))
		return false
	else
		return ValidatePhoneInput(AInputObject, AInputLabel, AOptionalBookmark);

}				//RequirePhoneInput()


function ValidatePhoneInput(AInputObject, AInputLabel, AOptionalBookmark)
{
	if (AInputObject.value == '')
		return true
	else
	if (! IsValidPhone(AInputObject.value))
	{
		alert('Invalid entry for ' + AInputLabel + '.');
    HandleOptionalBookmark(AOptionalBookmark);								
    
    if (AOptionalBookmark)
      AttemptFocus(AInputObject, 0)
    else								
      AttemptFocus(AInputObject);
		
		return false;
	}
	else
		return true;

}			//ValidatePhoneInput()


function RequirePagerInput(AInputObject, AInputLabel)
{
	if (! RequireInputText(AInputObject, AInputLabel, 0))
		return false
	else
		return ValidatePagerInput(AInputObject, AInputLabel);

}			//RequirePagerInput()


function ValidatePagerInput(AInputObject, AInputLabel, AOptionalBookmark)
{

	if (AInputObject.value == '')
		return true
	else
	if (AInputObject.value == '')
		return true;
	
	if (! IsValidPager(AInputObject.value))
	{
		alert('Invalid entry for ' + AInputLabel + '.');
		
    HandleOptionalBookmark(AOptionalBookmark);

    if (AOptionalBookmark)
      AttemptFocus(AInputObject, 0)
    else								
      AttemptFocus(AInputObject);
		
		return false;
	}
	else
		return true;

}			//ValidatePagerInput()


function RequireZipCodeInput(AInputObject, AInputLabel, ALongZipRequired)
{
	if (ALongZipRequired)
	{
		if (! RequireInputText(AInputObject, AInputLabel, 10, 10))
			return false;
	}
	else
	{
		if (! RequireInputText(AInputObject, AInputLabel, 5, -1))
			return false
	}
	
	return ValidateZipCodeInput(AInputObject, AInputLabel, ALongZipRequired);

}				//RequireZipCodeInput()


function ValidateZipCodeInput(AInputObject, AInputLabel, ALongZipRequired, AOptionalBookmark)
{
	if (AInputObject.value == '')
		return true
	else
	if (ALongZipRequired)
	{
		if (! RequireInputText(AInputObject, AInputLabel, 10))
			return false;
	}
	else
	if (! IsValidZip(InputObject.value, ALongZipRequired))
	{
		alert('Invalid entry for ' + AInputLabel + '.');

    HandleOptionalBookmark(AOptionalBookmark);
		
    if (AOptionalBookmark)
      AttemptFocus(AInputObject, 0)
    else								
      AttemptFocus(AInputObject);
		
		return false;
	}
	else
		return true;
		
}			//ValidateZipCodeInput()


function RequireSfExtensionInput(AInputObject, AInputLabel)
{

	if (! RequireInputText(AInputObject, AInputLabel, 0))
		return false
	else
		return ValidateSfExtensionInput(AInputObject, AInputLabel);

}			//RequireSfExtensionInput()

	
function ValidateSfExtensionInput(AInputObject, AInputLabel, AOptionalBookmark)
{
	if (AInputObject.value == '')
		return true
	else
	if (! IsValidSfExtension(AInputObject.value))
	{
		alert('Invalid entry for ' + AInputLabel + '.');
		
    HandleOptionalBookmark(AOptionalBookmark);

    if (AOptionalBookmark)
      AttemptFocus(AInputObject, 0)
    else								
      AttemptFocus(AInputObject);
		
		return false;
	}
	else
		return true;
		
}			//ValidateSfExtensionInput()


function ShowProblem(AInputObjectLabel, AProblemText)
{
	alert('Problem with entry for "' + AInputObjectLabel + '".' + CrLfx(2) + AProblemText);
						
}					//ShowProblem()


function GetWhizInputMaxLength(AControl)
{

	if (AControl.type == 'textarea')
	  return 100
	else
	if (AControl.maxLength < 1 || AControl.maxLength > 35)
	  return 35
	else
	  return AControl.maxLength;
	  
}     //GetWhizInputMaxLength()


function GetWhizDefaultText(ATextInput)
{
  var sCurrentName = GCurrentElement.name;
  
  if (GetWhizInputMaxLength(GCurrentElement) >= 10 && 
	  (Pos('Date', sCurrentName) > -1 || 
		  Pos('Dt', sCurrentName) > -1) ||
			  Pos('dob', sCurrentName) > -1)
	  return GetDateString(new Date())
  else
  if (Pos('Month', sCurrentName) > -1)
	  return GetMonthString(Now(), 2)
  else
  if (Pos('Day', sCurrentName) > -1)
	  return GetDayString(Now(), 2)
  else
  if (Pos('Year', sCurrentName) > -1)
  {
	  if (GCurrentElement.maxLength == 4)
		  return GetYearString(Now(), 4)
	  else
		  return GetYearString(Now(), 2);
  }
  else
  if (Pos('Weight', sCurrentName) > -1)
	  return '145'
  else
  if (Pos('Height', sCurrentName) > -1)
	  return '70'
  else
  if (Pos('Zip', sCurrentName) > -1)
	  return '74136'
  else
  if (Pos('Ext', sCurrentName) > -1)
	  return '1-' + RepeatString('9', GetWhizInputMaxLength(GCurrentElement) - 2)
  else
  if ((Pos('Pager', sCurrentName) > -1 || Pos('Cell', sCurrentName) > -1 ||
	  Pos('Phone', sCurrentName) > -1 || Pos('Fax', sCurrentName) > -1 || Pos('CallBack', sCurrentName) > -1) && 
		  IsBetween(GetWhizInputMaxLength(GCurrentElement), 8, 13))
	  return '918-494-9999'
  else
  if (Pos('SSN', sCurrentName) > -1 || Pos('Social', sCurrentName) > -1)
  {
	  if (GetWhizInputMaxLength(GCurrentElement) > 9)
		  return '777-77-7777'
	  else
		  return RepeatString('7',GetWhizInputMaxLength(GCurrentElement));
  }
  else
  if ((Pos('Num', sCurrentName) > -1 || Pos('No.', sCurrentName) > -1) &&
        (Pos('Contact', sCurrentName) > -1 && IsBetween(GetWhizInputMaxLength(GCurrentElement), 8, 15)))
  {
    if (GetWhizInputMaxLength(GCurrentElement) > 11)
	    return '918-494-9999'
	  else
	    return '494-9999';
	}
	else
  if (Pos('Num', sCurrentName) > -1 || Pos('No.', sCurrentName) > -1 ||
		  Pos('MRN', sCurrentName) > -1)
	  return RepeatString('1', GetWhizInputMaxLength(GCurrentElement))
  else
  if (Pos('Gender', sCurrentName) > -1)
    return 'Female'
  else
    return "";

}       //GetWhizDefaultText()


function WhizInput()
{
	var sData; sJunk1 = 'WhizInput()';
	
	
	function GetTextData(ASeedData, AInput)
	{
		var s = 'abcdefghij klmnopqrst uvwxyz';
		var Result;
		var i;
		
		if (ASeedData > '')
		{
			if (IsDigitString(ASeedData))
			  return ASeedData;
		}
			  
		if (ASeedData.length > GetWhizInputMaxLength(AInput))
			return Slice(ASeedData, 0, GetWhizInputMaxLength(AInput) - 1)
		else
		if (ASeedData.length < GetWhizInputMaxLength(AInput))
		{
			Result = ASeedData + ' - ';
			while (Result.length < GetWhizInputMaxLength(AInput))	
			{
				i = GetRandomInteger100();
				while (i > s.length)
					i = GetRandomInteger100();
					
				Result = Result + s.charAt(i - 1);
			}
			return TrimSpaces(Result);
		}
		else
			return ASeedData;
				
	}		//GetTextData()		
	
	
	if (GCurrentElement)
		with (GCurrentElement)
		  if (value > '' && (type == 'text' || type == 'textarea'))
		    SetFocusToNextInput(GCurrentElement)
		  else
			if (GCurrentElement.type == 'text' || GCurrentElement.type == 'textarea')
			{
			  sData = GetWhizDefaultText(GCurrentElement);
			  
			  if (sData == '')
				{
					sData = GCurrentElement.name;
					if (sData == '')
						sData = sJunk1;
				}
			
				with (GCurrentElement) 
				{
					value = GetTextData(sData, GCurrentElement);
					SetFocusToNextInput(GCurrentElement);
				}
			}
			else
			if (GCurrentElement.type == 'select-one')
			{
				with (GCurrentElement)
				{
					while (selectedIndex < length - 1)
					{
						selectedIndex = selectedIndex + 1;
						if (onchange)
							onchange();
						if (options[selectedIndex].value > '')
							break;
					}
					SetFocusToNextInput(GCurrentElement);
				}
			}
			else
			if (GCurrentElement.type == 'checkbox' || GCurrentElement.type == 'radio')
			{
			  if ((GCurrentElement.type == 'radio' && ! ElementToArray(GCurrentElement)[0].checked) ||
			      (GCurrentElement.type == 'checkbox' && ! GCurrentElement.checked))
				{
				  GCurrentElement.checked = true;
				  if (GCurrentElement.onclick)
            GCurrentElement.onclick();
				    //try
				    //{
					    //GCurrentElement.onclick();
					  //}
					  //catch (err)
					  //{
					  //}
			  }
				SetFocusToNextInput(GCurrentElement);
			}
			else
			  SetFocusToNextInput(GCurrentElement);
					
}		//WhizInput()


function ElementToArray(AObject)
{
  return eval(AObject.form.name + '.' + AObject.name);
}


function WhizTextInput()
{
  var sTemp;

	if (GCurrentElement)
		if (GCurrentElement.type == 'text' || GCurrentElement.type == 'textarea')
		  if (GCurrentElement.value == '')
		  {
		    sTemp = GetWhizDefaultText(GCurrentElement);
		    if (sTemp > '')
			    GCurrentElement.value = sTemp
			  else
			    GCurrentElement.value = GCurrentElement.name;
			}

  SetFocusToNextInput(GCurrentElement);

}


function WhizTextInputByName()
{
	if (GCurrentElement)
		if (GCurrentElement.type == 'text' || GCurrentElement.type == 'textarea')
			GCurrentElement.value = GCurrentElement.name;

    SetFocusToNextInput(GCurrentElement);
}
	
	
function WhizInputControl(AControl)
{
  GCurrentElement = AControl;
  WhizInput();  
}


function IsPopulatedElement(AControl)
{
  if (AControl.type == 'text' || AControl.type == 'textarea')
    return AControl.value > ''
  else
  if (AControl.type == 'checkbox')
    return AControl.checked
  else
    return false;
}


function WhizInputForm(AForm)
{
  var i;

  for (i=0;i < AForm.length;i++)
  {
    if (! IsPopulatedElement(AForm.elements[i]))
      if (CanFocusElement(AForm.elements[i]))
        WhizInputControl(AForm.elements[i]);
  }
  
  try
  {
    AForm.elements[AForm.length - 1].focus();
  }
  catch (err)
  {
    //do nothing
  }
}


function CanFocusElement(AFormElement)
{
  var currObj = AFormElement;

  function NotVisible()
  {
    if (currObj.style)
      return currObj.style.display == 'none' || currObj.style.visibility == 'hidden'
    else
      return false;
  }

  if (NotVisible())
    return false;

  while (currObj.parentNode)
  {
    currObj = currObj.parentNode;
    if (NotVisible())
      return false;
  }
  
  return true;
}

	
function IncrementDate(ATextInput, AAutoFill)
{
	if (AAutoFill && ATextInput.value == '')
	  ATextInput.value = GetDateString(Today())
	else
	  if (ATextInput.value > '')
	    if (IsValidDateString(ATextInput.value))
	      with (ATextInput)
	      {
	        value = IncDateString(value, 1);
	        focus();
	        select();
	      }
}
	
	
	function DecrementDate(ATextInput, AAutoFill)
	{
	  if (AAutoFill && ATextInput.value == '')
	    ATextInput.value = GetDateString(Today())
	  else
	    if (ATextInput.value > '')
	      if (IsValidDateString(ATextInput.value))
	        with (ATextInput)
	        {
	          value = DecDateString(value, 1);
	          focus();
	          select();
	        }
	
	}     //IncrementDate()

	
function FormatInputTime(ATextInput)
{
  //External Dependencies: DateTimeLib.js, StringLib.js
  var sTime;
  
  sTime = FormatTimeString(StripChar(ATextInput.value, ' '), 'am');
  if (IsValidTimeString(sTime))
    ATextInput.value = sTime;
}


function DoTimeExit(ATextInput)
{
  //External Dependencies: DateTimeLib.js, StringLib.js
  
  if (ATextInput.value > '')
  {
    FormatInputTime(ATextInput);
    if (IsValidTimeString(ATextInput.value))
      UnHighlightInput(ATextInput)
    else
      HighlightBadInput(ATextInput);
  }

}       //DoTimeExit()


function ValidateInputTime(ATextInput, AInputLabel, AOptionalBookmark)
{
  //External Dependencies: DateTimeLib.js, StringLib.js
  
  ATextInput.value = TrimSpaces(ATextInput.value);
  if (ATextInput.value > '')
    if (! IsValidTimeString(ATextInput.value))
    {
      alert('Invalid time entry for ' + AInputLabel);
      
      HandleOptionalBookmark(AOptionalBookmark);

      if (AOptionalBookmark)
        AttemptFocus(ATextInput, 0)
      else								
        AttemptFocus(ATextInput);
      
      return false;
    }
    
  return true;
}


function ShowSpaceBarMessage(ATextControl, ADefaultText)
{
  with (ATextControl)
    if (value == '')
      window.status = 'Hit <Space Bar> for ' + ADefaultText;
}


function ClearStatusBar()
{
  window.status = '';
}


function PopulateSelectFromArray(ASelect, AArray)
{
  var i;
  
  ASelect.length = AArray.length;
  
  for (i=0; i < AArray.length; i++)
  {
    ASelect[i].text = AArray[i].toString();
    ASelect[i].value = AArray[i].toString();
  }
}


function GetAvailableCharCount(AInput, AMaxChars)
{
  return (AMaxChars - AInput.value.length);
}


function UnselectText(AInput)
{
  with (AInput)
    value = value;
}


function SetCaretAtEnd(AInput)
{
  var tr;

  with (AInput)
    if (value > '')
    {
      AInput.focus();
      if (createTextRange)
      {
        tr = createTextRange();
        tr.move('character', value.length);             //move caret to end of text
        tr.select();
      }
      else
        value = value;
    }
        
}         //SetCaretAtEnd()


function IsCaretAtEnd(AInput)
{
  var tr, trChange;

  with (AInput)
    if (createTextRange)
    {
      tr = document.selection.createRange();
      trChange = AInput.createTextRange();
      trChange.move('character', value.length);
      return tr.compareEndPoints('EndToEnd', trChange) == 0;
    }
    else
      return false;
        
}         //IsCaretAtEnd()


function FocusAndSelect(ATextInput)
{

  with (ATextInput)
  {
    focus();
    select();
  }

}       //FocusAndSelect()


function SetSelectText(ASelect, AText, AAlternateIndex)
{
  var i;
  
  with (ASelect)
  {
    for (i=0; i < ASelect.options.length; i++)
      if (options[i].text == AText)
      {
        selectedIndex = i;
        return;
      }
      
    if (AAlternateIndex > -1)
      selectedIndex = AAlternateIndex
    else
      selectedIndex = -1;
      
  }

}         //SetSelectText()


function GetSelectedListIndices(AListBox)
{
  var i;
  var Result = new Array;
  
  for (i=0; i < AListBox.options.length; i++)
    if (AListBox[i].selected)
      Result[Result.length] = i;
      
  return Result;

}       //GetSelectedListIndices()


function RemoveSelectedIndices(AListBox)
{
  var i = 0;
  
  with (AListBox)
    while (i < options.length)
      if (options[i].selected)
        options[i] = null
      else
        i++;
  
}         //RemoveSelectedIndices()


function AddListItem(AText, AValue, ADestinationListBox, AOptionalColor)
//----------------------------------------------------------------------
// See also other list item routines: *ListItems()
//----------------------------------------------------------------------
{
  //var opt = document.createElement('option');
  var opt = new Option(AText, AValue);
  
  with (opt)
  {
    if (AOptionalColor)
      style.color = AOptionalColor;
  }
    
  with (ADestinationListBox)
    add(opt, options.length);
  
}       //AddListItem()


function CopyListItem(ASourceListBox, ADestinationListBox, AIndex, AAppendToDestination, AOptionalNewColor)
//-------------------------------------------------------------------------------------------
//  This routine is the same as MoveListItem(), except that the source item is not deleted
//-------------------------------------------------------------------------------------------
{
  var opt = document.createElement('option');
  
  with (opt)
  {
    text = ASourceListBox[AIndex].text;
    value = ASourceListBox[AIndex].value;
    if (AOptionalNewColor)
      opt.style.color = AOptionalNewColor;
  }
    
  with (ADestinationListBox)
    if (AAppendToDestination)
      add(opt, ADestinationListBox.length)
    else
      add(opt, 0);    //insert at first postition
  
}       //CopyListItem()


function TransferListItem(ASourceListBox, ADestinationListBox, AIndex)
//----------------------------------------------------------------------
// See also TransferListItems(), MoveListItem(), and MoveListItems()
//----------------------------------------------------------------------
{
  var opt = document.createElement('option');
  
  with (opt)
  {
    text = ASourceListBox[AIndex].text;
    value = ASourceListBox[AIndex].value;
    style.color = ASourceListBox[AIndex].style.color;
  }
    
  with (ADestinationListBox)
    add(opt, 0);    //insert at first postition
  
  with (ASourceListBox)
    options[AIndex] = null;

}       //TransferListItem()


function TransferListItemsInUserOrder(ASourceListBox, ADestinationListBox, AOptionalNewColor)
{
  //---------------------------------------------------------------------------
  // This routine preserves the order in which the user selected the items
  //   for transfer
  //---------------------------------------------------------------------------
  var arSelectedIndices = GetSelectedListIndices(ASourceListBox);
  var i;
  
  for (i=0; i < arSelectedIndices.length; i++)
    CopyListItem(ASourceListBox, ADestinationListBox, arSelectedIndices[i], true, AOptionalNewColor);

  for (i = arSelectedIndices.length; i > -1; i--)
    ASourceListBox[arSelectedIndices[i]] = null;
    
}         //TransferListItemsInUserOrder()


function TransferListItems(ASourceListBox, ADestinationListBox)
//----------------------------------------------------------------------
// See also MoveListItems()
//----------------------------------------------------------------------
// This routine assumes that multiple items may be selected. However, no 
//  problems occur when the source list box is empty, does not have a 
//  selected item or has only one selected item.
//----------------------------------------------------------------------
// This routine searches the list from the bottom up because it's
//  delegate routine inserts items at position 0 in the destination
//  list box. Transferring items from the bottom first keeps the items
//  sorted in their orignal order (at least for each multi-select move
//  operation).
//------------------------------------------------------------------------------------------
// It is Important to call this type of routine from the appropriate event. Othewise, anomalous
//  results may occur. This routine would typically be called from the OnChange event of
//  a select object
//-------------------------------------------------------------------------------------------
{
  var i = ASourceListBox.length - 1;
  
  while (ASourceListBox.length > 0 && i > -1)
    if (i > ASourceListBox.length - 1)
      i--
    else
    if (ASourceListBox[i].selected)
      TransferListItem(ASourceListBox, ADestinationListBox, i)
    else
      i--;
  
}       //TransferListItems()


function MoveListItem(ASourceListBox, ADestinationListBox, AIndex, AAppendToDestination)
//-------------------------------------------------------------------------------------------
//  This routine is the same as TransferListItem(), except that the
//    call specifies whether to Append to the destination list 
//    (AAppendToDestination=true) or to insert at position 0 (AAppendToDestination=false)
//-------------------------------------------------------------------------------------------
{

  CopyListItem(ASourceListBox, ADestinationListBox, AIndex, AAppendToDestination);
  
  with (ASourceListBox)
    options[AIndex] = null;

}       //MoveListItem()


function MoveListItems(ASourceListBox, ADestinationListBox, AAppendToDestination)
//-------------------------------------------------------------------------------------------
//  This routine is the same as TransferListItems(), except that the
//    call specifies whether to Append to the destination list 
//    (AAppendToDestination=true) or to insert at position 0 (AAppendToDestination=false)
//-------------------------------------------------------------------------------------------
// This routine assumes that multiple items may be selected. However, no 
//  problems occur when the source list box is empty, does not have a 
//  selected item or has only one selected item.
//-------------------------------------------------------------------------------------------
// It is Important to call this type of routine from the appropriate event. Othewise, anomalous
//  results may occur. This routine would typically be called from the OnChange event of
//  a select object
//-------------------------------------------------------------------------------------------
{
  var i;
  
  if (! AAppendToDestination)
    TransferListItems(ASoureListBox, ADestinationListBox)
  else
  {
    i = ASourceListBox.length - 1;
    while (ASourceListBox.length > 0 && (i > -1))
      if (i > ASourceListBox.length - 1)
        i--
      else
      if (ASourceListBox[i].selected)
        MoveListItem(ASourceListBox, ADestinationListBox, i, AAppendToDestination)
      else
        i--;
  }
  
}       //MoveListItems()


function SwapListItems(AListBox1, AListBox2)
{
  var arOpts2 = new Array(AListBox2.length);
  var i;

  for (i=0; i < AListBox2.length; i++)
    arOpts2[i] = AListBox2.options[i];
    
  with (AListBox2)
    while (length > 0)
      options[length - 1] = null;

  with (AListBox1)
    for (i=0; i < length; i++)
      with (options[i])
        AListBox2.options[AListBox2.length] = new Option(text, value);
    
  with (AListBox1)
    while (length > 0)
      options[length - 1] = null;
    
  for (i=0; i < arOpts2.length; i++)
    with (arOpts2[i])
      AListBox1.options[AListBox1.options.length] = new Option(text, value);

}       //SwapListItems()


function SelectValuesToDelimitedString(ASelectObject, ADelimiter)
{
  var i;
  var Result = '';
  
  if (ASelectObject.length > 0)
    with (ASelectObject)
    {
      for (i=0; i < length - 1; i++)
        if (options[i].value != undefined)
          Result = Result + options[i].value + ADelimiter;
      
      if (options[i].value != undefined)
        Result = Result + options[length - 1].value;
    }
  
  return Result;

}       //SelectValuesToDelimitedString()


function SelectCaptionsToDelimitedString(ASelectObject, ADelimiter)
{
  var i;
  var Result = '';
  
  if (ASelectObject.length > 0)
    with (ASelectObject)
    {
      for (i=0; i < length - 1; i++)
        if (options[i].value != undefined)
          Result = Result + options[i].text + ADelimiter;
      
      if (options[i].value != undefined)
        Result = Result + options[length - 1].text;
    }
  
  return Result;

}       //SelectCaptionsToDelimitedString()


function IsValueInListBox(AValue, AListBox)
{
  var i;
  var sVal = AValue.toLowerCase();
  
  with (AListBox)
    for (i=0; i < options.length; i++)
      if (options[i].value.toLowerCase() == sVal)
        return true;
        
  return false;
  
}       //IsValueInListBox()


function IsCaptionInListBox(ACaption, AListBox)
{

  var i;
  var sCap = ACaption.toLowerCase();
  
  with (AListBox)
    for (i=0; i < options.length; i++)
      if (options[i].text.toLowerCase() == sCap)
        return true;
        
  return false;
  
}       //IsCaptionInListBox()


function ClearOptions(ASelectObject)
{
  
  ASelectObject.options.length = 0;
  
}       //ClearOptions()


function GetAgeFromDOBInput(ATextInput)
{

  return GetAgeLazy(TrimSpaces(ATextInput.value), Now(), -1);

}         //GetAgeFromDOBInput()


function GetClinicalAgeFromDOBInput(ATextInput)
{

  return GetAgeClinicalLazy(TrimSpaces(ATextInput.value), Now(), -1);

}           //GetClinicalAgeFromDOBInput()


function OnPhysCredentialsKeyDown(AInput)
{
  var sTemp;

  if (event.keyCode == 32)
  {
    sTemp = TrimSpaces(AInput.value);
    switch (sTemp)
    {
      case '' :
        AInput.value = 'MD';
        event.returnValue = false;
        break;
      case 'MD' :
        AInput.value = 'DO';
        event.returnValue = false;
        break;
      case 'DO' :
        AInput.value = '';
        event.returnValue = false;
        break;
    }
  }
    
}         //OnPhysCredentialsKeyDown()


function OnPhysCredentialsExit(AInput)
{
  
  if (AInput.value > '')
    AInput.value = GetDoctoralCasing(GetUpperCaseMedicalCredentials(AInput.value));

}         //OnPhysCredentialsExit()


function OnShortListKeyDown(AInputObject, AStringArray, AOnItemScroll)
{
  var i;
  var sVal = AInputObject.value;
  var iKeyCode = event.keyCode;
  var iVal;
  var bDone = false;
  var s;
  
  
  function IsValidKey()
  {
    if (iKeyCode > 64 && iKeyCode < 91)
      return true
    else
    if (iKeyCode > 96 && iKeyCode < 123)
      return true
    else
    if (iKeyCode > 47 && iKeyCode < 58)
      return true
    else
      return false;
  }
  
  
  function InvokeOnItemScroll()
  {
    if (AOnItemScroll)
      eval(AOnItemScroll);
  }
  
  
  function PopulateFirstMatch(AStartIndex)
  {
    var s;

    for (i = AStartIndex; i < AStringArray.length; i++)
    {
      s = AStringArray[i].charAt(0);
      if (s.toLowerCase().charCodeAt(0) == iKeyCode || s.toUpperCase().charCodeAt(0) == iKeyCode)
      {
        AInputObject.value = AStringArray[i];
        bDone = true;
        InvokeOnItemScroll();
        break;
      }
    }
    
    if (! bDone)
      if (AStartIndex == 0)
        bDone = true;
  
  }           //PopulateFirstMatch()
  
  
  //called when key is <space bar>
  function PopulateNextItem()
  {
    var i;
    var bDone = false;
    
    if (AInputObject.value == '')
      AInputObject.value = AStringArray[0]
    else
    {
      for (i = 0; i < AStringArray.length; i++)
      {
        if (AInputObject.value == AStringArray[i])
        {
          if (i == AStringArray.length - 1)
            AInputObject.value = AStringArray[0]
          else
            AInputObject.value = AStringArray[i + 1]
            
          InvokeOnItemScroll();
          bDone = true;
          break;
        }
      }         //for...
      
      if (! bDone)
      {
        AInputObject.value = AStringArray[0];
        InvokeOnItemScroll();
      }        
    }       //if...else
      
  }           //PopulateNextItem()
  
  if (IsNavigationKey(iKeyCode))
    return 
  else
  if (iKeyCode == 32 || iKeyCode == 0)      //space bar or not activated by key
    PopulateNextItem()
  else
  if (IsValidKey())
  {
    if (sVal == '')
      PopulateFirstMatch(0)
    else
    {
      //looking for first match after current value; or first match if no match after current value
      for (i = 0; i < AStringArray.length; i++)
      {
        s = AStringArray[i].charAt(0);
        if (s.toLowerCase().charCodeAt(0) == iKeyCode || s.toUpperCase().charCodeAt(0) == iKeyCode)
          if (AInputObject.value == AStringArray[i])
          {
            if (i == AStringArray.length - 1)
              PopulateFirstMatch(0)
            else
              PopulateFirstMatch(i + 1);
            break;
          }
        }         //for...
        
      if (! bDone)
        PopulateFirstMatch(0);
    }
  }

  event.returnValue = false;

}             //OnShortListKeyDown()


function OnStateKeyDownAutoValue(AInputObject, AAutoSkip)
{
  if (event.keyCode == 32)
  {
    event.returnValue=false;
    if (AInputObject.value == '')
    {
      AInputObject.value = 'OK';
      if (AAutoSkip)
        SetFocusToNextInput(AInputObject);
    }
  }
}


function OnStateFocusAutoValue(AInputObject)
{
  var f = AInputObject.form;
  var prevInput;
  
  if (AInputObject.value == '')
  {
    prevInput = f[GetInputIndex(AInputObject) - 1];
    if (prevInput)
      if (IsCityInOklahoma(prevInput.value))
      {
        AInputObject.value = 'OK';
        SetFocusToNextInput(AInputObject);
      }
  }
}


function OnCityKeyDown(AInputObject, AAutoSkip)
{
  var iElement;
  
  if (event.keyCode == 32 && AInputObject.value == '')
  {
    event.returnValue=false;
    AInputObject.value = 'Tulsa';
    if (AAutoSkip)
    {
      iElement = GetInputIndex(AInputObject) + 1;
      AInputObject.form[iElement].focus();
      if (AInputObject.form[iElement].value == '' && AInputObject.form[iElement].maxLength == 2)
      {
        AInputObject.form[iElement].value = 'OK';
        SetFocusToNextInput(AInputObject.form[iElement]);
      }
    }
  }
}


function CtrlClick$ClearInput(AInput)
{
  
  if (event.button == 1 && event.ctrlKey && ! AInput.readOnly)
    AInput.value = '';

}           //CtrlClick$ClearInput()


function CtrlClick$Off(ARadioButton)
{

  if (event.button == 2 && event.ctrlKey)
    ARadioButton.checked = false;

}  


function MailInputKeyEvent(AInput)
{
  if (event.keyCode == 32)
  {
    UpdateMailInput(AInput);
    event.returnValue = false;
  }
}


function UpdateMailInput(AInput)
{
  var sValue = AInput.value.toLowerCase();
  var sAdd;

  if (sValue > '' && sValue.length > 1)
  {
    if (Pos('@', sValue) == -1)
      sAdd = '@'
    else
    if (Pos('@', sValue) != sValue.length - 1 && Pos('.', sValue) == -1)
      sAdd = '.com'
    else
    if (Pos('@', sValue) == sValue.length - 1 && Pos('.com', sValue) == -1)
      sAdd = 'saintfrancis.com'
    else
      return;
      
    AInput.value = TrimSpaces(AInput.value) + sAdd;
      
  }

}           //UpdateMailInput()


function MailInputExit(AInput)
{
  
  UpdateMailInput(AInput);

  if (AInput.value > '' && Pos('@', AInput.value) == AInput.value.length - 1)
    AInput.value = AInput.value + 'saintfrancis.com';
    
}            //MailInputExit()


function ShowHelpListHint(AHelpObj, AHintObj, AHorizontalOffset, AVerticalOffset)
{
  var iLeft, iTop;
  
  iLeft = AHelpObj.offsetLeft + AHelpObj.offsetWidth - 22;
  iLeft += AHorizontalOffset;
    
  iTop = AHelpObj.offsetTop + 30;
  iTop += AVerticalOffset;

  AHintObj.style.left = iLeft;
  AHintObj.style.top = iTop;  
}


function UnFilterHelpList(APopupWindow)
{
  var arItems = eval(APopupWindow.id + "PopupItem");
  var i;

  for (i=0; i < arItems.length; i++)
    arItems[i].style.display = '';

}


function UnFilter2DHelpList(APopupWindow)
{
  var arItems = eval(APopupWindow.id + "PopupItem");
  var arSecondaryItems = eval(APopupWindow.id + "PopupItemSecondary");
  var i;

  for (i=0; i < arItems.length; i++)
    arItems[i].style.display = '';

  for (i=0; i < arSecondaryItems.length; i++)
    arSecondaryItems[i].style.display = 'none';

}


function FilterHelpList(APopupWindow, AValue, AFilterRule)
{
  var arItems = eval(APopupWindow.id + "PopupItem");
  var arHide = new Array;
  var i;
  
  if (AValue == '')
  {
    for (i=0; i < arItems.length; i++)
      arItems[i].style.display = '';
    return;
  }
  
  if (event.keyCode == 9)
    return;
  
  AValue = AValue.toLowerCase();
  if (AFilterRule == 2)
  {
    for (i=0; i < arItems.length; i++)
      if (StartsWith(arItems[i].innerText.toLowerCase(),AValue.toLowerCase()))
        arItems[i].style.display = ''
      else
        arHide[arHide.length] = arItems[i];
  }
  else
    for (i=0; i < arItems.length; i++)
      if (arItems[i].innerText.toLowerCase().charAt(0) == AValue.toLowerCase().charAt(0))
        arItems[i].style.display = ''
      else
        arHide[arHide.length] = arItems[i];
        
  if (arHide.length == arItems.length)
    for (i=0; i < arItems.length; i++)
    {
      arItems[i].style.color = 'gray';
      if (arItems[i].style.display > '')
        arItems[i].style.display = '';
    }
  else
    for (i=0; i < arHide.length; i++)
      arHide[i].style.display = 'none';
        
}           //FilterHelpList()


function Filter2DHelpList(APopupWindow, AValue, AFilterRule, AHighLightColor)
{
  var arSecondaryItems = eval(APopupWindow.id + "PopupItemSecondary");
  var arHide = new Array;
  var i;
  
  FilterHelpList(APopupWindow, AValue, AFilterRule);
  
  if (AValue == '')
  {
    for (i=0; i < arSecondaryItems.length; i++)
      arSecondaryItems[i].style.display = 'none';
    return;
  }
  
  if (event.keyCode == 9)
    return;
  
  AValue = AValue.toLowerCase();
  if (AFilterRule == 2)
  {
    for (i=0; i < arSecondaryItems.length; i++)
      if (StartsWith(arSecondaryItems[i].innerText.toLowerCase(),AValue.toLowerCase()))
        arSecondaryItems[i].style.display = ''
      else
        arHide[arHide.length] = arSecondaryItems[i];
  }
  else
    for (i=0; i < arSecondaryItems.length; i++)
      if (arSecondaryItems[i].innerText.toLowerCase().charAt(0) == AValue.toLowerCase().charAt(0))
        arSecondaryItems[i].style.display = ''
      else
        arHide[arHide.length] = arSecondaryItems[i];

  if (arHide.length < arSecondaryItems.length)
  {
    Hide2DHelpListGrayItems(APopupWindow);
    Highlight2DHelpList(APopupWindow, AValue, '', AHighLightColor);
  }
  else
    for (i=0; i < arHide.length; i++)
      arHide[i].style.display = 'none';
       
}           //Filter2DHelpList()


function Hide2DHelpListGrayItems(APopupWindow)
{
  var arItems = eval(APopupWindow.id + "PopupItem");
  var i;

  for (i=0; i < arItems.length; i++)
    if ((arItems[i].style.display == '') && (arItems[i].style.color == 'gray'))
    {
      arItems[i].style.display = 'none';
      arItems[i].style.color = '';
    }
}


function HighlightHelpList(APopupWindow, AValue, AItemColorNormal, AItemColorHighlight)
{
  //this function supports THelpListInputBuilder which uses an instance of TPopupWindowBuilder
  //to present a help list and to autocomplete partial strings which are matched in the pop up
  //windows list
  
  DoHelpListHighlight(eval(APopupWindow.id + "PopupItem"), AValue, AItemColorNormal, AItemColorHighlight);

}


function Highlight2DHelpList(APopupWindow, AValue, AItemColorNormal, AItemColorHighlight)
{
  //this function supports T2DHelpListInputBuilder which uses an instance of TPopupWindowBuilder
  //to present a help list and to autocomplete partial strings which are matched in the pop up
  //windows list
  var arItems = eval(APopupWindow.id + "PopupItem");
  var arSecondaryItems = eval(APopupWindow.id + "PopupItemSecondary");
  
  if (DoHelpListHighlight(arItems, AValue, AItemColorNormal, AItemColorHighlight))
    UnHighlightHelpList(arSecondaryItems, AItemColorNormal)
  else
    DoHelpListHighlight(arSecondaryItems, AValue, AItemColorNormal, AItemColorHighlight);    
}


function DoHelpListHighlight(AItemArray, AValue, AItemColorNormal, AItemColorHighlight)
{
  var arItems = AItemArray;
  var i;
  
  if (AItemColorNormal == undefined)
    AItemColorNormal = '';

  if (AItemColorHighlight == undefined)
    AItemColorHighlight = 'blue';
    
  UnHighlightHelpList(AItemArray, AItemColorNormal);
    
  if (AValue > '')
  {
    AValue = AValue.toLowerCase();
    for (i=0; i < arItems.length; i++)
      if (arItems[i].style.display == '')
        if (arItems[i].innerText.toLowerCase().indexOf(AValue) == 0)
        {
          arItems[i].style.color = AItemColorHighlight;
          arItems[i].style.fontWeight = 'bold';
          return true;
        }
  }
  
  return false;
  
}               //DoHelpListHighlight()


function UnHighlightHelpList(AItemArray, AItemColorNormal)
{
  var i;
  
  if (AItemColorNormal == undefined)
    AItemColorNormal = '';
  
  for (i=0; i < AItemArray.length; i++)
    if (AItemArray[i].style.display == '')
    {
      AItemArray[i].style.color = AItemColorNormal;
      AItemArray[i].style.fontWeight = '';
    }
}



/* -- The idea is to provide THelpListInputBuilder with the ability to auto-complete
   -- multiple values into a single input, e.g. eggroll; egg-drop soup; croutons; lemon drops
   -- when the user types a ; the current value (last value) would complete.
   -- add a check to be sure the cursor is at the end of the input (if not, bail)
   -- when no ; is at the end, assume the user has tabbed out
   
function AutoInsertWithHelpList(APopupWindow, AInput, AStopChar)
{
  var arItems;
  var iLength = AInput.value.length;
  var iPosStart;
  var sValue;
  var i;
  
  if (iLength > 0 && AStopChar == AInput.value.charAt(iLength - 1))
  {
    iPosStart = iLength - 2;
    while (iPosStart > 0 && AInput.value.charAt(iPosStart) != AStopChar)
      iPosStart -= 1;
    sValue = TrimSpaces(AInput.value.substr(iPosStart));
    if (sValue > '')
    {
      sValue = sValue.toLowerCase();
      arItems = eval(APopupWindow.id + "PopupItem");
      for (i=0; i < arItems.length; i++)
        if (arItems[i].innerText.toLowerCase().indexOf(sValue) == 0)
        {
          if (iPosStart == 0)
            AInput.value = arItems[i].innerText + AStopChar + ' '
          else
            AInput.value = AInput.value.substr(0, iPosStart - 1) + arItems[i].innerText + AStopChar + ' ';
          return;
        }
    }
    
  }
  
}             //AutoInsertWithHelpList()
*/


/*
function DoHelpListAutoComplete(AItems, AInput)
{
  var arItems = AItems;
  var i;
  var sValue;

  if (AInput.value > '')
    if (AInput.value.charAt(0) == ' ')      //space at beginning disables autocomplete
    {
      AInput.value = TrimSpaces(AInput.value);
      return;
    }
    else    
      AInput.value = TrimSpaces(AInput.value);
  
  if (AInput.value == '')
    return;
  
  sValue = AInput.value.toLowerCase();
  for (i=0; i < arItems.length; i++)
    if (arItems[i].innerText.toLowerCase().indexOf(sValue) == 0)
    {
      AInput.value = arItems[i].innerText;
      return;
    }
}
*/


function DoHelpListAutoComplete(AItems, AInput)
{
  var arItems = AItems;
  var i;
  var sValue;

/*
  if (AInput.value > '')
    if (AInput.value.charAt(0) == ' ')      //space at beginning disables autocomplete
    {
      AInput.value = TrimSpaces(AInput.value);
      return;
    }
    else    
      AInput.value = TrimSpaces(AInput.value);
*/
  
  if (AInput.value == '')
    return;
  
  sValue = AInput.value.toLowerCase();
  for (i=0; i < arItems.length; i++)
    if (arItems[i].innerText.toLowerCase().indexOf(sValue) == 0)
    {
      AInput.value = arItems[i].innerText;
      return;
    }
}


function AutoCompleteWithHelpList(APopupWindow, AInput)
{
  var arItems = eval(APopupWindow.id + "PopupItem");
  
  DoHelpListAutoComplete(arItems, AInput);
}


function AutoCompleteWith2DHelpList(APopupWindow, AInput)
{
  var arItems = eval(APopupWindow.id + "PopupItem");
  var arSecondaryItems = eval(APopupWindow.id + "PopupItemSecondary");
  
  DoHelpListAutoComplete(arItems, AInput);
  DoHelpListAutoComplete(arSecondaryItems, AInput);
}


function EnforceHelpList(APopupWindow, AInput)
{
  var arItems = eval(APopupWindow.id + "PopupItem");
  var i ;

  //AInput.value = TrimSpaces(AInput.value);
  
  if (AInput.value == '')
    return;
  
  for (i=0; i < arItems.length; i++)
    if (arItems[i].innerText == AInput.value)
      return;
      
  alert('Value of input must match an entry in the list...');
  SetCaretAtEnd(AInput); 

}       //EnforceHelpList()


function Enforce2DHelpList(APopupWindow, AInput)
{
  var arItems = eval(APopupWindow.id + "PopupItem");
  var arSecondaryItems = eval(APopupWindow.id + "PopupItemSecondary");
  var i ;

  if (AInput.value == '')
    return;
  
  for (i=0; i < arItems.length; i++)
    if (arItems[i].innerText == AInput.value)
      return;
      
  for (i=0; i < arSecondaryItems.length; i++)
    if (arSecondaryItems[i].innerText == AInput.value)
      return;
      
  alert('Value of input must match an entry in the list...');
  SetCaretAtEnd(AInput); 


}       //Enforce2DHelpList()


function AutoPositionHelpList(AListObj, AInput)
{
  AListObj.style.left = AbsoluteX(AInput) + 1;
  AListObj.style.top = AbsoluteY(AInput) + AInput.offsetHeight + 1;
}


function EnforceLegalText(ATextInput, AOptionalMaxLength)
{
  
  function CheckValues(ASymbolPositions)
  {
    var i;
    var iInsertions = 0;
    var ch;
    
    for (i=0; i < ASymbolPositions.length; i++)
    {
      ASymbolPositions[i] += iInsertions;
      ch = ATextInput.value.charAt(ASymbolPositions[i] + 1);
      if (IsAlpha(ch) || ch == '/')
        if (AOptionalMaxLength == undefined || ATextInput.value.length + 1 <= AOptionalMaxLength)
        {
          UpdateValue(ASymbolPositions[i]);
          iInsertions += 1;
        }
        else
        {
          alert('Illegal Sequence in Text Input.\n\nThe symbol < followed by an alpha character or slash is not allowed. ' +
                  'Please correct by removing symbol < or inserting a space immediately following.\n\nNormally, ' +
                  'insertion of a space is automatic, but in this case a pre-determined maximum length would be ' +
                  'exceeded\n\n');
          ATextInput.focus();
          return;
        }
      }
  }
  
  function UpdateValue(AIndex)
  {
    ATextInput.value = ATextInput.value.substr(0, AIndex + 1) +
                                ' ' + ATextInput.value.substr(AIndex + 1);
  }
  
    
  if (ATextInput.value > '' && ATextInput.value.indexOf('<') > -1)
    if (ATextInput.value.indexOf('<') < ATextInput.value.length - 1)
    {
      if (AOptionalMaxLength == undefined && ATextInput.maxLength != undefined)
        AOptionalMaxLength = ATextInput.maxLength;
      CheckValues(AllPos('<', ATextInput.value));
    }
    else
      return;

}               //EnforceLegalText()


function GetTulsaAreaCities()
{
  var Result = new Array;
  
  Result[0] = 'Tulsa';
  Result[Result.length] = 'Broken Arrow';
  Result[Result.length] = 'Bixby';
  Result[Result.length] = 'Catoosa';
  Result[Result.length] = 'Collinsville';
  Result[Result.length] = 'Coweta';
  Result[Result.length] = 'Glenpool';
  Result[Result.length] = 'Jenks';
  Result[Result.length] = 'Mannford';
  Result[Result.length] = 'Owasso';
  Result[Result.length] = 'Sand Springs';
  Result[Result.length] = 'Sapulpa';
  Result[Result.length] = 'Skiatook';
  Result[Result.length] = 'Sperry';
  Result[Result.length] = 'Stillwater';
  
  return Result;
}


function IsCityInTulsaArea(ACityName)
{
  var i;
  var arCities = GetTulsaAreaCities();
  
  ACityName = ACityName.toLowerCase();
  
  for (i=0; i < arCities.length; i++)
    if (ACityName == arCities[i].toLowerCase())
      return true;
      
  return false;
}


function GetOklahomaCities()
{
  var Result = GetTulsaAreaCities();
  
  Result[Result.length] = 'Oklahoma City';
  Result[Result.length] = 'Muskogee';
  Result[Result.length] = 'Wagoner';
  Result[Result.length] = 'Lawton';
  Result[Result.length] = 'Edmond';
  Result[Result.length] = 'Norman';
  Result[Result.length] = 'Midwest City';
  Result[Result.length] = 'Moore';
  Result[Result.length] = 'Enid';
  Result[Result.length] = 'Bartlesville';
  Result[Result.length] = 'McAlester';
  Result[Result.length] = 'Okmulgee';
  Result[Result.length] = 'Tahlequah';
  Result[Result.length] = 'Vinita';
  Result[Result.length] = 'Ponca City';
  Result[Result.length] = 'Miami';
  
  return Result;
}


function IsCityInOklahoma(ACityName)
{
  var i;
  var arCities = GetOklahomaCities();
  
  ACityName = ACityName.toLowerCase();
  
  for (i=0; i < arCities.length; i++)
    if (ACityName == arCities[i].toLowerCase())
      return true;
      
  return false;
}


