//Inizio funzione di validazione automatica form function valida_form(nome_form,lista) { for(var i=0; i deve essere impostato'); document.forms[0].elements[eval(campo_form)].focus(); if (document.forms[0].elements[eval(campo_form)].type=='text' || document.forms[0].elements[eval(campo_form)].type=='textarea') document.forms[0].elements[eval(campo_form)].select(); return false; } return true; } function check_email(campo,nome_form) { var campo_form = new String (nome_form+'.DEFAULT.'+campo+'.01'); var s = document.forms[0].elements[eval(campo_form)].value; //E-mail address format - localpart@domain //The localpart should not contain the following characters - <>()[]\,;:@" and if the localpart includes // a period, it should be followed by any character other than those mentioned above. However, special characters are allowed provided // the entire local part is enclosed by double quotes e.g. "()[]"@domain var localPartfilter1 = /^[^<>()\[\]\x5C.,;:@" ]+(\.[^<>()\[\]\x5C.,;:@" ]+)*@$/; var localPartfilter2 = /^"[^\r\n]+"@$/; //The domain should start and end with an alphanumeric character and any period should be enclosed by an alphanumeric character. //Characters allowed in the domain are a-z A-Z 0-9 and -(hyphen) var domainfilter = /^([a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9]|[a-zA-Z0-9])(\.([a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9]|[a-zA-Z0-9]))*$/; var sepPos = 0; var localPart; var domain; var localPartOk = false; var domainOk = false; sepPos = s.lastIndexOf("@"); localPart = s.substring(0,sepPos+1); domain = s.substring(sepPos+1,s.length); if (localPartfilter1.test(localPart)) localPartOk = true; else if (localPartfilter2.test(localPart)) localPartOk = true; else localPartOk = false; if (domainfilter.test(domain)) domainOk = true; else domainOk = false; if ( (localPartOk==true && domainOk==true) ) return true; else if (s=="") alert(" Il campo < Email > non può essere vuoto!" ); else alert(" Indirizzo email non valido!" ); document.forms[0].elements[eval(campo_form)].focus(); if (document.forms[0].elements[eval(campo_form)].type=='text' || document.forms[0].elements[eval(campo_form)].type=='textarea') document.forms[0].elements[eval(campo_form)].select(); return false; } function check_cf_piva(campo,nome_form) { var campo_form = new String (nome_form+'.DEFAULT.'+campo+'.01'); cod = document.forms[0].elements[eval(campo_form)].value; if (cod.lenght == 0) err= "Il campo < Codice fiscale/Partita IVA > non puo'' essere vuoto"; else if( cod.length == 16 ) err = ControllaCF(cod); else if( cod.length == 11 ) err = ControllaPIVA(cod); else err = "Il codice introdotto non è valido:\n\n" + " - un codice fiscale deve essere lungo 16 caratteri;\n\n" + " - una partita IVA deve essere lunga 11 caratteri.\n"; if( err > '' ) { alert("VALORE ERRATO\n\n" + err + "\nCorreggi e riprova!"); document.forms[0].elements[eval(campo_form)].focus(); if (document.forms[0].elements[eval(campo_form)].type=='text' || document.forms[0].elements[eval(campo_form)].type=='textarea') document.forms[0].elements[eval(campo_form)].select(); } if( err > '' ) return false; else return true; } function ControllaCF(cf) { var validi, i, s, set1, set2, setpari, setdisp; if( cf == '' ) return ''; cf = cf.toUpperCase(); if( cf.length != 16 ) return "La lunghezza del codice fiscale non è\n" +"corretta: il codice fiscale dovrebbe essere lungo\n" +"esattamente 16 caratteri.\n"; validi = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; for( i = 0; i < 16; i++ ){ if( validi.indexOf( cf.charAt(i) ) == -1 ) return "Il codice fiscale contiene un carattere non valido `" + cf.charAt(i) + "'.\nI caratteri validi sono le lettere e le cifre.\n"; } set1 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; set2 = "ABCDEFGHIJABCDEFGHIJKLMNOPQRSTUVWXYZ"; setpari = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; setdisp = "BAKPLCQDREVOSFTGUHMINJWZYX"; s = 0; for( i = 1; i <= 13; i += 2 ) s += setpari.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) ))); for( i = 0; i <= 14; i += 2 ) s += setdisp.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) ))); if( s%26 != cf.charCodeAt(15)-'A'.charCodeAt(0) ) return "Il codice fiscale non è corretto:\n"+ "il codice di controllo non corrisponde.\n"; return ""; } function ControllaPIVA(pi) { if( pi == '' ) return ''; if( pi.length != 11 ) return "La lunghezza della partita IVA non è\n" + "corretta: la partita IVA dovrebbe essere lunga\n" + "esattamente 11 caratteri.\n"; validi = "0123456789"; for( i = 0; i < 11; i++ ){ if( validi.indexOf( pi.charAt(i) ) == -1 ) return "La partita IVA contiene un carattere non valido `" + pi.charAt(i) + "'.\nI caratteri validi sono le cifre.\n"; } s = 0; for( i = 0; i <= 9; i += 2 ) s += pi.charCodeAt(i) - '0'.charCodeAt(0); for( i = 1; i <= 9; i += 2 ){ c = 2*( pi.charCodeAt(i) - '0'.charCodeAt(0) ); if( c > 9 ) c = c - 9; s += c; } if( ( 10 - s%10 )%10 != pi.charCodeAt(10) - '0'.charCodeAt(0) ) return "La partita IVA non è valida:\n" + "il codice di controllo non corrisponde.\n"; return ''; } //Fine funzione di validazione automatica form var modificato; // La funzione compone Login PSR setTimeout("disableBackButton2()", 0); function disableBackButton2() { window.history.forward(); } // La funzione svuota e disabilita il campo field2 se l'opzione selezionata nel campo // field1 non e' uguale al valore RefValue function componelogin(field1, field2, field4, field3) { var f1, f2, f4, f3; f1 = findObj(field1); f2 = findObj(field2); f4 = findObj(field4); f3 = findObj(field3); var x = f1.value; var y = f2.value; var z = f4.value; var exp = /(["-+*'&@#\/%{}?£$\[\]°§=~_|!:,'.;ç^])/g; x=x.replace(exp,""); y=y.replace(exp,""); x=x.replace(/ /g,""); x=x.replace(/à/g,"a"); x=x.replace(/è/g,"e"); x=x.replace(/é/g,"e"); x=x.replace(/ò/g,"o"); x=x.replace(/ì/g,"i"); x=x.replace(/ù/g,"u"); y=y.replace(/ /g,""); y=y.replace(/à/g,"a"); y=y.replace(/è/g,"e"); y=y.replace(/é/g,"e"); y=y.replace(/ò/g,"o"); y=y.replace(/ì/g,"i"); y=y.replace(/ù/g,"u"); f3.value=y.charAt(0)+x.substring(0,18)+z.substring(0,7); f3.value =f3.value.toUpperCase(); /* f3.disabled="disabled"; */ } //Controlla che il valore del campo sia numerico function ControlloNumerico(Campo, Label) { var Field; Field = findObj(Campo); var st = Field.value; if (isNaN(st)) { alert("Il campo <" + Label + "> può contenere solo numeri!"); Field.focus(); Field.select(); return false; } else { return true; } } // La funzione controlla la validità sintattica di un indirizzo e-mail function validEmail(email) { var Field; Field = findObj(email); var st = Field.value; var emailReg = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/; if (emailReg.test(st) == true) { return true; } else { alert("Indirizzo e-mail non valido"); Field.focus(); Field.select(); return false; } } // La funzione controlla la lunghezza massima per un campo textarea // di 4000 caratteri function lunghezza_4000(FieldForm) { var Field; Field = findObj(FieldForm); var st = Field.value; if ( st.length > 4000) { alert("Attenzione lunghezza massima 4000 caratteri"); Field.focus(); Field.select(); return false; } return true; } // -------- // la funzione controlla che venga inserito un orario nel formato // HH:MI e che questo orario sia valido. // -------- function chkhour(element) { var f1; f1= findObj(element); var ora = 0; var minuti = 0; var filter=/^[0-9]{2}[:][0-9]{2}$/; inpHour = f1.value; if (inpHour.length == 0 ) {return true;} if (inpHour.length < 5) { inpHour = "0"+inpHour; } if (!filter.test(inpHour)) { alert("Inserire ora nel formato HH:MI!"); f1.focus(); f1.select(); return false; } ora = inpHour.substr(0,2); minuti = inpHour.substr(3,2); if (( ora < 24 && minuti < 60 ) || ( ora == 24 && minuti == 0 )) { return true; } else //errore { alert("Orario non valido!"); f1.focus(); f1.select(); return false; } } // -------- // la funzione controlla che venga inserito un orario nel formato // HH:MI, sia valido e che l'ora specificata sia < 13, cioè della // mattina. // -------- function chkhour_am(element) { var ora = 0; var minuti = 0; var filter=/^[0-9]{2}[:.,][0-9]{2}$/; inpHour = element.value; if (inpHour.length == 0 ) {return true;} if (inpHour.length < 5) { inpHour = "0"+inpHour; } if (!filter.test(inpHour)) { alert("Inserire l'ora nel formato HH:MI!"); element.focus(); element.select(); return false; } ora = inpHour.substr(0,2); minuti = inpHour.substr(3,2); if (( ora < 24 && minuti < 60 ) || ( ora == 24 && minuti == 0 )) { if ( ora < 13 ) { return true; } else //errore { alert("Orario non valido per la mattina!"); element.focus(); element.select(); return false; } } else //errore { alert("Orario non valido!"); element.focus(); element.select(); return false; } } // -------- // la funzione controlla che venga inserito un orario nel formato // HH:MI, sia valido e che l'ora specificata sia > 12, cioè del // pomeriggio. // -------- function chkhour_pm(element) { var ora = 0; var minuti = 0; var filter=/^[0-9]{2}[:.,][0-9]{2}$/; inpHour = element.value; if (inpHour.length == 0 ) {return true;} if (inpHour.length < 5) { inpHour = "0"+inpHour; } if (!filter.test(inpHour)) { alert("Inserire l'ora nel formato HH:MI!"); element.focus(); element.select(); return false; } ora = inpHour.substr(0,2); minuti = inpHour.substr(3,2); if (( ora < 24 && minuti < 60 ) || ( ora == 24 && minuti == 0 )) { if ( ora >= 11 ) { return true; } else //errore { alert("Orario non valido per il pomeriggio!"); element.focus(); element.select(); return false; } } else //errore { alert("Orario non valido!"); element.focus(); element.select(); return false; } } // Controlla che entrambi i campi dell'orario siano presenti function Ctr_dallealle(giorno,dalle, alle) { if (dalle.value!='' && alle.value=='' ) { alert('Il campo < ALLE > di < ' + giorno + ' > deve essere impostato.'); alle.focus(); return false; } if (dalle.value=='' && alle.value!='' ) { alert('Il campo < DALLE > di < ' + giorno + ' > deve essere impostato.'); dalle.focus(); return false; } return true; } // Controlla che i campi dell'orario siano in successione function Ctr_orario(giorno,mdalle,malle,pdalle,palle) { var or1 = mdalle.value; var or2 = malle.value; var or3 = pdalle.value; var or4 = palle.value; or1 = or1.replace(/[,.]/, ":"); or2 = or2.replace(/[,.]/, ":"); or3 = or3.replace(/[,.]/, ":"); or4 = or4.replace(/[,.]/, ":"); if(!Ctr_dallealle(giorno+' mattina',mdalle,malle)) { return false;} if(!Ctr_dallealle(giorno+' pomeriggio',pdalle,palle)) { return false;} if ((or1.length == 0) && (or3.length == 0)) { return true; } if (or1.length == 0) { or1 = '00:00'; or2 = '00:01'; } else { if (or1.length == 4) { or1 = '0'+ or1; } if (or2.length == 4) { or2 = '0'+ or2; } } if (or3.length == 0) { or3 = '24:01'; or4 = '24:02'; } if (or1 >= or2) { alert('Gli orari della mattina di ' + giorno + ' non sono corretti.'); mdalle.focus(); return false; } if (or2 > or3) //accettabile coincidenza di o2 con o3 { alert('Sovrapposizione degli orari della mattina e del pomeriggio di ' + giorno + '.'); malle.focus(); return false; } if (or3 >= or4) { alert('Gli orari del pomeriggio di ' + giorno + ' non sono corretti.'); pdalle.focus(); return false; } return true; } //La funzione controlla l'obbligatorietà di un campo //Controlla che nel campo field ci sia un valore. function checkNull( field , fieldName) { selected = 0; fieldIsNull = 0; if ( field.type == "text" || field.type == "password" || field.type == "textarea" ) { if ( field.value == "" ) fieldIsNull = 1; } else if ( field.type == "select-one" ) { if ( field.selectedIndex <= 0) fieldIsNull = 1; } else if ( field.type == "select-multiple" ) { fieldIsNull = 1; for ( i = 0; i < field.length; i++ ) if ( field.options[i].selected ) fieldIsNull = 0; } else if ( field.type == "undefined" || field.type == "checkbox" || field.type == "radio" ) { fieldIsNull = 1; for ( i = 0; i < field.length; i++ ) if ( field[i].checked ) fieldIsNull = 0; } if ( fieldIsNull ) { if ( typeof fieldName == "undefined" ) alert( " Deve essere impostato." ); else alert("Il campo <" + fieldName + "> deve essere impostato." ); if ( field.type == "text" || field.type == "textarea" || field.type == "password" || field.type == "select-one" || field.type == "select-multiple" ) field.focus(); //field.select(); return false; } return true; } //Controlla che il CAP sia di 5 cifre function CtrlCap(Field, Label) { var ValidChar = "0123456789"; var OK = true; if (Field.value.length < 5){ alert("Il campo <" + Label + "> deve essere formato da 5 cifre.") Field.focus(); return false; } for (var i = 0; i < Field.value.length; i++) { var ch = Field.value.charAt(i) for (j = 0; j < ValidChar.length; j++) if (ch == ValidChar.charAt(j)) break; if (j == ValidChar.length) { OK = false; break; } } if (!OK) { alert("Il campo <" + Label + "> può contenere solo numeri!") Field.focus(); return false; } return true; } //Controlla che i valori siano tutte cifre function CtrlNum(Field, Label) { var ValidChar = "0123456789"; var OK = true; for (var i = 0; i < Field.value.length; i++) { var ch = Field.value.charAt(i) for (j = 0; j < ValidChar.length; j++) if (ch == ValidChar.charAt(j)) break; if (j == ValidChar.length) { OK = false; break; } } if (!OK) { alert("Il campo <" + Label + "> può contenere solo numeri!") Field.focus(); return false; } return true; } //Controlla la presenza di @ nella stringa function CtrlMail(Field, Label) { if(Field.value != "") { if (Field.value.indexOf('@', 0) == -1) { alert("Il campo <" + Label + "> non è un indirizzo di E-Mail valido!"); Field.focus(); return false; } } return true; } // La funzione controlla la lunghezza massima per un campo textarea // di 400 caratteri function lunghezza_400(FieldForm) { var Field; Field = findObj(FieldForm); var st= Field.value; if ( st.length > 400) { alert("Attenzione lunghezza massima 400 caratteri"); Field.focus(); Field.select(); return false; } return true; } // La funzione controlla la lunghezza massima per un campo textarea // di 200 caratteri function lunghezza_200(FieldForm) { var Field; Field = findObj(FieldForm); var st= Field.value; if (st.length > 200) { alert("Attenzione lunghezza massima 200 caratteri"); Field.focus(); Field.select(); return false; } return true; } // La funzione controlla la lunghezza massima per un campo textarea // di 120 caratteri function lunghezza_120(Field) { var st = Field.value; if ( st.length > 120) { alert("Attenzione lunghezza massima 120 caratteri"); Field.focus(); Field.select(); return false; } return true; } // La funzione controlla la lunghezza massima per un campo textarea // di 240 caratteri function lunghezza_240(Field) { var st = Field.value; if ( st.length > 240) { alert("Attenzione lunghezza massima 240 caratteri"); Field.focus(); Field.select(); return false; } return true; } // La funzione controlla la lunghezza massima per un campo textarea // di 1000 caratteri function lunghezza_1000(FieldForm) { var Field; Field = findObj(FieldForm); var st= Field.value; if (st.length > 1000) { alert("Attenzione lunghezza massima 1000 caratteri"); Field.focus(); Field.select(); return false; } return true; } // La funzione controlla la lunghezza massima per un campo textarea // di 2000 caratteri function lunghezza_2000(Field) { var st = Field.value; if ( st.length > 2000) { alert("Attenzione lunghezza massima 2000 caratteri"); Field.focus(); Field.select(); return false; } return true; } // La funzione controlla la lunghezza massima per un campo textarea // di 500 caratteri function lunghezza_500(Field) { var st = Field.value; if ( st.length > 500) { alert("Attenzione lunghezza massima 500 caratteri"); Field.focus(); Field.select(); return false; } return true; } // funzione per ritrovare un oggetto mediante il nome indipendentemente dalla sua // posizione nella gerarchia della pagina function findObj(theObj, theDoc) { var p, i, foundObj; if(!theDoc) theDoc = document; if( (p = theObj.indexOf("?")) > 0 && parent.frames.length) { theDoc = parent.frames[theObj.substring(p+1)].document; theObj = theObj.substring(0,p); } if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj]; for (i=0; !foundObj && i < theDoc.forms.length; i++) foundObj = theDoc.forms[i][theObj]; for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) foundObj = findObj(theObj,theDoc.layers[i].document); if(!foundObj && document.getElementByName) foundObj = document.getElementByName(theObj); return foundObj; } // La funzione disabilita il campo hide1 se l'opzione selezionata nel campo // nameSelect supera il valore MaxOption function disabilita(nameSelect, maxOption, hide1) { var obj, obj2Hide1, max; obj = findObj(nameSelect); obj2Hide1 = findObj(hide1); max = maxOption; if ((obj.value)> max){ obj2Hide1.disabled=""; } else{ obj2Hide1.disabled="disabled"; } } // La funzione assegna l'unico valore presente, come default // (nameSelect e' una combobox) function setDefault(nameSelect) { var obj; obj = findObj(nameSelect); if (obj.length == 2) obj.selectedIndex=1; } // La funzione svuota e disabilita il campo field2 se l'opzione selezionata nel campo // field1 non e' uguale al valore RefValue function disabilita2(field1, RefValue, field2) { var f1, rval, f2; f1= findObj(field1); f2= findObj(field2); rval= RefValue; if ((f1.value)== rval){ f2.disabled=""; } else{ f2.value=""; f2.disabled="disabled"; } } // La funzione svuota e disabilita il campo field2 se l'opzione selezionata nel campo // field1 non e' uguale al valore RefValue function disabilita2_nuovo(field1, RefValue, RefValue2, field2) { var f1, rval, rval2, f2; f1= findObj(field1); f2= findObj(field2); rval= RefValue; rval2= RefValue2; if (((f1.value)== rval) || ((f1.value)== rval2)){ f2.disabled=""; } else{ f2.value=""; f2.disabled="disabled"; } } // La funzione svuota e disabilita il campo field2 se l'opzione selezionata nel campo // field1 non e' uguale al valore RefValue function disabilita3_nuovo(field1, RefValue, RefValue2, RefValue3, field2) { var f1, rval, rval2, rval3, f2; f1= findObj(field1); f2= findObj(field2); rval= RefValue; rval2= RefValue2; rval3= RefValue3; if (((f1.value)== rval) || ((f1.value)== rval2) || ((f1.value)== rval3)) { f2.disabled=""; } else{ f2.value=""; f2.disabled="disabled"; } } // La funzione disabilita il campo field2 se l'opzione selezionata nel campo // field1 non e' uguale al valore RefValue (utile per i pulsanti) function disabilita3(field1, RefValue, field2) { var f1, rval, f2; f1= findObj(field1); f2= findObj(field2); rval= RefValue; if ((f1.value)== rval){ f2.value=""; f2.disabled=""; } else{ f2.value=""; f2.disabled="disabled"; } } // La funzione svuota e disabilita il campo field2 se l'opzione selezionata nel campo // field1 non e' uguale al valore RefValue function disabilita8(field1, RefValue1, RefValue2, RefValue3, field2) { var f1, rval1, rval2, rval2, f2; f1= findObj(field1); f2= findObj(field2); rval1= RefValue1; rval2= RefValue2; rval3= RefValue3; if (((f1.value)== rval1) || ((f1.value)== rval2) || ((f1.value)== rval3)){ f2.disabled=""; } else{ f2.value=""; f2.disabled="disabled"; } } // La funzione svuota e disabilita il campo field2 se l'opzione selezionata nel campo // field1 non e' uguale al valore RefValue function disabilita4_mod(field1, RefValue1, RefValue2, field2) { var f1, rval1, rval2, f2; f1= findObj(field1); f2= findObj(field2); rval1= RefValue1; rval2= RefValue2; if (((f1.value)== rval1) || ((f1.value)== rval2)){ f2.disabled=""; } else{ f2.value=""; f2.disabled="disabled"; } } // La funzione svuota e disabilita il campo field2 se l'opzione selezionata nel campo // field1 non e' uguale al valore RefValue function disabilita5(field1, RefValue, field2) { var f1, rval, f2; f1= findObj(field1); f2= findObj(field2); rval= RefValue; if ((f1.value)== rval){ f2.value="N"; f2.disabled=""; } else{ f2.value=""; f2.disabled="disabled"; } } // AIUTO La funzione svuota e disabilita il campo field2 se l'opzione selezionata nel campo // field1 non e' uguale al valore RefValue function disabilita_aiuto(field1, field2, field3) { var f1, f2, f3; f1= findObj(field1); f2= findObj(field2); f3= findObj(field3); if ((f1.value)== "SW"){ f2.disabled="disabled"; f3.disabled="disabled"; } if ((f1.value)== "CW"){ f2.disabled="disabled"; f3.disabled="disabled"; } if ((f1.value)== "DW"){ f2.disabled="disabled"; f3.disabled="disabled"; } if ((f1.value)== "IW"){ f2.disabled="disabled"; f3.disabled="disabled"; } if ((f1.value)== "DE"){ f2.disabled="disabled"; f3.disabled="disabled"; } } // La funzione svuota e disabilita il campo field2 se l'opzione selezionata nel campo // field1 non e' uguale al valore RefValue function disabilita5_mod(field1, RefValue, field2) { var f1, rval, f2; f1= findObj(field1); f2= findObj(field2); rval= RefValue; if ((f1.value)== rval){ f2.disabled=""; } else{ f2.value=""; f2.disabled="disabled"; } } // La funzione svuota e disabilita il campo field2 se l'opzione selezionata nel campo // field1 non e' uguale al valore RefValue function disabilitafasc(field1, RefValue, field2) { var f1, rval, f2; f1= findObj(field1); f2= findObj(field2); rval= RefValue; if ((f1.value)== rval){ f2.value="Revoca Fascicolo"; f2.disabled=""; } else{ f2.value="Revoca Fascicolo"; f2.disabled="disabled"; } } // La funzione svuota e disabilita il campo field2 se l'opzione selezionata nel campo // field1 non e' uguale al valore RefValue function disabilitapma(field1, RefValue, field2) { var f1, rval, f2; f1= findObj(field1); f2= findObj(field2); rval= RefValue; if ((f1.value)== rval){ f2.value="Revoca PMA"; f2.disabled=""; } else{ f2.value="Revoca PMA"; f2.disabled="disabled"; } } // La funzione svuota e disabilita il campo field2 se l'opzione selezionata nel campo // field1 non e' uguale al valore RefValue function disabilitauma(field1, RefValue, field2) { var f1, rval, f2; f1= findObj(field1); f2= findObj(field2); rval= RefValue; if ((f1.value)== rval){ f2.value="Revoca UMA"; f2.disabled=""; } else{ f2.value="Revoca UMA"; f2.disabled="disabled"; } } // La funzione svuota e disabilita il campo field2 se l'opzione selezionata nel campo // field1 non e' uguale al valore RefValue function disabilitacampo(field1, RefValue1, RefValue2, field2) { var f1, rval, f2; f1= findObj(field1); f2= findObj(field2); rval1= RefValue1; rval2= RefValue2; if (((f1.value)== rval1) || ((f1.value)== rval2)){ f2.disabled=""; } else{ f2.value=""; f2.disabled="disabled"; } } //Verifica il formato di una data, nel senso che controlla: // - la correttezza del formato in termini gg-mm-aaaa // - la correzza dei mesi,giorni e anno //Ritorna true se la data è corretta e significativa, ritorna false altrimenti function verificaFormatoData(Field, Label) { var f1; f1= findObj(Field); if (f1.value == '') return true; // se la data è obbligatoria sarà chiamata prima la isNull e quindi qui il controllo non va fatto errore = 0; corretta =/^\d?\d[ /.-]\d?\d[ /.-]\d\d\d\d$/.test(f1.value); if (!corretta) { errore = 1; // errore sul formato della data } else { dataInp = f1.value; if (dataInp.charAt(1) == ' ' || dataInp.charAt(1) == '/' || dataInp.charAt(1) == '-' || dataInp.charAt(1) == '.') dataInp = '0' + dataInp if (dataInp.charAt(4) == ' ' || dataInp.charAt(4) == '/' || dataInp.charAt(4) == '-' || dataInp.charAt(4) == '.') dataInp = dataInp.substring(0,3) + '0' + dataInp.substring(3,9) if (dataInp.charAt(2) != dataInp.charAt(5)) errore = 2 else { giorno = dataInp.substring(0, 2) mese = dataInp.substring(3, 5) anno = dataInp.substring(6, 10) if (mese > 0 && mese < 13 && giorno > 0 && giorno < 32) { if (mese == 11 || mese == 4 || mese == 6 || mese == 9) { if (giorno > 30) errore = 2 } if (mese == 2) { //resto = anno % 4; resto = 1; if (((anno % 4 == 0) && (anno % 100 != 0)) || (anno % 400 == 0)) { // se è un anno bisestile imposto resto a zero altrimenti lo lascio a uno resto = 0; } if (resto == 0 && giorno > 29) errore = 2 else { if (resto != 0 && giorno > 28) errore = 2 } } } else errore = 2 } } if (errore!= 0) { if (errore == 1) { msg = "Il valore del campo <"+Label+"> non contiene un formato valido di data.\n"; msg = msg + "Immettere la data nel formato gg-mm-aaaa."; } else { msg = "Il valore del campo <"+Label+"> non contiene una data valida.\nImmettere la data"; msg = msg + " nel formato gg-mm-aaaa."; } alert(msg); f1.focus(); return false; } else { f1.value = dataInp; return true; } } // La funzione controlla la lunghezza massima (a_value) per un campo a_field di tipo textarea // e fornisce il messaggio di errore con il nome del campo (a_text) function lunghezza_x(a_field, a_value, a_text) { var v_field; v_field= findObj(a_field); if (v_field.value.length>a_value) { alert('La lunghezza del campo <'+a_text+'> non deve superare i '+a_value+' caratteri.'); v_field.focus(); v_field.select(); return false; } else return true; } function verificaDataMinoreUgualeDi(campo1, campo2,Label1, Label2) { var Field1= findObj(campo1); var Field2= findObj(campo2); if ((Field1.value == '') || (Field2.value == '')) return true; var dataInp1 = Field1.value; var dataInp2 = Field2.value; giorno1 = dataInp1.substring(0, 2); mese1 = dataInp1.substring(3, 5); anno1 = dataInp1.substring(6, 10); giorno2 = dataInp2.substring(0, 2); mese2 = dataInp2.substring(3, 5); anno2 = dataInp2.substring(6, 10); if (anno1 < anno2) return true; else if (anno1 == anno2) // Anni uguali: controllo sui mesi if (mese1 < mese2) return true; else if (mese1 == mese2) // Anni e mesi uguali: controllo sui giorni if (giorno1 <= giorno2) return true; msg = "La data immessa nel campo <"+ Label1 +"> non può essere posteriore a quella immessa nel campo <"+Label2+">"; alert(msg); Field1.focus(); return false; } function dataMaggioreUgualeDiOggi(campo1, Label1) { var Field1 = findObj(campo1); var dataInp1 = Field1.value; if (dataInp1 == '') return true; giorno1 = parseInt(dataInp1.substring(0, 2)); mese1 =parseInt(dataInp1.substring(3, 5)); anno1 =parseInt(dataInp1.substring(6, 10)); var data = new Date(); var giorno2, mese2, anno2; giorno2 = data.getDate(); mese2 = data.getMonth()+1; anno2 = data.getYear(); if ( anno1 > anno2) { Field1.style.borderColor=""; return true; } else{ if (anno1 == anno2) // Anni uguali: controllo sui mesi if (mese1 > mese2){ Field1.style.borderColor=""; return true; } else{ if (mese1 == mese2) // Anni e mesi uguali: controllo sui giorni if (giorno1 >= giorno2){ Field1.style.borderColor=""; return true; } } } msg = "La data immessa nel campo <"+ Label1 +"> non può essere precedente alla data odierna"; alert(msg); Field1.focus(); Field1.style.borderColor="red"; return false; } //*************** NUOVA FUNZIONE *****************/ function Trim(StrToTrim) { // CONTROLLA CHE IL VALORE IN INPUT SIA DI TIPO STRING //alert('nella funzione'); if (typeof StrToTrim != "string") { return StrToTrim; } // CATTURA IL PRIMO CARATTERE DELLA STRINGA // PER CONTROLLARE CHE NON SIA UNO SPAZIO VUOTO var StrBlank = StrToTrim.substring(0, 1); // ELIMINA LO SPAZIO VUOTO DALLA PRIMA POSIZIONE DELLA STRINGA //alert('primo while'); while (StrBlank == " ") { StrToTrim = StrToTrim.substring(1, StrToTrim.length); StrBlank = StrToTrim.substring(0, 1); } // CATTURA L'ULTIMO CARATTERE DELLA STRINGA // PER CONTROLLARE CHE NON SIA UNO SPAZIO VUOTO StrBlank = StrToTrim.substring(StrToTrim.length - 1, StrToTrim.length); // ELIMINA LO SPAZIO VUOTO DALL'ULTIMA POSIZIONE DELLA STRINGA //alert('secondo while'); while (StrBlank == " ") { StrToTrim = StrToTrim.substring(0, StrToTrim.length-1); StrBlank = StrToTrim.substring(StrToTrim.length-1, StrToTrim.length); } // ELIMINA POTENZIALI SPAZI VUOTI MULTIPLI // ALL'INIZIO ED ALLA FINE DI UNA STRINGA //alert('terzo while'); //while (StrToTrim.indexOf("") != -1) //{ //alert('nel terzo while'); //StrToTrim = StrToTrim.substring(0, StrToTrim.indexOf("")); //StrToTrim += StrToTrim.substring(StrToTrim.indexOf("") + 1, StrToTrim.length); //} // RESTITUISCE IL VALORE FINALE SENZA SPAZI VUOTI DI CONTORNO //alert('prima di uscire dalla funzione'); return StrToTrim; }