
//******************************************************************************************
//combo box
function checkOneTextareaEmpty(objField, textNum, bookmark, errorMessage) {
    validatorCheck = -999
    
    for (var n=0; n < objField.length; n++) {
	if ((objField[n].checked) && ((textNum-1) != n)) {
            validatorCheck = objField[n].value;
            break;
        }
        
        // se il check da controllare ha la sua textArea
        if ((objField[n].checked) && ((textNum-1) == n) && (document.getElementById(objField[n].name + "-" + textNum).value != "") ) {
            validatorCheck = objField[n].value + " | " + document.getElementById(objField[n].name + "-" + textNum).value;
            break;
   	} else {
            validatorCheck = -999
        }
        
    }

    if (validatorCheck == -999) {
        alert(errorMessage);
        eval("document.location='#" + bookmark + "'");
        return ("-1");
    }
	  	
}  
//******************************************************************************************

function ControllaCF(objField, errorMessage)
{
	cf=objField.value
	MyError = 0;
	var validi, i, s, set1, set2, setpari, setdisp;
	if( cf == '' )  return '';
	cf = cf.toUpperCase();
	if( cf.length != 16 )
		MyError = -999;
	validi = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
	for( i = 0; i < 16; i++ ){
		if( validi.indexOf( cf.charAt(i) ) == -1 )
			MyError = -999;
	}
	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) )
		MyError = -999;


    if (MyError == -999) {
        alert(errorMessage);
        objField.focus();
        return ("-1");
    }
}


function ControllaPIVA(objField, errorMessage)
{
	pi = objField.value
	MyError = 0;
		
	if( pi == '' )  return '';
	if( pi.length != 11 )
		MyError = -999;
	validi = "0123456789";
	for( i = 0; i < 11; i++ ){
		if( validi.indexOf( pi.charAt(i) ) == -1 )
		MyError = -999;
	}
	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) )
		MyError = -999;
	
    if (MyError = -999) {
        alert(errorMessage);
        objField.focus();
        return ("-1");
    }	
}
//******************************************************************************************
// radio con textarea 
// (se il relativo radio e' selezionato, la textarea associata deve avere un valore)
function radioAllTextareaEmpty(objField, bookmark, errorMessage) {
    validatorCheck = -999
    
    for (var n=0; n < objField.length; n++) {
	if ((objField[n].checked) && (document.getElementById(objField[n].name + "-" + (n+1)).value != "")) {
            // se il radio da controllare la sua textArea
            validatorCheck = objField[n].value + " | " + document.getElementById(objField[n].name + "-" + (n+1)).value;
     	    break;
   	}
    }

    if (validatorCheck == -999) {
        alert(errorMessage);
        eval("document.location='#" + bookmark + "'");
        return ("-1");
    }
	  	
}  
//******************************************************************************************
//******************************************************************************************
//e-mail 
function emailvalidator(campo,descirzionebox)
{
  //pattern=/[^@_\.\w\d]|@@|\.\.|__|^@|^\.|^_|@$|\.$|_$|@\.|\.@|@_|_@|\._|_\.|(@)[^@]*\1/g; 
  //pattern=/^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$/g;
  //pattern=/^[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]$/;
  //pattern=/^[\\w\\-]([\\.\\w])+[\\w]+@([\\w\\-]+\\.)+[A-Z]{2,4}$/;
  
  
  //pattern=/^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$/g;
  //pattern=/^([0-9a-zA-Z]([-|\.]?[0-9a-zA-Z]+)*@([0-9a-zA-Z]+([-|\.][0-9a-zA-Z])*)+\.[a-zA-Z]{2,9})$/;
  pattern=/^([0-9a-zA-Z])([-|\.|_]?[0-9a-zA-Z]+)*@([0-9a-zA-Z])([-|\.|_]?[0-9a-zA-Z]+)*\.([a-zA-Z]{2,9})$/;


  //if((((campo.value.match(/@/)) && (campo.value.match(/\./))) == null) || (campo.value.match(pattern) != null))
  if (!pattern.test(campo.value))
   {
   alert(descirzionebox)
   campo.focus(campo);
   return ("-1");
   }
}
//******************************************************************************************
//******************************************************************************************
//combo box
function radioComboEmpty(objField, bookmark, errorMessage) {
    validatorCheck = -999
    
    for (var n=0; n < objField.length; n++) {
	if ((objField[n].checked) && (document.getElementById(objField[n].name + "-" + (n+1)).selectedIndex != 0)) {
            validatorCheck = objField[n].value + " [" + document.getElementById(objField[n].name + "-" + (n+1)).selectedIndex + "]";
	    break;
   	}
    }

    if (validatorCheck == -999) {
        alert(errorMessage);
        eval("document.location='#" + bookmark + "'");
        return ("-1");
    }
	  	
}  
//******************************************************************************************
//******************************************************************************************
// radio con ultimo radio una textarea
// se il relativo radio e' selezionato e ha una textarea associata,
// quest'ultima deve avere un valore
function radioOneTextareaEmpty(objField, textNum, bookmark, errorMessage) {
    validatorCheck = -999
    
    for (var n=0; n < objField.length; n++) {
	if ((objField[n].checked) && ((textNum-1) != n)) {
            validatorCheck = objField[n].value;
            break;
        }
        
        // se il radio da controllare ha la sua textArea
        if ((objField[n].checked) && ((textNum-1) == n) && (document.getElementById(objField[n].name + "-" + textNum).value != "") ) {
            validatorCheck = objField[n].value + " | " + document.getElementById(objField[n].name + "-" + textNum).value;
            break;
   	}
    }

    if (validatorCheck == -999) {
        alert(errorMessage);
        eval("document.location='#" + bookmark + "'");
        return ("-1");
    }
	  	
}  
//******************************************************************************************

