

/*------------------------------------------------------*/	
/* FUNCTION     : FormatNum								*/
/* DESCRIPTION  : check the a number					*/
/* PARAMETERS											*/
/*	  num		: number								*/	
/*	  PartInt	: max length of part integer			*/
/*	  PartDec   : max length of part decimal			*/	
/* RETURN VALUES :										*/
/*	  number formatted if number is correct else false  */
/*------------------------------------------------------*/
function FormatNum(num,PartInt,PartDec)
{
	
	if (num<"")
		return false
	if (num=="")
		return true
	
	var i=num.indexOf(',');
	var j=num.indexOf('-');
	var segno="";
	
	if(num.indexOf('.')>-1)
		return false
	
	if (j>-1)
		segno=num.substring(0,1)
		
	if(i>-1)// se c'è la virgola
	{	
		if (j>-1)						//se c'è il segno meno
			parteInt=num.substring(1,i)
		else
			parteInt=num.substring(0,i)
			
		parteDec=num.substring(i+1)
		
		if ( parteInt.length<=PartInt && isNaN(parteInt)==false  && 
			 parteDec.length<=PartDec && isNaN(parteDec)==false)

			 return segno + parteInt + '.' + parteDec
		else return false
			
	}
	else //è un numero senza virgola
	{
		if (j>-1) //se c'è il segno meno
			num=num.substring(1)
	
		if (num.length<=PartInt && isNaN(num)==false)
			return segno + num
		else 
			return false
	}
}


/*----------------------------------------------------*/	
/* FUNCTION     : TxtLostFocus				          */
/* DESCRIPTION  : on lost focus of textbox	set		  */
/*						all character to upper		  */
/*----------------------------------------------------*/
function TxtLostFocus(textbox)
{
	textbox.value=Upper(textbox.value) 
}



/*----------------------------------------------------*/	
/* FUNCTION     : Upper			                      */
/* DESCRIPTION  : Return upperCase of string	      */
/*				  and delete all start and end space  */	
/* PARAMETERS                                         */
/*	  str		: (IN)string to Upper		          */	
/*----------------------------------------------------*/
function Upper(txtBox)
{  
	var str=txtBox.value
	
	if(str)
	{
		while (str.charAt(0)==" ")
			str=str.substr(1)
	
		while (str.charAt(str.length-1)==" ")
			str=str.substr(0,str.length-1)
	
		str=str.toUpperCase()
		txtBox.value=str
	}
}
/*----------------------------------------------------------*/	
/* FUNCTION     : InvalidChar								*/
/* DESCRIPTION  : return true if str have an invalid char	*/
/* PARAMETERS												*/
/*     txt		: (IN) string to check						*/
/*	   lentot	: (IN) string of invalid chars				*/
/*----------------------------------------------------------*/

function InvalidChar(str)
{
	chars="#|"
	
	if (str)
	{
		for (var i=0;i<chars.length;i++)
			if (str.indexOf(chars.substr(i,1))!=-1)
				return true
	}
	return false
}


/*----------------------------------------------------------*/	
/* FUNCTION     : ControllaCaratteriNonValidi				*/
/* DESCRIPTION  : Check if an input field have an invalid   */
/*				  char										*/	
/* PARAMETERS												*/
/*     form		 : (IN) form to check						*/
/* RETURN VALUES : true if there is an invalid char			*/   
/*----------------------------------------------------------*/

function ControllaCaratteriNonValidi(form)
{
	var elements;
	var i;
	
	if (navigator.appName.indexOf('Explorer')>=0)
	{
		elements=form.all
		for (i=0;i<elements.length;i++)
			if (elements[i].tagName.toUpperCase()=='INPUT' && elements[i].type.toUpperCase()=='TEXT')
				if (InvalidChar(elements[i].value))
				{	alert('Carattere non Valido')
					elements[i].focus();
					return true
				}
	}
	else 
	{	
		elements=form.elements 
		for (i=0;i<elements.length;i++)
			if (elements[i].type.toUpperCase()=='TEXT')
				if (InvalidChar(elements[i].value))
				{	alert('Carattere non Valido')
					elements[i].focus();
					return true
				}
	}
	return false
}

