   function calc_left (w) {
   	var left = (screen.availWidth / 2) - (w / 2);
   	return (left);
   }
   
   function calc_top (h) {
   	var top = (screen.availHeight / 2) - (h / 2);
   	return (top);
   }
   
   function open_popup (url, w, h, scrollbar,toolbar,status,menubar,id) {
    //alert(scrollbar)
    if(!scrollbar){scrollbar = 'no'}
    if(!toolbar){toolbar = 'no'}
    if(!status){status = 'no'}
    if(!menubar){menubar = 'no'}
    if(!id){id = ''}
    
   	var top = calc_top (h);
   	var left = calc_left (w);
   
   	popup = window.open (url,id,'width='+w+',height='+h+',left='+left+',top='+top+',screenX='+left+',screenY='+top+'status='+status+', menubar='+menubar+', toolbar='+toolbar+', scrollbars='+scrollbar);
   	popup.focus();
   }
   


/** FUNZIONI */

	// funzione per prendere un elemento con id univoco
		function prendiElementoDaId(id_elemento) {
			var elemento;
			if(document.getElementById)
				elemento = document.getElementById(id_elemento);
			else
				elemento = document.all[id_elemento];
			return elemento;
		};
	
	// funzione per assegnare un oggetto XMLHttpRequest
		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;
		};



/** OGGETTI / ARRAY */

	// oggetto di verifica stato
		var readyState = {
			INATTIVO:	0,
			INIZIALIZZATO:	1,
			RICHIESTA:	2,
			RISPOSTA:	3,
			COMPLETATO:	4
		};

	// array descrittivo dei codici restituiti dal server
	// [la scelta dell' array è per evitare problemi con vecchi browsers]
		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,idElement,method,postVariables,typePrint,fadeIn) {
  // variabili di funzione
  //alert('eccomi');
  if((method=='')||(method == null))
  {
    method = 'get';
  }
  
  var
    // assegnazione oggetto XMLHttpRequest
    ajax = assegnaXMLHttpRequest(),
    // assegnazione elemento del documento
    elemento = prendiElementoDaId(idElement),
    // risultato booleano di funzione
    usaLink = true;
  
  // se l'oggetto XMLHttpRequest non è nullo
  if(ajax) {
    // il link al file non deve essere usato
    usaLink = false;

    // impostazione richiesta asincrona in GET
    // del file specificato
    if((method.toLowerCase() == 'post'))
    {
			ajax.open("post", nomeFile, true);
			ajax.setRequestHeader("content-type", "application/x-www-form-urlencoded");
      ajax.setRequestHeader("connection", "close");
			ajax.send(postVariables);
    }
    else
    {
      ajax.open("get", nomeFile, true);
      ajax.setRequestHeader("connection", "close");
    }
    // rimozione dell'header "connection" come "keep alive"

    // impostazione controllo e stato della richiesta
    ajax.onreadystatechange = function() {
      
      // verifica dello stato
      if(ajax.readyState === readyState.COMPLETATO) {
        // verifica della risposta da parte del server
        if(statusText[ajax.status] === "OK"){
          // operazione avvenuta con successo
          if(typePrint=='add')
          {
            elemento.innerHTML += ajax.responseText;
          }
          else{
	            if(fadeIn==1)
	            {
	              //opacity('ajaxContent', 100, 0, 1000)
	              elemento.innerHTML = '<div id="ajaxContent" name="ajaxContent" style="filter: alpha(opacity=0); -moz-opacity: 0; opacity: 0;">'+ajax.responseText+'</div>';
	              opacity('ajaxContent', 0, 100, 1000)
	            }
	            else
	            {
	              elemento.innerHTML = ajax.responseText;
	            }
          }

          }
        else {
          // errore di caricamento
          elemento.innerHTML = "Impossibile effettuare l'operazione richiesta.<br />";
          elemento.innerHTML += "Errore riscontrato: " + statusText[ajax.status];
        }
      } 
    }

    // invio richiesta
    ajax.send(null);
  }
   
  return usaLink;
} 

function menu(params)
{
	//alert();
	document.write(''+
	              '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="850" height="375" id="menu" align="middle">'+
									'<param name="allowScriptAccess" value="sameDomain" />'+
									'<param name="movie" value="comuni/swf/menu.swf" />'+
									'<param name="quality" value="high" />'+
									'<param name="bgcolor" value="#ffffff" />'+
									'<param name="flashvars" value="'+params+'">'+
									'<embed flashvars="'+params+'" src="comuni/swf/menu.swf" quality="high" bgcolor="#ffffff" width="850" height="375" name="menu" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" swLiveConnect="true" />'+
								'</object>');
	
}

