function validateThisData(elthis){
	return validateData(elthis.attributes["chktype"].value,  elthis.attributes["chkprop"].value   ,elthis)
}

//Inserito opportunamente nel form, effettua la validazione dei dati prima di effettuare il submit
function autovalidation(){
var risultatoTest
risultatoTest=true
var i,j,validationtag,propertiestag,arrpropertiestag
collObjects = document.getElementsByTagName("input")
for (i=0;i<collObjects.length;i++){
validationtag=""
propertiestag=""
if (collObjects[i].type!="hidden"){
for (j=0;j<collObjects[i].attributes.length;j++){
if(collObjects[i].attributes[j].nodeName=="chktype")
{
validationtag=collObjects[i].attributes[j].nodeValue
}
if(collObjects[i].attributes[j].nodeName=="chkprop")
{
propertiestag=collObjects[i].attributes[j].nodeValue
}
}
}
if (validationtag!=""){
risultatoTest=risultatoTest && SwitchValidationTag(validationtag,propertiestag,collObjects[i])
}
}
return risultatoTest;
}
function autovalidation2(callerForm){
var risultatoTest
risultatoTest=true
var i,j,validationtag,propertiestag,arrpropertiestag
collObjects = document.getElementsByTagName("input")
for (i=0;i<collObjects.length;i++){
if(collObjects[i].form==callerForm){
validationtag=""
propertiestag=""
if (collObjects[i].type!="hidden"){
for (j=0;j<collObjects[i].attributes.length;j++){
if(collObjects[i].attributes[j].nodeName=="chktype")
{
validationtag=collObjects[i].attributes[j].nodeValue
}
if(collObjects[i].attributes[j].nodeName=="chkprop")
{
propertiestag=collObjects[i].attributes[j].nodeValue
}
}
}
if (validationtag!=""){
risultatoTest=risultatoTest && SwitchValidationTag(validationtag,propertiestag,collObjects[i])
}
}
}
return risultatoTest;
}
function validateData(validationtag,propertiestag,obj){
risultatoTest=true;
risultatoTest=risultatoTest && SwitchValidationTag(validationtag,propertiestag,obj)
if(!risultatoTest){
var originalClass=obj.className.split("ajax")[0]
obj.className=originalClass+" ajaxE";
}
return risultatoTest;
}

function SwitchValidationTag(validationtag,propertiestag,elemento){
var risultatoTest=true;
switch(validationtag.toLowerCase()){
case "nospecialchar":
var arrpropertiestag=propertiestag.split("§");
risultatoTest=risultatoTest && CheckCharTest(elemento.value,arrpropertiestag[0],arrpropertiestag[1]);
break;
case "notnull":
risultatoTest=risultatoTest && checkFieldNotNull(elemento.value,propertiestag);
break;
case "ip":
var arrpropertiestag=propertiestag.split("§");
risultatoTest=risultatoTest && checkIPFormat(elemento.value,arrpropertiestag[0],arrpropertiestag[1]);
break;
case "email":
var arrpropertiestag=propertiestag.split("§");
risultatoTest=risultatoTest && checkEmailFormat(elemento.value,arrpropertiestag[0],arrpropertiestag[1]);
break;
case "radioselected":
checkRadioSelected(elemento,propertiestag);
break;
case "checkdateformat":
var arrpropertiestag=propertiestag.split("§");
risultatoTest=risultatoTest && checkDateFormat(elemento.value,arrpropertiestag[0],arrpropertiestag[1]);
break;
case "checkggmmFormat":
var arrpropertiestag=propertiestag.split("§");
risultatoTest=risultatoTest && checkggmmFormat(elemento.value,arrpropertiestag[0],arrpropertiestag[1]);
break;
case "checkdateformatestesa":
var arrpropertiestag=propertiestag.split("§");
risultatoTest=risultatoTest && checkDateFormatEstesa(elemento.value,arrpropertiestag[0],arrpropertiestag[1],arrpropertiestag[2],arrpropertiestag[3],arrpropertiestag[4],arrpropertiestag[5],arrpropertiestag[6],arrpropertiestag[7]);
break;
case "checkhourformat":
var arrpropertiestag=propertiestag.split("§");
risultatoTest=risultatoTest && checkHourFormat(elemento.value,arrpropertiestag[0],arrpropertiestag[1]);
break;
case "checknumberformat":
var arrpropertiestag=propertiestag.split("§");
risultatoTest=risultatoTest && checkNumber(elemento.value,arrpropertiestag[0],arrpropertiestag[1],arrpropertiestag[2],arrpropertiestag[3],arrpropertiestag[4]);
break;
case "checknumberformatsep":
var arrpropertiestag=propertiestag.split("§");
elemento.value=elemento.value.replace(/\./g,'')
risultatoTest=risultatoTest && checkNumber(elemento.value,arrpropertiestag[0],arrpropertiestag[1],arrpropertiestag[2],arrpropertiestag[3],arrpropertiestag[4]);
break;
case "checknumberformatestesa":
var arrpropertiestag=propertiestag.split("§");
risultatoTest=risultatoTest && checkNumberEstesa(elemento.value,arrpropertiestag[0],arrpropertiestag[1],arrpropertiestag[2],arrpropertiestag[3],arrpropertiestag[4],arrpropertiestag[5],arrpropertiestag[6],arrpropertiestag[7]);
break;
case "checkbarcode":
var arrpropertiestag=propertiestag.split("§");
risultatoTest=risultatoTest && checkBarcode(elemento.value,arrpropertiestag[0],arrpropertiestag[1]);
break;
case "checkcdarticolo":
var arrpropertiestag=propertiestag.split("§");
risultatoTest=risultatoTest && checkCDarticolo(elemento.value,arrpropertiestag[0],arrpropertiestag[1]);
break;
}
return risultatoTest;
}