//******************************************************************************************
//testovuoto
function testovuoto(campo,descirzionebox)
{
  if (campo.value == "")
  {
    alert(descirzionebox);
    campo.focus();
    return ("-1");
  }
}

function testovuotobookmark(campo, bookmark,descirzionebox)
{
  if (campo.value == "")
  {
    alert(descirzionebox);
    campo.focus();
    eval("document.location='#" + bookmark + "'");    
    return ("-1");
  }
}


function testovuotonofocus(campo,descirzionebox)
{
  if (campo.value == "")
  {
    alert(descirzionebox);
    //campo.focus();
    return ("-1");
  }
}

//******************************************************************************************

//******************************************************************************************
//radio
function radioEmpty(objField, bookmark, errorMessage) {
    validatorCheck = -999
    
    for (var n=0; n < objField.length; n++) {
	if (objField[n].checked) {
            validatorCheck= objField[n].value;
	    break;
   	}
    }

    if (validatorCheck == -999) {
        alert(errorMessage);
        eval("document.location='#" + bookmark + "'");
        return ("-1");
    }
}
//******************************************************************************************

//******************************************************************************************
//radio
function radiovuoto(campo,descirzionebox)
{
validatorcheck=-999
		for (var n=0; n < campo.length; n++) {

	      if (campo[n].checked) {
   		      validatorcheck= campo[n].value;
	         break;
   		   }
	  	}
if (validatorcheck==-999)
	{
    alert(descirzionebox);
    return ("-1");
  }
	  	
	}  
//******************************************************************************************
//radio2
function radiodiversoda(campo,diversoda,descirzionebox)
{
validatorcheck=-999
		for (var n=0; n < campo.length; n++) {
	      if (campo[n].checked) {
   		      validatorcheck= campo[n].value;
	         break;
   		   }
	  	}
if (validatorcheck==-999)
	{
    alert(descirzionebox);
    return ("-1");
}
if (validatorcheck==diversoda)
	{
    alert(descirzionebox);
    return ("-1");
}
	  	
	}  	
//******************************************************************************************


function checkvuoto(campo,descirzionebox)
{
validatorcheck=-999
		for (var n=0; n < campo.length; n++) {

	      if (campo[n].checked) {
   		      validatorcheck= campo[n].value;
	         break;
   		   }
	  	}
if (validatorcheck==-999)
	{
    alert(descirzionebox);
    return ("-1");
  }
	  	
	}  
//esempio				

//******************************************************************************************
//combo
function combovuoto(campo,descirzionebox)
  {
if (campo.options.selectedIndex == 0)
  {
    alert(descirzionebox);
    campo.focus(campo);
    return ("-1");
  } 
  } 
//******************************************************************************************

//******************************************************************************************
//lista
function listavuota(campo,descirzionebox)
  {
if (campo.options.selectedIndex == -1)
  {
    alert(descirzionebox);
    campo.focus(campo);
    return ("-1");
  } 
  } 
