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('please enter an amount')
                }
                else
                {
                    $( "#form" ).submit();
                }

            
        }
        else
        {
            alert("You have entered an invalid email address!")
        }

        

        
      
    
    });

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

    
   

});