function GlobalCharTest(formPassato){
var risultatoTest
risultatoTest=true
var collObjects
collObjects = formPassato.elements
for (i=0;i<collObjects.length;i++){
if (collObjects[i].type=="text"){
risultatoTest=risultatoTest && CheckCharTest(collObjects[i].value,"",false);
}
}
return risultatoTest;
}

function CheckCharTest(stringaDaControllare,label,mandatory){
switch(mandatory){
case "false":
mandatory=false;
break;
case "true":
mandatory=true;
break;
}

if (stringaDaControllare.length==0){
if (mandatory==true){
alert("Attenzione!\n Il campo "+label+" e' vuoto!");
return false;
}else{
return true;
}
}else{
var risultatoTest
risultatoTest=stringaDaControllare.match('\\\\|\\||!|"|£|\\$|%|&|/|\\(|\\)|=|\\?|\\^|§|ç|\'|\\\[|\\\]');
if (risultatoTest==null){
return true;
}else{
alert('Attenzione:\nnel campo ' + label +'\ne\' stato inserito un carattere non valido: ' + risultatoTest)
return false
}
}
}


function checkIPFormat(sIP,label,mandatory)
{
switch(mandatory){
case "false":
mandatory=false;
break;
case "true":
mandatory=true;
break;
}
var ckSpecialChar
var oktoGo
oktoGo=true;

if (mandatory==false && sIP.length==0){
oktoGo=true;
}else{
ckSpecialChar=sIP.match('\\\\|\\||!|"|£|\\$|%|&|/|\\(|\\)|=|\\?|\\^|§|ç|\'|\\\[|\\\]');
if (ckSpecialChar!=null){
alert("Attenzione!\nNel campo "+label+"\n e' stato inserito un carattere non concesso: " + ckSpecialChar);
oktoGo=false;
}else{
if (sIP.length>=7 && sIP.length<=15){
Sp1=sIP.indexOf(".",0);
Sp2=sIP.indexOf(".",(parseInt(Sp1,10)+1));
Sp3=sIP.indexOf(".",(parseInt(Sp2,10)+1));
if (Sp1<0 || Sp2<0 || Sp3<0 ){
alert("Attenzione!\n L'indirizzo ip del campo "+label+" deve essere inserita nel formato \n n.n.n.n");
oktoGo=false;
}

nIP1=sIP.substring(0,Sp1);
nIP2=sIP.substring(Sp1+1,Sp2);
nIP3=sIP.substring(Sp2+1,Sp3);
nIP4=sIP.substring(Sp3+1,sIP.length);

if(nIP1>255 || nIP1<0 || nIP2>255 || nIP2<0 || nIP3>255 || nIP3<0 || nIP4>255 || nIP4<0 ||nIP1.match('[^0-9]')!=null || nIP2.match('[^0-9]')!=null || nIP3.match('[^0-9]')!=null || nIP4.match('[^0-9]')!=null){
alert("errore in "+label+":\n Il numero dell'IP deve essere compreso tra 0 e 255!");
oktoGo=false;
}
}else{
alert("Attenzione!\n L'indirizzo ip del campo "+label+" deve essere inserita nel formato \n n.n.n.n\n con n compresi tra 0 e 255!");
oktoGo=false;

}
}
}
return oktoGo;
}

