function dgl_vars(){

	var av = navigator.appVersion; // retrocomp
	var ua = navigator.userAgent; // retrocomp

	this.dom = document.getElementById?1:0;
	this.op = (ua.indexOf("pera")>-1)?1:0;
	this.ie = (ua.indexOf("MSIE")>-1 && this.dom && !this.op)?1:0;
	this.ie4 = (document.all && !this.dom)?1:0;
	this.ns4 = (document.layers && !this.dom)?1:0;
	this.gecko = (this.dom && ua.indexOf("Gecko")>-1)?1:0;
	this.comp  = (this.dom || this.ie4)?1:0;
	this.win = (ua.indexOf('Windows')>-1)?1:0;
	this.mx=-1;
	this.my=-1;
	this.tip=-1;
	this.mac= (av.indexOf("Mac")>-1)?1:0;
	return this
}

var dgl=new dgl_vars();

var n_lay = Array();

var n_laytmr=false;
var n_lay_act=false;
var n_pagew = 0;
var n_scrh = 0;
var n_info_pic = '/c/i/login/info_s.gif';
var n_warn_pic = '/c/i/login/alert_s.gif';
var n_stip_tm = Array();
var n_newmsg = false;
var n_bcstid = false;
var n_bcst = false;
var n_bcstt = 600;
var n_bar = false;
var n_mx=0, n_my=0;
var nn_win=0;

function n_alert_pos(x,y,sc) {
	if (!dgl.comp) return -1;
	var l='alertbox';
	n_lay_init(l,'','',sc,'');
	if (y!='') n_lay[l][0].style.top = y;
	if (x!='') n_lay[l][0].style.left = x;
	if (x!='') n_lay[l][5]=x;
	if (y!='') n_lay[l][6]=y;
}

function n_stip(st,di,x,y,t) {
    if (!dgl.comp) return -1;
    if (dgl.tip != -1) n_stip_off(dgl.tip);
    var o = getObj(di);
    o.innerHTML = "<div class='miniboxc' style='left: "+x+"px; top: "+y+"px' onmouseover=\"n_stip_off('"+di+"')\"><div class='miniboxcc'>"+st+"</div></div>";
    o.style.visibility = 'visible';
    if (n_stip_tm[di]) clearTimeout(n_stip_tm[di]);
    dgl.tip = di;
    n_stip_tm[di] = setTimeout("n_stip_off('"+di+"')", t * 1000);
}

function n_stip_off(di) {
	if (!dgl.comp) return -1;
	if (n_stip_tm[di]) clearTimeout(n_stip_tm[di]);
	var o = getObj(di);
	o.style.visibility='hidden';
	dgl.tip = -1;
}

function n_alertbox(s,i) {
	if (i == undefined) i = n_warn_pic; // <-- Modifica (Gianni)
	var r="<img src='/c/i/login/352-top.gif' width=352 height=5><br>";
	r += "<div class=box352><div class=boxcont>";
	r += "<table width=320 border=0 cellspacing=0 cellpadding=0><tr><td align=left valign=center width=61><img src='"+i+"' width=61 height=61></td>";
	r += "<td width=259 align=left valign=center><div class='txtwarn'>"+s+"</div></td>";
	r += "</table><center><a href=\"javascript:n_lay_vis('alertbox',0)\"><img src='/c/i/login/chiudi.gif' border=0 width=55 height=22 alt='chiudi'></a></center>";
	r += "</div></div><img src='/c/i/login/352-bot.gif' width=352 height=5><br>";
	return r;
}

function n_alert(s,i,t) {
	if (!dgl.comp) return -1;
	var l='alertbox';
	if (i=='') i = n_info_pic;
	n_lay[l][0].innerHTML = n_alertbox(s,i);
	n_lay_vis(l,1);
	if (t>0) n_lay[l][7]=setTimeout("n_lay_vis('"+l+"',0)",t*1000);
}

// --- Modifica (Gianni)
function n_confirm(text, function_name){
	if (!dgl.comp) return -1;
	var l='alertbox';
	var html;
	html  = "<img src='/c/i/login/352-top.gif' width='352' height='5'><br>";
	html += "<div class='box352'><div class='boxcont'>";
	html += "<table width=320 border=0 cellspacing=0 cellpadding=0><tr><td align=left valign=center width=61><img src='" + n_warn_pic + "' width=61 height=61></td>";
	html += "<td width=259 align=left valign=center><div class='txtwarn'>" + text + "</div></td></tr>";
	html += "<tr><td align=center valign=center colspan=2>";
	html += "<a href='#' onclick='"+function_name+"(true); n_lay_vis(\""+l+"\",0); return false;'><img src='/c/i/login/n_confirm_1.gif' border=0 /></a>";
	html += " &nbsp; ";
	html += "<a href='#' onclick='"+function_name+"(false); n_lay_vis(\""+l+"\",0); return false;'><img src='/c/i/login/n_confirm_0.gif' border=0 /></a>";
	html += "</td></tr>";
	html += "</table>";
	html += "</div></div>";
	html += "<img src='/c/i/login/352-bot.gif' width='352' height='5'><br>";
	n_lay[l][0].innerHTML = html;
	n_lay_vis(l,1);
}