//******************************************************************************************

//******************************************************************************************
//check
function checknonsel(campo,descirzionebox)
 {
  if (campo.checked==false)
	{
    alert(descirzionebox);
    return ("-1");
  }
}
//******************************************************************************************

//******************************************************************************************
//passwordconfirm
function confermapassword(campo1,campo2,descirzionebox)
 {
 if (campo1.value == campo2.value)
  {
  }
  else{
    alert(descirzionebox);
    campo1.value="";
    campo2.value="";
    campo1.focus();
    return ("-1");
  }
}
//******************************************************************************************

//******************************************************************************************
//Lunghezzacampo
function LunghezzaCampo(campo,lunghezza,descirzionebox)
 {
if (campo.value.length > lunghezza-0)
  {
  }
  else{
    alert(descirzionebox);
    campo.value="";
    campo.focus();
    return ("-1");
  }
}
//******************************************************************************************

//******************************************************************************************
//Lunghezzacampo
function LunghezzaCampoUgualeA(campo,lunghezza,descirzionebox)
 {
if (campo.value.length == lunghezza-0)
  {
  }
  else{
    alert(descirzionebox);
    campo.value="";
    campo.focus();
    return ("-1");
  }
}
//******************************************************************************************


//******************************************************************************************
//Lunghezzacampo
function LunghezzaMinimaCampo(campo,lunghezza,descirzionebox)
 {
if (campo.value.length > lunghezza-1)
  {
  }
  else{
    alert(descirzionebox);
    campo.value="";
    campo.focus();
    return ("-1");
  }
}
//******************************************************************************************

function IsNumeric(campo,tiponumero,descirzionebox)			
{
//tiponumero=1 intero, 2 con virgola 
	validatorcheck="1"
	checkvirgola="0"
	
	for (var i = 0; i < campo.value.length; ++i)
	{
		CT=campo.value.charAt(i);
		//---------------------------------------------------------------------------------------
		//numeri con virgola
		if (tiponumero=="2")
		{
			if (!(CT=="0" || CT=="1" || CT=="2" || CT=="3" || CT=="4" || CT=="5" || CT=="6" || CT=="7" || CT=="8" || CT=="9" || CT=="."))
			{
				validatorcheck="-1";
			}
			else
			{
				if (CT==".")
				{
					if (checkvirgola=="0")
					{
						checkvirgola="1";
					}
					else
					{
						validatorcheck="-1";
					}
				}
			}
		}
		//---------------------------------------------------------------------------------------
		//numeri senza virgola	
		if (tiponumero=="1")
		{			
			if (!(CT=="0" || CT=="1" || CT=="2" || CT=="3" || CT=="4" || CT=="5" || CT=="6" || CT=="7" || CT=="8" || CT=="9"))
			{
				validatorcheck="-1";
			}
		}
		//---------------------------------------------------------------------------------------		
	}
	
	if (validatorcheck=="-1")
	{
		alert(descirzionebox);
		campo.focus();
		return ("-1");
	}else{
		if (campo.value=="0"){
			alert(descirzionebox);
			campo.focus();
			return ("-1");
		}
	}
}

function IsNumericVirgola(campo,tiponumero,descirzionebox)			
{
//tiponumero=1 intero, 2 con virgola 
	validatorcheck="1"
	checkvirgola="0"
	
	for (var i = 0; i < campo.value.length; ++i)
	{
		CT=campo.value.charAt(i);
		//---------------------------------------------------------------------------------------
		//numeri con virgola
		if (tiponumero=="2")
		{
			if (!(CT=="0" || CT=="1" || CT=="2" || CT=="3" || CT=="4" || CT=="5" || CT=="6" || CT=="7" || CT=="8" || CT=="9" || CT==","))
			{
				validatorcheck="-1";
			}
			else
			{
				if (CT==",")
				{
					if (checkvirgola=="0")
					{
						checkvirgola="1";
					}
					else
					{
						validatorcheck="-1";
					}
				}
			}
		}
		//---------------------------------------------------------------------------------------
		//numeri senza virgola	
		if (tiponumero=="1")
		{			
			if (!(CT=="0" || CT=="1" || CT=="2" || CT=="3" || CT=="4" || CT=="5" || CT=="6" || CT=="7" || CT=="8" || CT=="9"))
			{
				validatorcheck="-1";
			}
		}
		//---------------------------------------------------------------------------------------		
	}
	
	if (validatorcheck=="-1")
	{
		alert(descirzionebox);
		campo.focus();
		return ("-1");
	}else{
		if (campo.value==","){
			alert(descirzionebox);
			campo.focus();
			return ("-1");
		}
	}

}


