function inizializza() {// Per aprire un link in una nuova finestra senza contravvenire alla legge Stanca
	var a = document.getElementsByTagName('a');
	for(var i=0;a[i];i++) if(a[i].className.indexOf('blank') != -1) {
		a[i].title += " [il collegamento apre una nuova finestra]";
		a[i].onclick = function(){window.open(this.href, '_blank','left=20,top=20,width=520,height=520,toolbar=0,location=0,directories=0,status=0,scrollbars=1,resizable=1');return false;};
		a[i].onkeypress = function (e) {
		k = (e) ? e.keyCode : window.event.keyCode;
		if(k==13) {
			window.open(this.href, '_blank');
			return false;
			}
		}
	}
}

function inizializzait() {// Per aprire un link in una nuova finestra senza contravvenire alla legge Stanca
	var a = document.getElementsByTagName('a');
	
	var optimalWidth = 1000;
	var optimalHeight = 700;

	if (optimalHeight > screen.height)
		optimalHeight = screen.height * 0.8
	if (optimalWidth > screen.width)
		optimalWidth = screen.width * 0.8

	var posleft = (screen.width - optimalWidth) / 2;
	var postop = (screen.height - optimalHeight) / 2;
	
	for(var i=0;a[i];i++) if(a[i].className.indexOf('blank') != -1) {
		a[i].title += " [il collegamento apre una nuova finestra]";
		a[i].onclick = function(){window.open(this.href, '_blank','left='+posleft+',top='+postop+',width='+optimalWidth+',height='+optimalHeight+',toolbar=0,location=0,directories=0,status=0,scrollbars=1,resizable=1');return false;};
		a[i].onkeypress = function (e) {
		k = (e) ? e.keyCode : window.event.keyCode;
		if(k==13) {
			window.open(this.href, '_blank');
			return false;
			}
		}
	}
}

function inizializzade() {// Per aprire un link in una nuova finestra senza contravvenire alla legge Stanca
	var a = document.getElementsByTagName('a');
	
	var optimalWidth = 1000;
	var optimalHeight = 700;
	

	if (optimalHeight > screen.height)
		optimalHeight = screen.height * 0.8
	if (optimalWidth > screen.width)
		optimalWidth = screen.width * 0.8

	var posleft = (screen.width - optimalWidth) / 2;
	var postop = (screen.height - optimalHeight) / 2;

	for(var i=0;a[i];i++) if(a[i].className.indexOf('blank') != -1) {
		a[i].title += " [der Link wird in einen neuen Fenster geöffnet]";
		a[i].onclick = function(){window.open(this.href, '_blank','left='+posleft+',top='+postop+',width='+optimalWidth+',height='+optimalHeight+',toolbar=0,location=0,directories=0,status=0,scrollbars=1,resizable=1');return false;};
		a[i].onkeypress = function (e) {
		k = (e) ? e.keyCode : window.event.keyCode;
		if(k==13) {
			window.open(this.href, '_blank');
			return false;
			}
		}
	}
}

function tableruler() {//Per cambiare lo sfondo di una riga su mouseover
 if (document.getElementById && document.createTextNode)
  {
   var tables = document.getElementsByTagName('table');
   for (var i=0;i<tables.length;i++)
   {
    if(tables[i].className=='ruler')
    {
     var trs=tables[i].getElementsByTagName('tr');
     for(var j=0;j<trs.length;j++)
     {
      if(trs[j].parentNode.nodeName.toUpperCase()=='TBODY')// && trs[j].parentNode.nodeName!='TFOOT')
       {
			 if(trs[j].className=='odd')
			 {
			 trs[j].onmouseover=function(){this.className='ruled';return false;}
			 trs[j].onmouseout=function(){this.className='odd';return false;}
			 }
			 else
			 {
			 trs[j].onmouseover=function(){this.className='ruled';return false;}
			 trs[j].onmouseout=function(){this.className='even';return false;}
			 }
     }
    }
   }
  }
 }
}



function addHelp()
{
	var strID, objHelp;
	
	if (document.getElementById && document.appendChild && document.removeChild)
	{	
		var objHelpform = document.getElementById('helped');
		if (objHelpform!=null) {
			var objAnchors = objHelpform.getElementsByTagName('a');

			for (var iCounter=0; iCounter<objAnchors.length; iCounter++)
			{
				if (objAnchors[iCounter].className == 'helplink')
				{
					strID = getIDFromHref(objAnchors[iCounter].href);
					objHelp = document.getElementById(strID);
					objHelp.style.display = 'none';
			
					objAnchors[iCounter].onclick = function(event){return expandHelp(this, event);}
					objAnchors[iCounter].onkeypress = function(event){return expandHelp(this, event);}
			
					objAnchors[iCounter].parentNode.appendChild(objHelp);
				}
			}
			var objOldnode = document.getElementById('helpcontainer');
			if (objOldnode!=null) {
				objOldnode.parentNode.removeChild(objOldnode);
			}
		}
			// Release memory to prevent IE memory leak
			// Thanks to Mark Wubben <http://novemberborn.net/>
			// for highlightint the issue</span>
		objHelpform = null;
		objHelp = null;
		objAnchors = null;
	}
}

function getIDFromHref(strHref)
{
	var iOffset = strHref.indexOf('#') + 1;
	var iEnd = strHref.length;

	return strHref.substring(iOffset, iEnd);
}

function expandHelp(objAnchor, objEvent)
{
	var iKeyCode;

	if (objEvent && objEvent.type == 'keypress')
	{
		if (objEvent.keyCode)
			iKeyCode = objEvent.keyCode;
		else if (objEvent.which)
			iKeyCode = objEvent.which;
		
		if (iKeyCode != 13 && iKeyCode != 32)
			return true;
	}

	strID = getIDFromHref(objAnchor.href);
	objHelp = document.getElementById(strID);

	if (objHelp.style.display == 'none')
		objHelp.style.display = 'block';
	else
		objHelp.style.display = 'none';

	return false;
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}