function StartSearch()
{
	if ((document.getElementById('search_input').value == '') || (document.getElementById('search_input').value == 'cerca nel catalogo'))
	{
		alert("Inserisci almeno una parola per iniziare la ricerca!");
		return false;
	}
	else
	{
		return true;
	}
}

function SelectPrivacy(checkbox_id)
{
	var privacy = document.getElementById(checkbox_id).src;
	var privacy = privacy.indexOf("checkbox_on.png");
		
	if (privacy == '-1')
	{
		document.getElementById(checkbox_id).src = 'imgs/checkbox_on.png';
	}
	else
	{	
		document.getElementById(checkbox_id).src = 'imgs/checkbox_off.png';
	}
}
		
function CheckEmail(str)
{
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
			
	if (str.indexOf(at)==-1)                                                   { return false; }
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)    { return false; }
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr) { return false; }
	if (str.indexOf(at,(lat+1))!=-1)                                           { return false; }
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)      { return false; }
	if (str.indexOf(dot,(lat+2))==-1)                                          { return false; }
	if (str.indexOf(" ")!=-1)                                                  { return false; }

	return true;
}

function SubmitContattiForm()
{	
	if (document.getElementById('form_nome').value == '')
	{
		alert("Per inviare il modulo devi inserire il nome!");
		return false;
	}
	else if (document.getElementById('form_azienda').value == '')
	{
		alert("Per inviare il modulo devi inserire il cognome!");
		return false;
	}
	else if (document.getElementById('form_email').value == '')
	{
		alert("Per inviare il modulo devi inserire l'indirizzo e-mail!");
		return false;
	}
	else if (CheckEmail(document.getElementById('form_email').value) == false)
	{
		alert("L'indirizzo e-mail inserito non e' valido!");
		return false;
	}
	else if (document.getElementById('form_telefono').value == '')
	{
		alert("Per inviare il modulo devi inserire il telefono!");
		return false;
	}
	else if (document.getElementById('form_richiesta').value == '')
	{
		alert("Per inviare il modulo devi inserire la richiesta!");
		return false;
	}
	else if (document.getElementById('form_privacy_tellme').value == 'no')
	{
		alert("Per inviare il modulo devi confermare l'accettazione della privacy policy!");
		return false;
	}
	else
	{
		return true;
	}
}

function SubmitInformazioniForm()
{	
	if (document.getElementById('form_nome').value == '')
	{
		alert("Per inviare il modulo devi inserire il nome!");
		return false;
	}
	else if (document.getElementById('form_cognome').value == '')
	{
		alert("Per inviare il modulo devi inserire il cognome!");
		return false;
	}
	else if (document.getElementById('form_email').value == '')
	{
		alert("Per inviare il modulo devi inserire l'indirizzo e-mail!");
		return false;
	}
	else if (CheckEmail(document.getElementById('form_email').value) == false)
	{
		alert("L'indirizzo e-mail inserito non e' valido!");
		return false;
	}
	else if (document.getElementById('form_richiesta').value == '')
	{
		alert("Per inviare il modulo devi inserire la richiesta!");
		return false;
	}
	else
	{
		return true;
	}
}
