/* REDIRECT PAGE */
function redirectPage (pageSend)
{
    window.location.href = pageSend;
}
/* FINE REDIRECT PAGE */

/* 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 */

/* FUNZIONE X ATTESA */
function loader_off (valore)
{
	  document.getElementById("loading_off").style.display = valore;
		//document.body.style.overflow='hidden';
}

function loader_on (valore)
{
	  document.getElementById("loading_on").style.display = valore;
		//document.body.style.overflow='auto';
}
/* FINE FUNZIONE X ATTESA */

/* APRE CHIUDE MENU */
function sottoMenuOpen (menuAction)
{
	document.getElementById(menuAction).style.display='inline';
}

function sottoMenuClose (menuAction)
{
	document.getElementById(menuAction).style.display='none';
}
/* FINE APRE CHIUDE MENU */

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

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

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

/* FORM ADD USER */
function controlloUsername ()
{
  var oXmlHttp = zXmlHttp.createRequest();
	var url = "../funzioni/users.php?user="+document.formInsert.username.value;
  oXmlHttp.open('get', url, true);
  oXmlHttp.onreadystatechange = function ()
  {
      if (oXmlHttp.readyState==4)
      {
          if (oXmlHttp.status==200)
          {
              var risposta=oXmlHttp.responseText;
              
              if (risposta=="yes")
                document.formInsert.submit();
              else
              {
                document.getElementById('campoUser').className='input3';
                document.getElementById('errorUser').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 ADD USER */


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

/* CAMBIA NUMERO OPZIONI SU SONDAGGIO */
function changeOption ()
{
	opinion = document.getElementById('numOption').value;
	direction = './sondaggi_add.php?numOption=' + opinion;
	location.href=direction;
}
/* FINE CAMBIA NUMERO OPZIONI SU SONDAGGIO */

/* CONTROLLO PASSWORD UGUALI */
function controlloPassword (nomeForm)
{
	pass = nomeForm.pri_password.value;
	rip_pass = nomeForm.rip_password.value;

	if (pass != rip_pass)
	{
    document.getElementById('pass').className='input3';
    document.getElementById('rip_password').className='input3';
    document.getElementById('txtErrorePassword').style.display='block';
		
		return false;
	}
	else
		return true;
}
/* CONTROLLO PASSWORD UGUALI */


/* INSERISCE CAMPO NEL FORM */
function categorie (valoreCampo, idCampo, nomeForm)
{
	nomeForm.id_categoria.value=idCampo;
	nomeForm.nome_categoria.value=valoreCampo;
	window.close();
}

function organizzazioni (valoreCampo, idCampo, nomeForm)
{
	nomeForm.id_organizzazione.value=idCampo;
	nomeForm.nome_organizzazione.value=valoreCampo;
	window.close();
}
/* INSERISCE CAMPO NEL FORM */

/* POPUP */
		function win_cat(url)
		{ 
		link = window.open(url,"categorie","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=550,height=300,left=0,top=0"); 
		} 

		function win_org(url)
		{ 
		link = window.open(url,"organizzazioni","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=550,height=300,left=0,top=0"); 
		} 
/* FINE POPUP */

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

/* 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;
              //alert(risposta);
              if (risposta=="yes")
                document.login.submit();
              else
              {
                document.getElementById('idUser').className='input3';
                document.getElementById('idPass').className='input3';
                document.getElementById('txtErrore').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 */

