// Contact Us BizForm

$(function () {

    // display state/provinces based on default/selected country
	
    var countryValue = $("#bizform select[id$='country'] option:selected").val();
    whichState(countryValue, 1);

    $("#bizform select[id$='country']").change(function () {
        countryValue = $("#bizform select[id$='country'] option:selected").val();
        whichState(countryValue, 0);
    });
	

	// set the hidden state field based on which us state or canadian province is selected
    $("#bizform #us_states select, #bizform #au_states select, #bizform #ca_provinces select").change(function () {
        popState($("option:selected", this).val());
    });

});

function whichState(c, s) {
    if (s == 1) {
        $("#bizform #us_states, #bizform #au_states, #bizform #ca_provinces").hide();
        if (c == 'US') {
            $("#bizform #us_states").show();
        }
        if (c == 'AU') {
            $("#bizform #au_states").show();
        }
        if (c == 'CA') {
            $("#bizform #ca_provinces").show();
        }
    }
    if (s == 0) {
        popState('');
        if (c != 'US' && c != 'AU' && c != 'CA') {
            $("#bizform #us_states, #bizform #au_states, #bizform #ca_provinces").fadeOut();
        } else {
            $("#bizform #us_states, #bizform #au_states, #bizform #ca_provinces").hide();
        }
        if (c == 'US') {
            $("#bizform #us_states").fadeIn();
        }
        if (c == 'AU') {
            $("#bizform #au_states").fadeIn();
        }
        if (c == 'CA') {
            $("#bizform #ca_provinces").fadeIn();
        }
    }
}

function popState(x) {
    $("#bizform div[id='state'] input[id$='state']").val(x);
    if (x == '') {
        $("#bizform #us_states select, #bizform #au_states select, #bizform #ca_provinces select").val('');
    }
}


