
//  funzionamento box offerte home page
  $(document).ready(function() {
			$(".nonImageContent .jCarouselLite").jCarouselLite({
				btnNext: ".nonImageContent .next",
				btnPrev: ".nonImageContent .prev"
			});
			
			jQuery(document).ready(function($) {
			$('a[rel*=facebox]').facebox()
			$.facebox.settings.opacity = 0.5; 
}) 


  });

// fine box offerte
 
// funzionamento Tab scheda prodotto
 
		$(document).ready(function() {
			var tabContainers = $('div.tabs > div');
			tabContainers.hide().filter(':first').show();
			
			$('div.tabs ul.tabNavigation a').click(function () {
				tabContainers.hide();
				tabContainers.filter(this.hash).show();
				$('div.tabs ul.tabNavigation a').removeClass('down');
				$(this).addClass('down');
				return false;
			}).filter(':first').click();
		});

 
 //  fine tab

// funzione per mostrare-nascondere elementi
function mostra(id) {
document.getElementById(id).style.display="";
}
function nascondi(id) {
document.getElementById(id).style.display="none";
}

// fine mostra-nascondi elementi




function datiEnabled(en)
{
var status = !en;
if(document.dati.TES_ORD_NOME)
document.dati.TES_ORD_NOME.disabled=status;
if(document.dati.TES_ORD_COGNOME)
document.dati.TES_ORD_COGNOME.disabled=status;
if(document.dati.TES_ORD_TITOLO)
document.dati.TES_ORD_TITOLO.disabled=status;
if(document.dati.TES_ORD_INDIRIZZO)
document.dati.TES_ORD_INDIRIZZO.disabled=status;
if(document.dati.TES_ORD_DUG)
document.dati.TES_ORD_DUG.disabled=status;
if(document.dati.TES_ORD_CIVICO)
document.dati.TES_ORD_CIVICO.disabled=status;
if(document.dati.TES_ORD_PROV)
document.dati.TES_ORD_PROV.disabled=status;
if(document.dati.TES_ORD_LOCALITA)
document.dati.TES_ORD_LOCALITA.disabled=status;
if(document.dati.TES_ORD_FRAZIONE)
document.dati.TES_ORD_FRAZIONE.disabled=status;
if(document.dati.TES_ORD_PRESSO)
document.dati.TES_ORD_PRESSO.disabled=status;
if(document.dati.TES_ORD_NAZIONE)
document.dati.TES_ORD_NAZIONE.disabled=status;
if(document.dati.TES_ORD_CAP)
document.dati.TES_ORD_CAP.disabled=status;
if(document.dati.TES_ORD_TELEFONO)
document.dati.TES_ORD_TELEFONO.disabled=status;
if(document.dati.TES_ORD_EMAIL)
document.dati.TES_ORD_EMAIL.disabled=status;
}