function IsNumericbookmark(campo,tiponumero, bookmark,descirzionebox)			
{
//tiponumero=1 intero, 2 con virgola 
	validatorcheck="1"
	checkvirgola="0"
	
	for (var i = 0; i < campo.value.length; ++i)
	{
		CT=campo.value.charAt(i);
		//---------------------------------------------------------------------------------------
		//numeri con virgola
		if (tiponumero=="2")
		{
			if (!(CT=="0" || CT=="1" || CT=="2" || CT=="3" || CT=="4" || CT=="5" || CT=="6" || CT=="7" || CT=="8" || CT=="9" || CT=="."))
			{
				validatorcheck="-1";
			}
			else
			{
				if (CT==".")
				{
					if (checkvirgola=="0")
					{
						checkvirgola="1";
					}
					else
					{
						validatorcheck="-1";
					}
				}
			}
		}
		//---------------------------------------------------------------------------------------
		//numeri senza virgola	
		if (tiponumero=="1")
		{			
			if (!(CT=="0" || CT=="1" || CT=="2" || CT=="3" || CT=="4" || CT=="5" || CT=="6" || CT=="7" || CT=="8" || CT=="9"))
			{
				validatorcheck="-1";
			}
		}
		//---------------------------------------------------------------------------------------		
	}
	
	if (validatorcheck=="-1")
	{
		alert(descirzionebox);
		campo.focus();
        eval("document.location='#" + bookmark + "'");
		return ("-1");
	}else{
		if (campo.value=="0"){
			alert(descirzionebox);
			campo.focus();
	        eval("document.location='#" + bookmark + "'");
			return ("-1");
		}
	}
}


//******************************************************************************************
function IsMoney(campo,Smigliaia,Scent,descirzionebox)			
{
//Smigliaia=separatore per le migliaia Scent=separatore per centesimi
	validatorcheck="1"
	checkvirgola="0"
	
	for (var i = 0; i < campo.value.length; ++i)
	{
		CT=campo.value.charAt(i);
		//---------------------------------------------------------------------------------------
		if (!(CT=="0" || CT=="1" || CT=="2" || CT=="3" || CT=="4" || CT=="5" || CT=="6" || CT=="7" || CT=="8" || CT=="9" || CT==Smigliaia|| CT==Scent))
		{
			validatorcheck="-1";
			/*alert (CT);*/
		}
		else
		{
			if ((CT==Scent)||(CT==Smigliaia))
			{
				if ((checkvirgola=="0")&&(CT==Scent))
				{
					checkvirgola="1";
				}
				else if ((checkvirgola=="1")&&(CT==Scent))
				{
					validatorcheck="-1";
				}
				else if ((CT==Smigliaia)&&(checkvirgola=="1"))
				{
					validatorcheck="-1";			
				}		
			}

			
			
		}
	}
	
	if (validatorcheck=="-1")
	{
		alert(descirzionebox);
		campo.focus();
		return ("-1");
	}else{
		if (campo.value=="0"){
			alert(descirzionebox);
			campo.focus();
			return ("-1");
		}
	}
}
//******************************************************************************************



