//****************************************************************************
//
function isEmpty(s) {
  return ((s == null) || (s.length == 0))
}

//****************************************************************************
//
function isDigit (c) {
  return ((c >= "0") && (c <= "9"))
}

//****************************************************************************
//
function isInteger (text_obj) {
  var i;
  var c;
  var s;

  s = text_obj.value;

  if (isEmpty(s))
    {
    alert("You must enter a number in the County Code box.   ");

    text_obj.blur();
    text_obj.focus();
    return(false);
    }
  if (s.length != 5)
    {
    alert("The County Code must be 5 digits.");

    text_obj.blur();
    text_obj.focus();
    return(false);
    }

  for (i = 0; i < s.length; i++)
    {
    c = s.charAt(i);
    if (!isDigit(c))
        {
        alert("Invalid Number [" + s + "].\\n" +
              "The County Code is always a 5 digit number");
        text_obj.blur();
        text_obj.value = "";

        text_obj.focus();
        return(false);
        }
	    }

  return(true);
}

//****************************************************************************
//
function update_text(select_obj) {
  var index     = select_obj.selectedIndex;
  var cnty_code = select_obj[index].value;
  var txtobj    = document.cnty_form.county_code;

  txtobj.value = cnty_code;

  txtobj.blur();
  txtobj.focus();

  return(true);
}

//****************************************************************************
//
function check_code(text_obj, domsg) {
  var s       = text_obj.value;
  var found   = false;
  var selobj  = document.cnty_form.county;
  var numopts = selobj.length;

  if ( (isEmpty(s)) || (s.length != 5))
    {
    domsg ? alert("Invalid County Code [" + s + "]") : "";

    selobj[0].selected = true;
    return(false);
    }

  for (i = 0; i < numopts; i++)
    {
    if (selobj[i].value == s)
        {
        selobj[i].selected = true;
        found = true;
        break;
        }
    }

  if (!found)
    {
    domsg ? alert("Invalid County Code [" + s + "]") : "" ;

    selobj[0].selected = true;
    }

  return(found);
}
