function setTout(id){
  eval("myTimerD" + id + " = setTimeout(\"ripristinaPrimoLivello('"+ id +"'); \",30);");
}

function ripristinaPrimoLivello(id){
 
  //document.getElementById(id).style.background = "#E4ECF8 url(file:///C:/progetti/marioNegri/web/img/hp/menu/sfOff.jpg) 100% 0 no-repeat";
  //document.getElementById(id).style.color = '#FFFFFF';
  document.getElementById(id).className='timeOut2';
  
}

function clearTout(id){
  
     eval("timD = typeof(myTimerD"+ id + ");"   );
	 if (timD != "undefined")
        eval("clearTimeout(myTimerD" + id + ")");
 
}

/* check function for biblioteca SE */

function check(f){

 if ((f.campo1.value == "") && (f.campo2.value == "")) {
   alert("Inserire un valore da ricercare");
   return;
 } 
 
 f.submit(); 

}




function setIndexByValue(sel,val){

    for(var i = 0; i < sel.length; i++){
    
        if(sel.options[i].value == val){
            sel.selectedIndex = i;
            break;
        }

    }

}




function ControlloNL() {

/* function invio form nletter */

        if ((document.nlRegister.nome.value == "") || (document.nlRegister.cognome.value == "") || (document.nlRegister.email.value == "") || (document.nlRegister.annoNascita.value == "") || (document.nlRegister.professione.value == "")) {

        alert("E' necessario inserire tutti i dati per proseguire");

        return false;

	}

        if (document.nlRegister.privacy.checked == false) {

        alert("E' necessario accettare la legge sulla privacy per proseguire")

        return false;

        }

        addr = new String(document.nlRegister.email.value);
        
        if (validEmailAddress(addr) == false){

         return false;
        }

        
document.nlRegister.submit();

}



function ControlloNL2() {

/* function invio form nletter */

        if ((document.nlRegister2.nome.value == "") || (document.nlRegister2.cognome.value == "") || (document.nlRegister2.email.value == "") || (document.nlRegister2.annoNascita.value == "") || (document.nlRegister2.professione.value == "") || (document.nlRegister2.testata.value == "")) {

        alert("E' necessario inserire tutti i dati per proseguire");

        return false;

	}

        if (document.nlRegister2.privacy.checked == false) {

        alert("E' necessario accettare la legge sulla privacy per proseguire")

        return false;

        }

        addr = new String(document.nlRegister2.email.value);
 
       if (validEmailAddress(addr) == false){

        return false;
       }


        
document.nlRegister2.submit();

}


function controllaRivista3() {

	var errore=false;
	var messaggio = "Attenzione :\n";

		
	
	
	if(document.rivista.cognome.value =="" && document.rivista.ente.value ==""){
		messaggio += "Campo cognome oppure Ente/Ragione Sociale obbligatorio\n";
		errore=true;
	}
	if (document.rivista.tipo.value != 1 ) {

		if(document.rivista.nome.value ==""){
			messaggio += "Campo nome obbligatorio\n";
			errore=true;
		}
		if(document.rivista.indirizzo.value ==""){
			messaggio += "Campo indirizzo obbligatorio\n";
			errore=true;
		}
		if(document.rivista.citta.value ==""){
			messaggio += "Campo città obbligatorio\n";
			errore=true;
		}
		if(document.rivista.cap.value ==""){
			messaggio += "Campo CAP obbligatorio\n";
			errore=true;
		}
		if(document.rivista.prov.value ==""){
			messaggio += "Campo provincia obbligatorio\n";
			errore=true;
		}
	}
	if(document.rivista.tipo.value != 2){
		if (validEmail(document.rivista.mail.value) == false){

		messaggio +="Indirizzo email non valido\n";
		errore=true;
		}
	}

	
	if (document.rivista.privacy.checked == false) {

        messaggio += "E' necessario accettare la legge sulla privacy per proseguire\n";
        errore=true;

        }


	if (errore==false) {
		document.rivista.submit();
	} else {
		alert(messaggio);
	}

}


