function showLoginScheda(elemento) {
	
	if (document.getElementById(elemento).style.display == 'block') {
	
		document.getElementById(elemento).style.display = 'none';
	}
	else {
	
		document.getElementById(elemento).style.display = 'block';
	
	}

}

function istanzaXHR() {
	
	var obj;
	
	if (window.XMLHttpRequest) {

		obj = new XMLHttpRequest();
	
	} else if (window.ActiveXObject) {
	
		obj = new ActiveXObject("Microsoft.XMLHTTP");
	
	}
	
	return obj;

}

function inviaXHR1(obj,url,azione,attr,attr1) {
	
	try {	

		obj.open("POST", url, true);	// Preparazione comunicazione
		obj.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		
		var parametri = "";

		if (azione == 'inviaMail') {	
			
			totaleEL = document.forms["msg"].elements.length-1;
			
			for (i=0;i<=totaleEL;i++) {
				
				if (document.forms["msg"].elements[i].name == "descrizione") { parametri += "&"+document.forms["msg"].elements[i].name+"="+document.forms["msg"].elements[i].value; }
				else if (document.forms["msg"].elements[i].name == "tipo") { parametri += "&"+document.forms["msg"].elements[i].name+"="+document.forms["msg"].elements[i].value; }
				else if (document.forms["msg"].elements[i].name == "scheda") { parametri += "&"+document.forms["msg"].elements[i].name+"="+document.forms["msg"].elements[i].value; }
				else if (document.forms["msg"].elements[i].name == "titlemenu")  { parametri += "&"+document.forms["msg"].elements[i].name+"="+document.forms["msg"].elements[i].value; }
				else if (document.forms["msg"].elements[i].name == "titlesubmenu"){ parametri += "&"+document.forms["msg"].elements[i].name+"="+document.forms["msg"].elements[i].value; }
				else if (document.forms["msg"].elements[i].name == "autore") { parametri += "&"+document.forms["msg"].elements[i].name+"="+document.forms["msg"].elements[i].value; }
				else if (document.forms["msg"].elements[i].name == "autore_id") { parametri += "&"+document.forms["msg"].elements[i].name+"="+document.forms["msg"].elements[i].value; }
			
			}
			
			obj.onreadystatechange = function() { sendEmail(obj, attr, attr1); };
			obj.send("action="+azione+parametri);
			
		} 
	}	catch (e) {
		
			alert("Errore: "+e);
		
	}
}

function inviaMail(attr,attr1) {
	
	if (attr.descrizione.value) {
			
		inviaXHR1(obj,"/ajax.php","inviaMail",attr,attr1);
	
	} else {
						
		document.getElementById('errormsg').innerHTML = '*Tutti i campi sono obbligatori.';

	}
}

obj=istanzaXHR();

function sendEmail(obj, attr, attr1) {
	
	if (obj.readyState == 4) { 
			
			if (obj.status == 200) { 
				
					if (obj.responseText == 1) {
						
						if (attr.titlemenu.value) { myUrl = "/"+attr.titlemenu.value; }
						else if (attr.titlesubmenu.value) { myUrl += "/"+attr.titlesubmenu.value; }
													
						document.getElementById('editor_guida').innerHTML = (attr1 == 1) ? "<table width='100%'><tr><td>Ti ringranziamo per il tuo contributo.</td></tr><tr><td align='right'><input class=\"bottonenew\" type=\"button\" value=\"chiudi\" onClick=\"javascript:location.href='/aeroporti/scheda/"+attr.scheda.value+myUrl+"'\"; /></td></tr></table>": "<table width='100%'><tr><td>Ti ringranziamo per il tuo contributo.</td></tr><tr><td align='right'><input class=\"bottonenew\" type=\"button\" value=\"chiudi\" onClick=\"javascript:location.href='/compagnie/scheda/"+attr.scheda.value+myUrl+"'\"; /></td></tr></table>";
										
					}	else {				
						
						document.getElementById('errormsg').innerHTML = "Si è verificato un'errore. Si prega di riprovare più tardi.";
					
					}
				
			} else {

			alert("Errore function sendEmail: "+obj.status);

		}
	} 
}