function OpenFAQ( Page )
{
	mywin = window.open( '/FAQ/' + Page + '.asp', 'win', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=350,height=375' );
	mywin.focus();
}

function OpenURL( Page )
{
	mywin = window.open( Page, 'win', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=450,height=375' );
	mywin.focus();
}
//------------------------------------------------------------------------------------------
//---  Controlla che il carattere sia una lettera
//------------------------------------------------------------------------------------------
function isLetter(theChar)
{
   var charArray = new Array(
      'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 
      'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 
      'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 
      'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 
      'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 
      's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '-')

      for (j = 0; j < charArray.length; j++)
         if (theChar == charArray[j])
            return true
   return false
}

//------------------------------------------------------------------------------------------
//---  Controlla che il carattere sia un numero
//------------------------------------------------------------------------------------------
function isDigit(theDigit)
{
   var digitArray = new Array('0','1','2','3','4',
         '5','6','7','8','9')

      for (j = 0; j < digitArray.length; j++)
         if (theDigit == digitArray[j])
            return true
   return false
}

//------------------------------------------------------------------------------------------
//---  Controlla che la stringa contenga numeri e lettere
//------------------------------------------------------------------------------------------
function isAlphaNumeric(TheField)
{
   var myStringa = String(TheField.value)

   for (i = 0; i <=myStringa.length-1 ; i++){
      if (!isDigit( myStringa.charAt(i) ) ){
        if (!isLetter( myStringa.charAt(i) ) ) return false
      }
   }
   return true
}

//------------------------------------------------------------------------------------------
//---  Controlla che il campo inserito sia un numero
//------------------------------------------------------------------------------------------
function isNumber(TheField)
{
   var ThePhone = new String(TheField.value)
   var theChar
   
   for (var i = 0; i < ThePhone.length; i++)
   {
      theChar = ThePhone.charAt(i)
      if ( !isDigit(theChar) ) return false
   }
   return true
}

//------------------------------------------------------------------------------------------
//---  Controlla la validità del numero di telefono
//------------------------------------------------------------------------------------------
function isValidPhone(TheField)
{
   var ThePhone = new String(TheField.value)
   var theChar
   for (var i = 0; i < ThePhone.length; i++)
   {
      theChar = ThePhone.charAt(i)
      if ( !isDigit(theChar) )
      {
         if ( !( (theChar == '(') || (theChar == ')') || (theChar == '-') || (theChar == '+')) ) return false
      }
   }
   return true
}

//------------------------------------------------------------------------------------------
//---  Controlla la validità dell'indirizzo e-mail
//------------------------------------------------------------------------------------------
function isEmail(TheField)
{
   var theEmail = new String(TheField.value)
   var theChar

   if ( theEmail.indexOf(" ")>=0 ) return false
   PosET     = theEmail.indexOf("@")
   PosPnt    = theEmail.lastIndexOf(".")
   BeforeET  = theEmail.charAt(PosET-1)
   BeforePnt = theEmail.charAt(PosPnt-1)

   var cont = 0
   for (j = theEmail.length; j >=0 ; j--){
      if (theEmail.charAt(j)!=".") 
         cont+=1
      else 
         break
   }

  if ( (PosET==-1)||(PosPnt==-1)||(BeforeET=="")||(BeforePnt=="@")||(PosET>PosPnt)||(cont-1<2) ) return false

   return true
}





//------------------------------------------------------------------------------------------
//---  Controlla la lunghezza minima del campo
//------------------------------------------------------------------------------------------
function isMinLength(TheField, minLength) {
	if (TheField.value.length >= minLength)
		return true
	else {
		return false
	     }
}


//------------------------------------------------------------------------------------------
//---  Controlla la lunghezza minima del campo
//------------------------------------------------------------------------------------------
function Hilite(TheField, msg) {
	TheField.focus()
	TheField.select()
	alert(msg)
	return false
}



function ControllaCF(cf)
{
	var validi, i, s, set1, set2, setpari, setdisp;
	if( cf == '' )  return '';
	cf = cf.toUpperCase();
	if( cf.length != 16 )
		return "La lunghezza del codice fiscale non è\n"
		+"corretta: il codice fiscale dovrebbe essere lungo\n"
		+"esattamente 16 caratteri.\n";
	validi = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
	for( i = 0; i < 16; i++ ){
		if( validi.indexOf( cf.charAt(i) ) == -1 )
			return "Il codice fiscale contiene un carattere non valido `" +
				cf.charAt(i) +
				"'.\nI caratteri validi sono le lettere e le cifre.\n";
	}
	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) )
		return "Il codice fiscale non è corretto:\n"+
			"il codice di controllo non corrisponde.\n";
	return "";
}


function ControllaPIVA(pi)
{
	if( pi == '' )  return '';
	if( pi.length != 11 )
		return "La lunghezza della partita IVA non è\n" +
			"corretta: la partita IVA dovrebbe essere lunga\n" +
			"esattamente 11 caratteri.\n";
	validi = "0123456789";
	for( i = 0; i < 11; i++ ){
		if( validi.indexOf( pi.charAt(i) ) == -1 )
			return "La partita IVA contiene un carattere non valido `" +
				pi.charAt(i) + "'.\nI caratteri validi sono le cifre.\n";
	}
	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) )
		return "La partita IVA non è valida:\n" +
			"il codice di controllo non corrisponde.\n";
	return '';
}

function getSelectedRadio(buttonGroup) {
   if (buttonGroup[0]) { 
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            return i
         }
      }
   } else {
      if (buttonGroup.checked) { return 0; }
   }
   return -1;
}