//onkeyup="mettiipunti(form1.ilpippo,',','.')" da mettere nei campi numerici per gestire l'immissione money
  function mettiipunti(campo,SeparatoreDecimali,SeparatoreMigliaia)
  {
	valorecampo=campo.value
	
	//SeparatoreDecimali=",";
	//SeparatoreMigliaia=".";
	
	validatorcheck="";
	
	intero="";
	decimali="";

	//inizio controllo carattere inserito *******************************************************************************
	for (var i = 0; i < valorecampo.length; ++i)
	{
		CT=valorecampo.charAt(i);
		if (!(CT=="0" || CT=="1" || CT=="2" || CT=="3" || CT=="4" || CT=="5" || CT=="6" || CT=="7" || CT=="8" || CT=="9" || CT=="."|| CT==","))
		{
			validatorcheck="-1";
			campo.value=valorecampo.substring(0,valorecampo.length -1)
		}
	}
	//fine controllo carattere inserito ****************************************************************************************
	
	//inizio a mettere separatore **********************************************************************************************
	if (validatorcheck!="-1")
	{
		//Inizio Cerco i  separatori migliaia***********************************************************************************
	  	for (var i = 0; i < valorecampo.length; ++i)
		{
			CT=valorecampo.charAt(i);
			if (CT==".")
			{
				valorecampo=valorecampo.replace(SeparatoreMigliaia,'');
			}
		}
		//Fine Cerco i  separatori migliaia *************************************************************************************

		//Inizio Cerco i  separatore decimale ***********************************************************************************
	  	for (var i = 0; i < valorecampo.length; ++i)
		{
			CT=valorecampo.charAt(i);
			if (CT==SeparatoreDecimali)
			{
				decimali=valorecampo.substring(i,valorecampo.length)
				valorecampo=valorecampo.substring(0,i)
			}
		}
		//Fine Cerco i  separatore decimale *************************************************************************************

		//inizio aggiunta separatore*********************************************************************************************
	    if ((valorecampo.length > 3 && valorecampo.length < 7)||(valorecampo.length >= 7 && valorecampo.length < 11)||(valorecampo.length >= 11 && valorecampo.length < 15)){
		    if (valorecampo.length > 3 && valorecampo.length < 7)
		    	{
					intero=valorecampo.substring(0,valorecampo.length-3);
					intero=intero + SeparatoreMigliaia;
					intero=intero + valorecampo.substring(valorecampo.length-3,valorecampo.length);
		    	}
		    if (valorecampo.length >= 7 && valorecampo.length < 11)
		    	{
					intero=valorecampo.substring(0,valorecampo.length-6);
					intero=intero + SeparatoreMigliaia;
					intero=intero + valorecampo.substring(valorecampo.length-6,valorecampo.length-3);
					intero=intero + SeparatoreMigliaia;
					intero=intero + valorecampo.substring(valorecampo.length-3,valorecampo.length);
		    	} 
		    if (valorecampo.length >= 11 && valorecampo.length < 15)
		    	{
		    		intero=intero + valorecampo.substring(0,valorecampo.length-9);
					intero=intero + SeparatoreMigliaia;
					intero=intero + valorecampo.substring(valorecampo.length-9,valorecampo.length-6);
					intero=intero + SeparatoreMigliaia;
					intero=intero + valorecampo.substring(valorecampo.length-6,valorecampo.length-3);
					intero=intero + SeparatoreMigliaia;
					intero=intero + valorecampo.substring(valorecampo.length-3,valorecampo.length);
		    	} 		    	
		    	
		    campo.value=intero + decimali;
		}
		//fine  aggiunta separatore**********************************************************************************************
	}	
	//finito  mettere separatore ************************************************************************************************
 }

//******************************************************************************************
//data corretta formato gg/mm/aaaa

