$(document).ready(function() {
var wrapper = $('fieldset.editable-list.fields');
var list = wrapper.find('ol');
var template = wrapper.find('script[name=template]').html();
var baseInputName = wrapper.find('script[name=template]').attr('data-base-input-name');
var data = eval(wrapper.find('script[name=data]').html());
var reverseLookupData = eval($('script[name=reverse_lookups]').html());
var index = 0;
var domFieldVal = function(domField, fieldName, val) {
var el = domField.find('input[data-field=' + fieldName + '], select[data-field=' + fieldName + ']');
return (typeof(val) == 'undefined' ? el.val() : el.val(val));
}
var domBoxAttr = function(fieldName) {
return $('#fancybox-wrap form').find('input[name=custom_fields_field[' + fieldName + ']], select[name=custom_fields_field[' + fieldName + ']]');
}
var domBoxAttrVal = function(fieldName, val) {
return (typeof(val) == 'undefined' ? domBoxAttr(fieldName).val() : domBoxAttr(fieldName).val(val));
}
var setupReverseLookupDropdown = function(currentVal) {
var dropdown = $('#fancybox-inner #edit-custom-field #custom_fields_field_reverse_lookup');
// Get the target content_type
var targetClassEl = $('#fancybox-inner #edit-custom-field #custom_fields_field_target');
var callback = function() {
// Clear the reverse_lookup dropdown
dropdown.find('option').remove();
// Add the initial blank entry
dropdown.append($('