/*----------------------------------------------------*/	
/* FUNCTION     : IsDate	                          */
/* DESCRIPTION  : Check if data is a data and		  */
/*				 return true else return false		  */
/* PARAMETERS                                         */
/*     data      : (IN) string to check			      */
/*----------------------------------------------------*/
function IsDate(data)
{
	var dataVect,dataObj;
	
	dataVect=data.split("/")
	if (dataVect.length!=3)
			return false
	else 
		{
			
			if (dataVect[0].length!=1 && dataVect[0].length!=2)
				return false
				
			if (dataVect[1].length!=1 && dataVect[1].length!=2)
				return false
			
			if (dataVect[2].length!=4)
				return false
						
			//oggetto data considera i mesi da 0 a 11
			dataVect[1]-=1
			dataObj=new Date(dataVect[2],dataVect[1],dataVect[0])
			if (dataObj.getDate()==dataVect[0] && dataObj.getMonth()==dataVect[1] && dataObj.getFullYear()==dataVect[2] )
				 return true
			else return false
		}	
}

/*---------------------------------------------------------------*/	
/* FUNCTION     : CompareDate	     							 */
/* DESCRIPTION  : compare two date							 	 */
/* PARAMETERS												     */
/*	  data1		: data to compare								 */
/*	  data2		: data to compare								 */
/*	RETURN VALUES												 */
/*				: 0  if data1=data2								 */	
/*				: 1  if data1>data2								 */	
/*				: -1 if data1<data2								 */	
/*---------------------------------------------------------------*/

 function CompareDate(data1,data2)
 {
	var Vect1,Vect2;
	var i;
	
	Vect1=data1.split("/")
	Vect2=data2.split("/")
	
	for (i=0;i<Vect1.length;i++)
		Vect1[i]=parseInt(DelZero(Vect1[i]))
	
	for (i=0;i<Vect2.length;i++)
		Vect2[i]=parseInt(DelZero(Vect2[i]))
		
	if 	(Vect1[0]==Vect2[0] && Vect1[1]==Vect2[1] && Vect1[2]==Vect2[2])
		return 0
		
	if 	(Vect1[2]>Vect2[2] || (Vect1[2]==Vect2[2] && Vect1[1]>Vect2[1]) || (Vect1[2]==Vect2[2] && Vect1[1]==Vect2[1] && Vect1[0]>Vect2[0]))
		 return 1
	else return -1		
 }	

/*---------------------------------------------------------------*/	
/* FUNCTION     : CurrentDate	      							 */
/* DESCRIPTION  : get the current system data					 */
/*---------------------------------------------------------------*/
function CurrentDate()
{
	var DateObj;
	var giorno,mese;
	
	DateObj=new Date()
	
	giorno=DateObj.getDate()
	giorno=AddZeroTot(giorno.toString(),2)
	mese=DateObj.getMonth() + 1
	mese=AddZeroTot(mese.toString(),2)	
	
	return( giorno + "/" + mese + "/" + DateObj.getFullYear())
}


/*------------------------------------------------------*/	
/* FUNCTION     : AddZeroTot							*/
/* DESCRIPTION  : fill number of zero since his length  */
/*				  id lentot 							*/
/* PARAMETERS                                           */
/*     numero   : (IN) number to format			        */
/*	   lentot	: (IN) len of number					*/
/*------------------------------------------------------*/

function AddZeroTot(numero,lentot)
{
	if (numero.length<lentot)
	{
		for (i=numero.length;i<lentot;i++)
		numero='0'+numero;
		return numero;
	}
	if (numero<="")
		return "0"
	return numero
}

