/****************************
 *         VARIE            *
 ****************************/

//PROVA
function fun()
{ alert("Ci sono anche io!!!"); }

// PER NAVIGARE
function vaiA(pag)
{
	//alert("vaiA("+pag+")");
	//window.location = "index.php?act="+act;
	if(pag=='')
		pag='home';
	document.actForm.pag.value=pag;
	document.actForm.submit();
}

function vaivai(dir)
{
	//alert("vaivai("+dir+")");
	if(dir=='')
		dir='';
	document.actForm.dir.value=dir;
	vaiA(dir);
	// vaiIn(dir, dir);
}

function vaiIn(dir, pag)
{
	//alert("vaiIn("+dir+", "+pag+")");
	document.actForm.dir.value=dir;
	vaiA(pag);
}

function vaiInAct(dir, pag, act)
{
	document.actForm.act.value=act;
	vaiIn(dir, pag);
}

function doLogin()
{
	//alert("doLogin()");
	document.loginForm.act.value="login";
	document.loginForm.submit();
}

function doLogout(dir, pag)
{
	//alert("doLogout("+dir+", "+pag+")");
	document.actForm.act.value="logout";
	vaiIn(dir, pag);
}


//STAMPA UNA STRINGA NELL'AREA DI STATO
//APPENA CAPISCI COME SI FA...
function showStatus(string)
{
	alert("showStatus("+string+")");
	document.statusForm.statusLabel="Ciao?";
}

//STAMPA UNA STRINGA NELL'AREA DI DEBUG
//APPENA CAPISCI COME SI FA...
function debug(string)
{
	alert("debug("+string+")");
}

//STAMPA UNA QUERY NELL'AREA DI DEBUG
function showQuery(query)
{
	alert("showQuery("+query+")");
	document.queryLabel.value = query;
}


/****************************
 *    AZIONI SULLE NEWS     *
 ****************************/

function controllaInserisciNews()
{
	//alert("controllaInserisciNews");
	document.newsForm.dir.value="news";
	document.newsForm.pag.value="news";
	document.newsForm.act.value="insert";
	document.newsForm.submit();
}

function confermaCancellaNews(id)
{
	//alert("confermaCancellaNews("+id+")");
	if(confirm("Sei sicura mamma? Così cancelli la voce!!"))
	{
		document.newsForm.dir.value="news";
		document.newsForm.pag.value="news";
		document.newsForm.act.value="delete";
		document.newsForm.id.value=id;
		document.newsForm.submit();
	}
}

/****************************
 *    AZIONI SULLE DATE     *
 ****************************/

function controllaInserisciData()
{
	//	alert("controllaInserisciData");
	$err="";
	if(document.dataForm.nome.value=="")
		$err+="- un NOME che distingua la data -";
	if(document.dataForm.conchi.value=="")
		$err+=" CON CHI la fai -";
	/*if(document.dataForm.nome.value=="")
		$err+=" la DATA (possibilmente esatta) della data -";*/
	if(document.dataForm.dove.value=="")
		$err+=" DOVE la fai -";
	if(document.dataForm.fatta.value=="0" && document.dataForm.commento.value!="")
		$err+="se la data non l\'hai fatta, perché inserisci un commento?";
		
	if($err=="")
	{
		document.dataForm.dir.value="dovequando";
		document.dataForm.pag.value="dovequando";
		document.dataForm.act.value="insert";
		document.dataForm.submit();
	}
	else
		alert("Cara mamma, mi devi dire le seguenti cose "+$err+
			"...confido nella tua collaborazione...");
}

function modificaData(id)
{
	//alert("modificaData("+id+")");
	document.dataForm.dir.value="dovequando";
	document.dataForm.pag.value="dovequando";
	document.dataForm.act.value="edit";
	document.dataForm.id.value=id;
	document.dataForm.submit();
}

function updateData()
{
	document.dataForm.dir.value="dovequando";
	document.dataForm.pag.value="dovequando";
	document.dataForm.act.value="update";
	document.dataForm.submit();
}

function confermaCancellaData(id)
{
	//alert("confermaCancellaNews("+id+")");
	if(confirm("Sei sicura mamma? Così cancelli la data!!"))
	{
		document.dataForm.dir.value="dovequando";
		document.dataForm.pag.value="dovequando";
		document.dataForm.act.value="delete";
		document.dataForm.id.value=id;
		document.dataForm.submit();
	}
}

function dettaglioData(id)
{
	//alert("dettaglioData("+id+")");
	document.dataForm.dir.value="dovequando";
	document.dataForm.pag.value="dovequando";
	document.dataForm.act.value="dettagliodata";
	document.dataForm.id.value=id;
	document.dataForm.submit();
}

/* Roba vecchia */


/****************************
 *    AZIONI SUGLI ALBUM    *
 ****************************/

//CONFERMA DELLA CANCELLAZIONE DI UN ALBUM
function confirmAndDeleteAlbum(id)
{
	//alert("confirmAndDeleteAlbum");
	if(confirm("Sei sicuro? Così cancelli la voce!!"))
	{
		//window.location = "index.php?act=nuovoAlbum&newAct=delete&id="+id;
		document.viewForm.act.value="nuovoAlbum";
		document.viewForm.newAct.value="delete";
		document.viewForm.id.value=id;
		document.viewForm.submit();
	}
}

//MODIFICA UN ALBUM
//devo per forza passargli anche l'immagine
function modifyAlbum(id, img)
{
	//alert("modifyAlbum");
	if(img!="")
		document.viewForm.editImg.value="0";
	document.viewForm.act.value="nuovoAlbum";
	document.viewForm.newAct.value="edit";
	document.viewForm.id.value=id;
	document.viewForm.submit();
}

