// funzione da chiamare al caricamento del body
function bodyLoad() {
  shadow();
  settaAltezza();
}

// Setta allo stesso valore l'altezza delle colonne
function settaAltezza() {
  var altCorpocentro = 0;
  var altCorpomenusx = 0;
  var altCorpomenudx = 0;
  var margineSicurezza = 60;
  var margintop = 25;
  if(document.getElementById("corpocentro") != null) {
    document.getElementById("corpocentro").style.height = "auto";
    altCorpocentro = document.getElementById("corpocentro").offsetHeight;
  }
  if(document.getElementById("corpomenusx") != null) {
    document.getElementById("corpomenusx").style.height = "auto";
    altCorpomenusx = document.getElementById("corpomenusx").offsetHeight;
  }
  if(document.getElementById("corpomenudx") != null) {
    document.getElementById("corpomenudx").style.height = "auto";
    altCorpomenudx = document.getElementById("corpomenudx").offsetHeight;
  }
  var max = 0;
  if(max < altCorpocentro)
    max = altCorpocentro;
  if(max < altCorpomenusx)
    max = altCorpomenusx;
  if(max < altCorpomenudx)
    max = altCorpomenudx;
  if(document.getElementById("corpocentro") != null) {
    document.getElementById("corpocentro").style.height = (max) + "px";
  }
  if(document.getElementById("corpomenusx") != null) {
    document.getElementById("corpomenusx").style.height = (max+margineSicurezza) + "px";
  }
  if(document.getElementById("corpomenudx") != null) {
    document.getElementById("corpomenudx").style.height = (max+margineSicurezza) + "px";
  }
  document.getElementById("corpo").style.height = (max+margineSicurezza+margintop) + "px";
  
  shadowAdjust();
}



// Ombra laterale - Inizializzazione
function shadow() {
  var headerRef = document.getElementById("header");
  var corpoRef = document.getElementById("corpo");
  
  var angoloSup = document.createElement("div");
  var lato = document.createElement("div");
  var bottom = document.createElement("img");
  
  /*var margineLeft = headerRef.style.marginLeft - 9;*/
  var margineLeft = -475 -9;
  var altezzaHeadCorpo = headerRef.offsetHeight + corpoRef.offsetHeight;
  
  with (angoloSup) {
    id = "shadowTop";
  	style.left = "50%";
  	style.marginLeft = margineLeft + "px";
  	style.top = headerRef.offsetTop + "px";
  	style.height = "9px";
  	style.width = "9px";
  	style.backgroundImage = "url(./imgs/shadow_BKG_top.gif)";
  	style.position = "absolute";
  	//style.zIndex = "300";
  }
  
  with (lato) {
    id = "shadowSide";
  	style.left = "50%";
  	style.marginLeft = margineLeft + "px";
  	style.top = (headerRef.offsetTop + 9) + "px";
  	style.height = (altezzaHeadCorpo - 9) + "px";
  	style.width = "9px";
  	style.backgroundImage = "url(./imgs/shadow_BKG_center.gif)";
  	style.position = "absolute";
  	//style.zIndex = "300";
  }
  
  with (bottom) {
    id = "shadowBottom";
  	style.left = "50%";
  	style.marginLeft = margineLeft + "px";
  	style.top = (headerRef.offsetTop + altezzaHeadCorpo) + "px";
  	style.height = "9px";
  	style.width = "959px";
	src = "./imgs/shadow_BKG_bottom.gif";
	alt = "";
  	style.position = "absolute";
  	//style.zIndex = "300";
  }

  document.body.appendChild(angoloSup);
  document.body.appendChild(lato);
  document.body.appendChild(bottom);
  
}

// Ombra Laterale - Aggiornamento - richiamata nella settaAltezza()
function shadowAdjust() {
  var headerRef = document.getElementById("header");
  var corpoRef = document.getElementById("corpo");
  var angoloSup = document.getElementById("shadowTop");
  var lato = document.getElementById("shadowSide");
  var bottom = document.getElementById("shadowBottom");
  
  var margineLeft = -475 -9;
  var altezzaHeadCorpo = headerRef.offsetHeight + corpoRef.offsetHeight;
  
  with (angoloSup) {
  	style.top = headerRef.offsetTop + "px";
  }
  
  with (lato) {
  	style.top = (headerRef.offsetTop + 9) + "px";
  	style.height = (altezzaHeadCorpo - 9) + "px";
  }
  
  with (bottom) {
  	style.top = (headerRef.offsetTop + altezzaHeadCorpo) + "px";
  } 
}


