// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
var charity_selected_from_lightbox = function(charity_id) {
  Lightbox.hideBox();
 
  var url = "/charities/" + charity_id + ".json"
 
  new Ajax.Request(url, {
    method: 'get',
    onSuccess: function(transport) {
      var charity = transport.responseJSON.charity;
          
      if (charity) {
        $('charity_name').value = charity.name;
        $('charity_city').value = charity.city;
        $('charity_state').value = charity.state;
        $('charity_zip').value = charity.zipcode;
        $('charity_contact').value = charity.contact_person;
        $('charity_phone').value = charity.contact_phone;
        $('charity_email').value = charity.email;
        $('charity_tax').value = charity.tax_id_number;
        $('charity_address').value = charity.address;
        selectValue('charity_organization_type', charity.organization_type, 6);
      } 
    }
  });
}

// Nested form support
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();
}
