function crea_categoria_download()
{
  if (document.form_categoria_download.nome.value=='') 
  {
      ShowDiv('controllo1');
	  return false;
   }
  
  if (document.form_categoria_download.nome_eng.value=='') 
  {
      ShowDiv('controllo2');
	  return false;
   }
   
   document.form_categoria_download.azione.value = 'crea';
   document.form_categoria_download.submit();
}

function modifica_categoria_download()
{
  if (document.form_categoria_download.nome.value=='') 
  {
      ShowDiv('controllo1');
	  return false;
   }
   
  if (document.form_categoria_download.nome_eng.value=='') 
  {
      ShowDiv('controllo2');
	  return false;
   }
   
   stringa_id = mygrid.getSelectedId();
   array_id = stringa_id.split(",");
   
   if (array_id.length>1) 
   {
      alert('Attenzione! Sono state selezionate pił righe');
	  return false;
   }

   document.location='categoria_download.php?azione=modifica&nome='+document.form_categoria_download.nome.value+'&nome_eng='+document.form_categoria_download.nome_eng.value+'&id='+stringa_id;
}

function elimina_categoria_download(tipo)
{
	document.location='categoria_download.php?tipo='+tipo+'&azione=elimina&id='+mygrid.getSelectedId();
}

function crea_categoria_utente()
{
  if (document.form_categoria_utente.nome.value=='') 
  {
      ShowDiv('controllo1');
	  return false;
   }
  
  if (document.form_categoria_utente.nome_eng.value=='') 
  {
      ShowDiv('controllo2');
	  return false;
   }
   
   document.form_categoria_utente.azione.value = 'crea';
   document.form_categoria_utente.submit();
}

function modifica_categoria_utente()
{
  if (document.form_categoria_utente.nome.value=='') 
  {
      ShowDiv('controllo1');
	  return false;
   }
   
  if (document.form_categoria_utente.nome_eng.value=='') 
  {
      ShowDiv('controllo2');
	  return false;
   }
   
   stringa_id = mygrid.getSelectedId();
   array_id = stringa_id.split(",");
   
   if (array_id.length>1) 
   {
      alert('Attenzione! Sono state selezionate pił righe');
	  return false;
   }

   document.location='categoria_utente.php?azione=modifica&nome='+document.form_categoria_utente.nome.value+'&nome_eng='+document.form_categoria_utente.nome_eng.value+'&id='+stringa_id;
}

function elimina_categoria_utente(tipo)
{
	document.location='categoria_utente.php?tipo='+tipo+'&azione=elimina&id='+mygrid.getSelectedId();
}

function crea_catalogo()
{
  if (document.form_catalogo.nome.value=='') 
  {
      ShowDiv('controllo1');
	  return false;
   }
  
  if (document.form_catalogo.nome_eng.value=='') 
  {
      ShowDiv('controllo2');
	  return false;
   }
   
   document.form_catalogo.azione.value = 'crea';
   document.form_catalogo.submit();
}

function modifica_catalogo()
{
  if (document.form_catalogo.nome.value=='') 
  {
      ShowDiv('controllo1');
	  return false;
   }
   
  if (document.form_catalogo.nome_eng.value=='') 
  {
      ShowDiv('controllo2');
	  return false;
   }
   
   stringa_id = mygrid.getSelectedId();
   array_id = stringa_id.split(",");
   
   if (array_id.length>1) 
   {
      alert('Attenzione! Sono state selezionate pił righe');
	  return false;
   }

   document.location='catalogo.php?azione=modifica&nome='+document.form_catalogo.nome.value+'&nome_eng='+document.form_catalogo.nome_eng.value+'&id='+stringa_id+'&ordine='+document.form_catalogo.ordine.value;
}

function elimina_catalogo(tipo)
{
	document.location='catalogo.php?tipo='+tipo+'&azione=elimina&id='+mygrid.getSelectedId();
}


