

function limitText(limitField, limitCount, limitNum) {
if (limitField.value.length > limitNum) {
limitField.value = limitField.value.substring(0, limitNum);
} else {
limitCount.value = limitNum - limitField.value.length;
}
}



function showDiv(field) {
  if (document.getElementById) { // DOM3 = IE5, NS6
    document.getElementById(field).style.visibility = 'visible';
  }
  else {
    if (document.layers) { // Netscape 4
      document.field.visibility = 'visible';
    }
    else { // IE 4
      document.all.field.style.visibility = 'visible';
    } 
  }
}

// checks or unchecks all specified checkboxes

function checkAll(field)
{
  for (i = 0; i < field.length; i++)
    if (field[i].checked == true)
      field[i].checked = false;
    else
      field[i].checked = true ;
}


// check if a string is blank

function isBlank(s)
{
  for (var i=0; i<s.length; i++) {
    var c = s.charAt(i);
    if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
  }
  return true;
}


// veryify a form

function verify(f)
{
  var msg;
  var emptyFields = "";
  var errors = "";

  for (var i=0; i<f.length; i++) {
    var e = f.elements[i];
    if (((e.type == "text") || (e.type == "textarea")) && !e.optional) {
      if ((e.value == null) || (e.value == "") || isBlank(e.value)) {
        emptyFields += "\n      " + e.name;
        continue;
      }
      if ((e.numeric || e.min != null) || (e.max != null)) {
        var v = parseFloat(e.value);
        if (isNaN(v) ||
            ((e.min != null) && (v < e.min)) ||
            ((e.max != null) && (v > e.max))) {
          errors += "- The field " + e.name + " must be a nmber";
          if (e.min != null)
            errors += " that is greater than " + e.min;
          if (e.max != null && e.min != null)
            errors += " and less than " + e.max;
          else if (e.max != null)
            errors += " that is less than " + e.amx;
          errors += ".\n";
        }
      }
    }
    if (e.type == "select-one" && !e.optional) {
      if (e.value == "0" || e.value == 0) {
        errors += "- The field " + e.name + " must be selected\n";
      }
    }
    if (e.type == "select-multiple" && !e.optional) {
      if (!e.value || e.value == 0 || e.value == "0") {
        errors += "- The field " + e.name + " must have at least one selection made in it.\n";
      }
    }
    //if (e.type == "file" && !e.optional) {
    //  if (!e.value) {
    //    errors += "- " + e.name + " file must be chosen to upload.\n";
    //  }
    // }
    //if (e.type == "checkbox" && !e.optional) {
    //  if (!e.checked) {
    //    errors += "- The field " + e.name + " must have at least one selection made from it.\n";
    //  }
    //}
  }
  if (!emptyFields & !errors) return true;

  msg = "-------------------------------------------------------------------\n";
  msg += "The form was not submitted because of the following error(s).\n";
  msg += "Please correct the error(s) and re-submit.\n";
  msg += "------------------------------------------------------------------\n";

  if (emptyFields) {
    msg += "- The following required field(s) are empty:" + emptyFields + "\n";
    if (errors) msg += "\n";
  }

  msg += errors;
  alert(msg);
  return false;
}

function changeImage(filename)
{
  document.articleimage.src = filename;
}

function mailPage()
{
  mail_str = "mailto:?subject= Mediastow: " + document.title;
  mail_str += "&body= Mediastow.com have archived this article for us -- " + document.title;
  mail_str += ". You can visit it here: " + location.href; 
  location.href = mail_str;
}