function controllaRivista2() {

	var errore=false;
	var messaggio = "Attenzione :\n";

		
	if (validEmail(document.rivista.mail.value) == false){

		messaggio +="Indirizzo email non valido\n";
		errore=true;
	}
	if(document.rivista.cognome.value =="" && document.rivista.ente.value ==""){
		messaggio += "Campo cognome oppure Ente/Ragione Sociale obbligatorio\n";
		errore=true;
	}
	
	if (document.rivista.tipo.value != 1 ) {

		if(document.rivista.nome.value ==""){
			messaggio += "Campo nome obbligatorio\n";
			errore=true;
		}
		if(document.rivista.indirizzo.value ==""){
			messaggio += "Campo indirizzo obbligatorio\n";
			errore=true;
		}
		if(document.rivista.citta.value ==""){
			messaggio += "Campo città obbligatorio\n";
			errore=true;
		}
		if(document.rivista.cap.value ==""){
			messaggio += "Campo CAP obbligatorio\n";
			errore=true;
		}
		if(document.rivista.prov.value ==""){
			messaggio += "Campo provincia obbligatorio\n";
			errore=true;
		}
	}

	
	if (document.rivista.privacy.checked == false) {

        messaggio += "E' necessario accettare la legge sulla privacy per proseguire\n";
        errore=true;

        }


	if (errore==false) {
		document.rivista.submit();
	} else {
		alert(messaggio);
	}

}

function validEmail(addr) {


  if (window.RegExp) {

    var notvalid = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
    var valid = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$";
    var regnv = new RegExp(notvalid);
    var regv = new RegExp(valid);
    if (!regnv.test(addr) && regv.test(addr))
      return true;
       else {
       return false;
       }
  }
  
  else {

    if(addr.indexOf("@") >= 0)
      return true;
      else {
       return false;
       }

  }



}


/*
function validEmail(addr) {


  if (window.RegExp) {

    var notvalid = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
    var valid = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$";
    var regnv = new RegExp(notvalid);
    var regv = new RegExp(valid);
    if (!regnv.test(addr) && regv.test(addr))
      return true;
       else {
       return false;
       }
  }
  
  else {

    if(addr.indexOf("@") >= 0)
      return true;
      else {
       return false;
       }

  }



}
*/



function controllaRivista() {

/* function invio form Negri News */

        if ((document.rivista.mail.value == "") || (document.rivista.nome.value == "")) {

        alert("E' necessario inserire tutti i dati per proseguire");

        return false;

	}

        if (document.rivista.privacy.checked == false) {

        alert("E' necessario accettare la legge sulla privacy per proseguire")

        return false;

        }

        addr2 = new String(document.rivista.mail.value);

       if (validEmailAddress2(addr2) == false){

        return false;
       }
       

        
document.rivista.submit();

}



function userChk() {

    
        if(confirm("Procedere alla cancellazione dell'utente?")) {

        document.getElementById("delete").submit();

        } else {

        return false;

        }

}




function changeLink() {

site = document.getElementById("linkList");

window.open(site[site.selectedIndex].value);

}





function validEmailAddress(addr) {


  if (window.RegExp) {

    var notvalid = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
    var valid = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$";
    var regnv = new RegExp(notvalid);
    var regv = new RegExp(valid);
    if (!regnv.test(addr) && regv.test(addr))
      return true;
       else {
       alert("Inserire un indirizzo e-mail valido");
       return false;
       }
  }
  
  else {

    if(addr.indexOf("@") >= 0)
      return true;
      else {
       alert("Inserire un indirizzo e-mail valido");
       return false;
       }

  }



}




function validEmailAddress2(addr2) {


  if (window.RegExp) {

    var notvalid = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
    var valid = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$";
    var regnv = new RegExp(notvalid);
    var regv = new RegExp(valid);
    if (!regnv.test(addr2) && regv.test(addr2))
      return true;
    else {
       alert("Inserire un indirizzo e-mail valido");
       return false;
       }
  
  }
  
  else {

    if(addr2.indexOf("@") >= 0)
      return true;
    else {
       alert("Inserire un indirizzo e-mail valido");
       return false;
       }

  }



}







function checkPub(f,ac){

/* function invio ricerca pubblicazioni */
 
 if (f.nas.value == "1") {

 if ((f.Clab.value == "") && (f.Ackn.value == "") && (f.Codice.value == "") && (f.Autore.value == "") && (f.Codice.value == "") && (f.Titolo.value == "") && (f.Rivista.value == "") && (f.Libro.value == "") && ((f.Cdip.selectedIndex == -1) || (f.Cdip.options[f.Cdip.selectedIndex].value == "")) ) {

   alert("Inserire un valore di ricerca");
   return;

 }
 
} else {

 if ((f.Codice.value == "") && (f.Autore.value == "") && (f.Codice.value == "") && (f.Titolo.value == "") && (f.Rivista.value == "") && (f.Libro.value == "")) {

   alert("Inserire un valore di ricerca");
   return;

 }

}  

if ((f.tipo[0].checked == false) && (f.tipo[1].checked == false) && (f.tipo[2].checked == false)) {
   
    alert("Scegliere tipologia di pubblicazione!");
    return;

}   

if ((f.Anno.value != "") || (f.AnnoF.value != "")) {

  if ((isNaN(f.Anno.value)) ||(isNaN(f.AnnoF.value)))  
  {
    alert("Inserire un valore di periodo valido!");
    return;
  }
}

 f.action=ac;
 f.target="_self";
 f.submit(); 

}
 


