// JavaScript Document
function roll_over(a){
  document.getElementById("men_"+a).src="img/"+a+"2.png";
}

function roll_out(a){
  document.getElementById("men_"+a).src="img/"+a+"1.png";
}

function roll_over2(a){
  document.getElementById("men_"+a).src="img/"+a+"4.png";
}

function roll_out2(a){
  document.getElementById("men_"+a).src="img/"+a+"3.png";
}

function svuota_div(obj) {
	var nObj =obj.cloneNode(false);
	obj.parentNode.insertBefore(nObj,obj);
	obj.parentNode.removeChild(obj);
}

function valida_target() { 
    for (var i=0; i<document.links.length; i++)
        if (document.links[i].className=="blank") {
            document.links[i].target="_blank";
        } 
}

function controlla_invio_curriculum(){
  svuota_div(document.getElementById("errore"));
  var err=0;
  if(document.getElementById("titolo").value.length<1){
    notifica="Il campo titolo  è obbligatorio";
    document.getElementById("errore").appendChild(document.createTextNode(notifica));
    return false;
  }
  
  if(document.getElementById("nome").value.length<1){
    notifica="Il campo nome è obbligatorio";
    document.getElementById("errore").appendChild(document.createTextNode(notifica));
    return false;
  }
  
  if(document.getElementById("cognome").value.length<1){
    notifica="Il campo cognome è obbligatorio";
    document.getElementById("errore").appendChild(document.createTextNode(notifica));
    return false;
  }
  
  if(document.getElementById("giorno").value.length<1){
    notifica="Campo giorno di nascita non selezionato";
    document.getElementById("errore").appendChild(document.createTextNode(notifica));
    return false;
  }
  
  if(document.getElementById("mese").value.length<1){
    notifica="Campo mese di nascita non selezionato";
    document.getElementById("errore").appendChild(document.createTextNode(notifica));
    return false;
  }
  
  if(document.getElementById("anno").value.length<1){
    notifica="Campo anno di nascita non selezionato";
    document.getElementById("errore").appendChild(document.createTextNode(notifica));
    return false;
  }
  
  if(document.getElementById("indirizzo").value.length<1){
    notifica="Il campo indirizzo è obbligatorio";
    document.getElementById("errore").appendChild(document.createTextNode(notifica));
    return false;
  }
  
  if(document.getElementById("citta").value.length<1){
    notifica="Il campo città è obbligatorio";
    document.getElementById("errore").appendChild(document.createTextNode(notifica));
    return false;
  }
  
  if(document.getElementById("provincia").value.length<1){
    notifica="Il campo provincia è obbligatorio";
    document.getElementById("errore").appendChild(document.createTextNode(notifica));
    return false;
  }
  
   if(document.getElementById("cap").value.length<1){
    notifica="Il campo cap è obbligatorio";
    document.getElementById("errore").appendChild(document.createTextNode(notifica));
    return false;
  }
  
  if(document.getElementById("nazione").value.length<1){
    notifica="Campo nazione non selezionato";
    document.getElementById("errore").appendChild(document.createTextNode(notifica));
    return false;
  }
  
  if(document.getElementById("cellulare").value.length<1){
    notifica="Il campo cellulare è obbligatorio";
    document.getElementById("errore").appendChild(document.createTextNode(notifica));
    return false;
  }
  
  if(document.getElementById("mail").value.length<1){
    notifica="Il campo mail è obbligatorio";
    document.getElementById("errore").appendChild(document.createTextNode(notifica));
    return false;
  }
  
  if(document.getElementById("mail2").value.length<1){
    notifica="La conferma della mail è obbligatoria";
    document.getElementById("errore").appendChild(document.createTextNode(notifica));
    return false;
  }
  
  if(document.getElementById("area").value.length<1){
    notifica="Il campo Area di interesse  è obbligatorio";
    document.getElementById("errore").appendChild(document.createTextNode(notifica));
    return false;
  }
  
  campo_email = document.getElementById("mail").value;
  var Filtro = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
  if (Filtro.test(campo_email)){
    //testo
  } else {
   notifica="Formato della mail non valido";
   document.getElementById("errore").appendChild(document.createTextNode(notifica));
   return false
  }
  
  campo_email2 = document.getElementById("mail2").value;
  var Filtro = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
  if (Filtro.test(campo_email2)){
    //testo
  } else {
   notifica="Formato della mail non valido";
   document.getElementById("errore").appendChild(document.createTextNode(notifica));
   return false
  }
   
   if (document.getElementById("mail").value!=document.getElementById("mail2").value){
    notifica="Inseriti due indirizzi email diversi";
    document.getElementById("errore").appendChild(document.createTextNode(notifica));
    return false;
   }
   
  if(document.getElementById("allegato").value.length<1){
    notifica="Il campo allegato è obbligatorio";
    document.getElementById("errore").appendChild(document.createTextNode(notifica));
    return false;
  }
  
   if(document.getElementById("privacy").checked==false){
    notifica="Accettare le condizioni sulla privacy per proseguire";
    document.getElementById("errore").appendChild(document.createTextNode(notifica));
    return false
   } 
  if (err==0) return true;
}

