function fadeAll(elements) {
    elements.each( function(element){ $(element).fade() } );
}

function appearAll(elements) {
    elements.each( function(element){ $(element).appear() } );
}

function peekABoo(ids_as_array, is_true ) {
  if (is_true == true ) {
    appearAll(ids_as_array);
  }  else {
    fadeAll(ids_as_array);
  }
}

function display_country_dependants( select, array_of_ids ) {
    country_field = $(select);
    if ( country_field.value == 'United States' ) {
        appearAll(array_of_ids);
      } else if ( country_field.value != '' ) {
        array_of_ids.each(
            function(id){
                field = $(id);
                if ( field.style.display != 'none' ) {
                    field.fade();
                }
            } );
      } else {
        appearAll(array_of_ids);
      }
}

function insert_fields(link, method, content) {
  var new_id = new Date().getTime();
  var regexp = new RegExp("new_" + method, "g")
  $(link).up().insert({
    before: content.replace(regexp, new_id)
  });
}
 
function remove_fields(link) {
  var hidden_field = $(link).previous("input[type=hidden]");
  if (hidden_field) {
    hidden_field.value = '1';
  }
  $(link).up(".fields").hide();
}