/*
  index.js
*/ 


//--- SubmitForm ---
function SubmitForm() {
  var frmEntry;
  var strErrors = "";
  
  frmEntry = document.getElementById('request_form');
  strErrors = CheckFullName(frmEntry, strErrors);
  strErrors = CheckAddress(frmEntry, strErrors);
  strErrors = CheckCity(frmEntry, strErrors);
  strErrors = CheckState(frmEntry, strErrors);
  strErrors = CheckZip(frmEntry, strErrors);
  strErrors = CheckEmail(frmEntry, strErrors);
  strErrors = CheckPhones(frmEntry, strErrors);
  strErrors = CheckBestTime(frmEntry, strErrors);
  strErrors = CheckFlooring(frmEntry, strErrors);

  if (strErrors.length > 0) {
    alert("Error: Incomplete Form (see below)\n" + strErrors);
  }
  else {
    frmEntry.submit();
  }
}


//--- CheckAddress ---
function CheckAddress(frmEntry, strErrors) {
  if (HasStringContent(frmEntry.address1) == false) {
    strErrors += "\n- Address is required.";
  }
  return strErrors;
}


//--- CheckBestTime ---
function CheckBestTime(frmEntry, strErrors) {
  if ((frmEntry.bt_morning.checked == false) &&
      (frmEntry.bt_afternoon.checked == false) &&
      (frmEntry.bt_evening.checked == false)) {
    strErrors += "\n- Best time to contact is required.";
  }
  return strErrors;
}


//--- CheckCity ---
function CheckCity(frmEntry, strErrors) {
  if (HasStringContent(frmEntry.city) == false) {
    strErrors += "\n- City is required.";
  }
  return strErrors;
}


//--- CheckEmail ---
function CheckEmail(frmEntry, strErrors) {
  if (HasStringContent(frmEntry.email) == false) {
    strErrors += "\n- Email is required.";
  }
  return strErrors;
}


//--- CheckFlooring ---
function CheckFlooring(frmEntry, strErrors) {
  if ((frmEntry.wants_carpet.checked == false) &&
      (frmEntry.wants_hardwood.checked == false) &&
      (frmEntry.wants_laminate.checked == false) &&
      (frmEntry.wants_ceramic.checked == false) &&
      (frmEntry.wants_vinyl.checked == false)) {
    strErrors += "\n- Flooring Line is required.";
  }
  return strErrors;
}


//--- CheckFullName ---
function CheckFullName(frmEntry, strErrors) {
  if (HasStringContent(frmEntry.full_name) == false) {
    strErrors += "\n- Full Name is required.";
  }
  return strErrors;
}


//--- CheckPhones ---
function CheckPhones(frmEntry, strErrors) {
  var blnHasPhone1;
  var blnHasPhone2;

  blnHasPhone1 = HasStringContent(frmEntry.phone);
  blnHasPhone2 = HasStringContent(frmEntry.phone2);
  
  if ((blnHasPhone1 == false) && (blnHasPhone2 == false)) {
    strErrors += "\n- At least one Phone is required.";
  }
  return strErrors;
}


//--- CheckState ---
function CheckState(frmEntry, strErrors) {
  if (HasStringContent(frmEntry.state) == false) {
    strErrors += "\n- State is required.";
  }
  return strErrors;
}


//--- CheckZip ---
function CheckZip(frmEntry, strErrors) {
  if (HasStringContent(frmEntry.zip) == false) {
    strErrors += "\n- Zip is required.";
  }
  return strErrors;
}


//--- HasStringContent ---
function HasStringContent(objInput) {
  var strContent;
  strContent = Trim(objInput.value);
  if(strContent.length > 0) {
    return true;
  }
  else {
    return false;
  }
}

