function main() {
	Effect.Grow("img1");
	setTimeout("Effect.Grow('img2')", 100);
	setTimeout("Effect.Grow('img3')", 200);
	setTimeout("Effect.Grow('img4')", 300);
	setTimeout("Effect.Grow('img5')", 400);
}

function iscrivimi() {
	var ok = true;
	var debugMsg = 'Inserire i seguenti campi mancanti: ';
	var campiObj = $('newsletterForm').serialize(true);
	
	if(campiObj.nome == '')
	{
		debugMsg += 'Nome';
		ok = false;
	}
	if(campiObj.cognome == '')
	{
		if(!ok)
			debugMsg += ','
		debugMsg += ' Cognome';
		ok = false;
	}
	if(campiObj.email == '')
	{
		if(!ok)
			debugMsg += ','
		debugMsg += ' email';
		ok = false;
	}
	if(campiObj.citta == '')
	{
		if(!ok)
			debugMsg += ','
		debugMsg += ' Citt&#224;';
		ok = false;
	}
	if((campiObj.ragsoc == '')&&(campiObj.tipo == 'azienda'))
	{
		if(!ok)
			debugMsg += ','
		debugMsg += ' Ragione Sociale';
		ok = false;
	}
	
	debugMsg += '.';
	if(!ok)
	{
		Dialog.alert(debugMsg,
				{width:300, height:100, okLabel: "ok",
				ok:function(win) {debug("validate alert panel"); return true;}});
		return false;
	}
	
	var validate = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
	if (!validate.test(campiObj.email))
	{
      		Dialog.alert("Indirizzo e-mail non specificato correttamente",
				{width:300, height:100, okLabel: "ok",
				ok:function(win) {debug("validate alert panel"); return true;}});
		return false;
	}
	
	if(campiObj.autorizzo != 'on')
	{
		Dialog.alert("E' necessaria l'autorizzazione al trattamento dei dati",
				{width:300, height:100, okLabel: "ok",
				ok:function(win) {debug("validate alert panel"); return true;}});
		return false;
	}
	
	var campi = $('newsletterForm').serialize();
	
	httpRequest = assignXMLHttpRequest();
	url = 'newsletter.php?request=iscrivi&' + campi;
	httpRequest.open("GET", url, true);
	httpRequest.onreadystatechange = function(){ processNewsletter('iscr'); };
	httpRequest.send(null);


}

function stampa(val) {
	httpRequest = assignXMLHttpRequest();
	if(val == '1')
		url = 'newsletter.php?request=stampa';
	if(val == '0')
		url = 'newsletter.php?request=stampaDett';
    if(val == '2')
        url = 'newsletter.php?request=stampaPriv';
    if(val == '3')
        url = 'newsletter.php?request=stampaAzie';
        
	httpRequest.open("GET", url, true);
	if(val == '1')
		httpRequest.onreadystatechange = function(){ processNewsletter('stampa'); };
	if(val == '0') 
        httpRequest.onreadystatechange = function(){ processNewsletter('stampaDett'); };
    if(val == '2')
        httpRequest.onreadystatechange = function(){ processNewsletter('stampaPriv'); };
    if(val == '3')
        httpRequest.onreadystatechange = function(){ processNewsletter('stampaAzie'); };

	httpRequest.send(null);
}

function cancella() {
	var campiObj = $('cancellaForm').serialize(true);
	
	httpRequest = assignXMLHttpRequest();
	url = 'newsletter.php?request=cancella&email=' + campiObj.email;
	httpRequest.open("GET", url, true);
	httpRequest.onreadystatechange = function(){ processNewsletter('canc'); };
	httpRequest.send(null);
}