function check_extension(filename,submitId) {
      var hash = {
        '.pdf' : 1,
        '.doc' : 1,
        '.zip' : 1,
        '.rar' : 1,
        '.docx' : 1,
      };
      var re = /\..+$/;
      var ext = filename.match(re);
      var submitEl = document.getElementById(submitId);
      if (hash[ext]) {
        //submitEl.disabled = false;
        return true;
      } else {
        document.getElementById(submitId).value="";
        return false;
      }
}



function controlla_contatto(){
  svuota_div(document.getElementById("errore"));
  var err=0;
  if(document.getElementById("titolo").value.length<1){
    notifica="Il campo titolo  è obbligatorio";
    document.getElementById("errore").appendChild(document.createTextNode(notifica));
    return false;
  }
  
  if(document.getElementById("nome").value.length<1){
    notifica="Il campo nome  è obbligatorio";
    document.getElementById("errore").appendChild(document.createTextNode(notifica));
    return false;
  }
  
  if(document.getElementById("cognome").value.length<1){
    notifica="Il campo cognome è obbligatorio";
    document.getElementById("errore").appendChild(document.createTextNode(notifica));
    return false;
  }
  
  if(document.getElementById("societa").value.length<1){
    notifica="Il campo società è obbligatorio";
    document.getElementById("errore").appendChild(document.createTextNode(notifica));
    return false;
  }
  
  if(document.getElementById("nazione").value.length<1){
    notifica="Il campo nazione è obbligatorio";
    document.getElementById("errore").appendChild(document.createTextNode(notifica));
    return false;
  }
  
  if(document.getElementById("mail").value.length<1){
    notifica="Il campo mail è obbligatorio";
    document.getElementById("errore").appendChild(document.createTextNode(notifica));
    return false;
  }
  
  if(document.getElementById("mail2").value.length<1){
    notifica="La conferma della mail è obbligatoria";
    document.getElementById("errore").appendChild(document.createTextNode(notifica));
    return false;
  }
  
  campo_email = document.getElementById("mail").value;
  var Filtro = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
  if (Filtro.test(campo_email)) {
    //ok
  } else {
   notifica="Formato della mail non valido";
   document.getElementById("errore").appendChild(document.createTextNode(notifica));
   return false
  }
  
  campo_email2 = document.getElementById("mail2").value;
  var Filtro = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
  if (Filtro.test(campo_email2)) {
    //testo
  } else {
   notifica="Formato della mail non valido";
   document.getElementById("errore").appendChild(document.createTextNode(notifica));
   return false
  }
  
  if (document.getElementById("mail").value!=document.getElementById("mail2").value){
    notifica="Inseriti due indirizzi email diversi";
    document.getElementById("errore").appendChild(document.createTextNode(notifica));
    return false;
   }
   
  if(document.getElementById("richiesta").value.length<1){
    notifica="Tipo di richiesta non selezionato";
    document.getElementById("errore").appendChild(document.createTextNode(notifica));
    return false;
  }
   
   if(document.getElementById("privacy").checked==false){
    notifica="Accettare le condizioni sulla privacy per proseguire";
    document.getElementById("errore").appendChild(document.createTextNode(notifica));
    return false
   } 
  
  if (err==0) manda_contatto();

}

