(function () {
    function MissingValueException(element, text) {
        this.element = element;
        this.text    = text;
    }

    var Contact = {
        checkField: function (id, text) {
                        var element = document.getElementById(id);
                        if (element && element.value === "") {
                            throw new MissingValueException(element, text);
                        }
                    },

        validate:   function (e) {
                        try {
                            Contact.checkField("contact-name", "ditt namn");
                            Contact.checkField("contact-phone", "ditt telefonnummer");
                            Contact.checkField("msg-text", "det meddelande du vill skicka");
                        } catch (ex) {
                            alert("Var god ange " + ex.text + ".");
                            ex.element.focus();
                            return false;
                        }
                        return true;
                    }
    };

    if (document.getElementById) {
        var form = document.getElementById("contact-form");
        if (form) {
            form.onsubmit = Contact.validate;
        }
    }
})();

