var alertcolor="white";
var alertbackground="#2E6A9E";

//utilizzato per fermare onsubmit di mozilla
function stopMozSubmit(e){	
	if(e.preventDefault){e.preventDefault();}
}

function stop_submit(){		
	
	if(navigator.appName == 'Netscape'){
				window.addEventListener("submit", stopMozSubmit, false);								
				return true;
	}else {							
				event.returnValue=false;
				return false;			
	}
		
}

function validate_know_more(validate_message,evt) {

	var company=document.getElementById("company").value;
	var site=document.getElementById("site").value;
	var phone=document.getElementById("phone").value;
	var email=document.getElementById("email").value;
	var country=document.getElementById("country").value;
	var area=document.getElementById("area").value;
	
	isemail=/^.+@.+\..{2,3}$/;

	var check=2;

	if (company=='') {
		document.getElementById("company").style.color=alertcolor;
		document.getElementById("company").style.background=alertbackground;
		check=1;
	}
	if (site=='') {
		document.getElementById("site").style.color=alertcolor;
		document.getElementById("site").style.background=alertbackground;
		check=1;
	}
	if (country=='') {
		document.getElementById("country").style.color=alertcolor;
		document.getElementById("country").style.background=alertbackground;
		check=1;
	}
	if (area=='') {
		document.getElementById("area").style.color=alertcolor;
		document.getElementById("area").style.background=alertbackground;
		check=1;
	}
	if (!(isemail.test(email))) {
		document.getElementById("email").style.color=alertcolor;
		document.getElementById("email").style.background=alertbackground;
		check=1;
	}
	if (isNaN(phone) || phone=='') {
		document.getElementById("phone").style.color=alertcolor;
		document.getElementById("phone").style.background=alertbackground;
		check=1;
	}
	
	if (check==1) {
		alert(validate_message);
		stop_action(evt);
	} else {
		document.info.submit();
	}

}

function validate_info(evt,alert_mess) {
	isemail=/^.+@.+\..{2,3}$/;
	var mail=document.info.email.value;
	var surname=document.info.surname.value;
	var preference_zone=document.info.preference_zone.value;
	var verimage=document.info.verimage.value;
	var x=0;
	
	if (mail=='' || !(isemail.test(mail))) {
		document.info.email.style.background='gray';
		document.info.email.style.color='white';
		x=1;		
	}
	if (surname =='' || !isNaN(surname)){
		document.info.surname.style.background='gray';
		document.info.surname.style.color='white';
		x=1;
	}
	if (preference_zone =='' || !isNaN(preference_zone)){
		document.info.preference_zone.style.background='gray';
		document.info.preference_zone.style.color='white';
		x=1;
	}
	if (verimage =='' || !isNaN(verimage)){
		document.info.verimage.style.background='gray';
		document.info.verimage.style.color='white';
		x=1;
	}
	if (x=="1"){
		alert(alert_mess);
		stop_action(evt);
	}
}

function validate_project(evt,alert_mess) {
	isemail=/^.+@.+\..{2,3}$/;
	var mail=document.info.email.value;
	var surname=document.info.surname.value;
	var notes=document.info.notes.value;
	var verimage=document.info.verimage.value;
	var x=0;
	
	if (mail=='' || !(isemail.test(mail))) {
		document.info.email.style.background='gray';
		document.info.email.style.color='white';
		x=1;		
	}
	if (surname =='' || !isNaN(surname)){
		document.info.surname.style.background='gray';
		document.info.surname.style.color='white';
		x=1;
	}
	if (notes =='' || !isNaN(notes)){
		document.info.notes.style.background='gray';
		document.info.notes.style.color='white';
		x=1;
	}
	if (verimage =='' || !isNaN(verimage)){
		document.info.verimage.style.background='gray';
		document.info.verimage.style.color='white';
		x=1;
	}
	if (x=="1"){
		alert(alert_mess);
		stop_action(evt);
	}
}

function checkWorkWithUs(evt) {

	var consent=document.work_with_us.consent;
	var privacy=document.work_with_us.privacy;

	var y=0;
	
	if (!consent[0].checked){
      y=2;
	}
	if (!privacy[0].checked){
      y=2;
	}	

	if (y=="2"){
		alert("è necessario accettare gli avvisi sulla privacy");
		stop_action(evt);
	}	
}

function stop_action(evt){		
	var bMoz = (navigator.appName == 'Netscape');	
	if (bMoz){
		evt.preventDefault();			
	}else{
		event.returnValue=false;
		return false;
	}		
}
