/* ------------------------------------------------------------------------------- */
/* Nasconde/mostra un elemento */
/* ------------------------------------------------------------------------------- */
function switch_el(el)
{
	if (document.getElementById(el).style.display == 'none') { document.getElementById(el).style.display = ''; } 
	else { document.getElementById(el).style.display = 'none'; }
}

/* ------------------------------------------------------------------------------- */
/* Cambia l'icona */
/* ------------------------------------------------------------------------------- */
function switch_icon(el, iconID, open_icon, close_icon)
{
	if (document.getElementById(el).style.display == 'none') { document[iconID].src = '../images/admin/'+open_icon; }
	else { document[iconID].src = '../images/admin/'+close_icon; }
} 

/* ------------------------------------------------------------------------------- */
/* Sulla base della risoluzione dello schermo ritorna la larghezza di un popup sulla base della grandezza specificata */
/* ------------------------------------------------------------------------------- */
function GetPopUpWidth(size)
{
scr_width = screen.width;
if (size == "verysmall") {reduct = 0.2;}	
if (size == "small") {reduct = 0.3;}	
if (size == "smallmedium") {reduct = 0.4;}	
if (size == "medium") {reduct = 0.5;}	
if (size == "mediumlarge") {reduct = 0.6;}	
if (size == "large") {reduct = 0.7;}	
if (size == "verylarge") {reduct = 0.8;}	
popup_width = scr_width * reduct;
popup_width = Math.round(popup_width);
return popup_width;
}

/* ------------------------------------------------------------------------------- */
/* Sulla base della larghezza del popup ritorna la sua altezza */
/* ------------------------------------------------------------------------------- */
function GetPopUpHeight(width)
{
popup_height = width * 0.77;
popup_height = Math.round(popup_height);
return popup_height;
}

/* ------------------------------------------------------------------------------- */
/* Apre un popup centrato nello schermo */
/* ------------------------------------------------------------------------------- */
function OpenPopUp(mypage, myname, w, h, scroll)
{
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
settings = 'height='+h+', width='+w+', top='+TopPosition+', left='+LeftPosition+', scrollbars='+scroll+', resizable'
return window.open(mypage, myname, settings)
}

/* ------------------------------------------------------------------------------- */
/* Chiude il popup e ricarica la pagina padre */
/* ------------------------------------------------------------------------------- */

function ClosePopUpAndReloadParent()
{
	window.opener.focus();
	window.opener.location.reload();
	window.close();
}


/* ------------------------------------------------------------------------------- */
/* Chiude il popup ma non ricarica la pagina padre */
/* ------------------------------------------------------------------------------- */

function ClosePopUp()
{
	window.close();
}


/* ------------------------------------------------------------------------------- */
/* Redirect alla pagina passata come parametro */
/* ------------------------------------------------------------------------------- */

function RedirectToPage(page)
{
	window.location = page;
}


/* ------------------------------------------------------------------------------- */
/* Redirect alla pagina passata come parametro */
/* ------------------------------------------------------------------------------- */

function ShowToolTip(content, width)
{
	return '&lt;div class=&quot;popupEventTitle&quot; style=&quot;width:' + width + 'px&quot;&gt;' + content + '&lt;/div&gt;';
}


/* ------------------------------------------------------------------------------- */
/* Aggiunge un campo per l'inserimento di un'immagine */
/* ------------------------------------------------------------------------------- */

function AddBrowseField(type, div_id, n, limit)
{
	// immagini
	if (type == 0)
	{
		singolare = 'una nuova immagine';
		plurale = 'immagini';
		campo = 'img';
	}
	// pdf
	else if (type == 1)
	{
		singolare = 'un nuovo documento';
		plurale = 'documenti';
		campo = 'pdf';
	}
	
	if (n == limit && limit != -1) 
	{
		alert('Raggiunto il numero massimo di '+plurale+', impossibile aggiungere '+singolare);
	}
	else
	{
		new_div = document.createElement('div');
		new_div.setAttribute('id', 'browse-'+type+'-'+n);
		new_div.innerHTML += '<p><input type="file" class="input" name="'+campo+n+'"></p>';
		document.getElementById(div_id).appendChild(new_div);
		n++;
	}
	return n;
}

