var USstates = {};
USstates["AK"] = "Alaska";
USstates["AL"] = "Alabama";
USstates["AZ"] = "Arizona";
USstates["AR"] = "Arkansas";
USstates["AS"] = "American Samoa";
USstates["CA"] = "California";
USstates["CO"] = "Colorado";
USstates["CT"] = "Connecticut";
USstates["DC"] = "District of Columbia";
USstates["DE"] = "Delaware";
USstates["FL"] = "Florida";
USstates["FM"] = "Federated States of Micronesia";
USstates["GA"] = "Georgia";
USstates["GU"] = "Guam";
USstates["HI"] = "Hawaii";
USstates["IA"] = "Iowa";
USstates["ID"] = "Idaho";
USstates["IL"] = "Illinois";
USstates["IN"] = "Indiana";
USstates["KS"] = "Kansas";
USstates["KY"] = "Kentucky";
USstates["LA"] = "Louisiana";
USstates["MA"] = "Massachusetts";
USstates["MD"] = "Maryland";
USstates["ME"] = "Maine";
USstates["MH"] = "Marshall Islands";
USstates["MI"] = "Michigan";
USstates["MN"] = "Minnesota";
USstates["MO"] = "Missouri";
USstates["MP"] = "Northern Mariana Islands";
USstates["MS"] = "Mississippi";
USstates["MT"] = "Montana";
USstates["NC"] = "North Carolina";
USstates["ND"] = "North Dakota";
USstates["NE"] = "Nebraska";
USstates["NH"] = "New Hampshire";
USstates["NJ"] = "New Jersey";
USstates["NM"] = "New Mexico";
USstates["NV"] = "Nevada";
USstates["NY"] = "New York";
USstates["OH"] = "Ohio";
USstates["OK"] = "Oklahoma";
USstates["OR"] = "Oregon";
USstates["PA"] = "Pennsylvania";
USstates["PR"] = "Puerto Rico";
USstates["PW"] = "Palau";
USstates["RI"] = "Rhode Island";
USstates["SC"] = "South Carolina";
USstates["SD"] = "South Dakota";
USstates["TN"] = "Tennessee";
USstates["TX"] = "Texas";
USstates["UT"] = "Utah";
USstates["VA"] = "Virginia";
USstates["VI"] = "Virgin Islands";
USstates["VT"] = "Vermont";
USstates["WA"] = "Washington";
USstates["WI"] = "Wisconsin";
USstates["WV"] = "West Virginia";
USstates["WY"] = "Wyoming";
/*
USstates["AA"] = "Armed Forces Americas";
USstates["AE"] = "Armed Forces Europe, Middle East, &amp; Canada";
USstates["AP"] = "Armed Forces Pacific";
*/
function createUSStatesList(selectedValue, attribs) {
    document.write("\n"+'<select '+attribs+'>'+"\n"+'<option value="">--Select a State--</option>'+"\n");
    for (var state in USstates) {
        document.writeln(
            '<option value="'+USstates[state]+'"'+
            (selectedValue == USstates[state] ? ' selected="selected">' : '>')+
            USstates[state]+'</option>'
        );
    }
    document.writeln('</select>');
}
function createMonthList(selectedValue, attribs) {
    var text = '';
    var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
    text += "\n"+'<select '+attribs+'>'+"\n"+'<option value="">--Month--</option>'+"\n";
    for (var i=0; i<months.length; i++) {
        text += '<option value="'+months[i]+'"'+
            (selectedValue == months[i] ? ' selected="selected">' : '>')+
            months[i]+'</option>'
    }
    text += '</select>';
    return text;
}
function createDayList(selectedValue, attribs, numDays) {
    var text = '';
    var daysCount = null != numDays ? numDays : 31;
    text += "\n"+'<select '+attribs+'>'+"\n"+'<option value="">--Day--</option>'+"\n";
    for (var i=1; i<=daysCount; i++) {
        text += '<option value="'+i+'"'+
                (selectedValue == i ? ' selected="selected">' : '>')+i+'</option>';
    }
    text += '</select>';
    return text;
}
function createYearList(selectedValue, attribs, start, limit) {
    var text = '';
    var now = new Date();
    var listCount = null != start ? start : 1930;
    var listLimit = null != limit ? limit : now.getFullYear()-15;
    text += "\n"+'<select '+attribs+'>'+"\n"+'<option value="">--Year--</option>'+"\n";
    for (listCount; listCount<=listLimit; listCount++) {
        text += '<option value="'+listCount+'"'+
            (selectedValue == listCount ? ' selected="selected">' : '>')+
            listCount+'</option>'
    }
    text += '</select>';
    return text;
}
function validateApplicationForm(f) {
    var errors = '';
    with (f) {
        if (first_name.value.replace(/ /g,'').length <= 0) {
            errors += 'Please enter your first name.'+"\n";
        }
        if (last_name.value.replace(/ /g,'').length <= 0) {
            errors += 'Please enter your last name.'+"\n";
        }
        if (address.value.replace(/ /g,'').length <= 0) {
            errors += 'Please enter your address.'+"\n";
        }
        if (city.value.replace(/ /g,'').length <= 0) {
            errors += 'Please enter your city.'+"\n";
        }
        if (state.selectedIndex <= 0) {
            errors += 'Please select a state.'+"\n";
        }
        if (zip.value.replace(/ /g,'').length <= 0) {
            errors += 'Please enter your zip code.'+"\n";
        }
        if (f.name == 'VolunteerApplication') {
            if (home_phone.value.replace(/ /g,'').length <= 0) {
                errors += 'Please enter your home phone number.'+"\n";
            }
        }
        if (email.value.replace(/ /g,'').length <= 0) {
            errors += 'Please enter your email address.'+"\n";
        }
        if (!(under_18[0].checked || under_18[1].checked)) {
            errors += 'Please check radio button whether or not you are under 18 years of age.'+"\n";
        }
        if (f.name == 'EmploymentApplication') {
            if (phone.value.replace(/ /g,'').length <= 0) {
                errors += 'Please enter your phone number.'+"\n";
            }
            if (!(days_available.checked || evenings_available.checked || nights_available.checked || weekends_available.checked)) {
                errors += 'Please revisit availability section and check appropriate checkboxes.'+"\n";
            }
            if (expected_salary.value.replace(/ /g,'').length <= 0) {
                errors += 'Please enter expected salary.'+"\n";
            }
            if (!wages.options[wages.selectedIndex].value) {
                errors += 'Please select appropriate option from drop down list next to the Salary expected field.'+"\n";
            }
            if (!position.options[position.selectedIndex].value &&
                other_position.value.replace(/ /g,'').length <= 0) {
                errors += 'Please select the position you apply for.'+"\n";
            }
            if (position.options[position.selectedIndex].value == 'Other' &&
                other_position.value.replace(/ /g,'').length <= 0) {
                errors += 'Please type in the other position you apply for.'+"\n";
            }

            if (!highest_grade.options[highest_grade.selectedIndex].value &&
                other_grade_level.value.replace(/ /g,'').length <= 0) {
                errors += 'Please select the Highes grade completed.'+"\n";
            }
            if (highest_grade.options[highest_grade.selectedIndex].value == 'Other' &&
                other_grade_level.value.replace(/ /g,'').length <= 0) {
                errors += 'Please type in the grade level you completed.'+"\n";
            }
            if (school_name_city_state_1.value.replace(/ /g,'').length <= 0) {
                errors += 'Please type in the School name, city and state in Education section.'+"\n";
            }
            if (major_classes_completed_1.value.replace(/ /g,'').length <= 0) {
                errors += 'Please type in the Major classes completed in Education section.'+"\n";
            }
            if (!(graduate_1[0].checked || graduate_1[1].checked)) {
                errors += 'Please check appropriate Did you graduate radio button in Education section.'+"\n";
            }
            if (diploma_degree_1.value.replace(/ /g,'').length <= 0) {
                errors += 'Please type in the Diploma/degree in Education section.'+"\n";
            }
        }
        if (captcha_code.value.replace(/ /g,'').length <= 0) {
            errors += 'Please enter the text from the image.'+"\n";
        }
    }
    if (errors.length > 0) {
        alert(errors);
        return false;
    }
    return true;
}
if (!Array.prototype.indexOf) {
  Array.prototype.indexOf = function(elt /*, from*/) {
    var len = this.length;
    var from = Number(arguments[1]) || 0;
    from = (from < 0) ? Math.ceil(from) : Math.floor(from);
    if (from < 0) {
        from += len;
    }
    for (; from < len; from++) {
      if (from in this && this[from] === elt) {
          return from;
      }
    }
    return -1;
  };
}
