// Validazione Campi + Disabilitazione  tasto invia se....JavaScript Document
var checkobj

function agreesubmit(el){
checkobj=el
if (document.all||document.getElementById){
for (i=0;i<checkobj.form.length;i++){  //hunt down submit button
var tempobj=checkobj.form.elements[i]
if(tempobj.type.toLowerCase()=="submit")
tempobj.disabled=!checkobj.checked
}
}
}

function defaultagree(el){
if (!document.all&&!document.getElementById){
if (window.checkobj&&checkobj.checked)
return true
else{
alert("Leggere ed accettare le condizioni sulla Privacy.")
return false
}
}
}

function formCheck(formobj){
        // Enter name of mandatory fields
        var fieldRequired = Array("Nome", "Telefono", "Email", "Messaggio" );
        // Enter field description to appear in the dialog box
        var fieldDescription = Array("Nome", "Telefono", "Email", "Messaggio");
        // dialog message
        var alertMsg = "Non hai compilato correttamente il form.\n Alcune informazioni non sono state inserite.\n Clicca su OK e verifica l'errore.\nI seguenti campi non sono stati compilati:\n";

        var l_Msg = alertMsg.length;

        for (var i = 0; i < fieldRequired.length; i++){
                var obj = formobj.elements[fieldRequired[i]];
                if (obj){
                        switch(obj.type){
                        case "select-one":
                                if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
                                        alertMsg += " - " + fieldDescription[i] + "\n";
                                }
                                break;
                        case "select-multiple":
                                if (obj.selectedIndex == -1){
                                        alertMsg += " - " + fieldDescription[i] + "\n";
                                }
                                break;
                        case "text":
                        case "textarea":
                                if (obj.value == "" || obj.value == null){
                                        alertMsg += " - " + fieldDescription[i] + "\n";
                                }
                                break;
                        default:
                        }
                        if (obj.type == undefined){
                                var blnchecked = false;
                                for (var j = 0; j < obj.length; j++){
                                        if (obj[j].checked){
                                                blnchecked = true;
                                        }
                                }
                                if (!blnchecked){
                                        alertMsg += " - " + fieldDescription[i] + "\n";
                                }
                        }
                }
        }

        if (alertMsg.length == l_Msg){
                return true;
        }else{
                alert(alertMsg);
                return false;
        }
}
