function copyEmail(){
	document.mail.submit();
}
//	CARICA COMUNE
function load_city(a, b, c, path){
	$.ajax({
		type: "POST",
		url: path + "client_ajax.php",
		data: "type=" + a + "&id=" + b ,
		success: function(html){
			$("#" + c).html(html);
		}
	});

	if(a == 'province'){
		load_city('comune', 0, 'city', path);
	}
}
function load_template(type, id, c)
{
	$.ajax({
		type: "POST",
		url: "includes/ajax/mail_ajax.php",
		data: "type=" + type + "&id=" + id,
		success: function(html){
			$("#" + c).html(html);
		}
	});
}
//	CONTROLLI SUBMIT
function controllo_admin()
{
	if (document.form.username.value=="" | document.form.password.value=="")
	{
		alert("Attenzione alcuni campi obbligatori non sono stati inseriti!")
		return(false)
	}
}
function controllo_input()
{
	if (document.form.name.value=="")
	{
		alert("Attenzione alcuni campi obbligatori non sono stati inseriti!")
		return(false)
	}
}
function controllo_user()
{
	var espressione = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	var flag = false;

	if (document.form.email.value=="")
	{
		alert("Inserire la mail nell'apposito campo!");
		return false;
	}
	if(document.form.email.value != ''){
		if (!espressione.test(document.form.email.value))
		{
			alert("La mail inserita non è valida!");
			return false;
		}
	}
}
function controllo_cat_template()
{
	if (document.form.template_cat.value=="")
	{
		alert("Attenzione inserire il nome della categoria!");
		return false;
	}
}
function controllo_template()
{
	if (document.form.template_name.value=="")
	{
		alert("Attenzione inserire il nome del template!");
		return false;
	}
}
function conferma_submit(tipo)
{
	switch(tipo)
	{
	case "invia":
		var from = document.main_form.from.value;
		var mail_from = document.main_form.mail_from.value;
		var ogg = document.main_form.oggetto.value;
		var dest = document.main_form.destinatari.value;
		var body = document.main_form.testo.value;
		var templ = document.main_form.template_name.value;
		var limit = document.main_form.limit.value;
		var r = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
		if(from == ''){
			alert('Non hai inserito il Mittente!');
			document.main_form.from.focus();
			break;
		}else if(!r.test(mail_from)){
			alert('Email Mittente inserita non correttamente!');
			document.main_form.from.focus();
			break;
		}else if(ogg == ''){
			alert('Non hai inserito l\'Oggetto!');
			document.main_form.oggetto.focus();
			break;
		}else{
			document.getElementById('idtable').style.display = "none";//tabella
			document.getElementById('loading').style.display = "block";

			var params = [
					 {name: 'type', value: tipo},
					 {name: 'limit', value: limit},
					 {name: 'from', value: from},
					 {name: 'mail_from', value: mail_from},
					 {name: 'oggetto', value: ogg},
					 {name: 'destinatari', value: dest},
					 {name: 'testo', value: body},
					 {name: 'template_name', value: templ}
				  ];

			$.ajax({
				type: "POST",
				url: "includes/ajax/mail_ajax.php",
				data: params,
				success: function(html){
					$("#stato_invio").html(html);
				}
			});
		}
	break;

	case "allega":
		document.getElementById("progress").style.display = "block";
		document.main_form.azione.value=tipo;
		document.main_form.action="action_controller.php";
		document.main_form.submit();
	break;
	}
}

