// lightbox
var enableCloseLightBox = true;

function makeRequest(url,callback,async) 
{
    if(async!==false)
        async = true
    
	if (window.XMLHttpRequest) // Mozilla, Safari,...
	{ 
		http_request = new XMLHttpRequest();
	} 
	else if (window.ActiveXObject) // IE
	{ 
		http_request = new ActiveXObject("Microsoft.XMLHTTP");
	}
	if(!http_request)
	{
		return;
	}
	if(callback && async===true)
		http_request.onreadystatechange = callback;
	http_request.open('GET', url, async);
	http_request.send(null);
	if(async===false)
	{
	   callback();
	}
}

function openPopUp(url,width,height)
{
	leftValue = (screen.width - width)/2;
	topValue = (screen.height - height)/2;
	window.open(url,'emoticons','width='+width+',height='+height+',top='+topValue+',left='+leftValue+',scrollbars=1');
}

function getViewportSize()
{
    var viewportwidth;
    var viewportheight;
    
    // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
    
    if (typeof window.innerWidth != 'undefined')
    {
      viewportwidth = window.innerWidth,
      viewportheight = window.innerHeight
    }
    
    // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
    
    else if (typeof document.documentElement != 'undefined'
     && typeof document.documentElement.clientWidth !=
     'undefined' && document.documentElement.clientWidth != 0)
    {
       viewportwidth = document.documentElement.clientWidth,
       viewportheight = document.documentElement.clientHeight
    }
    
    // older versions of IE
    
    else
    {
       viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
       viewportheight = document.getElementsByTagName('body')[0].clientHeight
    }
    return [viewportwidth, viewportheight];
}

function showLightBox(urlContenuto)
{
    closeLightBox();

		var body = document.getElementsByTagName('body')[0];
		body.style.height = '100%';
		body.style.width = '100%';
		body.style.overflow = 'hidden';

		var html = document.getElementsByTagName('html')[0];
		html.style.height = '100%';
		html.style.width = '100%';
		html.style.overflow = 'hidden';

    var altezza = document.documentElement.clientHeight;
    var container = document.createElement('DIV');
    container.style.width = "100%";
    container.style.height = altezza+"px";
    
    container.style.position = "absolute";
    container.style.top = "0px";
    container.style.left = "0px";
    
    var viewportSize = getViewportSize();
    var xPos = Math.round(viewportSize[0]);
    var yPos = Math.round(viewportSize[1]);
    container.id = "lightBox";
    var html = '<div style="position:relative;z-index:100000;filter:alpha(opacity=60);opacity:0.6;width:100%;height:'+altezza+'px;background:#000"></div>';
    html     +='<div onclick="closeLightBox()" style="z-index:100000;position:absolute;top:0px;width:100%;left:0px;height:'+altezza+'px"><table onclick="enableCloseLightBox=false" align="center" style="z-index:9999999;height:100%;margin:0 auto;padding:0 auto;vertical-align:middle;" onclick=""><tr><td valign="middle" style="margin:0 auto;padding:0 auto;vertical-align:middle;" id="lightBoxContent"></td></tr></table></div>';

    container.innerHTML = html;
    document.getElementsByTagName("body")[0].appendChild(container);
    makeRequest(urlContenuto,   function()
                                {
                                    if (http_request.readyState == 4 && http_request.status == 200) 
                                    {
                                        if(http_request.responseText)
                                            document.getElementById("lightBoxContent").innerHTML = http_request.responseText;

                                    }
                                    
                                })
}

function closeLightBox()
{
    if(!enableCloseLightBox)
    {
        enableCloseLightBox = true;
        return;
    }
    var container = document.getElementById("lightBox");
    if(container)
        container.parentNode.removeChild(container);
    
    var body = document.getElementsByTagName('body')[0];
		body.style.height = '100%';
		body.style.width = 'auto';
		body.style.overflow = 'auto';

		var html = document.getElementsByTagName('html')[0];
		html.style.height = '100%';
		html.style.width = 'auto';
		html.style.overflow = 'auto';

}

// show more
function Show_Stuff(id_element)
{
    var Element=document.getElementById(id_element);
    if (Element.style.display == "none")
    {
       Element.style.display = "";
    }
    else
    {
        Element.style.display = "none";
    }
}