function DocumentLoad() {
}

function Show(item){
  try {
    document.getElementById(item).style.display = 'table-row';
  } catch (e) {
    document.getElementById(item).style.display = 'block';
  }
}

function Hide(item){
  document.getElementById(item).style.display = 'none'; 
}

function ShowClass(clsName, list) {
  var rows = document.getElementsByTagName('tr');
  for(iElement = 0; iElement < rows.length; iElement++) {
    if(rows[iElement].className == clsName) {
      try {
        rows[iElement].style.display = 'table-row';
      } catch (e) {
        rows[iElement].style.display = 'block';
      }
    }
  }
  if (list == true) {
    if (document.getElementById(clsName+'Count').value > 0){
      Show(clsName);
    }
  }
}

function HideClass(clsName, list) {
  var rows = document.getElementsByTagName('tr');
  for(iElement = 0; iElement < rows.length; iElement++) {
    if(rows[iElement].className == clsName) {
      rows[iElement].style.display = 'none';
    }
  }
  if (list == true) {
    Hide(clsName);
  }
}

function AddInsurance() {
  newInsurance = launchCenter("AddInsurance.html", "insurance", 500, 550);
}

function AddProperty() {
  newProperty = launchCenter("AddProperty.html", "property", 500, 550);
}

function AddAuto() {
  newProperty = launchCenter("AddAuto.html", "auto", 500, 550);
}

function AddDriver() {
  newProperty = launchCenter("AddDriver.html", "auto", 500, 550);
}

function CheckInsTypes() {
  document.QuoteForm.elements['0240000insTypeBond'].checked=true;
  document.QuoteForm.elements['0250000insTypeCommercialAuto'].checked=true;
  document.QuoteForm.elements['0260000insTypeCommercialLiability'].checked=true;
  document.QuoteForm.elements['0270000insTypeCommercialProperty'].checked=true;
  document.QuoteForm.elements['0280000insTypeCommercialUmbrella'].checked=true;
  document.QuoteForm.elements['0290000insTypeDirectorsOfficersLiability'].checked=true;
  document.QuoteForm.elements['0300000insTypeDisability'].checked=true;
  document.QuoteForm.elements['0310000insTypeGroupHealth'].checked=true;
  document.QuoteForm.elements['0320000insTypeGroupLife'].checked=true;
  document.QuoteForm.elements['0330000insTypeProfessionalLiability'].checked=true;
  document.QuoteForm.elements['0340000insTypeWorkersComp'].checked=true;
  ShowClass('CommercialProperty', true);
  ShowClass('CommercialLiability', false);
  ShowClass('WorkersComp', false);
  ShowClass('CommercialAuto', true);
  if(document.QuoteForm.elements['0600000driverConviction'][0].checked){
    ShowClass('CommercialDriver', true);}
}

function UnCheckInsTypes() {
  document.QuoteForm.elements['0240000insTypeBond'].checked=false;
  document.QuoteForm.elements['0250000insTypeCommercialAuto'].checked=false;
  document.QuoteForm.elements['0260000insTypeCommercialLiability'].checked=false;
  document.QuoteForm.elements['0270000insTypeCommercialProperty'].checked=false;
  document.QuoteForm.elements['0280000insTypeCommercialUmbrella'].checked=false;
  document.QuoteForm.elements['0290000insTypeDirectorsOfficersLiability'].checked=false;
  document.QuoteForm.elements['0300000insTypeDisability'].checked=false;
  document.QuoteForm.elements['0310000insTypeGroupHealth'].checked=false;
  document.QuoteForm.elements['0320000insTypeGroupLife'].checked=false;
  document.QuoteForm.elements['0330000insTypeProfessionalLiability'].checked=false;
  document.QuoteForm.elements['0340000insTypeWorkersComp'].checked=false;
  document.QuoteForm.elements['0350000insTypeOther'].checked=false;
  document.QuoteForm.elements['0360000insTypeOtherDesc'].value='';
  HideClass('CommercialProperty', true);
  HideClass('CommercialLiability', false);
  HideClass('WorkersComp', false);
  HideClass('CommercialAuto', true);
  HideClass('CommercialDriver', true);
}