function checkEmailFormat(seMail,label,mandatory)
{
switch(mandatory){
case "false":
mandatory=false;
break;
case "true":
mandatory=true;
break;
}
var oktoGo;
oktoGo=true;

if (mandatory==false && seMail.length==0){
oktoGo=true;
}else{
ckSpecialChar=seMail.match('\\\\|\\||!|"|£|\\$|%|&|/|\\(|\\)|=|\\?|\\^|§|ç|\'|\\\[|\\\]');
if (ckSpecialChar!=null){
alert("Attenzione!\nNel campo "+label+"\n e' stato inserito un carattere non concesso: " + ckSpecialChar);
oktoGo=false;
}else{
if (seMail.length>0){
Sp1=seMail.indexOf("@",0);
Sp2=seMail.indexOf(".",(parseInt(Sp1,10)+1));
if (Sp1>0 && Sp2 > 0){
oktoGo=true;
}else{
alert("Attenzione!\n Il campo "+label+" non contiene una mail!");
oktoGo=false;
}
}else{
alert("Attenzione!\n Il campo "+label+" e' vuoto!");
oktoGo=false;

}
}
}
return oktoGo;
}

function checkFieldNotNull(sField,label)
{

var oktoGo;
oktoGo=true;

if (sField.length>0){
oktoGo=true;
}else{
alert("Attenzione!\n Il campo "+label+" e' vuoto!");
oktoGo=false;
}
return oktoGo;
}

function checkRadioSelected(eRadio,label)
{
selezioneFatta=false;
for (counter = 0; counter < eRadio.length; counter++)
{
if (eRadio[counter].checked)
selezioneFatta = true; 
}
return selezioneFatta;
}

function checkDateFormat(realDate,label,mandatory)
{
switch(mandatory){
case "false":
mandatory=false;
break;
case "true":
mandatory=true;
break;
}
var oktoGo;
oktoGo=true;

if (mandatory==false && realDate.length==0){
oktoGo=true;
}else{
ckSpecialChar=realDate.match('\\\\|\\||!|"|£|\\$|%|&|\\(|\\)|=|\\?|\\^|§|ç|\'|\\\[|\\\]');
if (ckSpecialChar!=null){
alert("Attenzione!\nNel campo "+label+"\n e' stato inserito un carattere non concesso: " + ckSpecialChar);
oktoGo=false;
}else{
if (realDate.length==10){
Sp1=realDate.indexOf("/",0);
Sp2=realDate.indexOf("/",(parseInt(Sp1,10)+1));
if (Sp1<0 && Sp2<0){
Sp1=realDate.indexOf(".",0);
Sp2=realDate.indexOf(".",(parseInt(Sp1,10)+1));
}
if (Sp1<0 || Sp2<0){
alert("Attenzione!\n La data del campo "+label+" deve essere inserita nel formato \ngg/mm/aaaa\ngg.mm.aaaa\nggmmaaaa");
oktoGo=false;
}

strYear=realDate.substring(Sp2+1,realDate.length);
strMonth=realDate.substring(Sp1+1,Sp2);
strDate=realDate.substring(0,Sp1);


var source_date = new Date(strYear*1,strMonth*1-1,strDate*1)
if(strDate*1 != source_date.getDate())
{
	alert('Giorno non adatto al mese');
	oktoGo=false;
}

if(strMonth.match('[^0-9]')!=null || strMonth>12){
alert("Verificare il mese digitato nel campo "+label+"!");
oktoGo=false;
}
if(strDate.match('[^0-9]')!=null || strDate>31){
alert("Verificare il giorno digitato nel campo "+label+"!");
oktoGo=false;
}

var actualData = new Date()
if(strYear.match('[^0-9]')!=null || (strYear<1900+actualData.getYear()-5) || (strYear>1900+actualData.getYear()+5)){
alert("Verificare l'anno digitato nel campo "+label+"!");
oktoGo=false;
}
}else{
if (realDate.length==8){
strYear=realDate.substring(4,8);
strMonth=realDate.substring(2,4);
strDate=realDate.substring(0,2);
	
var source_date = new Date(strYear*1,strMonth*1-1,strDate*1)
if(strDate*1 != source_date.getDate())
{
	alert('Giorno non adatto al mese');
	oktoGo=false;
}

if(strDate.match('[^0-9]')!=null || strDate>31){
alert("Verificare il giorno digitato nel campo "+label+"!");
oktoGo=false;
}
if(strMonth.match('[^0-9]')!=null || strMonth>12){
alert("Verificare il mese digitato nel campo "+label+"!");
oktoGo=false;
}

var actualData = new Date()
if(strYear.match('[^0-9]')!=null || (strYear<1900+actualData.getYear()-5) || (strYear>1900+actualData.getYear()+5)){
alert("Verificare l'anno digitato nel campo "+label+"!");
oktoGo=false;
}
}else{
alert("Attenzione!\n La data del campo "+label+" deve essere inserita nel formato \ngg/mm/aaaa\ngg.mm.aaaa\nggmmaaaa");
oktoGo=false;
}
}
}
}










return oktoGo;
}

