/****************************************************************
*   Funzioni di visualizzazione modal popup
****************************************************************/
function showModal(pagina, larghezza, altezza, classe, stile, scrollabile) {
	var clientWidth = $(window).width();
	var clientHeight = $(window).height();
	var scrolla = scrollabile = '' ? 'auto' : scrollabile;
	var w = larghezza >= clientWidth ? clientWidth - 40 : larghezza;
	var h = altezza >= clientHeight ? clientHeight - 40 : altezza;

	//sfondo
	var sfondo = $('<div id="popUpBackGround" />');
	sfondo.height((document.documentElement.scrollHeight ? document.documentElement.scrollHeight : document.body.scrollHeight) + 'px');
	sfondo.width((document.documentElement.scrollWidth ? document.documentElement.scrollWidth : document.body.scrollWidth) + 'px');
	sfondo.appendTo(document.body);

	//finestra
	var modal = $('<iframe id="popUp" frameborder="0" scrolling="' + scrolla + '" src="' + pagina + '" style="' + stile + '" class="' + classe + '" width="' + w + '" height="' + h + '" />');

	modal.appendTo(document.body);
	modal.addClass("popUpBody");
	modal.css("left", ((clientWidth / 2) - (w / 2) + 'px'));
	modal.css("top", ((clientHeight / 2) - (h / 2) + 'px'));
	modal.show();

	//pulsante chiusura
	var close = $('<a id="closeModalButton" href="javascript:hideModal();"><img width="30" height="30" src="immagini/close.png" /></a>');
	close.appendTo(document.body);
	close.addClass("close-modal-button");
	close.css("left", ((clientWidth / 2) - (w / 2) + w - 15) + 'px');
	close.css("top", ((clientHeight / 2) - (h / 2) - 15) + 'px');
	close.show();

	window.onresize = function () {
		sfondo.height((document.documentElement.scrollHeight ? document.documentElement.scrollHeight : document.body.scrollHeight) + 'px');
		sfondo.width((document.documentElement.scrollWidth ? document.documentElement.scrollWidth : document.body.scrollWidth) + 'px');
		var clientWidth = $(window).width();
		var clientHeight = $(window).height();
		modal.css("left", ((clientWidth / 2) - (w / 2) + 'px'));
		modal.css("top", ((clientHeight / 2) - (h / 2) + 'px'));
		close.css("left", ((clientWidth / 2) - (w / 2) + w - 15) + 'px');
		close.css("top", ((clientHeight / 2) - (h / 2) - 15) + 'px');
	}
}

function hideModal(control) {
	$('#popUpBackGround').remove();
	$('#popUp').remove();
	$('#closeModalButton').remove();
	window.onresize = null;
}
