	//============================================================================
	//-                      Copyright © 2006 Maxxcom Sas                        -
	//-                           All rights reserved.                           -
	//-                                                                          -
	//-    Questo codice sorgente è protetto da copyright in base alle leggi e   -
	//-    ai trattati internazionali. L'uso non autorizzato, la riproduzione    -
	//-    parziale o totale, l'alterazione, la distribuzione di questo codice   -
	//-    sorgente saranno perseguite in sede penale e civile in ottemperanza   -
	//-    alle leggi esistenti. Sono soggette alle rispettive licenze freeware, -
	//-    GPL, LGPL o di altro tipo, le parti di codice sorgente acquisite da   -
	//-    terze parte anche senza il consenso scritto. In tal caso i nomi degli -
	//-    autori sono riportati a monte delle procedure utilizzate e/o incluse. -
	//-    Eventuali omissioni o errori potranno essere comunicati all'indirizzo -
	//-    email info@maxxcom.it per una pronta correzione e/o integrazione.     -
	//-                                                                          -
	//-    www.maxxcom.it                                                        -
	//============================================================================

	/* ======================================================================================
   	THIS FUNCTION IS TAKEN DIRECTLY FROM NETSCAPE FROM:
   	http://developer.netscape.com/library/examples/..../javascript/formval/FormChek.js
   	which is a bunch of functions to validate forms

   	FUNCTION: isCreditCard(st)
   	INPUT:    st - a string representing a credit card number
   	RETURNS:  true, if the credit card number passes the Luhn Mod-10 test false, otherwise
   	========================================================================================= */
	function isCreditCard(st) {
  		if (st.length > 19) return (false);
  		sum = 0; mul = 1; l = st.length;
  		for (i = 0; i < l; i++) {
    		digit = st.substring(l-i-1,l-i);
    		tproduct = parseInt(digit ,10) * mul;
    		if (tproduct >= 10)
	      		sum += (tproduct % 10) + 1;
    		else
		  		sum += tproduct;
    		if (mul == 1)
      			mul++;
    		else
      			mul--;
  		}
  		if ((sum % 10) == 0)
    		return (true);
  		else
    		return (false);
	}

	function expiredCreditCard(month, year) {
		var now = new Date();
		var expiresIn = new Date(month+'/01/'+year);
		expiresIn.setMonth(expiresIn.getMonth()+1);
        if(now < expiresIn) return false;
		return true;
	}

	function isCodiceFiscale(codice) {
		if (codice == '') return true;
		var cf = codice.toUpperCase();
		var cfReg = /^[A-Z]{6}\d{2}[A-Z]\d{2}[A-Z]\d{3}[A-Z]$/;
		if (!cfReg.test(cf)) return false;
		var set1 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
		var set2 = "ABCDEFGHIJABCDEFGHIJKLMNOPQRSTUVWXYZ";
		var setpari = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
		var setdisp = "BAKPLCQDREVOSFTGUHMINJWZYX";
		var 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 false;
		return true;
	}

	function isPartitaIva(codice) {
		if (codice == '') return true;
		if (codice.length != 11 || isNaN(parseFloat(codice)) || 
			parseFloat(codice) < parseFloat(0)) return false;
		var s = 0;
		for(i = 0; i <= 9; i += 2)
			s += codice.charCodeAt(i) - '0'.charCodeAt(0);
		for( i = 1; i <= 9; i += 2) {
			c = 2*(codice.charCodeAt(i) - '0'.charCodeAt(0));
			if(c > 9)  c = c - 9;
			s += c;
		}
		if((10-s%10)%10 != codice.charCodeAt(10)-'0'.charCodeAt(0))
			return false;
		return true;
	}

	function checkVATNumber (toCheck,defCCode) {
 
  // Array holds the regular expressions for the valid VAT number
  var vatexp = new Array ();
  
  // To change the default country (e.g. from the UK to Germany - DE):
  //    1.  Change the country code in the defCCode variable below to "DE".
  //    2.  Remove the question mark from the regular expressions associated 
  //        with the UK VAT number: i.e. "(GB)?" -> "(GB)"
  //    3.  Add a question mark into the regular expression associated with
  //        Germany's number following the country code: i.e. "(DE)" -> "(DE)?"
  
  //var defCCode = "GB";
  
  // Note - VAT codes without the "**" in the comment do not have check digit
  // checking.

  
  vatexp.push (/^(DE)(\d{9})$/);                           //** Germany   
  vatexp.push (/^(ES)([A-Z]\d{8})$/);                       //** Spain (1)
  vatexp.push (/^(ES)(\d{8}[A-Z])$/);                       // Spain (2)
  vatexp.push (/^(ES)([A-Z]\d{7}[A-Z])$/);                  //** Spain (3)
  vatexp.push (/^(EU)(\d{9})$/);                            //** EU-type   
  vatexp.push (/^(FR)(\d{11})$/);                           //** France (1)
  vatexp.push (/^(FR)[(A-H)|(J-N)|(P-Z)]\d{10}$/);          // France (2)
  vatexp.push (/^(FR)\d[(A-H)|(J-N)|(P-Z)]\d{9}$/);         // France (3)
  vatexp.push (/^(FR)[(A-H)|(J-N)|(P-Z)]{2}\d{9}$/);        // France (4)
  vatexp.push (/^(GB)?(\d{9})$/);                           //** UK (standard)
  vatexp.push (/^(GB)?(\d{10})$/);                          //** UK (Commercial)
  vatexp.push (/^(GB)?(\d{12})$/);                          //UK (IOM standard)
  vatexp.push (/^(GB)?(\d{13})$/);                          //UK (IOM commercial)
  vatexp.push (/^(GB)?(GD\d{3})$/);                         //** UK (Government)
  vatexp.push (/^(GB)?(HA\d{3})$/);                         //** UK (Health authority)
  vatexp.push (/^(GR)(\d{8,9})$/);                          //** Greece 
  vatexp.push (/^(HU)(\d{8})$/);                            //** Hungary 
  vatexp.push (/^(IE)(\d{7}[A-W])$/);                       //** Ireland (1)
  vatexp.push (/^(IE)([7-9][A-Z\*\+)]\d{5}[A-W])$/);        //** Ireland (2)
  vatexp.push (/^(IT)(\d{11})$/);                           //** Italy 
  vatexp.push (/^(LV)(\d{11})$/);                           //** Latvia 
  vatexp.push (/^(LT)(\d{9}|\d{12})$/);                     //** Lithunia
  vatexp.push (/^(LU)(\d{8})$/);                            //** Luxembourg 
  vatexp.push (/^(MT)(\d{8})$/);                            //** Malta
  vatexp.push (/^(NL)(\d{9})B\d{2}$/);                      //** Netherlands
  vatexp.push (/^(PL)(\d{10})$/);                           //** Poland
  vatexp.push (/^(PT)(\d{9})$/);                            //** Portugal
  vatexp.push (/^(RO)(\d{2,10})$/);                         //** Romania
  vatexp.push (/^(SI)(\d{8})$/);                            //** Slovenia
  vatexp.push (/^(SK)(\d{9}|\d{10})$/);                     // Slovakia Republic
  vatexp.push (/^(SE)(\d{10}\d[1-4])$/);                    //** Sweden

  // Load up the string to check
  var VATNumber = toCheck.toUpperCase();
  
  // Remove spaces from the VAT number to help validation
  var chars = [" ","-",",","."];
  for ( var i=0; i<chars.length; i++) {
    while (VATNumber.indexOf(chars[i])!= -1) {
      VATNumber = VATNumber.slice (0,VATNumber.indexOf(chars[i])) + VATNumber.slice (VATNumber.indexOf(chars[i])+1);
    }
  }

  // Assume we're not going to find a valid VAT number
  var valid = false;                         
  
  // Check the string against the types of VAT numbers
  
    
      
      var cCode = RegExp.$1;                             // Isolate country code
      var cNumber = RegExp.$2;                           // Isolate the number
      if (cCode.length == 0) cCode = defCCode;           // Set up default country code
      
      // Now look at the check digits for those countries we know about.
      switch (cCode) {               
        case "DE":
          valid = DEVATCheckDigit (cNumber);
          break;                
        case "ES":
          valid = ESVATCheckDigit (VATNumber);
          break;       
        case "EU":
          valid = EUVATCheckDigit (cNumber);
          break;                
        case "FR":
          valid = FRVATCheckDigit (VATNumber);
          break;         
        case "GB":
          valid = UKVATCheckDigit (cNumber);
          break;                     
        case "GR":
          valid = ELVATCheckDigit (cNumber);
          break;               
        case "IT":
          valid = ITVATCheckDigit (cNumber);
          break;                   
        case "RO":
          valid = ROVATCheckDigit (cNumber);
          break;            
        default:
          valid = true;
                
      // Load new VAT number back into the form element
      if (valid) valid = VATNumber;      
      // We have found that the number is valid - break from loop
      break;
    
  }  
  // Return with either an error or the reformatted VAT number
  return valid;
}

	function DEVATCheckDigit (vatnumber) {
  // Checks the check digits of a German VAT number.  
  var product = 10;
  var sum = 0;     
  var checkdigit = 0;                      
  for (var i = 0; i < 8; i++) {    
    // Extract the next digit and implement perculiar algorithm!.
    sum = (Number(vatnumber.charAt(i)) + product) % 10;
    if (sum == 0) {sum = 10};
    product = (2 * sum) % 11;
  }  
  // Establish check digit.  
  if (11 - product == 10) {checkdigit = 0} else {checkdigit = 11 - product};  
  // Compare it with the last two characters of the VAT number. If the same, 
  // then it is a valid check digit.
  if (checkdigit == vatnumber.slice (8,9))
    return true
  else 
    return false;
}

	function UKVATCheckDigit (vatnumber) {
  // Checks the check digits of a UK VAT number.  
  var multipliers = [8,7,6,5,4,3,2];  
  // Government departments
  if (vatnumber.substr(0,2) == 'GD') {
    if (vatnumber.substr(2,3) < 500) 
      return true 
    else 
      return false;
  }  
  // Health authorities
  if (vatnumber.substr(0,2) == 'HA') {
    if (vatnumber.substr(2,3) > 499) 
      return true 
    else 
      return false;
  }  
  // Standard and commercial numbers
  if (vatnumber.length == 9 || vatnumber.length == 10) {
    var total = 0;
    if (vatnumber.length == 10 && vatnumber.slice (9,10) != '3') return false;     
    for (var i = 0; i < 7; i++) total = total + Number(vatnumber.charAt(i)) * multipliers[i];      
    while (total > 0) {total = total - 97;}      
    total = Math.abs(total);
    if (total == vatnumber.slice (7,9)) 
      return true 
    else  
      return false;
  }    
  return true;
}

	function ESVATCheckDigit (vatnumber) 
	{
	    // Checks the check digits of a Spanish VAT number.  
	    var total = 0; 
	    var temp = 0;
	    var multipliers = [2,1,2,1,2,1,2];
	    var esexp = new Array ();
	    esexp.push (/^[A-H]\d{8}$/);
	    esexp.push (/^[N|P|Q|S]\d{7}[A-Z]$/);
	    esexp.push (/^[0-9]{8}[A-Z]$/);
	    var i = 0;  
	    // With profit companies
	    if (esexp[0].test(vatnumber)) 
	    {  
		    // Extract the next digit and multiply by the counter.
		    for (i = 0; i < 7; i++) 
		    {
		        temp = Number(vatnumber.charAt(i+1)) * multipliers[i];
		        if (temp > 9) 
			        total = total + Math.floor(temp/10) + temp%10 
		        else 
			        total = total + temp;
		    }       
		    // Now calculate the check digit itself. 
		    total = 10 - total % 10;
		    if (total == 10) {total = 0;}    
		    // Compare it with the last character of the VAT number. If it is the same, 
		    // then it's a valid check digit.
		    if (total == vatnumber.slice (8,9)) 
		        return true
		    else 
		        return false;
	    }  
	        // Non-profit companies
	    else if (esexp[1].test(vatnumber)) 
	    {  
		    // Extract the next digit and multiply by the counter.
		    for (i = 0; i < 7; i++) 
		    {
		        temp = Number(vatnumber.charAt(i+1)) * multipliers[i];
		        if (temp > 9) 
			        total = total + Math.floor(temp/10) + temp%10 
		        else 
			        total = total + temp;
		    }      
		    // Now calculate the check digit itself.
		    total = 10 - total % 10;
		    total = String.fromCharCode(total+64);    
		    // Compare it with the last character of the VAT number. If it is the same, 
		    // then it's a valid check digit.
		    if (total == vatnumber.slice (8,9)) 
		        return true
		    else 
		        return false;
	    }	
	    // Personal number (NIF)
	    else if (esexp[2].test(vatnumber)) 
	    {
  		    return vatnumber.charAt(8) == 'TRWAGMYFPDXBNJZSQVHLCKE'.charAt(Number(vatnumber.substring(0, 8)) % 23);
	    }	
	    else return true;
	}
	
    function ITVATCheckDigit (vatnumber) {
        // Checks the check digits of an Italian VAT number.
        var total = 0;
        var multipliers = [1,2,1,2,1,2,1,2,1,2];
        var temp;
    
        // The last three digits are the issuing office, and cannot exceed more 201
        temp=Number(vatnumber.slice(0,7));
        if (temp==0) return false;
        temp=Number(vatnumber.slice(7,10));
        if ((temp<1) || (temp>201)) return false;
  
        // Extract the next digit and multiply by the appropriate  
        for (var i = 0; i < 10; i++) 
        {
            temp = Number(vatnumber.charAt(i)) * multipliers[i];
            if (temp > 9) 
                total = total + Math.floor(temp/10) + temp%10 
            else 
                total = total + temp;
        }
  
        // Establish check digit.
        total = 10 - total % 10;
        if (total > 9) {total = 0;};  
  
        // Compare it with the last character of the VAT number. If it is the same, 
        // then it's a valid check digit.
        if (total == vatnumber.slice (10,11)) 
            return true
        else 
            return false;
    }

    function FRVATCheckDigit (vatnumber) 
    {
        // Checks the check digits of a French VAT number.
        if (!(/^\d{11}$/).test(vatnumber)) return true;
        
        // Extract the last nine digits as an integer.
        var total = vatnumber.substring(2); 
  
        // Establish check digit.
        total = (total*100+12) % 97;
  
        // Compare it with the last character of the VAT number. If it is the same, 
        // then it's a valid check digit.
        if (total == vatnumber.slice (0,2)) 
            return true
        else 
            return false;
    }

    function LimitaCheck(cc,max)
    {
	    var conta = 0;
	    var ff = cc.form;
		for(var i=0; i<ff.length; i++) 
		{
		    var ee = ff.elements[i];
		    if(ee.type=='checkbox' && ee.checked && ee.name.substr(0,4)==cc.name.substr(0,4) ) conta++;
		}
		return (conta<=max);
	} 
	
	function ControllaCheck()
	{
		var selected = 0;
		var looping = true;
		var chk;
		var i = 0;
		for(i; i<7; i++) {
			chk = eval("Conferma.giorno" + i);
			if (chk != null) 
			{
				if (chk.checked) selected++;
		    }				
	    }
	    return selected;
	} 
	
	function check_radio() 
	{
		var controllo = false;
		var bottone =  document.actions_find.action_id;
		for(var i=0; i<bottone.length; i++) 
		{
		    if(bottone[i].checked) 
		    {
			    controllo = true;
			    break;
		    }
		    return controllo;
		}
	}	
	
	function checkSelezione()
    {
        var i, obj;
        for (i=0; i<document.all.length; i++) 
        {
                obj = document.all(i);
                if ((obj.type == "radio") && (obj.checked==true))
                {
                    return true;
                }
        }
    }

