-function displayMessage( set ) {
- CRM.$(function($) {
- if ( set ) {
- $('#locUsedMsg').html( locUsedMsgTxt ).addClass('status');
- } else {
- $('#locUsedMsg').html( ' ' ).removeClass('status');
- }
- });
-}
-
-function showLocFields( ) {
- var createNew = document.getElementsByName("location_option")[0].checked;
- var useExisting = document.getElementsByName("location_option")[1].checked;
- if ( createNew ) {
- cj('#existingLoc').hide();
- //clear all location fields values.
- cj("input[id *= 'address_1_']").val("");
- cj("input[id *= 'email_1_']").val("");
- cj("input[id *= 'phone_1_']").val("");
- //reset country/state.
- cj("select[id *= 'address_1_']").val("");
- displayMessage(false);
- } else if ( useExisting ) {
- cj('#existingLoc').show();
- }
-}
-
-showLocFields( );
+ function showLocFields(clear) {
+ var createNew = document.getElementsByName("location_option")[0].checked;
+ if (createNew) {
+ $('#existingLoc', $form).hide();
+ //clear all location fields values.
+ if (clear !== false) {
+ $(":input[id *= 'address_1_'], :input[id *= 'email_1_'], :input[id *= 'phone_1_']", $form).val("").change();
+ {/literal}{if $config->defaultContactCountry}
+ {if $config->defaultContactStateProvince}
+ // Set default state once options are loaded
+ var defaultState = {$config->defaultContactStateProvince}
+ {literal}
+ $('#address_1_state_province_id', $form).one('crmOptionsUpdated', function() {
+ $(this).val(defaultState).change();
+ });
+ {/literal}
+ {/if}
+ // Set default country
+ $('#address_1_country_id', $form).val({$config->defaultContactCountry}).change();
+ {/if}{literal}
+ }
+ displayMessage(0);
+ } else {
+ $('#existingLoc', $form).show();
+ if (clear !== false) {
+ $('#loc_event_id', $form).change();
+ }
+ }
+ }
+
+ $('input[name=location_option]').click(showLocFields);
+ showLocFields(false);
+
+ function displayMessage(count) {
+ if (count) {
+ var msg = {/literal}'{ts escape="js" 1="%1"}This location is used by %1 other events. Modifying location information will change values for all events.{/ts}'{literal};
+ $('#locUsedMsg', $form).text(ts(msg, {1: count})).addClass('status');
+ } else {
+ $('#locUsedMsg', $form).text(' ').removeClass('status');
+ }
+ }
+});