function ControllaData(campo,separatore,descirzionebox){

//	window.onerror=null // for all other strange errors
	var erryyyy=0
	var erryy=0	
	a=campo.value
//---------------------------------------------------------------------------------------yyyy
	if (a.length != 10) erryyyy=1
	d = a.substring(0, 2)// day
	c = a.substring(2, 3)// '/'separatore
	b = a.substring(3, 5)// month
	e = a.substring(5, 6)// '/'separatore
	f = a.substring(6, 10)// year

	//basic error checking
	if (b<1 || b>12) erryyyy = 1
	if (c != separatore) erryyyy = 1
	if (d<1 || d>31) erryyyy = 1
	if (e != separatore) erryyyy = 1
	if (f<0 || f>9999) erryyyy = 1
	
	//advanced error checking

	// months with 30 days
	if (b==4 || b==6 || b==9 || b==11){
		if (d==31) erryyyy=1
	}

	// february, leap year
	if (b==2){
		// feb
		var g=parseInt(f/4)
		if (isNaN(g)) {
			erryyyy=1
		}

		if (d>29) erryyyy=1
		if (d==29 && ((f/4)!=parseInt(f/4))) erryyyy=1
	}
//---------------------------------------------------------------------------------------yy
	if (a.length != 8) erryy=1
	d = a.substring(0, 2)// day
	c = a.substring(2, 3)// '/'separatore
	b = a.substring(3, 5)// month
	e = a.substring(5, 6)// '/'separatore
	f = a.substring(6, 8)// year

	//basic error checking
	if (b<1 || b>12) erryy = 1
	if (c != separatore) erryy = 1
	if (d<1 || d>31) erryyyy = 1
	if (e != separatore) erryy = 1
	if (f<0 || f>99) erryy = 1
	
	//advanced error checking

	// months with 30 days
	if (b==4 || b==6 || b==9 || b==11){
		if (d==31) erryy=1
	}

	// february, leap year
	f="20" + f;
	if (b==2){
		// feb
		var z=parseInt(f/4)
		if (isNaN(z)) {
			erryy=1
		}

		if (d>29) erryy=1
		if (d==29 && ((f/4)!=parseInt(f/4))) erryy=1
	}

//---------------------------------------------------------------------------------------risultati
	if (erryyyy==0 || erryy==0){
		if (erryy==0){
		campo.value=d + c + b + e + f

		}
	}else{
	    alert(descirzionebox);
	    //campo.value="";
	    campo.focus();
	    return ("-1");
	}
	
}
//----------------------------------------------------------------------------------------------------
function dataNoMaggioreDiOggi(campo,descirzionebox)
{
	var dt = new Date();
	var d=dt.getDate()
	var m=dt.getMonth()+1;
	var y=dt.getYear();
	
	if (d<10){d='0' + d;}
	if (m<10){m='0' + m;}
		
	var fulldataOggi= y + '' + m + '' + d;
	
	if (campo.value.length==10)
	{
		var yTest = campo.value.substring(6,10);
		var mTest = campo.value.substring(3,5);
		var dTest = campo.value.substring(0,2);				
		var fulldataTest = yTest + mTest + dTest;
	//	alert(campo.value +'|' + yTest + '!' + mTest + '!' + dTest+ ' | ' + fulldataOggi);
		
		if (fulldataTest>fulldataOggi)
			{
			    alert(descirzionebox);
			    campo.focus(campo);
			    return ("-1");
			}
	}
}
//----------------------------------------------------------------------------------
function dataBNoMaggioredataA(campoA,campoB,descirzionebox)
{
	
	if (campoA.value.length==10)
	{
		var yTest = campoA.value.substring(6,10);
		var mTest = campoA.value.substring(3,5);
		var dTest = campoA.value.substring(0,2);				
		var fulldataTestA = yTest + '' + mTest + '' + dTest;
	}
	
	if (campoB.value.length==10)
	{
		var yTest = campoB.value.substring(6,10);
		var mTest = campoB.value.substring(3,5);
		var dTest = campoB.value.substring(0,2);				
		var fulldataTestB = yTest + '' + mTest + '' + dTest;
	}	

	if ((campoA.value.length==10)&& (campoB.value.length==10))
	{
		if(fulldataTestB>fulldataTestA)
		{
			alert(descirzionebox);
			return ("-1");	
		}
	}
}
//----------------------------------------------------------------------------------------------------
function isNatural(carattere){
	CT=carattere;
	if (!(CT=="0" || CT=="1" || CT=="2" || CT=="3" || CT=="4" || CT=="5" || CT=="6" || CT=="7" || CT=="8" || CT=="9"))
	{
		return false;
		//alert('il campo non è numerico');
	}
	else
	{
		return true;
		//alert('il campo è numerico');
	}
}
function isseparator(carattere){
	CT=carattere;
	if (!(CT=="." || CT=="/" || CT=="-"))
	{
		return false;
	}
	else
	{
		return true;
	}
}

