function SetSession(varName){
  $.ajax({
    url: 'funzioni/ajax_func.php',
    data: {
      azione: 'setSession',
      sessVarName: varName
    },
    success: function(result){
      if(result!='') alert(result);
    },
    error: function(res1,res2,res3){
      alert(res1+'\n'+res2+'\n'+res3);
    }
  });
}
function NoAbbonamento()
{
  if(confirm('Devi avere un abbonamento attivo\n\nVuoi acquistarlo ora?\n\n'))
  {
    document.location='ris_abbonamenti.php';
  }
}
function GetObj1(idObj)
{
  return(document.getElementById(idObj));
}

function ClearString(Str1)
{
  myregexp = new RegExp("[^A-Z]","ig");
  Str2=Str1.replace(myregexp, "");
  
  return Str2;
}

/* ABILITA FILTRI */
function abilitaFiltri (divActive)
{
	if (document.getElementById(divActive).style.display == 'block')
		document.getElementById(divActive).style.display='none';
	else
		document.getElementById(divActive).style.display='block';
}
/* FINE ABILITA FILTRI */

/* FORM REGISTRA INCARICATO */
function controlloRegister() {

		var i1="0"
		var i2="0"
		var i3="0"
		var i4="0"
		
		/*se username presente*/
		if (document.getElementById('errorUser').style.display=="block")
		{	i1++; document.formRegister.username.className='input3'; }
		else
		{
				/*se username vuota*/
				if (document.formRegister.username.value=="")
				{	i3++; document.formRegister.username.className='input3'; }
				else
				{	document.formRegister.username.className=''; }
		}
	
		/*se codice xango errato*/
		if (document.getElementById('errorCodXango').style.display=="block")
		{	i4++; document.formRegister.codice_xango.className='input3'; }
		else
		{
				/*se codice xango vuoto*/
				if (document.formRegister.codice_xango.value=="")
				{	i3++; document.formRegister.codice_xango.className='input3'; }
				else
				{	document.formRegister.codice_xango.className=''; }
		}
	
		/*se email errata*/
		if (document.getElementById('errorEmail').style.display=="block")
		{	i2++; document.formRegister.email.className='input3'; }
		else
		{
				/*se email vuota*/
				if (document.formRegister.email.value=="")
				{	i3++; document.formRegister.email.className='input3'; }
				else
				{	document.formRegister.email.className=''; }
		}
	
		/*se password vuota*/
		if (document.formRegister.password.value=="")
		{	i3++; document.formRegister.password.className='input3'; }
		else
		{	document.formRegister.password.className=''; }
	
		/*se nome vuota*/
		if (document.formRegister.nome.value=="")
		{	i3++; document.formRegister.nome.className='input3'; }
		else
		{	document.formRegister.nome.className=''; }
	
		/*se cognome vuota*/
		if (document.formRegister.cognome.value=="")
		{	i3++; document.formRegister.cognome.className='input3'; }
		else
		{	document.formRegister.cognome.className=''; }
	
		/*se citta vuota*/
		if (document.formRegister.citta.value=="")
		{	i3++; document.formRegister.citta.className='input3'; }
		else
		{	document.formRegister.citta.className=''; }
	
		/*se cap vuota*/
		if (document.formRegister.cap.value=="")
		{	i3++; document.formRegister.cap.className='input3'; }
		else
		{	document.formRegister.cap.className=''; }
	
		/*se telefono vuota*/
		if (document.formRegister.cellulare.value=="")
		{	i3++; document.formRegister.cellulare.className='input3'; }
		else
		{	document.formRegister.cellulare.className=''; }
	
		if (i1!=0)
			alert ("Username già usato!");
		else if (i2!=0)
			alert ("L'Email inserita non è corretta!");
		else if (i4!=0)
			alert ("Il codice Xango non è corretto!");
		else if (i3!=0)
			alert ("Tutti i campi sono obbligatori!");
		else
		{
			return true;
		}
		
return false;
}

