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 finestra_immagine(chemin,defaultWidth,defaultHeight)
{
	i1 = new Image;
	i1.src = chemin;
	html = '<HTML>\n<HEAD>\n<TITLE>Image</TITLE>\n</HEAD>\n<BODY LEFTMARGIN=0 MARGINWIDTH=0 TOPMARGIN=0 MARGINHEIGHT=0>\n<CENTER><IMG SRC="'+chemin+'" BORDER=0 NAME=imageTest onLoad="window.resizeTo(document.imageTest.width+14,document.imageTest.height+32)"></CENTER>\n</BODY>\n</HTML>';
	popupImage = window.open('','_blank','toolbar=0,location=0,directories=0,menuBar=0,scrollbars=0,resizable=1');
	popupImage.document.open();
	popupImage.document.write(html);
	popupImage.document.close();
}


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>20 ) 
   {
      alert('Attenzione! Il campo username deve essere min. 5 caratteri e max. 20 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>20 ) 
   {
      alert('Attenzione! Il campo password deve essere min. 5 caratteri e max. 20 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_newsletter_colonna()
{
   var controllo_email = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;	
	
   if (document.newsletter_colonna.email.value=='' || !controllo_email.test(document.newsletter_colonna.email.value)) 
   {
      alert('Attenzione! e-mail errata');
	  document.newsletter_colonna.email.focus();
	  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 controlla_form_richiesta_info()
{
   var controllo_email = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;	
	
   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.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.richiesta.value=='') 
   {
      alert('Attenzione! inserire la richiesta');
	  document.form_registrazione.richiesta.focus();
	  return false;
   }
   
   if (document.form_registrazione.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 crea_categoria()
{
   flag = true;	
	
   if (tree.getSelectedItemId()=='')
   {
      ShowDiv('controllo1');
	  flag = false;
    } 
    else HideDiv('controllo1');
	
   if (document.form_categoria.nome.value=='') 
   	{
	  document.form_categoria.nome.focus();
      ShowDiv('controllo2');
	  flag = false;
    } 
    else HideDiv('controllo2');
	
   if (document.form_categoria.nome_eng.value=='') 
   	{
	  document.form_categoria.nome_eng.focus();
      ShowDiv('controllo3');
	  flag = false;
    } 
    else HideDiv('controllo3');
	
   if (flag == true)
   {	
   	  document.form_categoria.id.value = tree.getSelectedItemId();
   	  document.form_categoria.azione.value = 'crea';
   	  document.form_categoria.submit();
   }
   else return false;
}

function modifica_categoria()
{
   flag = true;
   
   if (tree.getSelectedItemId()=='')
   {
      ShowDiv('controllo1');
	  flag = false;
    } 
    else HideDiv('controllo1');
	
   if (document.form_categoria.nome.value=='') 
   	{
	  document.form_categoria.nome.focus();
      ShowDiv('controllo2');
	  flag = false;
    } 
    else HideDiv('controllo2');
	
   if (document.form_categoria.nome_eng.value=='') 
   	{
	  document.form_categoria.nome_eng.focus();
      ShowDiv('controllo3');
	  flag = false;
    } 
    else HideDiv('controllo3');
	
   if (flag == true)
   {	
   document.form_categoria.id.value = tree.getSelectedItemId();
   document.form_categoria.azione.value = 'modifica';
   document.form_categoria.submit();
   }
   else return false;
}

function elimina_categoria()
{
   flag = true;
   
   if (tree.getSelectedItemId()=='')
   {
      ShowDiv('controllo1');
	  HideDiv('controllo2');
	  return false;
   } 
   
   if (flag == true)
   {	
   document.form_categoria.id.value = tree.getSelectedItemId();
   document.form_categoria.azione.value = 'elimina';
   document.form_categoria.submit();
   }
   else return false;
}

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_stock()
{
	document.location='stock_elimina.php?id='+mygrid.getSelectedId();
}

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)
{
	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');
   
   if (document.form_download.categoria.value=='' || tree.getSelectedItemId() == 1 ) 
   	{
	  document.form_download.categoria.focus();
      ShowDiv('controllo4');
	  flag = false;
    } 
    else HideDiv('controllo4');
   
    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;
}