function crea_categoria()
{
  if (document.form_categoria.nome.value=='') 
  {
      ShowDiv('controllo1');
	  return false;
   }
  
  if (document.form_categoria.nome_eng.value=='') 
  {
      ShowDiv('controllo2');
	  return false;
   }
   
   document.form_categoria.azione.value = 'crea';
   document.form_categoria.submit();
}

function modifica_categoria()
{
  if (document.form_categoria.idcatalogo.value==0) 
  {
      ShowDiv('controllo3');
	  return false;
   }
   
  if (document.form_categoria.nome.value=='') 
  {
      ShowDiv('controllo1');
	  return false;
   }
   
  if (document.form_categoria.nome_eng.value=='') 
  {
      ShowDiv('controllo2');
	  return false;
   }
   
   stringa_id = mygrid.getSelectedId();
   array_id = stringa_id.split(",");
   
   if (array_id.length>1) 
   {
      alert('Attenzione! Sono state selezionate pił righe');
	  return false;
   }

   document.location='categoria.php?azione=modifica&nome='+document.form_categoria.nome.value+'&nome_eng='+document.form_categoria.nome_eng.value+'&id='+stringa_id+'&idcatalogo='+document.form_categoria.idcatalogo.value+'&ordine='+document.form_categoria.ordine.value;
}

function elimina_categoria(tipo)
{
	document.location='categoria.php?tipo='+tipo+'&azione=elimina&id='+mygrid.getSelectedId();
}

function ShowDiv(aDiv) 
{ 
  var el; 
  
  if (document.layers) // NS4 
  { 
    el = document.layers[aDiv]; 
    el.visibility = 'show'; 
  } 
  else if (document.all)   // IE4 non implementa getElementById() 
  { 
    el = document.all[aDiv]; 
    el.style.visibility = 'visible'; 
  } 
  else if (document.getElementById) // IE5+, NS6+, Mozilla/Gecko, Opera 5+ 
  { 
    //alert('W3C DOM compliancy'); 
    el = document.getElementById(aDiv); 
    el.style.visibility = 'visible'; 
  } 
} 

function HideDiv(aDiv) 
{ 
  var el; 

  if (document.layers) // NS4 
  { 
    el = document.layers[aDiv]; 
    el.visibility = 'hide'; 
  } 
  else if (document.all)   // IE4 non implementa getElementById() 
  { 
    el = document.all[aDiv]; 
    el.style.visibility = 'hidden'; 
  } 
  else if (document.getElementById) // IE5+, NS6+, Mozilla/Gecko, Opera 5+ 
  { 
    //alert('W3C DOM compliancy'); 
    el = document.getElementById(aDiv); 
    el.style.visibility = 'hidden'; 
  } 
} 

function finestra_immagine(imageURL,defaultWidth,defaultHeight){

//variabili----------------------------------------------------------------------------------
imageTitle = 'foto';
PositionX = 100;
PositionY = 100;
var AutoClose = true;
if (parseInt(navigator.appVersion.charAt(0))>=4){
var isNN=(navigator.appName=="Netscape")?1:0;
var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}
var optNN='scrollbars=no,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
var optIE='scrollbars=no,width=150,height=100,left='+PositionX+',top='+PositionY;
		
if (isNN){imgWin=window.open('about:blank','',optNN);}
if (isIE){imgWin=window.open('about:blank','',optIE);}
with (imgWin.document){
writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');writeln('<sc'+'ript>');
writeln('var isNN,isIE;');writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
writeln('isNN=(navigator.appName=="Netscape")?1:0;');writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
writeln('function reSizeToImage(){');writeln('if (isIE){');writeln('window.resizeTo(100,100);');
writeln('width=100-(document.body.clientWidth-document.images[0].width);');
writeln('height=100-(document.body.clientHeight-document.images[0].height);');
writeln('window.resizeTo(width,height);}');writeln('if (isNN){');       
writeln('window.innerWidth=document.images["George"].width;');writeln('window.innerHeight=document.images["George"].height;}}');
writeln('function doTitle(){document.title="'+imageTitle+'";}');writeln('</sc'+'ript>');
if (!AutoClose) writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()">')
else writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
writeln('<img name="George" src='+imageURL+' style="display:block"></body></html>');
close();		
}}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function controlla_ricerca()
{ 
   if (document.ricerca_prodotto.idcatalogo.value==0 ) return false;
   else return true;   
}


