// JavaScript Document
function chiamata(k,m) {document.getElementById('passa').name=k;document.getElementById('passa').value=m;document.chiama.submit();}
function chiamataSA(k,m) {document.chiama.action=document.chiama2.action;chiamata(k,m);}
function chiamata2(k,m) {document.chiama.action=document.chiama.action+'#mezzo';chiamata(k,m);}
function chiamata2SA(k,m) {document.getElementById('mezz').value=1;chiamataSA(k,m);}
function pulisci(s) {
  var ecco=s.replace(/^\s+|\s+$/g,"");
  var pos=ecco.search("  ");
  while(pos>0) {ecco=ecco.replace("  "," ");pos=ecco.search("  ");}
  return ecco;
}
function sostSgradito(c) {var s=document.getElementById('alert32').value;;s=s.replace('+',c);return s;}
function pulisci2(c,d,n) {//c il testo, d l'id per il focus, n carattere non gradito
  var s="";
  var pos=c.search('<');if(pos!=-1) {s=sostSgradito('<');}
  pos=c.search('>');if(pos!=-1) {s=sostSgradito('>');}
  if(n!="") {pos=c.search(n);if(pos!=-1) {s=sostSgradito(n);}}
  c=pulisci(c);if(c.length==0&&d) {s=document.getElementById('alert18').value;}
  if(s!="") {
	alert(s);
    if(d) {document.getElementById(d).focus();}
	return "";
  }
  return c;
}
function br2nl(c) {c=c.replace(/<BR>/g,"\n");c=c.replace(/<BR \/>/g,"\n");c=c.replace(/<BR\/>/g,"\n");c=c.replace(/<br>/g,"\n");c=c.replace(/<br \/>/g,"\n");c=c.replace(/<br\/>/g,"\n");return c;}
function nl2br(c) {c=c.replace(/\n/g,"<br>");return c;}
function apriChiudi(c) {
  if(document.getElementById(c).style.display=='none') {document.getElementById(c).style.display='';} else {document.getElementById(c).style.display='none';}
}
function avvisa(c,t,tt,w) {//c=elemento di rif., t=titolo, tt=testo
  var x=0,y=0,pos,n=1,s,t1;
  promptbox=document.createElement('div'); 
  promptbox.setAttribute('id','prompt');
  document.getElementsByTagName('body')[0].appendChild(promptbox);
  promptbox=eval("document.getElementById('prompt').style");promptbox.position='fixed';
  y=65;promptbox.top=y+"px";x=250;promptbox.left=x+"px";promptbox.width=w+"px";
  pos=tt.search("@");
  while(pos>-1) {s=document.getElementById(c+n.toString()).value;tt=tt.replace('@',linkAvvisa(s));tt=tt.replace('@','</strong></font></span>');pos=tt.search("@");n+=1;}
  t1=document.getElementById('chiudi').value;
  document.getElementById('prompt').innerHTML="<table cellspacing='0' cellpadding='0' border='0'><tr><td width='10' height='24' background='graphic/dialogUL.png'></td><td background='graphic/dialogUM.png' class='logtit2'>"+t+"</td><td width='18' background='graphic/dialogUR.png'><td></tr><tr><td background='graphic/dialogMM.png'></td><td background='graphic/dialogMM.png'><table cellspacing='0' cellpadding='0' border='0'><tr><td class='logtxt'>"+tt+"</td></tr><tr><td height='15'></td></tr><tr><td align='center'><input type='button' class='logbutton' value='"+t1+"' onClick='document.getElementsByTagName(\"body\")[0].removeChild(document.getElementById(\"prompt\"))'></td></tr></table></td><td background='graphic/dialogMR.png'></td></tr><tr><td height='15' background='graphic/dialogDL.png'></td><td background='graphic/dialogDM.png'></td><td background='graphic/dialogDR.png'></td></tr></table>";
//  new Draggable('prompt');
}
function linkAvvisa(s) {
  var r=" onmouseover=\'style.cursor=\"pointer\"\'";
  if(s==1) {r="<span onclick=\'chiamataSA(\"mn\",2)\'"+r+">";}
  if(s==2) {r="<span onclick=\'chiamataSA(\"mn\",4)\'"+r+">";}
  if(s==3) {r="<span onclick=\'document.getElementById(\"insorol\").click()\'"+r+">";}
  if(s==4) {r="<span onclick=\'chiamataSA(\"mn\",8)\'"+r+">";}
  if(s==5) {r="<span onclick=\'login()\'"+r+">";}
  if(s==6) {r="<span onclick=\'mandaPW()\'"+r+">";}
  if(s==7) {r="<span onclick=\'chiamataSA(\"vncl\",3)\'"+r+">";}
  if(s==8) {r="<span onclick=\'chiamataSA(\"cmbLab\",1)\'"+r+">";}
  r=r+"<font color=#FF6600><strong>";return r;
}
function Start_Clock() {
  var h1,h2,m0,m1,m2,dt;
  var s=new Date();
  var h=s.getHours();
  var m=s.getMinutes();
  h1=parseInt(h/10);h2=h-h1*10;m1=parseInt(m/10);m2=m-m1*10;
  document.images['caldos'].src="calendario/"+h1+"s.gif";document.images['caluos'].src="calendario/"+h2+"s.gif";
  document.images['caldog'].src="calendario/"+h1+"g.gif";document.images['caluog'].src="calendario/"+h2+"g.gif";
  document.images['caldms'].src="calendario/"+m1+"s.gif";document.images['calums'].src="calendario/"+m2+"s.gif";
  document.images['caldmg'].src="calendario/"+m1+"g.gif";document.images['calumg'].src="calendario/"+m2+"g.gif";
  m=s.getMonth()+1;
  var d=s.getDate();d=d.toString()
  m0=document.getElementById('mese0').value;
  if(m0==m) {dt=document.getElementById('mese1').value;} else {dt=document.getElementById('mese2').value;}
  dt=dt+"<br>"+d;
  document.getElementById('datario').innerHTML=dt;
  var edt=EdtDelta();
  var pos=edt.search("%");
  document.getElementById('edt').innerHTML=document.getElementById('defedt').value+' '+edt.substr(0,pos);
  document.getElementById('delta').innerHTML='dec '+edt.substring(pos+1);
  setTimeout('Start_Clock()',1000);
}
function EdtDelta() {
  var now=new Date()
  var segno="+";
  var jd, jdA, jdB, secj, lms, ams, ecc, obl, yyy, edt;
  var hours=now.getUTCHours();var minutes=now.getUTCMinutes();var seconds=now.getUTCSeconds();
  var tsegno=+1;
  var month=now.getUTCMonth()+1;var day=now.getUTCDate();var year=now.getUTCFullYear();
  var thours=hours;var tmin=minutes;var tsec=seconds;
  var tempo=hours+minutes/60+seconds/3600;
  jd=day+(tempo)/24;
  jdA=parseInt(year/100);
  jdB=2-jdA+parseInt(jdA/4);
  jd=parseInt(365.25*(year+4716))+parseInt(30.6001*(month+1))+jd+jdB-1524.5;
  secj=(jd-2415020)/36525;
  lms=279.69668+36000.76892*secj+Math.pow(0.0003025*secj,2);
  ams=358.47583+35999.04975*secj-0.00015*Math.pow(secj,2)-0.0000033*Math.pow(secj,3);
  ecc=0.01675104-0.0000418*secj-0.000000126*Math.pow(secj,2);
  obl=23.452294-0.0130125*secj-0.00000164*Math.pow(secj,2)+0.000000503*Math.pow(secj,3);
  yyy=Math.pow(Math.tan(obl/2*Math.PI/180),2);
  edt=yyy*Math.sin(2*lms*Math.PI/180)-2*ecc*Math.sin(ams*Math.PI/180)+4*ecc*yyy*Math.sin(ams*Math.PI/180)*Math.cos(2*lms*Math.PI/180)-.5*Math.pow(yyy,2)*Math.sin(4*lms*Math.PI/180)-(5/4)*Math.pow(ecc,2)*Math.sin(2*ams*Math.PI/180);
  edt=(edt*180/Math.PI)*4;
  var eot=edt;
  tsegno=1;
  if (edt<0) {segno="-"; tsegno=-1; edt=-edt;}
  edt=((edt*6000)+.5)/6000;
  var edtr=parseInt(edt)
  tmin=tmin+tsegno*edtr;
  tsec=tsec+tsegno*parseInt((edt-edtr)*60);
  if(tsec>59) {tsec=tsec-60; tmin=tmin+1;}
  if(tsec<0) {tsec=tsec+60; tmin=tmin-1;}
  if(tmin>59) {tmin=tmin-60; thours=thours+1;}
  if(tmin<0) {tmin=tmin+60; thours=thours-1;}
  if(thours>23) {thours=thours-23;}
  if(thours<0) {thours=thours+24;}
  var tt=thours+":";if(tmin<10) {tt=tt+"0";}
  tt=tt+tmin+":";if(tsec<10) {tt=tt+"0";}
  tt=tt+tsec;
  edt=parseInt((edt-edtr)*6000);
  edtr=segno+edtr+" m ";if(edt<100) {edtr=edtr+"0";}
  if(edt<10) {edtr=edtr+"0";}
  edtr=edtr+edt;
  var lun=edtr.length;edtr=edtr.substr(0, lun-2)+"."+edtr.substr(lun-2,2);edtr=edtr+" s";
  frase=edtr;
  var cs, delta, delta2, lvs;
  cs=(1.919460-0.004789*secj-0.000014*Math.pow(secj,2))*Math.sin(ams*Math.PI/180)+(0.020094-0.000100*secj)*Math.sin(2*ams*Math.PI/180)+0.000293*Math.sin(3*ams*Math.PI/180);
  lvs=lms+cs;
  delta=Math.asin(Math.sin(obl*Math.PI/180)*Math.sin(lvs*Math.PI/180))*180/Math.PI;
  segno="+";delta2=delta;if (delta2<0) {segno="-"; delta2=-delta2;}
  delta2=parseInt(delta2*1000000+.5);
  var deltas=" "+segno;
  if(delta2<1000000) {deltas="000000"+delta2;lun=deltas.length;deltas=deltas.substr(lun-6, 6);deltas=": "+segno+"0"+deltas;
  } else {deltas=deltas+delta2;}
  lun=deltas.length;
  deltas=deltas.substr(0, lun-6)+"."+deltas.substr(lun-6, 6);
  frase=frase+"%"+deltas;
  if(document.getElementById('latn')&&azmt.map) {lablab(delta,eot,tempo);}
  delt=delta;//per gnomolab
  return frase;
}
function fumetto(d,c,p,w,xo,yo) {//d id; c titolo; p testo; w larghezza, x offset, y offset
  if(document.getElementById(d).className=='iconappass'||document.getElementById(d).className=='iconapass') {return;}
  var x=0,y=0,tt,l="";
  var dad=document.getElementById(d);
  while(dad) {x+=dad.offsetLeft;y+=dad.offsetTop;dad=dad.offsetParent;}
  x=x+xo;y=y+yo;
  var cosabox=document.createElement('div'); cosabox.setAttribute ('id','mostraCosa');
  document.getElementsByTagName('body')[0].appendChild(cosabox);
  cosabox=eval("document.getElementById('mostraCosa').style");cosabox.position='absolute';
  if(w>0) {cosabox.width=w+"px";l=" width='"+w+"'"}//galleria: w=146, x=0, y=0
  cosabox.top=y+"px";cosabox.left=x+"px";cosabox.border='outset 1px #bbbbbb';
  if(c=="") {tt="";} else {tt="<table cellspacing='0' cellpadding='0' border='0'"+l+"><tr valign='middle'><td class='fumotit'>"+c+"</td></tr></table>";}
  document.getElementById('mostraCosa').innerHTML=tt+"<table cellspacing='0' cellpadding='0' border='0'"+l+"><tr><td><div class='fumo'>"+p+"</div></td></tr></table>";
}
function sfumetto() {
  if(document.getElementById('mostraCosa')!=null) {document.getElementsByTagName('body')[0].removeChild(document.getElementById('mostraCosa'));}
}
function jumpToAnchor(q) {document.location="#"+q;}
function edtlab(d,m,y,t) {
  var jd,jdA,jdB,secj,lms,ams,ecc,obl,yyy,edt;
  jd=d+t/24;
  jdA=parseInt(y/100);
  jdB=2-jdA+parseInt(jdA/4);
  jd=parseInt(365.25*(y+4716))+parseInt(30.6001*(m+1))+jd+jdB-1524.5;
  secj=(jd-2415020)/36525;
  lms=279.69668+36000.76892*secj+Math.pow(0.0003025*secj,2);
  ams=358.47583+35999.04975*secj-0.00015*Math.pow(secj,2)-0.0000033*Math.pow(secj,3);
  ecc=0.01675104-0.0000418*secj-0.000000126*Math.pow(secj,2);
  obl=23.452294-0.0130125*secj-0.00000164*Math.pow(secj,2)+0.000000503*Math.pow(secj,3);
  yyy=Math.pow(Math.tan(obl/2*Math.PI/180),2);
  edt=yyy*Math.sin(2*lms*Math.PI/180)-2*ecc*Math.sin(ams*Math.PI/180)+4*ecc*yyy*Math.sin(ams*Math.PI/180)*Math.cos(2*lms*Math.PI/180)-.5*Math.pow(yyy,2)*Math.sin(4*lms*Math.PI/180)-(5/4)*Math.pow(ecc,2)*Math.sin(2*ams*Math.PI/180);
  edt=(edt*180/Math.PI)*4;return edt;
}
