function nextQ(field) {
    if(field == window.document.form1.COUNTRY_01) {
        initState();
    }
    return;
}

function selectValue(field, value) {
    for(var i = 0; i < field.options.length; i++) {
        if(field.options[i].value == value) {
            field.options[i].selected = true
            return;
        }
    }
    return;
}

function initState() {
    var countryValue = getFieldValueLB(window.document.form1.COUNTRY_01);
    var stateField = window.document.form1.STATE_01;
    var value = getFieldValueLB(stateField);
    if(countryValue == "USA") {
       showUSStates();
    } else if (countryValue == "CAN") {
       showCANStates();
    }  else {
        stateField.length=0;
        stateField.options[stateField.length] = new Option("Select State","");    
        stateField.disabled = true;
        return;
    }
    selectValue(stateField,value);
    stateField.disabled = false;
    return;
}

function showUSStates() {
    var stateField = window.document.form1.STATE_01;
    stateField.enabled = true;
    stateField.length=0;
    stateField.options[stateField.length] = new Option("Select State","");    
    stateField.options[stateField.length] = new Option("Alabama","AL");
    stateField.options[stateField.length] = new Option("Alaska","AK");
    stateField.options[stateField.length] = new Option("American Samoa ","AS");
    stateField.options[stateField.length] = new Option("Arizona","AZ");
    stateField.options[stateField.length] = new Option("Arkansas","AR");
    stateField.options[stateField.length] = new Option("Armed Forces Africa","AE");
    stateField.options[stateField.length] = new Option("Armed Forces Americas","AA");
    stateField.options[stateField.length] = new Option("Armed Forces Canada","AE");
    stateField.options[stateField.length] = new Option("Armed Forces Europe","AE");
    stateField.options[stateField.length] = new Option("Armed Forces Middle East","AE");
    stateField.options[stateField.length] = new Option("Armed Forces Pacific","AP");
    stateField.options[stateField.length] = new Option("California","CA");
    stateField.options[stateField.length] = new Option("Colorado","CO");
    stateField.options[stateField.length] = new Option("Connecticut","CT");
    stateField.options[stateField.length] = new Option("Delaware","DE");
    stateField.options[stateField.length] = new Option("District of Columbia","DC");
    stateField.options[stateField.length] = new Option("Federated States of Micronesia","FM");
    stateField.options[stateField.length] = new Option("Florida","FL");
    stateField.options[stateField.length] = new Option("Georgia","GA");
    stateField.options[stateField.length] = new Option("Guam","GU");
    stateField.options[stateField.length] = new Option("Hawaii","HI");
    stateField.options[stateField.length] = new Option("Idaho","ID");
    stateField.options[stateField.length] = new Option("Illinois","IL");
    stateField.options[stateField.length] = new Option("Indiana","IN");
    stateField.options[stateField.length] = new Option("Iowa","IA");
    stateField.options[stateField.length] = new Option("Kansas","KS");
    stateField.options[stateField.length] = new Option("Kentucky","KY");
    stateField.options[stateField.length] = new Option("Louisiana","LA");
    stateField.options[stateField.length] = new Option("Maine","ME");
    stateField.options[stateField.length] = new Option("Marshall Islands","MH");
    stateField.options[stateField.length] = new Option("Maryland","MD");
    stateField.options[stateField.length] = new Option("Massachusetts","MA");
    stateField.options[stateField.length] = new Option("Michigan","MI");
    stateField.options[stateField.length] = new Option("Minnesota","MN");
    stateField.options[stateField.length] = new Option("Mississippi","MS");
    stateField.options[stateField.length] = new Option("Missouri","MO");
    stateField.options[stateField.length] = new Option("Montana","MT");
    stateField.options[stateField.length] = new Option("Nebraska","NE");
    stateField.options[stateField.length] = new Option("Nevada","NV");
    stateField.options[stateField.length] = new Option("New Hampshire","NH");
    stateField.options[stateField.length] = new Option("New Jersey","NJ");
    stateField.options[stateField.length] = new Option("New Mexico","NM");
    stateField.options[stateField.length] = new Option("New York","NY");
    stateField.options[stateField.length] = new Option("North Carolina","NC");
    stateField.options[stateField.length] = new Option("North Dakota","ND");
    stateField.options[stateField.length] = new Option("Northern Mariana Islands","MP");
    stateField.options[stateField.length] = new Option("Ohio","OH");
    stateField.options[stateField.length] = new Option("Oklahoma","OK");
    stateField.options[stateField.length] = new Option("Oregon","OR");
    stateField.options[stateField.length] = new Option("Palau","PW");
    stateField.options[stateField.length] = new Option("Pennsylvania","PA");
    stateField.options[stateField.length] = new Option("Rhode Island","RI");
    stateField.options[stateField.length] = new Option("South Carolina","SC");
    stateField.options[stateField.length] = new Option("South Dakota","SD");
    stateField.options[stateField.length] = new Option("Tennessee","TN");
    stateField.options[stateField.length] = new Option("Texas","TX");
    stateField.options[stateField.length] = new Option("Utah","UT");
    stateField.options[stateField.length] = new Option("Vermont","VT");
    stateField.options[stateField.length] = new Option("Virgin Islands","VI");
    stateField.options[stateField.length] = new Option("Virginia","VA");
    stateField.options[stateField.length] = new Option("Washington","WA");
    stateField.options[stateField.length] = new Option("District of Columbia","DC");
    stateField.options[stateField.length] = new Option("West Virginia","WV");
    stateField.options[stateField.length] = new Option("Wisconsin","WI");
    stateField.options[stateField.length] = new Option("Wyoming","WY");
}