function controlla_form_comp_contatti()
{
   var controllo_email = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
   
   if (document.form1.azienda.value=='' ) 
   {
      alert('Attenzione! Campo azienda vuoto');
	  return false;
   }  
   if (document.form1.contatto.value=='') 
   {
      alert('Attenzione! Campo contatto vuoto');
	  return false;
   }  
   if (document.form1.email.value=='' || !controllo_email.test(document.form1.email.value)) 
   {
      alert('Attenzione! e-mail errata');
	  return false;
   }  
   if (document.form1.citta.value=='') 
   {
      alert('Attenzione! Campo cittą vuoto');
	  return false;
   }  
   if (!document.form1.privacy.checked) 
   {
      alert('Attenzione! Non hai acconsentito al trattamento dei dati personali');
	  return false;
   }  

  return true;   
}

function controlla_form_registrazione()
{
   var controllo_email = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;	
	
   if (document.form_registrazione.username.value=='') 
   {
      alert('Attenzione! inserire Username');
	  document.form_registrazione.username.focus();
	  return false;
   }  
   
   if (document.form_registrazione.username.value.length<5 || document.form_registrazione.username.value.length>15 ) 
   {
      alert('Attenzione! Il campo username deve essere min. 5 caratteri e max. 15 caratteri');
	  document.form_registrazione.username.focus();
	  return false;
   }  
   
   if (document.form_registrazione.password.value=='') 
   {
      alert('Attenzione! inserire Password');
	  document.form_registrazione.password.focus();
	  return false;
   } 
   
   if (document.form_registrazione.password.value.length<5 || document.form_registrazione.password.value.length>15 ) 
   {
      alert('Attenzione! Il campo password deve essere min. 5 caratteri e max. 15 caratteri');
	  document.form_registrazione.password.focus();
	  return false;
   }  
   
   if (document.form_registrazione.password.value!=document.form_registrazione.password2.value) 
   {
      alert('Attenzione! Il campo conferma password \n non corrisponde alla password inserita');
	  document.form_registrazione.password2.focus();
	  return false;
   } 
   
   if (document.form_registrazione.nome.value=='') 
   {
      alert('Attenzione! inserire il nome');
	  document.form_registrazione.nome.focus();
	  return false;
   }  
   
   if (document.form_registrazione.cognome.value=='') 
   {
      alert('Attenzione! inserire il cognome');
	  document.form_registrazione.cognome.focus();
	  return false;
   }

   if (document.form_registrazione.cap.value=='') 
   {
      alert('Attenzione! inserire il CAP');
	  document.form_registrazione.cap.focus();
	  return false;
   }

   if (document.form_registrazione.email.value=='' || !controllo_email.test(document.form_registrazione.email.value)) 
   {
      alert('Attenzione! e-mail errata');
	  document.form_registrazione.email.focus();
	  return false;
   }  

   if (document.form_registrazione.privacy.checked==false) 
   {
      alert('Attenzione! Non hai acconsentito il trattamento dei dati');
	  return false;
   }

   return true; 
}

