function CompetitionEntryParticipation(element, completeHandler) {
    this.element = element;
    this.completeHandler = completeHandler;
    this.attachToEvents();
}

CompetitionEntryParticipation.prototype.attachToEvents = function() {
    var formElements = this.element.elements;
    var self = this;
    this.element.onsubmit = function() {
        var elements = self.getMandatoryElementsWithoutValues();
        if (elements.length == 0) {
            self.createOverlay();
            self.createIframe();
            self.setFormTarget();
            self.disableSubmitButton();
        } else {
            return true;
        }
    }
}

CompetitionEntryParticipation.prototype.disableSubmitButton = function () {
    Elements.getElementById("competition-submit").disabled=true;
};


CompetitionEntryParticipation.prototype.getMandatoryElementsWithoutValues = function() {
    return Array.filter(this.element.elements, function (element) {
        return new ClassName(element).contains('mandatory') && (element.value == '');
    });
}

CompetitionEntryParticipation.prototype.createOverlay = function() {
    this.overlay = new Overlay("small", false);
}

CompetitionEntryParticipation.prototype.createIframe = function() {
    this.iframe = Elements.create('<iframe name="progress" class="progress"></iframe>');
    Elements.insertBefore(this.element, this.iframe);
    var self = this;
    this.iframe.addEventListener("load", function() {
        self.overlay.show();
        self.completeHandler.handle(self);
    }, false);

}

CompetitionEntryParticipation.prototype.setFormTarget = function() {
    this.element.setAttribute("target", this.iframe.getAttribute("name"));
}