function scrividata(campo,separatore)
{
	
	valorecampo=campo.value
	
	//Inizio controllo se numero o separatore
		if ((!(isNatural(valorecampo.charAt(valorecampo.length-1)))) &&  (!(isseparator(valorecampo.charAt(valorecampo.length-1)))))
		{
			campo.value=valorecampo.substring(0,valorecampo.length-1)
			return;
		}
	//Fine controllo se numero o separatore
	
	switch(valorecampo.length.toString())
	{
		case '1': //1111111111111111111111111111111111111111111111111111111111111111111111111111111111111
		{
			if (!(isNatural(valorecampo.charAt(0))))
		 		{campo.value="";}
			break ;
		}
		case '2': //22222222222222222222222222222222222222222222222222222222222222222222222222222222222222
		{
			if (!(isNatural(valorecampo.charAt(1))))
		 	{
		 		if(isseparator(valorecampo.charAt(1)))
		 			{
		 				if (!(valorecampo.charAt(0)=="0"))
		 					{campo.value="0" + valorecampo.charAt(0) + separatore;}
		 				else
		 					{campo.value=valorecampo.charAt(0)}
		 			}
		 	}
		 	else
		 	{
		 		if ((valorecampo.charAt(0)=="0") && (valorecampo.charAt(0)=="1"))
		 			{campo.value=valorecampo.charAt(0)}
		 	}
			break
		}
		case '3': //333333333333333333333333333333333333333333333333333333333333333333333333333333333333
		{
			if (isNatural(valorecampo.charAt(2)))
				{campo.value=valorecampo.substring(0,2) +  separatore + valorecampo.charAt(2)}
			else
				{campo.value=valorecampo.substring(0,2) +  separatore}
			break
		}
			case '4': //444444444444444444444444444444444444444444444444444444444444444444444444444444
		{
			if (!(isNatural(valorecampo.charAt(3))))
				{campo.value=valorecampo.substring(0,3)}
			break
		}
			case '5': //55555555555555555555555555555555555555555555555555555555555555555555555555555555
		{
			if (!(isNatural(valorecampo.charAt(4))))
		 	{
		 		if(isseparator(valorecampo.charAt(4)))
		 			{
		 				if (!(valorecampo.charAt(3)=="0"))
		 					{campo.value=valorecampo.substring(0,3) + "0" + valorecampo.substring(3,4) +  separatore;}
		 				else
		 					{campo.value=valorecampo.substring(0,4)}
		 			}
		 	}
		 	else
		 	{
		 		if ((valorecampo.charAt(3)=="0")&&(valorecampo.charAt(4)=="0"))
		 		{campo.value=valorecampo.substring(0,4)}
		 	}
			break
		}
		case '6': //66666666666666666666666666666666666666666666666666666666666666666666666666666666
		{
			if (isNatural(valorecampo.charAt(5)))
				{campo.value=valorecampo.substring(0,5) +  separatore + valorecampo.charAt(5)}
			else
				{campo.value=valorecampo.substring(0,5) +  separatore}
			break
		}
		case '7': //777777777777777777777777777777777777777777777777777777777777777777777777777777777
		{
			if (!(isNatural(valorecampo.charAt(6))))
				{campo.value=valorecampo.substring(0,6)}
			break
		}
		case '8': //8888888888888888888888888888888888888888888888888888888888888888888888888888888888
		{
			if (!(isNatural(valorecampo.charAt(7))))
				{campo.value=valorecampo.substring(0,7)}
			else
			{
				if(valorecampo.charAt(6)=="0")
				{
					campo.value=valorecampo.substring(0,6) + '20' + valorecampo.charAt(6) + valorecampo.charAt(7)
				}
			}
			
			break
		}
			case '9': //9999999999999999999999999999999999999999999999999999999999999999999999999999999
		{
			if (!(isNatural(valorecampo.charAt(8))))
				{campo.value=valorecampo.substring(0,8)}
			else
				{if(valorecampo.charAt(6)=="0"){campo.value=valorecampo.substring(0,8)}}
			break
		}
			case '10': //10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 
		{
			if (!(isNatural(valorecampo.charAt(9))))
				{campo.value=valorecampo.substring(0,9)}
			break
		}	
			case '11': //11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 
		{
			campo.value=valorecampo.substring(0,10)
			break
		}
	}
}
//------------------------------------------------------------------------

//function FormValidator(theForm)
//{

//if (emailvalidator(theForm.telefono,"Your e-mail is not valid") == "-1"){return (false);}

//if (testovuoto(theForm.telefono,"il campo telefono è vuoto") == "-1"){return (false);}

//if (checkvuoto(theForm.healt,"il check healt è unselected") == "-1"){return (false);}

//if (combovuoto(theForm.richiesta,"il combo!!!!!") == "-1"){return (false);}

//if (checknonsel(theForm.ilcheck,"il check") == "-1"){return (false);}

//if (ControllaData(theForm.data,"La data deve essere immessa con formato ''gg/mm/aaaa'' ") == "-1"){return (false);}

//}