function controlla_immobiliare(){
  svuota_div(document.getElementById("errore2"));
  var err=0;
  if(document.getElementById("immo_titolo").value.length<1){
    notifica="Il campo titolo  è obbligatorio";
    document.getElementById("errore2").appendChild(document.createTextNode(notifica));
    return false;
  }
  
  if(document.getElementById("immo_nome").value.length<1){
    notifica="Il campo nome  è obbligatorio";
    document.getElementById("errore2").appendChild(document.createTextNode(notifica));
    return false;
  }
  
  if(document.getElementById("immo_cognome").value.length<1){
    notifica="Il campo cognome è obbligatorio";
    document.getElementById("errore2").appendChild(document.createTextNode(notifica));
    return false;
  }
  
  if(document.getElementById("immo_referente").value.length<1){
    notifica="Il campo referente è obbligatorio";
    document.getElementById("errore2").appendChild(document.createTextNode(notifica));
    return false;
  }
  
  if(document.getElementById("immo_societa").value.length<1){
    notifica="Il campo società è obbligatorio";
    document.getElementById("errore2").appendChild(document.createTextNode(notifica));
    return false;
  }
  
  if(document.getElementById("immo_indirizzo").value.length<1){
    notifica="Il campo indirizzo è obbligatorio";
    document.getElementById("errore2").appendChild(document.createTextNode(notifica));
    return false;
  }
  
  if(document.getElementById("immo_telefono").value.length<1){
    notifica="Il campo telefono è obbligatorio";
    document.getElementById("errore2").appendChild(document.createTextNode(notifica));
    return false;
  }
  
  if(document.getElementById("immo_zona").value.length<1){
    notifica="Selezionare il campo zona";
    document.getElementById("errore2").appendChild(document.createTextNode(notifica));
    return false;
  }
  
  if(document.getElementById("immo_uso").value.length<1){
    notifica="Selezionare il campo di destinazione uso";
    document.getElementById("errore2").appendChild(document.createTextNode(notifica));
    return false;
  }
  
  if(document.getElementById("immo_dimensione").value.length<1){
    notifica="Selezionare il campo dimensione";
    document.getElementById("errore2").appendChild(document.createTextNode(notifica));
    return false;
  }
  
   if(document.getElementById("immo_mail").value.length<1){
    notifica="Il campo mail è obbligatorio";
    document.getElementById("errore2").appendChild(document.createTextNode(notifica));
    return false;
  }
  
  if(document.getElementById("immo_mail2").value.length<1){
    notifica="La conferma della mail è obbligatoria";
    document.getElementById("errore2").appendChild(document.createTextNode(notifica));
    return false;
  }
  
     campo_email = document.getElementById("immo_mail").value;
  var Filtro = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
  if (Filtro.test(campo_email)){
    //testo
  } else {
   notifica="Formato della mail non valido";
   document.getElementById("errore2").appendChild(document.createTextNode(notifica));
   return false
  }
  
  campo_email2 = document.getElementById("immo_mail2").value;
  var Filtro = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
  if (Filtro.test(campo_email2)){
    //testo
  } else {
   notifica="Formato della mail non valido";
   document.getElementById("errore2").appendChild(document.createTextNode(notifica));
   return false
  }
   
   if (document.getElementById("mail").value!=document.getElementById("mail2").value){
    notifica="Inseriti due indirizzi email diversi";
    document.getElementById("errore2").appendChild(document.createTextNode(notifica));
    return false;
   }
   
   if(document.getElementById("immo_privacy").checked==false){
    notifica="Accettare le condizioni sulla privacy per proseguire";
    document.getElementById("errore2").appendChild(document.createTextNode(notifica));
    return false
   }
   
    
  if (err==0) return true;

}

