function is_email(string) {
	if (string.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) != -1)
 		return 1;
	else
		return 0;
}

function check_subscriber()
{
	p_email=document.getElementById('p_email');
	if (is_email(p_email.value)==1)
	{
		
		return true;
	}
	else
	{
		alert('attenzione! l\'email inserita non è valida');
		p_email.focus();
		return false;
	}
	return false;
}

function check_subscriber_block()
{
	p_email=document.getElementById('p_email_block');
	if (is_email(p_email.value)==1)
	{
		
		return true;
	}
	else
	{
		alert('attenzione! l\'email inserita non è valida');
		p_email.focus();
		return false;
	}
	return false;
}

function check_contact()
{
	p_email=document.getElementById('p_email');
	p_name=document.getElementById('p_name');
	p_subject=document.getElementById('p_subject');
	p_privacy=document.getElementById('p_privacy');
	p_message=document.getElementById('p_message');
	p_challenge=document.getElementById('p_challenge');
	if (p_name.value=='')
	{
		alert('Attenzione! Non hai inserito il nome');
		p_name.focus();
		return false;
	}
	
	if (p_subject.value=='')
	{
		alert('Attenzione! Non hai inserito l\'oggetto del messaggio');
		p_subject.focus();
		return false;
	}
	
	if (p_message.value=='')
	{
		alert('Attenzione! Il messaggio è vuoto');
		p_message.focus();
		return false;
	}
	if (!p_privacy.checked)
	{
		alert('Attenzione! Non hai accettato l\'informativa sulla privacy');
		p_privacy.focus();
		return false;
	}
	
	if (p_challenge.value=='')
	{
		alert('Attenzione! Devi inserire i caratteri che vedi nell\'immagine senza spazi');
		p_challenge.focus();
		return false;
	}
	
	if (is_email(p_email.value)==1)
	{
		
		return true;
	}
	else
	{
		alert('Attenzione! l\'email inserita non è valida');
		p_email.focus();
		return false;
	}
	return false;
}

function check_search_block()
{
	p_search_query=document.getElementById('p_search_query');
	if (p_search_query.value=='')
	{
		
		alert('attenzione! non hai inserito le parole da ricercare');
		p_search_query.focus();
		return false;
	}
	else
	{
		return true;
	}
	return false;
}


function check_reg()
{
	p_email=document.getElementById('p_email');
	p_name=document.getElementById('p_name');
	p_surname=document.getElementById('p_surname');
	p_privacy=document.getElementById('p_privacy');
	p_tel=document.getElementById('p_tel');
	p_challenge=document.getElementById('p_challenge');
	
	if (p_name.value=='')
	{
		alert('Attenzione! Non hai inserito il nome');
		p_name.focus();
		return false;
	}
	
	if (p_surname.value=='')
	{
		alert('Attenzione! Non hai inserito il cognome');
		p_surname.focus();
		return false;
	}
	
	if (p_tel.value=='')
	{
		alert('Attenzione! Non hai inserito il numero di telefono.');
		p_tel.focus();
		return false;
	}
	
	if (!p_privacy.checked)
	{
		alert('Attenzione! Non hai accettato l\'informativa sulla privacy');
		p_privacy.focus();
		return false;
	}
	
	if (p_challenge.value=='')
	{
		alert('Attenzione! Devi inserire i caratteri che vedi nell\'immagine senza spazi');
		p_challenge.focus();
		return false;
	}
	
	if (is_email(p_email.value)==1)
	{
		
		return true;
	}
	else
	{
		alert('Attenzione! l\'email inserita non è valida');
		p_email.focus();
		return false;
	}
	return false;
}