function CheckFields(form){
  if (RequireFields(form,['0010000businessName','0020000contactName','0030000streetAddress','0040000city','0050000state','0060000zipCode','0080000email','0090000phoneNumber','0110000callTime','0120000callAMPM','0130000businessType','0150000numFullTimeEmployees','0160000numPartTimeEmployees','0170000numYearsInBusiness','0180000numBusinessLocations','0190000annualizedPayroll','0200000annualSales','0210000businessDescription'],['Business Name is Required','Contact Name is Required.','Street Adress is Required.','City is Required.','State is Required.','Zip Code is Required.','Email Address is Required.','Phone Number is Required.','Call Time is Required.','Call Time is Required.','Business Type is Required.','Number of Full Time Employees is Required.','Number of Part Time Employees is Required.','Years in Business is Required','Number of Business Locations is Required.','Annualized Payroll is Required.','Annual Sales is Required.','Business Description is Required.']) == false) {
    return false;
  }

  if ((document.QuoteForm.elements['0240000insTypeBond'].checked==false) &&
      (document.QuoteForm.elements['0250000insTypeCommercialAuto'].checked==false) &&
      (document.QuoteForm.elements['0260000insTypeCommercialLiability'].checked==false) &&
      (document.QuoteForm.elements['0270000insTypeCommercialProperty'].checked==false) &&
      (document.QuoteForm.elements['0280000insTypeCommercialUmbrella'].checked==false) &&
      (document.QuoteForm.elements['0290000insTypeDirectorsOfficersLiability'].checked==false) &&
      (document.QuoteForm.elements['0300000insTypeDisability'].checked==false) &&
      (document.QuoteForm.elements['0310000insTypeGroupHealth'].checked==false) &&
      (document.QuoteForm.elements['0320000insTypeGroupLife'].checked==false) &&
      (document.QuoteForm.elements['0330000insTypeProfessionalLiability'].checked==false) &&
      (document.QuoteForm.elements['0340000insTypeWorkersComp'].checked==false) &&
      (document.QuoteForm.elements['0350000insTypeOther'].checked==false)){
    setTimeout(function(){document.QuoteForm.elements['0240000insTypeBond'].focus()}, 100);
    alert('At least one of the Insurance Type Requested Fields must be checked.');
    return false;
  }

  if (document.QuoteForm.elements['0250000insTypeCommercialAuto'].checked) {
    if (document.getElementById('CommercialAutoCount').value==0) {
      document.getElementById('CommercialAutoButton').focus();
      alert('You have requested a Commercial Auto Quote.  You must add at least one Auto.');
      return false;
    }

    if (RequireFields(form,['0600000driverConviction'],['Driver Conviction is a Required Field.']) == false) {
      return false;
    }

    if (document.QuoteForm.elements['0600000driverConviction'][0].checked) {
      if (document.getElementById('CommercialDriverCount').value==0) {
        document.getElementById('CommercialDriverButton').focus();
        alert('You noted that a driver had been convicted of a moving violations in the past 5 years.  You must add at least one violation.');
        return false;
      }
    }
  }

  if (document.QuoteForm.elements['0260000insTypeCommercialLiability'].checked) {
    if (RequireFields(form,['0390000classOfBusiness','0410000percentOfSubWork','0420000liabilityLimits'],['Class of Business is Required.','Percent of Subcontracted Work is Required.','Liability Limits is a Required Field.']) == false) {
      return false;
    }
  }

  if (document.QuoteForm.elements['0270000insTypeCommercialProperty'].checked) {
    if (document.getElementById('CommercialPropertyCount').value==0) {
      document.getElementById('CommercialPropertyButton').focus();
      alert('You have requested a Commercial Property Quote.  You must add at least one Property.');
      return false;
    }
  }

  if (document.QuoteForm.elements['0290000insTypeDirectorsOfficersLiability'].checked) {
    if (document.QuoteForm.elements['0140000businessOwnersOfficers'].value=='') {
      document.QuoteForm.elements['0140000businessOwnersOfficers'].style.backgroundColor = 'lightpink';
      setTimeout(function(){document.QuoteForm.elements['0140000businessOwnersOfficers'].focus()}, 100);
      alert('You have requested a Directors/Officers Liability Quote.  You must enter Owner/Officer information.');
      return false;
    } else {
      document.QuoteForm.elements['0140000businessOwnersOfficers'].style.backgroundColor = '';
    }
  }

  if (document.QuoteForm.elements['0340000insTypeWorkersComp'].checked) {
    if (RequireFields(form,['0450000FEIN'],['Federal Employer ID Number is Required.']) == false) {
      return false;
    }

    if (((document.QuoteForm.elements['0470000workersCompClassification'].value=='') ||
         (document.QuoteForm.elements['0480000workersCompAnnualPayroll'].value=='')) &&
        ((document.QuoteForm.elements['0490000workersCompClassification'].value=='') ||
         (document.QuoteForm.elements['0500000workersCompAnnualPayroll'].value=='')) &&
        ((document.QuoteForm.elements['0510000workersCompClassification'].value=='') ||
         (document.QuoteForm.elements['0520000workersCompAnnualPayroll'].value=='')) &&
        ((document.QuoteForm.elements['0530000workersCompClassification'].value=='') ||
         (document.QuoteForm.elements['0540000workersCompAnnualPayroll'].value=='')) &&
        ((document.QuoteForm.elements['0550000workersCompClassification'].value=='') ||
         (document.QuoteForm.elements['0560000workersCompAnnualPayroll'].value==''))) {
      document.QuoteForm.elements['0470000workersCompClassification'].style.backgroundColor = 'lightpink';
      setTimeout(function(){document.QuoteForm.elements['0470000workersCompClassification'].focus()}, 100);
      alert('You must fill in at least one Worker\'s Comp Classification.');
      return false;
    } else {
      document.QuoteForm.elements['0470000workersCompClassification'].style.backgroundColor = '';
    }

    if (RequireFields(form,['0570000workersCompOwners'],['Include Owners/Officers in Worker\'s Comp is a Required Field.']) == false) {
      return false;
    }

    if (document.QuoteForm.elements['0570000workersCompOwners'][0].checked) {
      if (document.QuoteForm.elements['0140000businessOwnersOfficers'].value=='') {
        document.QuoteForm.elements['0140000businessOwnersOfficers'].style.backgroundColor = 'lightpink';
        setTimeout(function(){document.QuoteForm.elements['0140000businessOwnersOfficers'].focus()}, 100);
        alert('You have requested that Owners/Officers be included in Worker\'s Comp coverage.  You must enter Owner/Officer information.');
        return false;
      } else {
        document.QuoteForm.elements['0140000businessOwnersOfficers'].style.backgroundColor = '';
      }
    }
  }

  return true;

//    if (RequireFields(form,[],[]) == false) {
}

