$(document).ready(function() {
  if ($("select[name='billing_address[country_id]']").size() == 1) {
  if ($("select[name='billing_address[country_id]']").val() == "5209061"){
    $(".billing_selector").hide();
    $("#billing_address_mx_state").val($("#billing_address_state").val()).show();
  } else if ($("select[name='billing_address[country_id]']").val() == "5750247"){
    $(".billing_selector").hide();
    $("#billing_address_us_state").val($("#billing_address_state").val()).show();
  } else {
    $(".billing_selector").hide();
    $("#billing_address_other_state").val($("#billing_address_state").val()).show();
  };
  
  if ($("select[name='shipping_address[country_id]']").val() == "5209061"){
    $(".shipping_selector").hide();
    $("#shipping_address_mx_state").val($("#shipping_address_state").val()).show();
  } else if ($("select[name='shipping_address[country_id]']").val() == "5750247"){
    $(".shipping_selector").hide();
    $("#shipping_address_us_state").val($("#shipping_address_state").val()).show();
  } else {
    $(".shipping_selector").hide();
    $("#shipping_address_other_state").val($("#shipping_address_state").val()).show();
  };
  
  };
  
  $("select[name='billing_address[country_id]']").change(function(){
    if ($(this).val() == "5209061"){
      $(".billing_selector").hide();
      $("#billing_address_mx_state").show();
    } else if ($(this).val() == "5750247"){
      $(".billing_selector").hide();
      $("#billing_address_us_state").show();
    } else {
      $(".billing_selector").hide();
      $("#billing_address_other_state").show();
    };
  });

  $("#billing_address_mx_state, #billing_address_us_state, #billing_address_other_state").change(function(){
    var temp_response = $(this).val();
    $("#billing_address_state").val(temp_response);
  });


  $("select[name='shipping_address[country_id]']").change(function(){
    if ($(this).val() == "5209061"){
      $(".shipping_selector").hide();
      $("#shipping_address_mx_state").show();
    } else if ($(this).val() == "5750247"){
      $(".shipping_selector").hide();
      $("#shipping_address_us_state").show();
    } else {
      $(".shipping_selector").hide();
      $("#shipping_address_other_state").show();
    };
  });

  $("#shipping_address_mx_state, #shipping_address_us_state, #shipping_address_other_state").change(function(){
    var temp_response = $(this).val();
    $("#shipping_address_state").val(temp_response);
  });



});