function processNewsletter(req) {
	if(httpRequest.readyState == 4)
		if(httpRequest.status == 200)
		{
			if(req == 'iscr')
			{
				var xmldoc = httpRequest.responseXML;
				
				if(xmldoc.documentElement.nodeName == 'error')
				{
					Dialog.alert("Indirizzo e-mail gi&#224; presente",
						{width:300, height:100, okLabel: "ok",
						ok:function(win) {debug("validate alert panel"); return true;}});
				}
				else Dialog.alert("Iscrizione completata",
					{width:300, height:100, okLabel: "ok",
					ok:function(win) {debug("validate alert panel"); return true;}});
				
			}
			else if (req == 'canc')
			{
				var xmldoc = httpRequest.responseXML;
				
				if(xmldoc.documentElement.nodeName == 'error')
				{
					Dialog.alert("Spiacenti, la sua email non &#232; presente sul database. Per cancellarsi dal servizio newsletter Jackpot scriva a <a href=\"mailto:noi@jackpotstaff.com\">noi@jackpotstaff.com</a>.",
						{width:300, height:100, okLabel: "ok",
						ok:function(win) {debug("validate alert panel"); return true;}});
				}
				else Dialog.alert("Utente cancellato con successo",
					{width:300, height:100, okLabel: "ok",
					ok:function(win) {debug("validate alert panel"); return true;}});
			}
			else if (req == 'stampa')
			{
				var xmldoc = httpRequest.responseXML;
				var strToPrint = '';
				var tableRoot = xmldoc.documentElement.firstChild;
				
				//alert(tableRoot.firstChild.nodeName);
				
				var row = tableRoot.firstChild;
				while(row != null)
				{
					strToPrint += row.firstChild.nextSibling.nextSibling.firstChild.nodeValue + ' | ';
					strToPrint += row.firstChild.firstChild.nodeValue + ' ';
					strToPrint += row.firstChild.nextSibling.firstChild.nodeValue + ' |<br/>';
					row = row.nextSibling;
				}
				
// 				Dialog.alert(strToPrint,
// 					{width:300, height:300, okLabel: "ok",
// 					ok:function(win) {debug("validate alert panel"); return true;}});
				
				$('content').innerHTML = strToPrint;
			}
			else if (req == 'stampaPriv')
			{
				var xmldoc = httpRequest.responseXML;
				var strToPrint = '';
				var tableRoot = xmldoc.documentElement.firstChild;
				
				//alert(tableRoot.firstChild.nodeName);
				
				var row = tableRoot.firstChild;
				while(row != null)
				{
					strToPrint += row.firstChild.nextSibling.nextSibling.firstChild.nodeValue + ' | ';
					strToPrint += row.firstChild.firstChild.nodeValue + ' ';
					strToPrint += row.firstChild.nextSibling.firstChild.nodeValue + ' |<br/>';
					row = row.nextSibling;
				}
				
// 				Dialog.alert(strToPrint,
// 					{width:300, height:300, okLabel: "ok",
// 					ok:function(win) {debug("validate alert panel"); return true;}});
				
				$('content').innerHTML = strToPrint;
			}
			else if (req == 'stampaAzie')
			{
				var xmldoc = httpRequest.responseXML;
				var strToPrint = '';
				var tableRoot = xmldoc.documentElement.firstChild;
				
				//alert(tableRoot.firstChild.nodeName);
				
				var row = tableRoot.firstChild;
				while(row != null)
				{
					strToPrint += row.firstChild.nextSibling.nextSibling.firstChild.nodeValue + ' | ';
					strToPrint += row.firstChild.firstChild.nodeValue + ' ';
					strToPrint += row.firstChild.nextSibling.firstChild.nodeValue + ' |<br/>';
					row = row.nextSibling;
				}
				
// 				Dialog.alert(strToPrint,
// 					{width:300, height:300, okLabel: "ok",
// 					ok:function(win) {debug("validate alert panel"); return true;}});
				
				$('content').innerHTML = strToPrint;
			}
			else if (req == 'stampaDett')
			{
				var xmldoc = httpRequest.responseXML;
				var strToPrint = '- ';
				var tableRoot = xmldoc.documentElement.firstChild;
				
				//alert(tableRoot.firstChild.nodeName);
				
				var row = tableRoot.firstChild;
				while(row != null)
				{
					strToPrint += row.firstChild.firstChild.nodeValue + ' ';
					strToPrint += row.firstChild.nextSibling.firstChild.nodeValue + '| ';
					strToPrint += row.firstChild.nextSibling.nextSibling.firstChild.nodeValue + '| ';
					strToPrint += row.firstChild.nextSibling.nextSibling.nextSibling.firstChild.nodeValue + '| ';
					try
					{
						strToPrint += row.firstChild.nextSibling.nextSibling.nextSibling.nextSibling.firstChild.nodeValue + ', ';
					}
					catch(e)
					{
					}
					try
					{
						strToPrint += row.firstChild.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.firstChild.nodeValue + ', ';
					}
					catch(e)
					{
					}
					try
					{
						row.firstChild.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.firstChild.nodeValue + ', ';
					}
					catch(e)
					{
					}
					try
					{
						row.firstChild.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.firstChild.nodeValue + ', ';
					}
					catch(e)
					{
					}
					try
					{
						row.firstChild.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.firstChild.nodeValue + ', ';
					}
					catch(e)
					{
						strToPrint = strToPrint.substr(0, strToPrint.length -2);
						strToPrint += '<br/>- ';
					}
					row = row.nextSibling;
				}
				strToPrint = strToPrint.substr(0, strToPrint.length -2);
				
// 				Dialog.alert(strToPrint,
// 					{width:300, height:300, okLabel: "ok",
// 					ok:function(win) {debug("validate alert panel"); return true;}});
				
				$('content').innerHTML = strToPrint;
			}
		}
	

}

function drawNewsletter(pwd)
{
	if(pwd == 'qwertmnbv')
	{
		$('container').innerHTML = "<div id=\"header\"></div><div id=\"content\"></div><div id=\"footer\"></div>";
		$('menuLeft').style.display = 'block';
	}
	else
	{
		$('container').innerHTML += "<br/><p>Password errata</p>";
		return false;
	}
}

// funzione per assegnare l'oggetto XMLHttpRequest
// compatibile con i browsers piu' recenti e diffusi
function assignXMLHttpRequest()
{
	// variabile che sara' ritornata
	var XHR = null;
 
	// informazioni sul nome del browser
	browserUtente = navigator.userAgent.toUpperCase();

	// browser standard con supporto nativo
	// non importa il tipo di browser
	if(typeof(XMLHttpRequest) === "function" || typeof(XMLHttpRequest) === "object")
		XHR = new XMLHttpRequest();
	// browser Internet Explorer
	// e' necessario filtrare la versione 4
	else if(window.ActiveXObject && browserUtente.indexOf("MSIE 4") < 0)
	{
		// la versione 6 di IE ha un nome differente
		// per il tipo di oggetto ActiveX
		if(browserUtente.indexOf("MSIE 5") < 0)
			XHR = new ActiveXObject("Msxml2.XMLHTTP");
		// le versioni 5 e 5.5 invece sfruttano lo stesso nome
		else
			XHR = new ActiveXObject("Microsoft.XMLHTTP");
	}

	return XHR;
}

