Invitation = new ( Class.create({
    
    initialize : function()
    {
    },
    
    LockFunctions : false,
    
    InvitationWindow : new Window({
        container: "window",
        title: "Meghívó",
        width: 360,
        contentURL: "Components/Invitation/Invitation.php"
    }),
    
    InvitationClicked : function(event)
    {
        Event.stop(event);
        
        GlobalLoading.Start();
        
        var invitationData = ActionHandler.GetResponse(
        {
            url: "Components/Invitation/InvitationActionHandler.php",
            action: "GetInvitationData"
        });
        
        this.InvitationWindow.Show();
        
        $("invitationText").insert("Meghívóid száma: " + invitationData.account_invitation + " (naponta " + invitationData.invitationPerDay + ")");
        
        var thisClass = this;
        
        $("email").focus();
        
        Event.observe("invitationCancel", "click", function(event) { Event.stop(event); thisClass.InvitationWindow.Close(); } );
        Event.observe("invitationOK", "click", this.SendInvitation.bindAsEventListener(this));
        
        GlobalLoading.Stop();
    },
    
    SendInvitation : function(event)
    {
        Event.stop(event);
        
        GlobalLoading.Start();
        
        if(!this.Lockfunctions)
        {
            if(Utils.IsValidString($("email").value, "Email"))
            {
                var pars = "email=" + encodeURIComponent($("email").value);
                var sendingData = ActionHandler.GetResponse(
                {
                    url: "Components/Invitation/InvitationActionHandler.php",
                    action: "SendInvitation",
                    parameters: pars
                });
                if(sendingData.isFreeEmail)
                {
                    $("invitationText").update("<br/><br/>Meghívódat elküldtük a megadott e-mail címre.");
                    $("email").value = "";
                }
                else
                {
                    $("invitationText").update("<br/><br/>A megadott e-mail címmel már regisztráltak.");
                }
            }
            else
            {
                $("invitationText").update("<br/><br/>Érvénytelen e-mail címet adtál meg.");
            }
        }
        
        GlobalLoading.Stop();
    }
    
}))();
