	Open=new Image(9,9)
	Closed=new Image(9,9)
	Open.src="images/folo.gif"
	Closed.src="images/folc.gif"
function showhide_2(id1,id2){
	var	oggetto = document.getElementById(id1),
		segno = document.getElementById(id2);
	if(oggetto.style.display==''){
		oggetto.style.display='none';
	
		segno.src=Closed.src;
	}else{
		oggetto.style.display='';
		
			segno.src=Open.src;
		
	}

 }

 function scheda_prodotto_focus(pointer) {
  var counter=document.getElementById('counter'),
 valore_corrente=document.getElementById('valore_corrente');
 if (isInt(pointer.value)) {valore_corrente.value=pointer.value} else {valore_corrente.value=0;}
 }
 
 function scheda_prodotto_change(pointer) {
 var counter=document.getElementById('counter'),
 valore_corrente=document.getElementById('valore_corrente');
 if(isInt(pointer.value)) {
counter.value=eval(parseInt(counter.value)+parseInt(pointer.value)-parseInt(valore_corrente.value));
} else {
counter.value=eval(parseInt(counter.value)-parseInt(valore_corrente.value));
}
 }
 
function scheda_prodotto_submit() {
 var counter=document.getElementById('counter');
 if (parseInt(counter.value)<1) {alert('Inserire la quantità da ordinare');return false;}
 return true;
 }
 
function scheda_prodotto_submit_en() {
 var counter=document.getElementById('counter');
 if (parseInt(counter.value)<1) {alert('Fill in quantity values');return false;}
 return true;
 }
 
 
function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";  
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function isInt(x) { 
   var y=parseInt(x); 
   if (isNaN(y)) return false; 
   return x==y && x.toString()==y.toString(); 
}

/* SWAP IMAGES (mouseover) */

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


/*POP-UP*/
function apri(finestra){
	open(finestra,'AA','resizable=no,scrollbars=yes,menubar=no,left=50,top=50,width=450,height=500');
}

function popup(finestra,x,y){
	open(finestra,'AA','resizable=no,scrollbars=yes,menubar=no,left=50,top=50,width='+x+',height='+y);
}


function filtro_fatture() {
			var from_d=document.getElementById('from_d').value,
			from_m=document.getElementById('from_m').value,
			from_y=document.getElementById('from_y').value,
			to_d=document.getElementById('to_d').value,
			to_m=document.getElementById('to_m').value,
			to_y=document.getElementById('to_y').value,
			ragionesociale=document.getElementById('ragionesociale').value;
			if (from_d !='' & from_m !='' & from_d !='' & to_d !='' & to_m !='' & to_y !='' || ragionesociale!='') {
			caricaTesto('index.php?action=ajax_filtro_fatture&from_d='+from_d+'&from_m='+from_m+'&from_y='+from_y+'&to_d='+to_d+'&to_m='+to_m+'&to_y='+to_y+'&ragionesociale='+ragionesociale,'lista_fatture');
		}
		if (from_d =='' & from_m =='' & from_d =='' & to_d =='' & to_m =='' & to_y =='' || ragionesociale!='') {
						caricaTesto('index.php?action=ajax_filtro_fatture&from_d='+from_d+'&from_m='+from_m+'&from_y='+from_y+'&to_d='+to_d+'&to_m='+to_m+'&to_y='+to_y+'&ragionesociale='+ragionesociale,'lista_fatture');
			}
			}

function controllopressione(formname) {
 	var
		a = document.forms[formname],
		x = a.elements,
	 	y="";
  for (var i=0;i<x.length;i++){
		if (x[i].getAttribute('controllopressione') && x[i].checked) {
			y++;
    }
	}
	if (y < 1) {return false;}
	return true;
}


/*CREA IL MENU*/

