jQuery(document).ready(function($){var load_ui_css=false;$('#start-time').each(function(i,el){$(el).addClass('em-time-input em-time-start').next('#end-time').addClass('em-time-input em-time-end').parent().addClass('em-time-range');});if($(".em-time-input").length>0){em_setup_timepicker('body');} $('.em-calendar-wrapper a').unbind("click");$('.em-calendar-wrapper a').undelegate("click");$('.em-calendar-wrapper').delegate('a.em-calnav, a.em-calnav','click',function(e){e.preventDefault();$(this).closest('.em-calendar-wrapper').prepend('
');var url=em_ajaxify($(this).attr('href'));$(this).closest('.em-calendar-wrapper').load(url,function(){$(this).trigger('em_calendar_load');});});$(document).delegate('.em-toggle','click change',function(e){e.preventDefault();var el=$(this);var rel=el.attr('rel').split(':');if(el.hasClass('show-search')){if(rel.length>1){el.closest(rel[1]).find(rel[0]).slideUp();} else{$(rel[0]).slideUp();} el.find('.show, .show-advanced').show();el.find('.hide, .hide-advanced').hide();el.removeClass('show-search');}else{if(rel.length>1){el.closest(rel[1]).find(rel[0]).slideDown();} else{$(rel[0]).slideDown();} el.find('.show, .show-advanced').hide();el.find('.hide, .hide-advanced').show();el.addClass('show-search');}});if(EM.search_term_placeholder){if('placeholder'in document.createElement('input')){$('input.em-events-search-text, input.em-search-text').attr('placeholder',EM.search_term_placeholder);}else{$('input.em-events-search-text, input.em-search-text').blur(function(){if(this.value=='')this.value=EM.search_term_placeholder;}).focus(function(){if(this.value==EM.search_term_placeholder)this.value='';}).trigger('blur');}} $('.em-search-form select[name=country]').change(function(){var el=$(this);$('.em-search select[name=state]').html('');$('.em-search select[name=region]').html('');$('.em-search select[name=town]').html('');if(el.val()!=''){el.closest('.em-search-location').find('.em-search-location-meta').slideDown();var data={action:'search_states',country:el.val(),return_html:true};$('.em-search select[name=state]').load(EM.ajaxurl,data);data.action='search_regions';$('.em-search select[name=region]').load(EM.ajaxurl,data);data.action='search_towns';$('.em-search select[name=town]').load(EM.ajaxurl,data);}else{el.closest('.em-search-location').find('.em-search-location-meta').slideUp();}});$('.em-search-form select[name=region]').change(function(){$('.em-search select[name=state]').html('');$('.em-search select[name=town]').html('');var data={action:'search_states',region:$(this).val(),country:$('.em-search-form select[name=country]').val(),return_html:true};$('.em-search select[name=state]').load(EM.ajaxurl,data);data.action='search_towns';$('.em-search select[name=town]').load(EM.ajaxurl,data);});$('.em-search-form select[name=state]').change(function(){$('.em-search select[name=town]').html('');var data={action:'search_towns',state:$(this).val(),region:$('.em-search-form select[name=region]').val(),country:$('.em-search-form select[name=country]').val(),return_html:true};$('.em-search select[name=town]').load(EM.ajaxurl,data);});$(document).delegate('.em-search-form, .em-events-search-form','submit',function(e){var form=$(this);if(this.em_search&&this.em_search.value==EM.txt_search){this.em_search.value='';} var results_wrapper=form.closest('.em-search-wrapper').find('.em-search-ajax');if(results_wrapper.length==0)results_wrapper=$('.em-search-ajax');if(results_wrapper.length>0){results_wrapper.append('');var submitButton=form.find('.em-search-submit');submitButton.data('buttonText',submitButton.val()).val(EM.txt_searching);var img=submitButton.children('img');if(img.length>0)img.attr('src',img.attr('src').replace('search-mag.png','search-loading.gif'));var vars=form.serialize();$.ajax(EM.ajaxurl,{type:'POST',dataType:'html',data:vars,success:function(responseText){submitButton.val(submitButton.data('buttonText'));if(img.length>0)img.attr('src',img.attr('src').replace('search-loading.gif','search-mag.png'));results_wrapper.replaceWith(responseText);if(form.find('input[name=em_search]').val()==''){form.find('input[name=em_search]').val(EM.txt_search);} results_wrapper=form.closest('.em-search-wrapper').find('.em-search-ajax');if(results_wrapper.length==0)results_wrapper=$('.em-search-ajax');jQuery(document).triggerHandler('em_search_ajax',[vars,results_wrapper,e]);}});e.preventDefault();return false;}});if($('.em-search-ajax').length>0){$(document).delegate('.em-search-ajax a.page-numbers','click',function(e){var a=$(this);var data=a.closest('.em-pagination').attr('data-em-ajax');var wrapper=a.closest('.em-search-ajax');var wrapper_parent=wrapper.parent();var qvars=a.attr('href').split('?');var vars=qvars[1];if(data!=''){vars=vars!=''?vars+'&'+data:data;} wrapper.append('');$.ajax(EM.ajaxurl,{type:'POST',dataType:'html',data:vars,success:function(responseText){wrapper.replaceWith(responseText);wrapper=wrapper_parent.find('.em-search-ajax');jQuery(document).triggerHandler('em_search_ajax',[vars,wrapper,e]);}});e.preventDefault();return false;});} $('.events-table').on('click','.em-event-delete',function(){if(!confirm("Are you sure you want to delete?")){return false;} window.location.href=this.href;});$('#event-form #event-image-delete, #location-form #location-image-delete').on('click',function(){var el=$(this);if(el.is(':checked')){el.closest('.event-form-image, .location-form-image').find('#event-image-img, #location-image-img').hide();}else{el.closest('.event-form-image, .location-form-image').find('#event-image-img, #location-image-img').show();}});if($("#em-tickets-form").length>0){$('#event-rsvp').click(function(event){if(!this.checked){confirmation=confirm(EM.disable_bookings_warning);if(confirmation==false){event.preventDefault();}else{$('#event-rsvp-options').hide();}}else{$('#event-rsvp-options').fadeIn();}});if($('input#event-rsvp').is(":checked")){$("div#rsvp-data").fadeIn();}else{$("div#rsvp-data").hide();} var reset_ticket_forms=function(){$('#em-tickets-form table tbody tr.em-tickets-row').show();$('#em-tickets-form table tbody tr.em-tickets-row-form').hide();};if($('#em-recurrence-checkbox').length>0){$('#em-recurrence-checkbox').change(function(){if($('#em-recurrence-checkbox').is(':checked')){$('#em-tickets-form .ticket-dates-from-recurring, #em-tickets-form .ticket-dates-to-recurring, #event-rsvp-options .em-booking-date-recurring').show();$('#em-tickets-form .ticket-dates-from-normal, #em-tickets-form .ticket-dates-to-normal, #event-rsvp-options .em-booking-date-normal, #em-tickets-form .hidden').hide();}else{$('#em-tickets-form .ticket-dates-from-normal, #em-tickets-form .ticket-dates-to-normal, #event-rsvp-options .em-booking-date-normal').show();$('#em-tickets-form .ticket-dates-from-recurring, #em-tickets-form .ticket-dates-to-recurring, #event-rsvp-options .em-booking-date-recurring, #em-tickets-form .hidden').hide();}}).trigger('change');}else if($('#em-form-recurrence').length>0){$('#em-tickets-form .ticket-dates-from-recurring, #em-tickets-form .ticket-dates-to-recurring, #event-rsvp-options .em-booking-date-recurring').show();$('#em-tickets-form .ticket-dates-from-normal, #em-tickets-form .ticket-dates-to-normal, #event-rsvp-options .em-booking-date-normal, #em-tickets-form .hidden').hide();}else{$('#em-tickets-form .ticket-dates-from-recurring, #em-tickets-form .ticket-dates-to-recurring, #event-rsvp-options .em-booking-date-recurring, #em-tickets-form .hidden').hide();} $("#em-tickets-add").click(function(e){e.preventDefault();reset_ticket_forms();var tickets=$('#em-tickets-form table tbody');var rowNo=tickets.length+1;var slot=tickets.first().clone(true).attr('id','em-ticket-'+rowNo).appendTo($('#em-tickets-form table'));slot.find('*[name]').each(function(index,el){el=$(el);el.attr('name',el.attr('name').replace('em_tickets[0]','em_tickets['+rowNo+']'));});slot.show().find('.ticket-actions-edit').trigger('click');slot.find('.em-date-input-loc').datepicker('destroy').removeAttr('id');slot.find('.em-time-input').unbind().each(function(index,el){this.timePicker=false;});em_setup_datepicker(slot);em_setup_timepicker(slot);$('html, body').animate({scrollTop:slot.offset().top-30});});$(document).delegate('.ticket-actions-edit','click',function(e){e.preventDefault();reset_ticket_forms();var tbody=$(this).closest('tbody');tbody.find('tr.em-tickets-row').hide();tbody.find('tr.em-tickets-row-form').fadeIn();return false;});$(document).delegate('.ticket-actions-edited','click',function(e){e.preventDefault();var tbody=$(this).closest('tbody');var rowNo=tbody.attr('id').replace('em-ticket-','');tbody.find('.em-tickets-row').fadeIn();tbody.find('.em-tickets-row-form').hide();tbody.find('*[name]').each(function(index,el){el=$(el);if(el.attr('name')=='ticket_start_pub'){tbody.find('span.ticket_start').text(el.attr('value'));}else if(el.attr('name')=='ticket_end_pub'){tbody.find('span.ticket_end').text(el.attr('value'));}else if(el.attr('name')=='em_tickets['+rowNo+'][ticket_type]'){if(el.find(':selected').val()=='members'){tbody.find('span.ticket_name').prepend('* ');}}else if(el.attr('name')=='em_tickets['+rowNo+'][ticket_start_recurring_days]'){var text=tbody.find('select.ticket-dates-from-recurring-when').val()=='before'?'-'+el.attr('value'):el.attr('value');if(el.attr('value')!=''){tbody.find('span.ticket_start_recurring_days').text(text);tbody.find('span.ticket_start_recurring_days_text, span.ticket_start_time').removeClass('hidden').show();}else{tbody.find('span.ticket_start_recurring_days').text(' - ');tbody.find('span.ticket_start_recurring_days_text, span.ticket_start_time').removeClass('hidden').hide();}}else if(el.attr('name')=='em_tickets['+rowNo+'][ticket_end_recurring_days]'){var text=tbody.find('select.ticket-dates-to-recurring-when').val()=='before'?'-'+el.attr('value'):el.attr('value');if(el.attr('value')!=''){tbody.find('span.ticket_end_recurring_days').text(text);tbody.find('span.ticket_end_recurring_days_text, span.ticket_end_time').removeClass('hidden').show();}else{tbody.find('span.ticket_end_recurring_days').text(' - ');tbody.find('span.ticket_end_recurring_days_text, span.ticket_end_time').removeClass('hidden').hide();}}else{tbody.find('.'+el.attr('name').replace('em_tickets['+rowNo+'][','').replace(']','').replace('[]','')).text(el.attr('value'));}});$(document).triggerHandler('em_maps_tickets_edit',[tbody,rowNo,true]);$('html, body').animate({scrollTop:tbody.parent().offset().top-30});return false;});$(document).delegate('.em-ticket-form select.ticket_type','change',function(e){var el=$(this);if(el.find('option:selected').val()=='members'){el.closest('.em-ticket-form').find('.ticket-roles').fadeIn();}else{el.closest('.em-ticket-form').find('.ticket-roles').hide();}});$(document).delegate('.em-ticket-form .ticket-options-advanced','click',function(e){e.preventDefault();var el=$(this);if(el.hasClass('show')){el.closest('.em-ticket-form').find('.em-ticket-form-advanced').fadeIn();el.find('.show,.show-advanced').hide();el.find('.hide,.hide-advanced').show();}else{el.closest('.em-ticket-form').find('.em-ticket-form-advanced').hide();el.find('.show,.show-advanced').show();el.find('.hide,.hide-advanced').hide();} el.toggleClass('show');});$('.em-ticket-form').each(function(){var show_advanced=false;var el=$(this);el.find('.em-ticket-form-advanced input[type="text"]').each(function(){if(this.value!='')show_advanced=true;});if(el.find('.em-ticket-form-advanced input[type="checkbox"]:checked').length>0){show_advanced=true;} el.find('.em-ticket-form-advanced option:selected').each(function(){if(this.value!='')show_advanced=true;});if(show_advanced)el.find('.ticket-options-advanced').trigger('click');});$(document).delegate('.ticket-actions-delete','click',function(e){e.preventDefault();var el=$(this);var tbody=el.closest('tbody');if(tbody.find('input.ticket_id').val()>0){el.text('Deleting...');$.getJSON($(this).attr('href'),{'em_ajax_action':'delete_ticket','id':tbody.find('input.ticket_id').val()},function(data){if(data.result){tbody.remove();}else{el.text('Delete');alert(data.error);}});}else{tbody.remove();} return false;});} if($('#em-bookings-table').length>0){$(document).delegate('#em-bookings-table .tablenav-pages a','click',function(){var el=$(this);var form=el.parents('#em-bookings-table form.bookings-filter');var match=el.attr('href').match(/#[0-9]+/);if(match!=null&&match.length>0){var pno=match[0].replace('#','');form.find('input[name=pno]').val(pno);}else{form.find('input[name=pno]').val(1);} form.trigger('submit');return false;});var em_bookings_settings_dialog={modal:true,autoOpen:false,minWidth:500,height:'auto',buttons:[{text:EM.bookings_settings_save,click:function(e){e.preventDefault();var match=$("#em-bookings-table form.bookings-filter [name=cols]").val('');var booking_form_cols=$('form#em-bookings-table-settings-form input.em-bookings-col-item');$.each(booking_form_cols,function(i,item_match){if(item_match.value==1){if(match.val()!=''){match.val(match.val()+','+item_match.name);}else{match.val(item_match.name);}}});$('#em-bookings-table-settings').trigger('submitted');$('#em-bookings-table form.bookings-filter').trigger('submit');$(this).dialog('close');}}]};var em_bookings_export_dialog={modal:true,autoOpen:false,minWidth:500,height:'auto',buttons:[{text:EM.bookings_export_save,click:function(e){$(this).children('form').submit();$(this).dialog('close');}}]};if($("#em-bookings-table-settings").length>0){$("#em-bookings-table-settings").dialog(em_bookings_settings_dialog);$(document).delegate('#em-bookings-table-settings-trigger','click',function(e){e.preventDefault();$("#em-bookings-table-settings").dialog('open');});$("#em-bookings-table-export").dialog(em_bookings_export_dialog);$(document).delegate('#em-bookings-table-export-trigger','click',function(e){e.preventDefault();$("#em-bookings-table-export").dialog('open');});var export_overlay_show_tickets=function(){if($('#em-bookings-table-export-form input[name=show_tickets]').is(':checked')){$('#em-bookings-table-export-form .em-bookings-col-item-ticket').show();$('#em-bookings-table-export-form #em-bookings-export-cols-active .em-bookings-col-item-ticket input').val(1);}else{$('#em-bookings-table-export-form .em-bookings-col-item-ticket').hide().find('input').val(0);}};$('#em-bookings-table form select').each(function(i,el){$(el).change(function(e){var select_el=$(this);var input_par=$('#em-bookings-table-export-form input[name='+select_el.attr('name')+']');var input_par_selected=select_el.find('option:selected');input_par.val(input_par_selected.val());});});export_overlay_show_tickets();$('#em-bookings-table-export-form input[name=show_tickets]').click(export_overlay_show_tickets);$(".em-bookings-cols-sortable").sortable({connectWith:".em-bookings-cols-sortable",update:function(event,ui){if(ui.item.parents('ul#em-bookings-cols-active, ul#em-bookings-export-cols-active').length>0){ui.item.addClass('ui-state-highlight').removeClass('ui-state-default').children('input').val(1);}else{ui.item.addClass('ui-state-default').removeClass('ui-state-highlight').children('input').val(0);}}}).disableSelection();load_ui_css=true;} $(document).delegate('#em-bookings-table form.bookings-filter','submit',function(e){var el=$(this);el.parents('#em-bookings-table').find('.table-wrap').first().append('');$.post(EM.ajaxurl,el.serializeArray(),function(data){var root=el.parents('#em-bookings-table').first();root.replaceWith(data);$('#em-bookings-table-export input[name=scope]').val(root.find('select[name=scope]').val());$('#em-bookings-table-export input[name=status]').val(root.find('select[name=status]').val());jQuery(document).triggerHandler('em_bookings_filtered',[data,root,el]);});return false;});$(document).delegate('.em-bookings-approve,.em-bookings-reject,.em-bookings-unapprove,.em-bookings-delete','click',function(){var el=$(this);if(el.hasClass('em-bookings-delete')){if(!confirm(EM.booking_delete)){return false;}} var url=em_ajaxify(el.attr('href'));var td=el.parents('td').first();td.html(EM.txt_loading);td.load(url);return false;});} if($('.em_bookings_events_table').length>0){$(document).delegate('.em_bookings_events_table form','submit',function(e){var el=$(this);var url=em_ajaxify(el.attr('action'));el.parents('.em_bookings_events_table').find('.table-wrap').first().append('');$.get(url,el.serializeArray(),function(data){el.parents('.em_bookings_events_table').first().replaceWith(data);});return false;});$(document).delegate('.em_bookings_events_table .tablenav-pages a','click',function(){var el=$(this);var url=em_ajaxify(el.attr('href'));el.parents('.em_bookings_events_table').find('.table-wrap').first().append('');$.get(url,function(data){el.parents('.em_bookings_events_table').first().replaceWith(data);});return false;});} $('a.em-booking-button').click(function(e){e.preventDefault();var button=$(this);if(button.text()!=EM.bb_booked&&$(this).text()!=EM.bb_booking){button.text(EM.bb_booking);var button_data=button.attr('id').split('_');$.ajax({url:EM.ajaxurl,dataType:'jsonp',data:{event_id:button_data[1],_wpnonce:button_data[2],action:'booking_add_one'},success:function(response,statusText,xhr,$form){if(response.result){button.text(EM.bb_booked);}else{button.text(EM.bb_error);} if(response.message!='')alert(response.message);},error:function(){button.text(EM.bb_error);}});} return false;});$('a.em-cancel-button').click(function(e){e.preventDefault();var button=$(this);if(button.text()!=EM.bb_cancelled&&button.text()!=EM.bb_canceling){button.text(EM.bb_canceling);var button_data=button.attr('id').split('_');$.ajax({url:EM.ajaxurl,dataType:'jsonp',data:{booking_id:button_data[1],_wpnonce:button_data[2],action:'booking_cancel'},success:function(response,statusText,xhr,$form){if(response.result){button.text(EM.bb_cancelled);}else{button.text(EM.bb_cancel_error);}},error:function(){button.text(EM.bb_cancel_error);}});} return false;});if($('.em-date-single, .em-date-range, #em-date-start').length>0){if(EM.locale!='en'&&EM.locale_data){$.datepicker.setDefaults(EM.locale_data);} load_ui_css=true;em_setup_datepicker('body');} if(load_ui_css)em_load_jquery_css();function updateIntervalDescriptor(){$(".interval-desc").hide();var number="-plural";if($('input#recurrence-interval').val()==1||$('input#recurrence-interval').val()=="") number="-singular";var descriptor="span#interval-"+$("select#recurrence-frequency").val()+number;$(descriptor).show();} function updateIntervalSelectors(){$('p.alternate-selector').hide();$('p#'+$('select#recurrence-frequency').val()+"-selector").show();} function updateShowHideRecurrence(){if($('input#event-recurrence').is(":checked")){$("#event_recurrence_pattern").fadeIn();$("#event-date-explanation").hide();$("#recurrence-dates-explanation").show();$("h3#recurrence-dates-title").show();$("h3#event-date-title").hide();}else{$("#event_recurrence_pattern").hide();$("#recurrence-dates-explanation").hide();$("#event-date-explanation").show();$("h3#recurrence-dates-title").hide();$("h3#event-date-title").show();}} $("#recurrence-dates-explanation").hide();$("#date-to-submit").hide();$("#end-date-to-submit").hide();$("#localised-date").show();$("#localised-end-date").show();$('#em-wrapper input.select-all').change(function(){if($(this).is(':checked')){$('input.row-selector').prop('checked',true);$('input.select-all').prop('checked',true);}else{$('input.row-selector').prop('checked',false);$('input.select-all').prop('checked',false);}});updateIntervalDescriptor();updateIntervalSelectors();updateShowHideRecurrence();$('input#event-recurrence').change(updateShowHideRecurrence);$('input#recurrence-interval').keyup(updateIntervalDescriptor);$('select#recurrence-frequency').change(updateIntervalDescriptor);$('select#recurrence-frequency').change(updateIntervalSelectors);if($('.em-location-map').length>0||$('.em-locations-map').length>0||$('#em-map').length>0||$('.em-search-geo').length>0){em_maps_load();} if(jQuery("div.em-location-data input#location-name").length>0){jQuery("div.em-location-data input#location-name").autocomplete({source:EM.locationajaxurl,minLength:2,focus:function(event,ui){jQuery("input#location-id").val(ui.item.value);return false;},select:function(event,ui){jQuery("input#location-id").val(ui.item.id).trigger('change');jQuery("input#location-name").val(ui.item.value);jQuery('input#location-address').val(ui.item.address);jQuery('input#location-town').val(ui.item.town);jQuery('input#location-state').val(ui.item.state);jQuery('input#location-region').val(ui.item.region);jQuery('input#location-postcode').val(ui.item.postcode);if(ui.item.country==''){jQuery('select#location-country option:selected').removeAttr('selected');}else{jQuery('select#location-country option[value="'+ui.item.country+'"]').attr('selected','selected');} jQuery('div.em-location-data input, div.em-location-data select').css('background-color','#ccc').attr('readonly','readonly');jQuery('#em-location-reset').show();jQuery('#em-location-search-tip').hide();jQuery(document).triggerHandler('em_locations_autocomplete_selected',[event,ui]);return false;}}).data("ui-autocomplete")._renderItem=function(ul,item){html_val=""+item.label+'