function diminuisciElemento(sez,sotSez){
//alert(sez + "," + sotSez);
/*
Legenda:
sez=0 e sotSez=0 --> ultimi aggiornamenti
sez=4 e sotSez=0 --> News
sez=1 e sotSez=2 --> Focus
sez=1 e sotSez=4 --> Intervista
*/
if (sez==0 && sotSez==0)var divPrincipale=$("ultimiPrincipale");

if (sez==4 && sotSez==0)
{var divPrincipale=$("newsPrincipale");
myDiv='News';
}

if (sez==1 && sotSez==2){var divPrincipale=$("focusPrincipale");
myDiv='Focus';
}

if (sez==1 && sotSez==4){var divPrincipale=$("intervistaPrincipale");
myDiv='Intervista';
}

var n_Elements=0;
var arrdivPrincipale=divPrincipale.getElementsByTagName('div');

	if(divPrincipale.hasChildNodes())
	{ //alert(divPrincipale.lastChild.id);
		divPrincipale.removeChild(divPrincipale.lastChild);
		//controllo quanti div figli soo rimasti: se ce n'è uno solo non permetto di diminuire ancora
		n_Elements=arrdivPrincipale.length;
		//alert(n_Elements);
		if(n_Elements==1) {
		var myImgMeno='img' + myDiv + 'Meno';
		//alert(myImgMeno);
		$(myImgMeno).hide();
		}
	}
}
//fine diminuisci elemento




function aggiungiElemento(sez,sotSez){
/*
Legenda:
sez=0 e sotSez=0 --> ultimi aggiornamenti
sez=4 e sotSez=0 --> News
sez=1 e sotSez=2 --> Focus
sez=1 e sotSez=4 --> Intervista
*/

if (sez==0 && sotSez==0){var divPrincipale=$("ultimiPrincipale");
myDiv='ultimi';
}

if (sez==4 && sotSez==0){var divPrincipale=$("newsPrincipale");
myDiv='News';
}

if (sez==1 && sotSez==2){var divPrincipale=$("focusPrincipale");
myDiv='Focus';
}

if (sez==1 && sotSez==4){var divPrincipale=$("intervistaPrincipale");
myDiv='Intervista';
}

var nth_Element=0;
if (sez==0 && sotSez==0){
var arrdivPrincipale=divPrincipale.getElementsByTagName('a');
}
else{var arrdivPrincipale=divPrincipale.getElementsByTagName('div');}

//for(var i=0; i<arrdivPrincipale.length;i++)
//{alert(i + ", " + arrdivPrincipale.item(i).id);}
nth_Element=arrdivPrincipale.length + 1;

if(nth_Element>1) {
var myImgMeno='img' + myDiv + 'Meno';
$(myImgMeno).show();}

//alert(nth_Element);
//inizio processo Ajax
	var usaLink = true;
	oXmlHttp = zXmlHttp.createRequest();
		if(oXmlHttp) {
  
    usaLink = false;
    oXmlHttp.open("get", "news.asp?nth_Element=" + nth_Element +"&sez=" + sez + "&sotSez=" + sotSez, true); 
//alert (nth_Element + "," + sez + "," + sotSez);

    oXmlHttp.onreadystatechange = function() {
	
      if (oXmlHttp.readyState == 4) { //completata
		if (oXmlHttp.status==200){ // HTTP response --> OK

		var newDiv=document.createElement('div');	
		$(divPrincipale).appendChild(newDiv);
		newDiv.id="singola" + myDiv + "Home_" + nth_Element
		//alert(newDiv.id);
		newDiv.style.clear="left";
		newDiv.innerHTML=oXmlHttp.responseText;
		
			}
	 	}
    };
    // invio richiesta
    oXmlHttp.send(null);
  }   
 // return usaLink;
//}
		
}
//fine aggiungi elemento

function ControllaStringa(campo)
{var st=campo.value;

if (st.length <3)
{
alert("Attenzione: Il numero di caratteri scritti non è sufficiente per la ricerca.");
 campo.value='';
 campo.focus();
 return false;
}
else
{
  for (var k=0;k<st.length;k++)
    if ((st.charAt(k)>="!") && (st.charAt(k)<="@"))
    { alert("Attenzione: Uno dei caratteri scritti non è corretto.");
      campo.value='';
      campo.focus();
      return false;
    } 
 	 return true;
} 
} 



function ControllaMail(campo)
{ 
 var st=campo.value; 
 if (st=='')
 {
 alert("Attenzione: scrivere l'E- mail.");
 campo.focus();
 return false;
 }
 
 
  if ( 
       	(st.indexOf("@")==-1) ||
       	(st.indexOf(".")==-1) || 
		(st.length < 6) ||
		(st.indexOf("@.")!=-1) ||
       	(st.indexOf("@@")!=-1) 
        
     )

  {  alert("Attenzione: indirizzo E- mail non valido.");
	 campo.value='';
     campo.focus();
     return false;
  }
  return true;
}  

function testoVuoto(campo,nome) 
{ if (campo.value=="")
	{  
	 alert("Attenzione: il campo '"+nome+"' è obbligatorio!");
	  campo.focus();
	  return true;   
	} 
  return false;
}


function ErrorString(campo,nomeCampo) 
{ var str = campo.value;
  for (var i=0;i < str.length;i++)
    {  
	  if ((str.charAt(i) > '0') && (str.charAt(i) < '9')) 
       {
          alert("Attenzione: il campo '"+nomeCampo+"' non può essere numerico!");
          campo.value="";
	      campo.focus();
	      return true;
       }
	}
  return false;
}


function ErrorEmail(campo)
{ 
 var st=campo.value; 
 if (st==''){return false;}
  if ( 
       	(st.indexOf("@")==-1) ||
       	(st.indexOf(".")==-1) || 
		(st.length < 6) ||
		(st.indexOf("@.")!=-1) ||
       	(st.indexOf("@@")!=-1) 
        
     )

  {  alert("Attenzione: indirizzo E- mail non valido.");
	 campo.value='';
     campo.focus();
     return true;
  }
  return false;
}  



function checkInvia()
{
if (
	(testoVuoto(document.frmMail.txtNome,"Nominativo"))||
	(ErrorString(document.frmMail.txtNome,"Nominativo"))||
	(testoVuoto(document.frmMail.txtEmail,"La tua email"))||
	(ErrorEmail(document.frmMail.txtEmail))||
	(testoVuoto(document.frmMail.txtOggetto,"Oggetto della email"))||	
	(testoVuoto(document.frmMail.txtArea,"Messaggio"))
	)
	return false;
else
	return true;
}