function checkggmmFormat(realDate,label,mandatory)
{
switch(mandatory){
case "false":
mandatory=false;
break;
case "true":
mandatory=true;
break;
}
var oktoGo;
oktoGo=true;

if (mandatory==false && realDate.length==0){
oktoGo=true;
}else{
ckSpecialChar=realDate.match('\\\\|\\||!|"|£|\\$|%|&|\\(|\\)|=|\\?|\\^|§|ç|\'|\\\[|\\\]');
if (ckSpecialChar!=null){
alert("Attenzione!\nNel campo "+label+"\n e' stato inserito un carattere non concesso: " + ckSpecialChar);
oktoGo=false;
}else{
if (realDate.length==5){
Sp1=realDate.indexOf("/",0);
if (Sp1<0){
Sp1=realDate.indexOf(".",0);
}
if (Sp1<0){
alert("Attenzione!\n La data del campo "+label+" deve essere inserita nel formato \ngg/mm/aaaa\ngg.mm.aaaa\nggmmaaaa");
oktoGo=false;
}

strMonth=realDate.substring(Sp1+1,realDate.length);
strDate=realDate.substring(0,Sp1);
if(strMonth.match('[^0-9]')!=null || strMonth>12){
alert("Verificare il mese digitato nel campo "+label+"!");
oktoGo=false;
}
if(strDate.match('[^0-9]')!=null || strDate>31){
alert("Verificare il giorno digitato nel campo "+label+"!");
oktoGo=false;
}

}else{
if (realDate.length==8){
strMonth=realDate.substring(2,4);
strDate=realDate.substring(0,2);

if(strDate.match('[^0-9]')!=null || strDate>31){
alert("Verificare il giorno digitato nel campo "+label+"!");
oktoGo=false;
}
if(strMonth.match('[^0-9]')!=null || strMonth>12){
alert("Verificare il mese digitato nel campo "+label+"!");
oktoGo=false;
}

}else{
alert("Attenzione!\n La data del campo "+label+" deve essere inserita nel formato \ngg/mm/aaaa\ngg.mm.aaaa\nggmmaaaa");
oktoGo=false;
}
}
}
}
return oktoGo;
}