function onchange_menu(changed,changed_1,changed_recupero) {
				var menuReparto=document.getElementById('menuReparto').value,
				menuUso=document.getElementById('menuUso').value,
				menuArticolo=document.getElementById('menuArticolo').value,
				menuPagine=document.getElementById('menuPagine').value,
				menuCollezione=document.getElementById('menuCollezione').value,
				textCodice=document.getElementById('textCodice').value,
				menuMarchio=document.getElementById('menuMarchio').value;
				if(changed==changed_1) {changed_1=changed_recupero;}
				caricaTesto('index.php?action=ajax_risultati_ricerca&textCodice='+textCodice+'&changed_1='+changed_1+'&changed_2='+changed_recupero+'&changed='+changed+'&menuReparto='+menuReparto+'&menuCollezione='+menuCollezione+'&menuUso='+menuUso+'&menuArticolo='+menuArticolo+'&menuMarchio='+menuMarchio+'&menuPagine='+menuPagine,'inner_content',false,true);
				caricaTesto('index.php?action=ajax_refresh_menu&textCodice='+textCodice+'&changed_1='+changed_1+'&changed_2='+changed_recupero+'&changed='+changed+'&menuReparto='+menuReparto+'&menuCollezione='+menuCollezione+'&menuUso='+menuUso+'&menuArticolo='+menuArticolo+'&menuMarchio='+menuMarchio+'&menuPagine='+menuPagine,'righe_ricerca',false,true);
				}
function onchange_menu_en(changed,changed_1,changed_recupero) {
				var menuReparto=document.getElementById('menuReparto').value,
				menuUso=document.getElementById('menuUso').value,
				menuArticolo=document.getElementById('menuArticolo').value,
				menuPagine=document.getElementById('menuPagine').value,
				menuCollezione=document.getElementById('menuCollezione').value,
				textCodice=document.getElementById('textCodice').value,
				menuMarchio=document.getElementById('menuMarchio').value;
				if(changed==changed_1) {changed_1=changed_recupero;}
				caricaTesto('index_en.php?action=ajax_risultati_ricerca&textCodice='+textCodice+'&changed_1='+changed_1+'&changed_2='+changed_recupero+'&changed='+changed+'&menuReparto='+menuReparto+'&menuCollezione='+menuCollezione+'&menuUso='+menuUso+'&menuArticolo='+menuArticolo+'&menuMarchio='+menuMarchio+'&menuPagine='+menuPagine,'inner_content',false,true);
				caricaTesto('index_en.php?action=ajax_refresh_menu&textCodice='+textCodice+'&changed_1='+changed_1+'&changed_2='+changed_recupero+'&changed='+changed+'&menuReparto='+menuReparto+'&menuCollezione='+menuCollezione+'&menuUso='+menuUso+'&menuArticolo='+menuArticolo+'&menuMarchio='+menuMarchio+'&menuPagine='+menuPagine,'righe_ricerca',false,true);
				}	

function ricerca_cliente() {
	var nome=document.getElementById('filtro').value;
	var filtro_mail=document.getElementById('filtro_mail').value;
	var piva=document.getElementById('filtro_piva').value;
	var username=document.getElementById('username').value;
	if (nome !='' || filtro_mail !=''|| piva !='' || username != '') {
		caricaTesto('index.php?action=ajax_ricerca_cliente&filter='+nome+'&email='+filtro_mail+'&piva='+piva+ '&username='+username,'ricerca_cliente');
	}
	if (nome =='' && filtro_mail =='' && piva=='' && username == '') {
		caricaTesto('index.php?action=ajax_ricerca_cliente','ricerca_cliente');
	} 
}

function check_code(element) {
element.style.background='';
if (element.value.length==6) {
			  var
    ajax = assegnaXMLHttpRequest();
  if(ajax) {
		var d = new Date();
		var time = d.getTime();
    ajax.open('get', 'index.php?action=ajax_check_code&key='+element.value+'&time='+time, true);
    ajax.setRequestHeader("connection", "close");
    ajax.onreadystatechange = function() {
	    if(ajax.readyState === readyState.COMPLETATO) {
				if(statusText[ajax.status] === "OK") {
					element.focus();
			 if(parseInt(ajax.responseText)==0) {element.style.background='#ff9296';} else {element.style.background='#92ffc3'}
		

						}
					}
				} 
			}
			ajax.send('var=1');
	}
			} 
			

function ricerca_file(nome,azienda,pubblicato,tipo) {
	caricaTesto('index.php?action=ajax_ricerca_file&nome='+nome+'&azienda='+azienda+'&pubblicato='+pubblicato+'&tipo='+tipo,'ricerca_file');
	}

