var adoptapp_data = [ ['realname', 'Please provide your name'], 
                      ['address', 'Please provide your address'],
                      ['city', 'Please provide your city'],
                      ['county', 'Please provide your county'],
                      ['zip', 'Please provide your zip code'],
                      ['home_phone', 'Please provide your home phone number'],
                      ['email_address', 'Please provide your email address'],
                      ['occupation', 'Please provide your occupation'],
                      ['employer', 'Please provide your employer'],
                      ['emp_years', 'Please provide your length of employment'],
                      ['home_check', 'Please indicate your willingness to have a homevisit'],
                      ['age_range', 'Please provide your age range'],
                      ['ilivein', 'Please provide home type'],
                      ['yard', 'Please provide your yard'],
                      ['howlonghome', 'Please select the length of time in home'],
                      ['ownorrent', 'Please select whether you own or rent'],
                      ['full_fee', 'Please indicate if you can pay the full adoption fee'],
                      ['adopt_mix', 'Please select your willingness to adopt a mixed-breed Saint'],
                      ['hours_alone', 'Please select the number of hours alone for the dog'],
                      ['while_away', 'Please tell us where the Saint will stay while you are away from home'],
                      ['whowillcare', 'Please tell us who will care for the Saint'],
                      ['wheresleep', 'Please tell us where the Saint will sleep'],
                      ['wherevacation', 'Please tell how the Saint will be cared for while you are on vacation'],
                      ['food', 'Please provide BRAND of dog food'],
                      ['housetrain', 'Please indicate your willingness to house-train'],
                      ['ifmove', 'Please tell us where the dog will go if you move'],
                      ['alonekids', 'Please indicate if the dog will be left alone with kids'],
                      ['ownpickup', 'Please tell us if you own a pickup'],
                      ['pickupback', 'Please indicate if the dog will ride in the back of the pickup'],
                      ['fullyaware', 'Please indicate that you are fully aware of our Adoption Policies'],
                      ['refname1', 'Please provide your first reference name'],
                      ['refphone1', 'Please provide your first reference phone number'],
                      ['refname2', 'Please provide your second reference name'],
                      ['refphone2', 'Please provide your second reference phone number'],
                      ['refname3', 'Please provide your third reference name'],
                      ['refphone3', 'Please provide your third reference phone number']
                  ];

function get_form_value(form_name,form_element){
    if(document[form_name][form_element].length != null){
        var type = document[form_name][form_element].type;
    }
    if((typeof(type) == 'undefined') || (type == 0)){
         var type = document[form_name][form_element].type;
    }
    switch(type)
    {
        case 'undefined': return;
        case 'radio':
                for(var x=0; x < document[form_name][form_element].length; x++) 
                        if(document[form_name][form_element[x]].checked == true)
                return document[form_name][form_element[x]].value;
        case 'select-one':
				var selected = document[form_name][form_element].selectedIndex;
				return document[form_name][form_element].options[selected].text;
        case 'select-multiple':
                var myArray = new Array();
                for(var x=0; x < document.form_name.form_element.length; x++) 
                        if(document[form_name][form_element[x]].selected == true)
                                myArray[myArray.length] = document[form_name][form_element[x]].value;
                return myArray;
        case 'checkbox': return document[form_name][form_element].checked;
    
        default: return document[form_name][form_element].value;
    }
}

function validate_form(form_name,required_elements){
    for(var i in required_elements){
        if (get_form_value(form_name,required_elements[i][0]) == ''){
            alert(required_elements[i][1] + '.');
            document[form_name][required_elements[i][0]].focus();
			return false;
        }
    }
	return true;
}

function init_adoptapp(state,prev_state){
    state_selects('state_select','state','select',state);
    state_selects('prev_state_select','prev_state','select',prev_state);
}
    
function init_fosterapp(state,prev_state){
    state_selects('state_select','state','select',state);
    state_selects('prev_state_select','prev_state','select',prev_state);
}
    
function init_volunteerapp(state,prev_state){
    state_selects('state_select','state','select',state);
}
    
function state_selects(div_id,sel_name,sel_class,selected_val){
    if (selected_val == '') { selected_val = 'CO'; }
    var states = ['AL','AK','AS','AZ','AR','CA','CO','CT','DE','DC','FM','FL','GA','GU','HI', 'ID','IL','IN','IA',
              'KS','KY','LA','ME','MH','MD','MA','MI','MN','MS','MO', 'MT','NE','NV','NH','NJ','NM','NY','NC',
              'ND','MP','OH','OK','OR','PW','PA', 'PR','RI','SC','SD','TN','TX','UT','VT','VI','VA','WA','WV','WI','WY']; 
    var string = '<SELECT ID=' + sel_name + ' NAME=' + sel_name + ' CLASS=' + sel_class + '>';
    var selected;
    for (var i in states) {
        if (states[i] == selected_val) {
             selected = 'selected';
        } 
        else {
            selected = '';
        }
        string += '<OPTION ' + selected + '>' + states[i];
    }
    document.getElementById(div_id).innerHTML = string;
}

