var xmlHttp;

function GetXmlHttpObject() {
	var xmlHttp=null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		//Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}

function isEmail(strEmail)
{
	validRegExp = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	if (strEmail.search(validRegExp) == -1) {
	  //alert(lblAlert);
	  return false;
	}
	return true;
}

function spedisciNewsletter(par,tot) 
{
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	
	document.getElementById("loading").style.display = "block";

	var url="ajax_spedisciMail.php";
	url+="?p="+par;
	url+="&sid="+Math.random();
	
	xmlHttp.onreadystatechange = function () {
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
			if (xmlHttp.responseText != "") {
				//cambio tendina paese
				document.getElementById("numeroMailSpedite").innerHTML=xmlHttp.responseText;
				if (xmlHttp.responseText < tot) {
					document.getElementById("pulsanteContinua").innerHTML="<a href=\"javascript:spedisciNewsletter("+xmlHttp.responseText+", "+tot+");\" class=\"aindice\">Continua...</a>";
				} else {
					document.getElementById("pulsanteContinua").innerHTML="FINITO";
				}
				document.getElementById("loading").style.display = "none";
			}
		} 
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function spedisciAtutti(par,tot) 
{
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	
	document.getElementById("loading").style.display = "block";

	var url="ajax_spedisciAtutti.php";
	url+="?p="+par;
	url+="&sid="+Math.random();
	
	xmlHttp.onreadystatechange = function () {
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
			if (xmlHttp.responseText != "") {
				//cambio tendina paese
				document.getElementById("numeroMailSpedite").innerHTML=xmlHttp.responseText;
				if (xmlHttp.responseText < tot) {
					document.getElementById("pulsanteContinua").innerHTML="<a href=\"javascript:spedisciAtutti("+xmlHttp.responseText+", "+tot+");\" class=\"aindice\">Continua...</a>";
				} else {
					document.getElementById("pulsanteContinua").innerHTML="FINITO";
				}
				document.getElementById("loading").style.display = "none";
			}
		} 
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function validationApplicationFormConCaptcha()
{
	errore = 0;
	msg = "";

	xmlHttp = GetXmlHttpObject();
	if (xmlHttp==null) 
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	
	if (document.getElementById("cognome").value == "") 
	{
		errore = 1;
		msg += "Occorre inserire il cognome<br />";
	}
	if (document.getElementById("nome").value == "")
	{
		errore = 1;
		msg += "Occorre inserire il nome<br />";
	}
	if (document.getElementById("email").value == "") 
	{
		errore = 1;
		msg += "Occorre inserire l'indirizzo email<br />";
	}
	if (!isEmail(document.getElementById("email").value))
	{
		errore = 1;
		msg += "Occorre inserire  un indirizzo email valido<br />";
	}
	if ((document.getElementById("telefono").value == "") && (document.getElementById("cellulare").value == "")) 
	{
		errore = 1;
		msg += "Occorre inserire un recapito telefonico<br />";
	}
	
	
	if (errore == 0) {
		//proseguo
		n = document.getElementById("nome").value;
		c = document.getElementById("cognome").value;
		t = document.getElementById("telefono").value;
		e = document.getElementById("email").value;
		m = document.getElementById("cellulare").value;
		p = document.getElementById("professione").value;
		i = document.getElementById("idCorso").value;
		dom = document.getElementById("recaptcha_challenge_field").value;
		ris = document.getElementById("recaptcha_response_field").value;
		var url="/ajax/CHKapplicationForm.php";
		url+="?e="+e;
		url+="&c="+c;
		url+="&n="+n;
		url+="&t="+t;
		url+="&m="+m;
		url+="&p="+p;
		url+="&i="+i;
		url+="&dom="+dom;
		url+="&ris="+ris;
		url+="&sid="+Math.random();

		xmlHttp.onreadystatechange = function () {
			if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
				if (xmlHttp.responseText != "") {
					//erorri: li visualizzo
					$.prompt(xmlHttp.responseText);
					Recaptcha.reload();
				} else {
					//indirizzo registrato
					function mycallbackfunc(v,m,f){
						$.prompt('i clicked ' + v);
						document.getElementById("email").value = "";
						document.getElementById("cognome").value = "";
						document.getElementById("nome").value = "";
						document.getElementById("telefono").value = "";
						document.getElementById("cellulare").value = "";
						window.close();
					}

					$.prompt("Grazie per la tua iscrizione", { callback: mycallbackfunc });
					
				}
			} 
		}
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
		
	} else {
		$.prompt(msg);
	}
}

function validationApplicationForm()
{
	errore = 0;
	msg = "";

	xmlHttp = GetXmlHttpObject();
	if (xmlHttp==null) 
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	
	if (document.getElementById("cognome").value == "") 
	{
		errore = 1;
		msg += "Occorre inserire il cognome<br />";
	}
	if (document.getElementById("nome").value == "")
	{
		errore = 1;
		msg += "Occorre inserire il nome<br />";
	}
	if (document.getElementById("email").value == "") 
	{
		errore = 1;
		msg += "Occorre inserire l'indirizzo email<br />";
	}
	if (!isEmail(document.getElementById("email").value))
	{
		errore = 1;
		msg += "Occorre inserire  un indirizzo email valido<br />";
	}
	if ((document.getElementById("telefono").value == "") && (document.getElementById("cellulare").value == "")) 
	{
		errore = 1;
		msg += "Occorre inserire un recapito telefonico<br />";
	}
	
	
	if (errore == 0) {
		//proseguo
		n = document.getElementById("nome").value;
		c = document.getElementById("cognome").value;
		t = document.getElementById("telefono").value;
		e = document.getElementById("email").value;
		m = document.getElementById("cellulare").value;
		p = document.getElementById("professione").value;
		i = document.getElementById("idCorso").value;
		//dom = document.getElementById("recaptcha_challenge_field").value;
		//ris = document.getElementById("recaptcha_response_field").value;
		var url="/ajax/CHKapplicationForm.php";
		url+="?e="+e;
		url+="&c="+c;
		url+="&n="+n;
		url+="&t="+t;
		url+="&m="+m;
		url+="&p="+p;
		url+="&i="+i;
		//url+="&dom="+dom;
		//url+="&ris="+ris;
		url+="&sid="+Math.random();

		xmlHttp.onreadystatechange = function () {
			if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
				if (xmlHttp.responseText != "") {
					//erorri: li visualizzo
					$.prompt(xmlHttp.responseText);
					//Recaptcha.reload();
				} else {
					//indirizzo registrato
					function mycallbackfunc(v,m,f){
						$.prompt('i clicked ' + v);
						document.getElementById("email").value = "";
						document.getElementById("cognome").value = "";
						document.getElementById("nome").value = "";
						document.getElementById("telefono").value = "";
						document.getElementById("cellulare").value = "";
						window.close();
					}

					//$.prompt("Grazie per la tua iscrizione", { callback: mycallbackfunc });
					$.prompt("La sua domanda di pre-iscrizione a EFLIT "+document.getElementById("idCorso").options[document.getElementById("idCorso").selectedIndex].text+" e' stata inviata con successo.<br />Poco dopo il termine previsto per la scadenza delle pre-iscrizioni, le invieremo per posta elettronica il modulo di iscrizione e il programma definitivo del corso.<br />Nel frattempo, per qualsiasi richiesta o chiarimento, non esiti a contattare Francesca Piccoli (piccoli@englishforlaw.it - cell: 348 0443862)<br /><br />Con i migliori saluti,<br />L'amministrazione EFLIT", { callback: mycallbackfunc });
					
				}
			} 
		}
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
		
	} else {
		$.prompt(msg);
	}
}

function cambio_pagina(p) {
	document.forms['entryform'].npagina.value = p;
	document.forms['entryform'].submit();
}

function apri_finestra(pagina,w,h) { 
	var idw=window.open(pagina,'EFLIT','status=no,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no, height='+h+',width='+w ); 
	idw.focus();
}

function apri_evento(pagina,w,h) {
	var idw=window.open(pagina,'evento','status=no,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes, height='+h+',width='+w );
	idw.focus();
}

function Archivio (data,m){
	var iw=window.open('popuparchivionews.php?date=' + data + '&m=' + m,'Archivio','toolbar=0,location=0,directories=0,menuBar=0,scrollbars=1,resizable=0,width=620,height=450,left=0,top=0');
    	iw.focus();
}

function apri_faq(idd) {
	var iw=window.open('risposta.php?id=' + idd,'FAQ','height=300,width=680,status=no,toolbar=no,menubar=no,location=no,scrollbars=no,resizable=yes');
	iw.focus();
}

function cambio_paginafoto(p) {
	document.forms['paginafoto'].npagina.value = p;
	document.forms['paginafoto'].submit();
}

function cambio_categoriafoto(p) {
	document.forms['catfoto'].idcat.value = p;
	document.forms['catfoto'].submit();
}
function apri_credits(pagina,w,h) {
	var idw=window.open(pagina,'cartina','status=no,statusbar=no,toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no, height='+h+',width='+w );
	idw.focus();
}
function entra_sito() {
	//document.forms['form1'].npagina.value = p;
	document.forms['form1'].submit();
}


