function countrySelect(p_countryCode) {
    $('#state').hide();
    $('#province').hide();
    $('#territory').hide();

    switch (p_countryCode) {
        case 'US': $('#state').show(); break;
        case 'CA': $('#province').show(); break;
        default: if (p_countryCode != '') $('#territory').show(); break;
    }
}

function recurSelect(p_recurType) {
    $('#recurParam').show();
    $('#daily').hide();
    $('#weekly').hide();
    $('#monthly').hide();

    switch (p_recurType) {
        case 'Daily': $('#daily').show(); break;
        case 'Weekly': $('#weekly').show(); break;
        case 'Monthly': $('#monthly').show(); break;
        default: $('#recurParam').hide(); break;
    }
}

function addressCheck() {
    var geocoder = new GClientGeocoder();
    switch ($('#COUNTRY_CODE').val()) {
        case 'US':
            geocoder.getLocations($('#ADDRESS').val() + ' ' + $('#CITY').val() + ', ' + $('#STATE_CODE').val() + ' ' + $('#POSTAL_CODE').val(), addressCheck_callback);
            break;
        case 'CA':
            geocoder.getLocations($('#ADDRESS').val() + ' ' + $('#CITY').val() + ', ' + $('#PROVINCE_CODE').val() + ' ' + $('#POSTAL_CODE').val() + ' Canada', addressCheck_callback);
            break;
        default:
            geocoder.getLocations($('#ADDRESS').val() + ' ' + $('#CITY').val() + ', ' + $('#TERRITORY').val() + ' ' + $('#POSTAL_CODE').val() + $('#COUNTRY_CODE').val(), addressCheck_callback);
            break;
    }
}

function addressCheck_callback(response) {
    if (!response || response.Status.code != 200 || response.Placemark.Length == 0) {
        colorCode(0);
    }
    else {
        colorCode(response.Placemark[0].AddressDetails.Accuracy);
    }

}

function colorCode(accuracy) {
    switch (accuracy) {
        case 8:
        case 9:
            $('#accuracyGauge').removeClass().addClass('google-accurate').html('Accurate. Match found.');
            break;
        case 6:
        case 7:
            $('#accuracyGauge').removeClass().addClass('google-zip').html('Inaccurate. Zip matches.');
            break;
        default:
            $('#accuracyGauge').removeClass().addClass('google-not-close').html('Inaccurate. No matches.');
            break;
    }
}