odoo.define('kalachakra.main', function (require) {
    

    $(document).ready(function() {
        
       
 
    });

    $( ".list-group-item" ).click(function() {
        var txtamount = $( this ).text();
        l=txtamount.length
        amount=txtamount.substr(0,l-2)
        if (jQuery(this).attr("id")=="btn_autre")
        {
            $("#amount_id").focus();
        }
        $("#amount_id").val(amount)
    });


    $( "#pay_now_btn" ).click(function() {
        
        $('#form').attr('action', '/kalachakra/participation?type=participation');
        $( "#form" ).submit();
    });

    $( "#pay_membership_btn" ).click(function() {
        
        $('#form').attr('action', '/kalachakra/participation?type=membership_and_participation');
        $( "#form" ).submit();
    });

    $( "#make_donation_btn" ).click(function() {
        
        $('#form').attr('action', '/kalachakra/participation?type=donation');
        $( "#form" ).submit();
    });


    $( "#pay_on_the_spot_btn" ).click(function() {

        $('#form').attr('action', '/kalachakra/onthespotpayment');
        
        
        $( "#form" ).submit();

    });


    $( "#btn_payment_choice" ).click(function() {

        //validation de l'adresse mail
        if  (ValidateEmail($("#email").val()))
        {
                //vérification montant
                if ($("#amount_id").val()==0)
                {
                    alert('merci de saisir un montant')
                }
                else if ($("#name_id").val()=='')
                {
                    alert('merci de saisir votre nom')
                }
                else if ($("#firstname_id").val()=='')
                {
                    alert('merci de saisir votre prénom')
                }
                else if ($("#street1_id").val()=='')
                {
                    alert('merci de saisir votre adresse')
                }
                else if ($("#city_id").val()=='')
                {
                    alert('merci de saisir votre ville')
                }
                else if ($("#zip_id").val()=='')
                {
                    alert('merci de saisir votre code postal')
                }
                else if ($("#title_id").val()=='')
                {
                    alert('merci de saisir votre civilité')
                }
                else
                {
                    $( "#form" ).submit();
                }

            
        }
        else
        {
            alert("adresse e-mail invalide")
        }

        

        
      
    
    });

    function ValidateEmail(mail) 
{
 if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(mail))
  {
    return (true)
  }
    
    return (false)
}

    
   

});

odoo.define('kalachakra.widget_booking_event', function (require) {
    'use strict';
    
    var publicWidget = require('web.public.widget');
    
    publicWidget.registry.visitor2 = publicWidget.Widget.extend({
        selector: ".oe_country_booking_events, .country_booking_events",
        disabledInEditableMode: false,
    
        /**
         * @override
         */
        start: function () {
            var defs = [this._super.apply(this, arguments)];
            var self = this;
            var $eventBookingList = this.$('.country_booking_events_list');
            this._originalContent = $eventBookingList[0].outerHTML;
            
            defs.push(this._rpc({route: '/event/get_country_booking_event_list'}).then(function (data) {
                if (data) {
                    self._$loadedContent = $(data);
    
                    self._$loadedContent.attr('contentEditable', false);
                    self._$loadedContent.addClass('o_temp_auto_element');
                    self._$loadedContent.attr('data-temp-auto-element-original-content', self._originalContent);
    
                    $eventBookingList.replaceWith(self._$loadedContent);
                }
            }));
            return Promise.all(defs);
        },
        /**
         * @override
         */
        destroy: function () {
            this._super.apply(this, arguments);
            if (this._$loadedContent) {
                this._$loadedContent.replaceWith(this._originalContent);
            }
        },
    });
    });
  
    