/*----------------------------INVIO MAIL-------------------------------------*/
function mandaEmail(){
	makeRequest("send_mail.php", "POST", "email=" + document.formulario.contactEmail.value + "&nome=" + document.formulario.firstName.value + "&testo=" + document.formulario.message.value, "emailMandata");
	document.getElementById("ajax-loader").style.display = "block";
}

function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
	if(chars == null)
	{
		chars = "\\s";
	}
	
	return str.toString().replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
	if(chars == null)
	{
		chars = "\\s";
	}
	
	return str.toString().replace(new RegExp("[" + chars + "]+$", "g"), "");
}





/*-----------------------------RIDIMENSIONA TEXTAREA-------------------------------*/
function sz(t) {
a = t.value.split('\n');
b=2;
for (x=0;x < a.length; x++) {
 if (a[x].length >= t.cols) b+= Math.floor(a[x].length/t.cols);
 }
b+= a.length;
if (b > t.rows) t.rows = b;
}






/*-----------------------------COMPARSA ALERT PER NOME------------------------------*/
function pos_alert_name(Obj){
	alert_name = document.getElementById("alert-name");
	alert_mail = document.getElementById("alert-mail");
	Message = document.getElementById("Message");
	Mail = document.getElementById("Mail");

	
	posY = Obj.offsetTop - 47;
	
	alert_name.style.top = posY+'px';
	alert_name.style.display='block';
	alert_mail.style.display='none';
	
	if(Message.value != "" && Mail.value != ""){
		document.getElementById("button-mail").style.display = "block";
	}
	
}
function Null_alert_name(){
	Message = document.getElementById("Message");
	Mail = document.getElementById("Mail");
	Name = document.getElementById("Name");
	alert_name = document.getElementById("alert-name");
	
	alert_name.style.display='none';
	
	if(Message.value == "" || Mail.value == "" || Name.value == ""){
		document.getElementById("button-mail").style.display = "none";
	}
}


function text_alert_name(){
	alert_name = document.getElementById("alert-name");
	
	alert_name.firstChild.firstChild.innerHTML = 'inserisci il tuo <b>nome</b> e <b>cognome</b>';	
}



/*-----------------------------COMPARSA ALERT PER E-MAIL------------------------------*/
function pos_alert_mail(Obj){
	alert_name = document.getElementById("alert-name");
	alert_mail = document.getElementById("alert-mail");
	Message = document.getElementById("Message");
	Name = document.getElementById("Name");
	
	posY = Obj.offsetTop - 65;
	
	alert_mail.style.top = posY+'px';
	alert_name.style.display='none';
	alert_mail.style.display='block';
	
	if(Message.value != "" && Name.value != ""){
		document.getElementById("button-mail").style.display = "block";
	}
}
function Null_alert_mail(){
	Message = document.getElementById("Message");
	Mail = document.getElementById("Mail");
	Name = document.getElementById("Name");
	alert_mail = document.getElementById("alert-mail");
	
	alert_mail.style.display='none';
	if(Message.value == "" || Mail.value == "" || Name.value == ""){
		document.getElementById("button-mail").style.display = "none";
	}
}

function text_alert_mail(){
	alert_mail = document.getElementById("alert-mail");
	
	alert_mail.firstChild.firstChild.innerHTML = 'inserisci la tua <b>mail</b> sulla quale ti possiamo contattare';	
}



/*-----------------------------COMPARSA ALERT PER MESSAGGIO------------------------------*/
function pos_alert_message(Obj){
	alert_message = document.getElementById("alert-message");
	
	posY = Obj.offsetTop - 28;
	
	alert_message.style.top = posY+'px';
	alert_message.style.display='block';
}
function Null_alert_message(){
	Message = document.getElementById("Message");
	Mail = document.getElementById("Mail");
	Name = document.getElementById("Name");
	alert_name = document.getElementById("alert-name");
	alert_mail = document.getElementById("alert-mail");
	alert_message = document.getElementById("alert-message");
	
	alert_message.style.display='none';
	alert_name.style.display='none';
	alert_mail.style.display='none';
	
	if(Message.value != "" && Name.value != ""){
		document.getElementById("button-mail").style.display = "block";
	}
}

function text_alert_message(){
	alert_message = document.getElementById("alert-message");
	
	alert_message.firstChild.firstChild.innerHTML = 'inserisci una <b>domanda</b>, un <b>consiglio</b> una <b>richiesta</b>, quello che preferisci :-)';	
}



