// browser detection
var BV=parseInt(navigator.appVersion.indexOf("MSIE")>0?navigator.appVersion.split(";")[1].substr(6):navigator.appVersion);
var BN=window.navigator.appName;
var IsWin=(navigator.userAgent.indexOf('Windows')!=-1)?true:false;
var OP=(navigator.userAgent.indexOf('Opera')!=-1&&BV>=4)?true:false;
var NS=(BN.indexOf('Netscape')!=-1&&(BV==4)&&!OP)?true:false;
var SM=(BN.indexOf('Netscape')!=-1&&(BV>=5)||OP)?true:false;
var IE=(BN.indexOf('Explorer')!=-1&&(BV>=4)||SM)?true:false;


//screen resolution
function myscreen(){
if(window.screen){a  = (screen.availWidth < 900) ? "800" : (screen.availWidth < 1100)? "1024" : ""; return a ;}
} 

//win popup rispetto a prima non controllo scrollbar; aggiungo x,y position
function openWindow(url,width,height)
   {
   x = (640 - width)/2;
   y = (480 - height)/2;
   if (screen)
      {
      y = (screen.height - height)/2;
      x = (screen.width - width)/2;
      }
  window.open(url,'newWin','width='+width+',height='+height+',screenX='+x+',screenY='+y+',top='+y+',left='+x);
   }

//win popup
function popWin( url, name, width, height, scroller ) {
	var outStr = 'height=' + height + ',width=' + width;
	if (scroller == true) {	outStr = outStr + ',menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes';} 
	else if (scroller == false) {	outStr = outStr + ',menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=no';} 
	else {	outStr = outStr +',menubar=yes,toolbar=yes,location=yes,directories=yes,status=yes,scrollbars=yes,resizable=yes';
	}newWindow=window.open(url, name, outStr);
}

//Width and Height inside 
function InWidthHeight() {
		if(IE & !SM)
			return [document.body.clientWidth,document.body.clientHeight];
		if(NS||SM)
			return [window.innerWidth,window.innerHeight];
}	

//X,Y position of images
function GetImgXY(imgName) {
		var x;
		var y;	
		if(IE||OP)	{
			//return [document.images[imgName].offsetLeft ,document.images[imgName].offsetTop];
			x = getOffset(document.images[imgName])[0];
			y = getOffset(document.images[imgName])[1];		
		} else	{
			return [window.document.images[imgName].x,window.document.images[imgName].y];			
		}
		return [x, y];
		                   }
//X,Y position of images corretto per IE						   					
function getOffset(img) {
		x = img.offsetLeft;
		y = eval(img).offsetTop;
		ce = eval(img).offsetParent;
		while (ce!=null)	{
			y += ce.offsetTop;
			x += ce.offsetLeft;
			ce = ce.offsetParent;
		}
		return [x,y];
			
		}		
//cambia bkground in base alla pg caricata:riceve (nmSz, Sz) onload via php
//TIENI PRESENTE L' URL RELATIVO ALLA CARTELLA CSS 
function topmenu(nmSz, Sz, toplnk, clk_print)	{
	var numSez = nmSz;
	var Sez = Sz;
	//if(numSez != 0) {		
		document.getElementById("masthead").style.background = "url('css/img/"+ Sez +"') no-repeat left bottom";
		var Scheda =document.getElementById("menuTop");	
		var linkScheda = Scheda.getElementsByTagName("a")
		linkScheda[numSez].style.color = "#333";
		linkScheda[numSez].style.textDecoration = "none";
		if(toplnk != 'off')
		{
			var top_menu =document.getElementById("navigation");	
			var top_link = top_menu.getElementsByTagName("a")
			top_link[toplnk].style.color = "#333";
			top_link[toplnk].style.textDecoration = "none";
		}
		if(clk_print!="yes") document.getElementById("click").style.display  = "block";
	//}else{
		//return null;
	//}
}

//cambia visibilità(display) a NavBar e lo registra nei coockie
function cambiasfondo(navVisibility) {
	var navDisplay = document.getElementById("navBar").style.visibility;	
	if (!navDisplay)navDisplay == "visible";
	if (navDisplay == "visible"){
		document.getElementById("navBar").style.display  = "none";
		document.getElementById("navBar").style.visibility = "hidden";
		document.getElementById("content").style.width = "745px";
		document.getElementById("click").style.background = "url('css/img/click5b.gif') no-repeat";
		createCookie("navBar", "hidden", 365);
	  }else{
		document.getElementById("content").style.width = "525px";
		document.getElementById("navBar").style.display  = "block";
		document.getElementById("navBar").style.visibility = "visible";
		document.getElementById("click").style.background = "url('css/img/click5.gif') no-repeat";
		createCookie("navBar", "visible", 365);
	  }
}