// Segue AJAX functions function createHttpRequest() { if(typeof XMLHttpRequest != "undefined") return new XMLHttpRequest(); else if(window.ActiveXObject) { var sVersions =["MSXML2.XMLHttp.5.0","MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0","MSXML2.XMLHttp","Microsoft.XMLHttp"]; for(var i=0; i < 5; i++) { try { ret = new ActiveXObject(sVersions[i]); return ret; } catch (oException) {;} } alert ("XMLHttpRequest non trovato"); } } // Crea un form e fa il submit. fields è un array tipo [["ID", value], ["NAME"], "PIPPO"]] per fare il post dei campi function post(page, field1, val1, field2, val2, field3, val3, field4, val4) { var myFormCreatedOnFly = document.createElement('form'); myFormCreatedOnFly.setAttribute('name', 'myFormCreatedOnFly'); myFormCreatedOnFly.setAttribute('method', 'post'); myFormCreatedOnFly.setAttribute('action', page); // myFormCreatedOnFly.setAttribute('target', '_blank'); // Add fields var fields = new Array(); if (field1 != null) fields[0] = [field1, val1]; if (field2 != null) fields[1] = [field2, val2]; if (field3 != null) fields[2] = [field3, val3]; if (field4 != null) fields[3] = [field4, val4]; for (var i=0; i 249) fld.value = fld.value.substring(0, 249); } // Rende true se la email e valida function emailValida(email) { var filtroMail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/; return filtroMail.test(email); } // Leva spazi iniziali e finali function trim(stringa) { while (stringa.substring(0,1) == ' ') stringa = stringa.substring(1, stringa.length); while (stringa.substring(stringa.length-1, stringa.length) == ' ') stringa = stringa.substring(0,stringa.length-1); return stringa; } // Controllo caratteri validi mentre digita il numero in un campo function inputNumero(event, fld) { var key = event.keyCode; if((key > 95) && (key < 106)) key -= 48; if(key == 46 || key == 8 || key == 9 || key == 39 || key == 37 || key == 116) // canc backspace tab dx sx F5 return true; if (key <= 57 && key >= 48) return true; if (key == 188) { // Virgola if ((fld.value).indexOf(",") == -1 && fld.value.length >0) return true; else return false; } return false; } // Controllo caratteri validi mentre digita il numero intero function inputInt(event, fld) { var key = event.keyCode; if((key > 95) && (key < 106)) key -= 48; if(key == 46 || key == 8 || key == 9 || key == 39 || key == 37 || key == 116) // canc backspace tab dx sx F5 return true; if (key <= 57 && key >= 48) return true; return false; } // Controllo caratteri validi mentre digita il numero intero function inputIntList(event, fld) { var key = event.keyCode; if((key > 95) && (key < 106)) key -= 48; if(key == 46 || key == 8 || key == 9 || key == 39 || key == 37 || key == 116 || key == 188) // canc backspace tab dx sx F5 , return true; if (key <= 57 && key >= 48) return true; return false; } // Controllo caratteri validi mentre digita il numero intero function inputIntBlur(fld, len) { var n = fld.value, i; if (n.length > len) n = ''; for (i=0; i < n.length; i++) if (('0123456789').indexOf(n.substring(i,i+1)) == -1) n = ''; fld.value = n; } // Controllo caratteri validi mentre digita. Accetta solo numeri e lettere function inputIntChar(event, fld) { var key = event.keyCode; if((key > 95) && (key < 106)) key -= 48; if(key == 46 || key == 8 || key == 9 || key == 39 || key == 37 || key == 116) // canc backspace tab dx sx F5 return true; if (key <= 57 && key >= 48) return true; if (key >= 65 && key <= 90) return true; return false; } // Controllo caratteri validi quando finisce di digitare il nome function inputIntCharBlur(fld) { var i, s = fld.value.toUpperCase(), valid = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ", ret = true; for(i=0; i < s.length; i++) if (valid.indexOf(s.substring(i, i+1)) == -1) ret = false; if (!ret) { fld.value = ''; alert('Sono stati digitati caratteri non ammessi in questo campo. Sono ammesi solo lettere e numeri'); } return ret; } // Controllo caratteri validi mentre digita la data function inputData(event, fld) { key = event.keyCode; if((key > 95) && (key < 106)) key -= 48; if (key == 46 || key == 8 || key == 9 || key == 39 || key == 37 || key == 116) // canc backspace tab dx sx F5 return true; if (key <= 57 && key >= 48) // numeri return true; if (key == 55 || key == 111) // slash return true; return false; } // Controllo caratteri validi mentre digita la data ora nel formato gg/mm/aaaa hh:mm function inputDataOra(event, fld) { key = event.keyCode; if((key > 95) && (key < 106)) key -= 48; if (key == 46 || key == 8 || key == 9 || key == 39 || key == 37 || key == 116) // canc backspace tab dx sx F5 return true; if (key <= 57 && key >= 48) // numeri return true; if (key == 55 || key == 111) // slash return true; if (key == 190) // : return true; if (key == 32) // spazio return true; return false; } // Controllo formato gg/mm/aaaa sull'onblur di un campo function onblurData(fld, annoInizio, annoFine) { var ret, array = fld.value.split("/"); if (fld.value == "") return true; if (array.length != 3) ret = false; else ret = checkData(array[0], array[1], array[2]); if (ret) if (array[2] < 1902 || array[2] > (new Date()).getFullYear() + 1) ret = false; if (!ret) { fld.value = ''; alert("Formato data errato \n\nusare il formato gg/mm/aaaa"); } return ret } // Controllo formato gg/mm/aaaa hh:mm sull'onblur di un campo function onblurDataOra(fld, annoInizio, annoFine) { var ret, msg = ''; if (annoInizio === undefined) annoInizio = 1902; if (annoFine === undefined) annoFine = (new Date()).getFullYear(); if (fld.value == "") return true; array0 = fld.value.split(" "); if (array0.length != 2) { msg = "Formato data o ora errato \n\nusare il formato gg/mm/aaaa hh:mm"; ret = false; } else { array = array0[0].split("/"); ret = checkData(array[0], array[1], array[2]); if (!ret) msg = "Formato data errato \n\nusare il formato gg/mm/aaaa hh:mm"; } if (ret) { if (array[2] < annoInizio) { msg = "L'anno deve essere maggiore o uguale a " + annoInizio; ret = false; } if (array[2] > annoFine) { msg = "L'anno deve essere minore o uguale a " + annoFine; ret = false; } } if (ret) { array = array0[1].split(":"); ret = checkTime(array[0], array[1]); if (!ret) msg = "Formato ora errato \n\nusare il formato gg/mm/aaaa hh:mm"; } if (!ret) { fld.value = ''; alert(msg); } return ret } // Controllo caratteri validi mentre digita il nome function inputNome(event, fld) { var key = event.keyCode; if((key > 95) && (key < 106)) key -= 48; if(key == 46 || key == 8 || key == 9 || key == 39 || key == 37 || key == 116) // canc backspace tab dx sx F5 return true; if (key == 219 || key == 32 || key == 189) // ' , spazio e - return true; if (key >= 65 && key <= 90) return true; return false; } // Controllo caratteri validi quando finisce di digitare il nome function inputNomeBlur(fld) { var i, s = fld.value.toUpperCase(), valid = " ABCDEFGHIJKLMNOPQRSTUVWXYZ'-", ret = true; for(i=0; i < s.length; i++) if (valid.indexOf(s.substring(i, i+1)) == -1) ret = false; if (!ret) { fld.value = ''; alert('Sono stati digitati caratteri non ammessi in questo campo'); } return ret; } // Controllo caratteri validi nel campo ricerca nel db function inputSrc(event, fld) { var key = event.keyCode; if((key > 95) && (key < 106)) key -= 48; if(key == 46 || key == 8 || key == 9 || key == 39 || key == 37 || key == 13 || key == 116) // canc backspace tab dx sx return F5 return true; if (key <= 57 && key >= 48) return true; if (key >= 65 && key <= 90) return true; if (key == 219 || key == 32 || key == 189) // ' , spazio e - return true; return false; } // Rende true se data corretta function checkData(g, m, a) { var d = new Date(a, m -1, g); return (d.getDate() == g && d.getMonth() == (m - 1) && d.getFullYear() == a); } // Rende true se time corretto function checkTime(h, m) { return (h>=0 && h<=23 && m >= 0 && m <=59); } // Aggiunge un'option ad un combo function addOption(combo, value, text) { var flag = (combo.disabled); if (flag) combo.disabled = false; var opt = document.createElement("option"); combo.appendChild(opt); opt.value = value; opt.text = text; if (flag) combo.disabled = true; } // Seleziona una opzione di un combo function selectOption(fld, index) { fld.selectedIndex = -1; fld.selectedIndex = index; } // In cfToTest il CF da verificare function controlloCF(cognome, nome, gNascita, mNascita, aNascita, sesso, cfToTest) { var cf; cfToTest = cfToTest.toUpperCase(); cf = procControlloCF(cognome, nome, gNascita, mNascita, aNascita, sesso, '', cfToTest); return (cf == cfToTest); } // Rende il CF. se dati insufficienti rende stringa vuota function generaCF(cognome, nome, gNascita, mNascita, aNascita, sesso, codMinisteriale) { if (sesso != 'M' && sesso != 'F') return ''; if (cognome == '') return ''; if (nome == '') return ''; return procControlloCF(cognome, nome, gNascita, mNascita, aNascita, sesso, codMinisteriale, ''); } function procControlloCF(cognome, nome, gNascita, mNascita, aNascita, sesso, codMinisteriale, cfToTest) { var n, k, cf = "", c, temp, tmp, flag, tot, vocali = 'AEIOU', mesi = new Array('A', 'B', 'C', 'D', 'E', 'H', 'L', 'M', 'P', 'R', 'S', 'T'), pos = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ', dispari = new Array(1,0,5,7,9,13,15,17,19,21,1,0,5,7,9,13,15,17,19,21,2,4,18,20,11,3,6,8,12,14,16,10,22,25,24,23), pari = new Array(0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25); cfToTest = cfToTest.toUpperCase(); if (codMinisteriale == '') codMinisteriale = cfToTest.substring(11, 15); // LEVA CARATTERI STRANI DAL COGNOME cognome = cognome.split("'").join(""); cognome = cognome.split('"').join(""); cognome = cognome.split(',').join(""); cognome = cognome.split('-').join(""); cognome = cognome.split('.').join(""); cognome = cognome.split(' ').join(""); cognome = cognome.toUpperCase(); // LEVA CARATTERI STRANI DAL NOME nome = nome.split("'").join(""); nome = nome.split('"').join(""); nome = nome.split(',').join(""); nome = nome.split('-').join(""); nome = nome.split('.').join(""); nome = nome.split(' ').join(""); nome = nome.toUpperCase(); // CALCOLA COGNOME n = 0 // cerca 3 consonanti while (n < cognome.length && cf.length < 3) { c = cognome.substring(n, n+1); if (vocali.indexOf(c) == -1) // se NON vocale la mette nel CF cf += c; n++; } // se troppo corto cerca fino a 3 vocali n = 0 while (n < cognome.length && cf.length < 3) { c = cognome.substring(n, n+1); if (vocali.indexOf(c) != -1) // se vocale la mette nel CF cf += c; n++; } cf = (cf + 'XXX').substring(0,3); // poi fill con X // CALCOLA NOME // cerca 1a, 3a e 4a consonante n = 0; temp = ''; k = 1; while (n < nome.length && temp.length < 3) { c = nome.substring(n, n+1); if (vocali.indexOf(c) == -1) { // � una consonante if(k != 2) // salta la seconda temp += c; // se NON vocale la mette nel CF k++; } n++; } if (temp.length < 3) { // non ci sono 4 consonanti: prova a prendere quelle che ci sono n=0; temp = ''; while (n < nome.length && temp.length < 3) { c = nome.substring(n, n+1); if (vocali.indexOf(c) == -1) // � una consonante temp += c; // se NON vocale la mette nel CF n++; } } cf += temp; // se troppo corto cerca fino a 3 vocali n=0; while (n < nome.length && cf.length < 6) { c = nome.substring(n, n+1); if (vocali.indexOf(c) != -1) // � una vocale cf += c; // se vocale la mette nel CF n++; } cf = (cf + 'XXX').substring(0,6); // poi fill con X // ANNO NASCITA cf += aNascita.substring(aNascita.length-2); // MESE NASCITA if (mNascita >0) cf += mesi[mNascita -1]; // GIORNO NASCITA -- aggiunge 40 se femmina if (sesso == "F") gNascita = (gNascita*1 + 40); tmp = '00' + gNascita; cf += tmp.substring(tmp.length-2); // Comune cf += codMinisteriale; // CIFRA FINALE DI CHECK n = tot = 0; while (n < cf.length && n < 15) { // Caratteri dispari c = cf.substring(n, n+1); k = pos.indexOf(c); if (n%2 == 0) { // se e pari nn = dispari[k]; tot += dispari[k]; } else { nn = pari[k]; tot += pari[k]; } n++; } cf += String.fromCharCode(65 + tot%26); cf = cf.toUpperCase(); return cf; } // Controlla solo il formato di un codice fiscale. Rende true se OK function checkCfSoloFormato(cf) { var i, ret=true, tipo, formato = "AAAAAA99A99A999A", numeri = '0123456789', lettere ='ABCDEFGHIJKLMNOPQRSTUVWXYZ'; if (cf.length != 16) ret = false; else { cf = cf.toUpperCase(); for (i=0; i<16; i++) { tipo = formato.substring(i, i+1); c = cf.substring(i, i+1); if (tipo == 'A') { if (lettere.indexOf(c) == -1) // non e lettera ret = false; } else { if (numeri.indexOf(c) == -1) // non e un numero ret = false; } } } return ret; } // rende true se iban e corretto function checkIBAN(iban) { // iban = 'IT60Q0123412345000000753XYZ'; (uno buono per test) var numeri='0123456789', lettere='ABCDEFGHIJKLMNOPQRSTUVWXYZ', k, c, ret=true, POS, temp, temp2="", temp3, temp4, resto; iban = iban.toUpperCase() temp = iban.substring(4, 27) + iban.substring(0,4); for (k=0; k<27; k++) { c = temp.charCodeAt(k); char = temp.substring(k, k+1); if (c > 90) { // NON e NUMERO NE LETTRA MAIUSCOLA ret = false; k = 99; } else { pos = numeri.indexOf(char); if (numeri.indexOf(char) != -1) // e' un numero ? temp2 += char; else if (lettere.indexOf(char) != -1) // e una lettera ? temp2 += (c - 55).toString(); // ??? else { // ne lettera ne numero: errore ret = false; k = 99; } } } if (ret) { resto = 0; while (temp2 != '') { if (temp2.length > 4) { temp3 = temp2.substring(0, 4); temp2 = temp2.substring(4, 99); } else { temp3 = temp2; temp2 = ''; } temp4 = resto.toString() + temp3; resto = temp4 % 97; } } if (resto != 1) ret = false return ret; } /* function roundTo(decimalpositions) { var i = this * Math.pow(10,decimalpositions); i = Math.round(i); return i / Math.pow(10,decimalpositions); } Number.prototype.roundTo = roundTo; */ // Arrotonda un numero: Es.: roundTo(3.1416,2) -> 3.14 function roundTo(value, decimalpositions) { var i = value * Math.pow(10,decimalpositions); i = Math.round(i); return i / Math.pow(10,decimalpositions); } // Serve a rimpiazzare target=_blank function openNewWin(location) { window.open(location); return false; }