/*---------------------------------------------------------------*/	
/* FUNCTION     : DelZero										 */
/* DESCRIPTION  : Delete all char = "0" to the left of str		 */
/* PARAMETERS												     */
/*	  str	: (IN) string to delete								 */
/*---------------------------------------------------------------*/
function DelZero(str)
{
	while(str.charAt(0)=='0')
		str=str.substr(1)
		
	if (str=="")
		return parseInt("0")
	else
		return parseInt(str)
}
/*----------------------------------------------------*/
function DateDiff(data1,data2)
{
	var mmData1=GetDataMilliseconds(data1)
	var mmData2=GetDataMilliseconds(data2)
	var daymilly=((1000*60)*60)*24
	return parseInt((mmData1-mmData2)/daymilly)
}
/*----------------------------------------------------*/
function GetDataMilliseconds(data)
{
	data=data.split("/")
	var giorno=parseInt(DelZero(data[0]))
	var mese=parseInt(DelZero(data[1])-1)
	var anno=parseInt(DelZero(data[2]))
	return Date.UTC(anno,mese,giorno) 
}
/*----------------------------------------------------*/
function ImpostaHHMMSS()
{

hours = s / 60 / 60 ;
h = Math.floor(hours);
minutes = s  /60  - (60 * h);
mm = Math.floor(minutes);
seconds = s  - (60 * h) - (60 * mm);
ss = Math.round(seconds);
}
/*----------------------------------------------------*/
function timer()
{
	
	clearTimeout(timeID);
	if (count == 0)
	   s = LoadTime();
	
	count += 1;
	s -= 1;
	// aggiorna il timer
    document.ExecTest.TempoImpiegato.value = s;
    ImpostaHHMMSS();
	//ss = s;
	//if (s > 59) 
	//{ 
	//	s -= 60; m += 1; ss -= 60; 
	//}
	//mm = m;
	//if (m > 59) 
	//{ 
	//	m -= 60; h += 1; mm -= 60; 
	//}
	if (ss < 10) ss = "0" + ss;
	if (mm < 10) mm = "0" + mm;
	msg = "<font class='TestoBold'>" + h + ":" + mm + ":" + ss + "</font>";
	if (navigator.appName == "Netscape") 
	{
		document.t.document.write(msg);		
		document.t.document.close();			
	}
	else 
		t.innerHTML = msg;
		
	timeID = setTimeout("timer()", 1000);
	
	if (s == 0)
		{
		alert('Siamo spiacenti ma il tempo di esecuzione del test è scaduto!')
		document.ExecTest.operation.value = "TIMEOUT";
		document.ExecTest.submit();
		}
}
/*----------------------------------------------------*/
function stopTimer(c){
	
	clock = "off"
	
	if (c == 'stop') 
		clearTimeout(timeID);
	if (c == 'clear') 
	{ 
		clearTimeout(timeID);
		ss = 0; mm = 0; m = 0; s = -1;
		count = 0;
		timer();
		stopTimer('stop');
    }
}
/*----------------------------------------------------*/
function right(e)
{
   if (navigator.appName == 'Netscape' && (e.which == 2 || e.which == 3)) return false;
   else if (navigator.appName == "Microsoft Internet Explorer" && (event.button == 2 || event.button == 3))
   {
      alert("Tasto destro disabilitato");
      return false;
   }
}

/*----------------------------------------------------*/
function NextQuestion()
{
var AppoDomanda;
var AppoTempo;

	tipotest = parseInt(document.ExecTest.tipotest.value)
	if (ControlloChecked(tipotest))
		{
		AppoDomanda = parseInt(document.ExecTest.NumeroDomanda.value) + 1;  
		document.ExecTest.NumeroDomanda.value = AppoDomanda;
		document.ExecTest.TempoImpiegato.value = s;
		// trix 18/04/2001 
		clearTimeout(timeID);
		// end trix
		document.ExecTest.operation.value = "SUCC";
		TipoSubmit = true;
		window.opener.resizeBy(0,0); 
		document.ExecTest.submit();
		}
}
/*----------------------------------------------------*/
function ControlloChecked(tipotest)
{
var i,n
var Find,Find1,Find2,Find3

	if (tipotest == "1")
		{
		n = document.ExecTest.nrisp.value;
		Find = 0;
		for (i = 0; i < n;i++)	
			{
			if (document.ExecTest.rb[i].checked == true)
				Find++;	
			}
		if (Find == 0)
			return false;			
		}
	if (tipotest == "2")
		{
		n = document.ExecTest.nrisp.value;
		Find = 0;
		for (i = 0; i < n;i++)	
			{
			if (document.ExecTest.rb[i].checked == true)
				Find++;	
			}
		if (Find == 0)
			return false;			
		}
	if (tipotest == "3")
		{
		n = 3;
		Find1 = 0;
		for (i = 0; i<=n-1;i++)	
			{
			if (document.ExecTest.rb1[i].checked == true)
				Find1++;	
			}
		if (Find1 == 0)
			return false;	
				
		n = 3;
		Find2 = 0;
		for (i = 0; i<=n-1;i++)	
			{
			if (document.ExecTest.rb2[i].checked == true)
				Find2++;	
			}
		if (Find2 == 0)
			return false;	
			
		n = 3;
		Find3 = 0;
		for (i = 0; i<=n-1;i++)	
			{
			if (document.ExecTest.rb3[i].checked == true)
				Find3++;	
			}
		if (Find3 == 0)
			return false;	
		else
			return true;							
		}
	if (tipotest == "4")
		{
		n = document.ExecTest.nrisp.value;
		Find = 0;
		for (i = 0; i < n;i++)	
			{
			if (document.ExecTest.rb[i].checked == true)
				Find++;	
			}
		if (Find == 0)
			return false;			
		}
	if (tipotest == "5")
		{
		n = document.ExecTest.nrisp.value;
		Find = 0;
		for (i = 0; i < n;i++)	
			{
			if (document.ExecTest.rb[i].checked == true)
				Find++;	
			}
		if (Find == 0)
			return false;			
		}		
	return true;
}	
/*----------------------------------------------------*/	
/* FUNCTION     : Trim		   	                      */
/* DESCRIPTION  : esegue il trim della stringa		  */
/*				  elimina spazi in testa e in coda	  */
/* PARAMETERS	: stringa di input   				  */
/* RETURN    	: stringa senza spazi (testa e coda)  */
/*----------------------------------------------------*/
function Trim(str)
{
	while(str.substr(0,1)==' ')
		str=str.substr(1)
	while(str.substr(str.length-1)==' ')
		str=str.substr(0,str.length-1)	
	return str
}
/*----------------------------------------------------*/	
/* FUNCTION     : RepAp		   	                      */
/* DESCRIPTION  : La funzione sostituisce il singolo  */
/*				  apice con due singoli apici         */
/* PARAMETERS	: stringa di input   				  */
/* RETURN    	: stringa senza singoli apici         */
/*----------------------------------------------------*/
	