function controlla_form_newsletter()
{
   var controllo_email = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;	
	
   if (document.FRMregNewsLetterPlus.nome.value=='') 
   {
      alert('Attenzione! inserire il nome');
	  document.FRMregNewsLetterPlus.nome.focus();
	  return false;
   }  
   
   if (document.FRMregNewsLetterPlus.cognome.value=='') 
   {
      alert('Attenzione! inserire il cognome');
	  document.FRMregNewsLetterPlus.cognome.focus();
	  return false;
   }

   if (document.FRMregNewsLetterPlus.email.value=='' || !controllo_email.test(document.FRMregNewsLetterPlus.email.value)) 
   {
      alert('Attenzione! e-mail errata');
	  document.FRMregNewsLetterPlus.email.focus();
	  return false;
   }  
   
   if (document.FRMregNewsLetterPlus.privacy.checked==false) 
   {
      alert('Attenzione! Non hai acconsentito il trattamento dei dati');
	  return false;
   }

   return true; 
}


function seleziona_stato_provincia(id_stato,id_provincia)
{
	for(i=0; i<300; i++) { 
	if (document.form_registrazione.stato.options[i].value == id_stato)
	{
		document.form_registrazione.stato.options[i].selected=true;
		break;
	}
	}
	for(i=0; i<150; i++) { 
	if (document.form_registrazione.provincia.options[i].value == id_provincia)
	{
		document.form_registrazione.provincia.options[i].selected=true;
		break;
	}
	}
	return true;
}

function seleziona_cat_prodotto()
{
	document.form_prodotto.categoria.value=tree.getItemText(tree.getSelectedItemId());
	document.form_prodotto.idcategoria.value=tree.getSelectedItemId();
}

function seleziona_cat_utente()
{
	document.form_utente.categoria.value=tree.getItemText(tree.getSelectedItemId());
	document.form_utente.idcategoria.value=tree.getSelectedItemId();
}

function seleziona_cat_download()
{
	document.form_download.categoria.value=tree.getItemText(tree.getSelectedItemId());
	document.form_download.idcategoria.value=tree.getSelectedItemId();
}


function elimina_evento()
{
	document.location='evento_elimina.php?id='+mygrid.getSelectedId();
}

function elimina_utente()
{
	document.location='utente_elimina.php?id='+mygrid.getSelectedId();
}

function elimina_download()
{
	document.location='download_elimina.php?id='+mygrid.getSelectedId();
}

function elimina_prodotto()
{
	document.location='prodotto_elimina.php?id='+mygrid.getSelectedId();
}

function cambia_gruppo_utente()
{
	document.location='utente_permessi.php?idgruppo='+utentetree.getSelectedItemId();
}

function crea_permesso(idgruppo)
{
	if (downloadtree.getAllChecked()=='') alert('Attenzione! Selezionare almeno una categoria');
	else document.location='utente_permessi.php?azione=crea&idgruppo='+idgruppo+'&idcategoria='+downloadtree.getAllChecked();
}


function controlla_form_download()
{
   flag = true;
   
   if (document.form_download.nome.value=='')
   	{
	  document.form_download.nome.focus();
      ShowDiv('controllo1');
	  flag = false;
    } 
    else HideDiv('controllo1');

   if (document.form_download.nome_eng.value=='')
   	{
	  document.form_download.nome_eng.focus();
      ShowDiv('controllo2');
	  flag = false;
    } 
    else HideDiv('controllo2');
   
   if (document.form_download.file.value=='')
   	{
	  document.form_download.file.focus();
      ShowDiv('controllo3');
	  flag = false;
    } 
    else HideDiv('controllo3');
   
    return flag; 
}

