// JavaScript Document
function caricamento() {
	document.getElementById("loading").style.display='block';
	document.getElementById("ffile").submit();
	document.getElementById("form_file").style.display='none';
	
}
function EliminaFoto(cid,id) {
	if (confirm("Sei sicuro di voler eleiminare questa foto?")) {
		document.location.href='index.php?cid='+cid+'&id='+id;
	}
}
function InviaFoto(foto) {
	alert(foto);
}
function SetNewsFolder(id) {
	document.getElementById("id_folder").value=id;
	document.form_nm.submit();
}
function EliminaCategoriaMappa(id) {
	if (confirm('Sei sicuro di voler eliminare definitivamente questa categoria?')) {
		window.location.href='index.php?id=290&canc_id='+id;
	}
}
function EliminaCategoriaMappaM(id) {
	if (confirm('Sei sicuro di voler eliminare definitivamente questa categoria?')) {
		window.location.href='index.php?id=322&canc_id='+id;
	}
}
function EliminaCategoriaAssociazione(id) {
	if (confirm('Sei sicuro di voler eliminare definitivamente questa categoria?')) {
		window.location.href='index.php?id=383&canc_id='+id;
	}
}
function EliminaPuntoMappa(id) {
	if (confirm('Sei sicuro di voler eliminare definitivamente questo punto di interesse?')) {
		window.location.href='index.php?id=291&canc_id='+id;
	}
}
function EliminaPuntoMappaM(id) {
	if (confirm('Sei sicuro di voler eliminare definitivamente questo punto di interesse?')) {
		window.location.href='index.php?id=323&canc_id='+id;
	}
}
function EliminaNews(id) {
	if (confirm('Sei sicuro di voler eliminare definitivamente questa news?')) {
		document.getElementById('idnews').value=id;
		document.getElementById('form_modifica').action='index.php?id=190';
		document.form_modifica.submit();
	}
}
function EliminaSettore(id) {
	if (confirm('Sei sicuro di voler eliminare definitivamente questo settore?')) {
		window.location.href='index.php?id=274&canc_id='+id;
	}
}
function EliminaUfficio(id) {
	if (confirm('Sei sicuro di voler eliminare definitivamente questo ufficio?')) {
		window.location.href='index.php?id=279&canc_id='+id;
	}
}
function EliminaAtto(id) {
	if (confirm('Sei sicuro di voler eliminare definitivamente questo atto?')) {
		window.location.href='index.php?id=405&canc_id='+id;
	}
}
function EliminaR(id) {
	if (confirm('Sei sicuro di voler eliminare definitivamente questa riunione?')) {
		window.location.href='index.php?id=434&canc_id='+id;
	}
}
function EliminaPratica(id) {
	if (confirm('Sei sicuro di voler eliminare definitivamente questa pratica?')) {
		window.location.href='index.php?id=280&canc_id='+id;
	}
}
function SalvaUfficio() {
	var a=(document.getElementById('nome_ufficio').value!='');
	if (a) {
		document.form_ufficio.submit();
	}else{
		alert('Inserisci almeno il nome dell\'ufficio.');
	}
}
function SalvaSettore() {
	var a=(document.getElementById('nome_settore').value!='');
	if (a) {
		document.form_settore.submit();
	}else{
		alert('Inserisci il nome del settore');
	}
}
function SalvaPratica() {
	var a=(document.getElementById('nome_pratica').value!='');
	if (a) {
		document.form_pratica.submit();
	}else{
		alert('Inserisci il nome della pratica');
	}
}
function ModificaNews(id) {
	//alert('Vai alla pagina di modifica della news');
	document.getElementById('idnews').value=id;
	document.getElementById('form_modifica').action='index.php?id=188';
	document.form_modifica.submit();
}
function SetIdCategoria(id) {
		document.getElementById("id_categoria_news").value=document.getElementById(id).value;
}
function CercaNews() {
	var a=(document.getElementById("NewsDal").value!='');
	var b=(document.getElementById("NewsAl").value!='');
	if (a || b) {
		document.form_cerca_news.submit();
	}else{
		alert("Inserire almeno una data per la ricerca");
	}
}
function DataNonValida(obj) {
	alert('Data non valida.\nInserisci le date in uno dei seguenti formati:\nggmmaa\nggmmaaaa\ndove giorno mese ed anno possono o meno essere separati dai caratteri / . -');
	//document.getElementById(obj).focus();
	//document.getElementById(obj).select();
	document.getElementById(obj).value='';
}
function normalizza_data(data) {
	var w=new String(data);
	w=w.replace(/ /g,"/");
	w=w.replace(/\./g,"/");
	w=w.replace(/-/g,"/");
	var a_w=w.split("/");
	if (a_w.length==1) {
		//alert(a_w[0]);
		return a_w[0];
	} else {
		var gg="00"+a_w[0];
		var mm="00"+a_w[1];
		var aa=a_w[2];
		var g=gg.substr(gg.length-2,2);
		var m=mm.substr(mm.length-2,2);
		var a=aa;
		//alert(g+"/"+m+"/"+a);
		return g+"/"+m+"/"+a;
	}
}
function Bisestile(anno) {
	if (parseInt(anno)%4==0) {
		return true;
	} else {
		return false;
	}
}
function DataValida(g,m,a) {
	switch (m) {
		case '01':
		case '03':
		case '05':
		case '07':
		case '08':
		case '10':
		case '12':
			//31 giorni
			if (g>0 && g<32) return true;
			break;
		case '04':
		case '06':
		case '09':
		case '11':
			//30 giorni
			if (g>0 && g<31) return true;
			break;
		case '02':
			if (Bisestile(a)) {
				if (g>0 && g<30) return true;
			} else {
			if (g>0 && g<29) return true;
			}
			break;
		default:
			return false;
	}
}
function DataVeloce(obj) {
	var x=normalizza_data(document.getElementById(obj).value);
	var d=new String(x);
	d=d.replace(/ /g,"");
	d=d.replace(/\//g,"");
	d=d.replace(/\./g,"");
	d=d.replace(/-/g,"");
	//alert(d);
	switch (d.length) {
		case 0: return false;
			break;
		case 6:
			var gg=d.substr(0,2);
			var mm=d.substr(2,2);
			var aa=d.substr(4,2);
			if (parseInt(aa)>20) {
				var aaaa='19'+aa;
			} else {
				var aaaa='20'+aa;
			}
			if (gg<'01' || gg>'31') {DataNonValida(obj); return false;}
			if (mm<'01' || mm>'12') {DataNonValida(obj); return false;}
			if (aa<'00' || aa>'99') {DataNonValida(obj); return false;}
			if (!DataValida(gg,mm,aaaa)) {DataNonValida(obj); return false;}
			document.getElementById(obj).value=gg+"/"+mm+"/"+aaaa;
			break;
		case 8:
			var gg=d.substr(0,2);
			var mm=d.substr(2,2);
			var aaaa=d.substr(4,4);
			if (gg<'01' || gg>'31') {DataNonValida(obj); return false;}
			if (mm<'01' || mm>'12') {DataNonValida(obj); return false;}
			if (aaaa<'00' || aaaa>'99') {DataNonValida(obj); return false;}
			if (!DataValida(gg,mm,aaaa)) {DataNonValida(obj); return false;}
			document.getElementById(obj).value=gg+"/"+mm+"/"+aaaa;
			break;
	default:
		DataNonValida(obj); 
		return false;
	}
}
function MostraRicerca(sez) {
    switch (sez) {
		case 'iosono':
			document.getElementById('miinteressa').style.display='none';
			document.getElementById('iosono').style.display='block';
			//document.getElementById('SezioneRicerca').innerHTML='IO SONO...';
			break;
		case 'miinteressa':
			document.getElementById('iosono').style.display='none';
			document.getElementById('miinteressa').style.display='block';
			//document.getElementById('SezioneRicerca').innerHTML='MI INTERESSA...';
			break;
	}
}
function VaiRicercaSemplice() {
	if (SCat!='') {
		document.getElementById("SCat").value=SCat;
		document.DatiRicercaSemplice.submit();
	} else {
		alert('Seleziona una delle voci sottostanti,\nper poter effettuare la ricerca semplificata.');
		return false;
	}
}
function AddRemoveI(id) {
	var value=document.getElementById(id).value;
	SCat=value;
	for (i=1;i<=50;i++) {
		if (document.getElementById("c-"+i)) {
			document.getElementById("c-"+i).checked=false;
		}
	}
	document.getElementById(id).checked=true;
}
function ElaboraDati() {
	var a=(document.getElementById('nome').value=='');
	var b=(document.getElementById('cognome').value=='');
	//var c=new Boolean(document.getElementById('sesso').value!='');
	var d=(document.getElementById('natoa').value=='');
	var e=(document.getElementById('provincia_nascita').value=='');
	var f=(document.getElementById('data_nascita').value=='');
	var g=(document.getElementById('residentea').value=='');
	var h=(document.getElementById('provincia_residenza').value=='');
	var i=(document.getElementById('indirizzo').value=='');
	var l=(document.getElementById('nr_civico').value=='');
//	alert(a);return false;
	var check=new Boolean();
	check=a || b || d || e || f || g || h || i || l;
	//alert(check);return false;
	if (check) {
		alert('Inserisci tutti i dati!');
		return false;
	}
	var i;
	var r=false;
	for (i=1;i<34;i++) {
		r=(r || (document.getElementById('c'+i).checked));
	}
	if (!r) {
		alert('Seleziona almeno un certificato.');
		return false;
	}
	document.form_autocertificazione.submit();
}

function MostraNascondiDiv(me,iddiv) {
	if (document.getElementById(me).checked) {
		document.getElementById(iddiv).style.display='block';
	} else {
		document.getElementById(iddiv).style.display='none';
	}
}
function ControllaFormScriviDilloALillo() {
	var a=(document.getElementById('nome').value!='');
	var b=(document.getElementById('cognome').value!='');
	var c=(document.getElementById('indirizzo').value!='');
	var d=(document.getElementById('localita').value!='');
	var e=(document.getElementById('provincia').value!='');
	var f=(document.getElementById('domanda').value!='');
	var g=(document.getElementById('email').value!='');
	var h=(document.getElementById('controllo_immagine').value!='');
	if (a && b && c && d && e && f && g && h) {
		document.form_invia_messaggio.submit();
	} else {
		alert('Per inviare un messaggio devi compilare tutti i campi.\nInoltre devi inserire il codice di controllo.');
	}
}
function ControllaFormRispondiDilloALillo() {
	var a=(document.getElementById('titolo').value!='');
	var b=(document.getElementById('id_domanda').value!='');
	var c=(document.getElementById('text_risposta').value!='');
	if (a && b && c) {
		document.form_risposta.submit();
	} else {
		alert('Inserisci tutti i dati.');
	}
}
function MostraLogin() {
	var a=(document.getElementById('loginform').style.display=='block');
	if (a) {
		document.getElementById('loginform').style.display='none';
	}else{
		document.getElementById('loginform').style.display='block';
	}
}
function startUpload(){
      document.getElementById('f1_upload_process').style.visibility = 'visible';
      document.getElementById('f1_upload_form').style.visibility = 'hidden';
      return true;
}
function cancAllegato(riga,id_allegato) {
	var i=riga.parentNode.parentNode.rowIndex;
	var idallegati=new String();
	idallegati=document.getElementById('allegati').value;
	var ids=new Array();
	ids=idallegati.split(",");
	var indice=-1;
	for (ii=0;ii<ids.length;ii++) {
		if (ids[ii]==id_allegato) indice=ii;
	}
	if (indice!=-1) ids.splice(indice,1);
	document.getElementById('allegati').value=ids;
	document.getElementById('tabella_allegati').deleteRow(i);
}

function insAllegato(id,allegato) {
	var x=document.getElementById('tabella_allegati').insertRow(0);
	var y=x.insertCell(0);
	var z=x.insertCell(1);
	y.innerHTML='<a href="#galleria_img" onclick="cancAllegato('+id+')"><img src="assets/templates/DefSanteramo/images/ico_elimina.gif" alt="Elimina questo allegato" /></a>';
	z.innerHTML="NEW CELL2";
}

function cancImgGalleria(riga,id_allegato) {
	var i=riga.parentNode.parentNode.rowIndex;
	var idallegati=new String();
	idallegati=document.getElementById('gal_img').value;
	var ids=new Array();
	ids=idallegati.split(",");
	var indice=-1;
	for (ii=0;ii<ids.length;ii++) {
		if (ids[ii]==id_allegato) indice=ii;
	}
	if (indice!=-1) ids.splice(indice,1);
	document.getElementById('gal_img').value=ids;
	document.getElementById('tab_immagini_news').deleteRow(i);
}
function cancImgGalleria2(id_allegato) {
	var n=new Array();
	n=id_allegato.split(".");
	/*
	var o=obj.parentNode.parentNode.parentNode.parentNode.parentNode.id;
	alert(o+'\n'+'cella_g_'+n[0]);
	*/
	var idallegati=new String();
	idallegati=document.getElementById('gal_img').value;
	var ids=new Array();
	ids=idallegati.split(",");
	var indice=-1;
	for (ii=0;ii<ids.length;ii++) {
		if (ids[ii]==id_allegato) indice=ii;
	}
	if (indice!=-1) ids.splice(indice,1);
	document.getElementById('gal_img').value=ids;
	document.getElementById('cella_g_'+n[0]).style.display='none';
}
function cancLink(id_link) {
	/*
	var n=new Array();
	n=id_allegato.split(".");
	var o=obj.parentNode.parentNode.parentNode.parentNode.parentNode.id;
	alert(o+'\n'+'cella_g_'+n[0]);
	*/
	var links=new String();
	links=document.getElementById('links').value;
	var ids=new Array();
	ids=links.split(",");
	var indice=-1;
	for (ii=0;ii<ids.length;ii++) {
		if (ids[ii]==id_link) indice=ii;
	}
	if (indice!=-1) ids.splice(indice,1);
	document.getElementById('links').value=ids;
	document.getElementById('link'+id_link).style.display='none';
}
function cancRifNormativo(riga,id_allegato) {
	var i=riga.parentNode.parentNode.rowIndex;
	var idallegati=new String();
	idallegati=document.getElementById('rif_normativi').value;
	var ids=new Array();
	ids=idallegati.split(",");
	var indice=-1;
	for (ii=0;ii<ids.length;ii++) {
		if (ids[ii]==id_allegato) indice=ii;
	}
	if (indice!=-1) ids.splice(indice,1);
	document.getElementById('rif_normativi').value=ids;
	document.getElementById('tabella_rif_normativi').deleteRow(i);
}
function VisualizzaFormAllegati() {
	if (document.getElementById('blocco_form').style.display=='block') {
		document.getElementById('blocco_form').style.display='none';
		document.getElementById('Ucontainer').style.display='block'
	}else{
		document.getElementById('Ucontainer').style.display='none';
		document.getElementById('blocco_form').style.display='block'
	}
}
function VisualizzaFormRiferimenti() {
	if (document.getElementById('blocco_form').style.display=='block') {
		document.getElementById('blocco_form').style.display='none';
		document.getElementById('Ucontainer2').style.display='block'
	}else{
		document.getElementById('Ucontainer2').style.display='none';
		document.getElementById('blocco_form').style.display='block'
	}
}
function SalvaDelibera() {
	var a=(document.getElementById('nr').value!='');
	var b=(document.getElementById('mittente').value!='');
	var c=(document.getElementById('oggetto').value!='');
	var d=(document.getElementById('data').value!='');
	if (a && b && c && d) {
		document.form_delibera.submit();
	}else{
		alert('Inserisci tutti i dati relativi alla delibera');
	}
}
function SalvaR() {
	var b=(document.getElementById('tipo').value!='');
	var d=(document.getElementById('data').value!='');
	if (b && d) {
		document.form_delibera.submit();
	}else{
		alert('Inserisci tutti i dati relativi alla riunione.');
	}
}
function SalvaDetermina() {
	var a=(document.getElementById('nr').value!='');
	var c=(document.getElementById('oggetto').value!='');
	var d=(document.getElementById('data').value!='');
	if (a &&  c && d) {
		document.form_delibera.submit();
	}else{
		alert('Inserisci tutti i dati relativi alla determina');
	}
}
function SalvaDocAlbo() {
	var a=(document.getElementById('nr').value!='');
	var b=(document.getElementById('mittente').value!='');
	var c=(document.getElementById('oggetto').value!='');
	var d=(document.getElementById('datai').value!='');
	var e=(document.getElementById('dataf').value!='');
	if (a && b && c && d && e) {
		document.form_albo.submit();
	}else{
		alert('Inserisci tutti i dati relativi al documento');
	}
}
function SalvaGaraBandoConcorso() {
	var a=(document.getElementById('data').value!='');
	var b=(document.getElementById('tipo').value!='');
	var c=(document.getElementById('oggetto').value!='');
	var d=(document.getElementById('scadenza').value!='');
	if (a && b && c && d) {
		document.form_delibera.submit();
	}else{
		alert('Inserisci tutti i dati relativi al documento');
	}
}
function SalvaRegolamento() {
	var a=(document.getElementById('data').value!='');
	var b=(document.getElementById('tipo').value!='');
	var c=(document.getElementById('oggetto').value!='');
	var d=(document.getElementById('nr').value!='');
	var e=(document.getElementById('emessoda').value!='');
	if (a && b && c && d && e) {
		document.form_delibera.submit();
	}else{
		alert('Inserisci tutti i dati relativi al documento');
	}
}
function SalvaEsito() {
	var a=(document.getElementById('dataesito').value!='');
	var b=(document.getElementById('oggettoesito').value!='');
	var e=document.getElementById('allegati').value;
	document.getElementById('allegatiesito').value=e;
	if (a && b) {
		document.form_delibera.submit();
	}else{
		alert('Inserisci tutti i dati relativi al documento');
	}
}
function EliminaDocumento(idd,idpag) {
	if (confirm('Sei sicuro di voler eliminare questo documento?')) {
		window.location.href='index.php?id='+idpag+'&canc_d='+idd;
	}
}
function EliminaEsito() {
	if (confirm('Sei sicuro di voler eliminare tutti i dati di questo esito?'))  {
		document.getElementById('dataesito').value='';
		document.getElementById('oggettoesito').value='';
		document.getElementById('allegati').value='';
		document.getElementById('allegatiesito').value='';
		document.form_delibera.submit();
	}
}
function MostraDiv(id) {
	if (document.getElementById(id)) document.getElementById(id).style.display='block';
}
function NascondiDiv(id) {
	if (document.getElementById(id)) document.getElementById(id).style.display='none';
}
function AssociaImg(img) {
	document.getElementById('immagine_news').innerHTML='<img width="125" src="assets/templates/DefSanteramo/img_news/'+img+'" align="absmiddle" />';
	document.getElementById('hidden_img').value=img;
}
function AddCancCRS(id) {
	var a=(document.getElementById(id).checked==true);
	if (a) {
		document.getElementById('CategoriaRicercaSemplificata').value+='|'+document.getElementById(id).value+'|';
	} else {
		var	value=document.getElementById('CategoriaRicercaSemplificata').value;
		var vsearch='|'+document.getElementById(id).value+'|';
		document.getElementById('CategoriaRicercaSemplificata').value=value.replace(vsearch,"");
	}
}
function Seleziona(id,value) {
	//alert(id+' '+value);
	if (document.getElementById(id)) {
		document.getElementById(id).selectedIndex=value;
	}
}
function InviaForm(id) {
	if (document.getElementById(id)) {
		document.getElementById(id).submit();
	}
}
function ImpostaValore(id,value) {
	if (document.getElementById(id)) {
		document.getElementById(id).value=value;
	}
}
function StampaPagina() {
	finestra = window.open("stampa.html",'','width=640,height=480');
}
function InviaPerEmail() {
	var pag=window.location.href;
	//alert(pag);
	window.location.href='index.php?id=313&pag='+pag;
}
function CercaIndirizzo(address) {
	geocoder = new GClientGeocoder();
    geocoder.getLatLng(address,
		function(point) {
			if (point) {
				return point.toUrlValue();
			} else {
				return false;
			}
		});
}
function MostraGalleriaFotografica() {
	document.getElementById("GalleriaFotografica").style.display='block';
}
function ControllaIndirizziEmail() {
	var a=document.getElementById("mittente").value!='';
	var b=document.getElementById("destinatari").value!='';
	if (a && b) {
		document.form_mail.submit();
	}else{
		alert('Inserisci il mittente e il/i destinatario/i.');
	}
}
function IscriviNewsletter() {
	var email=(document.getElementById("emailnews").value);
	var at=email.split("@");
	if (at.length==2) {
		document.form_newsletter.submit();
	}else{
		alert('Inserisci un indirizzo email valido');
	}
}
function CreaInviaNewsletter() {
	if (document.getElementById('inv').value!="") {
		document.getElementById('form_newsletter').submit();
	}else{
		alert('Seleziona almeno un news da inviare.');
	}
}
function InsCancNewsletter(id) {
	var value=document.getElementById(id).value;
	if (document.getElementById(id).checked) {
		if (document.getElementById('inv').value=='') {
			document.getElementById('inv').value=value;
		}else{
			document.getElementById('inv').value+=','+value;
		}
	}else{
		var s_inv=new String();
		s_inv=document.getElementById('inv').value;
		var id_inv=new Array();
		id_inv=s_inv.split(",");
		var indice=-1;
		for (ii=0;ii<id_inv.length;ii++) {
			if (id_inv[ii]==value) indice=ii;
		}
		if (indice!=-1) id_inv.splice(indice,1);
		document.getElementById('inv').value=id_inv;
	}
}
function SalvaDatiSeduta() {
	var a=(document.getElementById("data").value!='');
	if (a) {
		document.form_seduta.submit();
	}else{
		alert("Inserire la data della prossima seduta.");
	}
}