function checkDateFormatEstesa(realDate,label,mandatory,confrontoConOggi,anniIndietro,anniAvanti,confrontoConAltroCampo,labelConCuiConfrontare,idConCuiConfrontare)
{
var strYear
var strMonth
var strDate
switch(mandatory){
case "false":
mandatory=false;
break;
case "true":
mandatory=true;
break;
}
var oktoGo;
oktoGo=true;

if (mandatory==false && realDate.length==0){
oktoGo=true;
}else{
ckSpecialChar=realDate.match('\\\\|\\||!|"|£|\\$|%|&|\\(|\\)|=|\\?|\\^|§|ç|\'|\\\[|\\\]');
if (ckSpecialChar!=null){
alert("Attenzione!\nNel campo "+label+"\n e' stato inserito un carattere non concesso: " + ckSpecialChar);
oktoGo=false;
}else{
if (realDate.length==10){
Sp1=realDate.indexOf("/",0);
Sp2=realDate.indexOf("/",(parseInt(Sp1,10)+1));
if (Sp1<0 && Sp2<0){
Sp1=realDate.indexOf(".",0);
Sp2=realDate.indexOf(".",(parseInt(Sp1,10)+1));
}
if (Sp1<0 || Sp2<0){
alert("Attenzione!\n La data del campo "+label+" deve essere inserita nel formato \ngg/mm/aaaa\ngg.mm.aaaa\nggmmaaaa");
oktoGo=false;
}

strYear=realDate.substring(Sp2+1,realDate.length);
strMonth=realDate.substring(Sp1+1,Sp2);
strDate=realDate.substring(0,Sp1);
	
var source_date = new Date(strYear*1,strMonth*1-1,strDate*1)
if(strDate*1 != source_date.getDate())
{
	alert('Giorno non adatto al mese');
	oktoGo=false;
}
if(strMonth.match('[^0-9]')!=null || strMonth>12){
alert("Verificare il mese digitato nel campo "+label+"!");
oktoGo=false;
}
if(strDate.match('[^0-9]')!=null || strDate>31){
alert("Verificare il giorno digitato nel campo "+label+"!");
oktoGo=false;
}

var actualData = new Date()
if(strYear.match('[^0-9]')!=null ){
alert("Verificare l'anno digitato nel campo "+label+"!");
oktoGo=false;
}

}else{
if (realDate.length==8){
strYear=realDate.substring(4,8);
strMonth=realDate.substring(2,4);
strDate=realDate.substring(0,2);
	
var source_date = new Date(strYear*1,strMonth*1-1,strDate*1)
if(strDate*1 != source_date.getDate())
{
	alert('Giorno non adatto al mese');
	oktoGo=false;
}

if(strDate.match('[^0-9]')!=null || strDate>31){
alert("Verificare il giorno digitato nel campo "+label+"!");
oktoGo=false;
}
if(strMonth.match('[^0-9]')!=null || strMonth>12){
alert("Verificare il mese digitato nel campo "+label+"!");
oktoGo=false;
}


var actualData = new Date()
if(strYear.match('[^0-9]')!=null){
alert("Verificare l'anno digitato nel campo "+label+"!");
oktoGo=false;
}

}else{
alert("Attenzione!\n La data del campo "+label+" deve essere inserita nel formato \ngg/mm/aaaa\ngg.mm.aaaa\nggmmaaaa");
oktoGo=false;
}
}
}


if(oktoGo){

var actualData = new Date()

switch (confrontoConOggi){
case "magg":
if(!(
(strYear>1900+actualData.getYear()) ||
(strYear==1900+actualData.getYear()  &&  strMonth>actualData.getMonth()+1)  ||
(strYear==1900+actualData.getYear()  &&  strMonth==actualData.getMonth()+1  &&  strDate>actualData.getDate())
)){
alert("Attenzione:\nla data nel campo "+label+" deve essere strettamente maggiore di quella attuale!");
oktoGo=false
}
break;
case "magguguale":
if(!(
(strYear>1900+actualData.getYear()) ||
(strYear==1900+actualData.getYear()  &&  strMonth>actualData.getMonth()+1)  ||
(strYear==1900+actualData.getYear()  &&  strMonth==actualData.getMonth()+1  &&  strDate>=actualData.getDate())
)){
alert("Attenzione:\nla data nel campo "+label+" deve essere maggiore o uguale a quella attuale!");
oktoGo=false
}
break;
case "uguale":
if(
(strYear==1900+actualData.getYear()  &&  strMonth==actualData.getMonth()+1  &&  strDate==actualData.getDate())
){}
else{
alert("Attenzione:\nla data nel campo "+label+" deve essere uguale a quella attuale!");
oktoGo=false
}
break;
case "minuguale":
if(
(strYear>1900+actualData.getYear()) ||
(strYear==1900+actualData.getYear()  &&  strMonth>actualData.getMonth()+1)  ||
(strYear==1900+actualData.getYear()  &&  strMonth==actualData.getMonth()+1  &&  strDate>actualData.getDate())
){
alert("Attenzione:\nla data nel campo "+label+" deve essere minore o uguale a quella attuale!");
oktoGo=false
}
break;
case "min":
if(
(strYear>1900+actualData.getYear()) ||
(strYear==1900+actualData.getYear()  &&  strMonth>actualData.getMonth()+1)  ||
(strYear==1900+actualData.getYear()  &&  strMonth==actualData.getMonth()+1  &&  strDate>=actualData.getDate())
){
alert("Attenzione:\nla data nel campo "+label+" deve essere minore di quella attuale!");
oktoGo=false
}
break;
}



if(anniIndietro!="no"){
if(strYear<1900+actualData.getYear()-anniIndietro*1){
alert("Verificare l'anno digitato nel campo "+label+":\ninserire date fino a "+anniIndietro+" anni indietro!");
oktoGo=false;
}
}
if(anniAvanti!="no"){
if(strYear>1900+actualData.getYear()+anniAvanti*1){
alert("Verificare l'anno digitato nel campo "+label+":\ninserire date fino a "+anniAvanti+" anni avanti!");
oktoGo=false;
}
}


}

if(oktoGo && confrontoConAltroCampo!="no"){

var actualData = new Date()
var secondaData=document.getElementById(idConCuiConfrontare).value

if(checkDateFormat(secondaData,labelConCuiConfrontare,true)){


if (secondaData.length==10){
Sp1=secondaData.indexOf("/",0);
Sp2=secondaData.indexOf("/",(parseInt(Sp1,10)+1));
if (Sp1<0 && Sp2<0){
Sp1=secondaData.indexOf(".",0);
Sp2=secondaData.indexOf(".",(parseInt(Sp1,10)+1));
}
strY2=secondaData.substring(Sp2+1,secondaData.length)*1;
strM2=secondaData.substring(Sp1+1,Sp2)*1;
strD2=secondaData.substring(0,Sp1)*1;
}else{
strY2=secondaData.substring(4,8)*1;
strM2=secondaData.substring(2,4)*1;
strD2=secondaData.substring(0,2)*1;
}

strYear=strYear*1;
strMonth=strMonth*1;
strDate=strDate*1;
	
var source_date = new Date(strYear*1,strMonth*1-1,strDate*1)
if(strDate*1 != source_date.getDate())
{
	alert('Giorno non adatto al mese');
	oktoGo=false;
}


switch (confrontoConAltroCampo){
case "magg":
if(!(
(strYear>strY2)  ||
(strYear==strY2  &&  strMonth>strM2)  ||
(strYear==strY2  &&  strMonth==strM2  &&  strDate>strD2)
)){
alert("Attenzione:\nla data nel campo "+label+" deve essere strettamente maggiore\n della data nel campo "+labelConCuiConfrontare+"!");
oktoGo=false
}
break;
case "magguguale": 
if(!(
(strYear>strY2) ||
(strYear==strY2  &&  strMonth>strM2)  ||
(strYear==strY2  &&  strMonth==strM2  &&  strDate>=strD2)
)){
alert("Attenzione:\nla data nel campo "+label+" deve essere maggiore o uguale \n alla data nel campo "+labelConCuiConfrontare+"!");
oktoGo=false
}
break;
case "uguale":
if(
(strYear==strY2  &&  strMonth==strM2  &&  strDate==strD2)
){}
else{
alert("Attenzione:\nla data nel campo "+label+" deve essere uguale\n alla data nel campo "+labelConCuiConfrontare+"!");
oktoGo=false
}
break;
case "minuguale":
if(
(strYear>strY2) ||
(strYear==strY2  &&  strMonth>strM2)  ||
(strYear==strY2  &&  strMonth==strM2  &&  strDate>strD2)
){

alert("Attenzione:\nla data nel campo "+label+" deve essere minore o uguale\n alla data nel campo "+labelConCuiConfrontare+"!");
oktoGo=false
}
break;
case "min":
if(
(strYear>strY2) ||
(strYear==strY2  &&  strMonth>strM2)  ||
(strYear==strY2  &&  strMonth==strM2  &&  strDate>=strD2)
){
alert("Attenzione:\nla data nel campo "+label+" deve essere minore\n della data nel campo "+labelConCuiConfrontare+"!");
oktoGo=false
}
break;
}
}

}
}
return oktoGo;
}