function assegnaXMLHttpRequest() {
	var
		XHR = null,
		browserUtente = navigator.userAgent.toUpperCase();
	if(typeof(XMLHttpRequest) === "function" || typeof(XMLHttpRequest) === "object")
		XHR = new XMLHttpRequest();
	else if(window.ActiveXObject && browserUtente.indexOf("MSIE 4") < 0) {
		if(browserUtente.indexOf("MSIE 5") < 0)
			XHR = new ActiveXObject("Msxml2.XMLHTTP");
		else
			XHR = new ActiveXObject("Microsoft.XMLHTTP");
	}
	return XHR;
}

var readyState = {
	INATTIVO:       0,
	INIZIALIZZATO:  1,
	RICHIESTA:      2,
	RISPOSTA:       3,
	COMPLETATO:     4
};

var statusText = new Array();
	statusText[100] = "Continue";
	statusText[101] = "Switching Protocols";
	statusText[200] = "OK";
	statusText[201] = "Created";
	statusText[202] = "Accepted";
	statusText[203] = "Non-Authoritative Information";
	statusText[204] = "No Content";
	statusText[205] = "Reset Content";
	statusText[206] = "Partial Content";
	statusText[300] = "Multiple Choices";
	statusText[301] = "Moved Permanently";
	statusText[302] = "Found";
	statusText[303] = "See Other";
	statusText[304] = "Not Modified";
	statusText[305] = "Use Proxy";
	statusText[306] = "(unused, but reserved)";
	statusText[307] = "Temporary Redirect";
	statusText[400] = "Bad Request";
	statusText[401] = "Unauthorized";
	statusText[402] = "Payment Required";
	statusText[403] = "Forbidden";
	statusText[404] = "Not Found";
	statusText[405] = "Method Not Allowed";
	statusText[406] = "Not Acceptable";
	statusText[407] = "Proxy Authentication Required";
	statusText[408] = "Request Timeout";
	statusText[409] = "Conflict";
	statusText[410] = "Gone";
	statusText[411] = "Length Required";
	statusText[412] = "Precondition Failed";
	statusText[413] = "Request Entity Too Large";
	statusText[414] = "Request-URI Too Long";
	statusText[415] = "Unsupported Media Type";
	statusText[416] = "Requested Range Not Satisfiable";
	statusText[417] = "Expectation Failed";
	statusText[500] = "Internal Server Error";
	statusText[501] = "Not Implemented";
	statusText[502] = "Bad Gateway";
	statusText[503] = "Service Unavailable";
	statusText[504] = "Gateway Timeout";
	statusText[505] = "HTTP Version Not Supported";
	statusText[509] = "Bandwidth Limit Exceeded";

function caricaTesto(nomeFile,id_destinazione,noshow,allowcache) {
  var
    ajax = assegnaXMLHttpRequest(),
    elemento = document.getElementById(id_destinazione),
    usaLink = true;
  if(ajax) {
    usaLink = false;
		var d = new Date();
		var time = d.getTime();
		if (!allowcache) {
    if(nomeFile.indexOf('?')>=0) {
			ajax.open('get', nomeFile+'&time='+time, true);
		}	else {
			ajax.open('get', nomeFile+'?time='+time, true);
		}
		} else {
			ajax.open('get', nomeFile, true);
			}
    ajax.setRequestHeader("connection", "close");
    ajax.onreadystatechange = function() {
	    if(ajax.readyState === readyState.COMPLETATO) {
				if(statusText[ajax.status] === "OK") {
			  	if (!noshow) {
			  			//alert(ajax.responseText);
						elemento.innerHTML = ajax.responseText;
		
	}
						}
					}
				} 
			}
				else {
					elemento.innerHTML = "Impossibile effettuare l'operazione richiesta.<br />";
					elemento.innerHTML += "Errore riscontrato: " + ajax.status;
			
			}
	
	  ajax.send('var=1');

	return usaLink;
}

function showhide(id){
	var oggetto = document.getElementById('id');
	if(oggetto.style.display==''){
		oggetto.style.display='none';
	}else{
		oggetto.style.display='';
	}
}



function change_img(imageName,imageSrc) {

document.images[imageName].src = imageSrc;

} 


