//***********************************
//chiamato in hotel_home.htm dalle home page degli hotel
function mailing_singolo(){	
    var mail = document.getElementById('campo_m').value;
    if (! (mailOK(mail))){
        alert("E-mail non valida");
        return;
    }
    
	var ajaxRequest;  
    ajaxRequest=assegnaXMLHttpRequest();

	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			var ajaxDisplay = document.getElementById('div_grazie_mailing');			
			ajaxDisplay.innerHTML = ajaxRequest.responseText;
		}
	}
	var att_mail = document.getElementById('att_mail').value;
    var att_nome = document.getElementById('att_nome').value;
    var note        = document.getElementById('note').value;
    var nome_cliente = document.getElementById('nome_cliente').value;
    var tel_cliente  = document.getElementById('tel_cliente').value;
        
    note = note.replace("&","#e#");
    
    
    //var periodo_dal  = document.getElementById('dalg').value+"-"+document.getElementById('dalm').value+"-"+document.getElementById('dala').value;
    var giorno_dal =document.form1.dalg.options[document.form1.dalg.selectedIndex].text;
	if(giorno_dal<10) giorno_dal="0"+giorno_dal;
    var mese_dal = document.form1.dalm.options[document.form1.dalm.selectedIndex].text;
	if(mese_dal<10) mese_dal="0"+mese_dal;
    var anno_dal = document.form1.dala.options[document.form1.dala.selectedIndex].text;
	
    var giorno_al =document.form1.alg.options[document.form1.alg.selectedIndex].text;
	if(giorno_al<10) giorno_al="0"+giorno_al;
    var mese_al = document.form1.alm.options[document.form1.alm.selectedIndex].text;
	if(mese_al<10) mese_al="0"+mese_al;
    var anno_al = document.form1.ala.options[document.form1.ala.selectedIndex].text;
    var periodo_dal  = giorno_dal+"-"+mese_dal+"-"+anno_dal;
    var periodo_al  = giorno_al+"-"+mese_al+"-"+anno_al;
    //var periodo_al  = document.getElementById('alg').value+"-"+document.getElementById('alm').value+"-"+document.getElementById('ala').value;
	
    
    var queryString ="att_nome=" + att_nome + "&att_mail=" + att_mail + "&note="+note+ "&campo_m=" + mail + "&nome_cliente=" + nome_cliente + "&tel_cliente=" + tel_cliente ;
    queryString +="&periodo_dal="+periodo_dal+"&periodo_al="+periodo_al;
    
    
	ajaxRequest.open("POST", "../../grazie_mailing_singolo.php", true);
   ajaxRequest.setRequestHeader("content-type", "application/x-www-form-urlencoded");
   ajaxRequest.send(queryString);
}


function mailOK(a) {
    if(a=="") return false;
    var pe=a.indexOf('.');
    var ss=a.indexOf(' ');
    var lch=a.length-1;
    var atr=a.indexOf('@');
    var att=atr+1;
    
    var sq=a.substring(0,atr); 
    var sw=a.substring(atr,pe); 
    var se=a.substring(pe,lch);
    
    if((atr<1) || (pe<=att) || (pe==lch) || (pe<1)  || (ss != -1) || (sq.length<=2) || (sw.length<=3) || (se.length<=1)) 
        return false;
    
    return true;

}