function doSubmitDati()
{
	if (validate())
	{
	    vbContinue=false;
	    
	    if ((selectedLanguage=="DE") && (vbBz))
	    {
	        if ((document.dati.TES_BZ_BANCA.value == "") ||
	            (document.dati.TES_BZ_BLZ.value == "") ||
	            (document.dati.TES_BZ_CC.value == "") ||
	            (document.dati.TES_BZ_FILIALE.value == ""))
	            {
	                alert(bzErrore); 
	                vbContinue = false;   
	            }
	            else
	                vbContinue = true;   
	    }
	    else if ((selectedLanguage=="IT") && (document.getElementById("TES_ORD_INVIO_FATT")) && (document.getElementById("TES_ORD_INVIO_FATT").checked))
	    {
	    	vsCodFisc = document.getElementById("codice_fiscale").value;
	    	vsPIva = document.getElementById("partita_iva").value;
	    	if(vsCodFisc == "")
	    	{
	    		alert("Il Codice Fiscale è Obbligatorio");
	    	}
	    	
	    	if(vsPIva == "")
	    	{
	    		alert("La Partita Iva è Obbligatoria");
	    	}	    	
	    	
	    	if (ControllaPIVA(vsPIva))
	    	{
	    		if((vsCodFisc.length == 11) && ControllaPIVA(vsCodFisc))
	    			vbContinue = true;
	    		else if((vsCodFisc.length == 16) && ControllaCF(vsCodFisc))
	    				vbContinue = true;	
	    		else
	    		{
	    			alert("Lunghezza del Codice Fiscale non corretta")
	    			vbContinue = false;	 
	    		}	   		
	    	}	
	    	else
	    		vbContinue = false;	
	    }
	    else if ((selectedLanguage=="GB") && (vbCCUK))
	    {
	        if ((document.dati.TES_CC_TIPO_CARTA.value == "") ||
	            (document.dati.TES_CC_NUMERO_CARTA.value == "") ||
	            (document.dati.TES_CC_SCADENZA_MESE.value == "") ||
	            (document.dati.TES_CC_SCADENZA_ANNO.value == "") ||
              ((issues[document.dati.TES_CC_TIPO_CARTA.selectedIndex]==1) && (start_date[document.dati.TES_CC_TIPO_CARTA.selectedIndex]!=1) && document.dati.TES_CC_ISSUE_NUM.value == "") ||
				  ((start_date[document.dati.TES_CC_TIPO_CARTA.selectedIndex]==1) && document.dati.TES_CC_INIZIO_MESE.value == "") ||
				  ((start_date[document.dati.TES_CC_TIPO_CARTA.selectedIndex]==1) && document.dati.TES_CC_INIZIO_ANNO.value == "")  
              )
	            {
	                alert(ccukErrore); 
	                vbContinue = false;   
	            }
	            else
					{
					    
						 if (document.dati.TES_CC_TIPO_CARTA.value == "SWITCH CARD")
						    {
							 	var cardnum = document.dati.TES_CC_NUMERO_CARTA.value;
								 var issuenum = document.dati.TES_CC_ISSUE_NUM.value;
						       if(checkSwitch(cardnum,issuenum)==true)
								    vbContinue = true;
								 else
								    vbContinue = false;
							 }
						 else
							  vbContinue = true;   						  						  
					}
	    }
      else
	       vbContinue = true;
			vbObblig= privacyObbl;
		
		if ((vbContinue) && (selectedLanguage=="NL") && (vbBannl))
	    	  {
					
	        	 if ((document.dati.TES_BZ_BANCA.value == "") ||
	             (document.dati.TES_BZ_CC.value == ""))
	              {
	                alert(bannlErrore); 
	                vbContinue = false;   
	              }
	           		 else
	                vbContinue = true; 
				}
				
      if (vbContinue) 
			  { 
				 if (vbObblig==1)
	          if (document.dati.TES_ORD_PRIVACY_01[0].checked || document.dati.TES_ORD_PRIVACY_01[1].checked)
               document.dati.submit();
            else
               alert(ordConfermaPrivacy);
				 else
				 document.dati.submit();
			  }
			
    }
      
}

function ControllaCF(cf)
{

	var validi, i, s, set1, set2, setpari, setdisp;
	if( cf == '' )  return false;
	cf = cf.toUpperCase();
	if( cf.length != 16 )
		{
		alert( "La lunghezza del codice fiscale non è\n"
		+"corretta: il codice fiscale dovrebbe essere lungo\n"
		+"esattamente 16 caratteri.\n");
						return false;
		}
	validi = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
	for( i = 0; i < 16; i++ ){
		if( validi.indexOf( cf.charAt(i) ) == -1 )
		{
			alert( "Il codice fiscale contiene un carattere non valido `" +
				cf.charAt(i) +
				"'.\nI caratteri validi sono le lettere e le cifre.\n");
								return false;
								}
	}
	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) )
	{
	alert("Il codice fiscale non è corretto:\n"+
			"il codice di controllo non corrisponde.\n");
							return false;
		}
	return true;
}


function ControllaPIVA(pi)
{
	if( pi == '' )  return false;
	if( pi.length != 11 )
	{
		alert ("La lunghezza della partita IVA non è\n" +
			"corretta: la partita IVA dovrebbe essere lunga\n" +
			"esattamente 11 caratteri.\n");
	return false;
	}
	validi = "0123456789";
	for( i = 0; i < 11; i++ ){
		if( validi.indexOf( pi.charAt(i) ) == -1 )
		{
			alert( "La partita IVA contiene un carattere non valido `" +
				pi.charAt(i) + "'.\nI caratteri validi sono le cifre.\n");
				return false;
		}
	}
	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) )
	{
		alert( "La partita IVA non è valida:\n" +
			"il codice di controllo non corrisponde.\n");
					return false;
	}
	return true;
}