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) {

	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);
	} 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_info_home(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 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 (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;
	}		
}

function validate_info_request(evt,alert_mess) {
	isemail=/^.+@.+\..{2,3}$/;
	var mail=document.info_request.email.value;
	var name=document.info_request.name.value;	
	var surname=document.info_request.surname.value;
	var re_province=document.info_request.re_province.value;
  var re_town=document.info_request.re_town.value;
  var task_type=document.info_request.task_type.value;
  var type=document.info_request.type.value; 	
	var verimage=document.info_request.verimage.value;
	var x=0;
	var y=0;	
	
	if (mail=='' || !(isemail.test(mail))) {
		document.info_request.email.style.background='gray';
		document.info_request.email.style.color='white';
		x=1;		
	}
	if (name =='' || !isNaN(name)){
		document.info_request.name.style.background='gray';
		document.info_request.name.style.color='white';
		x=1;
	}	
	if (surname =='' || !isNaN(surname)){
		document.info_request.surname.style.background='gray';
		document.info_request.surname.style.color='white';
		x=1;
	}
	if (re_province =='' || !isNaN(re_province)){
		document.info_request.re_province.style.background='gray';
		document.info_request.re_province.style.color='white';
		x=1;
	}
	if (re_town =='' || !isNaN(re_town)){
		document.info_request.re_town.style.background='gray';
		document.info_request.re_town.style.color='white';
		x=1;
	}	
	if (task_type =='---' || !isNaN(task_type)){
		document.info_request.task_type.style.background='gray';
		document.info_request.task_type.style.color='white';
		x=1;
	}	

	if (type =='---' || !isNaN(type)){
		document.info_request.type.style.background='gray';
		document.info_request.type.style.color='white';
		x=1;
	}	
  if (document.info_request.consent[0].checked) {
    y=2;
  }
	if (verimage =='' || !isNaN(verimage)){
		document.info_request.verimage.style.background='gray';
		document.info_request.verimage.style.color='white';
		x=1;
	}
	if (x=="1") {
		alert(alert_mess);
		stop_action(evt);

	} else if (y=="2") {
		alert('è necessario dare il consenso al trattamento dei dati per continuare');
		y=0;
		stop_action(evt);

	}else {
		document.info_request.submit();
	}  
}

function validate_info_valuation(evt,alert_mess) {
	isemail=/^.+@.+\..{2,3}$/;
	var mail=document.info_valuation.email.value;
	var name=document.info_valuation.name.value;	
  var surname=document.info_valuation.surname.value;
	var re_province=document.info_valuation.re_province.value;
  var re_town=document.info_valuation.re_town.value;
  var cap=document.info_valuation.cap.value;  
  var task_type=document.info_valuation.task_type.value;
  var type=document.info_valuation.type.value;
  var mq=document.info_valuation.mq.value;
  var description=document.info_valuation.description.value;     	
	var verimage=document.info_valuation.verimage.value;
	var x=0;
	var y=0;	
	
	if (mail=='' || !(isemail.test(mail))) {
		document.info_valuation.email.style.background='gray';
		document.info_valuation.email.style.color='white';
		x=1;		
	}
	if (surname =='' || !isNaN(surname)){
		document.info_valuation.surname.style.background='gray';
		document.info_valuation.surname.style.color='white';
		x=1;
	}
	if (name =='' || !isNaN(name)){
		document.info_valuation.name.style.background='gray';
		document.info_valuation.name.style.color='white';
		x=1;
	}	
	if (cap =='' || isNaN(cap)){
		document.info_valuation.cap.style.background='gray';
		document.info_valuation.cap.style.color='white';
		x=1;
	}
	if (mq =='' || isNaN(mq)){
		document.info_valuation.mq.style.background='gray';
		document.info_valuation.mq.style.color='white';
		x=1;
	}	
	if (re_province =='' || !isNaN(re_province)){
		document.info_valuation.re_province.style.background='gray';
		document.info_valuation.re_province.style.color='white';
		x=1;
	}
	if (re_town =='' || !isNaN(re_town)){
		document.info_valuation.re_town.style.background='gray';
		document.info_valuation.re_town.style.color='white';
		x=1;
	}	
	if (task_type =='---' || !isNaN(task_type)){
		document.info_valuation.task_type.style.background='gray';
		document.info_valuation.task_type.style.color='white';
		x=1;
	}	

	if (type =='---' || !isNaN(type)){
		document.info_valuation.type.style.background='gray';
		document.info_valuation.type.style.color='white';
		x=1;
	}	
	if (description =='' || !isNaN(description)){
		document.info_valuation.description.style.background='gray';
		document.info_valuation.description.style.color='white';
		x=1;
	} 	
  if (document.info_valuation.consent[0].checked) {
    y=2;
  }

	if (verimage =='' || !isNaN(verimage)){
		document.info_valuation.verimage.style.background='gray';
		document.info_valuation.verimage.style.color='white';
		x=1;
	}
	if (x=="1") {
		alert(alert_mess);
		stop_action(evt);

	} else if (y=="2") {
		alert('è necessario dare il consenso al trattamento dei dati per continuare');
		y=0;
		stop_action(evt);

	}else {
		document.info_valuation.submit();
	}  
}

