// JavaScript Document



function valida_log(){
user=document.logon.user.value;
pass=document.logon.pass.value;

if (user==""){alert("Immettere username"); return false}
if (pass==""){alert("Immettere Password"); return false}
}

function valid_cerca()
{
	p_ric=document.cerca.p_ric.value;
	if (p_ric=="")
	{
      alert("Inserire i dati per la ricerca"); return false
    }
}

function valida_reg(param)
{

	arr_campi=new Array("nome", "cognome", "residente", "provincia", "cap","indirizzo","tel","cell","email","tipo","universita","facolta");
	arr_titoli=new Array("Nome", "Cognome", "Città", "Provincia", "Cap", "Indirizzo", "Telefono", "Cellulare", "e-mail", "Tipo studente", "Università", "facoltà");
	
	var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;

	//alert(arr_campi.length +" -- " + arr_titoli.length)
	
	for(i=0; i<=arr_campi.length-1; i++)
	{
		campo=eval("document.registra."+arr_campi[i]+".value");
		//alert(campo)
	
   		if ((campo == "") || (campo == "undefined")) 
		{
      		alert("il campo " + arr_titoli[i] + " è obbligatorio");
	  		return false;
		}
	}
	
	 if (document.registra.cap.value!="")
	 {
	   ct=Number(document.registra.cap.value);
       if (isNaN(ct))
	      {
		    alert("Inserire valori numerici nel campo Codice postale. Niente trattini lettere o spazi.");
	        return false;
	      }

	 }
	 
	 if (document.registra.tel.value!="")
	  {
	   ct=Number(document.registra.tel.value);
       if (isNaN(ct))
	      {
		    alert("Inserire valori numerici nel campo Telefono. Niente trattini lettere o spazi.");
	        return false;
	      }

	  }
	  
	 if (document.registra.cell.value!="")
	  {
	   ct=Number(document.registra.cell.value);
       if (isNaN(ct))
	      {
		    alert("Inserire valori numerici nel campo Cellulare. Niente trattini lettere o spazi.");
	        return false;
	      }

	  }	  
	if (param=="dati")
	{
   		if ((document.registra.psw.value == "") || (document.registra.psw.value == "undefined")) 
		{
      		alert("il campo Password è obbligatorio");
	  		return false;
		}

	}
		
		if (!email_reg_exp.test(document.registra.email.value) || (document.registra.email.value == "") || (document.registra.email.value == "undefined")) 
		{
           alert("Inserire un indirizzo email valido");
           return false;
        }
		
		if (!document.registra.privacy.checked) 
		{
      		alert("Per proseguire accettare la normativa sul trattamento dei dati personali");
	  		return false;
		}
		
	document.registra.submit();
}



function show_div(param)
{
	e=document.getElementById(param).style.display;
	if (e=="none")
	{
	  document.getElementById(param).style.display="block";
  	  for(i=1; i<=tot_div; i++)
	  {
		if (param!=("ord"+i))
	    document.getElementById("ord"+i).style.display="none";

	  }
	}else
	 {
	  document.getElementById(param).style.display="none";
	 }
	 
}
//================================================================================================================================
// FUNZIONI GENERICHE (cioè che possono essre richiamate da script in pagine diverse)

function checkall(param)   //select all checkbox
  {
   sa=false;
  if(eval("document."+param+".check_all.checked"))
    sa=true;

  for (i=0;i<eval("document."+param+".elements.length");i++)
    {
   
      if(sa)
         eval("document."+param+".elements["+i+"].checked=true");
      else
         eval("document."+param+".elements["+i+"].checked=false");
    }
  }

countwin=1;
function update_win(param)
{
	 win_upd=window.open(param, "win"+countwin, 'width=500, height=400, ,toolbar=no, location=no, status=no, menubar=no, scrollbars=no, resizable=no');
	 win_upd.focus();
	 countwin++;
}

//================================================================================================================================