function checkHourFormat(realTime,label,mandatory)
{
switch(mandatory){
case "false":
mandatory=false;
break;
case "true":
mandatory=true;
break;
}
var oktoGo;
oktoGo=true;

if (mandatory==false && realTime.length==0){
oktoGo=true;
}else{
ckSpecialChar=realTime.match('^0123456789:');
if (ckSpecialChar!=null){
alert("Attenzione!\nNel campo "+label+"\n e' stato inserito un carattere non concesso: " + ckSpecialChar);
oktoGo=false;
}else{
realTime=realTime.replace(/\./g,":")
Sp1=realTime.indexOf(":",0);
Sp2=realTime.indexOf(":",(parseInt(Sp1,10)+1));

strSeconds=realTime.substring(Sp2+1,realTime.length);
strMinutes=realTime.substring(Sp1+1,Sp2);
strHour=realTime.substring(0,Sp1);

if(strHour.match('[^0-9]')!=null || parseInt(strHour,10)>23){
alert("Verificare le ore digitate nel campo "+label+"!");
oktoGo=false;
}
if(strMinutes.match('[^0-9]')!=null || parseInt(strMinutes,10)>59){
alert("Verificare i minuti digitati nel campo "+label+"!");
oktoGo=false;
}
if(strSeconds.match('[^0-9]')!=null || parseInt(strSeconds,10)>59){
alert("Verificare i secondi digitati nel campo "+label+"!");
oktoGo=false;
}

}
}
return oktoGo;
}

