/* INSERISCE CAMPO NEL FORM */

function GetObj(idObj)
{
  return (document.getElementById(idObj));
}

function altraCat (valoreCampo)
{
	if (valoreCampo=="0")
		document.getElementById('altraCategoria').style.display='';
	else
		document.getElementById('altraCategoria').style.display='none';
		
	if (valoreCampo=="1")
		document.getElementById('ass_cat').style.display='';
	else
		document.getElementById('ass_cat').style.display='none';
		
  if (valoreCampo=="7")
		document.getElementById('camcom').style.display='';
	else
		document.getElementById('camcom').style.display='none';
		
	if (valoreCampo=="8")
		document.getElementById('camcomestero').style.display='';
	else
		document.getElementById('camcomestero').style.display='none';	
}

function altraAssCat (valoreCampo)
{
  if (valoreCampo=="99999")
	{
		document.getElementById('sel_ass_cat').style.display='none';
		document.getElementById('nome_ass_cat').style.display='';
	}
}


function categorie (valoreCampo, idCampo, nomeForm)
{
	nomeForm.id_categoria.value=idCampo;
	nomeForm.nome_categoria.value=valoreCampo;
	
	if (valoreCampo=="Altro")
	{
		window.opener.document.getElementById('altraStrut').style.display='block';
		//window.opener.document.getElementById('strutturaAppartenenza').style.display='none';
	}
	else
	{
		//window.opener.document.getElementById('strutturaAppartenenza').style.display='block';
		window.opener.document.getElementById('altraStrut').style.display='none';
	}
	
	window.close();
}

function organizzazioni (valoreCampo, idCampo, nomeForm)
{
	nomeForm.id_organizzazione.value=idCampo;
	nomeForm.nome_organizzazione.value=valoreCampo;
	
	if (valoreCampo=="Altro")
	{
		window.opener.document.getElementById('altroOrg').style.display='block';
		window.opener.document.getElementById('strutturaAppartenenza').style.display='none';
		window.opener.document.getElementById('tr_desc_att').style.display='';
	}
	else
	{
		window.opener.document.getElementById('strutturaAppartenenza').style.display='block';
		window.opener.document.getElementById('altroOrg').style.display='none';
		window.opener.document.getElementById('tr_desc_att').style.display='none';
	}
			
	window.close();
}
/* INSERISCE CAMPO NEL FORM */

/* POPUP */
		function win_catNew(URLlink)
		{ 
			idOrganizzazione = formInsert.id_organizzazione.value;
			linkURL = URLlink+"&id_organizzazione="+idOrganizzazione;
			
		link = window.open(linkURL,"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_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;
              
              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 */


function Paginatore_aree(id_tab,pag,pag_tot)
{
  for(i=1;i<=pag_tot;i++)
  {
    var id_obj="tab_"+id_tab+"_"+i;
    var obj=document.getElementById(id_obj);
    if(i==pag)
      obj.style.display="block";
    else
      obj.style.display="none";
  }    
}  

function Visualizza_aree(value)
{
  var id_sett="settore_"+value;
  var i=0;
  for(i=0;i<100;i++)
  {
    var temp="settore_"+i+"";
    if(document.getElementById(temp)!=null)
    {
      //alert(document.getElementById(temp));
      document.getElementById(temp).style.display="none";
    }
  }
  if(value!="0")
  {
    document.getElementById(id_sett).style.display="block";
  }
  return false;
}

function ProvSel(idProv)
{
  var oXmlHttp = zXmlHttp.createRequest();
	var url = "./funzioni/ajax_func.php?azione=selCom&idProv="+idProv;
  oXmlHttp.open('get', url, true);
  oXmlHttp.onreadystatechange = function ()
  {
      if (oXmlHttp.readyState==4)
      {
          if (oXmlHttp.status==200)
          {
              var risposta=oXmlHttp.responseText;
              document.getElementById('divCom').innerHTML=risposta;          
              return;
          }
          if (oXmlHttp.status==404)
          {
              alert('La pagina '+ url + ' non esiste!');
          }
          else alert('Errore, status: '+oXmlHttp.status);
      }
  }
  oXmlHttp.send(null);
    
  return false;
}
