//menu

if (document.getElementById){
document.write('<style type="text/css">\n')
document.write('.children{display: none;}\n')
document.write('</style>\n')
}


function SwitchMenu(obj){
	if(document.getElementById){
	var el = document.getElementById(obj);
	var ar = document.getElementById("leftMenuContent").getElementsByTagName("span");
		if(el.style.display != "block"){
			for (var i=0; i<ar.length; i++){
				if (ar[i].className=="children")
				ar[i].style.display = "none";
			}
			el.style.display = "block";
		}else{
			el.style.display = "none";
		}
	}
}


// commenti previsioni concluse
var arrayText = [];
function cutStrings(idPrefix, charsNumber)
 {
  var cont = 1;
  while(StringContainer = document.getElementById(idPrefix+cont))
  {
   arrayText[cont] = StringContainer.innerHTML;
   if(StringContainer.innerHTML.length>charsNumber)
   	StringContainer.innerHTML = StringContainer.innerHTML.substring(0,charsNumber)+" <a href='javascript:showFullText(\""+(idPrefix+cont)+"\",\""+cont+"\")';return false;>[...]</span><\/a>";
   cont++;
  }
 }
 function showFullText(idContainer, idText)
 {
  document.getElementById(idContainer).innerHTML = arrayText[idText];
 }

// 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=40);opacity:0.4;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';

}