// Box laterale
function disegnaBox(num) {
  var headerRef = document.getElementById("header");
  var paddingColonna = 25; // distanza in pixel tra header ed inizio della colonna
  var altezzaVoceMenu = 29; // altezza di una voce del menu' laterale
  var sfasamentoX = -9; // numero di pixel di sfasamento (effetto fuori dalla colonna)
  var sfasamentoY = 30; // numero di pixel tra l'ultima voce di menu' ed il box
  
  var posizioneY = headerRef.offsetTop + headerRef.offsetHeight + paddingColonna + (num*altezzaVoceMenu) + sfasamentoY;
  var posizioneX = headerRef.offsetLeft + sfasamentoX;
  
  var nodoDiv = document.createElement("div");
  var shadowTop = document.createElement("img");
  var shadowLato = document.createElement("div");
  var shadowBottom = document.createElement("img");
  
  with(nodoDiv) {
  	id = "callcenter";
  	style.zIndex = 100;
  	style.position = "absolute";
  	style.top = posizioneY + "px";
  	//style.left = posizioneX + "px";
  	style.left = "50%";
  	style.marginLeft = (-475 - 9) + "px";
  	//style.width = "219 -15 -15 px";
  	style.width = "189px";
  	style.padding = "15px";
  	style.backgroundColor = "#FFFFFF";
  	style.color = "#737373";
  }
  
  // aggiungere qui il contenuto del box
  var tmp = document.createElement("img");
  tmp.src = "./imgs/callcenter_altredomande.gif";
  tmp.alt = "Altre domande?";
  nodoDiv.appendChild(tmp);
  
  nodoDiv.appendChild( document.createElement("br") );
  
  nodoDiv.appendChild( document.createTextNode("Chiama il Call Center") );
  
  nodoDiv.appendChild( document.createElement("br") );
  
  tmp = document.createElement("span");
  tmp.style.fontSize = "20px";
  tmp.style.fontWeight = "bold";
  tmp.appendChild( document.createTextNode("800.66.22.11") );
  nodoDiv.appendChild(tmp);
  
   nodoDiv.appendChild( document.createElement("br") );
  
  nodoDiv.appendChild( document.createTextNode("Per cellulari o dall'estero") );
  
  nodoDiv.appendChild( document.createElement("br") );
  
  tmp = document.createElement("span");
  tmp.style.fontSize = "16px";
  tmp.style.fontWeight = "bold";
  tmp.appendChild( document.createTextNode("010.57.57.992") );
  nodoDiv.appendChild(tmp);
  
  
  
  
  nodoDiv.appendChild( document.createElement("br") );
  
  nodoDiv.appendChild( document.createTextNode("luned́ - venerd́: 8.00 - 20.00") );
  
  nodoDiv.appendChild( document.createElement("br") );
  
  nodoDiv.appendChild( document.createTextNode("sabato: 9.00 - 14.00") );
  
  nodoDiv.appendChild( document.createElement("br") );
  
  nodoDiv.appendChild( document.createTextNode("oppure ") );
  
  tmp = document.createElement("a");
  tmp.href = "https://portal.contoconto.it/ContoOnLine/faces/jsp/Contatti/Contatti.jsp";
  tmp.appendChild( document.createTextNode("scrivici") );
  nodoDiv.appendChild(tmp);
  
  document.body.appendChild(nodoDiv);
  
  var callcenterRef = document.getElementById("callcenter");
  
  with(shadowTop) {
  	src = "./imgs/shadow_BKG_top.gif";
  	alt = "";
  	style.zIndex = 100;
  	style.position = "absolute";
  	style.top = callcenterRef.offsetTop + "px";
  	//style.left = (callcenterRef.offsetLeft - 9) + "px";
  	style.left = "50%";
  	style.marginLeft = (-475 - 9 -9) + "px";
  	style.border = "none";
  }
  
  with(shadowLato) {
  	style.backgroundImage = "url(./imgs/shadow_BKG_center.gif)";
  	style.zIndex = 100;
  	style.position = "absolute";
  	style.top = (callcenterRef.offsetTop + 9) + "px";
  	style.left = "50%";
  	style.marginLeft = (-475 - 9 -9) + "px";
  	style.border = "none";
  	style.width = "9px";
  	style.height = (callcenterRef.offsetHeight - 9) + "px";
  }
  
  with(shadowBottom) {
  	src = "./imgs/shadow_callcenter_bottom.gif";
  	alt = "";
  	style.zIndex = 100;
  	style.position = "absolute";
  	style.top = (callcenterRef.offsetTop + callcenterRef.offsetHeight) + "px";
  	style.left = "50%";
  	style.marginLeft = (-475 - 9 -9) + "px";
  	style.border = "none";
  }
  
  document.body.appendChild(shadowTop);
  document.body.appendChild(shadowLato);
  document.body.appendChild(shadowBottom);
}