function validate_info_lawyer(evt,alert_mess) {
	isemail=/^.+@.+\..{2,3}$/;
	var mail=document.info_lawyer.email.value;
	var name=document.info_lawyer.name.value;	
  var surname=document.info_lawyer.surname.value;
  var question=document.info_lawyer.question.value;     	
	var verimage=document.info_lawyer.verimage.value;
	var x=0;
	var y=0;	
	
	if (mail=='' || !(isemail.test(mail))) {
		document.info_lawyer.email.style.background='gray';
		document.info_lawyer.email.style.color='white';
		x=1;		
	}
	if (surname =='' || !isNaN(surname)){
		document.info_lawyer.surname.style.background='gray';
		document.info_lawyer.surname.style.color='white';
		x=1;
	}
	if (name =='' || !isNaN(name)){
		document.info_lawyer.name.style.background='gray';
		document.info_lawyer.name.style.color='white';
		x=1;
	}	

	if (question =='' || !isNaN(question)){
		document.info_lawyer.question.style.background='gray';
		document.info_lawyer.question.style.color='white';
		x=1;
	}	
  if (document.info_lawyer.consent[0].checked) {
    y=2;
  }

	if (verimage =='' || !isNaN(verimage)){
		document.info_lawyer.verimage.style.background='gray';
		document.info_lawyer.verimage.style.color='white';
		x=1;
	}
	if (x=="1") {
		alert(alert_mess);
		stop_action(evt);

	} else if (y=="2") {
		alert('è necessario dare il consenso al trattamento dei dati per continuare');
		y=0;
		stop_action(evt);

	}else {
		document.info_lawyer.submit();
	}  
}

function validate_re_request(evt,alert_mess) {
	isemail=/^.+@.+\..{2,3}$/;
	var mail=document.re_request.email.value;
	var name=document.re_request.name.value;	
	var surname=document.re_request.surname.value;
	var verimage=document.re_request.verimage.value;
	var x=0;
	var y=0;	
	
	if (mail=='' || !(isemail.test(mail))) {
		document.re_request.email.style.background='gray';
		document.re_request.email.style.color='white';
		x=1;		
	}
	if (name =='' || !isNaN(name)){
		document.re_request.name.style.background='gray';
		document.re_request.name.style.color='white';
		x=1;
	}	
	if (surname =='' || !isNaN(surname)){
		document.re_request.surname.style.background='gray';
		document.re_request.surname.style.color='white';
		x=1;
	}
  if (document.re_request.consent[0].checked) {
    y=2;
  }
	if (verimage =='' || !isNaN(verimage)){
		document.re_request.verimage.style.background='gray';
		document.re_request.verimage.style.color='white';
		x=1;
	}
	if (x=="1") {
		alert(alert_mess);
		stop_action(evt);
		x=0;

	} else if (y=="2") {
		alert('è necessario dare il consenso al trattamento dei dati per continuare');
		y=0;
		stop_action(evt);

	}else {
		document.re_request.submit();
	}  
}


