var form = "";
var submitted = false;
var error = false;
var error_message = "";

function check_input(field_name, field_size, message) {
  if (form.elements[field_name] && (form.elements[field_name].type != "hidden")) {
    var field_value = form.elements[field_name].value;

    if (field_value == '' || field_value.length < field_size) {
      error_message = error_message + "* " + message + "\n";
      error = true;
    }
  }
}

function check_email(field, message) {
  if ((form.elements[field].value.indexOf('@') == -1) || (form.elements[field].value.indexOf('.') == -1)) {
    error_message = error_message + "* " + message + "\n";
	error = true;
  }
}

function check_password(field1, field2, message) {
    var field_value1 = form.elements[field1].value;
    var field_value2 = form.elements[field2].value;

    if (field_value1 != field_value2) {
      error_message = error_message + "* " + message + "\n";
      error = true;
    }
}

function check_form(form_name) {
  
  if (submitted == true) {
    alert("This form has already been submitted. Please press Ok and wait for this process to be completed.");
    return false;
  }

  error = false;
  form = form_name;
  error_message = "Errors have occured during the process of your form.\n\nPlease make the following corrections:\n\n";

  check_input("fname", 2, "Your First Name must contain a minimum of 2 characters.");
  check_input("lname", 2, "Your Last Name must contain a minimum of 2 characters.");
  check_input("address1", 5, "Your Address must contain a minimum of 5 characters.");
  check_input("city", 3, "Your City must contain a minimum of 3 characters.");
  check_input("zip", 3, "Your Zip Code must contain a minimum of 3 characters.");
  check_input("phone", 7, "Your Contact Number must contain a minimum of 7 characters.");
  check_input("email", 6, "Your E-Mail Address must contain a minimum of 6 characters.");
  check_email("email", "Your E-Mail Address must be in correct format.");
  check_input("u_name", 6, "Your Username must contain a minimum of 6 characters.");
  check_input("u_pass", 6, "Your Password must contain a minimum of 6 characters.");
  check_password("u_pass", "u_pass2", "Your Passwords do not match.");
  

  if (error == true) {
    alert(error_message);
    return false;
  } else {
    submitted = true;
    return true;
  }
}

function check_form2(form_name) {
  
  if (submitted == true) {
    alert("This form has already been submitted. Please press Ok and wait for this process to be completed.");
    return false;
  }

  error = false;
  form = form_name;
  error_message = "Errors have occured during the process of your form.\n\nPlease make the following corrections:\n\n";

  check_input("domain_name", 7, "Your Domain Name must contain a minimum of 7 characters.");
  check_input("fname", 2, "Your First Name must contain a minimum of 2 characters.");
  check_input("lname", 2, "Your Last Name must contain a minimum of 2 characters.");
  check_input("address1", 5, "Your Address must contain a minimum of 5 characters.");
  check_input("city", 3, "Your City must contain a minimum of 3 characters.");
  check_input("zip", 3, "Your Zip Code must contain a minimum of 3 characters.");
  check_input("phone", 7, "Your Contact Number must contain a minimum of 7 characters.");
  check_input("email", 6, "Your E-Mail Address must contain a minimum of 6 characters.");
  check_email("email", "Your E-Mail Address must be in correct format.");

  if (error == true) {
    alert(error_message);
    return false;
  } else {
    submitted = true;
    return true;
  }
}

function check_form3(form_name) {
  
  if (submitted == true) {
    alert("This form has already been submitted. Please press Ok and wait for this process to be completed.");
    return false;
  }

  error = false;
  form = form_name;
  error_message = "Errors have occured during the process of your form.\n\nPlease make the following corrections:\n\n";

  check_input("u_name", 2, "Your Last Name must contain a minimum of 2 characters.");
  check_input("phone", 7, "Your Contact Number must contain a minimum of 7 characters.");
  check_input("email", 6, "Your E-Mail Address must contain a minimum of 6 characters.");
  check_email("email", "Your E-Mail Address must be in correct format.");

  if (error == true) {
    alert(error_message);
    return false;
  } else {
    submitted = true;
    return true;
  }
}