function controlloLink ()
{
  var oXmlHttp = zXmlHttp.createRequest();
	var url = "./funzioni/link.php?link="+document.formRegister.nome_link.value;
  oXmlHttp.open('get', url, true);
  oXmlHttp.onreadystatechange = function ()
  {
      if (oXmlHttp.readyState==4)
      {
          if (oXmlHttp.status==200)
          {
              var risposta=ClearString(oXmlHttp.responseText);
              //alert(risposta);
              //return(false);
              //*
              if (risposta=="presente")
              {
                document.getElementById('idNome').className='input3';
                document.getElementById('errorPresente').style.display='block';
                document.getElementById('errorVuoto').style.display='none';
              	var invio="no";
              }                    
              else if (risposta=="vuoto")
              {
                document.getElementById('idNome').className='input3';
                document.getElementById('errorVuoto').style.display='block';
                document.getElementById('errorPresente').style.display='none';
              	var invio="no";
              }                    
              else if (risposta=="yes")
              {
                //alert('Submit');
								document.formRegister.submit();
							}
							//*/
							
          }
          if (oXmlHttp.status==404)
              alert('La pagina '+ url + ' non esiste!');
          /*else	alert('Errore, status: '+oXmlHttp.status);*/
      }

  }
  oXmlHttp.send(null);
    
 	return false;
}

function controlloUsername ()
{
  var oXmlHttp = zXmlHttp.createRequest();
	var url = "./funzioni/users.php?user="+document.formRegister.username.value;
  oXmlHttp.open('get', url, true);
  oXmlHttp.onreadystatechange = function ()
  {
      if (oXmlHttp.readyState==4)
      {
          if (oXmlHttp.status==200)
          {
              var risposta=oXmlHttp.responseText;
              
              if (risposta=="no")
              {
                document.formRegister.username.className='input3';
                document.getElementById('errorUser').style.display='block';
              }                    
              else
              {
                document.formRegister.username.className='';
                document.getElementById('errorUser').style.display='none';
              }                    
              
              return;
          }
          if (oXmlHttp.status==404)
          {
              alert('La pagina '+ url + ' non esiste!');
          }
          else alert('Errore, status: '+oXmlHttp.status);
      }
  }
  oXmlHttp.send(null);
    
  return false;
}

function controlloEmail() {

		var str=document.formRegister.email.value
		var inc="0"
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		
		if (str.indexOf(at)==-1)
				inc++;
				
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
				inc++;

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
				inc++;

		 if (str.indexOf(at,(lat+1))!=-1)
				inc++;

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
				inc++;

		 if (str.indexOf(dot,(lat+2))==-1)
				inc++;
		
		 if (str.indexOf(" ")!=-1)
				inc++;
	
	if (inc!=0)
	{
    document.getElementById('idEmail').className='input3';
		document.getElementById('errorEmail').style.display='block';
	}
	else
	{
    document.getElementById('idEmail').className='';
		document.getElementById('errorEmail').style.display='none';
	}
}

function controlloCodiceXango() {

		inc=0;
		var str=document.formRegister.codice_xango.value.length;
		
		if (str != 8)
				inc++;
				
	if (inc!=0)
	{
    document.getElementById('idCodXango').className='input3';
		document.getElementById('errorCodXango').style.display='block';
	}
	else
	{
    document.getElementById('idCodXango').className='';
		document.getElementById('errorCodXango').style.display='none';
	}
}
/* FINE FORM REGISTRA INCARICATO */

/* INVITA CHI VUOI CAMBIO ANTEPRIMA */
function cambiaAnteprima (attivare, totali)
{
	for (i = 1 ; i <= totali ; i++)
	{
		var disab = 'pagina'+i;
		document.getElementById(disab).style.display = 'none';
	}
	var activ = 'pagina'+attivare;
	document.getElementById(activ).style.display = 'block';
}