function controlloPunti(str){
    str=str+""
    var offset=0;
    var corretta=true
    var virgola=str.indexOf(",")

    if(virgola<0)
        virgola=str.length

    if(str.indexOf(".",offset)==0)
        corretta=false
    else
        corretta=true
    while (corretta && str.indexOf(".",offset)>0 && offset>=0)
    {
         if((virgola-str.indexOf(".",offset))%4!=0){
            corretta=false
         }
         if(virgola-str.indexOf(".",offset)<0){
            corretta=false
         }
         offset=str.indexOf(".",offset+2)
    }
    if(corretta)
        return true
    else
        return false
}

function checkNumber(stringNumber,label,mandatory,tipo,minimo,massimo){

stringNumber=stringNumber+""
switch(mandatory){
case "false":
mandatory=false;
break;
case "true":
mandatory=true;
break;
}

var okToGo


if (mandatory==true && stringNumber.length==0){
alert("Attenzione!\n Il campo "+label+" e' vuoto!");
okToGo=false;
}else{
    okToGo=controlloPunti(stringNumber);
    
        
    
if (okToGo){
stringNumber=stringNumber.replace(/\./g,"");
if (stringNumber.indexOf(",")>-1){
stringNumber=stringNumber.replace(",",".");
}

if (isNaN(stringNumber)){
alert("Attenzione!\n Nel campo "+label+"\ndeve essere inserito un numero");
okToGo=false
}else{

switch(tipo){
case "int":
if(stringNumber.match('[^0-9\-]')!=null){
alert("Attenzione!\n Nel campo "+label+"\ndeve essere inserito un numero Intero");
okToGo=false
}
break;
case "float","any":
if(stringNumber.match('[^0123456789.]')!=null){
alert("Attenzione!\n Nel campo "+label+"\ndeve essere inserito un numero");
okToGo=false
}
break;
}
if(okToGo){
if (minimo!="no"){
if (minimo*1>stringNumber*1){
alert("Attenzione!\n Nel campo "+label+"\ndeve essere inserito un numero\nmaggiore o uguale a " + minimo);
okToGo=false
}
}
if (massimo!="no"){
if (massimo*1<stringNumber*1){
alert("Attenzione!\n Nel campo "+label+"\ndeve essere inserito un numero\nminore o uguale a " + massimo);
okToGo=false
}
}
}
}
}else{
    alert("Attenzione!\nIl campo "+label+" contiene una errata separazione delle cifre!");
}
}
return okToGo;
}

function checkBarcode(txt_numero,label,mandatory) {

switch(mandatory){
case "false":
mandatory=false;
break;
case "true":
mandatory=true;
break;
}

if (mandatory==true && txt_numero.length==0){
alert("Attenzione!\n Il campo "+label+" e' vuoto!");
return false
}else{
if(txt_numero.length==0){
return true
}else{
txt_numero=txt_numero.replace(/\./g,"")
if (txt_numero.search(/[^0-9]/)>=0){
alert("Attenzione!\n Il campo "+label+" deve contenere solo cifre!");
return false;
}else{
var sum = 0;
var numlen;

numlen = txt_numero.length;
if((((((numlen != 7) && (numlen != 11)) && (numlen != 12)) && (numlen != 13)) && (numlen != 17)) && (numlen != 14)){
alert("Attenzione!\n Numero errato di cifre nel campo\n"+label);
return false
}else{
for (index = numlen-2; index >= 0; index--) {
if(index%2==0){
sum+=txt_numero.charAt(index)*1
}else{
sum+=txt_numero.charAt(index)*3
}
}
cc = ((1000 - sum) % 10);
if(cc+""==txt_numero.charAt(numlen-1))
return true;
else
alert("Attenzione!\n Codice a Barre errato nel campo\n"+label);
return false;
}
}
}
}
}

