function visibile(lg) {
  var lge,ret;
  lge=xGetElementById(lg);
  if(lge!=null) {
    if(lge.style.display!='none') {
      lge.style.display='none';
    }
    else {
      lge.style.display='';
    }
  }
}

function nascondi(lg) {
	lge=xGetElementById(lg);
  if(xDef(lge)) {
  	lge.style.display='';
  }
}

function selezionaTutti(a) {
	var u,c;
	u=xGetElementsByClassName('selotto',null,'input');
	io=xGetElementById('btSelAll');
	if(io.innerHTML=="Deseleziona Tutti") {
		for(c=0;c<u.length;c++) {
			u[c].checked=false;
		}
		io.onClick="selezionaTutti(true); return false;";
		io.innerHTML="Seleziona Tutti";
	}
	else {
		for(c=0;c<u.length;c++) {
			u[c].checked=true;
		}
		io.onClick="selezionaTutti(false); return false;";
		io.innerHTML="Deseleziona Tutti";
	}
}

function eliminaSelezionatiDEF(a) {
	u=xGetElementsByClassName('selotto',null,'input');
	n=0;
	for(c=0;c<u.length;c++) {
		if(u[c].checked) n++;
	}
	if(n>0) {
		if(a=='') a="eliminare"; 
		return confirm("Sei sicuro di voler " + a + " quanto selezionato?");
	}
	else {
		alert("Non hai selezionato niente!");
		return false;
	}
}

function eliminaSelezionati() {
	a="eliminare";
	return eliminaSelezionatiDEF(a);
}

function abilitaSelezionati() {
	a="abilitare";
	return eliminaSelezionatiDEF(a);
}

function disabilitaSelezionati() {
	a="disabilitare";
	return eliminaSelezionatiDEF(a);
}

function addToChart(id) {
	jx.load("carrello.php?do=add&prod=" + id,
	function(data){
		a=xGetElementById('resul');
		dati=data.split('|');
		a.innerHTML=dati[1];
		myre=new RegExp('(Y|y)');
		if(dati[0].match(myre)) {
			b=xGetElementById('btAddChart');
			b.innerHTML='';
		}
	}
	,'text','get');
}

function addToChartList(id) {
	jx.load("carrello.php?do=add&prod=" + id,
	function(data){
		a=xGetElementById('resul');
		dati=data.split('|');
		a.innerHTML=dati[1];
		myre=new RegExp('(Y|y)'); 
		if(dati[0].match(myre)) {
			b=xGetElementById('cls_' + id);
			b.innerHTML="<img src='img/basket_x.gif' alt=' '>";
		}
	}
	,'text','get');
}

function eliminaFromLink(id) {
	a=xGetElementById('delText');
	mystr=a.innerHTML.replace('%PROD%',id);
	return confirm(mystr);
}

function setLang(a) {
	jx.load("index.php?lang=" + a,
		function(data){
			//return true;
			window.location.reload();
		}
	,'text','get');
}

function checkPass(k) {
	npass=xGetElementById("npass");
	if(npass.value!=k.value) {
		err=xGetElementById("pass_err");
		err.innerHTML="<span class='err'>Le password inserite non corrispondono</span>";
	}
}

function setPassoInd() {
//	a=xGetElementById('hidPasso');
//	a.value=(a.value - 1);
	a=xCreateElement('input');
	a.setAttribute('type','hidden');
	a.setAttribute('name','passo');
	a.setAttribute('value','0');
	xAppendChild(document.toMoneta,a);
	document.toMoneta.action="carrello.php";
}

function eliminaProdObj(io) {
	b=xGetElementById('tbObj');
	
	inputs=xGetElementsByTagName('input',b);
	
	todel=new Array();
	n=0;
	for(c=0;c<inputs.length;c++) {
		if(inputs[c].type=='checkbox'&&inputs[c].checked) {
			pz=inputs[c].name.split('_');
			todel[n]=pz[2];
			n++;
		}
	}
	
	io.href+="&del=" + todel.join('|');
//	alert(io.href);
}

function salvaProdObj(io) {
	b=xGetElementById('tbObj');
	
	inputs=xGetElementsByTagName('input',b);
	
	todel=new Array();
	n=0;
	for(c=0;c<inputs.length;c++) {
		pz=inputs[c].name.split('_');
		todel[n]=pz[1] + "=" + inputs[c].value;
		n++;
	}
	selects=xGetElementsByTagName('select',b);
	pz=selects[0].name.split('_');
	todel[n]=pz[1] + "=" + selects[0].options[selects[0].selectedIndex].value;
	
	c=0;
	mydel=new Array();
	for(n=0;n<todel.length;n++) {
		if(todel[n]!='') mydel[c]=todel[n];
		c++;
	}
	
	io.href+="&salva=y&" + mydel.join('&');
//	alert(io.href);
}

function apriFinestra(a) {
	var io;
	var w = 800;
  var h = 600;
  var l = Math.floor((screen.width - w)/2);
  var t = Math.floor((screen.height - h)/2);
  io=xGetElementById(a);
  window.open(io.href,'',"'width=" + w + "px,height=" + h + "px,top=" + t + "px,left=" + l + "px,scrollbars=1,resizable=0,toolbar=0,location=0,directories=0,status=0,menubar=0");
}

/*
function eliminaComponenti(id,comp) {
	jx.load("configurazione.php?elimina=" + comp,
		function(data){
			b=xGetElementById('');
		}
	,'text','get');
}
*/
