/***********************************
* Modulo Richiesta Preventivi
************************************
* $version: 0.3;
* $date: 22/09/2005;
* file: fuction.js;
* $size: 6879bytes;
* $author: Service4PC.it
* $url: http://www.service4pc.it/
***********************************/

function isEmpty(str) {
         for (var intLoop = 0; intLoop<str.length; intLoop++)
             if (" " != str.charAt(intLoop))
                return false;
             return true;
}

function checkSfondo(f) {
         for (var intLoop = 0; intLoop<f.elements.length; intLoop++)
             if ("sfondo"==f.elements[intLoop].className) {
                alert("Tutti i campi con un * sono obbligatori.");
                return false;
             }
}

function fixUp(el) {
         el.className = isEmpty(el.value) ? "sfondo" : "";
}

function checkChar(el) {
         if (32 != event.keyCode)
            el.className = "";
}

function checkForm() {
     // Variabili associate ai campi del form
     var v_local_da = document.modulo_prev.local_da.value;
     var v_local_a = document.modulo_prev.local_a.value;
     var v_data_part_gg = document.modulo_prev.data_part_gg.value;
     var v_data_part_mm = document.modulo_prev.data_part_mm.value;
     var v_data_part_yy = document.modulo_prev.data_part_yy.value;
     var v_data_rit_gg = document.modulo_prev.data_rit_gg.value;
     var v_data_rit_mm = document.modulo_prev.data_rit_mm.value;
     var v_data_rit_yy = document.modulo_prev.data_rit_yy.value;
     var v_lingua = document.modulo_prev.lingua.value;
     var v_posti = document.modulo_prev.posti.value;
     var v_nome = document.modulo_prev.nome.value;
     var v_email = document.modulo_prev.email.value;
     var v_indirizzo = document.modulo_prev.indirizzo.value;
     var v_citta = document.modulo_prev.citta.value;
     var v_nazione = document.modulo_prev.nazione.value;
     var v_cap = document.modulo_prev.cap.value;
     var v_tel = document.modulo_prev.tel.value;

     var regex = /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/;
     var regex2 = /^[2][0][0-9][0-9]$/;

     if ((v_local_da == "") || (v_local_da == "undefined")) {
        // Effettua il controllo sul campo 'local_da'
        alert("Il campo 'Località di partenza' è obbligatorio.");
        // document.modulo_prev.local_da.focus();
        return false;
     } else if ((v_local_a == "") || (v_local_a == "undefined")) {
        // Effettua il controllo sul campo 'local_a'
        alert("Il campo 'Località di arrivo' è obbligatorio.");
        // document.modulo_prev.local_a.focus();
        return false;
     } else if ((v_data_part_gg == "") || (v_data_part_gg == "undefined")) {
        // Effettua il controllo sul campo 'data_part_gg'
        alert("Il campo 'Data della partenza (Giorno)' è obbligatorio.");
        // document.modulo_prev.data_part_gg.focus();
        return false;
     } else if ((v_data_part_mm == "") || (v_data_part_mm == "undefined")) {
        // Effettua il controllo sul campo 'data_part_mm'
        alert("Il campo 'Data della partenza (Mese)' è obbligatorio.");
        // document.modulo_prev.data_part_mm.focus();
        return false;
     } else if ((v_data_part_yy == "") || (!regex2.test(v_data_part_yy)) || (v_data_part_yy == "undefined")) {
        // Effettua il controllo sul campo 'data_part_yy'
        alert("Il campo 'Data della partenza (Anno)' è obbligatorio.");
        // document.modulo_prev.data_part_yy.focus();
        return false;
     } else if ((v_data_rit_gg == "") || (v_data_rit_gg == "undefined")) {
        // Effettua il controllo sul campo 'data_rit_gg'
        alert("Il campo 'Data di ritorno (Giorno)' è obbligatorio.");
        // document.modulo_prev.data_rit_gg.focus();
        return false;
     } else if ((v_data_rit_mm == "") || (v_data_rit_mm == "undefined")) {
        // Effettua il controllo sul campo 'data_rit_mm'
        alert("Il campo 'Data di ritorno (Mese)' è obbligatorio.");
        // document.modulo_prev.data_rit_mm.focus();
        return false;
     } else if ((v_data_rit_yy == "") || (!regex2.test(v_data_rit_yy)) || (v_data_rit_yy == "undefined")) {
        // Effettua il controllo sul campo 'data_rit_yy'
        alert("Il campo 'Data di ritorno (Anno)' è obbligatorio.");
        // document.modulo_prev.data_rit_yy.focus();
        return false;
     } else if ((v_lingua == "") || (v_lingua == "undefined")) {
        // Effettua il controllo sul campo 'lingua'
        alert("Il campo 'Lingua' è obbligatorio.");
        // document.modulo_prev.lingua.focus();
        return false;
     } else if ((v_posti == "") || (v_posti == "undefined")) {
        // Effettua il controllo sul campo 'posti'
        alert("Il campo 'Numero dei posti' è obbligatorio.");
        // document.modulo_prev.posti.focus();
        return false;
     } else if ((v_nome == "") || (v_nome == "undefined")) {
        // Effettua il controllo sul campo 'nome'
        alert("Il campo 'Nome' è obbligatorio.");
        // document.modulo_prev.nome.focus();
        return false;
     } else if ((v_email == "") || (v_email == "undefined") || (!regex.test(v_email))) {
        // Effettua il controllo sul campo 'email'
        alert("Il campo 'Email' è obbligatorio.");
        // document.modulo_prev.email.focus();
        return false;
     } else if ((v_indirizzo == "") || (v_indirizzo == "undefined")) {
        // Effettua il controllo sul campo 'indirizzo'
        alert("Il campo 'Indirizzo' è obbligatorio.");
        // document.modulo_prev.indirizzo.focus();
        return false;
     } else if ((v_citta == "") || (v_citta == "undefined")) {
        // Effettua il controllo sul campo 'citta'
        alert("Il campo 'Città' è obbligatorio.");
        // document.modulo_prev.citta.focus();
        return false;
     } else if ((v_nazione == "") || (v_nazione == "undefined")) {
        // Effettua il controllo sul campo 'nazione'
        alert("Il campo 'Nazione' è obbligatorio.");
        // document.modulo_prev.nazione.focus();
        return false;
     } else if ((v_cap == "") || (v_cap == "undefined")) {
        // Effettua il controllo sul campo 'cap'
        alert("Il campo 'CAP' è obbligatorio.");
        // document.modulo_prev.cap.focus();
        return false;
     } else if ((v_tel == "") || (v_tel == "undefined")) {
        // Effettua il controllo sul campo 'cap'
        alert("Il campo 'Telefono' è obbligatorio.");
        // document.modulo_prev.tel.focus();
        return false;
     } else {
        // INVIA IL FORM
        document.modulo_prev.method = "post";
        document.modulo_prev.action = "elabora.php";
        document.modulo_prev.submit();
     }
  }