/* CONTROLLO FORM CERCA USER XANGO */
function formCercaUserXango()
{
	var controllo=0;
	
	if (document.cercaUserXango.UserXango.value=="")
		controllo++;

	if (controllo==0)
	{
			document.cercaUserXango.sends.disabled=true;
			return true;
	}
	else
	{
			alert ('Tutti i campi sono obbligatori');
			return false;
	}
}
/* FINE CONTROLLO FORM CERCA USER XANGO */

/* CONTROLLO FORM SEND EMAIL */
function formSendEmail()
{
	var controllo=0;
	
	if (document.SendEmail.oggetto.value=="")
		controllo++;

	if (document.SendEmail.testo.value=="")
		controllo++;

	if (document.SendEmail.privacy.checked==false)
		controllo++;
	
	if (controllo==0)
	{
			document.SendEmail.sends.disabled=true;
			return true;
	}
	else
	{
			alert ('Tutti i campi sono obbligatori');
			return false;
	}
}
/* FINE CONTROLLO FORM SEND EMAIL */

/* ABILITA TUTTI GLI UTENTI DEL FORM WEBINAR DOWNLINE */
function webinar(check)
{
	formLength = document.formDownline.elements;

	/* li cicla tutti e ne recupera il tipo */
	for (var i=0;i<formLength.length;i++)
	{
		formLength[i].checked=check;
	}
}
/* FINE ABILITA TUTTI GLI UTENTI DEL FORM WEBINAR DOWNLINE */

/* CONTROLLO FORM INVITA CHI VUOI 2 */
function formInvita2()
{
	var controllo=0;
	
	if (document.invita2.oggetto.value=="")
		controllo++;

	if (document.invita2.messaggio.value=="")
		controllo++;

	//if (document.invita2.privacy.checked==false)
		//controllo++;
	
	if (controllo==0)
			return true;
	else
	{
			alert ('Tutti i campi sono obbligatori');
			return false;
	}
}
/* FINE CONTROLLO FORM INVITA CHI VUOI 2 */

/* CONTROLLO VALIDA EMAIL */
function isEmail(string) {
		if (string.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) != -1)
				return 1;
		else
				return 0;
}
/* FINE CONTROLLO VALIDA EMAIL */

/* CONTROLLO FORM INVITA CHI VUOI */
function formInvita()
{
	var controllo=0;
	
	if (document.invita.nome.value=="")
		controllo++;

	if (document.invita.cognome.value=="")
		controllo++;

	if ( isEmail(document.invita.email.value) == 0 )
	{
		controllo++;
		controllo2="yes";
	}
	else
		controllo2="no";

	if (controllo==0)
			return true;
	else
	{
			
			
			if (controllo2=="yes")
				alert ('Inserire un indirizzo e-mail valido');
			else
				alert ('Tutti i campi sono obbligatori');
			return false;
	}
}
/* FINE CONTROLLO FORM INVITA CHI VUOI */

/* CONTROLLO FORM BONUS */
function formBonus()
{
	var controllo=0;
	
	if (document.bonus.codeid.value=="")
		controllo++;

	if (document.bonus.nome.value=="")
		controllo++;

	if (document.bonus.email.value=="")
		controllo++;

	if (document.bonus.payment_number.value=="")
		controllo++;

	if (document.bonus.date_earned.value=="")
		controllo++;

	if (document.bonus.commission_type.value=="")
		controllo++;

	if (document.bonus.amount_paid.value=="")
		controllo++;

	if (document.bonus.choose_payment_method.value=="")
		controllo++;

	if (document.bonus.statusbonus.value=="")
		controllo++;

	if (document.bonus.effective_date.value=="")
		controllo++;

	if (document.bonus.privacy.checked==false)
		controllo++;
	
	if (controllo==0)
	{
			document.bonus.sends.disabled=true;
			return true;
	}
	else
	{
			alert ('Tutti i campi sono obbligatori');
			return false;
	}
}
/* FINE CONTROLLO FORM BONUS */