function n_box(contents, pic){
	if (!dgl.comp) return -1;
	var l='alertbox';
	var html;
	html  = "<img src='/c/i/login/352-top.gif' width='352' height='5'><br>";
	html += "<div class='box352'><div class='boxcont'>";
	if (pic != ''){
		html += "<table width=320 border=0 cellspacing=0 cellpadding=0><tr><td align=left valign=center width=61><img src='" + pic + "' width=61 height=61></td>";
		html += "<td width=259 align=left valign=center><div class='txtwarn'>" + contents + "</div></td>";
		html += "</table>";
	}else{
		html += contents;
	}
	html += "</div></div>";
	html += "<img src='/c/i/login/352-bot.gif' width='352' height='5'><br>";
	n_lay[l][0].innerHTML = html;
	n_lay_vis(l,1);
}
// ---
function nu_alert(l,s,i,t) { n_alert(s,i,t); }

function n_lay_vis(la,v) {
	n_lay_id(la);
	if (v==2) {
		if (n_lay[la][4]==0) v=1;
		else v=0;
	}
	if (v==1) n_lay_repos(la,true);
	var vi='hidden';
	if (v==1) vi = 'visible';
	n_lay[la][0].style.visibility = vi;
	n_lay[la][4]=v;
}

function n_lay_id(la) {
	if (n_lay[la]) return;
	n_lay_init(la,'','','','');
}

function n_lay_out(l) {
	if (!dgl.comp) return;
	n_lay_id(l);
	n_lay[l][7]=setTimeout('n_lay_vis(\''+l+'\',0)',500);
}

function n_lay_in(l) {
	if (!dgl.comp) return;
	n_lay_id(l);
	if (n_lay[l][7]) {
		clearTimeout(n_lay[l][7]);
		n_lay[l][7] = 0;
	}
}

function n_lay_init(la,imgx,imgy,sc,sh) {
	// obj, imgx, imgy, scroll, vis, x, y, tmr
	n_lay[la] = Array(getObj(la),imgx,imgy,sc);
	if (n_lay[la][0].style.left) n_lay[la][5] = parseInt(n_lay[la][0].style.left);
	else n_lay[la][5] = 0;
	if (n_lay[la][0].style.top) n_lay[la][6] = parseInt(n_lay[la][0].style.top);
	else n_lay[la][6] = 0;
	if (n_lay[la][0].style.visibility == 'hidden') n_lay[la][4]=0;
	else n_lay[la][4]=1;
	if (sh!='') n_lay[la][4]=2;
	n_lay[la][7] = false;
	//if ((imgx!='')&&(imgx!='center')) alert(document.images[imgx]);
	if ((imgx!='')&&(imgx!='center')) n_lay[la][1]=document.images[imgx];
	if (imgy!='') n_lay[la][2]=document.images[imgy];
	if ((imgx!='')||(imgy!='')||(sc!='')) n_lay_act=true;
}

function n_lay_repos_all(forced) {
	var w=-1; var s=-1;
	if (n_pagew!=n_width()) w = n_width();
	if (n_scrh!=n_getscroll()) s = n_getscroll();
	if ((w!=-1)||(s!=-1)||forced) {
		n_pagew = n_width();
		n_scrh = n_getscroll();
		for (var i in n_lay) if (n_lay[i][4]>0) n_lay_repos(i,false);
	}
}

function n_lay_repos(i,f) {
	if (f) {
		n_pagew = n_width();
		n_scrh = n_getscroll();
	}
	if (n_lay[i][1]=='center') {
		var x=parseInt(n_pagew / 2);
		if (x<380) x = 380;
		n_lay[i][0].style.left = x + n_lay[i][5];
	} else if (n_lay[i][1]!='') {
		var x=findPosX(n_lay[i][1]);
		n_lay[i][0].style.left = x + n_lay[i][5];
	}
	var yscr=0;
	if (n_lay[i][3] != '') yscr=n_scrh;
	if (n_lay[i][2]!='') {
		var y=findPosY(n_lay[i][2]);
		n_lay[i][0].style.top = y + n_lay[i][6] + yscr;
	} else if (n_lay[i][3] != '') n_lay[i][0].style.top = n_lay[i][6] + yscr;
	if (n_lay[i][4]==2) {
		n_lay[i][0].style.visibility = 'visible';
		n_lay[i][4]=1;
	}
}

function n_lay_wd(start) {
	if (start && n_laytmr) return;
	if (n_laytmr) clearTimeout(n_laytmr);
	n_laytmr=1;
	n_lay_repos_all(false);
	n_laytmr=setTimeout('n_lay_wd(false)',250);
}

function findPosX(obj) {
	if (!dgl.comp) return -1;
	var l=0;
	var r=0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			l += obj.offsetLeft;
			obj = obj.offsetParent;
			r=1;
		}
	} else if (obj.x) {
		l += obj.x;
		r=1;
	}

	if (r==1) return l;
	else return -1;
}

