/*
#####################################################################################################
FUNZIONE POP UP UPLOAD ALLEGATI
#####################################################################################################
*/
function addAllegato(){
	var w = 360;
	var h = 220;
	var x=( screen.Width - w )/2;
	var y=( screen.Height - h )/2;
	var win=window.open("comunicati/uploadAllegato.php","allegato","resizable=0,width= "+w+" ,height="+h+", status=0, left="+x+", top="+y+", scrollbars=0, menubar=0, toolbars=0, directories=0");
	win.focus();
}


function deleteAllegato(sezione, tabella, idAllegato){
	var del=window.open(sezione + "/deleteFileAllegato.php?tabella="+tabella+"&idAllegato="+idAllegato, "delete", "width=4, height=3, scrollbars=0, status=0, menubar=0, toolbars=0, directories=0, left=4000, top=3000");
}



/*
#####################################################################################################
FUNZIONE DI NAVIGAZIONE
#####################################################################################################
*/
function eseguiAzione(file, azione, idCat, method, start){
	var nomeForm=document.navigator;
	nomeForm.action=file+'.php';
	nomeForm.method=method;
	nomeForm.azione.value=azione;
	nomeForm.start.value=start;
	nomeForm.idCat.value=idCat;
	nomeForm.submit();
}

/*
#####################################################################################################
FUNZIONE PER LE OPERAZIONI DA ESEGUIRE
#####################################################################################################
*/
function eseguiOperazione(azione, id, nomeForm){
	var thisForm=document.forms[nomeForm];
	switch (azione){
		case "insertCat":
			
			
			thisForm.azione.value=azione;
			thisForm.submit();
		break;

		
		
		
		
		
		case "insertCom":
		case "updateCom":
			messaggioType="ERRORE";

			if(thisForm.idCat)
				if(alertControlForm(thisForm.idCat, 'Categoria')==false) return;
				if(alertControlForm(thisForm.numero, 'Numero del comunicato')==false) return;
				if(alertControlForm(thisForm.gg, 'Giorno del comunicato')==false) return;
				if(alertControlForm(thisForm.mm, 'Mese del comunicato')==false) return;
				if(alertControlForm(thisForm.aa, 'Anno del comunicato')==false) return;
				if(alertControlForm(thisForm.testo, 'Testo del comunicato')==false) return;
	thisForm.azione.value=azione;
			thisForm.submit();
		break;
		
		
		
		
		case "updateCat":
			
			/*
			for(var i=1; i<=numeroLingue; i++){
				nomeTemp="titolo"+i;
				if(alertControlForm(thisForm.elements[nomeTemp], 'categoria')==false) return;
			}
			*/
			
			thisForm.azione.value=azione;
			thisForm.submit();
		break;
		
		case "deleteCat":
		case "deleteCom":
		case "archiveCom":
		case "resumeCom":
		case "archivePhoto":
		case "resumePhoto":
			
			var cliccato=false;
			var frase="";
			
			for(var i=0; i<thisForm.elements.length; i++){
				if(thisForm.elements[i].type=="checkbox"){
					if(thisForm.elements[i].checked) cliccato=true;
				}
			}
			if(!cliccato){
				messaggioType="ERRORE";
				messaggioAlert="Selezionare almeno un oggetto";
				gDialog.Display();
           		return;
			}
			
				if(azione=="deleteCom") messaggioAlert="Sei sicuro di voler cancellare questi comunicati e tutti gli allegati ad esso associati?";
			if(azione=="deleteCat") messaggioAlert="Sei sicuro di voler cancellare questa categoria e tutti i comunicati ad essa associati?";
			else if(azione=="archiveCom") messaggioAlert="Sei sicuro di voler archiviare questo Comunicato?";
			else if(azione=="deletePhoto") messaggioAlert="Sei sicuro di voler cancellare questa foto?";
			else if(azione=="visiblePhoto") messaggioAlert="Sei sicuro di voler rendere visibile online questa foto?";
			else if(azione=="unvisiblePhoto") messaggioAlert="Sei sicuro di voler rendere invisibile questa foto?";
			else if(azione=="archivePhoto") messaggioAlert="Sei sicuro di voler archiviare questa foto?";
			else if(azione=="resumePhoto") messaggioAlert="Sei sicuro di voler ripristinare questa foto?";
			
			messaggioType="CONFERMA";
			richiamaScript=nomeForm;
			thisForm.azione.value=azione;
			gDialog.Display();
			
		break;
		
	}
}

/*
#####################################################################################################
FUNZIONE CONTROLLO DEI FORM
#####################################################################################################
*/
function alertControlForm(campo, variabile){
	tipo=campo.type;
	switch (tipo){
		case "file":
		case "text":
			if(campo.value==''){
				messaggioAlert="Attenzione! Riempire il campo "+ variabile.toUpperCase();
				gDialog.Display();
				return false;
			}
		break;
		case "radio":
			if(!(campo.checked)){
				messaggioAlert="Attenzione! Selezionare il campo "+ variabile.toUpperCase();
				gDialog.Display();
				return false;
			}
		break;
		case "select-one":
			if(campo.selectedIndex==0){
				messaggioAlert="Attenzione! Selezionare un valore per "+ variabile.toUpperCase();
				gDialog.Display();
				return false;
			}
		break;
	}
}

function chiudiFinestra(nomeForm){
	gDialog.DestroyLayers();
	messaggioType="";
	messaggioAlert="";
	if(nomeForm!="")
		document.forms[nomeForm].submit();
	return;
}


function popUpTorneo(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=580,height=320,left = 237,top = 234');");
}
function openAssemblea(w, h){
	var x=( screen.Width - w )/2;
	var y=( screen.Height - h )/2;
	var win=window.open("vt/assemblea.html","link2","resizable=0,width= "+w+" ,height="+h+", status=0, left="+x+", top="+y+", scrollbars=0, menubar=0, toolbars=0, directories=0");
}
