
function vedoTab(nome){
 if(nome == "form_mutuo"){
  var objTab = document.getElementById("form_mutuo");
  objTab.style.display = "block";
   var objTab = document.getElementById("tab_richiedi");
  objTab.style.display = "none";
  var objTasto = document.getElementById("bot_calcolo");
  objTasto.className= "tabactive";
  var objTasto = document.getElementById("bot_chiedo");
  objTasto.className= "tab";
 }else{
  var objTab = document.getElementById("form_mutuo");
  objTab.style.display = "none";
  var objTab = document.getElementById("tab_richiedi");
  objTab.style.display = "block";
   var objTasto = document.getElementById("bot_calcolo");
  objTasto.className= "tab";
  var objTasto = document.getElementById("bot_chiedo");
  objTasto.className= "tabactive";
 }

}

function AzzeraMiglior(){
      for ( i = 0 ; i < 3  ; i++ ) {
          document.formPrevent.miglior[i].checked = false ;
      }
}

function CheckCampi(){

      $errore=0;

      document.formPrevent.Importo.value= document.formPrevent.Importo.value.replace(",","");
      document.formPrevent.Importo.value= document.formPrevent.Importo.value.replace(".","");
      document.formPrevent.Importo.value= document.formPrevent.Importo.value.replace(",","");
      document.formPrevent.Importo.value= document.formPrevent.Importo.value.replace(".","");

      document.formPrevent.Valore.value= document.formPrevent.Valore.value.replace(",","");
      document.formPrevent.Valore.value= document.formPrevent.Valore.value.replace(".","");
      document.formPrevent.Valore.value= document.formPrevent.Valore.value.replace(",","");
      document.formPrevent.Valore.value= document.formPrevent.Valore.value.replace(".","");
      document.formPrevent.Durata.value= document.formPrevent.Durata.value.replace(",","");
      document.formPrevent.Durata.value= document.formPrevent.Durata.value.replace(".","");
      document.formPrevent.Durata.value= document.formPrevent.Durata.value.replace(",","");
      document.formPrevent.Durata.value= document.formPrevent.Durata.value.replace(".","");
      

      if (isNaN(document.formPrevent.Importo.value)){
          $errore=1;
          alert("Nella casella Importo Mutuo possono essere inseriti soltanto numeri.");
          document.formPrevent.Importo.focus();
          return;
      }
      if (document.formPrevent.Importo.value == ''){
          $errore=1;
          alert("Per calcolare il preventivo è necessario specificare l'importo del mutuo.");
          document.formPrevent.Valore.focus();
          return;
      }

      if (isNaN(document.formPrevent.Valore.value)){
          $errore=1;
          alert("Nella casella Valore Immobile possono essere inseriti soltanto numeri.");
          document.formPrevent.Valore.focus();
          return;
      }
      if (document.formPrevent.Valore.value == ''){
          $errore=1;
          alert("Per calcolare il preventivo è necessario indicare il valore dell'immobile da ipotecare.");
          document.formPrevent.Valore.focus();
          return;
      }
      if ((document.formPrevent.Valore.value < 50000) || (document.formPrevent.Valore.value > 1990000)) {
          $errore=1;
          alert("Nella casella del valore immobiliare possono essere inseriti solo importi compresi tra 50.000 e 1.990.000");
          document.formPrevent.Valore.focus();
          return;
      }

      if ((document.formPrevent.Importo.value < 30000) || (document.formPrevent.Importo.value > 990000)) {
          $errore=1;
          alert("Il preventivo automatico funziona con importi compresi tra 30.000 e 990.000 Euro.");
          document.formPrevent.Importo.focus();
          return;
      }

      var n3 = Math.abs(document.formPrevent.Durata.value);
      if (isNaN(document.formPrevent.Durata.value)){
          $errore=1;
          alert("Nella casella della durata possono essere inseriti soltanto numeri.");
          document.formPrevent.Durata.focus();
          return;
      }
      if (document.formPrevent.Durata.value > 30){
          if (n3 % 5 != 0){
               $errore=1;
               alert("Consentite solo durate intere comprese tra 5 e 30 o multiple di 5 fino a 50");
               document.formPrevent.Durata.focus();
               return;
           }
      }

      if ((document.formPrevent.Durata.value < 5) || (document.formPrevent.Durata.value > 50)) {
             $errore=1;
             alert("Consentite solo durate intere comprese tra 5 e 30 o multiple di 5 fino a 50.");
             document.formPrevent.Durata.focus();
             return;
      }


      if (document.formPrevent.Provincia.value == '') {	
          $errore=1;
          alert("Selezionare una tra le povincie elencate.");
          document.formPrevent.Provincia.focus();
          return;
      }

      $errore=1;
      for ( i = 0 ; i < 3  ; i++ ) {
          if (document.formPrevent.miglior[i].checked == 1) {
              $errore=0;
          }
      }
      if ($errore == 1 ) {
          alert("Selezionare tra miglior tasso, spread o taeg.");
          document.formPrevent.miglior[1].focus();
          return;
      }

      if ($errore == 0 ) {
	  document.formPrevent.submit();
      }
}
