// VARIABILI GENERALI ****************************************************************************************
var myRequest = null;
var nomeDiv;
var myWidth;
var myHeight;
var sinX;
var sopY;
var posx;
var posy;
var finW;
var finH;
var ApreChiudi;
var funzione;
var txtCerca;
var pgCerca;
var PgControllo = "circuit/ajax/view_pg_controllo.php";
// FUNZIONE CHE PERMETTE DI FARE LA CHIAMATA AJAX ************************************************************
function CreateXmlHttpReq2(x) {
  var xmlhttp = null;
  try {
    xmlhttp = new XMLHttpRequest();
  } catch(e) {
    try {
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch(e) {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
  xmlhttp.onreadystatechange = x;
  return xmlhttp;
}
// CHIAMATA ATTRAVERSO IL METODO GET *************************************************************************
function AjaxCambiaTipo(p,d,t,j,w,h,px,py,fun){
	nomeDiv = t; 
	ApreChiudi =j;
	finW =w;
	finH =h;
	posx =px;
	posy =py;
	funzione=fun
	var nomepg = escape(PgControllo);//escape(""+p);
	//alert(nomepg);
	var dati = d;     //alert(dati);
  	var r = Math.random();
	myRequest = CreateXmlHttpReq2(AjaxRichiestaInf);
    myRequest.open("GET",nomepg+"?id="+dati+"&rand="+escape(r)); 
	//myRequest.setRequestHeader("Connection", "close");
    myRequest.send(null);
}
// PERMETTE DI AVERE TUTTI I CAMPI DI UN FORM PER MANDARLI CON IL METODO POST
function createQuery(x,y){	
    var elements = x.elements;
    var pairs = new Array();		
    for (var i = 0; i < elements.length; i++) {
        if ((name = elements[i].name) && (value = elements[i].value)){
            pairs.push(name + "=" + encodeURIComponent(value));	
			if(name == "f_reg_cognome" && y=="p")txtCerca = encodeURIComponent(value);
			if(name == "f_reg_nome" && y=="i")txtCerca = encodeURIComponent(value);
		}	
    }
	return pairs.join("&");		
}
// CHIUDI FINESTRA DIV ***************************************************************************************
function AjaxChiudiFinestra(x){
	var chiudi = objLiv0(x);	
	chiudi.innerHTML ="";
	aprechiudeB(x,0);
}
// APRE CHIUDI FINESTRA DIV **********************************************************************************
function aprechiudeB(x,y){
	if(y==0){
		objLiv(x).visibility = "hidden";
		objLiv(x).display = "none";
	}
	if(y==1){
	//alert(x);
		if(x=="risultato"){
			objLiv(x).visibility = "visible";
			objLiv(x).display = "block";
		}else{  objLivAjax(x);}
	}
}
// DIMENSIONE DEL DIV E POSIZIONAMENTO DI QUESTA *************************************************************
function objLivAjax(strLivName){		
	if (document.layers){			
		myWidth = window.innerWidth;
		myHeight = window.innerHeight
	}
	else if (document.getElementById){
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	else if (document.all){
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight
	}	
		sinX = (finW/2);
		sopY = (finH/2);
		if(posx==0){
		posx = (myWidth/2) - sinX;
		}
		if(posy==0){
		posy = ((myHeight/2) - sopY);
		
		}	
		objLiv(strLivName).width = finW;
		objLiv(strLivName).height = finH;
		
		objLiv(strLivName).left = posx;
		objLiv(strLivName).top = posy;
		
		objLiv(strLivName).visibility = "visible";
		objLiv(strLivName).display = "block";
}
function objLiv(strLivName)
			{
				objDoc = window.document;
				if (document.layers)
				{
					return objDoc.layers[strLivName];
				}
				else if (document.getElementById)
				{
					return objDoc.getElementById(strLivName).style;
				}
				else if (document.all)
				{
					return objDoc.all[strLivName].style;
				}
			}	
		function objLiv0(strLivName)
			{
				objDoc = window.document;
				if (document.layers)
				{
					return objDoc.layers[strLivName];
				}
				else if (document.getElementById)
				{
					return objDoc.getElementById(strLivName);
				}
				else if (document.all)
				{
					return objDoc.all[strLivName];
				}
			}			