function Right(str, n)
{
	if (n <= 0)
	   return "";
	else if (n > String(str).length)
	   return str;
	else {
	   var iLen = String(str).length;
	   return String(str).substring(iLen, iLen - n);
	}
}

function Left(str, n)
{
	if (n <= 0)
		return "";
	else if (n > String(str).length)
		return str;
	else
		return String(str).substring(0,n);
}


function idFromNumber(number) {
    if (number < 10) {
        return ('0' + String(number));
    } else {
        return String(number);
    }
}

function openHtmlPopup(htmlFile) {
    $('#popup-container').load(htmlFile, function () {                              //Chiamata Ajax che carica un HTML. Function è la callback, chiamata a caricamento terminato
        $('#popup-container').fadeIn(1000);
        $('#popup-container').css("left", ($(window).width() - $('#popup-container').width()) / 2);     //Centra il popup
        $('#popup-container').css("top", ($(window).height() - $('#popup-container').height()) / 2);
    });

    $('#oscuratore').css('height', $(document).height());
    $('#oscuratore').fadeTo(500, 0.8);
};

function closePopup() {
    $('#oscuratore').fadeOut(1000);
    $('#popup-container').fadeOut(500, removeHtml);
}

function removeHtml() {                                                         //Cancella il contenuto del popup-container
    $('#popup-container').replaceWith('<div id="popup-container"></div>');
}

$(window).resize(function () {
    $("#oscuratore").css({ "height": $(window).height(), "width": $(window).width() }, 300);
});