function printFlash(swf,w,h,params)
{
	//alert();
	document.write(''+
	              '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="'+w+'" height="'+h+'" align="middle">'+
									'<param name="allowScriptAccess" value="sameDomain" />'+
									'<param name="movie" value="'+swf+'" />'+
									'<param name="quality" value="high" />'+
									'<param name="flashvars" value="'+params+'">'+
									'<embed flashvars="'+params+'" src="'+swf+'" quality="high" width="'+w+'" height="'+h+'" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" swLiveConnect="true" />'+
								'</object>');
	
}

function toMenu(args){
   var sendText = args;
   window.document.menu.SetVariable("menu", sendText);
}

			function checkQuest()
			{
			  if(document.getElementById('risposta').value)
			  {
			    return(true);
			  }
			  else
			  {
			    alert('Attenzione!\nbisogna votare per proseguire.');
			    return(false);
			  }
			}
			
			
			function makeRisp(risp,altro)
			{
			  document.getElementById("risposta").value = risp;
			  if(altro == 1)
			  {	
			    document.getElementById("altro").readOnly = false;
			  }
			  else
			  {
			   if(document.getElementById("altro")){
			    document.getElementById("altro").value    = "";		
			    document.getElementById("rispostaAltro").value    = "";			
			    document.getElementById("altro").readOnly = true;}	  
			  }
			
			}
			
	function caricaSez(reparto,baseUrl)
  {
  	window.open('/contenuti/il_tuo_ipermercato/mappa/reparto.php?r='+reparto,reparto,'width=500,height=400');
  }
  
      
		  function volantino(vol)
		  {
		   idIper = GetCookie("ipermercato");
		   if(!idIper)
		   {
		   	  window.open('/volantino/?'+vol,'volantino','width=400,height=250')
		   }
		   else
		   {
		   	  window.open('/volantino/?'+vol);
		   }
		  }
      
      function cambiaPagina(parIn)
      {
        var myvars=parIn.split("&");
        for(i=0;i<myvars.length;i++)
        {
        	tempVar = myvars[i];
        	mySingleVars = tempVar.split("\=");
        	eval('var '+ mySingleVars[0] +' = "'+mySingleVars[1]+'"');
        	//alert(mySingleVars[0]+" "+mySingleVars[1])
        }
      	p = '';
      	brand = '';
      	cat = '';
      	if(liv1=='catalogo'){cat = liv2}
      	else if(liv1 == 'brand'){brand = liv2}

      	//alert('cambiaContenuti,'+liv1+','+cat+','+brand+','+parIn);
      	flashProxy.call('cambiaContenuti',liv1,cat,brand,parIn);
      }
      
      

function openWin(url,name,w,h,loc,scr,men,too,res)
{
  props = "width="+ w +",height="+ h +",location="+loc+",scrollbars="+scr+",menubars="+men+",toolbars="+too+",resizable="+res+"";
  window.open(url,name, props);
}

function unique(a) {
	tmp = new Array(0);
	for(i=0;i<a.length;i++){
  if((a[i] && a[i]!='' && a[i].length>1))
   {
		if(!contains(tmp, a[i])){
			 tmp.length+=1;
			 tmp[tmp.length-1]=a[i];
		}
   } 
	}
	return tmp;
}



function contains(a, e) {
	for(j=0;j<a.length;j++)if((a[j]==e))return true;
	return false;
}


function getCookieVal (offset) 
{
var endstr = document.cookie.indexOf (";", offset);

if (endstr == -1)

endstr = document.cookie.length;

return unescape(document.cookie.substring(offset, endstr));

}

function GetCookie (name) 
{
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) 
{
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) 
break; 
}

return null;
}

function SetCookie (name, value)
{
//alert('cookie');
var argv = SetCookie.arguments;

var argc = SetCookie.arguments.length;

var expires = (2 < argc) ? argv[2] : null;

var path = (3 < argc) ? argv[3] : null;

var domain = (4 < argc) ? argv[4] : null;

var secure = (5 < argc) ? argv[5] : false;

document.cookie = name + "=" + escape (value) +

((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +

 
((path == null) ? "" : ("; path=" + path)) +

((domain == null) ? "" : ("; domain=" + domain)) +

((secure == true) ? "; secure" : "");

}


function opacity(id, opacStart, opacEnd, millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}

 function roll(base,menu,status)
 {
   eval("document.menu_"+menu+".src='"+base+"comuni/img/menu_"+menu+"_"+status+".gif';");
 }