// Validatore di data // function checkdate(objName) { var datefield = objName; if (chkdate(objName) == false) { datefield.select(); alert("Data immessa in formato non corretto o data non valida."); datefield.focus(); return false; } else { return true; } } function chkdate(objName) { //var strDatestyle = "US"; //United States date style var strDatestyle = "EU"; //European date style var strDate; var strDateArray; var strDay; var strMonth; var strYear; var intday; var intMonth; var intYear; var booFound = false; var datefield = objName; var strSeparatorArray = new Array("-"," ","/","."); var intElementNr; var err = 0; var strMonthArray = new Array(12); strMonthArray[0] = "Gen"; strMonthArray[1] = "Feb"; strMonthArray[2] = "Mar"; strMonthArray[3] = "Apr"; strMonthArray[4] = "Mag"; strMonthArray[5] = "Giu"; strMonthArray[6] = "Lug"; strMonthArray[7] = "Ago"; strMonthArray[8] = "Set"; strMonthArray[9] = "Ott"; strMonthArray[10] = "Nov"; strMonthArray[11] = "Dic"; strDate = datefield.value; if (strDate.length < 1) { return true; } if ((strDate.length > 0)&&(strDate.length < 6)) { return false; } for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) { if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) { strDateArray = strDate.split(strSeparatorArray[intElementNr]); if (strDateArray.length != 3) { err = 1; return false; } else { strDay = strDateArray[0]; strMonth = strDateArray[1]; strYear = strDateArray[2]; } booFound = true; } } if (booFound == false) { if (strDate.length>5) { strDay = strDate.substr(0, 2); strMonth = strDate.substr(2, 2); strYear = strDate.substr(4); } } if (strYear.length == 2) { strYear = '20' + strYear; } // US style if (strDatestyle == "US") { strTemp = strDay; strDay = strMonth; strMonth = strTemp; } intday = parseInt(strDay, 10); if (isNaN(intday)) { err = 2; return false; } intMonth = parseInt(strMonth, 10); if (isNaN(intMonth)) { for (i = 0;i<12;i++) { if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) { intMonth = i+1; strMonth = strMonthArray[i]; i = 12; } } if (isNaN(intMonth)) { err = 3; return false; } } intYear = parseInt(strYear, 10); if (isNaN(intYear)) { err = 4; return false; } if (intMonth>12 || intMonth<1) { err = 5; return false; } if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) { err = 6; return false; } if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) { err = 7; return false; } if (intMonth == 2) { if (intday < 1) { err = 8; return false; } if (LeapYear(intYear) == true) { if (intday > 29) { err = 9; return false; } } else { if (intday > 28) { err = 10; return false; } } } return true; } // Anno bisestile function LeapYear(intYear) { if (intYear % 100 == 0) { if (intYear % 400 == 0) { return true; } } else { if ((intYear % 4) == 0) { return true; } } return false; } // Check sul delete function Conferma() { return confirm("Si vuole procedere veramente all'eliminazione?"); } function ConfirmToOrder() { return confirm("Si vuole procedere alla trasformazione in ordine?"); } function ConfirmToComplete() { return confirm("Si vuole procedere alla richiesta di completamento/verifica dell'ordine?"); } // Check Formato Ora function checkformatoora(inizio) { if (inizio.length < 1) { return true; } if (inizio.value.indexOf(":") != -1) { orei = inizio.value.split(':'); } if (inizio.value.indexOf(".") != -1) { orei = inizio.value.split('.'); } if (isNaN(orei[0]*1)||isNaN(orei[1]*1)||(orei[0]*1>23)||(orei[1]*1>59)) { alert("Formato ora non valido."); inizio.focus(); return false; } return true; } // Check Ora function checkora(inizio,fine) { orei = inizio.value.split(':'); oref = fine.value.split(':'); if (isNaN(orei[0]*1)||isNaN(orei[1]*1)||(orei[0]*1>23)||(orei[1]*1>59)) { alert("Formato ora inizio non valido."); inizio.focus(); return false; } if (isNaN(oref[0]*1)||isNaN(oref[1]*1)||(oref[0]*1>23)||(oref[1]*1>59)) { alert("Formato ora fine non valido."); fine.focus(); return false; } mini = orei[0] * 60 + orei[1] * 1; minf = oref[0] * 60 + oref[1] * 1; if (mini>minf) { alert("L´ora di fine azione deve essere non inferiore all´ora di inizio."); } inizio.focus(); return (mini<=minf); } function replacechar(theString, a, b) { var theNewString = "" if ((a.length != 1) || (b.length != 1)) { theNewString = "Error: the remove/put in place items must only be 1 character long." } else { for (var i = 0; i < theString.length; i++) { if (theString.substring(i, i+1) == a) { theNewString += b } else { theNewString += theString.substring(i, i+1) } } } return theNewString } function LoadWindow(url) { window.open(url,"NEW",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=400,height=400,left=400,right=70,top=150'); } function CloseWindow() { window.close(); }