/* CONTROLLO FORM SPEDIZIONE */
function formSpedizione()
{
	var controllo=0;
	
	if (document.spedizione.codeid.value=="")
		controllo++;

	if (document.spedizione.nome.value=="")
		controllo++;

	if (document.spedizione.email.value=="")
		controllo++;

	if (document.spedizione.oggetto.value=="")
		controllo++;

	if (document.spedizione.n_spedizione.value=="")
		controllo++;

	if (document.spedizione.mese_riferimento.value=="")
		controllo++;

	if (document.spedizione.informazioni.value=="")
		controllo++;

	if (document.spedizione.privacy.checked==false)
		controllo++;
	
	if (controllo==0)
	{
			document.spedizione.sends.disabled=true;
			return true;
	}
	else
	{
			alert ('Tutti i campi sono obbligatori');
			return false;
	}
}
/* FINE CONTROLLO FORM SPEDIZIONE */

/* ATTIVA E DISABILITA CAMPI PER LINGUA */
var div_lingua="Visibileit";

function activateVisibility (divNascondere)
{
	document.getElementById(div_lingua).style.display = 'none';
	document.getElementById(divNascondere).style.display = 'block';

	div_lingua = divNascondere;
}
/* FINE ATTIVA E DISABILITA CAMPI PER LINGUA */

/* ATTIVA E DISABILITA VIDEO FORMAZIONE */
var div_attivo="Visibile0";
var link_attivo="Link0";

function activateVisibility2 (divNascondere,linkNascondere)
{
	document.getElementById(div_attivo).style.display = 'none';
	document.getElementById(divNascondere).style.display = 'block';
	
	document.getElementById(link_attivo).className = '';
	document.getElementById(linkNascondere).className = 'link2';
	
	div_attivo = divNascondere;
	link_attivo = linkNascondere;
}
/* FINE ATTIVA E DISABILITA VIDEO FORMAZIONE */

/* CONTROLLO FORM CONTATTI */
function formContact()
{
	var controllo=0;
	
	if (document.Contact.nome.value=="")
		controllo++;

	if (document.Contact.email.value=="")
		controllo++;

	if (document.Contact.informazioni.value=="")
		controllo++;

	if (document.Contact.privacy.checked==false)
		controllo++;
	
	if (controllo==0)
	{
			document.Contact.sends.disabled=true;
			return true;
	}
	else
	{
			alert ('Tutti i campi sono obbligatori');
			return false;
	}
}
/* FINE CONTROLLO FORM CONTATTI */

/* CONTROLLO FORM ATTIVITA' */
function formPrimoContact()
{
	var controllo=0;
	
	if (document.primoContact.nome.value=="")
		controllo++;

	if (document.primoContact.email.value=="")
		controllo++;

	if (document.primoContact.telefono.value=="")
		controllo++;

	if (document.primoContact.citta.value=="" && document.primoContact.citta2.value=="")
		controllo++;

	if (document.primoContact.privacy.checked==false)
		controllo++;

	if (controllo==0)
	{
			document.primoContact.sends.disabled=true;
			return true;
	}
	else
	{
			alert ('Tutti i campi sono obbligatori');
			return false;
	}
}
function formPrimoContact2()
{
  //*
  if(document.getElementById('idNazione').value == "105")
    document.primoContact.citta.value=document.primoContact.sel_citta.value;
  else
    document.primoContact.citta.value=document.primoContact.inp_citta.value;
  //*/  
  //alert(document.primoContact.citta.value);
  //return (false);
	var controllo=0;
	
	if (document.primoContact.nome.value=="")
		controllo++;

	if (document.primoContact.email.value=="")
		controllo++;

	if (document.primoContact.telefono.value=="")
		controllo++;

	if (document.primoContact.citta.value=="")
		controllo++;

	if (document.primoContact.privacy.checked==false)
		controllo++;

	if (controllo==0)
	{
			document.primoContact.sends.disabled=true;
			return true;
	}
	else
	{
			alert ('Tutti i campi sono obbligatori');
			return false;
	}
}
/* FINE CONTROLLO FORM ATTIVITA' */