function findPosY(obj) {
	if (!dgl.comp) return -1;
	var l=0;
	var r=0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			l += obj.offsetTop;
			obj = obj.offsetParent;
			r=1;
		}
	} else if (obj.y) {
		l += obj.y;
		r=1;
	}

	if (r==1) return l;
	else return -1;
}

function n_getscroll() {
	var pos;
	if (window.innerHeight) pos = window.pageYOffset
	else if (document.documentElement && document.documentElement.scrollTop) pos = document.documentElement.scrollTop
	else if (document.body) pos = document.body.scrollTop

	return pos;
}

function n_width() {
	if (self.innerHeight) return(self.innerWidth);
	else if (document.documentElement && document.documentElement.clientHeight) return(document.documentElement.clientWidth);
	else if (document.body) return(document.body.clientWidth);
}

function getObj(name) {
 if (!dgl.comp) return false;
 if (document.getElementById) return(document.getElementById(name));
 else if (document.all) return(document.all[name]);
 return false;
}

function help_win(u) {
  var n_win;
  var ur = "/serveaiuto/";
  var eu = eval("'-'+u+'-'");
  if (eu.indexOf("undef") != 1) ur=u;
  n_win = window.open (ur,"Help","width=800,height=450,directories=yes,menubar=yes,status=yes,toolbar=yes,resizable=yes,scrollbars=yes,location=yes");
  if (n_win.focus != null) n_win.focus();
}

function getCookie(Name) {
	var search = Name + "="
	if (document.cookie.length > 0) { // if there are any cookies
		offset = document.cookie.indexOf(search)
		if (offset != -1) { // if cookie exists
			offset += search.length          // set index of beginning of value
			end = document.cookie.indexOf(";", offset)          // set index of end of cookie value
			if (end == -1) end = document.cookie.length
			return unescape(document.cookie.substring(offset, end))
		}
	}
	return("")
}

function setCookie(na, co, sec) {
	var c = na + "=" + escape(co) + "; expires=";

	if (sec>0) {
		var da= new Date();
		da.setTime(da.getTime()+(sec*1000));
		c = c + da.toGMTString()
	}
	c=c+"; path=/; domain=.libero.it";
	document.cookie=c;
}

function common_boot() {
	//onload
}

function common_unload() {
	// unload

	if (nn_win) if (!nn_win.closed) if (nn_win.close) nn_win.close();
	nn_win=0;

}

function common_eoc() {
	if (n_lay_act) setTimeout('n_lay_wd(true)',50);
	document.onmousemove= mousepos;
	//testit();
}

function n_broadcast(imm) {
	var o1 = getObj('msgdlgxo');
	var o2 = getObj('msgdlgx');
	var o = getObj('msgdlg');
	if (o) {
		o.innerHTML = "<strong>"+n_bcst+"</strong><div style='text-align: center; padding-top: 6px; padding-bottom: 1px;'><a href='' onClick='n_broadcast_out(1); return false'><img src='/c/i/login/miniok.gif' border='0'></a></div>";
		if (imm) setTimeout("n_broadcast_in()",700);
		else n_broadcast_in();
		setTimeout("n_broadcast_out(0)",60000);
	}
}

function n_broadcast_in() {
	var o1 = getObj('msgdlgxo');
	o1.style.visibility = 'visible';
}

function n_broadcast_out(ok) {
	var o1 = getObj('msgdlgxo');
	o1.style.visibility = 'hidden';
	if (ok==1) {
		setCookie('bcastid', n_bcstid, n_bcstt);
	}
}

function mousepos(e) {
	if (dgl.comp) {
		if (dgl.ns4||dgl.gecko) {
			dgl.mx = e.pageX;
			dgl.my = e.pageY;
		} else {
			if (dgl.ie&&dgl.win&&!dgl.ie4) {
				dgl.mx = (event.clientX-2)+document.body.scrollLeft;
				dgl.my = (event.clientY-2)+document.body.scrollTop;
			} else {
				dgl.mx = event.clientX+document.body.scrollLeft;
				dgl.my = event.clientY+document.body.scrollTop;
			}
		}
	}
}

function mkzoom(l,w,h,s) {
  var sc;
  if(!w) w=490;
  if(!h) h=250;

  if(!s) {
  	s=0;
  	sc="yes";
  } else sc="no";

  if (nn_win) if (nn_win.close) nn_win.close();
  nn_win=0;

  var d = new Date();
  var t = d.getTime();

  //if (dgl.mac) d=t;
  //else d='';

  nn_win = window.open(l.href,"nnwin","width="+w+",height="+h+",status=no,toolbar=no,resizable=no,scrollbars="+sc+",top=120,left=150");
  if (nn_win.focus) nn_win.focus();
}

function mkpop(u,w,h,s) {
	var a = new Array();
	a.href=u;
	mkzoom(a,w,h,s);
}
