PageSourceSearch

https://heavenaddress.com/public/js/site_311.js

js heavenaddress.com collected 2026-10-02 07:19:30 UTC 146,911 bytes, 4,255 lines download raw bytes

1var ha = {};
2var ajaxPackage = {
3    ajax: {
4        init: function (url, data, successCallback, errorCallback, dataType, async) {
5            dataType = typeof dataType !== 'undefined' ? dataType : 'json';
6            async = typeof async !== 'undefined' ? async : true;
7            $.ajax({
8                url: url,
9                type: 'POST',
10                data: data,
11                async: async,
12                dataType: dataType,
13                success: function (data) {
14                    successCallback(data);
15                },
16                error: function (xhr, ajaxOptions, thrownError) {
17                    if(typeof errorCallback  !== 'undefined'){
18                        errorCallback(xhr, ajaxOptions, thrownError);
19                    }
20                    ha.ajax.defaultErrorCallback(xhr, ajaxOptions, thrownError);
21                }
22            });
23        },
24
25        defaultErrorCallback: function (xhr, ajaxOptions, thrownError) {
26            console.log(xhr);
27        },
28
29        submitRelationship: function (data, callback) {
30            var url = $('#active-archive form').attr('action');
31            $("#myModal").find(".modal-content").html('<div class="modal-body text-center">'+ $('#lang_loading').val()+'</div>');
32            ha.ajax.init(url, data, callback, ha.ajax.defaultErrorCallback);
33        },
34
35        getInstruct: function(memorial_id, callback) {
36            var url = '/instruct';
37            var data = {
38                memorial_id: memorial_id
39            };
40            ha.ajax.init(url, data, callback);
41        }
42
43    }
44};
45$.extend(true, ha, ajaxPackage);
46function display_profile_setting()
47{
48    $('.drop').toggle('fast');
49}
50
51function mark_read_notification()
52{
53    $.ajax({
54        type: 'POST',
55        url: '/profile/remove_notification',
56        dataType: 'json',
57        success: function(response) 
58        {
59            load_top_notification();
60            /*if(response.status == 1)
61            {
62                $('#notification .num_notification a').html(response.no);
63                $('#notification .notify_content li.setable').removeClass('unread');
64                
65                $('#mark_read_all').hide();
66            }*/
67        }
68     });
69}
70
71function display_notification()
72{
73    $('.notify_layout').toggle('fast', function(){
74        load_top_notification();
75    });
76
77}
78
79function display_count_short(count) 
80{
81    var short_num = (count < 999)? count:( (count<9999)? (count/1000).toFixed(1).toString()+"K" :( (count<99999)? (count/1000).toFixed(0).toString()+"K" : (count/1000000).toFixed(1).toString()+"M" )  );
82    //short_num = count.toLocaleString();
83    return short_num;                   
84}
85
86function load_top_notification()
87{
88    $('#notification .notify_content ul').html("<li style='text-align: center; padding:10px; width: 100%'><img src='public/images/loading_more.gif' alt='loading'/></li>");
89    $.ajax({
90        type: 'POST',
91        url: '/chat/ajax_top_notification',
92        data:{is_ajax:1},
93        dataType: 'json',
94        success: function(response) 
95        {
96            if(response.status == 1)
97            {
98                if(response.number > 99)
99                {
100                    $('#notification .num_notification a').html('99+');
101                    $('#num-of-notification').html('99+')
102                    $('.noti-num').html('99+');
103
104                }
105        		else
106        		{
107        			$('#notification .num_notification a').html(response.number);
108                    $('#num-of-notification').html(response.number);
109                    $('.noti-num').html(response.number);
110        		}
111
112        		if(response.number > 0) {
113                    $('.noti-num').removeClass('hidden');
114                    $('#mark_read_all').show();
115                } else {
116                    $('.noti-num').addClass('hidden');
117                    $('#mark_read_all').hide();
118
119                }
120
121                $('#notification .notify_content ul').html(response.html);
122                check_and_load_scrollpane(response.html);
123
124        	}
125        }
126     });
127}
128
129function show_content_msg(memorial_id, content_id)
130{
131    if(content_id > 0)
132        {
133            $.ajax({
134                type: 'POST',
135                url: '/not_controller/'+memorial_id+'/memorabilia/' + content_id,
136                success: function(response) {
137                    $('#content_msg_'+content_id).html(response);
138                    $('#read_more_'+content_id).hide();
139                }
140             });
141        }
142    else
143        {
144            $.ajax({
145                type: 'POST',
146                url: '/memorial/ajax_get_memorial/'+memorial_id,
147                dataType: 'json',
148                success: function(response) {
149                    $('#content_msg_'+memorial_id).html(response.obituary_message);
150                    $('#read_more_'+memorial_id).hide();
151                }
152             });
153        }
154}
155
156function check_and_load_scrollpane(response_html){
157    if ($('#notification .notify_content ul').length > 0)
158    {
159        if(typeof pane_api != 'undefined')
160        {
161            pane_api.destroy();
162        }
163        /* Using for IE, 'pane_api.destroy()' remove all li tags in ul  */
164        if($('#notification .notify_content ul').html() == '')
165        {
166            $('#notification .notify_content ul').html(response_html);
167        }
168        pane = $('#notification .notify_content ul');
169        pane.jScrollPane({showArrows:true,autoReinitialise:false});
170        pane_api = pane.data('jsp');
171    }
172}
173
174function popup_linking(memorial_id)
175{
176    url = '/profile/popup_linking/' + memorial_id;
177    $.nmManual( url, {
178        callbacks : {
179            afterClose: function() {
180                //document.location = redirect;
181            }
182        }
183    });
184}
185
186function popup_linking_magnific(memorial_id)
187{
188    var url = '/profile/popup_linking/' + memorial_id + '/-/?responsive=true';
189    $('#myModal').modal('show').find('.modal-content').load(url);
190}
191
192
193function popup_why_donate()
194{
195    url = '/home/popup_why_donate?responsive=true';
196     $.magnificPopup.open({
197        items: {
198            src: url,
199        },
200
201        tLoading: '',
202        type: 'ajax',
203        mainClass: 'ha-popup',
204        fixedContentPos: true,
205        closeOnBgClick: false,
206        closeOnContentClick: false,
207        preloader: true,
208        overflowY: 'scroll',
209        showCloseBtn:false
210    });
211}
212
213function popup_unlink(memorial_id)
214{
215    url = '/profile/popup_unlink/' + memorial_id;
216    
217    $.nmManual( url, {
218        callbacks : {
219            afterClose: function() {
220                //document.location = redirect;
221            }
222        }
223    });
224}
225
226function popup_unlink_magnific(memorial_id)
227{
228    url = '/profile/popup_unlink/' + memorial_id + '/?responsive=true';
229    open_magnific_ajax_popup(url);
230}
231
232var DateFormatting = {
233
234    init: function()
235    {
236        var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
237
238        // Loop over and write in the date formatted using the local
239        $('span.convertTimestamp').each(function()
240        {
241            var utcDate = new Date($(this).html());
242
243            // Add leading zeros
244            // Hours
245            var hours = new String(utcDate.getHours());
246
247//          if (hours.length == 1)
248//          {
249//              hours = '0' + utcDate.getHours();
250//          }
251            var ampm = '';
252            if (hours > 12)
253            {
254                hours = hours - 12;
255                ampm = 'PM';
256            }
257            else
258            {
259                ampm = 'AM';
260            }
261
262            // Minutes
263            var minutes = new String(utcDate.getMinutes());
264
265            if (minutes.length == 1)
266            {
267                minutes = '0' + utcDate.getMinutes();
268            }
269
270            // Seconds
271            var seconds = new String(utcDate.getSeconds());
272
273            if (seconds.length == 1)
274            {
275                seconds = '0' + utcDate.getSeconds();
276            }
277
278            //$(this).html(utcDate.getDate() + ' ' + months[utcDate.getMonth()] + ' ' + utcDate.getFullYear() + ' ' + hours + ':' + minutes + ':' + seconds);
279            $(this).html(utcDate.getDate() + ' ' + months[utcDate.getMonth()] + ' ' + utcDate.getFullYear() + ' ' + hours + ':' + minutes + ampm );
280            $(this).removeClass('convertTimestamp');
281        });
282    }
283};
284
285function direct_to_donation(el, url)
286{
287    if(donation_confirm_message == 'm_donation_confirm')
288    {
289        res = confirm("You are being directed to a secure page for the donation process. Please click OK to proceed.");
290    }
291    else
292    {
293        res = confirm(donation_confirm_message);
294    }
295
296    if(res)
297    {
298        //window.open(url);
299    }
300
301    // this attribute will be used by other event handler (ie. track-link event handler)
302    $(el).attr('data-confirm', res);
303    return res
304}
305
306function direct_to_donation_sg(el, url, memorial_id, company_id)
307{
308    if(res = confirm(donation_confirm_message))
309    {
310        if (company_id ) {
311            $.ajax({
312                type: 'POST',
313                url: '/donation/send_email_donation/'+memorial_id + '/' + company_id,
314                data : {url:url},
315                dataType: 'json',
316                success: function(response) {
317                }
318            });
319        }
320        //window.open(url);
321    }
322
323    $(el).attr('data-confirm', res);
324    return res;    
325}
326function direct_to_donation_comchest(el, url, memorial_id, company_id)
327{
328    if(res = confirm('You are being directed to Community Chest website for the donation process. Please click OK to proceed.'))
329    {
330        if (company_id ) {
331            $.ajax({
332                type: 'POST',
333                url: '/donation/send_email_donation/'+memorial_id + '/' + company_id,
334                data : {url:url},
335                dataType: 'json',
336                success: function(response) {
337                }
338            });
339        }
340        //window.open(url);
341    }
342
343    $(el).attr('data-confirm', res);
344    return res;
345}
346
347function resize_iframe_onload(width, container){
348    var i = 0;
349    var intervalIframe = setInterval(function() {
350        i++;
351        var contentHeight = $('.'+ container).height() + 50;
352        var iframeHeight = $('.mfp-iframe', window.parent.document).height() + 50;
353        
354         if(contentHeight == 50 && i > 20)
355         {
356             contentHeight = $('.iframe-popup-container').height();
357             iframeHeight = $('.mfp-iframe', window.parent.document).height();
358         }
359
360        if(contentHeight == iframeHeight && (contentHeight != 50 && iframeHeight != 50) || i==100)
361        {
362            clearInterval(intervalIframe);
363        }
364        //set width and height for container
365        $('.mfp-content', window.parent.document).css({
366            'width': width+'px',
367            'max-width': '95%',
368            'height' : contentHeight+'px'
369        })
370    }, 1);
371}
372
373function resize_iframe_onload_upload_wizard(width, container){
374    // var i = 0;
375    var intervalIframe = setInterval(function() {
376        // i++;
377        var contentHeight = $('.'+ container).height() + 100;
378        var iframeHeight = $('.mfp-iframe', window.parent.document).height() + 100;
379
380        if(contentHeight == iframeHeight && (contentHeight != 100 && iframeHeight != 100)) //|| i==300)
381        {
382            clearInterval(intervalIframe);
383        }
384        //set width and height for container
385        $('.mfp-content', window.parent.document).css({
386            'width': width+'px',
387            'max-width': '95%',
388            'height' : contentHeight+'px'
389        })
390    }, 1);
391}
392
393function resize_iframe_onload_msg_email_notification(width, container){
394    var intervalIframe = setInterval(function() {
395
396        var contentHeight = $('.'+ container).height() + 50;
397        var iframeHeight = $('.mfp-iframe', window.parent.document).height() + 50;
398
399        if(contentHeight == iframeHeight && (contentHeight != 50 && iframeHeight != 50))
400        {
401            clearInterval(intervalIframe);
402        }
403        contentHeight = contentHeight - 22;
404        //set width and height for container
405        $('.mfp-content', window.parent.document).css({
406            'width': width+'px',
407            'max-width': '95%',
408            'height' : contentHeight+'px'
409        })
410    }, 1);
411}
412
413function resize_iframe_onload_height(height){
414    //set width and height for container
415    $('.mfp-content', window.parent.document).css({
416      'height' : height+'px'
417    });
418
419    $('.billing_forgot_pass', window.parent.document).css({
420        'height' : '40px'
421    });
422}
423
424function open_magnific_iframe_popup(url){
425
426    var curLength = 0;
427    var interval;
428    $.magnificPopup.close();
429    $.magnificPopup.open({
430        items: {
431            src: url,
432        },
433
434        type:'iframe',
435        closeOnBgClick: false,
436        closeOnContentClick: false,
437        mainClass: 'ha-iframe-popup',
438        disableOn: false,
439        preloader: true,
440        fixedContentPos: true,
441        tLoading: '',
442        overflowY: 'scroll',
443        iframe: {
444            markup: '<div class="mfp-iframe-scaler ">'+
445                '<div class="mfp-close"></div>'+
446                '<iframe class="mfp-iframe magnific-popup-container" frameborder="0" allowfullscreen scrolling="no"></iframe>'+
447            '</div>', // HTML markup of popup, `mfp-close` will be replaced by the close button
448        },
449
450        callbacks: {
451            beforeAppend: function() {
452               interval = setInterval(function() {
453                    if ($('iframe').length !== curLength) {
454                        curLength = $('.column-header').length;
455                        $('.mfp-content').css('visibility', 'hidden');
456                        $('.mfp-preloader').show();
457
458                    }
459                }, 1);
460            },
461            beforeOpen: function() { 
462                var iOS = ( navigator.userAgent.match(/iPad|iPhone|iPod/g) ? true : false );
463                if(iOS == true){
464                    $('html').addClass('mfp-helper');     
465                }
466                
467            },
468            open: function(){
469                this.content.find('iframe').on('load', function() {
470                    clearInterval(interval);
471                    setTimeout(function() {
472                        $('.mfp-content').css('visibility', 'visible');
473                        $('.mfp-preloader').hide();   
474                    },900);
475                });
476            },
477
478             close: function(){
479                $('html').removeClass('mfp-helper');
480             }
481        },
482    });
483}
484
485
486function open_magnific_ajax_popup(url){
487    $.magnificPopup.open({
488        items: {
489            src: url,
490        },
491        tLoading: '',
492        type: 'ajax',
493        mainClass: 'ha-popup',
494        fixedContentPos: true,
495        closeOnBgClick: false,
496        closeOnContentClick: false,
497        preloader: true,
498        overflowY: 'scroll',
499        showCloseBtn: true
500    });
501}
502
503function open_magnific_ajax_popup_close(url){
504    $.magnificPopup.open({
505        items: {
506            src: url,
507        },
508        tLoading: '',
509        type: 'ajax',
510        mainClass: 'ha-popup',
511        fixedContentPos: true,
512        closeOnBgClick: true,
513        closeOnContentClick: true,
514        preloader: true,
515        overflowY: 'scroll',
516        showCloseBtn: false
517    });
518}
519
520function open_magnific_inline_popup(open_obj){
521    $.magnificPopup.open({
522        items: {
523            src: '#'+open_obj
524        },
525        tLoading: '',
526        type:'inline',
527        mainClass: 'ha-popup',
528        fixedContentPos: true,
529        closeOnBgClick: false,
530        closeOnContentClick: false,
531        preloader: true,
532        overflowY: 'scroll',
533        showCloseBtn:false
534    });
535}
536
537$(document).ready(function(){
538
539    $('body').on('click', '.magnific-iframe-popup', function(e){
540        e.preventDefault();
541        var url = $(this).attr('href');
542        open_magnific_iframe_popup(url);
543        return false;
544    });
545
546    $('body').on('click', '.bs-modal-normal', function(e){
547        e.preventDefault();
548        var url = $(this).attr('href');
549        open_modal(url);
550        return false;
551    });
552    
553    $('body').on('click', '.authentication-popup', function(e){
554        e.preventDefault();
555        var url = $(this).attr('href');
556        open_modal(url, 'custom');
557        return false;
558    });
559
560    $('body').on('click', '.magnific-ajax-popup', function(e){
561        e.preventDefault();
562        var url = $(this).attr('href');
563        open_magnific_ajax_popup(url);
564        return false;
565    });
566
567    $('body').on('click', '.magnific-ajax-popup-close', function(e){
568        e.preventDefault();
569        var url = $(this).attr('href');
570        open_magnific_ajax_popup_close(url);
571        return false;
572    });
573
574     $('body').on('click', '.closePopup', function(e){
575        e.preventDefault();
576        if (window.parent == window.top) {
577          window.parent.$.magnificPopup.close();
578        }
579        else{
580            $.magnificPopup.close();
581        }
582    });
583
584    $('body').on('click', 'a.track-link',function() {
585        var resource_type = '';
586        var resource_id = '';
587
588        $('.recent-activity a,.recent-activity img,.highlight-images a').not('.no-tip').tipTip();
589        $("input[type='text'], textarea").labelify({ replaceEmptyOnly: true, labelledClass: "labelHighlight" });
590        
591        if (typeof dataLayer !== 'undefined') {
592            resource_type = dataLayer[0].resource_type;
593            resource_id = dataLayer[0].resource_id;
594        }
595        
596        if(!($(this).hasClass('nyroModal') || $(this).attr('target') == '_blank' || $(this).data('toggle') == 'modal'))
597        {
598            var url = this.href;
599            $.ajax({
600                url:"/home/track_link/",
601                type: "POST",
602                data:  {page:window.location.href, id:this.id, href:this.href, res_type:resource_type, res_id:resource_id},
603                success:function(){
604                    window.location.href = url;
605                },
606                error:function (xhr, textStatus, thrownError){
607                }
608            });
609            return false;
610        }
611        else
612        {
613            $.post('/home/track_link', {page:window.location.href, id:this.id, href:this.href, res_type:resource_type, res_id:resource_id});
614        }
615    });
616
617    //open relationship box
618    $('body').on('click', '.connect_status',function(){
619        id = $(this).attr('id');
620        info = id.substr(8,id.length);
621        value = {'info' : info};
622        url = '/profile/show_request_relationship/'+info;
623
624        $.nmManual( url, {} 
625        );
626    });
627
628    $('body').on('click', '.connect_status_magnific',function(){
629        id = $(this).attr('id');
630        info = id.substr(8,id.length);
631        value = {'info' : info};
632        url = '/profile/show_request_relationship/'+info+'/?responsive=true';
633        open_magnific_iframe_popup(url);
634
635        // $.nmManual( url, {} 
636        // );
637    });
638
639    $('body').on('click', '#msg', function(){
640        $('#msg_box').toggle('normal',function(){
641            //$.nmTop().resize(true);
642            //$('.nyroModalCont').css('height',320);
643            $('.nyroModalCont').css('height',$('.nyroModalCont').contents().height() + 20);
644        });
645        
646
647    });
648
649
650    $('body').on('click', 'a.parent-link', function() {
651
652        window.top.location = $(this).attr('data-href');
653        window.parent.$.magnificPopup.instance.updateStatus('loading');
654        $('.mfp-content', window.parent.document).hide();
655        $('.mfp-preloader', window.parent.document).show();
656    });
657
658    //Reload modal content
659    $('#myModal, #myCustomModal, #myLargerModal').on("show.bs.modal", function(e) {
660        var link = $(e.relatedTarget);
661        if(link.attr("href"))
662        {
663            $(this).find(".modal-content").load(link.attr("href"));
664        }
665    });
666
667    $('#myModal, #myCustomModal, #myLargerModal').on("hide.bs.modal", function(e) {
668        $(e.target).find(".modal-content").html('<div class="modal-body">Loading...</div>');
669    });
670});
671
672function pad(number, length) {
673    var str = '' + number;
674    while (str.length < length) {
675        str = '0' + str;
676    }
677
678    return str;
679}
680
681/* ===============================
682 | BETWEEN2DATES.JS
683 | Copyright, Andy Croxall ([email protected])
684 | For documentation and demo see http://www.mitya.co.uk/scripts/Calculate-time-between-two-dates-100
685 |
686 | USAGE
687 | This script may be used, distributed and modified freely but this header must remain in tact.
688 | For usage info and demo, including info on args and params, see www.mitya.co.uk/scripts
689 =============================== */
690
691
692function between2Dates(date1, date2, unit){
693    var datePattern = /\d{2}\/\d{2}\/\d{4} \d{2}:\d{2}:\d{2}/;
694    var units = {
695        seconds: 1000,
696        minutes: 1000 * 60,
697        hours: 1000 * 60 * 60,
698        days: 1000 * 60 * 60 * 24,
699        weeks: 1000 * 60 * 60 * 24 * 7,
700        months: 1000 * 60 * 60 * 24 * 7 * 4.3,
701        years: 1000 * 60 * 60 * 24 * 365
702    }
703    if (!date1 || (!datePattern.test(date1) && date1 != 'now') || !date2 || (!datePattern.test(date2) && date2 != 'now') || !units[unit]) {
704        alert("between2Dates() error: one or more of the parameters passed are invalid.");
705        return false;
706    }
707    var date1_obj = new Date(), date2_obj = new Date();
708    if (date1 != 'now') {
709        date1 = date1.split(' ');
710        date1_a = date1[0].split('/');
711        date1_obj = new Date(date1_a[1]+' '+date1_a[0]+' '+date1_a[2]+' '+date1[1]);
712    }
713    if (date2 != 'now') {
714        date2 = date2.split(' ');
715        date2_a = date2[0].split('/');
716        date2_obj = new Date(date2_a[1]+' '+date2_a[0]+' '+date2_a[2]+' '+date2[1]);
717    }
718    return Math.round(Math.abs(date1_obj.getTime() - date2_obj.getTime()) / units[unit]*Math.pow(10,2))/Math.pow(10,2);
719}
720
721function get_age(dob, dod)
722{
723    var today = dod;
724
725    var dob_curr_date = dob.getDate();
726    var dob_curr_month = dob.getMonth() + 1; //months are zero based
727    var dob_curr_year = dob.getFullYear();
728    dob = dob_curr_year + "-" + pad(dob_curr_month,2) + "-" + pad(dob_curr_date,2);
729    var dob_b = pad(dob_curr_date,2) + "/" + pad(dob_curr_month,2) + "/" + dob_curr_year;
730
731    var dod_curr_date = dod.getDate();
732    var dod_curr_month = dod.getMonth() + 1; //months are zero based
733    var dod_curr_year = dod.getFullYear();
734    var dod_b = pad(dod_curr_date,2) + "/" + pad(dod_curr_month,2) + "/" + dod_curr_year;
735
736    var d = dob;
737    if (!/\d{4}\-\d{2}\-\d{2}/.test(d)) {
738        // check valid format
739        return false;
740    }
741    d = d.split("-");
742    var byr = parseInt(d[0]);
743    var nowyear = today.getFullYear();
744
745    if (byr < 1775) {  // check valid year
746        return false;
747    }
748    if(byr >= nowyear) {
749        var days = between2Dates(dob_b + ' 00:00:00', dod_b + ' 00:00:00', 'days');
750        if(days > 31) {
751            var months = between2Dates(dob_b + ' 00:00:00', dod_b + ' 00:00:00', 'months');
752            months = Math.floor(months);
753            return '{"age":'+months+', "unit":"m"}';
754        }
755        else {
756            days = Math.floor(days);
757            return '{"age":'+days+', "unit":"d"}';
758        }
759    }
760    var bmth = parseInt(d[1],10)-1;
761    if (bmth<0 || bmth>11) {
762        // check valid month 0-11
763        return false;
764    }
765    var bdy = parseInt(d[2],10);
766    if (bdy<1 || bdy>31) {
767        // check valid date according to month
768        return false;
769    }
770    var age = nowyear - byr;
771    var nowmonth = today.getMonth();
772    var nowday = today.getDate();
773    if (bmth > nowmonth) {
774        age = age - 1;
775    }  // next birthday not yet reached
776    else if (bmth == nowmonth && nowday < bdy) {
777        age = age - 1;
778    }
779    return '{"age":'+age+', "unit":"y"}';
780}
781
782function strtohex(str) {
783    var hex, i;
784    var result = "";
785    for (i=0; i<str.length; i++) {
786        hex = str.charCodeAt(i).toString(16);
787        result += ("000"+hex).slice(-4);
788    }
789    return result;
790}
791
792function select_message_magnific(id)
793{
794    $.ajax({
795        type: 'POST',
796        url: '/tag_message/get_message/' + id,
797        dataType: 'json',
798        success: function(response) {
799            $('.post_panel .content_post textarea',window.parent.document).val(response.message).focus().val(response.message);
800                
801            if (window.parent == window.top) {
802              window.parent.$.magnificPopup.close();
803
804            }
805        }
806     });
807}
808
809function to_english_time(time, language_code)
810{
811    console.log('to_english_time language_code:');
812    console.log(language_code);
813    if (language_code == 'zh-CN' || language_code == 'zh-TW')
814    {
815        var am_pm_tmp = time.substr(0, 2);
816        var am_pm = '';
817        switch (am_pm_tmp)
818        {
819            case '凌晨':
820            case '上午':
821                am_pm = 'AM';
822                break;
823            case '下午':
824            case '晚上':
825                am_pm = 'PM';
826                break;
827        }
828        time_tmp = time.substr(2, 5);
829        time_tmp = time_tmp.split(':');
830        var hour = time_tmp[0];
831        var min = time_tmp[1];
832        var time_val = hour + ':' + min + ' ' + am_pm;
833    }
834    else if (language_code == 'es' || language_code == 'fr')
835    {
836        var time_tmp = time.split(':');
837        var hour = time_tmp[0];
838        var min = time_tmp[1];
839        var am_pm = 'AM';
840        if (hour >=12)
841        {
842            hour -= 12;
843            am_pm = 'PM';
844        }
845        var time_val = hour + ':' + min + ' ' + am_pm;
846        console.log('time_val:');
847        console.log(time_val);
848    }
849    else if (language_code == 'pt')
850    {
851        if (time == 'Meia-noite')
852        {
853            var time_val = '12:00 AM';
854        }
855        else if (time == 'Meio-dia')
856        {
857            var time_val = '12:00 PM';
858        }
859        else
860        {
861            var time_tmp = time.split(':');
862            var hour = time_tmp[0];
863            var min = time_tmp[1].substr(0, 2);
864            var am_pm_tmp = time_tmp[1].substr(6, 3);
865
866            if (am_pm_tmp == 'man')
867            {
868                var time_val = hour + ':' + min + ' AM';
869            }
870            else
871            {
872                var time_val = hour + ':' + min + ' PM';
873            }
874        }
875    }
876    return time_val;
877}
878
879function setBereavementRegisterHoverText(jqueryObj) {
880    var bereavementContent = '<div>If someone you know has died, The Australian Bereavement Register can help reduce the amount of unwanted promotional addressed advertising mail being sent to them, stopping painful daily reminders.';
881    bereavementContent += 

'<p><p>';
882    bereavementContent += 'By registering with their free service, the names and addresses of the deceased are removed from mailing lists, stopping most unsolicited mail within as little as eight weeks.</div>';
883    jqueryObj.CreateBubblePopup({
884        position: 'bottom',
885        width: 300,
886        align: 'center',
887        innerHtml: bereavementContent,
888        innerHtmlStyle:  { color:'#000', 'background-color': '#fff','text-align':'justify' },
889        themeName: 'grey',
890        themePath: '/images/jquerybubblepopup-theme'
891    });
892}
893
894function show24hours(language_code)
895{
896    var show24hours;
897    switch (language_code) {
898        case 'es':
899        case 'fr':
900            show24hours = true;
901            break;
902        case 'en':
903        case 'zh-CN':
904        case 'zh-TW':
905        case 'pt':
906        default:
907            show24hours = false;
908    }
909    return show24hours;
910}
911
912function open_modal(url, modal_type)
913{
914    var modalElement = '#myModal';
915    if(modal_type == 'larger')
916    {
917        modalElement = '#myLargerModal';
918    } else if(modal_type == 'custom'){
919        modalElement = '#myCustomModal';
920    }
921
922    $(modalElement).modal();
923    $(modalElement).find(".modal-content").load(url);
924}
925
926function get_branch(element_id, id, last_selected)
927{
928    if(typeof(last_selected)==='undefined') last_selected = '';
929    if(id > 0)
930    {
931        return new Promise(function(resolve) {
932            $.ajax({
933            type: "GET",
934            url: "/create_memorial/get_branch/" + id,
935            dataType: 'json',
936            success: function (data) {
937                resolve(data);
938                if (data.total > 1) {
939                    $('#' + element_id + '_branch_status').val('1');
940                    html = "<select style='width:300px;' id='" + element_id + "_branch' name='" + element_id + "_branch'>";
941                    html += "<option value=''>---</option>";
942                    for (i = 0; i < data.total; i++) {
943                        if (data.branches[i].branch_id == last_selected) {
944                            html += "<option selected='selected' value='" + data.branches[i].branch_id + "'>" + data.branches[0].branch_name + ' (' + data.branches[0].formatted_address + ')' + "</option>";
945                        }
946                        else {
947                            html += "<option value='" + data.branches[i].branch_id + "'>" + data.branches[0].branch_name + ' (' + data.branches[0].formatted_address + ')' + "</option>";
948                        }
949                    }
950                    html += "</select>";
951                    $("#" + element_id + "_show").html(html);
952                }
953                else if (data.total == 1) {
954                    $('#' + element_id + '_branch_status').val('0');
955                    html = "<input type='hidden' value='" + data.branches[0].branch_id + "' name='" + element_id + "_branch' id='" + element_id + "_branch' />";
956                    $("#" + element_id + "_show").html(data.branches[0].branch_name + ' (' + data.branches[0].formatted_address + ')' + html);
957                }
958                $("select[name='" + element_id + "_branch']").uniform();
959            }
960        });
961    });
962    }
963    else
964    {
965        $('#'+element_id+'_branch_status').val('0');
966        $("#"+element_id+"_show").html('');
967    }
968}
969
970/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
971 *                                                           *
972 * Impression Tracking                                       *
973 *                                                           *
974 * Documentation available at the following URL:             *
975 * https://wiki.gheaven.com/doku.php?id=impression_tracking  *
976 *                                                           *
977 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
978
979var HATracking = (function(){
980    var Track = {};
981    Track.contentImpressionList = [];
982    
983    Track.ContentImpression = function(element, for_event)
984    {
985        this.tracked_content = element.attr('data-content-type');
986
987        if(this.tracked_content == null) // Impressions are created from elements with this attribute, so this check is only for actions.
988        {
989            console.log('data-content-type must be set on elements that are to be used for content actions.');
990            return []; // Return an empty array to signify that initialisation failed.
991        }        
992
993        this.object_id = element.attr('id');
994        this.resource_key = element.attr('data-resource-key');
995        this.resource_value = element.attr('data-resource-value');
996
997        if(this.resource_key == null || this.resource_value == null)
998        {
999            console.log('data-resource-key and data-resource-value must be set on elements that are to be used for c
999ontent impressions.');
1000            return []; // Return an empty array to signify that initialisation failed.
1001        }
1002
1003        var href = element.attr('data-content-url');
1004        var href_type = null;
1005        if(href != null && (href == 'link_href' || href == 'image_src')) // If the content-url attribute is 'link_href' or 'image_src', move that to href_type and leave href as null.
1006        {
1007            href_type = href;
1008            href = null;
1009        }
1010        if(href == null) // If we don't have a href from the content-url attribute, see if we can determine one automatically.
1011        {
1012            if(element.is('a') && (href_type == null || href_type == 'link_href')) // For a link element, get the href (unless content-url is set to 'image_src').
1013            {
1014                href = element.attr('href');
1015                href_type = 'link_href';
1016            }
1017            else if(element.is('img')) // For an image element, get the src.
1018            {
1019                href = element.attr('src');
1020                href_type = 'image_src';
1021            }
1022            else // If the element isn't a link or image, check if it's a wrapper for a single link or image, and get the href or src from there.
1023            {
1024                var element_children = element.find('img, a');
1025                if(element_children.length == 1)
1026                {
1027                    if(element_children.is('a'))
1028                    {
1029                        href = element_children.attr('href');
1030                        href_type = 'link_href';
1031                    }
1032                    else if(element_children.is('img'))
1033                    {
1034                        href = element_children.attr('src');
1035                        href_type = 'image_src';
1036                    }
1037                }
1038            }
1039        }
1040        if(href == null) // If we still don't have a href, set it null. Also ensure that href_type is null.
1041        {
1042            this.href = null;
1043            href_type = null;
1044        }
1045        else // If we have a href, set it accordingly. If we don't have a href_type, just use 'content_url'.
1046        {
1047            this.href = href;
1048            if(href_type == null)
1049            {
1050                href_type = 'content_url';
1051            }
1052        }
1053        this.href_type = href_type;
1054
1055        // If this call is for an impression (not an event), and is for a link element or the wrapper of a single link element, add an automatic click tracker (we also need to ensure that the element hasn't opted out of this).
1056        var tracked_link_wrapper = (element_children != null && element_children.is('a') && element_children.attr('data-content-action-auto') != 'false');
1057        if(!for_event && (element.is('a') || tracked_link_wrapper) && element.attr('data-content-action-auto') != 'false')
1058        {
1059            tracked_element = tracked_link_wrapper ? element_children : element;
1060            tracked_element.on('click', {tracked_link_wrapper: tracked_link_wrapper, wrapper_element: element}, Track.addAutomaticContentClick);
1061        }
1062    }
1063
1064    Track.trackContentImpressions = function(container_element)
1065    {
1066        var content_type_attribute = '[data-content-type]';
1067        $(container_element).find(content_type_attribute).addBack(content_type_attribute)
1068        .each(function(index, element){
1069            var content_impression = new Track.ContentImpression($(element), false);
1070            if(content_impression instanceof Track.ContentImpression) // This checks if the ContentImpression was created successfully. Error states return an empty array instead of an initialised ContentImpression.
1071            {
1072               Track.contentImpressionList.push(content_impression); 
1073            }
1074        });
1075        if(Track.contentImpressionList.length > 0)
1076        {
1077            Track.saveContentEvent(Track.contentImpressionList, 'content_impression', null, function(){
1078                Track.contentImpressionList = []; // When the content impressions are saved, empty the array so that it's ready for any subsequent calls.
1079            });
1080        }
1081    }
1082
1083    Track.prepareImpressionsForPage = function()
1084    {
1085        Track.trackContentImpressions($('body'));
1086    }
1087
1088    Track.trackContentClick = function(element, tracked_event, callback_function)
1089    {
1090        var impression_element = $(element).attr('data-content-action-element');
1091        var using_nominated_impression_element;
1092        if(impression_element == null) // If this element hasn't nominated a different element, use it directly.
1093        {
1094            impression_element = $(element);
1095            using_nominated_impression_element = false;
1096        }
1097        else // If a different element has been nominated, set it here.
1098        {
1099            impression_element = $(impression_element);
1100            using_nominated_impression_element = true;
1101        }
1102        if(tracked_event == null) // If tracked_event wasn't passed to the function, get it from the data attribute.
1103        {
1104            tracked_event = $(element).attr('data-content-action');
1105            if(tracked_event == null) // The element triggering the event has priority, so only check the nominated element if it's still not set.
1106            {
1107                if(using_nominated_impression_element)
1108                {
1109                    tracked_event = $(impression_element).attr('data-content-action');
1110                }
1111                if(tracked_event == null) // If tracked event is still not set, we don't have enough details to save the content action.
1112                {
1113                    console.log('The tracked event type must be set to record a content action.');
1114                    return false;
1115                }
1116            }
1117        }
1118        // Create a new ContentImpression object, and if successful, save the content action.
1119        var content_impression = new Track.ContentImpression(impression_element, true);
1120        if(content_impression instanceof Track.ContentImpression) // This checks if the ContentImpression was created successfully. Error states return an empty array instead of an initialised ContentImpression.
1121        {
1122            Track.saveContentEvent([content_impression], 'content_action', tracked_event, callback_function);
1123        }
1124    }
1125
1126    Track.addAutomaticContentClick = function(event)
1127    {
1128        event.preventDefault();
1129        var link_element = $(this);
1130        var link_href = link_element.attr('href');
1131        var tracked_event = link_element.attr('data-content-action');
1132        var event_element = link_element;
1133        if(event.data.tracked_link_wrapper) // If this call is triggered by a link that's a child of the impression element, set the wrapper as the event element appropriately.
1134        {
1135            // Only set the wrapper as the event element if the link hasn't nominated a different element.
1136            event_element = link_element.attr('data-content-action-element');
1137            var link_nominated_event_element;
1138            if(event_element == null)
1139            {
1140                event_element = event.data.wrapper_element;
1141                link_nominated_event_element = false;
1142            }
1143            else // If the event has nominated a different element, set that as the event element.
1144            {
1145                event_element = $(event_element);
1146                link_nominated_event_element = true;
1147                if(event_element.attr('data-content-action-auto') == 'false') // If the nominated element has opted out of automatic click tracking, continue to the link target and return from this function.
1148                {
1149                    window.location.href = link_href;
1150                }
1151            }
1152            tracked_event_set_by_wrapper = false;
1153            if(tracked_event == null) // If the link element didn't set the tracked event, check if the wrapper element or nominated element set it (whichever is appropriate).
1154            {
1155                tracked_event = event_element.attr('data-content-action');
1156                tracked_event_set_by_wrapper = true;
1157            }
1158        }
1159        // If the link didn't nominate a different element for the event, check if the wrapper did.
1160        if(!event.data.tracked_link_wrapper || !link_nominated_event_element) // Confusingly, we also do this for links that aren't from a wrapper impression (ie, the link IS the impression element). This is because in this case we didn't enter the previous IF statement. So in this case, we're actually checking if the link itself nominated a different element for the event.
1161        {
1162            var wrapper_nominated_event_element = event_element.attr('data-content-action-element');
1163            if(wrapper_nominated_event_element != null)
1164            {
1165                event_element = $(wrapper_nominated_event_element);
1166                if(tracked_event == null || (event.data.tracked_link_wrapper && tracked_event_set_by_wrapper)) // If the tracked event isn't set, or was set by the wrapper (not the link), see if the nominated element has set the tracked event.
1167                {
1168                    var event_element_tracked_event = event_element.attr('data-content-action');
1169                    if(event_element_tracked_event != null) // We need to check that's it's not null before setting this, otherwise we could override a legitimate event from the wrapper with null.
1170                    {
1171                        tracked_event = event_element_tracked_event;
1172                    }
1173                }
1174                if(event_element.attr('data-content-action-auto') == 'false') // If the nominated element has opted out of automatic click tracking, continue to the link target and return from this function.
1175                {
1176                    window.location.href = link_href;
1177                }
1178            }
1179        }
1180        HATracking.trackContentClick(event_element, (tracked_event == null) ? 'link_click' : tracked_event, function(){
1181            window.location.href = link_href;
1182        });
1183    }
1184
1185    Track.saveContentEvent = function(content_array, event_type, tracked_event, callback_function)
1186    {
1187        var event_data = {};
1188        event_data['url'] = window.location.href;
1189        event_data['event_type'] = event_type;
1190
1191        if(typeof dataLayer !== 'undefined')
1192        {
1193            event_data['dataLayer_resource_key'] = dataLayer[0].resource_type;
1194            event_data['dataLayer_resource_value'] = dataLayer[0].resource_id;
1195        }
1196
1197        var impression_data = [];
1198        $.each(content_array, function(index, impression){
1199            if(event_type == 'content_action')
1200            {
1201                impression['tracked_event'] = tracked_event;
1202            }
1203            impression_data.push(impression);
1204        });
1205        event_data['impression_data'] = JSON.stringify(impression_data);
1206        $.ajax({
1207            url: '/track/track_content_impression',
1208            method: 'POST',
1209            data: event_data,
1210            error: function(){
1211                var data_type = (event_type == 'content_impression') ? 'impression' : 'action';
1212                console.log('Error saving ' + data_type + ' data to the server.');
1213            },
1214            complete: function(){
1215                if(callback_function != null)
1216                {
1217                    callback_function();
1218                }
1219            }
1220        }); 
1221    }
1222
1223    return {
1224        trackContentImpressions: Track.trackContentImpressions,
1225        prepareImpressionsForPage: Track.prepareImpressionsForPage,
1226        trackContentClick: Track.trackContentClick
1227    }
1228})();
1229
1230$(document).ready(HATracking.prepareImpressionsForPage);
1231var EnjoyHint = function (_options) {
1232
1233    var $event_element;
1234    var that = this;
1235
1236    var defaults = {
1237
1238        onStart: function () {
1239
1240        },
1241
1242        onEnd: function () {
1243
1244        },
1245
1246        onSkip: function () {
1247
1248        },
1249
1250        onNext: function () {
1251
1252        },
1253
1254        onClose: function () {
1255
1256        },
1257    };
1258
1259    var options = $.extend(defaults, _options);
1260    var data = [];
1261    var current_step = 0;
1262
1263    $body = $('body');
1264
1265
1266    /********************* PRIVATE METHODS ***************************************/
1267
1268    var init = function () {
1269
1270        if ($('.enjoyhint')) {
1271
1272            $('.enjoyhint').remove();
1273        }
1274
1275        $body.css({'overflow':'hidden'});
1276
1277        $(document).on("touchmove",lockTouch);
1278
1279        $body.enjoyhint({
1280
1281            onNextClick: function () {
1282
1283                nextStep();
1284            },
1285
1286            onSkipClick: function () {
1287
1288                options.onSkip();
1289                skipAll();
1290            },
1291
1292            onCloseClick: function() {
1293                options.onClose();
1294            },
1295        });
1296    };
1297
1298    var lockTouch = function(e) {
1299
1300        e.preventDefault();
1301    };
1302
1303    var destroyEnjoy = function () {
1304
1305        $('.enjoyhint').remove();
1306        $body.css({'overflow':'auto'});
1307        $(document).off("touchmove", lockTouch);
1308    };
1309
1310    that.clear = function(){
1311
1312        var $nextBtn = $('.enjoyhint_next_btn');
1313        var $skipBtn = $('.enjoyhint_skip_btn');
1314
1315        $nextBtn.removeClass(that.nextUserClass);
1316        $nextBtn.text("Next");
1317        $skipBtn.removeClass(that.skipUserClass);
1318        $skipBtn.text("Skip");
1319    };
1320
1321    var stepAction = function () {
1322
1323        if (!(data && data[current_step])) {
1324
1325            $body.enjoyhint('hide');
1326            options.onEnd();
1327            destroyEnjoy();
1328            return;
1329        }
1330
1331        options.onNext();
1332
1333        var $enjoyhint = $('.enjoyhint');
1334
1335        $enjoyhint.removeClass("enjoyhint-step-" + current_step);
1336        $enjoyhint.removeClass("enjoyhint-step-" + (current_step + 1));
1337        $enjoyhint.addClass("enjoyhint-step-" + (current_step + 1));
1338
1339        var step_data = data[current_step];
1340
1341        if (step_data.onBeforeStart && typeof step_data.onBeforeStart === 'function') {
1342
1343            step_data.onBeforeStart();
1344        }
1345
1346        var timeout = step_data.timeout || 0;
1347
1348        setTimeout(function () {
1349
1350            if (!step_data.selector) {
1351
1352                for (var prop in step_data) {
1353
1354                    if (step_data.hasOwnProperty(prop) && prop.split(" ")[1]) {
1355
1356                        step_data.selector = prop.split(" ")[1];
1357                        step_data.event = prop.split(" ")[0];
1358
1359                        if (prop.split(" ")[0] == 'next' || prop.split(" ")[0] == 'auto' || prop.split(" ")[0] == 'custom') {
1360
1361                            step_data.event_type = prop.split(" ")[0];
1362                        }
1363
1364                        step_data.description = step_data[prop];
1365                    }
1366                }
1367            }
1368
1369            setTimeout(function () {
1370
1371                that.clear();
1372            }, 250);
1373
1374            $(document.body).scrollTo(step_data.selector, step_data.scrollAnimationSpeed || 250, {offset: -220});
1375
1376            setTimeout(function () {
1377
1378                var $element = $(step_data.selector);
1379                var event = makeEventName(step_data.event);
1380
1381                $body.enjoyhint('show');
1382                $body.enjoyhint('hide_next');
1383                $event_element = $element;
1384
1385                if (step_data.event_selector) {
1386
1387                    $event_element = $(step_data.event_selector);
1388                }
1389
1390                if (!step_data.event_type && step_data.event == "key") {
1391
1392                    $element.keydown(function (event) {
1393
1394                        if (event.which == step_data.keyCode) {
1395
1396                            current_step++;
1397                            stepAction();
1398                        }
1399                    });
1400                }
1401
1402                if (step_data.showNext == true) {
1403
1404                    $body.enjoyhint('show_next');
1405                }
1406
1407                if (step_data.showSkip == false) {
1408
1409                    $body.enjoyhint('hide_skip');
1410                } else {
1411
1412                    $body.enjoyhint('show_skip');
1413                }
1414
1415                if (step_data.showSkip == true) {
1416
1417                }
1418
1419                if (step_data.nextButton) {
1420
1421                    var $nextBtn = $('.enjoyhint_next_btn');
1422
1423                    $nextBtn.addClass(step_data.nextButton.className || "");
1424                    $nextBtn.text(step_data.nextButton.text || "Next");
1425                    that.nextUserClass = step_data.nextButton.className;
1426                }
1427
1428                if (step_data.skipButton) {
1429
1430                    var $skipBtn = $('.enjoyhint_skip_btn');
1431
1432                    $skipBtn.addClass(step_data.skipButton.className || "");
1433                    $skipBtn.text(step_data.skipButton.text || "Skip");
1434                    that.skipUserClass = step_data.skipButton.className;
1435                }
1436
1437                if (step_data.event_type) {
1438
1439                    switch (step_data.event_type) {
1440
1441                        case 'auto':
1442
1443                            $element[step_data.event]();
1444
1445                            switch (step_data.event) {
1446
1447                                case 'click':
1448                                    break;
1449                            }
1450
1451                            current_step++;
1452                            stepAction();
1453
1454                            return;
1455                            break;
1456
1457                        case 'custom':
1458
1459                            on(step_data.event, function () {
1460
1461                                current_step++;
1462                                off(step_data.event);
1463                                stepAction();
1464                            });
1465
1466                            break;
1467
1468                        case 'next':
1469
1470                            $body.enjoyhint('show_next');
1471                            break;
1472                    }
1473
1474                } else {
1475
1476                    $event_element.on(event, function (e) {
1477
1478                        if (step_data.keyCode && e.keyCode != step_data.keyCode) {
1479
1480                            return;
1481                        }
1482
1483                        current_step++;
1484                        $(this).off(event);
1485
1486                        stepAction(); // clicked
1487                    });
1488                }
1489
1490                var max_habarites = Math.max($element.outerWidth(), $element.outerHeight());
1491                var radius = step_data.radius || Math.round(max_habarites / 2) + 5;
1492                var offset = $element.offset();
1493                var w = $element.outerWidth();
1494                var h = $element.outerHeight();
1495                var shape_margin = (step_data.margin !== undefined) ? step_data.margin : 10;
1496
1497                var coords = {
1498                    x: offset.left + Math.round(w / 2),
1499                    y: offset.top + Math.round(h / 2) - $(document).scrollTop()
1500                };
1501
1502                var shape_data = {
1503                    enjoyHintElementSelector: step_data.selector,
1504                    center_x: coords.x,
1505                    center_y: coords.y,
1506                    text: step_data.description,
1507                    top: step_data.top,
1508                    bottom: step_data.bottom,
1509                    left: step_data.left,
1510                    right: step_data.right,
1511                    margin: step_data.margin,
1512                    scroll: step_data.scroll
1513                };
1514
1515                if (step_data.shape && step_data.shape == 'circle') {
1516
1517                    shape_data.shape = 'circle';
1518                    shape_data.radius = radius;
1519                } else {
1520
1521                    shape_data.radius = 0;
1522                    shape_data.width = w + shape_margin;
1523                    shape_data.height = h + shape_margin;
1524                }
1525
1526                $body.enjoyhint('render_label_with_shape', shape_data, that.stop);
1527            }, step_data.scrollAnimationSpeed + 20 || 270);
1528        }, timeout);
1529    };
1530
1531    var nextStep = function() {
1532
1533        current_step++;
1534        stepAction();
1535    };
1536
1537    var skipAll = function() {
1538
1539        var step_data = data[current_step];
1540        var $element = $(step_data.selector);
1541
1542        off(step_data.event);
1543        $element.off(makeEventName(step_data.event));
1544
1545        destroyEnjoy();
1546    };
1547
1548    var makeEventName = function (name, is_custom) {
1549
1550        return name + (is_custom ? 'custom' : '') + '.enjoy_hint';
1551    };
1552
1553    var on = function (event_name, callback) {
1554
1555        $body.on(makeEventName(event_name, true), callback);
1556    };
1557
1558    var off = function (event_name) {
1559
1560        $body.off(makeEventName(event_name, true));
1561    };
1562
1563
1564    /********************* PUBLIC METHODS ***************************************/
1565
1566    window.addEventListener('resize', function() {
1567
1568        if ($event_element != null) {
1569
1570            $body.enjoyhint('redo_events_near_rect', $event_element[0].getBoundingClientRect());
1571        }
1572    });
1573
1574    that.stop = function() {
1575
1576        skipAll();
1577    };
1578
1579    that.reRunScript = function(cs) {
1580
1581        current_step = cs;
1582        stepAction();
1583    };
1584
1585    that.runScript = function () {
1586
1587        current_step = 0;
1588        options.onStart();
1589        stepAction();
1590    };
1591
1592    that.resumeScript = function () {
1593
1594        stepAction();
1595    };
1596
1597    that.setCurrentStep = function(cs) {
1598
1599        current_step = cs;
1600    };
1601
1602    that.getCurrentStep = function () {
1603
1604        return current_step;
1605    };
1606    that.trigger = function (event_name) {
1607        $body.trigger(makeEventName(event_name, true));
1608    };
1609
1610    that.setScript = function (_data) {
1611
1612        if (_data) {
1613
1614            data = _data;
1615        }
1616    };
1617
1618    //support deprecated API methods
1619    that.set = function (_data) {
1620
1621        that.setScript(_data);
1622    };
1623
1624    that.setSteps = function (_data) {
1625
1626        that.setScript(_data);
1627    };
1628
1629    that.run = function () {
1630
1631        that.runScript();
1632    };
1633
1634    that.resume = function () {
1635
1636        that.resumeScript();
1637    };
1638
1639    init();
1640};;CanvasRenderingContext2D.prototype.roundRect = function (x, y, w, h, r) {
1641
1642    if (w < 2 * r) r = w / 2;
1643    if (h < 2 * r) r = h / 2;
1644    this.beginPath();
1645    this.moveTo(x + r, y);
1646    this.arcTo(x + w, y, x + w, y + h, r);
1647    this.arcTo(x + w, y + h, x, y + h, r);
1648    this.arcTo(x, y + h, x, y, r);
1649    this.arcTo(x, y, x + w, y, r);
1650    this.closePath();
1651    return this;
1652};
1653
1654(function ($) {
1655
1656    var that;
1657
1658    var originalLabelLeft, originalLabelTop;
1659    var originalArrowLeft, originalArrowTop;
1660    var originalCenterX, originalCenterY;
1661    var originalSkipbuttonLeft, originalSkipbuttonTop;
1662    var prevWindowWidth, prevWindowHeight;
1663    var originalWidth = window.innerWidth, originalHeight = window.innerHeight;
1664
1665    var methods = {
1666
1667        init: function (options) {
1668
1669            return this.each(function () {
1670
1671                var defaults = {
1672
1673                    onNextClick: function () {
1674
1675                    },
1676                    onSkipClick: function () {
1677
1678                    },
1679                    onCloseClick: function() {
1680
1681                    },
1682
1683                    animation_time: 800
1684                };
1685
1686                this.enjoyhint_obj = {};
1687                that = this.enjoyhint_obj;
1688
1689                that.resetComponentStuff = function() {
1690
1691                    originalLabelLeft = null;
1692                    originalLabelTop = null;
1693                    originalArrowLeft = null;
1694                    originalArrowTop = null;
1695                    originalCenterX = null;
1696                    originalCenterY = null;
1697                    originalSkipbuttonLeft = null;
1698                    originalSkipbuttonTop = null;
1699                    prevWindowWidth = null;
1700                    prevWindowHeight = null;
1701                    originalWidth = window.innerWidth;
1702                    originalHeight = window.innerHeight;
1703                };
1704
1705
1706                var $that = $(this);
1707                that.options = jQuery.extend(defaults, options);
1708
1709                //general classes
1710                that.gcl = {
1711
1712                    chooser: 'enjoyhint'
1713                };
1714
1715                // classes
1716                that.cl = {
1717
1718                    enjoy_hint: 'enjoyhint',
1719                    hide: 'enjoyhint_hide',
1720                    disable_events_element: 'enjoyhint_disable_events',
1721                    btn: 'enjoyhint_btn',
1722                    skip_btn: 'enjoyhint_skip_btn',
1723                    close_btn: 'enjoyhint_close_btn',
1724                    next_btn: 'enjoyhint_next_btn',
1725                    main_canvas: 'enjoyhint_canvas',
1726                    main_svg: 'enjoyhint_svg',
1727                    svg_wrapper: 'enjoyhint_svg_wrapper',
1728                    svg_transparent: 'enjoyhint_svg_transparent',
1729                    kinetic_container: 'kinetic_container'
1730                };
1731
1732                function makeSVG(tag, attrs) {
1733
1734                    var el = document.createElementNS('http://www.w3.org/2000/svg', tag);
1735
1736                    for (var k in attrs) {
1737
1738                        el.setAttribute(k, attrs[k]);
1739                    }
1740
1741                    return el;
1742                }
1743
1744
1745                // =======================================================================
1746                // ========================---- enjoyhint ----==============================
1747                // =======================================================================
1748
1749                that.canvas_size = {
1750
1751                    w: $(window).width()*1.4,
1752                    h: $(window).height()*1.4
1753                };
1754
1755                var canvas_id = "enj_canvas";
1756
1757                that.enjoyhint = $('<div>', {'class': that.cl.enjoy_hint + ' ' + that.cl.svg_transparent}).appendTo($that);
1758                that.enjoyhint_svg_wrapper = $('<div>', {'class': that.cl.svg_wrapper + ' ' + that.cl.svg_transparent}).appendTo(that.enjoyhint);
1759                that.$stage_container = $('<div id="' + that.cl.kinetic_container + '">').appendTo(that.enjoyhint);
1760                that.$canvas = $('<canvas id="' + canvas_id + '" width="' + that.canvas_size.w + '" height="' + that.canvas_size.h + '" class="' + that.cl.main_canvas + '">').appendTo(that.enjoyhint);
1761                that.$svg = $('<svg width="' + that.canvas_size.w + '" height="' + that.canvas_size.h + '" class="' + that.cl.main_canvas + ' ' + that.cl.main_svg + '">').appendTo(that.enjoyhint_svg_wrapper);
1762
1763                var defs = $(makeSVG('defs'));
1764                var marker = $(makeSVG('marker', {id: "arrowMarker", viewBox: "0 0 36 21", refX: "21", refY: "10", markerUnits: "strokeWidth", orient: "auto", markerWidth: "16", markerHeight: "12"}));
1765                var polilyne = $(makeSVG('path', {style: "fill:none; stroke:rgb(255,255,255); stroke-width:2", d: "M0,0 c30,11 30,9 0,20"}));
1766
1767                defs.append(marker.append(polilyne)).appendTo(that.$svg);
1768
1769                that.kinetic_stage = new Kinetic.Stage({
1770                    container: that.cl.kinetic_container,
1771                    width: that.canvas_size.w,
1772                    height: that.canvas_size.h,
1773                    scaleX: 1
1774                });
1775
1776                that.layer = new Kinetic.Layer();
1777                that.rect = new Kinetic.Rect({
1778                    fill: 'rgba(0,0,0,0.6)',
1779                    width: that.canvas_size.w,
1780                    height: that.canvas_size.h
1781                });
1782
1783                var $top_dis_events = $('<div>', {'class': that.cl.disable_events_element}).appendTo(that.enjoyhint);
1784                var $bottom_dis_events = $top_dis_events.clone().appendTo(that.enjoyhint);
1785                var $left_dis_events = $top_dis_events.clone().appendTo(that.enjoyhint);
1786                var $right_dis_events = $top_dis_events.clone().appendTo(that.enjoyhint);
1787
1788                var stopPropagation = function(e) {
1789
1790                    e.stopImmediatePropagation();
1791                };
1792
1793                $("button").focusout(stopPropagation);
1794                $top_dis_events.click(stopPropagation);
1795                $bottom_dis_events.click(stopPropagation);
1796                $left_dis_events.click(stopPropagation);
1797                $right_dis_events.click(stopPropagation);
1798
1799
1800                that.$skip_btn = $('<div>', {'class': that.cl.skip_btn}).appendTo(that.enjoyhint).html('Skip').click(function (e) {
1801
1802                    that.hide();
1803                    that.options.onSkipClick();
1804                });
1805                that.$next_btn = $('<div>', {'class': that.cl.next_btn}).appendTo(that.enjoyhint).html('Next').click(function (e) {
1806
1807                    that.options.onNextClick();
1808                });
1809
1810                that.$close_btn = $('<div>', {'class': that.cl.close_btn}).appendTo(that.enjoyhint).html('').click(function (e) {
1811
1812                    that.hide();
1813                    that.options.onSkipClick();
1814                    that.options.onCloseClick();
1815                });
1816
1817                that.$canvas.mousedown(function (e) {
1818
1819                    $('canvas').css({left: '4000px'});
1820
1821                    var BottomElement = document.elementFromPoint(e.clientX, e.clientY);
1822                    $('canvas').css({left: '0px'});
1823
1824                    $(BottomElement).click();
1825
1826                    return false;
1827                });
1828
1829
1830                var circle_r = 0;
1831                var shape_init_shift = 130;
1832
1833                that.shape = new Kinetic.Shape({
1834                    radius: circle_r,
1835                    center_x: -shape_init_shift,
1836                    center_y: -shape_init_shift,
1837                    width: 0,
1838                    height: 0,
1839                    sceneFunc: function (context) {
1840
1841                        var ctx = this.getContext("2d")._context;
1842                        var pos = this.pos;
1843                        var def_comp = ctx.globalCompositeOperation;
1844                        ctx.globalCompositeOperation = 'destination-out';
1845                        ctx.beginPath();
1846
1847                        var x = this.attrs.center_x - Math.round(this.attrs.width / 2);
1848                        var y = this.attrs.center_y - Math.round(this.attrs.height / 2);
1849                        ctx.roundRect(x, y, this.attrs.width, this.attrs.height, this.attrs.radius);
1850                        ctx.fillStyle = "red";
1851                        ctx.fill();
1852
1853                        ctx.globalCompositeOperation = def_comp;
1854                    }
1855                });
1856
1857                that.shape.radius = circle_r;
1858                that.layer.add(that.rect);
1859                that.layer.add(that.shape);
1860                that.kinetic_stage.add(that.layer);
1861
1862                $(window).on('resize', function() {
1863
1864                    if (!($(that.stepData.enjoyHintElementSelector).is(":visible"))) {
1865
1866                        that.stopFunction();
1867                        $(window).off('resize');
1868                        return;
1869                    }
1870
1871                    prevWindowWidth = window.innerWidth;
1872                    prevWindowHeight = window.innerHeight;
1873
1874                    var boundingClientRect = $(that.stepData.enjoyHintElementSelector)[0].getBoundingClientRect();
1875
1876                    that.shape.attrs.center_x = Math.round(boundingClientRect.left + boundingClientRect.width / 2);
1877                    that.shape.attrs.center_y = Math.round(boundingClientRect.top + boundingClientRect.height / 2);
1878                    that.shape.attrs.width = boundingClientRect.width + 11;
1879                    that.shape.attrs.height = boundingClientRect.height + 11;
1880
1881                    var newWidth = window.innerWidth;
1882                    var newHeight = window.innerHeight;
1883                    var scaleX = newWidth / originalWidth;
1884                    var scaleY = newHeight / originalHeight;
1885
1886                    that.kinetic_stage.setAttr('width', originalWidth * scaleX);
1887                    that.kinetic_stage.setAttr('height', originalHeight * scaleY);
1888
1889                    if (that.stepData != null) {
1890
1891                        prevWindowWidth = window.innerWidth;
1892                        prevWindowHeight = window.innerHeight;
1893
1894
1895                        /* Init */
1896
1897                        if (!originalCenterX) {
1898
1899                            originalCenterX = that.shape.attrs.center_x;
1900                            originalCenterY = that.shape.attrs.center_y;
1901                        }
1902
1903                        if (!originalArrowLeft) {
1904
1905                            originalArrowLeft = [];
1906                            var attr = $('#enjoyhint_arrpw_line').attr('d');
1907                            originalArrowLeft.push(attr.substr(1).split(',')[0]);
1908                            originalArrowLeft.push(attr.substr(attr.indexOf('Q') + 1).split(',')[0]);
1909                            originalArrowLeft.push(attr.split(' ')[2].split(',')[0]);
1910                            originalArrowTop = [];
1911                            originalArrowTop.push(attr.split(',')[1].split(' ')[0]);
1912                            originalArrowTop.push(attr.split(',')[2].split(' ')[0]);
1913                            originalArrowTop.push(attr.split(',')[3]);
1914                        }
1915
1916                        var labelElement = $('.enjoy_hint_label');
1917
1918                        if (!originalLabelLeft) {
1919
1920                            originalLabelLeft = labelElement[0].getBoundingClientRect().left;
1921                            originalLabelTop = labelElement[0].getBoundingClientRect().top;
1922                        }
1923
1924                        var skipButton = $('.enjoyhint_skip_btn');
1925
1926                        if (!originalSkipbuttonLeft) {
1927
1928                            originalSkipbuttonLeft = skipButton[0].getBoundingClientRect().left;
1929                            originalSkipbuttonTop = skipButton[0].getBoundingClientRect().top;
1930                        }
1931
1932
1933                        /* Resizing label */
1934
1935                        labelElement.css('left', window.innerWidth / 2 - labelElement.outerWidth() / 2);
1936
1937
1938                        /* Resizing arrow */
1939
1940                        var labelRect = labelElement[0].getBoundingClientRect();
1941
1942
1943
1944                            $('#enjoyhint_arrpw_line').show();
1945
1946                            labelElement.css('top', originalLabelTop);
1947
1948                            var x1, x2, y1, y2;
1949
1950                            var labelLeftOfShape = labelRect.left + labelRect.width / 2 < that.shape.attrs.center_x;
1951                            var labelAboveShape = labelRect.top + labelRect.height / 2 < that.shape.attrs.center_y;
1952
1953                            if (window.innerWidth < 900) {
1954
1955                                x1 = Math.round(labelRect.left + (labelRect.width / 2 + 15) * (labelRect.left + labelRect.width / 2 < that.shape.attrs.center_x ? 1 : -1));
1956                                y1 = Math.round(labelRect.top + labelRect.height * (labelRect.top + labelRect.height / 2 < that.shape.attrs.center_y ? 1 : -1));
1957                                x2 = Math.round(that.shape.attrs.center_x + (that.shape.attrs.radius + 15) * (labelLeftOfShape ? -1 : 1));
1958                                y2 = Math.round(that.shape.attrs.center_y);
1959                            } else {
1960
1961                                x1 = Math.round((labelRect.left + (labelRect.width / 2)) + ((labelRect.width / 2 + 15) * (labelLeftOfShape ? 1 : -1)));
1962                                y1 = Math.round(labelRect.top + labelRect.height / 2);
1963                                x2 = Math.round(that.shape.attrs.center_x);
1964                                y2 = Math.round(that.shape.attrs.center_y + (((that.shape.attrs.height / 2) + 15) * (labelAboveShape ? -1 : 1)));
1965                            }
1966
1967                            var midX = x1 + (x2 - x1) / 2;
1968                            var midY = y1 + (y2 - y1) / 2;
1969
1970                            var bezX = x1 < x2 ? x2 : x1;
1971                            var bezY = y1 < y2 ? y1 : y2;
1972
1973                            if (Math.abs(labelRect.left + labelRect.width / 2 - that.shape.attrs.center_x) < 200) {
1974
1975                                x1 = x2 = labelRect.left + labelRect.width / 2;
1976                                y1 = labelRect.top;
1977                                bezX = x1;
1978                                bezY = y1;
1979                            }
1980
1981                            if (window.innerWidth < 900) {
1982
1983                                bezX = x1 < x2 ? x1 : x2;
1984                                bezY = y1 < y2 ? y2 : y1;
1985                            }
1986
1987                            var newCoordsLine = "M%d1,%d2 Q%d3,%d4 %d5,%d6"
1988                                .replace("%d1", x1).replace("%d2", y1)
1989                                .replace("%d3", bezX).replace("%d4", bezY)
1990                                .replace("%d5", x2).replace("%d6", y2);
1991                            $('#enjoyhint_arrpw_line')[0].setAttribute('d', newCoordsLine);
1992
1993
1994
1995                        /* Resizing skip button */
1996
1997                        var newSkipbuttonLeft = +originalSkipbuttonLeft + (that.shape.attrs.center_x - originalCenterX) / 2;
1998                        skipButton.css('left', newSkipbuttonLeft < 15 ? 15 : newSkipbuttonLeft);
1999                        skipButton.css('top', labelRect.top + labelRect.height + 20);
2000                    }
2001
2002                    that.rect = new Kinetic.Rect({
2003                        fill: 'rgba(0,0,0,0.6)',
2004                        width: window.innerWidth,
2005                        height: window.innerHeight
2006                    });
2007
2008                    that.layer.removeChildren();
2009                    that.layer.add(that.rect);
2010                    that.layer.add(that.shape);
2011                    that.layer.draw();
2012                    that.kinetic_stage.draw();
2013                });
2014
2015                var enjoyhint_elements = [
2016                    that.enjoyhint,
2017                    $top_dis_events,
2018                    $bottom_dis_events,
2019                    $left_dis_events,
2020                    $right_dis_events
2021                ];
2022
2023                that.show = function () {
2024
2025                    that.enjoyhint.removeClass(that.cl.hide);
2026                };
2027
2028                that.hide = function () {
2029
2030                    that.enjoyhint.addClass(that.cl.hide);
2031
2032                    var tween = new Kinetic.Tween({
2033                        node: that.shape,
2034                        duration: 0.002,
2035                        center_x: -shape_init_shift,
2036                        center_y: -shape_init_shift
2037                    });
2038
2039                    tween.play();
2040                };
2041
2042                that.hide();
2043
2044                that.hideNextBtn = function () {
2045
2046                    that.$next_btn.addClass(that.cl.hide);
2047                    that.nextBtn = "hide";
2048                };
2049
2050                that.showNextBtn = function () {
2051
2052                    that.$next_btn.removeClass(that.cl.hide);
2053                    that.nextBtn = "show";
2054                };
2055
2056                that.hideSkipBtn = function () {
2057
2058                    that.$skip_btn.addClass(that.cl.hide);
2059                };
2060
2061                that.showSkipBtn = function () {
2062
2063                    that.$skip_btn.removeClass(that.cl.hide);
2064                };
2065
2066                that.renderCircle = function (data) {
2067
2068                    var r = data.r || 0;
2069                    var x = data.x || 0;
2070                    var y = data.y || 0;
2071
2072                    var tween = new Kinetic.Tween({
2073                        node: that.shape,
2074                        duration: 0.2,
2075                        center_x: x,
2076                        center_y: y,
2077                        width: r * 2,
2078                        height: r * 2,
2079                        radius: r
2080                    });
2081
2082                    tween.play();
2083
2084                    var left = x - r;
2085                    var right = x + r;
2086                    var top = y - r;
2087                    var bottom = y + r;
2088                    var margin = 20;
2089
2090                    return {
2091                        x: x,
2092                        y: y,
2093                        left: left,
2094                        right: right,
2095                        top: top,
2096                        bottom: bottom,
2097                        conn: {
2098                            left: {
2099                                x: left - margin,
2100                                y: y
2101                            },
2102                            right: {
2103                                x: right + margin,
2104                                y: y
2105                            },
2106                            top: {
2107                                x: x,
2108                                y: top - margin
2109                            },
2110                            bottom: {
2111                                x: x,
2112                                y: bottom + margin
2113                            }
2114                        }
2115                    };
2116
2117                };
2118
2119                that.renderRect = function (data, timeout) {
2120
2121                    var r = data.r || 0;
2122                    var x = data.x || 0;
2123                    var y = data.y || 0;
2124                    var w = data.w || 0;
2125                    var h = data.h || 0;
2126                    var margin = 20;
2127
2128                    var tween = new Kinetic.Tween({
2129                        node: that.shape,
2130                        duration: timeout,
2131                        center_x: x,
2132                        center_y: y,
2133                        width: w,
2134                        height: h,
2135                        radius: r
2136                    });
2137
2138                    tween.play();
2139
2140                    var half_w = Math.round(w / 2);
2141                    var half_h = Math.round(h / 2);
2142                    var left = x - half_w;
2143                    var right = x + half_w;
2144                    var top = y - half_h;
2145                    var bottom = y + half_h;
2146
2147                    return {
2148                        x: x,
2149                        y: y,
2150                        left: left,
2151                        right: right,
2152                        top: top,
2153                        bottom: bottom,
2154                        conn: {
2155                            left: {
2156                                x: left - margin,
2157                                y: y
2158                            },
2159                            right: {
2160                                x: right + margin,
2161                                y: y
2162                            },
2163                            top: {
2164                                x: x,
2165                                y: top - margin
2166                            },
2167                            bottom: {
2168                                x: x,
2169                                y: bottom + margin
2170                            }
2171                        }
2172                    };
2173                };
2174
2175                that.renderLabel = function (data) {
2176
2177                    var x = data.x || 0;
2178                    that.originalElementX = x;
2179                    var y = data.y || 0;
2180
2181                    var label = that.getLabelElement({
2182                        x: x,
2183                        y: y,
2184                        text: data.text
2185                    });
2186
2187                    var label_w = label.width();
2188                    var label_h = label.height();
2189                    var label_left = label.offset().left;
2190                    var label_right = label.offset().left + label_w;
2191                    var label_top = label.offset().top - $(document).scrollTop();
2192                    var label_bottom = y + label_h;
2193
2194                    var margin = 10;
2195
2196                    var conn_left = {
2197                        x: label_left - margin,
2198                        y: label_top + Math.round(label_h / 2)
2199                    };
2200
2201                    var conn_right = {
2202                        x: label_right + margin,
2203                        y: label_top + Math.round(label_h / 2)
2204                    };
2205
2206                    var conn_top = {
2207                        x: label_left + Math.round(label_w / 2),
2208                        y: label_top - margin
2209                    };
2210
2211                    var conn_bottom = {
2212                        x: label_left + Math.round(label_w / 2),
2213                        y: label_bottom + margin
2214                    };
2215
2216                    label.detach();
2217
2218                    setTimeout(function () {
2219
2220                        $('#enjoyhint_label').remove();
2221                        label.appendTo(that.enjoyhint);
2222                    }, that.options.animation_time / 2);
2223
2224                    return {
2225                        label: label,
2226                        left: label_left,
2227                        right: label_right,
2228                        top: label_top,
2229                        bottom: label_bottom,
2230                        conn: {
2231                            left: conn_left,
2232                            right: conn_right,
2233                            top: conn_top,
2234                            bottom: conn_bottom
2235                        }
2236
2237                    };
2238                };
2239
2240                that.renderArrow = function (data) {
2241
2242                    if (1 || window.innerWidth >= 640) {
2243
2244                        var x_from = data.x_from || 0;
2245                        var y_from = data.y_from || 0;
2246                        var x_to = data.x_to || 0;
2247                        var y_to = data.y_to || 0;
2248                        var by_top_side = data.by_top_side;
2249                        var control_point_x = 0;
2250                        var control_point_y = 0;
2251                        if (by_top_side) {
2252                            if (y_from >= y_to) {
2253
2254                                control_point_y = y_to;
2255                                control_point_x = x_from;
2256                            } else {
2257
2258                                control_point_y = y_from;
2259                                control_point_x = x_to;
2260                            }
2261
2262                        } else {
2263                            if (y_from >= y_to) {
2264
2265                                control_point_y = y_from;
2266                                control_point_x = x_to;
2267                            } else {
2268
2269                                control_point_y = y_to;
2270                                control_point_x = x_from;
2271                            }
2272                        }
2273                    }
2274
2275
2276
2277                    var text = data.text || '';
2278                    that.enjoyhint.addClass(that.cl.svg_transparent);
2279
2280                    setTimeout(function () {
2281
2282                        $('#enjoyhint_arrpw_line').remove();
2283
2284                        var d = 'M' + x_from + ',' + y_from + ' Q' + control_point_x + ',' + control_point_y + ' ' + x_to + ',' + y_to;
2285                        if (by_top_side) {
2286                            d = 'M' + control_point_x + ',' + (y_to - 50) + ' L' + control_point_x + ',' + y_to;
2287                        }
2288                        that.$svg.append(makeSVG('path', {style: "fill:none; stroke:rgb(255,255,255); stroke-width:3", 'marker-end': "url(#arrowMarker)", d: d, id: 'enjoyhint_arrpw_line'}));
2289                        that.enjoyhint.removeClass(that.cl.svg_transparent);
2290
2291                    }, that.options.animation_time / 2);
2292                };
2293
2294                that.getLabelElement = function (data) {
2295
2296                    return $('<div>', {"class": 'enjoy_hint_label', id: 'enjoyhint_label'})
2297                        .css({
2298                            'top': data.y + 'px',
2299                            'left': data.x + 'px'
2300                        })
2301                        .html(data.text).appendTo(that.enjoyhint);
2302                };
2303
2304
2305                that.disableEventsNearRect = function (rect) {
2306
2307                    $top_dis_events.css({
2308                        top: '0',
2309                        left: '0'
2310                    }).height(rect.top);
2311
2312                    $bottom_dis_events.css({
2313                        top: rect.bottom + 'px',
2314                        left: '0'
2315                    });
2316
2317                    $left_dis_events.css({
2318                        top: '0',
2319                        left: 0 + 'px'
2320                    }).width(rect.left);
2321
2322                    $right_dis_events.css({
2323                        top: '0',
2324                        left: rect.right + 'px'
2325                    });
2326                };
2327
2328                (function($) {
2329
2330                    $.event.special.destroyed = {
2331
2332                        remove: function(o) {
2333
2334                            if (o.handler) {
2335
2336                                o.handler()
2337                            }
2338                        }
2339                    }
2340                })(jQuery);
2341
2342                that.renderLabelWithShape = function (data) {
2343                    that.stepData = data;
2344
2345                    function findParentDialog(element) {
2346
2347                        if (element.tagName === "MD-DIALOG") {
2348
2349                            return element;
2350                        } else if (typeof element.tagName == "undefined") {
2351
2352                            return null;
2353                        } else {
2354
2355                            return findParentDialog($(element).parent()[0]);
2356                        }
2357                    }
2358
2359                    var dialog = findParentDialog($(that.stepData.enjoyHintElementSelector)[0]);
2360
2361                    if (dialog != null) {
2362
2363                        $(dialog).on('dialogClosing', function() {
2364
2365                            that.stopFunction();
2366                            return;
2367                        });
2368                    }
2369
2370                    that.resetComponentStuff();
2371
2372                    var shape_type = data.shape || 'rect';
2373                    var shape_data = {};
2374
2375                    var half_w = 0;
2376                    var half_h = 0;
2377
2378                    var shape_offsets = {
2379                        top: data.top || 0,
2380                        bottom: data.bottom || 0,
2381                        left: data.left || 0,
2382                        right: data.right || 0
2383                    };
2384
2385                    switch (shape_type) {
2386
2387                        case 'circle':
2388
2389                            half_w = half_h = data.radius;
2390
2391                            var sides_pos = {
2392                                top: data.center_y - half_h + shape_offsets.top,
2393                                bottom: data.center_y + half_h - shape_offsets.bottom,
2394                                left: data.center_x - half_w + shape_offsets.left,
2395                                right: data.center_x + half_w - shape_offsets.right
2396                            };
2397
2398                            var width = sides_pos.right - sides_pos.left;
2399                            var height = sides_pos.bottom - sides_pos.top;
2400                            data.radius = Math.round(Math.min(width, height) / 2);
2401
2402                            //new half habarites
2403                            half_w = half_h = Math.round(data.radius / 2);
2404
2405                            var new_half_w = Math.round(width / 2);
2406                            var new_half_h = Math.round(height / 2);
2407
2408                            //new center_x and center_y
2409                            data.center_x = sides_pos.left + new_half_w;
2410                            data.center_y = sides_pos.top + new_half_h;
2411
2412                            shape_data = that.renderCircle({
2413                                x: data.center_x,
2414                                y: data.center_y,
2415                                r: data.radius
2416                            });
2417
2418                            break;
2419
2420                        case 'rect':
2421
2422                            half_w = Math.round(data.width / 2);
2423                            half_h = Math.round(data.height / 2);
2424
2425                            var sides_pos = {
2426                                top: data.center_y - half_h + shape_offsets.top,
2427                                bottom: data.center_y + half_h - shape_offsets.bottom,
2428                                left: data.center_x - half_w + shape_offsets.left,
2429                                right: data.center_x + half_w - shape_offsets.right
2430                            };
2431                            data.width = sides_pos.right - sides_pos.left;
2432                            data.height = sides_pos.bottom - sides_pos.top;
2433
2434                            half_w = Math.round(data.width / 2);
2435                            half_h = Math.round(data.height / 2);
2436
2437                            //new center_x and center_y
2438                            data.center_x = sides_pos.left + half_w;
2439                            data.center_y = sides_pos.top + half_h;
2440
2441                            shape_data = that.renderRect({
2442                                x: data.center_x,
2443                                y: data.center_y,
2444                                w: data.width,
2445                                h: data.height,
2446                                r: data.radius
2447                            }, 0.2);
2448
2449                            break;
2450                    }
2451
2452                    var body_size = {
2453                        w: that.enjoyhint.width(),
2454                        h: that.enjoyhint.height()
2455                    };
2456
2457                    var label = that.getLabelElement({
2458                        x: 0,
2459                        y: 0,
2460                        text: data.text
2461                    });
2462
2463                    var label_width = label.outerWidth();
2464                    var label_height = label.outerHeight();
2465                    label.remove();
2466                    var top_offset = data.center_y - half_h;
2467                    var bottom_offset = body_size.h - (data.center_y + half_h);
2468                    var left_offset = data.center_x - half_w;
2469                    var right_offset = body_size.w - (data.center_x + half_w);
2470
2471                    var label_hor_side = (body_size.w - data.center_x) < data.center_x ? 'left' : 'right';
2472                    var label_ver_side = (body_size.h - data.center_y) < data.center_y ? 'top' : 'bottom';
2473                    var label_shift = 150;
2474                    var label_margin = 40;
2475                    var label_shift_with_label_width = label_shift + label_width + label_margin;
2476                    var label_shift_with_label_height = label_shift + label_height + label_margin;
2477                    var label_hor_offset = half_w + label_shift;
2478                    var label_ver_offset = half_h + label_shift;
2479
2480                    //original: var label_x = (label_hor_side == 'left') ? data.center_x - label_hor_offset - label_width : data.center_x + label_hor_offset;
2481                    var label_y = (label_ver_side == 'top') ? 0 : data.center_y + label_ver_offset;
2482                    var label_x = window.innerWidth / 2 - label_width / 2;
2483
2484                    if (label_ver_side != 'top' && top_offset < label_shift_with_label_height && bottom_offset < label_shift_with_label_height) {
2485
2486                        label_y = data.center_y + label_margin;
2487                    }
2488
2489                    var label_data = that.renderLabel({
2490                        x: label_x,
2491                        y: label_y,
2492                        text: data.text
2493                    });
2494
2495                    if (label_ver_side == 'top') {
2496                        var label_max_height = shape_data.top - label_margin - 100;
2497                        if (label_height > label_max_height) {
2498                            setTimeout(function () {
2499                                $('#enjoyhint_label').css({
2500                                    height: label_max_height,
2501                                    overflow: 'hidden'
2502                                });
2503
2504                                $('.enjoyhint_skip_btn').css('top', label_max_height + 20);
2505                                $('.enjoyhint_next_btn').css('top', label_max_height + 20);
2506                            }, that.options.animation_time / 2 + 100);
2507                        }
2508                        else {
2509                            setTimeout(function () {
2510                                $('#enjoyhint_label').css({
2511                                    top: label_max_height - label_height
2512                                });
2513
2514                                $('.enjoyhint_skip_btn').css('top', label_max_height + 20);
2515                                $('.enjoyhint_next_btn').css('top', label_max_height + 20);
2516                            }, that.options.animation_time / 2 + 100);
2517                        }
2518                    }
2519                    that.$next_btn.css({
2520                        left: label_x,
2521                        top: label_y + label_height + 20
2522                    });
2523
2524                    var left_skip = label_x + that.$next_btn.width() + 10;
2525
2526                    if (that.nextBtn == "hide"){
2527
2528                        left_skip = label_x;
2529                    }
2530
2531                    that.$skip_btn.css({
2532                        left: left_skip,
2533                        top: label_y + label_height + 20
2534                    });
2535
2536                    that.$close_btn.css({
2537                        right : 10,
2538                        bottom: 10
2539                    });
2540
2541                    that.disableEventsNearRect({
2542                        top: shape_data.top,
2543                        bottom: shape_data.bottom,
2544                        left: shape_data.left,
2545                        right: shape_data.right
2546                    });
2547
2548                    var x_to = 0;
2549                    var y_to = 0;
2550                    var arrow_side = false;
2551                    var conn_label_side = 'left';
2552                    var conn_circle_side = 'left';
2553
2554                    var is_center = (label_data.left <= shape_data.x && label_data.right >= shape_data.x);
2555                    var is_left = (label_data.right < shape_data.x);
2556                    var is_right = (label_data.left > shape_data.x);
2557
2558                    var is_abs_left = (label_data.right < shape_data.left);
2559                    var is_abs_right = (label_data.left > shape_data.right);
2560
2561                    var is_top = (label_data.bottom < shape_data.top);
2562                    var is_bottom = (label_data.top > shape_data.bottom);
2563                    var is_mid = (label_data.bottom >= shape_data.y && label_data.top <= shape_data.y);
2564                    var is_mid_top = (label_data.bottom <= shape_data.y && !is_top);
2565                    var is_mid_bottom = (label_data.top >= shape_data.y && !is_bottom);
2566
2567
2568                    function setArrowData(l_s, c_s, a_s) {
2569
2570                        conn_label_side = l_s;
2571                        conn_circle_side = c_s;
2572                        arrow_side = a_s;
2573                    }
2574
2575                    function sideStatements(top_s, mid_top_s, mid_s, mid_bottom_s, bottom_s) {
2576
2577                        var statement = [];
2578
2579                        if (is_top) {
2580                            statement = top_s;
2581                        } else if (is_mid_top) {
2582                            statement = mid_top_s;
2583                        } else if (is_mid) {
2584                            statement = mid_s;
2585                        } else if (is_mid_bottom) {
2586                            statement = mid_bottom_s;
2587                        } else {//bottom
2588                            statement = bottom_s;
2589                        }
2590
2591                        if (!statement) {
2592
2593                            return;
2594                        } else {
2595
2596                            setArrowData(statement[0], statement[1], statement[2]);
2597                        }
2598                    }
2599
2600                    if (is_center) {
2601
2602                        if (is_top) {
2603                            setArrowData('left', 'top', 'top');
2604                        } else if (is_bottom) {
2605                            setArrowData('top', 'bottom', 'bottom');
2606                        } else {
2607                            sideStatements(
2608                                ['left', 'top', 'top'],//top
2609                                ['left', 'top', 'top'],//mid_top
2610                                ['left', 'top', 'top'],//mid
2611                                ['top', 'top', 'top'],//mid_bot
2612                                ['left', 'bottom', 'bottom']//bot
2613                            );
2614                        }
2615
2616                    } else if (is_left) {
2617
2618                        sideStatements(
2619                            ['right', 'top', 'top'],//top
2620                            ['bottom', 'left', 'bottom'],//mid_top
2621                            ['right', 'left', 'top'],//mid
2622                            ['top', 'left', 'top'],//mid_bot
2623                            ['right', 'bottom', 'bottom']//bot
2624                        );
2625
2626                    } else {//right
2627
2628                        sideStatements(
2629                            ['left', 'top', 'top'],//top
2630                            ['bottom', 'right', 'bottom'],//mid_top
2631                            ['left', 'top', 'top'],//mid
2632                            ['top', 'right', 'top'],//mid_bot
2633                            ['left', 'bottom', 'bottom']//bot
2634                        );
2635
2636                    }
2637
2638                    var label_conn_coordinates = label_data.conn[conn_label_side];
2639                    var circle_conn_coordinates = shape_data.conn[conn_circle_side];
2640                    var by_top_side = (arrow_side == 'top');
2641
2642                    that.renderArrow({
2643                        x_from: label_conn_coordinates.x,
2644                        y_from: label_conn_coordinates.y,
2645                        x_to: circle_conn_coordinates.x,
2646                        y_to: circle_conn_coordinates.y,
2647                        by_top_side: by_top_side
2648                    });
2649
2650                };
2651
2652                that.clear = function () {
2653
2654                    that.ctx.clearRect(0, 0, 3000, 2000);
2655                };
2656
2657                return this;
2658            });
2659        },
2660
2661        set: function (val) {
2662
2663            this.each(function () {
2664
2665                this.enjoyhint_obj.setValue(val);
2666            });
2667
2668            return this;
2669        },
2670
2671        show: function () {
2672
2673            this.each(function () {
2674
2675                this.enjoyhint_obj.show();
2676            });
2677
2678            return this;
2679        },
2680
2681        hide: function () {
2682
2683            this.each(function () {
2684
2685                this.enjoyhint_obj.hide();
2686            });
2687
2688            return this;
2689        },
2690
2691        hide_next: function () {
2692
2693            this.each(function () {
2694
2695                this.enjoyhint_obj.hideNextBtn();
2696            });
2697
2698            return this;
2699        },
2700
2701        show_next: function () {
2702
2703            this.each(function () {
2704
2705                this.enjoyhint_obj.showNextBtn();
2706            });
2707
2708            return this;
2709        },
2710
2711        hide_skip: function () {
2712
2713            this.each(function () {
2714
2715                this.enjoyhint_obj.hideSkipBtn();
2716            });
2717
2718            return this;
2719        },
2720
2721        show_skip: function () {
2722
2723            this.each(function () {
2724
2725                this.enjoyhint_obj.showSkipBtn();
2726            });
2727
2728            return this;
2729        },
2730
2731        render_circle: function (x, y, r) {
2732
2733            this.each(function () {
2734
2735                this.enjoyhint_obj.renderCircle(x, y, r);
2736            });
2737
2738            return this;
2739        },
2740
2741        render_label: function (x, y, r) {
2742
2743            this.each(function () {
2744
2745                this.enjoyhint_obj.renderLabel(x, y, r);
2746            });
2747
2748            return this;
2749        },
2750
2751        render_label_with_shape: function (data, stopFunction) {
2752
2753            this.each(function () {
2754
2755                that.stopFunction = stopFunction;
2756                this.enjoyhint_obj.renderLabelWithShape(data);
2757            });
2758
2759            return this;
2760        },
2761
2762        redo_events_near_rect: function(rect) {
2763
2764            that.disableEventsNearRect({
2765                top: rect.top,
2766                bottom: rect.bottom,
2767                left: rect.left,
2768                right: rect.right
2769            });
2770        },
2771
2772        clear: function () {
2773
2774            this.each(function () {
2775
2776                this.enjoyhint_obj.clear();
2777            });
2778
2779            return this;
2780        },
2781
2782        close: function (val) {
2783
2784            this.each(function () {
2785
2786                this.enjoyhint_obj.closePopdown();
2787            });
2788
2789            return this;
2790        }
2791    };
2792
2793    $.fn.enjoyhint = function (method) {
2794
2795        if (methods[method]) {
2796
2797            return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
2798        } else if (typeof method === 'object' || !method) {
2799
2800            return methods.init.apply(this, arguments);
2801        } else {
2802
2803            $.error('Method ' + method + ' does not exist on $.numinput');
2804        }
2805
2806        return this;
2807    };
2808})(window.jQuery);
2809function googleMap(map_container_id, lat, lng) {
2810    this.map_container_id = map_container_id;
2811    this.map_lat = lat;
2812    this.map_lng = lng;
2813}
2814
2815googleMap.prototype = {
2816    map : null,
2817    zoom: 17,
2818    map_lat: null,
2819    map_lng: null,
2820    map_type: 'roadmap',
2821    locations: '',
2822    current_infowindow : null,
2823    current_latlng : null,
2824    html : null,
2825    to_html : null,
2826    from_html : null,
2827    no_pin : false,
2828    directionsDisplay : null,
2829    directionsService : null,
2830    pin_icon : 'public/images/lib/gmap/Memorial-Pin.png',
2831    pin_icon_related : 'public/images/lib/gmap/Resting-Place-Pin.png',
2832    my_lat: null,
2833    my_lng: null,
2834    map_direction_container_id: 'fd_map_directions',
2835    autocomplete: null,
2836    multiLocation: false,
2837    markers: [],
2838    timeoutHandle: 0,
2839    infowindow: null,
2840
2841    displayMap: function () {
2842
2843        if (typeof google == "undefined") {
2844            return;
2845        }
2846
2847        var mapOptions = {
2848            center: new google.maps.LatLng(this.map_lat, this.map_lng),
2849            zoom: this.zoom,
2850            mapTypeId: this.map_type
2851        };
2852        this.map = new google.maps.Map(document.getElementById(this.map_container_id), mapOptions);
2853        var locations = [];
2854
2855        if(!this.multiLocation)
2856        {
2857            this.locations = [
2858                this.locations
2859            ];
2860        }
2861        else
2862        {
2863            // locations = this.locations;
2864        }
2865
2866        if(!this.no_pin)
2867        {
2868            this.addAllMarkers();
2869        }
2870
2871    },
2872
2873    addAllMarkers: function () {
2874        var i;
2875        var location;
2876        this.markers = [];
2877        if(!this.infowindow)
2878        {
2879            this.infowindow = new google.maps.InfoWindow();
2880        }
2881        var infowindow = this.infowindow;
2882
2883        for (i = 0; i < this.locations.length; i++) {
2884            location = this.locations[i];
2885            this.addMarker(location);
2886
2887            google.maps.event.addListener(this.map, 'click', function() {
2888                infowindow.close();
2889            });
2890        }
2891    },
2892
2893    addMarker: function(data) {
2894
2895        var point = new google.maps.LatLng(data.lat, data.lng);
2896
2897        var marker = new google.maps.Marker({
2898            position: point,
2899            map: this.map,
2900            icon: this.pin_icon
2901        });
2902        this.markers.push({marker_id: data.marker_id, marker:marker});
2903
2904        var onOpenMarker = this.onOpenMarker;
2905        var infowindow = this.infowindow;
2906        google.maps.event.addListener(marker, 'click', (function(){
2907
2908            onOpenMarker(marker, data, infowindow);
2909
2910            return false;
2911        }));
2912    },
2913
2914    onOpenMarker: function (marker, location, infowindow) {
2915
2916        if(typeof infowindow == 'undefined')
2917        {
2918            if(!this.infowindow)
2919                this.infowindow = new google.maps.InfoWindow();
2920            infowindow = this.infowindow;
2921        }
2922        else
2923        {
2924            this.infowindow = infowindow;
2925        }
2926
2927        var html = this.html;
2928        if(location.html != '')
2929        {
2930            html = location.html;
2931        }
2932        var info_win_str = '<div class="info_win"><h4>' + location.title + '</h4>' + html + '</div>';
2933
2934        infowindow.setContent(info_win_str);
2935        infowindow.open(this.map, marker);
2936        $('.info_win').parent().css('overflow','');
2937
2938        infowindow.content_changed = function() {
2939            infowindow.open(this.map, marker);
2940        };
2941
2942
2943        return false;
2944    },
2945
2946    setMarkers: function (map) {
2947        if(this.markers) {
2948            for (var i = 0; i < this.markers.length; i++) {
2949                this.markers[i].marker.setMap(map);
2950            }
2951        }
2952    },
2953
2954    getDirections: function (from_location, to_location, direction) {
2955        $('#'+this.map_direction_container_id).html('');
2956        var from_lat, from_lng, to_lat, to_lng = null;
2957
2958        if(from_location != null)
2959        {
2960            from_lat = from_location.lat();
2961            from_lng = from_location.lng();
2962        }
2963        else // From current location
2964        {
2965            from_lat = this.my_lat;
2966            from_lng = this.my_lng;
2967        }
2968
2969        if(to_location != null)
2970        {
2971            to_lat = to_location.lat();
2972            to_lng = to_location.lng();
2973        }
2974        else // to the first marker
2975        {
2976            to_lat = this.my_lat;
2977            to_lng = this.my_lng;
2978        }
2979        // else if(typeof my_lat != 'undefined')
2980        // {
2981        //     from_lat = this.my_lat;
2982        //     from_lng = this.my_lng;
2983        // }
2984
2985        if(typeof direction == 'undefined')
2986        {
2987            direction = 'to';
2988        }
2989
2990        var map_container_id = this.map_container_id;
2991        var directionsService = new google.maps.DirectionsService();
2992        var directionsDisplay = new google.maps.DirectionsRenderer();
2993        directionsDisplay.setMap(this.map);
2994
2995        var request = null;
2996        var mapOptions = null;
2997
2998        if(direction == 'from')
2999        {
3000            mapOptions = {
3001                center: new google.maps.LatLng(from_lat, from_lng),
3002                zoom: this.zoom,
3003                mapTypeId: this.map_type
3004            };
3005
3006            request = {
3007                origin: new google.maps.LatLng(from_lat, from_lng),
3008                destination: new google.maps.LatLng(to_lat, to_lng),
3009                travelMode: google.maps.DirectionsTravelMode.DRIVING
3010            };
3011        }
3012        else
3013        {
3014            mapOptions = {
3015                center: new google.maps.LatLng(to_lat, to_lng),
3016                zoom: this.zoom,
3017                mapTypeId: this.map_type
3018            };
3019
3020            request = {
3021                origin: new google.maps.LatLng(to_lat, to_lng),
3022                destination: new google.maps.LatLng(from_lat, from_lng),
3023                travelMode: google.maps.DirectionsTravelMode.DRIVING
3024            };
3025        }
3026
3027        directionsDisplay.setPanel(document.getElementById(this.map_direction_container_id));
3028        directionsService.route(request, function(response, status) {
3029            if (status == google.maps.DirectionsStatus.OK) {
3030
3031                var direction_map = new google.maps.Map(document.getElementById(map_container_id), mapOptions);
3032                directionsDisplay.setMap(direction_map);
3033                directionsDisplay.setDirections(response);
3034
3035            } else {
3036                alert('There is no direction.');
3037                console.log('Error: ' + status);
3038            }
3039        });
3040    },
3041    handleErrors: function(error)
3042    {
3043        switch(error.code)
3044        {
3045            case error.PERMISSION_DENIED: console.log("Location Sharing needs to be activated for this feature to work.");
3046                break;
3047
3048            case error.POSITION_UNAVAILABLE: console.log("Current position could not be detected.");
3049                break;
3050
3051            case error.TIMEOUT: console.log("Position retrieval timed out");
3052                break;
3053
3054            default: console.log("Unknown Error");
3055                break;
3056        }
3057    },
3058    set_autocomplete: function(obj) {
3059        var input = document.getElementById($(obj).attr("name"));
3060        var options = {
3061            types: ['geocode']
3062        };
3063        this.autocomplete = new google.maps.places.Autocomplete(input, options);
3064    },
3065
3066    initiate_geolocation: function (callback, location) {
3067        var map = this.map;
3068        var pin_icon = this.pin_icon;
3069        var to_location = [];
3070        // var my_lat = this.my_lat;
3071        // var my_lng = this.my_lng;
3072
3073        if(location != null)
3074        {
3075            to_location = location;
3076        }
3077        else
3078        {
3079            if(!this.multiLocation)
3080            {
3081                to_location = this.locations;;
3082            }
3083            else
3084            {
3085                to_location = this.locations[0];
3086            }
3087        }
3088
3089        var map_direction_container_id = this.map_direction_container_id;
3090        var directionsDisplay = new google.maps.DirectionsRenderer();
3091
3092        var handle_geolocation_query = function (position){
3093            my_lat = position.coords.latitude;
3094            my_lng = position.coords.longitude;
3095
3096            directionsDisplay.setMap(map);
3097            directionsDisplay.setPanel(document.getElementById(map_direction_container_id));
3098
3099            var arr_locations = [
3100                ['You', my_lat, my_lng, 2],
3101                to_location
3102            ];
3103            var bounds = new google.maps.LatLngBounds();
3104            var infowindow = new google.maps.InfoWindow();
3105            var marker, i;
3106            for (i = 0; i < arr_locations.length; i++) {
3107                marker = new google.maps.Marker({
3108                    position: new google.maps.LatLng(arr_locations[i][1], arr_locations[i][2]),
3109                    map: map,
3110                    icon: pin_icon
3111                });
3112                google.maps.event.addListener(marker, 'click', (function(marker, i) {
3113                    return function() {
3114                        var info_win_str = '<div class="info_win"><strong>' + arr_locations[i][0] + '</strong></div>';
3115                        infowindow.setContent(info_win_str);
3116                        infowindow.open(map, marker);
3117                        $('.info_win').parent().css('overflow','');
3118                        infowindow.content_changed=function() {
3119                            infowindow.open(map, marker);
3120                        }
3121                    }
3122                })(marker, i));
3123                bounds.extend(marker.getPosition());
3124            }
3125            map.fitBounds(bounds);
3126            callback(position);
3127        };
3128        navigator.geolocation.getCurrentPosition(handle_geolocation_query, this.handleErrors);
3129    },
3130    getAddressFromLatLng: function (location, input_autoupdate) {
3131        var latlng = null;
3132        if(location != null)
3133        {
3134            latlng = new google.maps.LatLng(location[0], location[1]);
3135        }
3136        else
3137        {
3138            latlng = new google.maps.LatLng(this.my_lat, this.my_lng);
3139        }
3140
3141        var geocoder = new google.maps.Geocoder();
3142        geocoder.geocode({'latLng': latlng}, function(results, status) {
3143            if (status == google.maps.GeocoderStatus.OK) {
3144                input_autoupdate.val(results[0].formatted_address);
3145            } else {
3146                console.log("Geocoder failed due to: " + status);
3147            }
3148        });
3149    },
3150    displayMap_dragable: function (option) {
3151        map_geocode_output_id = option.map_geocode_id;
3152        map_lat_output_id = option.map_lat_id;
3153        map_lng_output_id = option.map_lng_id;
3154        reverse_geocode_id = option.reverse_geocode;
3155        input_address_id = option.input_address_id;
3156        setPosition = ( typeof option.setPosition !== 'undefined' ? option.setPosition: false);
3157
3158        addresspicker_map = $(input_address_id);
3159        $(map_geocode_output_id).val(JSON.stringify(option.service_geocode, null, 4));
3160
3161        if(addresspicker_map.data('ui-addresspicker') == null) {
3162            // lat = this.map_lat;
3163            // lng = this.map_lng;
3164            // formatted_address = this.html;
3165            // map_type: this.map_type;
3166            // zoom: this.zoom;
3167
3168            addresspicker_map.keypress(function(e) {
3169                var code = (e.keyCode ? e.keyCode : e.which);
3170                if(code == 13) { //Enter keycode
3171                    return false;
3172                }
3173            });
3174
3175            var addresspickerMap = addresspicker_map.addresspicker({
3176                regionBias: "au",
3177                updateCallback: function(geocodeResult, parsedGeocodeResult) {
3178                    $(map_geocode_output_id).val(JSON.stringify(geocodeResult, null, 4));
3179                },
3180                geometry: {
3181                    viewport: null
3182                },
3183                elements: {
3184                    map:      '#' + this.map_container_id,
3185                    lat:      map_lat_output_id,
3186                    lng:      map_lng_output_id
3187                },
3188                mapOptions: {
3189                    center: new google.maps.LatLng( this.map_lat, this.map_lng),
3190                    zoom: this.zoom,
3191                    mapTypeId: this.map_type
3192                },
3193                reverseGeocode: ($(reverse_geocode_id).attr('checked') !== 'checked'),
3194                autocomplete: 'googleplace'
3195            });
3196
3197            var gmarker = addresspickerMap.addresspicker( "marker");
3198            gmarker.setVisible(true);
3199            gmarker.setIcon(this.pin_icon);
3200            addresspickerMap.addresspicker("updatePosition");
3201            if(setPosition)
3202            {
3203                addresspickerMap.addresspicker("setPosition", this.map_lat, this.map_lng);
3204            }
3205
3206            if(this.html)
3207            {
3208                addresspicker_map.val(this.html);
3209            }
3210
3211            $(reverse_geocode_id).on('click', function(){
3212                addresspickerMap.addresspicker("option", "reverseGeocode", ($(this).attr('checked') !== 'checked'));
3213            });
3214        }
3215        else {
3216            $(input_address_id).addresspicker("setPosition", this.map_lat, this.map_lng);
3217        }
3218    },
3219    mapBoundChange: function(callback){
3220
3221        if(this.map)
3222        {
3223            google.maps.event.addListener(this.map, 'bounds_changed', function(event) {
3224                var zoomLevel = this.getZoom();
3225                callback(zoomLevel);
3226            });
3227        }
3228    },
3229
3230    repopulate_marker_callback: function (data) {
3231
3232        var inter_markers = [];
3233        var prev_markers = [];
3234        for (var i = 0; i< this.markers.length; i++){
3235            prev_markers.push(this.markers[i][0]);
3236        }
3237
3238
3239        for (var i = 0; i < data.length; i++) {
3240            var marker_id = data[i].rp_id;
3241            var intersect = false;
3242            for ( var j = 0; j < prev_markers.length; j++) {
3243                if( marker_id == prev_markers[j])
3244                {
3245                    prev_markers.splice(j--,1);
3246                    inter_markers.push(marker_id);
3247                    intersect = true;
3248                    break;
3249                }
3250            }
3251            if( !intersect )
3252            {
3253                var title = markerNodes[i].getAttribute('marker-title');
3254                var desc = markerNodes[i].getAttribute('marker-desc');
3255                var info = markerNodes[i].getAttribute('marker-info');
3256                var point = new google.maps.LatLng( parseFloat(data[i].lat), parseFloat(data[i].lng) );
3257
3258
3259            }
3260        }
3261        for (var i = 0; i < prev_markers.length; i++)
3262        {
3263            for (var j = 0; j < markersmap.length ; j++)
3264            {
3265                if( prev_markers[i] == markersmap[j][0])
3266                {
3267                    var marker = markersmap[j][1];
3268                    marker.setMap(null);
3269                    markersmap.splice(j,1);
3270                    break;
3271                }
3272            }
3273        }
3274    },
3275
3276    auto_resize_map: function()
3277    {
3278        if(this.locations.length > 0) {
3279            var max_lon = -1000000;
3280            var min_lon = 1000000;
3281            var max_lat = -1000000;
3282            var min_lat = 1000000;
3283            for( var i=0; i < this.locations.length; i++)
3284            {
3285                var location = this.locations[i];
3286                var pos = new google.maps.LatLng( parseFloat(location.lat), parseFloat(location.lng));
3287
3288                max_lon = Math.max(pos.lng(), max_lon);
3289                min_lon = Math.min(pos.lng(), min_lon);
3290                max_lat = Math.max(pos.lat(), max_lat);
3291                min_lat = Math.min(pos.lat() ,min_lat);
3292            }
3293
3294            var len_lon = max_lon - min_lon;
3295            var len_lat = max_lat - min_lat;
3296            min_lon -= len_lon * 0.01;
3297            max_lon += len_lon * 0.01;
3298            min_lat -= len_lat * 0.01;
3299            max_lat += len_lat * 0.01;
3300            var bds = new google.maps.LatLngBounds(new google.maps.LatLng(min_lat, min_lon), new google.maps.LatLng(max_lat, max_lon) );
3301            this.map.fitBounds(bds);
3302        }
3303    }
3304}
3305var googleMapPackage = {
3306    gmap: {
3307        html: '',
3308        no_pin: false,
3309        locations: '',
3310        map_lat: '',
3311        map_lng: '',
3312        initRPMap: function () {
3313            var map = new googleMap('map_canvas', this.map_lat, this.map_lng);
3314            map.map_type = 'hybrid';
3315            map.no_pin = this.no_pin;
3316            map.locations = this.locations,
3317            map.html = this.html;
3318            map.displayMap();
3319        },
3320    }
3321};
3322$.extend(true, ha, googleMapPackage);
3323var gtmPackage = {
3324    gtm:{
3325        bindEvent: function(){
3326            // Google Ecommerce for "Buy Flowers" link in menu bar.
3327            $('#buy-flowers-link').on('click', function(event){
3328                event.preventDefault();
3329                var link = $(this);
3330                var link_href = $(this).attr('href');
3331                dataLayer.push({
3332                    'event': 'promoClick',
3333                    'ecommerce': {
3334                        'promoClick': {
3335                            'promotions': [{
3336                                'name': 'Buy Flowers - Main Menu',
3337                            }]
3338                        }
3339                    },
3340                    'eventCallback': function(){
3341                        HATracking.trackContentClick(link, 'flowers_link_click', function(){
3342                            document.location = link_href;
3343                        });
3344                    }
3345                });
3346            });
3347        },
3348
3349        flowerPush: function () {
3350            dataLayer.push({
3351                'ecommerce': {
3352                    'promoView': {
3353                        'promotions': [{
3354                            'name': 'Buy Flowers - Main Menu'
3355                        }]
3356                    }
3357                },
3358                'event': 'promoView'
3359            });
3360        }
3361    }
3362
3363};
3364$.extend(true, ha, gtmPackage);
3365
3366
3367var instructPackage = {
3368    instruct: {
3369        currentStep: 0,
3370        enjoyhint: null,
3371        init: function (page) {
3372            if (page == 'memorialMain') {
3373                var that = this;
3374                var callback = function (data) {
3375                    console.log('instruct data: ', data);
3376                    if (data.status === 1) {
3377                        var result = data.result;
3378                        if (result.show === 1) {
3379                            that.run(page);
3380                            that.showToggleIcon(page);
3381                        }
3382                    }
3383                };
3384                var url = $(location).attr('href'),
3385                    parts = url.split("/"),
3386                    memorial_id = parts[parts.length - 2];
3387
3388                ha.ajax.getInstruct(memorial_id, callback);
3389            }
3390            else {
3391                this.run(page);
3392                this.showToggleIcon(page);
3393            }
3394        },
3395        showToggleIcon: function (page) {
3396            var button = $('<button id="toggleIcon" title="Go to top">?</button>');
3397            button.css({
3398                'display': 'inline-block',
3399                'position': 'fixed',
3400                '-webkit-box-sizing': 'content-box',
3401                'box-sizing': 'content-box',
3402                '-webkit-border-radius': '1em',
3403                'border-radius': '1em',
3404                'font': '400 25px/normal Arial,Helvetica,sans-serif',
3405                'color': '#fff',
3406                'background': 'rgba(132,175,22,1)',
3407                'border': '2px solid rgba(132,175,22,1)',
3408                'width': '23px',
3409                'height': '32px',
3410                'bottom': '10px',
3411                'right': '10px'
3412            });
3413            $('body').append(button);
3414            var that = this;
3415            button.on('click', function (e) {
3416                that.run(page);
3417            }).hide();
3418        },
3419        run: function (page) {
3420            var that = this;
3421            //initialize instance
3422            var enjoyhint_instance = new EnjoyHint({
3423                onClose: function () {
3424                    that.currentStep = enjoyhint_instance.getCurrentStep();
3425                    $('#toggleIcon').show();
3426                },
3427                onSkip: function () {
3428                    that.currentStep = 0;
3429                    $('#toggleIcon').show();
3430                },
3431                onStart: function () {
3432                    $('#toggleIcon').hide();
3433                }
3434            });
3435
3436            this.enjoyhint = enjoyhint_instance;
3437            var enjoyhint_script_steps = this.getStepSet(page);
3438
3439            enjoyhint_instance.set(enjoyhint_script_steps);
3440            if (this.currentStep > 0) {
3441                enjoyhint_instance.setCurrentStep(this.currentStep);
3442                enjoyhint_instance.resume();
3443            }
3444            else {
3445                enjoyhint_instance.run();
3446            }
3447        },
3448        getStepSet: function (page) {
3449            var result = [];
3450            var that = this;
3451            $.each(that.stepSet[page], function (index, data) {
3452                $.each(data, function (key, value) {
3453                    if ($(value.selector + ':visible').length > 0) {
3454                        result.push(value);
3455                    }
3456                });
3457            });
3458
3459            if (result.length > 1) {
3460                result[result.length - 1].skipButton = {text: 'Finish'};
3461                result[result.length - 1].showNext = 'false';
3462                result[result.length - 1].event = 'skip';
3463            }
3464            return result;
3465        },
3466        stepSet: {
3467            memorialMain: {
3468                postingSteps: [
3469                    {
3470                        selector: '.post_item',
3471                        description: 'Select a type of content',
3472                        event: 'next',
3473                        showNext: true
3474                    },
3475                    {
3476                        selector: '.content_post',
3477                        description: 'Click here to start posting something - you don\'t need to input any message though',
3478                        event: 'next',
3479                        showNext: true
3480                    }
3481                ],
3482                emotionIconSteps: [
3483                    {
3484                        selector: '.user-tools li:nth-child(1)',
3485                        event: 'next',
3486                        description: 'Love u - Lorem ipsum',
3487                        showNext: true
3488                    },
3489                    {
3490                        selector: '.user-tools li:nth-child(2)',
3491                        event: 'next',
3492                        description: 'Miss u - Lorem ipsum',
3493                        showNext: true
3494                    },
3495                    {
3496                        selector: '.user-tools li:nth-child(3)',
3497                        event: 'next',
3498                        description: 'Thank u - Lorem ipsum',
3499                        showNext: true
3500                    }
3501                ],
3502                sharingPublicSteps: [
3503                    {
3504                        selector: '#left_menu .share_block',
3505                        event: 'next',
3506                        description: 'Lorem ipsom',
3507                        showNext: true
3508                    },
3509                    {
3510                        selector: '#left_menu .share_block .social_icon:nth-child(1)',
3511                        event: 'next',
3512                        description: 'Facebook share Lorem ipsom',
3513                        showNext: true
3514                    },
3515                    {
3516                        selector: '#left_menu .share_block .social_icon:nth-child(2)',
3517                        event: 'next',
3518                        description: 'Twitter tweet Lorem ipsom',
3519                        showNext: true
3520                    },
3521                    {
3522                        selector: '#left_menu .share_block .social_icon:nth-child(3)',
3523                        event: 'next',
3524                        description: 'Google plus Lorem ipsom',
3525                        showNext: true
3526                    }
3527                ],
3528                sharingAddToMyHeavenSteps: [
3529                    {
3530                        selector: '#left_menu .share_block .add_memorial_li a',
3531                        event: 'next',
3532                        description: 'Lorem ipsum 2',
3533                        showNext: true
3534                    }
3535                ],
3536                sharingPrivateSteps: [
3537                    {
3538                        selector: '#left_menu .share_block .email',
3539                        event: 'skip',
3540                        description: 'Lorem ipsum 2',
3541                        showNext: true
3542                    }
3543                ],
3544                serviceDetailSteps: [
3545                    {
3546                        selector: '#funeral_service_link a',
3547                        event: 'next',
3548                        description: 'funeral service Lorem ipsum',
3549                        showNext: true
3550                    }
3551                ]
3552            },
3553            memorialCreate: {
3554                createSteps: [
3555                    {
3556                        selector: '.hint-1 div',
3557                        event: 'next',
3558                        description: 'hint-1 gender Lorem ipsum',
3559                        showNext: true
3560                    },
3561                    {
3562                        selector: '.hint-2 div',
3563                        event_type: 'custom',
3564                        event: 'first_name',
3565                        description: 'hint-2 firstname Enter first name and press tab',
3566                        onBeforeStart: function(){
3567                            $('#first_name').keydown(function(e){
3568                                if(e.keyCode == 9 && $(this).val() !== ''){
3569                                    ha.instruct.enjoyhint.trigger('first_name');
3570                                }
3571                            });
3572                        },
3573                    },
3574                    {
3575                        selector: '.hint-3 div',
3576                        event_type: 'custom',
3577                        event: 'last_name',
3578                        description: 'hint-3 lastname Enter last name and press tab',
3579                        onBeforeStart: function(){
3580                            $('#last_name').keydown(function(e){
3581                                if(e.keyCode == 9 && $(this).val() !== ''){
3582                                    ha.instruct.enjoyhint.trigger('last_name');
3583                                }
3584                            });
3585                        },
3586                    },
3587                    {
3588                        selector: '.hint-4 div',
3589                        event: 'next',
3590                        description: 'hint-4 display as lorem ipsum',
3591                        showNext: true
3592                    }
3593                ]
3594            }
3595        },
3596    }
3597};
3598$.extend(true, ha, instructPackage);
3599var mainPackage = {
3600
3601    siteURL:  '',
3602    partnerID: '',
3603    displayNameBloodhound: new Bloodhound({
3604        datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
3605        queryTokenizer: Bloodhound.tokenizers.whitespace,
3606        remote: {
3607            url: '/memorial/responsive_displayname_autocomplete?q=%QUERY',
3608            wildcard: '%QUERY'
3609        }
3610    }),
3611    langText: {
3612        ha_no_file_selected: '',
3613        ha_choose_file: ''
3614    },
3615
3616    init: function () {
3617        ha.bindEvent();
3618        ha.disableRightClickModal();
3619        ha.gtm.bindEvent();
3620        ha.gtm.flowerPush();
3621    },
3622
3623    bindEvent: function(){
3624        // $("select, input:checkbox, input:radio, input:file").not('.no-uniform, .js-switch, .switch input, .uploader-ha input, select[name="relationship"],select[name="ytube_relationship"], select[name="country"], select#fd,select#cem, select#service_location, select#dropcommunity, #content_uploadifive,select.key_date_cbo, .create_memorial_mobile .radio_row input:radio, .event-image #event_uploadify, .event-image #event_uploadifive, input.memorial-upload, .create_a_memorial_body *, .memorial-confirmation *,#white_label #partner_body *, #post_panel *').uniform({
3625        //     fileDefaultText: ha.langText.ha_no_file_selected,
3626        //     fileBtnText: ha.langText.ha_choose_file,
3627        // });
3628
3629        $("input[type='text'], textarea").not('#search-input').labelify({ replaceEmptyOnly: true, labelledClass: "labelHighlight" });
3630        $(".RF #search-input").labelify({ replaceEmptyOnly: true, labelledClass: "labelHighlight" });
3631
3632      $('.ha-main-nav .more-menu').on('click touchstart', function (e) {
3633        e.preventDefault();
3634        $('.side').toggleClass('on');
3635        $('body').toggleClass('on-side');
3636      });
3637
3638
3639      if(ha.partnerID != ''){
3640            ha.displayNameBloodhound.remote.url = '/memorial/responsive_displayname_autocomplete/'+ ha.partnerID +'?q=%QUERY';
3641        }
3642
3643        $('.input-search').typeahead({
3644                highlight: true,
3645                minLength: 3,
3646                hint: false
3647            }
3648            ,{
3649                source: ha.displayNameBloodhound,
3650                display: 'name',
3651            });
3652
3653        $('.input-search').bind('typeahead:select', function(ev, suggestion) {
3654            window.location = suggestion.url;
3655        });
3656
3657        $("#header-search i").on('mouseover', function () {
3658            var $form = $(this).parent('form');
3659            $form.addClass('active');
3660            $form.find('input').focus();
3661        });
3662
3663        $("#header-search i").on('click', function () {
3664            var $form = $(this).parent('form');
3665            if($form.hasClass('active') && $form.find('input').val().length != 0) {
3666                $form.submit();
3667                return;
3668            } else if(!$form.hasClass('active')){
3669                $form.addClass('active');
3670                $form.find('input').focus();
3671            }
3672        });
3673
3674        load_top_notification();
3675
3676        $('body').on('click', '#mark_read_all', function(e){
3677            e.preventDefault();
3678            $.ajax({
3679                type: 'POST',
3680                url: '/profile/remove_notification',
3681                dataType: 'json',
3682                success: function(response) {
3683                    load_top_notification();
3684                }
3685            });
3686        });
3687
3688        $("#header-search input").on('blur', function () {
3689            if($(this).val().length == 0)
3690                $(this).closest('form').removeClass('active');
3691        });
3692
3693        $('a.scroll-down').on('click', function(e) {
3694            e.preventDefault();
3695            $('html, body').animate({ scrollTop: $($(this).attr('href')).offset().top}, 500, 'linear');
3696        });
3697
3698        $(".whitelabel_header .header-holder").sticky({
3699            topSpacing:0,
3700            zIndex:99
3701        });
3702
3703        $("#left-panel").not(".whitelabel-container #left-panel").sticky({
3704            topSpacing: 80
3705        });
3706
3707        $(".partners").not(".whitelabel-container .partners").sticky({
3708            topSpacing: 70,
3709        });
3710
3711        $('.whitelabel-container #left-panel').sticky({
3712            topSpacing: 108,
3713        });
3714
3715        $(".whitelabel-container .partners").sticky({
3716            topSpacing: 108,
3717        });
3718
3719        if ($("img[usemap]").length > 0) {
3720            $('img[usemap]').rwdImageMaps();
3721        }
3722
3723        $('#search-icon').on('click touchstart', function (e) {
3724            e.stopPropagation();
3725            e.preventDefault();
3726            var searchForm = $('#mobile-menu-search');
3727            if(searchForm.hasClass('hidden')) {
3728                $('#mobile-menu-search').removeClass('hidden');
3729                $('#search-icon .fas.fa-search').removeClass('fa-search');
3730                $('#search-icon .fas').addClass('fa-times');
3731            } else {
3732                $('#mobile-menu-search').addClass('hidden');
3733                $('#search-icon .fas.fa-times').removeClass('fa-times');
3734                $('#search-icon .fas').addClass('fa-search');
3735            }
3736
3737        });
3738
3739        $('a[data-toggle="modal"]').on('click', function (e) {
3740            e.preventDefault();
3741        });
3742    },
3743
3744    disableRightClickModal: function () {
3745        //prevent default behavior of middle click for popup
3746        $("a[data-target='#myModal'], a.bs-modal-normal, a.authentication-popup").mousedown(function(e) {
3747            e.preventDefault();
3748            if(e.which == 2){
3749                $(this).click();
3750            }
3751            return false;
3752        });
3753        //disable context menu for popup and right click event
3754        $("a[data-target='#myModal'], a.bs-modal-normal, a.authentication-popup").on('contextmenu', function(e){
3755            e.preventDefault();
3756            $(this).click();
3757            return false;
3758        });
3759
3760
3761    },
3762
3763    convertTimeToEnglishFormat: function(time, languageCode) {
3764        var period = '';
3765        var periodTmp;
3766        var timeTmp, hour, min, convertedTime;
3767        if (languageCode == 'zh-CN' || languageCode == 'zh-TW')
3768        {
3769            periodTmp = time.substr(0, 2);
3770            switch (periodTmp)
3771            {
3772                case '凌晨':
3773                case '上午':
3774                    period = 'AM';
3775                    break;
3776                case '下午':
3777                case '晚上':
3778                    period = 'PM';
3779                    break;
3780            }
3781            timeTmp = time.substr(2, 5);
3782            timeTmp = timeTmp.split(':');
3783            hour = timeTmp[0];
3784            min = timeTmp[1];
3785            convertedTime = hour + ':' + min + ' ' + period;
3786        }
3787        else if (languageCode == 'es' || languageCode == 'fr')
3788        {
3789            timeTmp = time.split(':');
3790            hour = timeTmp[0];
3791            min = timeTmp[1];
3792            period = 'AM';
3793            if (hour >= 12)
3794            {
3795                if(hour > 12) {
3796                    hour -= 12;
3797                }
3798
3799                period = 'PM';
3800            }
3801            convertedTime = hour + ':' + min + ' ' + period;
3802        }
3803        else if (languageCode == 'pt')
3804        {
3805            if (time == 'Meia-noite')
3806            {
3807                convertedTime = '12:00 AM';
3808            }
3809            else if (time == 'Meio-dia')
3810            {
3811                convertedTime = '12:00 PM';
3812            }
3813            else
3814            {
3815                timeTmp = time.split(':');
3816                hour = timeTmp[0];
3817                min = timeTmp[1].substr(0, 2);
3818                periodTmp = timeTmp[1].substr(6, 3);
3819
3820                if (periodTmp == 'man')
3821                {
3822                    convertedTime = hour + ':' + min + ' AM';
3823                }
3824                else
3825                {
3826                    convertedTime = hour + ':' + min + ' PM';
3827                }
3828            }
3829        }
3830        else {
3831            convertedTime = time;
3832        }
3833
3834        return convertedTime;
3835    },
3836
3837    reloadCallBack: function (data) {
3838        window.location.reload();
3839    },
3840
3841    companyLanding: {
3842        companyInit: function() {
3843            $('#pannel').find('.description').readmore();
3844        },
3845        branchInit: function() {
3846            var branches =  $.parseJSON($('#gmap-data').text());
3847            console.log($('#gmap-data').text());
3848            ha.companyLanding.showMap(branches);
3849            $('#branch-panel').find('.description').readmore();
3850        },
3851        showMap: function(locations) {
3852            var marker, i;
3853
3854            var mapOptions = {
3855                zoom: 18,
3856                mapTypeId: google.maps.MapTypeId.ROADMAP,
3857                fullscreenControl: true,
3858                streetViewControl: false
3859            };
3860            var bounds = new google.maps.LatLngBounds();
3861            var map = null;
3862            var geocoder = new google.maps.Geocoder();
3863            var infoWindow = new google.maps.InfoWindow();
3864            // var placeService = new google.maps.places.PlacesService(map);
3865
3866            var multiple = false;
3867            if (locations.length > 1) {
3868                multiple = true;
3869            }
3870            for (i = 0; i < locations.length; i++) {
3871
3872                var point;
3873                var location = locations[i];
3874                if (location.lat && location.lng) {
3875                    point = new google.maps.LatLng(location.lat, location.lng);
3876                    ha.companyLanding.renderMap(map, point, bounds, location, infoWindow, multiple);
3877                    // placeService.textSearch({'query': location.name, 'location': point, 'radius': 100}, function(results, status) {
3878                    //     if (status === google.maps.GeocoderStatus.OK) {
3879                    //         if (results[0]) {
3880                    //             ha.companyLanding.getPlaceDetail(placeService, results[0].place_id);
3881                    //         }
3882                    //     }
3883                    // });
3884                }
3885            }
3886
3887            if (locations.length > 1) {
3888                // map.fitBounds(bounds);
3889            }
3890            else {
3891
3892            }
3893
3894        },
3895        addMarker: function(infoWindow, marker, location, point) {
3896            google.maps.event.addListener(marker, 'mouseover', (function (marker) {
3897                return function () {
3898                    var info_win_str = '<div class="info_win"><strong>' + location.name + '</strong><br/>' + location.address;
3899
3900                    infoWindow.setContent(info_win_str);
3901                    infoWindow.open(this.map, marker);
3902                    $('.info_win').parent().css('overflow', '');
3903                    infoWindow.content_changed = function () {
3904                        infoWindow.open(this.map, marker);
3905                    };
3906
3907                    this.current_infowindow = infoWindow;
3908                    this.current_latlng = point;
3909                }
3910            })(marker));
3911            google.maps.event.addListener(marker, 'mouseout', function() {
3912                infoWindow.close();
3913            });
3914        },
3915        renderMap: function(map, point, bounds, location, infoWindow, multiple) {
3916            // marker = new google.maps.Marker({
3917            //     position: point,
3918            //     map: map
3919            // });
3920            // ha.companyLanding.addMarker(infoWindow, marker,location, point);
3921
3922            if (multiple) {
3923                bounds.extend(marker.getPosition());
3924            }
3925            else {
3926                // map.setCenter(point);
3927                if ($('#branchPano').length > 0) {
3928                    var pano = new google.maps.StreetViewPanorama(
3929                        document.getElementById('branchPano'),
3930                        {
3931                            position: point,
3932                            preference: google.maps.StreetViewPreference.BEST,
3933                            radius: 500
3934                        });
3935                }
3936            }
3937        },
3938        getPlaceDetail: function(placeService, placeId) {
3939            var open = $('.info .opening_hours');
3940            placeService.getDetails({placeId: placeId}, function(placeResult, placeStatus){
3941                console.log(placeResult);
3942                if (placeResult['photos']) {
3943                    for (var j=1; j<3; j++) {
3944                        if (placeResult['photos'][j-1]) {
3945                            var photoUrl = placeResult['photos'][j-1].getUrl({'maxWidth': 1920});
3946                            $('#place-img-'+j).attr('src', photoUrl).show();
3947                            $('#place-img-'+j).parent().attr('href', photoUrl);
3948                        }
3949                    }
3950                    $('.place-photo-fancybox').fancybox({'type':'image'});
3951                }
3952
3953
3954                if (placeResult['opening_hours']) {
3955
3956                    var d = new Date();
3957                    var n = d.getDay();
3958                    var googleDayOfWeekIndex = n-1 < 0 ? 6 : n-1;
3959                    var chevron = '<a href="#" id="open-hours-toggle"><span class="glyphicon glyphicon-menu-down"></span></a></span>';
3960                    var openHourToggleWrapper = '<span id="toggle-wrapper">'+placeResult['opening_hours']['weekday_text'][googleDayOfWeekIndex] + chevron +'</span>';
3961                    var fullOpenHours = '<table style="display:none"> \n';
3962                    for (var index=0; index<7; index++) {
3963                        var split = placeResult['opening_hours']['weekday_text'][googleDayOfWeekIndex].split(": ");
3964                        fullOpenHours += '<tr>';
3965                        fullOpenHours += '<td>'+split[0]+'</td>';
3966                        fullOpenHours += '<td>'+split[1]+'</td>';
3967                        fullOpenHours += '</tr>';
3968                        googleDayOfWeekIndex = googleDayOfWeekIndex+1;
3969                        if ( googleDayOfWeekIndex > 6) googleDayOfWeekIndex = 0;
3970                    }
3971                    //fullOpenHours += '</ul>';
3972                    fullOpenHours += '</table>';
3973
3974                    open.html(openHourToggleWrapper + fullOpenHours).show();
3975
3976                    $('#open-hours-toggle').on('click', function(e) {
3977                        e.preventDefault();
3978                        open.find('table').show();
3979                        open.find('span#toggle-wrapper').hide();
3980                    });
3981
3982                    open.on('click', 'table', function() {
3983                        $(this).hide();
3984                        open.find('span#toggle-wrapper').show();
3985                    });
3986                }
3987            })
3988        }
3989    },
3990    storage: {
3991        save : function(key, jsonData, expirationMin){
3992            if (typeof (Storage) == "undefined"){return false;}
3993            var expirationMS = expirationMin * 60 * 1000;
3994            var record = {value: JSON.stringify(jsonData), timestamp: new Date().getTime() + expirationMS}
3995            localStorage.setItem(key, JSON.stringify(record));
3996            return jsonData;
3997        },
3998        load : function(key){
3999            if (typeof (Storage) == "undefined"){return false;}
4000            var record = JSON.parse(localStorage.getItem(key));
4001            if (!record){return false;}
4002            return (new Date().getTime() < record.timestamp && JSON.parse(record.value));
4003        }
4004    }
4005};
4006$.extend(true, ha, mainPackage);
4007
4008/* Licensed under the MIT License, Paris Kasidiaris <[email protected]> */
4009function notificationCenter(options) {
4010	var element = document.createElement("ul");
4011	element.setAttribute("class", "njs-notification-center");
4012	document.body.appendChild(element);
4013	if ( typeof options == 'undefined' ) element.options = {};
4014	else element.options = options;
4015	element.notify = function(options) {
4016		var opt = {};
4017		for ( var attr in element.options ) opt[ attr ] = element.options[ attr ];
4018		for ( var attr in options ) opt[ attr ] = options[ attr ];
4019		var n = notification(opt);
4020		if ( n.DOCUMENT_NODE ) {
4021			if (!element.firstChild) element.appendChild(n);
4022			else element.insertBefore(n, element.firstChild);
4023		}
4024		n.show();
4025		return n;	
4026	}
4027	element.destroy = function() {
4028		return this.parentNode.removeChild( this );
4029	}
4030	return element;
4031}
4032
4033function notification(options) {
4034	if ( window.webkitNotifications && !window.webkitNotifications.checkPermission() && options.desktopNotification !== false ) {
4035		var title = options.title , content = options.content , icon = null;
4036		if ( options.icon ) icon = options.icon;
4037		var notification = window.webkitNotifications.createNotification( icon , title , content );
4038		return notification;
4039	}
4040	if ( typeof options == "undefined") options = new Object();
4041	var element = document.createElement("li"), title = document.createElement("div"), content = document.createElement("div"), image = document.createElement("img"), closeButton = document.createElement("span");
4042	element.setAttribute("class", "njs-notification" );
4043	content.setAttribute("class", "njs-notification-content");
4044	if ( typeof options.title != "undefined") {
4045		var title = document.createElement("div");
4046		title.setAttribute("class", "njs-notification-title");
4047		title.textContent = options.title;
4048		title.style.fontWeight = "bold";
4049		element.appendChild(title);
4050	}
4051	content.innerHTML = options.content;
4052	element.appendChild(content);
4053	if ( options.icon ) {
4054		var icon = document.createElement( 'img' );
4055		icon.setAttribute( 'src' , options.icon );
4056		icon.setAttribute( 'class' , 'njs-notification-icon' );
4057		element.insertBefore( icon , element.firstChild );
4058	}
4059	element.show = function() {
4060		element.style.display = "block";
4061		if ( options.ondisplay ) options.ondisplay.call( this );
4062	}
4063	element.close = function() {
4064		element.style.display = "none";
4065		if ( options.onclose ) options.onclose.call( this );
4066	}
4067	element.onclick = function (e) {
4068		if ( options.onclick ) options.onclick.call( this , e );
4069	}
4070	element.destroy = function() {
4071		return this.parentNode.removeChild( this );
4072	}
4073	element.getTitle = function() {
4074		return title.textContent;
4075	}
4076	element.getContent = function() {
4077		return content.innerHTML;
4078	}
4079	closeButton.setAttribute("class", "njs-notification-close-button");
4080	closeButton.innerHTML = "&times;";
4081	closeButton.onmousedown = function() {
4082		element.parentNode.removeChild(element);
4083	}
4084	element.appendChild(closeButton);
4085	return element;
4086}
4087var popupPackage = {
4088    popup:{
4089        initActivateArchive: function () {
4090            $(".mn_title").tipTip();
4091            $("#link_relationship").flexselect();
4092            ha.popup.bindActiveArchiveEvent();
4093        },
4094
4095        initAddMemorial: function () {
4096            $(".mn_title").tipTip();
4097            $("select.link_flexselect").flexselect();
4098            ha.popup.bindAddMemorial();
4099        },
4100
4101        bindAddMemorial: function () {
4102            $('#link_relationship_flexselect').blur(function(){
4103                ha.popup.checkRelationship();
4104            });
4105
4106            $('#btn-update-relationship').on('click', function (e) {
4107               ha.popup.submitRelationshipForm(e, ha.popup.successAddMemorial);
4108            });
4109        },
4110
4111        bindActiveArchiveEvent: function () {
4112            $('#save_active').on('click', function(e){
4113                ha.popup.submitRelationshipForm(e, ha.popup.successActivate);
4114            });
4115
4116            $('#link_relationship_flexselect').blur(function () {
4117                $('#link_relationship_flexselect_dropdown').css('height', '55px');
4118                ha.popup.checkRelationship();
4119            });
4120        },
4121
4122        submitRelationshipForm: function (e, successCallback) {
4123            e.preventDefault();
4124            if(ha.popup.checkRelationship()){
4125                var memorial_grouping = $("select[name='memorial_grouping']").val();
4126                var subscription = $("select[name='subscription']").val();
4127                var link_relationship = $('#link_relationship').val();
4128                var page = $('#page_name').val();
4129                var data = {
4130                    memorial_grouping: memorial_grouping,
4131                    subscription: subscription,
4132                    link_relationship: link_relationship,
4133                    page: page
4134
4135                };
4136                ha.ajax.submitRelationship(data, successCallback);
4137            }
4138        },
4139
4140        checkRelationship: function () {
4141            var value = $('#link_relationship_flexselect').val();
4142            if(value != '') {
4143                $('#link_relationship_flexselect').css('border','1px solid #D3D3D3');
4144                return true;
4145            }
4146            else {
4147                $('#link_relationship_flexselect').css('border','1px solid red');
4148                return false;
4149            }
4150        },
4151
4152        successActivate: function (data) {
4153            if(data.redirect_url) {
4154                document.location = data.redirect_url;
4155            } else {
4156                $("#myModal").find(".modal-body").html(data.msg);
4157            }
4158            
4159        },
4160
4161        successAddMemorial: function (data) {
4162           document.location = '/profile/view_memorials/'+ data.user_id +'/'+ data.success;
4163           
4164        },
4165    }
4166};
4167
4168$.extend(true, ha, popupPackage);
4169
4170var socialPackage = {
4171    social:{
4172        isShortenURL: false,
4173        $container: null,
4174        memorialUrl: null,
4175        shortenUrl: null,
4176
4177        bindEvent: function () {
4178            ha.social.$container = $('#social-left-sticky-bar');
4179            ha.social.memorialUrl = ha.social.$container.data('memorial-url');
4180
4181            ha.social.$container.find('.fb-icon').click(function () {
4182                    ha.social.fbShare();
4183            });
4184
4185            ha.social.$container.find('.shorten').click(function (e) {
4186                var currentElement = $(this);
4187                if (currentElement.hasClass('twitter-icon')) {
4188                    var wi = window.open('about:blank', "twitterwindow", "height=450, width=550, toolbar=0, location=0, menubar=0, directories=0, scrollbars=0");
4189                }
4190                if(ha.social.shortenUrl) {
4191                    ha.social.gotoUrl(wi, currentElement);
4192                    return;
4193                }
4194                else {
4195                    e.preventDefault();
4196                    ha.social.getShortLink(currentElement).then(function () {
4197                        ha.social.gotoUrl(wi, currentElement);
4198                    })
4199                }
4200            });
4201        },
4202
4203        fbShare: function () {
4204            FB.ui({
4205                method: 'share',
4206                href: ha.social.$container.find('.fb-icon').data('href'),
4207                display: 'popup'
4208            }, function(response){
4209                if (response && !response.error_code) {
4210                    var fbCounter = ha.social.$container.find('.fb-icon .social-counter-number').html();
4211                    if(fbCounter === ''){
4212                        fbCounter = 1;
4213                    }
4214                    else{
4215                        fbCounter = parseInt(fbCounter) + 1;
4216                    }
4217
4218                    ha.social.$container.find('.fb-icon .social-counter-number').html(fbCounter);
4219                }
4220            });
4221        },
4222        
4223        gotoUrl: function (wi, $el) {
4224          var dataHref = $el.data('href');
4225          if (ha.social.shortenUrl != null) {
4226              if ($el.hasClass('twitter-icon')) {
4227                  var newTWUrl = dataHref.replace(ha.social.memorialUrl, ha.social.shortenUrl);
4228                  wi.location.href = newTWUrl;
4229              }
4230              else {
4231                  var encodedMemorialUrl = encodeURIComponent(ha.social.memorialUrl);
4232                  var encodedShortenUrl = encodeURIComponent(ha.social.shortenUrl);
4233                  var newUrl = dataHref.replace(encodedMemorialUrl, encodedShortenUrl);
4234
4235                  window.location = newUrl;
4236
4237              }
4238          }
4239        },
4240
4241        getShortLink: function () {
4242            return new Promise(function (resolve) {
4243                ha.ajax.init("/memorial/ajax_shorten_url", {'url': ha.social.memorialUrl}, function (data) {
4244                    ha.social.isShortenURL = true;
4245                    ha.social.shortenUrl = data.id;
4246
4247                    resolve(ha.social.shortenUrl);
4248                });
4249            })
4250        }
4251    }
4252};
4253$.extend(true, ha, socialPackage);
4254
4255//# sourceMappingURL=sourcemap/site/site.js.map

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.