function checkCDarticolo(txt_numero,label,mandatory) {
for (var i=0;i<txt_numero.length;i++){
if(isNaN(txt_numero.charAt(i))){
if(txt_numero.charAt(i)!="-" && txt_numero.charAt(i)!="."){
alert("Attenzione!\nNel codice articolo sono accettati come separatori\ni caratteri . e -\n"+label);
return false
}
}
}
return true;
}

function checkNumberEstesa(stringNumber,label,mandatory,tipo,minimo,massimo,confrontoConAltroCampo,labelConCuiConfrontare,idConCuiConfrontare){
stringNumber=stringNumber+""
switch(mandatory){
case "false":
mandatory=false;
break;
case "true":
mandatory=true;
break;
}

var okToGo
okToGo=true

if (mandatory==true && stringNumber.length==0){
alert("Attenzione!\n Il campo "+label+" e' vuoto!");
okToGo=false;
}else{
if (stringNumber.indexOf(".")>-1){
alert("Attenzione!\nNel campo "+label+"\nil separatore dei decimali deve essere la virgola,\n non il punto!");
okToGo=false;
}
if (okToGo){
if (stringNumber.indexOf(",")>-1){
stringNumber=stringNumber.replace(",",".");
}

if (isNaN(stringNumber)){
alert("Attenzione!\n Nel campo "+label+"\ndeve essere inserito un numero");
okToGo=false
}else{

switch(tipo){
case "int":
if(stringNumber.match('[^0-9\-]')!=null){
alert("Attenzione!\n Nel campo "+label+"\ndeve essere inserito un numero Intero");
okToGo=false
}
break;
case "float","any":
if(stringNumber.match('[^0123456789.]')!=null){
alert("Attenzione!\n Nel campo "+label+"\ndeve essere inserito un numero");
okToGo=false
}
break;
}
if(okToGo){
if (minimo!="no"){
if (minimo*1>stringNumber*1){
alert("Attenzione!\n Nel campo "+label+"\ndeve essere inserito un numero\nmaggiore o uguale a " + minimo);
okToGo=false
}
}
if (massimo!="no"){
if (massimo*1<stringNumber*1){
alert("Attenzione!\n Nel campo "+label+"\ndeve essere inserito un numero\nminore o uguale a " + massimo);
okToGo=false
}
}
}
}
}
}
if(okToGo && confrontoConAltroCampo!="no"){
secondonumero=document.getElementById(idConCuiConfrontare).value.replace(/,/g, ".")
switch (confrontoConAltroCampo){
case "magg":
if((stringNumber*1)<=(secondonumero*1)){
alert("Attenzione:\nil numero nel campo "+label+" deve essere strettamente maggiore\n del numero nel campo "+labelConCuiConfrontare+"!");
okToGo=false
}
break;
case "magguguale":
if((stringNumber*1)<(secondonumero*1)){
alert("Attenzione:\nil numero nel campo "+label+" deve essere maggiore o uguale \n del numero nel campo "+labelConCuiConfrontare+"!");
okToGo=false
}
break;
case "uguale":
if(!(stringNumber*1)==(secondonumero*1)){}
else{
alert("Attenzione:\nil numero nel campo "+label+" deve essere uguale\n del numero nel campo "+labelConCuiConfrontare+"!");
okToGo=false
}
break;
case "minuguale":
if((stringNumber*1)>(secondonumero*1)){
alert("Attenzione:\nil numero nel campo "+label+" deve essere minore o uguale\n del numero nel campo "+labelConCuiConfrontare+"!");
okToGo=false
}
break;
case "min":
if((stringNumber*1)>=(secondonumero*1)){
alert("Attenzione:\nil numero nel campo "+label+" deve essere minore\n del numero nel campo "+labelConCuiConfrontare+"!");
okToGo=false
}
break;
}
}
return okToGo;
}

function dataISO(data){
if(data.length==8){
return data.substr(4,4)+"-"+data.substr(2,2)+"-"+data.substr(0,2)
}else{
return data.substr(6,4)+"-"+data.substr(3,2)+"-"+data.substr(0,2)
}
}
