// fx_01.js (c)2K2 Digiland - Italia OnLine

// Browser ID

var DG_BROW_N="UNK";
var DG_BROW_V=0;
var DG_PLAT="UNK";
var DG_JAVA=false;

var agt=navigator.userAgent.toLowerCase();
var appVer = navigator.appVersion.toLowerCase();
var is_minor = parseFloat(appVer);
var is_major = parseInt(is_minor);

var iePos  = appVer.indexOf('msie');
if (iePos !=-1) {
	is_minor = parseFloat(appVer.substring(iePos+5,appVer.indexOf(';',iePos)))
	is_major = parseInt(is_minor);
}
var nav6Pos = agt.indexOf('netscape6');
if (nav6Pos !=-1) {
	is_minor = parseFloat(agt.substring(nav6Pos+10))
	is_major = parseInt(is_minor)
}

DG_BROW_V=is_major;

if (document.layers) DG_BROW_N="nav";
if (document.all)
	DG_BROW_N="ie";
else
	if (document.getElementById) DG_BROW_N="nav";

if (agt.indexOf("opera")!=-1) DG_BROW_N="opera";

if (agt.indexOf("win")!=-1) DG_PLAT="win";
if (agt.indexOf("mac")!=-1) DG_PLAT="mac";
if (agt.indexOf("inux")!=-1) DG_PLAT="linux";

if (navigator.javaEnabled()) DG_JAVA=true;

var DG_IE=false;
var DG_NAV=false;

if ((DG_BROW_N=="ie")||(DG_BROW_N=="opera")) DG_IE=DG_BROW_V;

if (DG_BROW_N=="nav") DG_NAV=DG_BROW_V;

// Floatmenu

var timer_ids=new Array();
var on_off=new Array();
var lay_x=new Array();
var lay_y=new Array();
var father_l=new Array();

var f_lay_wd = 0;

function inizialize_lay(l,father,x,y) {
	on_off[l]=0;
	timer_ids[l]=0;
	father_l[l]=father;
	if (x>=0) lay_x[l]=x;
	if (y>=0) lay_y[l]=y;
	mostra_lay(l,0);
	if (f_lay_wd == 0){
		f_lay_wd = 1;
		lay_wd();
	}
}

function position_lay(l,x,y) {
	lay_x[l]=x;
	lay_y[l]=y;
}

function which_l(l) {
	var o=0;
	if (DG_IE==4) o=document.all[l];
	else if (DG_NAV==4) o=eval("document."+l);
	else if ((DG_NAV>=5)||(DG_IE>=5))  o=document.getElementById(l);
	return o;
}

function mostra_lay(l,onoff) {
	var o=which_l(l);

	x=lay_x[l];
	y=lay_y[l];
	if (father_l[l]!='none') {
		x=x+lay_x[father_l[l]];
		y=y+lay_y[father_l[l]];
	}

	on_off[l]=onoff;
	if (onoff==1) dentro(l);

	ox = findPosX(document.images[0]) - 8;
	oy = findPosY(document.images[0]) - 24;

	if (DG_NAV==4) {
		o.pageX = x+ox;
		o.pageY = y+oy;
		if (onoff==1) o.visibility = "show";
		else if (onoff==0) o.visibility = "hide";
	} else if ((DG_IE>=4)||(DG_NAV>4)) {
		o.style.left = x+ox;
		o.style.top = y+oy;
		if (onoff==1) o.style.visibility = "visible";
		else if (onoff==0) o.style.visibility = "hidden";
	}
}

function shake_lay(l, n) {
	var o=which_l(l);

	var s=n % 2;

	if (s==0) {
		lay_x[l]+=4;
		lay_y[l]+=1;
	} else {
		lay_x[l]-=4;
		lay_y[l]-=1;
	}

	mostra_lay(l, 2);
	n-=1;

	if (n>0) timer_ids[l]=setTimeout("shake_lay(\'" + l + "\'," + n + ")", 50);

}