function crea_http_req() {
	var req = false;
	if (window.XMLHttpRequest){
		req = new XMLHttpRequest();
	} else if (window.ActiveXObject){
	  req=new ActiveXObject("Microsoft.XMLHTTP")
	}
	 return req;
}

function manda_contatto() {
	var dati_post = "titolo=" +
					encodeURIComponent( document.getElementById("titolo").value ) + "&nome=" +
					encodeURIComponent( document.getElementById("nome").value ) + "&cognome=" +
					encodeURIComponent( document.getElementById("cognome").value ) + "&societa=" +
					encodeURIComponent( document.getElementById("societa").value ) + "&indirizzo=" +
					encodeURIComponent( document.getElementById("indirizzo").value ) + "&nazione=" +
					encodeURIComponent( document.getElementById("nazione").value ) + "&cellulare=" +
					encodeURIComponent( document.getElementById("cellulare").value ) + "&mail=" +
					encodeURIComponent( document.getElementById("mail").value ) + "&richiesta=" +
					encodeURIComponent( document.getElementById("richiesta").value );
  //loader("loader");
  http_req.open('POST', 'inc/invio_contatto.php', true);
	http_req.onreadystatechange = esito_contatto;
	http_req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	http_req.setRequestHeader("Content-length", dati_post.length);
	http_req.send(dati_post);
}

function esito_contatto() {
	if(http_req.readyState == 4) {
	 //pulisciloader("loader");
		var esito = http_req.responseText;
    if(esito=="send"){
      document.getElementById("modulo_curriculum").className="nascondi";
      document.getElementById("errore").style.marginLeft=0;
      document.getElementById("errore").appendChild(document.createTextNode("Richiesta inviata con successo."));
    } else {
			document.getElementById("errore").appendChild(document.createTextNode("Errore. Impossibile procedere con la richiesta. Riprovare più tardi"));
		}
	}
}


function resetta_modulo(){
  document.getElementById("titolo").value="";
	document.getElementById("nome").value="";
  document.getElementById("cognome").value="";
	document.getElementById("societa").value="";
	document.getElementById("indirizzo").value="";
	document.getElementById("nazione").value="";
	document.getElementById("cellulare").value="";
	document.getElementById("mail").value="";
	document.getElementById("mail2").value="";
	document.getElementById("privacy").value="";
	document.getElementById("richiesta").value="";
  document.getElementById('modulo_curriculum').className='block';
  document.getElementById("errore").innerHtml=" ";
  document.getElementById('errore').style.marginLeft='120px';
  svuota_div(document.getElementById("errore"));
  document.getElementById("immo_titolo").value="";
  document.getElementById("immo_nome").value="";
  document.getElementById("immo_cognome").value="";
  document.getElementById("immo_referente").value="";
  document.getElementById("immo_societa").value="";
  document.getElementById("immo_indirizzo").value="";
  document.getElementById("immo_telefono").value="";
  document.getElementById("immo_fax").value="";
  document.getElementById("immo_mail").value="";
  document.getElementById("immo_mail2").value="";
  document.getElementById("immo_zona").value="";
  document.getElementById("immo_uso").value="";
  document.getElementById("immo_dimensione").value="";
  document.getElementById("immo_note").value="";
  document.getElementById("errore2").innerHtml=" ";
  document.getElementById('errore2').style.marginLeft='120px';
  svuota_div(document.getElementById("errore2"));
}

var http_req = crea_http_req();

