<!-- VARIABILI APPOGGIO GENERALI -->

<!-- APPOGGIO AJAX -->
function CreateXmlHttpReq2(handler) {
  var xmlhttp = null;
  try {xmlhttp = new XMLHttpRequest();}
  catch(e) {
    try {xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");}
    catch(e) {xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");}
  }
  xmlhttp.onreadystatechange = handler;
  return xmlhttp;
}


<!-- CALCOLA RATA MUTUO -->
function calcRata(tipo) {
  richiesto = document.getElementById("richiesto"+tipo).value;
  anni = document.getElementById("anni"+tipo).value;
  myRequestRata = CreateXmlHttpReq2(calcolaRata);
  myRequestRata.open("POST","nuovo_calcRata.php");
  myRequestRata.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  postvar = "tipo="+tipo+"&anni="+anni+"&richiesto="+richiesto;
  myRequestRata.send(postvar);
}
function calcolaRata() {
  if (myRequestRata.readyState == 4 && myRequestRata.status == 200) {
    risposta = myRequestRata.responseText.split("|*|");
    document.getElementById("rataCalcolata"+risposta[0]).innerHTML = ""+risposta[1];
  }
}


<!-- AGGIORNA COEFF MUTUO -->
function modTasso(anni, tasso, tipo) {
  myRequestTasso = CreateXmlHttpReq2(saveTasso);
  myRequestTasso.open("POST","nuovo_saveTasso.php");
  myRequestTasso.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  postvar = "anni="+anni+"&tasso="+tasso+"&tipo="+tipo;
  myRequestTasso.send(postvar);
}
function saveTasso() {
  if (myRequestTasso.readyState == 4 && myRequestTasso.status == 200) {
    rispostaT = myRequestTasso.responseText.split("|*|");
    if(rispostaT[2]>1){      
      document.getElementById(rispostaT[0]+"anni2").innerHTML = ""+rispostaT[1];
    }
    else{      
      document.getElementById(rispostaT[0]+"anni1").innerHTML = ""+rispostaT[1];
    }  
  }
}


<!-- AGGIORNA SECONDI AGENZIE -->
function modSecondi(idm, sec) {
  myRequestSecondi = CreateXmlHttpReq2(saveSecondi);
  myRequestSecondi.open("POST","nuovo_saveSecondi.php");
  myRequestSecondi.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  postvar = "idm="+idm+"&sec="+sec;
  myRequestSecondi.send(postvar);
}
function saveSecondi() {
  if (myRequestSecondi.readyState == 4 && myRequestSecondi.status == 200) {
    var rispostaT = myRequestSecondi.responseText.split("|*|");
    document.getElementById("tempo"+rispostaT[0]).innerHTML = ""+rispostaT[1];
  }
}


<!-- AGGIORNA ASSOCIAZIONE AGENZIA -->
function modAgenzia(idm) {  
  myRequestAgenzia = CreateXmlHttpReq2(saveAgenzia);
  myRequestAgenzia.open("POST","nuovo_saveAgenzia.php");
  myRequestAgenzia.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  postvar = "idm="+idm;
  myRequestAgenzia.send(postvar);
}
function saveAgenzia() {  
  if (myRequestAgenzia.readyState == 4 && myRequestAgenzia.status == 200) {
    var risposta = myRequestAgenzia.responseText.split("|*|");
    document.getElementById("agenzia"+risposta[0]).style.backgroundColor = ""+risposta[1];
  }
}


<!-- AGGIORNA ASSOCIAZIONE CATEGORIE CONVENZIONATE -->
function modCategoria(idm, categoria) {
  myRequestCategoria = CreateXmlHttpReq2(saveCategoria);
  myRequestCategoria.open("POST","nuovo_saveCategoria.php");
  myRequestCategoria.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  postvar = "idm="+idm+"&categoria="+categoria;
  myRequestCategoria.send(postvar);
}
function saveCategoria() {
  if (myRequestCategoria.readyState == 4 && myRequestCategoria.status == 200) {
    var rispostaC = myRequestCategoria.responseText.split("|*|");
    document.getElementById(rispostaC[1]+rispostaC[0]).style.backgroundColor = ""+rispostaC[2];
  }
}


<!-- SVUOTA I CAMPI DELLA SCHEDA -->
function svuotaScheda(){
  document.getElementById("titolo").value = "";
  document.getElementById("indirizzo").value = "";
  document.getElementById("note").innerHTML = "";
}



<!-- SALVA SCHEDA -->
function salvaScheda(idm){
  var tipo1 = 1;
  var titolo1 = document.getElementById("titolo").value;
  var indirizzo1 = document.getElementById("indirizzo").value;
  var note1 = document.getElementById("note").value;
  myRequestSaveScheda = CreateXmlHttpReq2(saveScheda);
  myRequestSaveScheda.open("POST","nuovo_saveScheda.php");
  myRequestSaveScheda.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  postvar = "idm="+idm+"&tipo="+tipo1+"&titolo="+titolo1+"&indirizzo="+indirizzo1+"&note="+note1;
  myRequestSaveScheda.send(postvar);

}
function saveScheda() {
  if (myRequestSaveScheda.readyState == 4 && myRequestSaveScheda.status == 200) {
    alert(myRequestSaveScheda.responseText);
  }
}



<!-- SALVA SCHEDA NUOVA -->
function salvaSchedaNew(){
  var tipo2 = 0;
  var titolo2 = document.getElementById("titolo").value;
  var indirizzo2 = document.getElementById("indirizzo").value;
  var note2 = document.getElementById("note").value;
  myRequestSaveScheda = CreateXmlHttpReq2(saveScheda);
  myRequestSaveScheda.open("POST","nuovo_saveScheda.php");
  myRequestSaveScheda.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  postvar = "tipo="+tipo2+"&titolo="+titolo2+"&indirizzo="+indirizzo2+"&note="+note2;
  myRequestSaveScheda.send(postvar);
}