/* CONTROLLO SU NAZIONE/PROVINCIA */
function controlloNazione ()
{
	if (document.getElementById('idNazione').value != "105")
	{
		document.getElementById('idProvincia').disabled=true;
		document.getElementById('selCom').style.display="none";
		document.getElementById('inpCitta').style.display="block";
	}
	else
	{
		document.getElementById('idProvincia').disabled=false;
		document.getElementById('inpCitta').style.display="none";
		document.getElementById('selCom').style.display="block";
	}
}
/* FINE CONTROLLO SU NAZIONE/PROVINCIA */

/* POPUP */
function Apri_popup(link)
{
  window.open('popup/'+link+'','mywindow','width=400,height=400,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,copyhistory=no,resizable=no');
}

function elencoVisite(link)
{
	if (window.innerHeight)
		ih = window.innerHeight;
	else if (document.documentElement && document.documentElement.clientHeight)
		ih = document.documentElement.clientHeight;
	else if (document.body)
		ih = document.body.clientHeight;

	if (window.innerWidth)
		iw = window.innerWidth;
	else if (document.documentElement && document.documentElement.clientWidth)
		iw = document.documentElement.clientWidth;
	else if (document.body)
		iw = document.body.clientWidth;
  
	altezza = (ih-400)/2;
	larghezza = (iw-600)/2;
	
  window.open(link,'mywindow','top='+altezza+',left='+larghezza+',width=600,height=400,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,copyhistory=no,resizable=no');
}

function addNote(link)
{
	if (window.innerHeight)
		ih = window.innerHeight;
	else if (document.documentElement && document.documentElement.clientHeight)
		ih = document.documentElement.clientHeight;
	else if (document.body)
		ih = document.body.clientHeight;

	if (window.innerWidth)
		iw = window.innerWidth;
	else if (document.documentElement && document.documentElement.clientWidth)
		iw = document.documentElement.clientWidth;
	else if (document.body)
		iw = document.body.clientWidth;
  
	altezza = (ih-500)/2;
	larghezza = (iw-600)/2;
	
  window.open(link,'mywindow','top='+altezza+',left='+larghezza+',width=600,height=500,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,copyhistory=no,resizable=no');
}

function popup_pers(link)
{
	if (window.innerHeight)
		ih = window.innerHeight;
	else if (document.documentElement && document.documentElement.clientHeight)
		ih = document.documentElement.clientHeight;
	else if (document.body)
		ih = document.body.clientHeight;

	if (window.innerWidth)
		iw = window.innerWidth;
	else if (document.documentElement && document.documentElement.clientWidth)
		iw = document.documentElement.clientWidth;
	else if (document.body)
		iw = document.body.clientWidth;
  
  window.open(link,'mywindow','width='+iw+',height='+ih+',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=1,copyhistory=no,resizable=no');
}
/* POPUP */

/* FORM LOGIN */
function controlloLogin ()
{
  var oXmlHttp = zXmlHttp.createRequest();
	var url = "./funzioni/login.php?user="+document.login.user.value+"&pass="+document.login.pass.value;
  oXmlHttp.open('get', url, true);
  oXmlHttp.onreadystatechange = function ()
  {
      if (oXmlHttp.readyState==4)
      {
          if (oXmlHttp.status==200)
          {
              var risposta=oXmlHttp.responseText;
              var tmp=ClearString(risposta);
              
              if (tmp=="yes")
                document.login.submit();
              else
              {
                document.getElementById('idUser').className='input3';
                document.getElementById('idPass').className='input3';
                document.getElementById('errorLogin').style.display='block';
              }                    
              
              return;
          }
          if (oXmlHttp.status==404)
          {
              alert('La pagina '+ url + ' non esiste!');
          }
          else alert('Errore, status: '+oXmlHttp.status);
      }
  }
  oXmlHttp.send(null);
    
  return false;
}
/* FINE FORM LOGIN */

