var mf = new Object;
mf.Form = function(){
    this.check = new Object;
    this.check.textbox = function(node){
        if(node.value == ''){
            node.style.backgroundColor = 'red';
            return false;
        }
        node.style.backgroundColor = 'white';
        return true;
    }
    this.check.combobox = function(node){
        if(node.options[node.selectedIndex].value == ''){
            node.style.backgroundColor = 'red';
            return false;
        }
        node.style.backgroundColor = 'white';
        return true;
    }
    this.check.checkbox = function(node){
        if(!node.checked){
            node.parentNode.style.border = '2px solid red';
            node.parentNode.style.padding = '2px';
            return false;
        }
        node.parentNode.style.border = '0 none transparent';
        node.parentNode.style.padding = '0';
        return true;
    }
    this.check.required = new Array;
    this.check.required[0] = new Array("language","combobox");
    this.check.required[1] = new Array("pohlavi","combobox");
    this.check.required[2] = new Array("jmeno","textbox");
    this.check.required[3] = new Array("prijmeni","textbox");
    this.check.required[4] = new Array("email","textbox");
    this.check.required[5] = new Array("souhlas","checkbox");
    this.form = document.getElementById("newslet");
    this.form.isValid = function(){
        for(var i=0; i<mf.form.check.required.length; i++){
            var node = document.getElementById(mf.form.check.required[i][0]);
            if(node){
                node.onclick = function(){
                    this.style.backgroundColor = 'white';
                }
            }
        }
        var res = true;
        for(var i=0; i<mf.form.check.required.length; i++){
            var node = document.getElementById(mf.form.check.required[i][0]);
            if(mf.form.check.required[i][1] == 'textbox'){
                if(!mf.form.check.textbox(node)){
                    res = false;
                }
            }
            if(mf.form.check.required[i][1] == 'combobox'){
                if(!mf.form.check.combobox(node)){
                    res = false;
                }
            }
            if(mf.form.check.required[i][1] == 'checkbox'){
                if(!mf.form.check.checkbox(node)){
                    res = false;
                }
            }
        }
        if(!res){
            return false;
        }
        return true;
    }
    this.form.onsubmit = this.form.isValid;
    this.form.onreset = this.form.isValid;
}
mf.form = new mf.Form;