function apply(fon){
 
 /* gestione cambio misura font presenti sul header */

 if (fon == "") {
  document.getElementById("s2").disabled = 1;  
  document.getElementById("s3").disabled = 1;
  document.getElementById("s1").disabled = 0;
 } else if (fon == "1") {
  document.getElementById("s1").disabled = 1;  
  document.getElementById("s3").disabled= 1;
  document.getElementById("s2").disabled = 0;
 } else if (fon == "-1") {
  document.getElementById("s1").disabled = 1;  
  document.getElementById("s2").disabled = 1;
  document.getElementById("s3").disabled = 0;
 }

  eval("document.cookie=\"MN_FONT="+fon+"; path=/\";");


}



function cercaSE(){

  /* function per campo motore ricerca barra destra */

  if ((document.getElementById("cform").tipo[0].checked == false) && (document.getElementById("cform").tipo[1].checked == false) && (document.getElementById("cform").tipo[2].checked == false)) {  

   alert("Choose a destination for the search!");
 
  } else {

   if  (document.getElementById("cform").tipo[0].checked == true) {
     /* pubmed */
   

     document.getElementById("cform").action="http://www.ncbi.nlm.nih.gov/sites/entrez?CMD=search&DB=pubmed";
     document.getElementById("cform").encoding="application/x-www-form-urlencoded";
     document.getElementById("cform").target="_blank";
     document.getElementById("searchConfig").value="pubmed";
     document.getElementById("wordText").name="term";
     document.getElementById("cform").submit();

//     Go('search');

   } else if (document.getElementById("cform").tipo[1].checked == true) {
     /* staff  */ 
    
     document.getElementById("cform").action="/mn/it/sezioni/istituto/staff.html";
     document.getElementById("cform").encoding="application/x-www-form-urlencoded";
     document.getElementById("cform").target="_self";
     document.getElementById("wordText").name="nome";
     document.getElementById("cform").submit();  
         

 
   } else if (document.getElementById("cform").tipo[2].checked == true) {
     /* sito */

     document.getElementById("cform").action="/mn/it/dbsearch/search.html";
     document.getElementById("cform").encoding="application/x-www-form-urlencoded";
     document.getElementById("cform").target="_self";
     document.getElementById("wordText").name="query";
     document.getElementById("cform").submit();  
  
   }

  }

}

/* elements for pubmed search */

function Go(cmd)
{
    inGo=true;
    var frm = document.getElementById("cform");
    var sel = frm.db;
    frm.CMD.value = escape(cmd);
    if ( cmd =='Pager' ) { frm.cmd.value = ''; }  else { frm.cmd.value = cmd; }
    AddLimits();
    var q = frm.action;
    frm.action = q.substring(0, q.indexOf('?')) + '?CMD=' +frm.CMD.value + '&DB='+sel.value;
    inGo=false;
    frm.submit();
}

function AddLimits()
{
  var frm = document.getElementById("cform");
  var sel = frm.db;
  if (sel.value == "pubmed" ) {
    var a = Element("auth_dd");
    if( a != null ) {
      AddToQuery('author_','Auth','pmfilter_AuthOp','AND',false);
    }
    var j = Element("journ_dd");
    if( j != null ) {
      AddToQuery('journ_','Jour','','OR',true);
    }
  }
}

function Element(id)
{
  if (document.getElementById!=null) {
    return document.getElementById(id);
  }
  if (document.all!=null) {
    return document.all[id];
  }
  if (document.layers!=null) {
    return document.layers[id];
  }
  return null;
}


/*function per invio registrazione interazione farmaci*/

function inFarma() {

 f = document.interazioni;

 if ((f.nome.value == "") && (f.cognome.value == "") && (f.iscrizione.value == "") ) {
   
    alert("E' necessario inserire tutti i dati per proseguire");
    return;

 } 

 if (validEmailAddress(f.email.value) == false) {

  return;

 }

 f.submit(); 

}