function fuori(l) {
	if (DG_NAV!=4) timer_ids[l]=setTimeout('if (on_off[\'' +l+'\']==1) { mostra_lay(\''+l+'\',0); }',500);
}

function dentro(l) {
	if (timer_ids[l]!=0) clearTimeout(timer_ids[l]);
}

var mem_pagew = 0;
var mem_posx = -1;

function lay_wd() {
	if ((document.body.clientWidth != mem_pagew)||(mem_posx != findPosX(document.images[0]))) {
		 mem_pagew = document.body.clientWidth;
		 mem_posx = findPosX(document.images[0]);
		 lay_repos_all();
	}
	setTimeout("lay_wd()", 250);
}

function lay_repos_all() {
	for (var i in on_off)
		mostra_lay(i,on_off[i]);
}

// Stampalinkmenu

var menu_cnt=0;

function stahref(href) {
	menu_cnt++;
	if (menu_cnt==menu_sel)  document.write("<A HREF='" + href + "' class=linkrosso>");
	else document.write("<A HREF='" + href + "' class=linkgrigio>");
}

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=350,status=yes,toolbar=yes,resizable=yes,scrollbars=yes");
  if (n_win.focus != null) n_win.focus();
}

function opencamwindow(u) {
	var camwindow;
	camwindow = window.open(u,"camwind",'width=480,height=370,top=200,left=50,scrollbars=0,resizable=0');
        camwindow.focus();
	if (camwindow.focus != null) camwindow.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 findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

var mediawin=null;

function zmedia(ur,x,y) {

	if (!x) x=660;
	if (!y) y=360;

        if (mediawin!=null) {
    		mediawin.close();
                mediawin= null;
        } else {
                mediawin= null;
        }
	posx=parseInt((800-x)/2);
	posy=parseInt((600-y)/2);

        if (mediawin==null) {
                mediawin = window.open(ur,"mediawin",'toolbar=0,left='+posx+',top='+posy+',location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width='+x+',height='+y);
        }

}

var nn_win=0;

function mkzoom2(l,w,h,s) {
  var sc;
  if(!w) w=660;
  if(!h) h=360;

  if(!s) {
  	s=0;
  	sc="yes";
  } else sc="no";

  if (nn_win) if (nn_win.close) nn_win.close();
  nn_win=0;

  posx=parseInt((800-w)/2);
  posy=parseInt((600-w)/2);

  var d = new Date();
  var t = d.getTime();

  nn_win = window.open(l.href,"nnwin","top="+posy+",left="+posx+",width="+w+",height="+h+",status=no,toolbar=no,resizable=no,scrollbars="+sc+",top=120,left=150");
  if (nn_win.focus) nn_win.focus();
}

function unlo() {
	if (nn_win) nn_win.close();
	if (mediawin) mediawin.close();
}

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;
}

// --- (Gianni)
// Apre una popup che non viene chiusa on unload
var fx_win = 0;
function mkzoom_non_chiudere(l,w,h,s) {
  var sc;
  if(!w) w=660;
  if(!h) h=360;

  if(!s) {
  	s=0;
  	sc="yes";
  } else sc="no";

  if (fx_win) if (fx_win.close) fx_win.close();
  fx_win=0;

  posx=parseInt((800-w)/2);
  posy=parseInt((600-w)/2);

  var d = new Date();
  var t = d.getTime();

  fx_win = window.open(l.href,"fx_win","top="+posy+",left="+posx+",width="+w+",height="+h+",status=no,toolbar=no,resizable=no,scrollbars="+sc+",top=120,left=150");
  if (fx_win.focus) fx_win.focus();
}


// varie 

function ceblo() {
	for (i=0; i<document.forms.length; i++) {
		if (document.forms[i].id.value)
			if (document.forms[i].key.value)
				// if (document.forms[i].ricercablog.value)
					if (document.forms[i].key.value != '') document.forms[i].submit();
	}
}

function switcar(frm) {
	frm.ur.value=this.location+" ";
	frm.submit();	
}
