﻿function isValidEmail(strEmail) {

  if (strEmail.length == 0) {
    return true;
  } else if (strEmail.length < 5) {
    return false;
  } else {
    if (strEmail.indexOf(" ") > 0) {
      return false;
    } else {
      if (strEmail.indexOf("@") < 1) {
        return false;
      } else {
        if (strEmail.lastIndexOf(".") < (strEmail.indexOf("@") + 2)) {
          return false;
        } else {
          if (strEmail.lastIndexOf(".") >= strEmail.length - 2) {
            return false;
          }
        }
      }
    }
  }
  return true;
}




function checkFieldInput(field, errText) {
  var sizeNull = eval("document.sendform." + field + ".value.length == 0;");
  if (sizeNull) {
    alert(errText);
    eval("document.sendform." + field + ".focus();");
    return false;
  }
  return true;
}


function submitmaterial() {

  if (!checkFieldInput("navn", "Indtast navn")) { return false };
  if (!checkFieldInput("adresse", "Indtast adresse")) { return false };
  if (!checkFieldInput("postnr", "Indtast postnr")) { return false };
  if (!checkFieldInput("by", "Indtast by")) { return false };
  if (!checkFieldInput("email", "Indtast e-mail adresse")) { return false };
  if (document.sendform.email.value.length > 0 && !isValidEmail(document.sendform.email.value)) {
    alert('Indtast venligst en korrekt email-adresse');
    document.sendform.email.focus();
    return false;
  }

  document.sendform.submit();
}
