function wincenter(width,height,t)
{
  if(navigator.appName == "Microsoft Internet Explorer") {
   ascreenY = document.body.offsetHeight;
   ascreenX = window.screen.availWidth;
  }
  else 
  {
   ascreenY = window.outerHeight
   ascreenX = window.outerWidth
  }
	
	leftvar = (ascreenX - width) / 2;
  rightvar = (ascreenY - height) / 2;
  if(navigator.appName == "Microsoft Internet Explorer") 
	{
   leftprop = leftvar;
   topprop = rightvar;
  }
  else 
	{
   leftprop = (leftvar - pageXOffset);
   topprop = (rightvar - pageYOffset);
  }
	if(t=='L') return leftprop; else return topprop;

}

function genpop(file) 
{
a=file;
b='';
w=400;
h=200;
t=wincenter(w,h,'T');
l=wincenter(w,h,'L');
idwin=window.open(a,b,['width='+w,'height='+h,'left='+l,'top='+t,'toolbar=no','location=no','status=no','menubar=no','scrollbars=yes']); 
}

function toggleDiv(theDiv, classVedi, classNascondi)
{
	var allTags=document.getElementsByTagName("div");

	for (var i=0;i<allTags.length;i++)
	{
		vsId = allTags[i].id;
		if (vsId.substring(0,4)=="div_")
			allTags[i].className=classNascondi;
	}
	
	if(document.getElementById(theDiv).className==classVedi)
	{
		document.getElementById(theDiv).className=classNascondi;
		//document.getElementById('imm_'+theDiv).src='../images/back/piu.gif';
	}
	else if(document.getElementById(theDiv).className==classNascondi)
	{
		document.getElementById(theDiv).className=classVedi;
		//document.getElementById('imm_'+theDiv).src='../images/back/meno.gif';
	}
 
}

function simple_toggleDiv(theDiv, classVedi, classNascondi)
{
	if(document.getElementById(theDiv).className==classVedi)
		document.getElementById(theDiv).className=classNascondi;
	else if(document.getElementById(theDiv).className==classNascondi)
		document.getElementById(theDiv).className=classVedi;
}

function getRequestObject()
{
 			var A;
			try {
				A=new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					A=new ActiveXObject("Microsoft.XMLHTTP");
				} catch (oc) {
					A=null;
				}
			}
			if(!A && typeof XMLHttpRequest != "undefined")
				A = new XMLHttpRequest();
      return A;
}

function CercaProdotto()
{
	var vsCat = document.getElementById("CATEGORIA").value;
	var vsProd = document.getElementById("PRODOTTO").value;
	var uri = "act/act_ricerca_prodotti.php";
	var post_data;
	var sajax_request_type = "POST";
	var post_data = "CATEGORIA="+vsCat+"&PRODOTTO="+vsProd;
	var x;
	
	x = getRequestObject();  
	x.open(sajax_request_type, uri, true);
	
	//POST
	x.setRequestHeader("Method", "POST " + uri + " HTTP/1.1");
	x.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	
	x.onreadystatechange = function() 
	{
		if (x.readyState != 4) 
			return;
		//alert(x.responseText);
		
		vaRis = eval(x.responseText);
		document.getElementById("lista").options.clear;
		for (i in vaRis)
			document.getElementById("lista").options.add(new Option(vaRis[i],vaRis[i]),0); 
			
		document.getElementById("divlista").className="menuvisibile2";
			//simple_toggleDiv("divlista", "menuvisibile2", "menuhidden");
		//document.getElementById("lista").focus();
	}
	x.send(post_data);
	delete x;
}

function setProdotto(vsValore)
{
	document.getElementById('PRODOTTO').value=vsValore;
	document.getElementById("divlista").className="menuhidden";
}

onList=false;