function controlla_form_stock()
{
   flag = true;
   
   if (document.form_stock.articolo.value=='')
   	{
	  document.form_stock.articolo.focus();
      ShowDiv('controllo1');
	  flag = false;
    } 
    else HideDiv('controllo1');
	
   if (document.form_stock.articolo_eng.value=='')
   	{
	  document.form_stock.articolo_eng.focus();
      ShowDiv('controllo2');
	  flag = false;
    } 
    else HideDiv('controllo2');
   
    if (document.form_stock.quantita.value=='') 
	{
	  document.form_stock.quantita.focus();
      ShowDiv('controllo3');
	  flag = false;
    } 
    else HideDiv('controllo3');
	
    if (document.form_stock.prezzo.value=='') 
	{
	  document.form_stock.prezzo.focus();
      ShowDiv('controllo4');
	  flag = false;
    } 
    else HideDiv('controllo4');
	
    if (document.form_stock.descrizione.value=='') 
	{
	  document.form_stock.descrizione.focus();
      ShowDiv('controllo5');
	  flag = false;
    } 
    else HideDiv('controllo5');

    if (document.form_stock.descrizione_eng.value=='') 
	{
	  document.form_stock.descrizione_eng.focus();
      ShowDiv('controllo6');
	  flag = false;
    } 
    else HideDiv('controllo6');
  
    return flag; 
}

function controlla_form_evento()
{
   flag = true;
   
   if (document.form_evento.data.value=='')
   	{
	  document.form_evento.data.focus();
      ShowDiv('controllo1');
	  flag = false;
    } 
    else HideDiv('controllo1');
   
    if (document.form_evento.titolo.value=='') 
	{
	  document.form_evento.titolo.focus();
      ShowDiv('controllo2');
	  flag = false;
    } 
    else HideDiv('controllo2');
  
    if (document.form_evento.titolo_eng.value=='') 
	{
	  document.form_evento.titolo_eng.focus();
      ShowDiv('controllo3');
	  flag = false;
    } 
    else HideDiv('controllo3');
	
    return flag; 
}

function controlla_form_utente()
{
   flag = true;
	
   if (document.form_utente.nome.value=='')
   {
	  document.form_utente.nome.focus();
      ShowDiv('controllo1');
	  flag = false;
   } 
   else HideDiv('controllo1');
   
   if (document.form_utente.cognome.value=='')
      {
	  document.form_utente.cognome.focus();
      ShowDiv('controllo2');
	  flag = false;
   } 
   else HideDiv('controllo2');
   
   if (document.form_utente.categoria.value=='' || tree.getSelectedItemId() == 1 )
   {
	  document.form_utente.categoria.focus();
      ShowDiv('controllo3');
	  flag = false;
   } 
   else HideDiv('controllo3');
   
   if (document.form_utente.username.value=='')
      {
	  document.form_utente.username.focus();
      ShowDiv('controllo4');
	  flag = false;
   } 
   else HideDiv('controllo4');
   
   if (document.form_utente.password.value=='') 
   {
	  document.form_utente.password.focus();
      ShowDiv('controllo5');
	  flag = false;
   } 
   else HideDiv('controllo5');

   return flag; 
}


function controlla_form_prodotto()
{
   flag = true;
   
   if (document.form_prodotto.modello.value=='')
   {
	  document.form_prodotto.modello.focus();
      ShowDiv('controllo1');
	  flag = false;
   } 
   else HideDiv('controllo1');
   
   if (document.form_prodotto.modello_eng.value=='')
   {
	  document.form_prodotto.modello_eng.focus();
      ShowDiv('controllo2');
	  flag = false;
   } 
   else HideDiv('controllo2');
    
   if (document.form_prodotto.categoria.value=='' || tree.getSelectedItemId() == 1 )
   {
	  document.form_prodotto.categoria.focus();
      ShowDiv('controllo3');
	  flag = false;
   } 
   else HideDiv('controllo3');
   
   if (document.form_prodotto.descrizione_breve.value=='')
   {
	  document.form_prodotto.descrizione_breve.focus();
      ShowDiv('controllo4');
	  flag = false;
   } 
   else HideDiv('controllo4');
   
   if (document.form_prodotto.descrizione_breve_eng.value=='')
   {
	  document.form_prodotto.descrizione_breve_eng.focus();
      ShowDiv('controllo5');
	  flag = false;
   } 
   else HideDiv('controllo5');

   return flag;
}