function isNotValidEmail(elem) {
	var str = elem.value;
	var re  = /\b[a-z0-9._%-]+@[a-z0-9._%-]+\.[a-z0-9._%-]{2,4}\b/;
	if (!str.match(re))
		return false;
	else
		return true;
}

function isNumber(what)
{
   
   var i=new RegExp("^[0-9]+[0-9]+[0-9]+[0-9]+[0-9]");
   if(!i.test(what)) 
   { 
   	alert("Il numero di telefono non è corretto");
   	return (false); 
   } 
   return (true);
}


function validateForm(form)
{
  privacy = document.getElementById('accept')
  
  switch (form) 
  {
    case "mamme":
    
      forum   = document.getElementById('ddlForum_ddlValue');
      
      firstName = document.getElementById('Webviewstaticfield1_txtValue');
      surname = document.getElementById('Webviewstaticfield2_txtValue');
      email = document.getElementById('Webviewstaticfield3_txtValue');
      tel = document.getElementById('Webviewstaticfield4_txtValue');

      address = document.getElementById('Webviewstaticfield5_txtValue');
      babyAge = document.getElementById('Webviewdynamictextboxattribute1_txtValue');
      nick = document.getElementById('txtNickname_txtValue');
      passwd = document.getElementById('txtPassword_txtValue');
      
      if(privacy.checked == false)
      {
        alert("E' necessario accettare le condizioni sulla privacy");
        privacy.focus();
        return (false);
      }

      if(email.value == '')
      {
        alert("L'e-Mail è obbligatoria");
        email.focus();
        return (false);
      }
      
      
      if (!isNotValidEmail(email))
	    {
      
		    alert("il formato dell'e-Mail non è corretto");
		    email.focus();
		    return false;
	    }
	    
      if(firstName.value == '')
      {
        alert('Il nome è obbligatorio');
        firstName.focus();
        return (false);
      }
        
        

      if ( forum.value == 'Si' )
      {
        if(surname.value == '')
        {
          alert('Il cognome è obbligatorio');
          surname.focus();
          return (false);
        }
        
        
        if(nick.value == '')
        {
          alert('Il nickname è obbligatorio');
          nick.focus();
          return (false);
        }
        
        
        if(tel.value == '')
        {
          alert('Il telefono è obbligatorio');
          tel.focus();
          return (false);
        }

        if(address.value == '')
        {
          alert("L'indirizzo obbligatorio");
          address.focus();
          return (false);
        }
        
        if(babyAge.value == '')
        {
          alert("L'età del bambino è obbligatoria");
          babyAge.focus();
          return (false);
        }
        
        if(passwd.value == '')
        {
          alert("La password e' obbligatoria");
          passwd.focus();
          return (false);
        }
      }
      
      return (true);
          
    break
    
    case "pediatri":
    
      forum   = document.getElementById('ddlForum_ddlValue');
      
      firstName = document.getElementById('Webviewstaticfield1_txtValue');
      surname = document.getElementById('Webviewstaticfield2_txtValue');
      email = document.getElementById('Webviewstaticfield3_txtValue');
      tel = document.getElementById('Webviewstaticfield4_txtValue');

      address = document.getElementById('Webviewstaticfield5_txtValue');
      competence = document.getElementById('Webviewdynamictextboxattribute1_ddlValue');
      experience = document.getElementById('Webviewdynamicdropdownlistattribute1_txtValue');
      passwd = document.getElementById('txtPassword_txtValue');
      
      if(privacy.checked == false)
      {
        alert("E' necessario accettare le condizioni sulla privacy");
        privacy.focus();
        return (false);
      }

      if(email.value == '')
      {
        alert("L'e-Mail è obbligatoria");
        email.focus();
        return (false);
      }
      
      
      if (!isNotValidEmail(email))
	    {
      
		    alert("il formato dell'e-Mail non è corretto");
		    email.focus();
		    return false;
	    }

      if(firstName.value == '')
      {
        alert('Il nome è obbligatorio');
        firstName.focus();
        return (false);
      }
      
      if ( forum.value == 'Si' )
      {
        if(surname.value == '')
        {
          alert('Il cognome è obbligatorio');
          surname.focus();
          return (false);
        }
        
        
        if(tel.value == '')
        {
          alert('Il telefono è obbligatorio');
          tel.focus();
          return (false);
        }

        if(address.value == '')
        {
          alert("L'indirizzo obbligatorio");
          address.focus();
          return (false);
        }

        if(experience.value == '')
        {
          alert("Indicare gli anni di attività");
          experience.focus();
          return (false);
        }
        
        if(passwd.value == '')
        {
          alert("La password e' obbligatoria");
          passwd.focus();
          return (false);
        }
        
      }

    break

    
    case "contattaci":
    
      subject = document.getElementById('Webviewdynamictextboxattribute1_ddlValue');
      question = document.getElementById('Webviewdynamicdropdownlistattribute1_txtValue');
      firstName = document.getElementById('Webviewstaticfield1_txtValue');
      surname = document.getElementById('Webviewstaticfield2_txtValue');
      email = document.getElementById('Webviewstaticfield3_txtValue');
      tel = document.getElementById('Webviewstaticfield4_txtValue');
      if(privacy.checked == false)
      {
        alert("E' necessario accettare le condizioni sulla privacy");
        privacy.focus();
        return (false);
      }
      
      if(firstName.value == '')
      {
        alert('Il nome è obbligatorio');
        firstName.focus();
        return (false);
      }
      
      if(surname.value == '')
      {
        alert('Il cognome è obbligatorio');
        surname.focus();
        return (false);
      }
      
      if(email.value == '')
      {
        alert("L'e-Mail è obbligatoria");
        email.focus();
        return (false);
      }
      
      
      if (!isNotValidEmail(email))
	    {
      
		    alert("il formato dell'email non è corretto");
		    email.focus();
		    return false;
	    }
      
      
      if(tel.value == '')
      {
        alert('Il telefono è obbligatorio');
        tel.focus();
        return (false);
      }

      if(subject.value == '')
      {
        alert("Indicare l'argomento della richiesta");
        subject.focus();
        return (false);
      }
      
      if(question.value == '')
      {
        alert("E' necessario scrivere una richiesta");
        question.focus();
        return (false);
      }
      
        else{
        return (true);
          
      }
    
    break
    
    case "esperto":
    
      subject = document.getElementById('Webviewdynamicdropdownlistattribute1_txtValue');
      question = document.getElementById('Webviewdynamicdropdownlistattribute2_txtValue');
      firstName = document.getElementById('Webviewstaticfield1_txtValue');
      surname = document.getElementById('Webviewstaticfield2_txtValue');
      email = document.getElementById('Webviewstaticfield3_txtValue');
      tel = document.getElementById('Webviewstaticfield4_txtValue');
      if(privacy.checked == false)
      {
        alert("E' necessario accettare le condizioni sulla privacy");
        privacy.focus();
        return (false);
      }
      
      if(firstName.value == '')
      {
        alert('Il nome è obbligatorio');
        firstName.focus();
        return (false);
      }
      
      if(surname.value == '')
      {
        alert('Il cognome è obbligatorio');
        surname.focus();
        return (false);
      }
      
      if(email.value == '')
      {
        alert("L'e-Mail è obbligatoria");
        email.focus();
        return (false);
      }
      
      
      if (!isNotValidEmail(email))
	    {
      
		    alert("il formato dell'email non è corretto");
		    email.focus();
		    return false;
	    }
      
      
      if(tel.value == '')
      {
        alert('Il telefono è obbligatorio');
        tel.focus();
        return (false);
      }

      if(subject.value == '')
      {
        alert("Indicare l'oggetto della richiesta");
        subject.focus();
        return (false);
      }
      
      if(question.value == '')
      {
        alert("E' necessario scrivere una domanda");
        question.focus();
        return (false);
      }
      
        else{
        
        return (true);
        }
    
    break
    
    case "campioni":
    
      newsletter   = document.getElementById('ddlNewsLetterRegistration');
      
      firstName = document.getElementById('Webviewstaticfield1_txtValue');
      surname = document.getElementById('Webviewstaticfield2_txtValue');
      email = document.getElementById('Webviewstaticfield3_txtValue');
      address = document.getElementById('Webviewstaticfield5_txtValue');
      localita = document.getElementById('Webviewdynamictextboxattribute2_txtValue');
      cap = document.getElementById('Webviewdynamictextboxattribute3_txtValue');
      provincia = document.getElementById('Webviewdynamictextboxattribute4_txtValue');
      babyAge = document.getElementById('Webviewdynamictextboxattribute1_txtValue');
      prodotti = document.getElementById('cbxProdotti'); 
      howKnow = document.getElementById('ddlHowKnown_ddlValue');
            
      var ischecked = false;
    	
	    for(i=0;i<countcheck;i++){
		    if(document.getElementById("cbxProdotti_" + i ).checked){
		    ischecked  = true;
		    break;
		    }
	    }
	    
	    if( !ischecked )
	    {
	      alert("E' necessario selezionare almeno un prodotto" );
	      return false;
	    }
	    
      if(privacy.checked == false)
      {
        alert("E' necessario accettare le condizioni sulla privacy");
        privacy.focus();
        return (false);
      }

      if(localita.value == '')
      {
        alert("La località è obbligatoria");
        localita.focus();
        return (false);
      }
      
      if(cap.value == '')
      {
        alert("Il cap è obbligatoria");
        cap.focus();
        return (false);
      }
      
      if(provincia.value == '')
      {
        alert("La provincia è obbligatoria");
        provincia.focus();
        return (false);
      }
      
      if(firstName.value == '')
      {
        alert('Il nome è obbligatorio');
        firstName.focus();
        return (false);
      }

	  if(surname.value == '')
      {
        alert('Il cognome è obbligatorio');
        surname.focus();
        return (false);
      }
        
      if(address.value == '')
		  {
			  alert("L'indirizzo obbligatorio");
			  address.focus();
			  return (false);
		  }

		  if(babyAge.value == '')
		  {
			  alert("L'età del bambino è obbligatoria");
			  babyAge.focus();
			  return (false);
		  }
		  
		  if(howKnow.options[0].selected)
		  {
			  alert("Indica come ci hai conosciuto");
			  return (false);
		  }
		  
		  if( newsletter.value == "Si" )
		  {
		    if (!isNotValidEmail(email))
	      {
        
		      alert("il formato dell'e-Mail non è corretto");
		      email.focus();
		      return false;
	      }
		  }
		  		  
		  return (true);
      
   }
}

function showHideMandatoryMarker( showHide, elName )
{
  var list = document.getElementsByTagName( 'span' );
  
  for ( i = 0; i < list.length; i++ )
  {
    if ( list[i].name == elName )
      list[i].style.visibility = showHide ? 'visible' : 'hidden';
  }
}




