﻿function getBrowser(){
  var ievs = (/MSIE (\d+\.\d+);/.test(navigator.userAgent)), iev;
  if(ievs){
    iev = Number(RegExp.$1);
    if(iev == 6){return "Internet Explorer 6";}
	}
  if(ievs){
    iev = Number(RegExp.$1);
    if(iev == 7){return "Internet Explorer 7";}
  }
  if(ievs){
    iev = Number(RegExp.$1);
    if(iev == 8){return "Internet Explorer 8";}
  }
}
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 getPos(elem){
	var c={x: 0, y: 0};
	while (elem) {
		c.x+=elem.offsetLeft;
		c.y+=elem.offsetTop;
		elem=elem.offsetParent;
	}
	return c;
}
function SetFontSize(id, Val800x600, Val){
	var Ogg = getElement(id);
	if(Ogg){Ogg.style.fontSize = GetValForResolution(Val800x600, Val);}
}
function formatHtml(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 = getElement(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 = getElement(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 stampa(){window.print();}	
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 aggiornaSchedaProdotto(codice, descrBreve, descrizione, descrizioneEstesa, prezzoNetto, prezzoLordo, disp, imgDir, img, carrelloNonDisp, mostraPrezziNonDisp, colNormale, colEvidenziato, avvisoDispo, mostraDispo, confrontiClass, azione, confrontiMsg, mostraPrezziVisitatori){
  var elem;
  setParam('codVariante', codice); 
  if(mostraPrezziNonDisp !== 'true' && (disp == 'no' || disp <= 0)){
    elem = getElement('schedaProdotto_prezzoNetto');
    if(elem){elem.style.display = 'none';}
    elem = getElement('schedaProdotto_prezzoLordo');
    if(elem){elem.style.display = 'none';}
    elem = getElement('schedaProdotto_iconaPromo');
    if(elem){elem.style.display = 'none';}
    elem = getElement('schedaProdotto_iva');
    if(elem){elem.style.display = 'none';}
  }else{
    elem = getElement('schedaProdotto_prezzoNetto');
    if(elem){
      iva = getElement('schedaProdotto_iva');
      if(prezzoNetto !== '0,00 €'){
        elem.style.display = 'block';
        nuovoPrezzo = elem.innerHTML;
        expr = new RegExp("num=[0-9]*.*width");
        nuovoPrezzo = nuovoPrezzo.replace(expr, "num=" + eurofix(prezzoNetto) + "&width");
        elem.innerHTML = formatHtml(nuovoPrezzo);
        if(iva){iva.style.display = 'block';}
      } else {
        elem.style.display = 'none';
        if(iva){iva.style.display = 'none';}
      }
    }
    elem = getElement('schedaProdotto_prezzoLordo');
    if(elem){
      if(prezzoLordo !== prezzoNetto){
        elem.style.display = 'block';
        promo = getElement('schedaProdotto_iconaPromo');
        if(promo){promo.style.display = 'block';}
        nuovoPrezzo = elem.innerHTML;
        expr = new RegExp("num=[0-9]*.*width");
        nuovoPrezzo = nuovoPrezzo.replace(expr, "num=" + eurofix(prezzoLordo) + "&width");
        elem.innerHTML = formatHtml(nuovoPrezzo);
      } else  {
        elem.style.display = 'none';
        promo = getElement('schedaProdotto_iconaPromo');
        if(promo){promo.style.display = 'none';}
      }
    }
  }
  elem = getElement('schedaProdotto_disponibilita');
  if(elem){
    if(mostraDispo == 'nascosta'){ 
      elem.style.display = 'none';
      dispLabel = getElement('schedaProdotto_labelDisponibilita');
      if(dispLabel) dispLabel.style.display = 'none';
    }
    else elem.style.display = 'block';
    elem.innerHTML = formatHtml(disp);
    if(disp == 'no' || disp <= 0){
      elem.style.color = '#F00'; //rosso
      carrello = getElement('schedaProdotto_boxCarrello');
      if(carrelloNonDisp !== 'true' || mostraPrezziVisitatori !== 'true'){   
        if(carrello){carrello.style.display = 'none';}
        
        // abilitare avviso se disp
        elem = getElement('avvisoDispo_aggiungi');
        if(elem){
          if(avvisoDispo !== 'true'){ // se già non l'ho richiesto
            elem.style.display = 'block';
          } else {
            elem.style.display = 'none';
          } 
        }
      } else {
        if(carrello && prezzoNetto == '0,00 €'){carrello.style.display = 'none';}
        else{carrello.style.display = 'block';}
      }
    } else {
      elem.style.color = '#00CC33'; //verde
      if(mostraPrezziVisitatori == 'true'){  
        carrello = getElement('schedaProdotto_boxCarrello');
        if(carrello){carrello.style.display = 'block'}
      }
      // disabilitare avviso se disp
      elem = getElement('avvisoDispo_aggiungi');      
      if(elem){elem.style.display = 'none';}
    }
  } 
  elem = getElement('variante');
  if(elem){elem.value = codice;} 
  elem = getElement('schedaProdotto_codice');
  if(elem){elem.innerHTML = formatHtml(codice);}  
  elem = getElement('schedaProdotto_titolo');
  if(elem){elem.innerHTML = formatHtml(descrBreve);}
  elem = getElement('schedaProdotto_descrizione');
  if(elem){elem.innerHTML = formatHtml(descrizione);}
  elem = getElement('schedaProdotto_schedaTecnica');
  if(elem){elem.innerHTML = formatHtml(descrizioneEstesa);}
  
  var aImgArt = img.split(';');
  elem = getElement('schedaProdotto_immagine');
  if(elem) elem.src = imgDir + getNomeMiniatura(aImgArt[0], 160, 160);;
  var imgName = '';
  
  contenitoreMiniature = getElement('schedaProdotto_contenitoreMiniature');
  if(!contenitoreMiniature) return false
  aElems = contenitoreMiniature.childNodes;
  // resetto tutto
  for(i=0;i<aElems.length;i++){
    if(i == 0) aElems[i].style.borderColor = colEvidenziato;
    else aElems[i].style.borderColor = colNormale;
     aElems[i].style.display = 'none';
  }
  // imposto valori giusti
  for(var i=0; i < aImgArt.length; i++){
    elem = getElement('schedaProdotto_miniatura_' + i);
    if(!elem) break;
    if(aImgArt[i] !== ''){ 
      elem.style.display = 'block'; 
      imgName = imgDir + getNomeMiniatura(aImgArt[i], 40, 40);
      elem.src = imgName;
    } 
  }
  // Gestione Confronti
  if(confrontiClass){
    elem = getElement('boxConfronti_button');
    if(elem) elem.className = confrontiClass;
  }
  if(confrontiMsg){
    document.forms.schedaProdotto_addCart.messaggio.value = confrontiMsg;
  }
  // Gestione Azione
  if(azione) document.forms.schedaProdotto_addCart.azioneConfronti.value = azione;
}
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 aggiungiAlCarrello(id, paramID, codArt, descrizione, descrizionePlurale, txtcolor, bgcolor, cartID){
  if(cartID){var cart = getElement(cartID);} 
  else{var cart = document.forms.schedaProdotto_addCart;}
  cart.pulsante.value = 'acquista';
  mostra('infoBox');
  var qta = document.getElementById("qta" + codArt).value, descr = qta + " ";
	if(qta > 1){descr += descrizionePlurale;}
	else{descr += descrizione;}
	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 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 gestioneTasti(e) {
	var key = (window.event) ? event.keyCode : e.keyCode;
	var ESC = (window.event) ? 27 : e.DOM_VK_ESCAPE;
	if(key == ESC){
		if(document.getElementById("riquadroDisabilitato").style.display == 'block'){nascondiVarianti();}
		if(document.getElementById("listaProdotti_boxFiltri").style.display == 'block'){
			nascondi("listaProdotti_boxFiltri");
			mostra("mostraFiltri");
		}
	} 
}
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){
	document.forms.schedaProdotto_addCart.azione.value = azione;
  mostraMessaggio(descrizione, txtcolor, bgcolor);
	setTimeout("submitForm('schedaProdotto_addCart')", 1000);
}
function gestioneConfronti(id, descrizione, azione, txtcolor, bgcolor, cartID){
  if(cartID){var cart = getElement(cartID);} 
  else{var cart = document.forms.schedaProdotto_addCart;} 
  cart.pulsante.value = 'confronto';
  if(azione) cart.azioneConfronti.value = azione;
  if(!descrizione) descrizione = cart.messaggio.value;
  mostraMessaggio(descrizione, txtcolor, bgcolor);
	//setTimeout("submitForm('schedaProdotto_addCart')", 1000);
  setTimeout("submitForm('" + cart.id + "')", 1000);
}
function gestioneAvvisoDispo(id, descrizione, azione, txtcolor, bgcolor){
	document.forms.schedaProdotto_addCart.azione.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);	
}
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){
	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(){
  elem = getElement('schedaProdotto_immagine');
  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 = getElement('schedaProdotto_titoloAttributi');
  if(!titolo){return false;}
  titolo.style.display='none';
  var container = getElement('schedaProdotto_containerAttributi');
  if(!container){return false;}
  
  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 == '') return false;
  titolo.style.display='block';
  var aResp = resp.split('|');
  var aAttr;
  for(var i in aResp){
    aAttr = aResp[i].split('=');//aAttr[0]->CodAttr|aAttr[1]->ValAttr
    var cod = new div('CodiceAttributo_' + aAttr[0]);
    cod.classe('schedaProdotto_descrizioneAttributo');
    cod.content(aAttr[0]);
    cod.container(container);
    cod.show();
    var val = new div('ValoreAttributo_' + aAttr[0]);
    val.classe('schedaProdotto_valoreAttributo');
    if(!aAttr[1]) val.content('n.d.');
    else val.content(aAttr[1]);
    val.container(container);
    val.show();
  }
} 
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){
  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';
      catbox.style.left = rifPos.x + 183 + '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 openFolder(rifTitolo, idContenuto, box){
  if(!rifTitolo) return false;
  var rifContenuto = getElement(idContenuto); 
  if(!rifContenuto) return false;
  var rifContenitoreTitoliFolders = getElement(box + '_contenitoreTitoliFolders');
  if(!rifContenitoreTitoliFolders) return false;
  // chiudo tutti i folder
  aElems = rifContenitoreTitoliFolders.childNodes;
  for(var elem in aElems){
    if(aElems[elem].id){
      aElems[elem].className = box + '_titoliFolders';
    }
  }
  var rifContenitoreContenutiFolders = getElement(box + '_contenitoreContenutiFolders');
  if(!rifContenitoreContenutiFolders) return false;
  aElems = rifContenitoreContenutiFolders.childNodes;
  for(var elem in aElems){
    if(aElems[elem].id){ 
      aElems[elem].className = box + '_contenutiFolders';
    }
  }
  // Apro folder selezionato
  rifTitolo.className = box + '_titoloFolderAperto';
  rifContenuto.className = box + '_contenutoFolderAperto';
}
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();
	}
}
function hidePopup(id){
	var box = getElement(id)
	if(box){box.parentNode.removeChild(box);}
}
function show(id){
  var oElem = getElement(id);
  if(oElem) oElem.style.display = 'block';
}
function hide(id){
  var oElem = getElement(id);
  if(oElem) oElem.style.display = 'none';
}
function add2selectXML(id, oXml){
  var oList = getElement(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 = getElement(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){
  if(evento == 'over'){ 
    mouseOverPointer(rif);
    rif.style.backgroundColor = colore;
  }
  if(evento == 'out'){
    mouseOutPointer();
    rif.style.backgroundColor = 'inherit';
  }
}