//CORREZIONI
function correzioni(Obj){
	var textarea = Obj;
	var volgarita = document.getElementById('volgarita');
	var alert_message = document.getElementById("alert-message");

	//CONTROLLO PAROLACCE
	textarea.value = textarea.value.replace(/cazzo/gi,"xxxxx")
	textarea.value = textarea.value.replace(/troia/gi,"xxxxx")
	textarea.value = textarea.value.replace(/puttana/gi,"xxxxxxx")
	textarea.value = textarea.value.replace(/lesbica/gi,"xxxxxxx")
	textarea.value = textarea.value.replace(/fottiti/gi,"xxxxxxx")
	textarea.value = textarea.value.replace(/porco/gi,"xxxxx")
	textarea.value = textarea.value.replace(/figa/gi,"xxxx")
	textarea.value = textarea.value.replace(/pompino/gi,"xxxxxxx")
	textarea.value = textarea.value.replace(/sborra/gi,"xxxxxx")
	textarea.value = textarea.value.replace(/porca/gi, 'xxxxx')
	textarea.value = textarea.value.replace(/stronzo/gi,"xxxxxxx")
	textarea.value = textarea.value.replace(/stronza/gi,"xxxxxxx")
	textarea.value = textarea.value.replace(/coglioni/gi,"xxxxxxxx")
	textarea.value = textarea.value.replace(/minchia/gi,"xxxxxx")
	textarea.value = textarea.value.replace(/fottuta/gi,"xxxxxxxx")
	textarea.value = textarea.value.replace(/fottere/gi,"xxxxxxxx")
	textarea.value = textarea.value.replace(/idiota/gi,"xxxxx")
	textarea.value = textarea.value.replace(/coglioni/gi,"xxxxxxxx")
	textarea.value = textarea.value.replace(/coglione/gi,"xxxxxxxx")
	textarea.value = textarea.value.replace(/fuck/gi,"xxxx")	
	textarea.value = textarea.value.replace(/pirla/gi,"xxxxx")	
	textarea.value = textarea.value.replace(/deficente/gi,"xxxxxxxxx")
	textarea.value = textarea.value.replace(/scemo/gi,"xxxxx")	
	textarea.value = textarea.value.replace(/scema/gi,"xxxxx")
	textarea.value = textarea.value.replace(/vaffanculo/gi,"xxxxxxxxxx")	
	textarea.value = textarea.value.replace(/cretino/gi,"xxxxxx")	
	
	//CONTROLLO ORTOGRAFICO
	textarea.value = textarea.value.replace(/gesu/gi,"Gesù")
	textarea.value = textarea.value.replace(/gesù/gi,"Gesù")
	textarea.value = textarea.value.replace(/senzo/gi,"senso")
	textarea.value = textarea.value.replace(/senzi/gi,"sensi")
	textarea.value = textarea.value.replace(/penzi/gi,"pensi")
	textarea.value = textarea.value.replace(/penza/gi,"pensa")
	textarea.value = textarea.value.replace(/penzo/gi,"penso")
	textarea.value = textarea.value.replace(/aqua/gi,"acqua")
	textarea.value = textarea.value.replace(/un'amico/gi,"un amico")
	textarea.value = textarea.value.replace(/un'altro/gi,"un altro")
	textarea.value = textarea.value.replace(/un amica/gi,"un'amica")
	textarea.value = textarea.value.replace(/un altra/gi,"un'altra")
	textarea.value = textarea.value.replace(/provincie/gi,"province")
	textarea.value = textarea.value.replace(/superfice/gi,"superficie")
	textarea.value = textarea.value.replace(/scenza/gi,"scienza")
	textarea.value = textarea.value.replace(/conoscienza/gi,"conoscenza")
	textarea.value = textarea.value.replace(/coscenza/gi,"coscienza")
	textarea.value = textarea.value.replace(/sufficente/gi,"sufficiente")
	textarea.value = textarea.value.replace(/blù/gi,"blu")
	textarea.value = textarea.value.replace(/propio/gi,"proprio")
	textarea.value = textarea.value.replace(/accellerare/gi,"accelerare")
	textarea.value = textarea.value.replace(/collutazione/gi,"colluttazione")
	textarea.value = textarea.value.replace(/eccezzionale/gi,"eccezionale ")
	textarea.value = textarea.value.replace(/esterefatto/gi,"esterrefatto")
	textarea.value = textarea.value.replace(/pressocché/gi,"pressoché")
	textarea.value = textarea.value.replace(/esterefatto/gi,"esterrefatto")
	textarea.value = textarea.value.replace(/appropiato/gi,"appropriato")
	textarea.value = textarea.value.replace(/areoporto/gi,"aeroporto")
	textarea.value = textarea.value.replace(/esterefatto/gi,"esterrefatto")
	
	//punteggiatura
	textarea.value = textarea.value.replace(/,[\s]*/g,", ");
	textarea.value = textarea.value.replace(/\.[\s]*/g,". ");
	textarea.value = textarea.value.replace(/\?[\s]*/g,"? ");
	textarea.value = textarea.value.replace(/\![\s]*/g,"! ");
	textarea.value = textarea.value.replace(/\n\n\n/gi,"")
	
	
	textarea.value.search('xxx')=='-1'? textarea.style.border='1px solid #D2D0D0':avviso(Obj);
}



function avviso(Obj){
	volgarita = document.getElementById("volgarita");
	alert_message = document.getElementById("alert-message");
	
	volgarita.firstChild.firstChild.innerHTML = 'stai inserendo dei termini <b>volgari</b>, questa mail non verrà spedita se non correggi!';	
	Obj.style.border ='1px solid red'
	//volgarita.style.display='block';
	if(alert_message.style.display == 'block'){
		volgarita.style.top = alert_message.offsetTop + alert_message.offsetHeight + 3 + 'px';
	}else{
		volgarita.style.top = Obj.offsetTop + volgarita.offsetHeight/2 + 'px';
	}
}


function send_control(){
	Name = document.getElementById("Name");
	Mail = document.getElementById("Mail");
	if(Name.value != "" && Mail.value != ""){
		document.getElementById("button-mail").style.display = "block";
	}
	if(Name.value == ""){
		alert_name = document.getElementById("alert-name");
		alert_name.style.display = "block"
		alert_name.firstChild.firstChild.innerHTML = '<b>Ricorda il Nome!</b>';
		
		posY = Name.offsetTop - 28;
		alert_name.style.top = posY+'px';
	}
	if(Mail.value == ""){
		alert_mail = document.getElementById("alert-mail");
		alert_mail.style.display = "block"
		alert_mail.firstChild.firstChild.innerHTML = '<b>Ricorda la mail!</b>';
		
		posY = Mail.offsetTop - 28;
		alert_mail.style.top = posY+'px';
	}
}




















