var defaultEmptyOK = false;
// ------------------------------------------------------------------------------------
//    Screen 4: Travel Modes
// ------------------------------------------------------------------------------------
function referralValidate(theForm)  {
	var alertMsg = 'The following items were missing or invalid:\n___________________________________\n\n';
	var alertOff = true;

	if ( isEmpty(theForm.ClaimantName.value) || isValidEmail(theForm.ClaimantName.value) )
	{
		alertMsg = alertMsg + '- Claimant Name\n';
    theForm.ClaimantName.focus();
    alertOff = false;
	}
	if ( isEmpty(theForm.CattyName.value) || isValidEmail(theForm.CattyName.value) )
	{
		alertMsg = alertMsg + '- Claimant Attorney Name\n';
    theForm.CattyName.focus();
    alertOff = false;
	}
	if ( isEmpty(theForm.EmployerName.value) || isValidEmail(theForm.EmployerName.value) )
	{
		alertMsg = alertMsg + '- Employer Name\n';
    theForm.EmployerName.focus();
    alertOff = false;
	}
	if (alertOff == false)
	{
		alert(alertMsg);
		return(false);
	}		
}
// ------------------------------------------------------------------------------------
//    Screen 2: Required work location
// ------------------------------------------------------------------------------------
function validateWorkLoc(theForm) {
	var alertMsg = 'Please choose a Work Location from the list.\n';
	if (theForm.cboWorkLoc.value == "NONE")
  {
		theForm.cboWorkLoc.focus();
		alert(alertMsg);
		return(false);
	}		
}
// ------------------------------------------------------------------------------------
//    Screen 5: Mileage to / from work
// ------------------------------------------------------------------------------------
function validateMileage(theForm)  {
  var alertMsg = 'Enter the distance from home to work in miles.\n';
	var alertOff = true;
	if ( theForm.mileage.value == "" || theForm.mileage.value == "0") 
	  alertOff = false;
	else
	  if ( !isInteger( theForm.mileage.value ) ) 
		  alertOff = false;
  if (alertOff == false)
	{
	  alert(alertMsg);
	  theForm.mileage.focus();
	  return false;
	}
}
// ------------------------------------------------------------------------------------
//    Screen 6: Commute time in minutes
// ------------------------------------------------------------------------------------
function validateDriveTime(theForm)  {
	var alertMsg = 'The following items were incomplete or missing:\n___________________________________\n\n';
	var alertOff = true;
	if (theForm.hmtowk.value == "" || theForm.hmtowk.value == "0")
	{
		alertMsg = alertMsg + '- Time to drive from home to work\n';
		theForm.hmtowk.focus();
		alertOff = false;
	}
	if (theForm.wktohm.value == "" || theForm.wktohm.value == "0")
	{
		alertMsg = alertMsg + '- Time to drive from work to home\n';
		if (alertOff == true)
		{
			theForm.wktohm.focus();
			alertOff = false;
		}
	}
	if (alertOff == false)
	{
		alert(alertMsg);
		return(false);
	}		
}
// ------------------------------------------------------------------------------------
//    Screen 7: Compressed Work Week Yes/No
// ------------------------------------------------------------------------------------
function validateCwwYn(theForm)  {
	var alertMsg = 'Please click a button to indicate YES or NO.\n';
	if ( (theForm.cwwy[0].checked == false) && (theForm.cwwy[1].checked == false) )
	{
	  alert(alertMsg);
    return(false);
	}
}
// ------------------------------------------------------------------------------------
//    Screen 7a: Compressed Work Week Schedule
// ------------------------------------------------------------------------------------
function validateCwwSched(theForm)  {
	var alertMsg = 'Please click a button to indicate your schedule type.\n';
	if ( (theForm.cwwysched[0].checked == false) && (theForm.cwwysched[1].checked == false) && (theForm.cwwysched[2].checked == false) && (theForm.cwwysched[3].checked == false) && (theForm.cwwysched[4].checked == false) )
	{
	  alert(alertMsg);
    return(false);
	}
}
// ------------------------------------------------------------------------------------
//    Screen 7b: Compressed Work Week Day Off
// ------------------------------------------------------------------------------------
function validateCwwDay(theForm)  {
	var alertMsg = 'Please click a button to indicate YES or NO.\n';
	if ( (theForm.cwwday[0].checked == false) && (theForm.cwwday[1].checked == false) )
	{
	  alert(alertMsg);
    return(false);
	}
}
// ------------------------------------------------------------------------------------
//    Screen 8: Rideshare Match Interest Yes/No
// ------------------------------------------------------------------------------------
function validateRideYn(theForm)  {
	var alertMsg = 'Please click a button to indicate YES or NO.\n';
	if ( (theForm.rideyn[0].checked == false) && (theForm.rideyn[1].checked == false) )
	{
	  alert(alertMsg);
    return(false);
	}
}
// ------------------------------------------------------------------------------------
//    Screen 8a: Rideshare Cross Streets
// ------------------------------------------------------------------------------------
function validateStreets(theForm)  {
	var alertMsg = 'The following items were incomplete or missing:\n___________________________________\n\n';
	var alertOff = true;
	if (theForm.street1.value == "")
	{
		alertMsg = alertMsg + '- Cross street #1\n';
		theForm.street1.focus();
		alertOff = false;
	}
	if (theForm.street2.value == "")
	{
		alertMsg = alertMsg + '- Cross street #2\n';
		if (alertOff == true)
		{
			theForm.street2.focus();
			alertOff = false;
		}
	}
	if (alertOff == false)
	{
		alert(alertMsg);
		return(false);
	}		
}
// ------------------------------------------------------------------------------------
//    Miscellaneous functions
// ------------------------------------------------------------------------------------
function warnInvalid (theField, s)  {   
  theField.focus()
  theField.select()
  alert(s)
  return false;
}
function isEmpty(s)  {   
  return ((s == null) || (s.length == 0))
}
function isDigit (c)  {
  return ((c >= "0") && (c <= "9"))
}
function isInteger (s)  {
  var i;
  if (isEmpty(s)) 
    if (isInteger.arguments.length == 1) 
		   return defaultEmptyOK;
    else 
		   return (isInteger.arguments[1] == true);
    for (i = 0; i < s.length; i++)
    {   
      var c = s.charAt(i);
      if (!isDigit(c)) return false;
    }
    return true;
}
function isInRange(str, num1, num2)  {
	var i = parseInt(str)
	return((i >= num1) && (i <= num2))
}
function isAlpha(str)  {
	for (i = 0; i < str.length; i++)
	{
	if ( !( ((str.charAt(i) >= "a") && (str.charAt(i) <= "z")) ||
      		((str.charAt(i) >= "A") && (str.charAt(i) <= "Z")) ) )
		return false;
	else 
		return true;
	}
}
function isValidEmail(str)  {
	var dot;
	var atsign;
	for (i = 0; i < str.length; i++)
	{
    if ( (str.charAt(i) == "@") ) atsign = "@";
    if ( (str.charAt(i) == ".") ) dot = ".";
	}
  if ( ( isEmpty(atsign) ) || ( isEmpty(dot) ) )
    return false;
	else
	  return true;
}