function validate_alpha(alphaobj) {
  var tst_value = /^[A-Za-z0-9@\.]{1,}$/;  
  if (!tst_value.test(alphaobj.value)) {
    alert("One of the characters in the " + alphaobj.name + " is not a valid");
    return false;
  } else {
    return true;
  }
}

function validate_numeric(numobj , field_name) {
  var tst_value = /^[0-9]{1,}$/;    
  if (!tst_value.test(numobj.value)) {
    alert("One of the characters in the " + field_name + " is not a numeric");
    return false;
  } else {
    return true;
  }
}

function validate_not_blank(field, field_name) {
  var x=field.value;
  if (x.length > 0) {
    return true;
  } else {
    alert("The field: \"" + field_name + "\" is a required field and needs to be filled in!");
    return false;
  }
}

function validate_not_zero(field, field_name) {
  var x=field.value;
  if (x != 0) {
    return true;
  } else {
    alert("The field: \"" + field_name + "\" is a required field.  Please make a selection!");
    return false;
  }
}

function validate_3_parms_not_zero(field1, field2, field3, message_string) {
  var x1=field1.value;
  var x2=field2.value;
  var x3=field3.value;

  if ((x1 == 0) && (x2 == 0) && (x3 == 0)) {
    alert(message_string);
    return (false);
  } else { 
    return true;
  } 
}

function validate_selected_value_not(select_obj, num, field_name) {
  if (select_obj.selectedIndex == num) {
    alert("Need to select a " + field_name);
    return false;
  } else {
    return true;
  }
}

function validate_string_equal(string1, string2, field_name) {
  if (string1.value != string2.value) {
    alert(field_name + " not the same.  Reenter values");
    return false;
  } else {
    return true;
  }
}

function validate_checkbox_selected(cb_obj) {
  var i;
  if (cb_obj.length) {
    for (i=0; i < cb_obj.length; i++) {
      if (cb_obj[i].checked) {
        return true;
      } 
    }
    alert("Nothing checked.  Please make a selection");
    return false;
  } else {
    if (cb_obj.checked) {
      return true;
    } else {
      alert("Nothing checked.  Please make a selection");
      return false;
    }
  }
}

function confirm_popup(msg_text) {
  retcode = confirm(msg_text);
  return retcode;
}

function validate_folder_name(alphaobj, field_name) {
  var tst_value = /^[^\'$?&<%>=/\.]{1,}$/;  
  if (!tst_value.test(alphaobj.value)) {
    alert("One of the characters in the " + field_name + " is not a valid");
    return false;
  } else {
    return true;
  }
}

function check_valid_selection(select_obj, select_desc_string) {
  var count=0;
  var i;

  for (i=0; i<select_obj.length; i++) {

    if (select_obj.options[i].selected) {
      count++;
    }
  }

  // Assume first line is a selection message and should not be counted
  if ((count > 1) && select_obj.options[0].selected) {
    alert ("Invalid selection made for " + select_desc_string + " Please reselect");
    return false;
  }

  //alert("return true for" + select_desc_string);
  return true;
}
    
function count_sel_not_zero_entry(select_obj) {
  var count=0;

  // Assume first line is a selection message and should not be counted
  if (select_obj.length > 1) {
    for (i=1; i<select_obj.length; i++) {
      if (select_obj.options[i].selected) {
        count++;
      }
    }
  }

  return count;
}

function count_all_sel_not_zero_entry(select_obj) {
  var count=0;

  for (i=0; i<select_obj.length; i++) {
    if (select_obj.options[i].selected) {
      count++;
    }
  }

  return count;
}

function test_url(urlobj, message_string) {
    var tst_value = /^(((http)s?)\:\/\/)?\w+(\.\w+)+[\S\s]*$/i; 
    if (urlobj.value.length != 0) {   
        if (!tst_value.test(urlobj.value)) {
                alert("Invalid URL format for field: " + message_string + ".  Either re-enter or leave blank");
                return false;
        } else {
                //alert("Valid URL format");
                return true;
        }
    } else {
        return true;      // nothing entered
    }   
}


