﻿function getBrowser(){
  var ievs = (/MSIE (\d+\.\d+);/.test(navigator.userAgent)), iev;
  if(ievs){
    var iev = Number(RegExp.$1);
    switch(iev){
      case 6:
      case 7:
      case 8:
      case 9:
        return "Internet Explorer " + iev;
        break;
      default:
        return "Sconosciuto";
    }
  }
}
function GetResolution(){
	var altezza = window.screen.height;
	var larghezza = window.screen.width;
	return larghezza + "x" + altezza;
}	
function GetValForResolution(Val800x600, Val){
	if(GetResolution() == "800x600"){return Val800x600;}
	else{return Val;}
}
function getElement(id){
	if(!id){return false;}
	if(document.getElementById(id)){return (document.getElementById(id));}
	else if(document.all){return (document.all[id]);}
}
function getParentElement(id){
	var elem = window.parent.document.getElementById(id);
	if(elem){return elem;}
	return false;
}
function getSiteCenter(){
	var h = document.body.offsetHeight;
	var l = document.body.offsetWidth;
	var center = {top: 0, left: 0};
  center.top = h/2;
  center.left = l/2;
  return center;
}		
function getPos(elem){
	var c={x: 0, y: 0, left:0, top:0};
  switch(getBrowser()){
    case 'Internet Explorer 6':
    case 'Internet Explorer 7':
    //case 'Internet Explorer 8':
    //case 'Internet Explorer 9':
    	while (elem) {
    		c.x += elem.offsetLeft;
    		c.y += elem.offsetTop;
    		elem = elem.offsetParent;
    	}      
      break;
    default:
   		c.x = elem.offsetLeft;
   		c.y = elem.offsetTop;
  }  
  c.left = c.x;
  c.top = c.y;
	return c;
}
function getPageDim(){
  var r={width: 0, height: 0, scroll: 0};
  r.width = (window.innerWidth)?window.innerWidth:document.documentElement.clientWidth; 
  r.height = (window.innerHeight)?window.innerHeight:document.documentElement.clientHeight;
  r.scrollY = (window.scrollY)?window.scrollY:document.documentElement.scrollTop;
  return r;
}
function SetFontSize(id, Val800x600, Val){
	var Ogg = getElement(id);
	if(Ogg){Ogg.style.fontSize = GetValForResolution(Val800x600, Val);}
}
function formatHtml(param){
  if(param){
    param = param.replace(/simboloapice/g, "'");
    param = param.replace(/simbolovirgolette/g, '"');
    param = param.replace(/simboloacapo/g, '\n');
  }
	return param;
}	
function redirect(pagina, newWindow){
	pagina = formatHtml(pagina);
	if(newWindow){window.open(pagina);}
	else{location.href = pagina;}		
}
function setPointer(obj, pointer){
	obj = getElement(obj);
	if(!obj){return false;}
	switch(pointer) {
		case 'over':
			pointer = 'pointer';
		break;
		case 'out':
			pointer = 'default';
		break;
	}
	obj.style.cursor = pointer;
}	
function setDocumentPointer(pointer){
	switch(pointer) {
		case 'over':
			pointer = 'pointer';
		break;
		case 'out':
			pointer = 'default';
		break;
	}
	document.body.style.cursor = pointer;
}	
function mouseOverPointer(obj){setPointer(obj, 'over');}	
function mouseOutPointer(obj){setPointer(obj, 'default');}	
function mouseOverDocPointer(){setDocumentPointer('over');}	
function mouseOutDocPointer(){setDocumentPointer('default');}
function setColor(id, textColor){ 
	var Ogg = getElement(id);
	if(Ogg){Ogg.style.color= textColor;}
}	
function setStyle(obj,color,backgroundColor,pointer,borderColor){	
	if(obj){
		obj = $(obj);
    if(!obj) return false;
		if(color) obj.style.color = color;
    if(backgroundColor) obj.style.backgroundColor = backgroundColor;
		if(pointer) obj.style.cursor = pointer;
    if(borderColor) obj.style.border = "1px solid " + borderColor;
	}
}	
function setBtnOutStyle(obj,color){
	if(obj){
		obj = $(obj);
		obj.style.backgroundColor = obj.parentNode.style.backgroundColor;
		obj.style.color = color;
		obj.style.cursor = 'default';
	}
}
function submitFormParam(id, paramID, paramValue){
	document.getElementById(paramID).value=paramValue;
	document.getElementById(id).submit();
}
function submitForm(id){document.getElementById(id).submit();}	
function submitFormTimeOut(id, timeout){
  setTimeout("document.getElementById('" + id + "').submit()", timeout);
}
function submitFormAccount(id){
	document.getElementById(id).azione.value = "";
	document.getElementById(id).submit();
}	
function onChangePaese(rif){
  $('PaeseSped').value = rif.value;
  var aValue = rif.value.split('|');
  if($$('tipoCliente') == 'Azienda') $('CodNazText').value = aValue[1];
  $('CodNaz').value = aValue[1];
}
function stampa(){window.print();}
function stampaSchedaProdotto(){
  var elem, box = 'schedaProdotto';
  elem = $(box + '_containerSchedaTecnica');
  if(elem) elem.style.display = 'block';
  elem = $(box + '_containerAttributi');
  if(elem) elem.style.display = 'block';
  elem = $(box + '_containerCorrelati');
  if(elem) elem.style.display = 'none';
  elem = $('schedaProdotto_miniatura_1');
  if(elem){ 
    //var nMarginLeft = elem.style.marginLeft;
    elem.style.marginLeft = '0';
  }
  window.print();
  //if(elem) elem.style.marginLeft = nMarginLeft;
}		
function confermaOrdineDemo(){alert('Versione DEMO - Conferma ordine avvenuta');location.href = 'index.php';}	
function goBack(){history.back();}	
function refresh(){location.reload();}	
function submitFormLogin(page){
	document.forms.login.azione.value="process";
	document.forms.login.page.value=page;
	document.forms.login.submit();
}	
function eurofix(string){return string.replace(/ €/g, "+%80");}
function mostra(id){getElement(id).style.display = 'block';}	
function nascondi(id){getElement(id).style.display = 'none';}	
function mostraNascondiDettaglioOrdine(id){
	if(document.getElementById('ordine' + id).style.display == 'block'){
    nascondi('ordine' + id);
		nascondi('Chiudi' + id);
		mostra('Apri' + id);
	} else {
		mostra('ordine' + id);
		nascondi('Apri' + id);
		mostra('Chiudi' + id);
	}
}		
function showInfoBox(text, txtCol, bgCol){
  var width = 200;
  if(!txtCol) txtCol = "#666666";
  if(!bgCol) bgCol = "#FFFFD1";
	var d = new div('InfoBox');
  d.content(text);
 	d.border("1px", "solid", "silver");
	d.padding("30px");
  d.show();
	var oPage = getPageDim();
  d.width(width);  
  x = (oPage.width - width)/ 2 + "px"; 
  y = (oPage.height - d.getHeight())/ 2 + oPage.scrollY + "px";
  d.locate(x, y);
  d.zindex(100);
  d.color(txtCol);
	d.backgroundColor(bgCol);
}
function aggiungiAlCarrello(id, paramID, codArt, msgSingolare, msgPlurale, txtcolor, bgcolor, cartID, nLottoVen, lLottoVenMul, aMsg, lInCart){
  var oQta = $("qta" + codArt);
  if(!gestioneLotto(oQta, nLottoVen, lLottoVenMul, aMsg, lInCart)) return false;
  $('azione_' + codArt).value = 'addProdotto';
  $('pulsante_' + codArt).value = 'acquista';
  mostra('infoBox');
  var qta = oQta.value;
  var descr = qta + " ";
	if(qta > 1){descr += msgPlurale;}
	else{descr += msgSingolare;}
	var elem = getElement("infoBox_testo");
  if(elem){
		elem.innerHTML = formatHtml(descr);
		elem = getElement("infoBox");
		elem.style.color = txtcolor;
		elem.style.backgroundColor = bgcolor;
		var scrollY = (window.scrollY)?window.scrollY:document.documentElement.scrollTop;
		if(scrollY !== 0){elem.style.marginTop = scrollY + 'px';}
	  setTimeout("submitFormParam('" + id + "','" + paramID + "','" + codArt + "')", 10);
  }
}
function gestioneLotto(oQta, nLottoVen, lLottoVenMul, aMsg, lInCart){
  var cMsg = '', nNewQta;
  if(nLottoVen <= 1 || (oQta.value % nLottoVen) == 0 || (lInCart == 'true' && lLottoVenMul == 'false')) return true;
  if(oQta.value < nLottoVen){
    nNewQta = nLottoVen;
    cMsg = aMsg['minimo'];
  } else {
    if(lLottoVenMul == 'false'){ 
      return true;
    } else {
      nNewQta = Math.ceil(oQta.value / nLottoVen) * nLottoVen;
      cMsg = aMsg['multiplo'];
    }
  }
  cMsg = cMsg.replace('[NewQta]', nNewQta);
  if(confirm(cMsg)){
    oQta.value = nNewQta;
    return true;  
  }
  return false;  
}
function salvaDatiCliente(id, paramID, paramValue, descrizione, txtcolor, bgcolor){
	  mostra('infoBox');
		getElement("infoBox_testo").innerHTML = formatHtml(descrizione);
		var elem = getElement("infoBox");
		elem.style.color = txtcolor;
		elem.style.backgroundColor = bgcolor;
	  setTimeout("submitFormParam('" + id + "','" + paramID + "','" + paramValue + "')", 500);
}
function loginPressEnter(field, e, page){
	var key  = (window.event) ? event.keyCode : e.keyCode, enter = 13;
	if(key == enter){submitFormLogin(page);}
}
function rollover(id){
	if(!getElement(id)) return false; 
  var immagine = getElement(id).src;
  if(!immagine) return false; 
	if(immagine.substr(immagine.length - 8, 4) == 'Over'){immagine = immagine.slice(0, immagine.length - 8) + immagine.slice(immagine.length - 4);}     else {
		immagine = document.getElementById(id).src;
		immagineNormale = immagine.split('/');
		immagineNormale = immagineNormale[immagineNormale.length-1];
		immagineNormale = immagineNormale.slice(0, immagineNormale.length - 4);
		immagineOver = immagineNormale + 'Over';
		immagine = immagine.replace(immagineNormale, immagineOver);
	}
	document.getElementById(id).src = immagine;
}
function schedaTecnica(tipo){
	if(tipo == 'completa'){
		nascondi('schedaProdotto_btnSegueContainer');
    var elem = getElement('schedaCompleta');
    if(elem){ 
      if(getBrowser() !== 'Internet Explorer 6') elem.style.maxHeight = 'none';
      elem.style.height = 'auto';
    }
		mostra('schedaProdotto_btnChiudiContainer');
	} else if(tipo == 'parziale'){
    var elem = getElement('schedaCompleta');
    if(elem){ 
      if(getBrowser() !== 'Internet Explorer 6') elem.style.maxHeight = '150px';
      else{ 
        if(elem.scrollHeight > 149) elem.style.height = '150px';
        else elem.style.height = 'auto';
      }
    }
		nascondi('schedaProdotto_btnChiudiContainer');
		mostra('schedaProdotto_btnSegueContainer');				
	}
}	
function rolloverValutazione(id){		
	var classe = id.slice(0, id.length - 1);
	var indice = id.slice(id.length - 1);
	var immagine = document.getElementById(classe + indice).src;
	if(immagine.substr(immagine.length - 8, 4) == 'Over'){
		immagine = immagine.slice(0, immagine.length - 8) + immagine.slice(immagine.length - 4);
		for(i=1; i<=indice; i++){document.getElementById(classe + i).src = immagine;}
	} else {
		for(i=1; i<=indice; i++){ 
			immagine = document.getElementById(classe + i).src;
			immagineNormale = immagine.split('/');
			immagineNormale = immagineNormale[immagineNormale.length-1];
			immagineNormale = immagineNormale.slice(0, immagineNormale.length - 4);
			immagineOver = immagineNormale + 'Over';
			immagine = immagine.replace(immagineNormale, immagineOver);
			document.getElementById(classe + i).src = immagine;
		}
	}
}	
function setValutazione(id, valutazione, descrizione, azione, txtcolor, bgcolor){
	var form = document.forms.schedaProdotto_addCart;
	if(form.voto){form.voto.value = valutazione;}
	if(form.azione){form.azione.value = azione;}
  mostraMessaggio(descrizione, txtcolor, bgcolor);
	setTimeout("submitForm('schedaProdotto_addCart')", 1000);
}	
function eliminaValutazione(id, descrizione, azione, txtcolor, bgcolor){
	document.forms.schedaProdotto_addCart.azione.value = azione;
  mostraMessaggio(descrizione, txtcolor, bgcolor);
	setTimeout("submitForm('schedaProdotto_addCart')", 1000);
}	
function gestionePreferiti(id, descrizione, azione, txtcolor, bgcolor, fcCodArt){
  $('azione_' + fcCodArt).value = azione;
  mostraMessaggio(descrizione, txtcolor, bgcolor);
	setTimeout("submitForm('schedaProdotto_addCart')", 1000);
}
function gestioneConfronti(id, descrizione, azione, txtcolor, bgcolor, cartID, fcCodArt){
  if(cartID){var cart = getElement(cartID);} 
  else{var cart = document.forms.schedaProdotto_addCart;} 
  $('pulsante_' + fcCodArt).value = 'confronto';
  if(azione) setParam('azione_' + fcCodArt, azione);
  if(!descrizione) descrizione = cart.messaggio.value;
  mostraMessaggio(descrizione, txtcolor, bgcolor);
  setTimeout("submitForm('" + cart.id + "')", 1000);
}
function gestioneAvvisoDispo(id, descrizione, azione, txtcolor, bgcolor, fcCodArt){
	$('azione_' + fcCodArt).value = azione;
  mostraMessaggio(descrizione, txtcolor, bgcolor);
	setTimeout("submitForm('schedaProdotto_addCart')", 1000);
}
function mostraMessaggio(descrizione, txtcolor, bgcolor){
	if(!descrizione || descrizione == ''){return false;}
	mostra('infoBox');
	var elem = getElement("infoBox");
	if(elem){
    var scrollY = (window.scrollY)?window.scrollY:document.documentElement.scrollTop;
    elem.style.top = elem.offsetTop + scrollY + 'px';
		elem.style.color = txtcolor;
		elem.style.backgroundColor = bgcolor;
	}	
	//document.getElementById("infoBox_testo").innerHTML = formatHtml(descrizione);
  impostaMessaggio(descrizione);	
}
function impostaMessaggio(descrizione){
  var oMsg = $("infoBox_testo");
  if(!oMsg) return false;
	oMsg.innerHTML = formatHtml(descrizione);
}
function nascondiMessaggio(ritardo){
  if(!ritardo) var ritardo = 1000;
  //alert(ritardo);
  setTimeout("nascondi('infoBox')", ritardo);
}
function centerImage(containerID){
  var container = getElement(containerID);
  if(container){
    var aImg = container.getElementsByTagName('IMG'), marginTop = 0;
    for(var i = 0; i < aImg.length; i++){
      marginTop = (container.offsetHeight - aImg[i].offsetHeight) / 2;	
      aImg[i].style.marginTop = marginTop + 'px';
    }
  }
}
function adatta(immagine, contenitore){
	immagine.style.margin = 0;
	immagine.style.width = 550 + "px";
	immagine.style.height = 350 + "px";
}	
function aspectRatio(altezza, larghezza, w, h){
  if(w <= 550 && h <= 550 && w >= 100 && h >= 100){
    var width = w, height = h;  
  } else {
  	var ratio = w/h, width = larghezza, height = width / ratio;
  	if(height > altezza){
  		height = altezza;
  		width = height * ratio;
  	}
  }
	return { "altezza":height, "larghezza":width };
}	
function getImgFromMiniatura(miniatura){
  img = miniatura.replace('/thumbnails', '');
  var name = img.substr(0, img.lastIndexOf('_'));
  var ext = _aImmagini[basename(name).toLowerCase()]['ext'];
  return name + '.' + ext;
}
function replaceSizeMiniatura(miniatura, width, height){
  var aName = miniatura.split('_');
  var name = '';
  for(var $i=0; $i < aName.length - 1;$i++) name += aName[$i] + '_';
  var ext = miniatura.split('.');
  ext = ext[ext.length - 1];
  return name + width + 'x' + height + '.' + ext;
}
function getNomeMiniatura(img, width, height){
  var name = img.substr(0, img.lastIndexOf('.'));
  if(width && height) name += '_' + width + 'x' + height;
  name += '.jpg'; 
  return name;
}
var _aImmagini;
function creaArrayImmagini(imgName, w, h){
  _aImmagini = Array();
  addArrayImmagini(basename(imgName), w, h);
}
function addArrayImmagini(imgName, w, h){
  var aInfo = Array();
  aInfo['w'] = w;
  aInfo['h'] = h; 
  aInfo['ext'] = imgName.substr(imgName.lastIndexOf('.') + 1);
  _aImmagini[basename(imgName, true).toLowerCase()] = aInfo;  
}
function basename(url, noext){
  if(url.lastIndexOf('/') != -1) url = url.substr(url.lastIndexOf('/') + 1);
  if(noext && url.lastIndexOf('.') != -1) url = url.substr(0, url.lastIndexOf('.'));
  return url;
}
function zoomImmagineProdotto(imgID){
  if(!imgID) elem = $('schedaProdotto_immagine');
  else elem = $(imgID);
  if(!elem) return false;
  var immagine = getImgFromMiniatura(elem.src);
  var w = _aImmagini[basename(immagine, true).toLowerCase()]['w'];
  var h = _aImmagini[basename(immagine, true).toLowerCase()]['h'];

  if(getElement('fullImage_Container')){return false;}
	var container = document.createElement('DIV');
	var closeBtn = document.createElement('DIV');
	var fullImage = document.createElement('IMG');
	var larghezza = 550, altezza = 550;
	fullImage.style.margin = 0;
	fullImage.style.padding = 0;
	fullImage.style.top = 0;
	fullImage.style.left = 0;
  fullImage.src = immagine;
  
	if(container){
		container.id = 'fullImage_Container';
		container.style.position = 'absolute';
		container.style.width = 0 + "px";
		container.style.height = 0 + "px";
		var scrollY = (window.scrollY)?window.scrollY:document.documentElement.scrollTop;
		container.style.top = 195 + scrollY + "px";
		container.style.border = "2px solid #000";
		container.style.backgroundColor = '#FFF';
		document.body.appendChild(container);
		container.style.left = document.body.offsetWidth / 2 - container.offsetWidth / 2 + "px";		
    
    fullImage.onload = function(){
			aDim = aspectRatio(altezza, larghezza, w, h);
			fullImage.style.width = aDim.larghezza + "px";
			fullImage.style.height = aDim.altezza + "px";
			container.style.height = aDim.altezza + "px";
			container.style.width = aDim.larghezza + "px";
			container.style.left = document.body.offsetWidth / 2 - container.offsetWidth / 2 + "px";		
		};
		container.appendChild(fullImage);		
		// patch		
		fullImage.style.margin = 0;
     
		aDim = aspectRatio(altezza, larghezza, w, h);
		fullImage.style.width = aDim.larghezza + "px";
		fullImage.style.height = aDim.altezza + "px";
		container.style.height = aDim.altezza + "px";
		container.style.width = aDim.larghezza + "px";
		container.style.left = document.body.offsetWidth / 2 - container.offsetWidth / 2 + "px";		
		// end patch			
		if(fullImage.offsetWidth > container.offsetWidth || fullImage.offsetHeight > container.offsetHeight){container.style.overflow = 'scroll';}
		closeBtn.innerHTML = "x";
		closeBtn.style.position = 'absolute';
		var width = 20;
		closeBtn.style.top = container.offsetTop + 3 + "px"; 
		closeBtn.style.left = container.offsetLeft + container.offsetWidth - width - 3 + "px";
		closeBtn.style.width = width + 'px';
		closeBtn.style.height = '14px'; 
		closeBtn.style.color = '#fff';
		closeBtn.style.backgroundColor = '#000';
		closeBtn.style.textAlign = 'center';
		closeBtn.style.font = 'bold 11px Verdana, Arial, sans-serif';
		closeBtn.onclick = function(){ document.body.removeChild(container); document.body.removeChild(closeBtn); setPointer(this.id, 'out');};
		closeBtn.onmouseover = function(){setPointer(this.id, 'over');};
		closeBtn.onmouseout = function(){setPointer(this.id, 'out');}; 
		container.onclick = function(){document.body.removeChild(container); document.body.removeChild(closeBtn); setPointer(this.id, 'out');};
		container.onmouseover = function(){setPointer(this.id, 'over');};
		container.onmouseout = function(){setPointer(this.id, 'out');}; 
		document.body.appendChild(closeBtn);
	}
	return true;
}
function switchImmagine(id, width, height, colN, colE){
  elem = getElement('schedaProdotto_immagine');
  if(!elem) return false   
  miniatura = getElement(id);
  if(!miniatura) return false
    
  imgNormale = replaceSizeMiniatura(miniatura.src, width, height);
  elem.src = imgNormale;

  contenitoreMiniature = getElement('schedaProdotto_contenitoreMiniature');
  if(!contenitoreMiniature) return false
  aElems = contenitoreMiniature.childNodes;
  for(i=0;i<aElems.length;i++){
    aElems[i].style.borderColor = colN;
  } 
  miniatura.style.borderColor = colE;
}
function setStylesheet(){
	if(GetResolution() == "800x600"){document.getElementsByTagName("link")[1].disabled = false;}
	else{document.getElementsByTagName("link")[1].disabled = true;}
}
function offsetTopIE(obj){
	var rect = obj.getBoundingClientRect();
	return rect.top;
}
function offsetLeftIE(obj){
	var rect = obj.getBoundingClientRect();
	return rect.left;
}
function gestioneAttributi(method, articolo){
  var titolo = $('schedaProdotto_titoloAttributi');
  if(!titolo){return false;}
  var container = $('schedaProdotto_containerAttributi');
  if(!container){return false;}
  titolo.style.display = 'none';
  container.style.display = 'none';
  container.innerHTML = '';
  
  var elem = getElement('variante');
  if(elem){ajaxGet(method + "?variante=" + elem.value + "&articolo=" + articolo, visualizzaAttributi, titolo, container);}
}
function visualizzaAttributi(resp, titolo, container){  
  if(resp !== 'null'){    
    if(titolo) titolo.style.display = 'block';
    container.innerHTML = formatHtml(resp);
    var elem = $('schedaProdotto_activeFolder');
    if(elem){ 
      var aParams = elem.title.split('|');
      if(aParams[0] == 'vuoto' || aParams[0] == 'Correlati') elem.title = 'Attributi|' + titolo.id + '|' + container.id + '|schedaProdotto';
      setFolder(elem.title);
    }
  }
  var afterAttributiCustom = window['afterAttributiCustom'];
  if(typeof(afterAttributiCustom) == 'function'){afterAttributiCustom.apply(this, arguments);}
}
function gestioneCorrelati(method, articolo){
  var titolo = $('schedaProdotto_titoloCorrelati');
  if(!titolo){return false;}
  var container = $('schedaProdotto_containerCorrelati');
  if(!container){return false;}
  
  titolo.style.display = 'none';
  container.style.display = 'none';
  container.innerHTML = '';
  
  var elem = getElement('variante');
  if(elem){ajaxGet(method + "?variante=" + elem.value + "&articolo=" + articolo, visualizzaCorrelati, titolo, container);}
}
function visualizzaCorrelati(resp, titolo, container){
  if(resp !== 'null'){    
    titolo.style.display = 'block';
    container.innerHTML = formatHtml(resp);

    var elem = $('schedaProdotto_activeFolder');
    if(elem){ 
      var aParams = elem.title.split('|');
      if(aParams[0] == 'vuoto') elem.title = 'Correlati|' + titolo.id + '|' + container.id + '|schedaProdotto';
      setFolder(elem.title);
    }
  }
  var afterCorrelatiCustom = window['afterCorrelatiCustom'];
  if(typeof(afterCorrelatiCustom) == 'function'){afterCorrelatiCustom.apply(this, arguments);}
}  
function setMarca(marca){
  var elem = getElement('marcheMarca');
  if(elem) elem.value = marca;
}
function setParam(id, value){
	var oParam = getElement(id); 
	if(oParam){oParam.value = value;}
}
_SottocategorieAperte = ''; 
function nascondiSottocategorie(CodCat){
  if(!CodCat) CodCat = _SottocategorieAperte;
  if(CodCat != ''){
    catbox = getElement('categorie_boxSottocategorie_' + CodCat);
    if(catbox){
      catbox.style.display = 'none';
      _SottocategorieAperte = '';
    }
    catbox = getElement('boxCategoria_' + CodCat);
    if(catbox){
      catbox.style.backgroundColor = catbox.parentNode.style.backgroundColor;
    }
  }  
}
function mostraSottocategorie(CodCat, rif, borderColor, siteArea){
  catbox = getElement('categorie_boxSottocategorie_' + CodCat);
  if(catbox){
    catbox.style.display = 'block';
    _SottocategorieAperte = CodCat;
    if(rif){
      catbox.style.position = 'absolute';
      var rifPos = getPos(rif);
      catbox.style.top = rifPos.y - 1 + 'px';
      if(siteArea == 'Colonna sinistra') catbox.style.left = rifPos.x + 183 + 'px';
      else catbox.style.left = rifPos.x - 190 + 'px';
      catbox.style.border = '1px solid ' + borderColor;
      catbox.style.zIndex = '1000';
      catbox.style.padding = '0';
    }
  }
}
function categoriaOver(CodCat, bgCol){
  var catbox = getElement('boxCategoria_' + CodCat);
  var sottocatbox = getElement('categorie_boxSottocategorie_' + CodCat);
  if(catbox){
    catbox.style.cursor = 'pointer';
    catbox.style.backgroundColor = bgCol;
  }
}
function categoriaOut(CodCat){
  var catbox = getElement('boxCategoria_' + CodCat);
  var sottocatbox = getElement('categorie_boxSottocategorie_' + CodCat);
  if(catbox){
    catbox.style.cursor = 'default';
    catbox.style.backgroundColor = catbox.parentNode.style.backgroundColor;
  }
}
function getExtension(filename){
  return filename.substr(filename.lastIndexOf('.') + 1);
}
function setFolder(cParams){
  if(cParams == 'vuoto') return false;
  var aParams = cParams.split('|');
  openFolder($(aParams[1]), aParams[2], aParams[3]);
}
function openFolder(rifTitolo, idContenuto, box){
  var rifContenitoreTitoliFolders = $(box + '_contenitoreTitoliFolders');
  if(!rifContenitoreTitoliFolders) return false;
  var aElems = Array();
  // chiudo tutti i folder
  aElems = rifContenitoreTitoliFolders.getElementsByTagName('DIV');
  for(var elem in aElems){
    if(aElems[elem].id){
      aElems[elem].className = box + '_titoliFolders';
    }
  }
  var rifContenitoreContenutiFolders = $(box + '_contenitoreContenutiFolders');
  if(!rifContenitoreContenutiFolders) return false;
  aElems = rifContenitoreContenutiFolders.getElementsByTagName('DIV');
  for(var elem in aElems){
    if(aElems[elem] && aElems[elem].id){ 
      aElems[elem].className = box + '_contenutiFolders';
      aElems[elem].style.display = 'none';
    }
  }

  if(!rifTitolo) return false;
  var rifContenuto = $(idContenuto); 
  if(!rifContenuto) return false;
  // Apro folder selezionato
  if(rifTitolo) rifTitolo.className = box + '_titoloFolderAperto';
  if(rifContenuto){
    rifContenuto.className = box + '_contenutoFolderAperto';
    rifContenuto.style.display = 'block';
  }
}
function getMousePosition(e){
	if(!e) e = window.event;

	var vDoc=(document.documentElement && document.documentElement.scrollTop)?document.documentElement:document.body;
	var aPos = new Array();
  aPos['x'] = (e.pageX)?e.pageX:e.clientX+vDoc.scrollLeft;
	aPos['y'] = (e.pageY)?e.pageY:e.clientY+vDoc.scrollTop;
  return aPos;
}
function showPopup(id, html, e, containerID){
	if(!getElement(id)){
    var aPos = getMousePosition(e);
		var d = new div(id);	
    if(containerID) d.container(containerID);
		d.locate(aPos['x'] + 'px', aPos['y'] + 15 + 'px');
    d.zindex(100);
		d.border("1px", "solid", "silver");
		d.padding("5px");
    d.color("#666666");
		d.backgroundColor("#FFFFD1");
		d.content(formatHtml(html));
		d.show();
    setTimeout('hidePopup("' + id + '")', 1000)
	}
}
function hidePopup(id){
	var box = $(id)
	if(box){box.parentNode.removeChild(box);}
}
function show(id){
  var oElem = $(id);
  if(oElem) oElem.style.display = 'block';
}
function hide(id){
  var oElem = getElement(id);
  if(oElem) oElem.style.display = 'none';
}
function showInput(id){
  var oElem = $(id);
  if(oElem) oElem.style.display = 'block';
  oElem = $(id + '_label');
  if(oElem) oElem.style.display = 'block';
}
function hideInput(id){
  var oElem = $(id);
  if(oElem) oElem.style.display = 'none';
  oElem = $(id + '_label');
  if(oElem) oElem.style.display = 'none';
}
function add2selectXML(id, oXml){
  var oList = $(id);
  if(oList){ 
    var iLen = oList.options.length;
    var oRoot = oXml.documentElement;
    var cContenuti = oRoot.getElementsByTagName("option");
    var oChild = cContenuti[0].firstChild;
    var sValore, sDescrizione;
    do{
      switch(oChild.tagName){
        case "Valore": 
          sValore = oChild.text;
        break;
        case "Descrizione":
          sDescrizione = oChild.text;
        break;
      }
    } while(oChild = oChild.nextSibling);
    if(sDescrizione){oList.options[iLen] = new Option(sDescrizione, sValore);}
    else{oList.options[iLen] = new Option(sValore, sValore);}
  }
}
function modOptionXML(id, oXml){
  var oList = $(id);
  if(oList){ 
    var oRoot = oXml.documentElement;
    var cContenuti = oRoot.getElementsByTagName("option");
    var oChild = cContenuti[0].firstChild;
    var sValore, sDescrizione;
    do{
      switch(oChild.tagName){
        case "Valore": 
          sValore = oChild.text;
        break;
        case "Descrizione":
          sDescrizione = oChild.text;
        break;
      }
    } while(oChild = oChild.nextSibling);
    if(sDescrizione){oList.options[oList.selectedIndex].text = sDescrizione;}
    else{oList.options[oList.selectedIndex].text = sValore;}
    oList.options[oList.selectedIndex].value = sValore;
  }
}
function setTestoRisMin(){
  var altezza = window.screen.height;
	var larghezza = window.screen.width;
  if(larghezza >= 1024 && altezza >= 768){nascondi('Footer_RisoluzioneMinima');}
}
function evidenziaRiga(rif, evento, colore, noPointer){
  if(evento == 'over'){ 
    if(noPointer != true){setDocumentPointer('over');}
    if(rif){rif.style.backgroundColor = colore;}
  }
  if(evento == 'out'){
    if(noPointer != true){setDocumentPointer('out');}
    if(rif){rif.style.backgroundColor = rif.parentNode.style.backgroundColor;}
  }
}
function set(id, value){
  var elem = $(id);
  if(!elem){return false;}
  if(elem.type == 'checkbox'){ 
    if(value == 'true'){elem.checked = true;}
    else elem.checked = false;
  }else{elem.value = value;}
  return true;
}
function $(id){return getElement(id);}
function $$(id){if($(id)){return $(id).value;}}
function getKeyPressed(e){
	var key;
  if(window.event){key = event.keyCode;}
  else{
    if(e){key = e.keyCode;}
    else {return false;}
  }
	if(key == 9){return 'TAB';}
	if(key == 27){return 'ESC';}
	if(key == 113){return 'F2';}
	if(key == 114){return 'F3';}
	if(key == 119){return 'F8';}
	if(key == 46){return 'CANC';}
	if(key == 38){return 'UP';}
	if(key == 40){return 'DOWN';}
	if(key == 13){return 'INVIO';}
	if(key == 32){return 'BAR';}
	if(key == 33){return 'PGUP';}
	if(key == 34){return 'PGDOWN';}
  if(key == 35){return 'FINE';}
  if(key == 36){return 'HOME';}
  if(key == 37){return 'LEFT';}
  if(key == 39){return 'RIGHT';}
	if(key == 45){return 'INS';}
	else{return key;}	
}
function getInfo(elem){
  if(elem.nodeType == undefined) elem = $(elem);
	var i = {left: 0, top: 0};
  if(getBrowser() == 'Internet Explorer 7'){
  	while(elem){
  		if(elem.offsetLeft){i.left+=elem.offsetLeft;}
  		if(elem.offsetTop){i.top+=elem.offsetTop;}
  		elem = elem.parentNode;
  	}
  } else {
    i.left = elem.offsetLeft;
    i.top = elem.offsetTop;
  }
	return i;
}
function eliminaDestinazione(msg, CodDest){
  if(confirm(msg)){
    set('CodDest', CodDest);
    set('Azione', 'elimina destinazione');
    submitForm('destinazioni');
  }  
}
function compilaDestinazione(cDati){
  cDati = formatHtml(cDati);
  var aDati = cDati.split('|');
  var aCampo;
  for(var i in aDati){
    aCampo = aDati[i].split('=');
    set(aCampo[0], aCampo[1]);
  }
  hide('boxDestinazioni_Contenitore');
}
function modificaDestinazione(CodDest, cDati){
  cDati = formatHtml(cDati);
  var aDati = cDati.split('*');
  var aCampo;
  for(var i in aDati){
    aCampo = aDati[i].split('=');
    set(aCampo[0], aCampo[1]);
  }
  set('CodDest', CodDest);
  set('Azione', 'crea destinazione');
  $('destinazioni_TitoloForm').innerHTML = 'Modifica destinazione';
  $('DescrCli').focus();
  $('DescrCli').select();
  window.scrollTo(0,0);
}
function svuotaDestinazione(cPaese){
  set('DescrCli', '');
  set('Indirizzo', '');
  set('CAP', '');
  set('Citta', '');
  set('Provincia', '');
  set('Paese', formatHtml(cPaese));
  set('CodDest', '');
  set('Azione', 'crea destinazione');
  $('destinazioni_TitoloForm').innerHTML = 'Nuova destinazione';
  $('DescrCli').focus();
  $('DescrCli').select();
}
