

//------------------------------
// pagine EVENTI
//------------------------------

function Popup(url) 
{
	my_window= window.open (url,'','status=1,width=420,height=450'); 
}

function GeneraCaptcha (id)
{
	var image = document.getElementById(id);
	var url = "GeneraCaptcha.aspx?id=" + Math.random();
	image.src = url;
}

function VisualizzaFoto(bloccoFeedBack, action) { 	
	
		var str = bloccoFeedBack.src;
		var i = str.lastIndexOf('?') + 4;
		var l = str.length;
		var id = str.substring(i,l);
		//var url = bloccoFeedBack.src + "&a=" + action;
		var url = "Allegato.asp?id=" + id + "&a=" + action;
		url += "&t=" + Math.random();
		richiestaHTML_AJAX(url,  bloccoFeedBack, "src");
}
function inizializzaFoto(bloccoFeedBack, id) { 	
		
		var url = "Allegato.asp?id=" + id + "&a=open";
		url += "&t=" + Math.random();
		richiestaHTML_AJAX(url,  bloccoFeedBack, "src");
		bloccoFeedBack.src = "Images/Icons/loading.gif";
}

function AllegatiEvento(pagina, idEvento) { 
	var idBloccoFeedBack = "e" + idEvento; 
	var idFreccia = "f" + idEvento; 
	
	var bloccoFeedBack = document.getElementById(idBloccoFeedBack);
	var imgFreccia = document.getElementById(idFreccia);
	
    if (bloccoFeedBack.style.display == "none") {
		var url = "Default.asp?p=" + pagina + "&Evento=" + idEvento;
        visualizzaBlocco(bloccoFeedBack, imgFreccia);
        richiestaHTML_AJAX(url,  bloccoFeedBack, "html");
        
    } else {
        nascondiBlocco(bloccoFeedBack, imgFreccia);
    } 
}


function nascondiBlocco(bloccoFeedBack, imgFreccia) {
	bloccoFeedBack.style.display = "none";
	imgFreccia.src="Images/Icons/tip.gif";
}
function visualizzaBlocco(bloccoFeedBack, imgFreccia) {
	bloccoFeedBack.style.display = "inline";
	imgFreccia.src="Images/Icons/pin.gif";
}


//------------------------------
// AJAX
//------------------------------

function richiestaHTML_AJAX(url, bloccoFeedBack, type) { 
    
    makeRequest(url, bloccoFeedBack,type);
}

function makeRequest(url, bloccoFeedBack,type) {
    
    var httpRequest;
    //alert(url);

    if (window.XMLHttpRequest) { // Mozilla, Safari, ...
        httpRequest = new XMLHttpRequest();
        if (httpRequest.overrideMimeType) {
            httpRequest.overrideMimeType("text/xml");
            // See note below about this line
        }
    } 
    else if (window.ActiveXObject) { // IE
        try {
            httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
            } 
            catch (e) {
                       try {
                            httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
                           } 
                         catch (e) {}
                      }
                                   }

    if (!httpRequest) {
        alert("impossibile creare istanza XMLHTTP !");
        return false;
    }
    httpRequest.onreadystatechange = function() { handleContents(httpRequest, bloccoFeedBack, type); };
    httpRequest.open("GET", url, true);
    httpRequest.send(null);

}

function handleContents(httpRequest, bloccoFeedBack, type) {

    if (httpRequest.readyState == 4) {
        if (httpRequest.status == 200) {
			var sHttp = httpRequest.responseText;
			switch (type) {
				case "html":
					bloccoFeedBack.innerHTML = sHttp;
					break;
				case "text":
					bloccoFeedBack.innerText = sHttp;
					break;
				case "src":
					bloccoFeedBack.src = sHttp;
					break;	
			}
					
            // debug
            var dbg = document.getElementById("debug")
            if( ! (dbg == null )) {
                dbg.innerText =  sHttp;
            }
            
        } 
        else {
			alert("    Errore Ajax     " + httpRequest.status);
        }
    } else {
            if (httpRequest.readyState == 1) {
				switch (type) {
					case "html":
						bloccoFeedBack.innerHTML = "<i>loading ...</i>";
						break;
					case "text":
						bloccoFeedBack.innerText = "loading...";
						break;
					case "src":
						bloccoFeedBack.src = "Images/Icons/loading.gif";
						break;	
				}			
            }        
    }

}





