﻿function sendForm(){	
	
	var nome=$('nome');
	var txt=$('messaggio');
	var tst=$('messaggio').value;
	var fdb=$('fdb');
	var cnt=$('comments');
	var inc=$('inCommento');

	
	var e=0;
	
	nome.style.backgroundColor='#FFF';
	txt.style.backgroundColor='#FFF';
	
	if(trim(nome.value)==''){
		nome.style.backgroundColor='#FFC6C6';
		e++;
	}else if(trim(tst)==''){
		txt.style.backgroundColor='#FFC6C6';
		e++;
	}
	
	if(e==1){
		fdb.innerHTML='Completare il campo evidenziato';
	}else if(e>1){
		fdb.innerHTML='Completare i campi evidenziati';
	}else{
		
		cnt.innerHTML='<p><strong>Invio del messaggio in corso. Attendere prego.</strong></p><img src="../Immagini/Struttura/commonIco/wait.gif" alt="Attendere prego" />';
		var r=a();
		
		r.onreadystatechange = function() {			
			if(r.readyState==4){
				if(r.status==200){
					cnt.innerHTML=r.responseText;
					txt.value="";
					nome.value="";
				}else{
					cnt.innerHTML="<p class=\"r\">Errore durante l'invio del messaggio!</p>";
				}
			}			
		};
		r.open("POST",'../res/php/do/commenta.php',true);
		r.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		r.send("n="+nome.value+"&m="+tst+"&s=Rifugi&c=CesareMores");
	}
}

è(window, 'load', function(){	
	if($('invia')!=null){
		è($("invia"), 'click', function(){
			sendForm();
		});
	}

	hilight('rifugiM');
});
