
var xmlHttp = createXmlHttpRequestObject();

function createXmlHttpRequestObject()
{
	var xmlHttp;
	try
	{
		xmlHttp = new XMLHttpRequest();
	}
	catch(e)
	{
		var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
										"MSXML2.XMLHTTP.5.0",
										"MSXML2.XMLHTTP.4.0",
										"MSXML2.XMLHTTP.3.0",
										"MSXML2.XMLHTTP",
										"Microsoft.XMLHTTP");
		for(var i=0; i < XmlHttpVersions.length && !xmlHttp; i++)
		{
			try
			{
				xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
			}
			catch(e) {}
		}
	}
	if(!xmlHttp)
		alert("Impossibile creare l'oggetto");
	else
		return xmlHttp;
}

function handleRequestStateChange()
{
	if(xmlHttp.readyState == 4)
	{
		if(xmlHttp.status == 200)
		{
			try
			{
				handleServerResponse();
			}
			catch(e)
			{
				//alert("Non leggo alcuna risposta:\n" + e.toString());
			}
		}
		else
		{
			//alert("Errore:\n" + xmlHttp.statusText);
		}
	}
}

// Processo funzione che gestisce il resto

function process()
{
	if(xmlHttp)
	{
		try
			{
			xmlHttp.open("GET","includes/ajax.php?func=pvt", true);
			xmlHttp.onreadystatechange = handleRequestStateChange;
			xmlHttp.send(null);
		}
		catch (e)
		{
			alert("Impossibile connettersi allo script:\n" + e.toString());
		}
	}
}

// Risposta funzione che gestisce la risposta da parte dello script php

function handleServerResponse()
{
	var res = xmlHttp.responseText;
	if(res == 1) {
		GB_showCenter('Hai un nuovo messaggio privato!', 'http://www.napulee.net/new_msg.php','150','350');
	}
 setTimeout("process();", 30000);
}
	