function RepAp(str)
{
	if (str)
	{
		return str.replace(/'/gi,"''")
	}
	else return ""
}
/*----------------------------------------------------*/	
/* FUNCTION     : RePipe	   	                      */
/* DESCRIPTION  : La funzione sostituisce il carattere*/
/*				  Pipe (|) con un balnck ' '          */
/* PARAMETERS	: stringa di input   				  */
/* RETURN    	: stringa senza Pipe                  */
/*----------------------------------------------------*/	
function RepPipe(str)
{
	if (str)
	{
		return str.replace(/|/gi," ")
	}
	else return ""
}	  
/*------------------------------------------------------*/	
/* FUNCTION     : Checkumber(input) 					*/
/* DESCRIPTION  : check if the inout is a  number   	*/
/* PARAMETERS											*/
/*	  num		: number								*/	
/*	  PartInt	: max length of part integer			*/
/*	  PartDec   : max length of part decimal			*/	
/* RETURN VALUES :										*/
/*	  number formatted if number is correct else false  */
/*------------------------------------------------------*/
function CheckNum(InputString)
{
var AppoNumer = 0;

    AppoNumer= Number(InputString);
    if (isNaN(AppoNumer))
       return false
    else
       return true   
}
/*------------------------------------------------------*/	
/* FUNCTION     : popup(input) 							*/
/*------------------------------------------------------*/
function popup(url,width,height)
{
    var opts;
	var popwin;
	var name;
	
	name = "prova";
	
	if ( navigator.appName != "Microsoft Internet Explorer")
		{
        opts = "toolbar=no,status=no,location=no,menubar=no,scrollbars=yes,resizable=no ";
	    opts += ",height=" + height + ",width=" + width;
		}    
	else
		{
   	    opts = "toolbar=no,status=no,location=no,menubar=no,scrollbars=yes";
	    opts += ",height=" + height + ",width=" + width;	
		}
	
	popwin = window.open(url, name, opts);
	
	//popwin.focus();
	
	//if (url != "")
	//  popwin.location = url;
	
	return (popwin);   

}
function popupcomp(url,width,height)
{
    var opts;
	var popwin;
	var name;
	
	name = "prova";
	
	if ( navigator.appName != "Microsoft Internet Explorer")
		{
        opts = "toolbar=yes,status=yes,location=yes,menubar=yes,scrollbars=yes,resizable=yes";
	    opts += ",height=" + height + ",width=" + width;
		}    
	else
		{
   	    opts = "toolbar=yes,status=yes,location=yes,menubar=yes,scrollbars=yes";
	    opts += ",height=" + height + ",width=" + width;	
		}
	
	popwin = window.open(url, name, opts);
	
	//popwin.focus();
	
	//if (url != "")
	//  popwin.location = url;
	
	return (popwin);   

}
/*----------------------------------------------------*/	
/* FUNCTION     : RepC	   							  */
/* DESCRIPTION  : La funzione sostituisce il carattere*/
/*				  # con un blanck ' '			      */
/* PARAMETERS	: stringa di input   				  */
/* RETURN    	: stringa senza #	                  */
/*----------------------------------------------------*/	
function RepC(str)
{
	if (str)
	{
		return str.replace(/#/gi," ")
	}
	else return ""
}
/*----------------------------------------------------*/	  