//CHIEDE LA MODIFICA DELL'IMMAGINE DI UN ALBUM
function editImage()
{
	alert("editImage");
	document.albumForm.newAct.value="edit";
	//alert(document.albumForm.editImg.value);
	document.albumForm.editImg.value=1;
	//alert(document.albumForm.editImg.value);
	document.albumForm.submit();
}

// CONTROLLO DELLA FORM DELL'ALBUM
function checkAlbum()
{
	//alert("checkAlbum");
	if((checkArtista()==1) && (checkAlbumName()==1))
		return 1;
	return 0;
}

// CONTROLLO DEL NOME DELL'ARTISTA
function checkArtista()
{
	//alert("checkArtista");
	if(document.albumForm.artista.value == "")
	{
		alert("Inserisci un autore");
		return 0;
	}
	return 1;
}

// CONTROLLO DEL NOME DELL'ALBUM
function checkAlbumName()
{
	//alert("checkAlbumName");
	if(document.albumForm.nomeAlbum.value == "")
	{
		alert("Inserisci un nome per l'album");
		return 0;
	}
	return 1;
}


// INSERIMENTO DI UN ALBUM E MOSTRA DELLA FORM PER UN ALTRO INSERIMENTO DELLO STESSO AUTORE
function insertAndOther()
{
	//alert("insertAndOther");
	document.albumForm.ancoraAutore.value=1;
	checkAndInsertAlbum(1);		
}


//PER L'INSERIMENTO DI UN ALBUM
function checkAndInsertAlbum(continua)
{
	//alert("checkAndInsertAlbum("+continua+")");
	document.albumForm.ancoraAlbum.value=continua;
	if(checkAlbum()==1)
		document.albumForm.submit();
}

//CONTROLLO SUL NOME DELL'IMMAGINE
function checkImageName(imgName)
{
	//alert("checkImageName("+imgName+"));
	if(img.indexOf("\"", 0) != -1)
		alert("Il nome del\'immagine non può contenere \"");
	else if(img.indexOf("&", 0) != -1)
		alert("Il nome del\'immagine non può contenere &");
	else if(img.indexOf("'", 0) != -1)
		alert("Il nome del\'immagine non può contenere '");		
}

/**********************************
 *    AZIONI SULLE COMPILATION    *
 **********************************/

//CONFERMA DELLA CANCELLAZIONE
function confirmAndDeleteComp(id)
{
	//alert("confirmAndDeleteComp");
	if(confirm("Sei sicuro? Così cancelli la compilation!!"))
	{
		//window.location = "index.php?act=nuovoAlbum&newAct=delete&id="+id;
		document.compForm.act.value="nuovoCD";
		document.compForm.newAct.value="delete";
		document.compForm.comp.value=id;
		document.compForm.submit();
	}
}

// MODIFICA UNA COMPILATION (ATTO DELL'INSERIMENTO NEL DB)
function modifyComp(id)
{
	//alert("modifyComp("+id+")");
	document.compForm.act.value="nuovoCD";
	document.compForm.newAct.value="update";
	document.compForm.comp.value=id;
	document.compForm.submit();
}

// MODIFICA DI UNA COMPILATION
function editComp(id)
{
	//alert("editComp("+id+")");
	document.compForm.act.value="nuovoCD";
	document.compForm.newAct.value="edit";
	document.compForm.comp.value=id;
	document.compForm.submit();
}

//PER L'INSERIMENTO DI UNA COMPILATION NUOVA
function checkAndInsertComp()
{
	//alert("checkAndInsertComp");
	if(document.compForm.compName.value.indexOf("\"", 0) != -1)
		alert("Il nome della compilation non può contenere \"");
	else
	{
		document.compForm.act.value="nuovoAlbum";
		document.compForm.newComp.value="1";
		document.compForm.newAct.value="new";
		document.compForm.submit();
	}
}

//PER L'INSERIMENTO DI UN ALBUM NELLA COMPILATION
function addAlbumToComp(idComp)
{
	//alert("addAlbumToComp");
	document.compForm.act.value="nuovoAlbum";
	document.compForm.isComp.value="1";
	document.compForm.newAct="new";
	document.compForm.comp.value=idComp;
	document.compForm.submit();
}

//PER LA STAMPA DELLA COVER PER UNA COMPILATION
function printCompCover(idComp)
{
	//alert("printCompCover("+idComp+")");
	document.compForm.act.value="printCompCover";
	document.compForm.comp.value=idComp;
	document.compForm.submit();
}

/*******************************
 *   FUNZIONI PER LA RICERCA   *
 *******************************/
 
// CERCA QUALCOSA NEL DB
function generalSearch(field, value)
{
	//alert("generalsearch("+field+", "+value+")");
	document.viewForm.act.value="vista";
	document.viewForm.field.value=field;
	document.viewForm.myvalue.value=value;
	document.viewForm.submit();
}

//CERCA QUALCOSA NEL DB, MA VUOLE SOLO NA pgenum-ESIMA PAGINA DEL RISULTATO
function generalSearchFrom(field, value, pagenum)
{
	//alert("generalSearchFrom("+field+", "+value+", "+pagenum+")");
	document.viewForm.pagnum.value=pagenum;
	generalSearch(field, value);
	//come mai non funziona?????
	/*document.viewForm.act.value="vista";
	document.viewForm.field.value=field;
	document.viewForm.myvalue.value=value;
	document.viewForm.submit();*/
}

//CERCA UNA AUTORE
function searchArtista(artista)
{ generalSearch("artista", artista); }

//CERCA UNA COMPILATION
function searchComp(comp)
{ generalSearch("comp", comp); }

//CERCA UN ANNO
function searchAnno(anno)
{ generalSearch("anno", anno); }