var XMLHTTP;
var idcal
var UltimoAGG

function aggiornaRisultatiPartitaSecca(idCalendario)
{
    {
        var url = "ajax/newcalendariodettRefresh.asp?idcal="+idCalendario;
        XMLHTTP = QualeBrowser(GestioneStatoPS);
        XMLHTTP.open("GET", url, true);
        XMLHTTP.send(null);
    }
}

function GestioneStatoPS()
{
    if (XMLHTTP.readyState == 4)
    {
        
        var Z = XMLHTTP.responseText.split("|");
	var Y = Z[1];
	Z.pop();
        if (UltimoAGG == undefined) 
        	UltimoAGG = Z;
        var secondSplit;
        for (var H = 0; H<Z.length;H++) {
        	secondSplit = Z[H].split(";");
        	document.getElementById("result"+ secondSplit[0]).innerHTML = secondSplit[1];
        	if (Z[H] == UltimoAGG[H])
        		document.getElementById("result"+ secondSplit[0]).parentNode.style.backgroundColor = "";
        	else
        		document.getElementById("result"+ secondSplit[0]).parentNode.style.backgroundColor = "red";
        document.getElementById("resulttesto"+ secondSplit[0]).innerHTML = Y;
        }
        UltimoAGG = Z;
    }
}

function aggiornaRisultati(ids,gg)
{
    {
        var url = "ajax/newcalendariorefresh.asp?ids="+ids+"&gg="+gg;
        XMLHTTP = QualeBrowser(GestioneStatoAgg);
        XMLHTTP.open("GET", url, true);
        XMLHTTP.send(null);
    }
}

function GestioneStatoAgg()
{
    if (XMLHTTP.readyState == 4)
    {
        
        var Z = XMLHTTP.responseText.split("|");
        Z.pop();
        var secondSplit;
        for (var H = 0; H<Z.length;H++) {
        	secondSplit = Z[H].split(";");
        	document.getElementById("result"+ secondSplit[0]).innerHTML = secondSplit[1];
        }
    }
}

function aggiornaRisultatiPartiteInCorso(data)
{
    {
        var url = "ajax/partiteincorsoc5lRefresh.asp?Date="+data;
        XMLHTTP = QualeBrowser(GestioneStatoPIC);
        XMLHTTP.open("GET", url, true);
        XMLHTTP.send(null);
    }
}

function GestioneStatoPIC()
{
    if (XMLHTTP.readyState == 4)
    {
        
        var Z = XMLHTTP.responseText.split("|");
	Z.pop();
        if (UltimoAGG == undefined) 
        	UltimoAGG = Z;
        var secondSplit;
        for (var H = 0; H<Z.length;H++) {
        	secondSplit = Z[H].split(";");
        	document.getElementById("result"+ secondSplit[0]).innerHTML = secondSplit[1];
        	if (Z[H] == UltimoAGG[H])
        		document.getElementById("result"+ secondSplit[0]).parentNode.style.backgroundColor = "";
        	else
        		document.getElementById("result"+ secondSplit[0]).parentNode.style.backgroundColor = "red";
        }
        UltimoAGG = Z;
    }
}


function RinviaPartita(status,stringa)
{
    idcal = stringa
    if (stringa.length > 0)
    {
        var url = "ajax/rinviata.asp?scelta=" + status + "&par=" + stringa;
        XMLHTTP = QualeBrowser(GestioneStato);
        XMLHTTP.open("GET", url, true);
        XMLHTTP.send(null);
    }
    else
    {
        document.getElementById("result"+ stringa).innerHTML = "";
        document.getElementById("resultID"+ stringa).innerHTML = "";
    } 
}

function TogliRinviaPartita(stringa)
{
    idcal = stringa
    if (stringa.length > 0)
    {
        var url = "ajax/rinviata.asp?scelta=0&par=" + stringa;
        XMLHTTP = QualeBrowser(GestioneStato);
        XMLHTTP.open("GET", url, true);
        XMLHTTP.send(null);
    }
    else
    {
        document.getElementById("result"+ stringa).innerHTML = "";
        document.getElementById("resultID"+ stringa).innerHTML = "";
    } 
}

function GestioneStato()
{
    if (XMLHTTP.readyState == 4)
    {
        var R = document.getElementById("result"+ idcal);
        var ID = document.getElementById("resultID"+ idcal);
        R.innerHTML = XMLHTTP.responseText;
        if (XMLHTTP.responseText == "rinv.")
        {	
        	ID.innerHTML = "<a href=\"#\" onClick=\"TogliRinviaPartita('"+idcal+"')\" id=\"M\">Norm.</a> <a href=\"#\" onClick=\"RinviaPartita('2','"+idcal+"')\" id=\"M\">Sosp.</a>";
        }
        else if (XMLHTTP.responseText == "sosp.")
        {
        	ID.innerHTML = "<a href=\"#\" onClick=\"TogliRinviaPartita('"+idcal+"')\" id=\"M\">Norm.</a> <a href=\"#\" onClick=\"RinviaPartita('1','"+idcal+"')\" id=\"M\">Rinv.</a>";
        }
        else
        {
        	ID.innerHTML = "<a href=\"#\" onClick=\"RinviaPartita('1','"+idcal+"')\" id=\"M\">Rinv.</a> <a href=\"#\" onClick=\"RinviaPartita('2','"+idcal+"')\" id=\"M\">Sosp.</a>";
        }
    }
}

function QualeBrowser(QualeBrowser)
{
    if (navigator.userAgent.indexOf("MSIE") != (-1))
    {
        var Classe = "Msxml2.XMLHTTP";
        if (navigator.appVersion.indexOf("MSIE 5.5") != (-1));
        {
            Classe = "Microsoft.XMLHTTP";
        } 
        try
        {
            OggettoXMLHTTP = new ActiveXObject(Classe);
            OggettoXMLHTTP.onreadystatechange = QualeBrowser;
            return OggettoXMLHTTP;
        }
        catch(e)
        {
            alert("Errore: l'ActiveX non verrą eseguito!");
        }
    }
    else if (navigator.userAgent.indexOf("Mozilla") != (-1))
    {
        OggettoXMLHTTP = new XMLHttpRequest();
        OggettoXMLHTTP.onload = QualeBrowser;
        OggettoXMLHTTP.onerror = QualeBrowser;
        return OggettoXMLHTTP;
    }
    else
    {
        alert("L'esempio non funziona con altri browser!");
    }
}

function utenticonnessi()
{
    {
        var url = "ajax/contautenti.asp";
        XMLHTTP = QualeBrowser(GestioneStatoUC);
        XMLHTTP.open("GET", url, true);
        XMLHTTP.send(null);
    }
}

function GestioneStatoUC()
{
    if (XMLHTTP.readyState == 4)
    {
        
        var Z = XMLHTTP.responseText;
        document.getElementById("utenticonnessi").innerHTML = Z;
    }
}         

function risultatoagg(stringa)
{
    {
        var url = "liveupdate/update2.asp?DB=" + stringa;
        XMLHTTP = QualeBrowser(GestioneStatorisultatoagg);
        XMLHTTP.open("GET", url, true);
        XMLHTTP.send(null);
    }
}

function GestioneStatorisultatoagg()
{
    if (XMLHTTP.readyState == 4)
    {
        
        var Z = XMLHTTP.responseText;
        document.getElementById("risultatoagg").innerHTML = Z;
    }
} 