function showCANStates() {
    var stateField = window.document.form1.STATE_01;
    stateField.enabled = true;
    stateField.length=0;
    stateField.options[stateField.length] = new Option("Select Province","");
    stateField.options[stateField.length] = new Option("Alberta","AB");
    stateField.options[stateField.length] = new Option("British Columbia","BC");
    stateField.options[stateField.length] = new Option("Manitoba","MB");
    stateField.options[stateField.length] = new Option("New Brunswick","NB");
    stateField.options[stateField.length] = new Option("Newfoundland","NF");
    stateField.options[stateField.length] = new Option("Northwest Territories","NT");
    stateField.options[stateField.length] = new Option("Nova Scotia","NS");
    stateField.options[stateField.length] = new Option("Nunavut","NU");
    stateField.options[stateField.length] = new Option("Ontario","ON");
    stateField.options[stateField.length] = new Option("Prince Edward Island","PE");
    stateField.options[stateField.length] = new Option("Quebec","QC");
    stateField.options[stateField.length] = new Option("Saskatchewan","SK");
    stateField.options[stateField.length] = new Option("Yukon Territory","YT");
}

function validate_PROVINCE_01(form) {
    var countryField = form.COUNTRY_01;
    var countryValue = getFieldValueLB(countryField);
    if(countryValue == "USA" || countryValue == "CAN") {
        return validate_STATE_01(form);
    }

    var field = form.PROVINCE_01;
    var value = getFieldValueTF(field)
    if(!validateIsRequired(value)) {
        alert("Please enter Other Province (if not listed).");
        field.focus();
        return false;
    }
    return true;
}

function validate_AIU_UNDERSTAND_01() {
    var len = window.document.form1.elements.length;
    var i=0;
    for(i=0;i<len;i++) {
        if(window.document.form1.elements[i].type==('checkbox')) {
            if(window.document.form1.elements[i].checked == true) {
                return true;
            }
        }
    }
    alert( "Please check the box indicating your understanding that you will be contacted by an AIU Online Admissions Advisor." );
    window.document.form1.AIU_UNDERSTAND_01.focus();
    return false;
}
