window.onload=keisan;
moon_flg=(img_size+",,,").split(",");

img_url="http://qpon.quu.cc/java/moon/";//月の写真の保存場所
back_img="moon1"+(moon_flg[0]*1-1)+".png";
moon_size=230;
if(moon_flg[0]*1==1){moon_size=115;}
if(moon_flg[0]*1==2){moon_size=230;}
if(moon_flg[0]*1==3){moon_size=345;}
if(moon_flg[0]*1==4){moon_size=460;}
//moon_size=230;if(moon_flg[0]*1<2){moon_size=115;}if(moon_flg[0]*1>2){moon_size=460;}
moon_size2=moon_size/2;

//月齢計算
function moon(julian) {
//////////////////////////////////////////////////////////////////
// 月齢計算は福原直人さんのソースを使わせていただきました	//
// http://member.nifty.ne.jp/naohito/topic/moonage.js.txt	//
//////////////////////////////////////////////////////////////////
kijun=2451550.09765;//2000/1/6 23:23の新月
syuki= 29.530589;//周回日数
var k= Math.floor((julian - kijun) / syuki);
var t     = k / 1236.85;

//直前の新月日(ユリウス日)
var nmoon = kijun;
nmoon=nmoon+  syuki  * k;
nmoon=nmoon+  0.0001337 * t * t;
nmoon=nmoon-  0.40720   * Math.sin((201.5643 + 385.8169 * k) * 0.017453292519943);
nmoon=nmoon+  0.17241   * Math.sin((2.5534 +  29.1054 * k) * 0.017453292519943);
///////////////////////////////////////////////////////////////////
//月齢
d=julian - nmoon;
if(d<0){d=0;}
  return d;
}


//桁揃え
function keta(num){
  if (num < 10){ num= '0' + num;  } 
 return num;
}
//少数点揃え
function ten(num){
age=(Math.round(num*10))/10;
age=""+age;
l=age.indexOf(".",0);
if(l<0){age=age+".0";}
 return age;
}

j_tim="";
///////ユリウス日→年月日////////
nisu=new Array(0,31,28,31,30,31,30,31,31,30,31,30,31);
function jull(s){
ss=s*0.416666;
if(ss==0){clearTimeout(j_tim);return;}
jull_sub();
}
//月齢自動増減
s_nisu=new Array();
function jull_sub(){
j_tim=setTimeout("jull_sub()",200);
julian=julian+ss;
moonage=moon(julian);//現在時刻の月齢
ju=julian-0.125;
y1=Math.floor(ju/(400*365));
y2=Math.floor(ju/(100*365));
y3=Math.floor(ju/(4*365));
yy=Math.floor((ju-y3+y2-y1)/365);
nisu[2]=29;
if(yy%4==0){ nisu[2]=29;}
if(yy%100==0){ nisu[2]=28;}
if(yy%400==0){ nisu[2]=29;}
s_nisu[0]=0;
for(i=1;i<=12;i++){
s_nisu[i]=s_nisu[i-1]+nisu[i];

}
year=yy-4713+1;
dd1=(ju-y3+y2-y1-35);
dd=Math.floor(dd1%365);
ii=0;
for(i=0;i< 12;i++){
if(dd>s_nisu[i]){ii=i;}
}
month=ii+1;
ddd=dd-s_nisu[ii];

day=Math.floor(ddd);
ju2=ju-Math.floor(ju);
hh=Math.floor(ju2*1440);

hour=Math.floor(hh/60);
minute=hh%60;
you= Math.floor(ju+2)%7;
//データの値セット
dt_put();
moon_put();
}

//現在の年月日、時刻
//var moonage;
week   = new Array('\日', '\月', '\火', '\水', '\木', '\金', '\土');
//現在の年月日、時刻
function ima(){
nowDate   = new Date();
year    = nowDate.getYear();
if(year < 2000){  year += 1900;}
month  = nowDate.getMonth() + 1;
day    = nowDate.getDate();
you =nowDate.getDay();
hour   = nowDate.getHours();
minute = nowDate.getMinutes();
}

//初期化
function cls(){
ima();
keisan_sub();
dt_put();
moon_put();
}
//データ取り出し
function dt_get(){
year    = document.moon_form.nen.value*1;
month   = document.moon_form.tuki.value*1;
day   = document.moon_form.hi.value*1;
hour   = document.moon_form.ji.value*1;
minute = document.moon_form.hun.value*1;
}
//月齢計算
function keisan(){
dt_get();
keisan_sub();
dt_put();
document.getElementById("tuki_tbl").style.visibility="hidden";
moon_put();
setTimeout("moon_sow()",1000);
}
function moon_sow(){
document.getElementById("tuki_tbl").style.visibility="visible";

}
//
function keisan_sub(){
ymd=year+"/"+month+"/"+day;
d0=Date.parse(ymd);//1970/01/01からのミリ秒
d1=(hour*60+minute)*60*1000;//今日のミリ秒
d_time=(d0+d1)/ 86400000;//1970/01/01の日数
julian=d_time +2440587.5;//ユリウス通日(紀元前4713年1月1日からの日数）
moonage=moon(julian);//現在時刻の月齢
in_date= new Date(ymd);
you=in_date.getDay();
}
//データの値セット
function dt_put(){
document.moon_form.rei.value=ten(moonage);
document.moon_form.jul.value=julian;
//document.moon_form.nen.value=year;/////////
document.moon_form.tuki.value=keta(month);
document.moon_form.hi.value=keta(day);
document.moon_form.ji.value=keta(hour);
document.moon_form.hun.value=keta(minute);

document.moon_form.youbi.value=week[you];

}
//月の絵の満ち欠け
function moon_put(){
document.moon_l.height=moon_size;
document.moon_r.height=moon_size;
document.moon_l1.height=moon_size;
document.moon_r1.height=moon_size;
if(moonage<7.5){
document.moon_l1.src=img_url+"moon_rl1.gif";
document.moon_l1.width=moon_size2+1;
document.moon_l.src=img_url+"moon_rl1.gif";
document.moon_l.width=2;

p=(Math.round(Math.cos(3.1416*(((1-(7.5-moonage)/7.5))*-90/180))*100))/100;
document.moon_r1.src=img_url+"moon_rl.gif";
document.moon_r1.width=moon_size2*(1-p);
document.moon_r.src=img_url+"moon_r1.gif";
document.moon_r.width=moon_size2*(p);
tuki_tbl.filters["blur"].direction=90;
}
if(moonage>=7.5 && moonage<15){
p=(100-Math.round(Math.cos(3.1416*(((15-moonage)/7.5)*90/180))*100))/100;
document.moon_l.src=img_url+"moon_l.gif";
document.moon_l.width=moon_size2*(1-p);
document.moon_l1.src=img_url+"moon_rl1.gif";
document.moon_l1.width=moon_size2*p;

document.moon_r.src=img_url+"moon_rl.gif";
document.moon_r.width=2;
document.moon_r1.src=img_url+"moon_rl.gif";
document.moon_r1.width=moon_size2+1;
tuki_tbl.filters["blur"].direction=90;
}
if(moonage>=15 && moonage<22.5){
document.moon_l1.src=img_url+"moon_rl.gif";
document.moon_l1.width=1
document.moon_l.src=img_url+"moon_rl.gif";
document.moon_l.width=moon_size2+1;

p=(Math.round(Math.cos(3.1416*(((1-(22.5-moonage)/7.5))*-90/180))*100))/100;
document.moon_r1.src=img_url+"moon_rl1.gif";
document.moon_r1.width=moon_size2*(1-p);
document.moon_r.src=img_url+"moon_r.gif";
document.moon_r.width=moon_size2*(p);
tuki_tbl.filters["blur"].direction=270;
}
if(moonage>22.5){
p=(100-Math.round(Math.cos(3.1416*(((30-moonage)/7.5)*90/180))*100))/100;
document.moon_l.src=img_url+"moon_l1.gif";
document.moon_l.width=moon_size2*(1-p);
document.moon_l1.src=img_url+"moon_rl.gif";
document.moon_l1.width=moon_size2*p;

document.moon_r.src=img_url+"moon_rl1.gif";
document.moon_r.width=moon_size2+1;
document.moon_r1.src=img_url+"moon_rl1.gif";
document.moon_r1.width=2
tuki_tbl.filters["blur"].direction=270;
}

}


<!--月の表示-->

//月表示
document.write('<table border=0 cellpadding=20  bgcolor=#000000 style="text-align:center;filter:chroma(color=#000000,enabltd=1)"><tr><td align=center><br>');
document.write('<table height=',moon_size,' id="tuki_tbl" width=',moon_size,' cellspacing=0 cellpadding=0 background="',img_url,back_img,'" style="visibility:hidden;cursor:crosshair;filter:blur(add=1,direction=0,strength=2,enabled=1);" onContextmenu="cls();return false;" onMousemove="return false;"><tr>');
document.write('<td title="未来へ" onMouseDown="jull(0.1)" onMouseUp="jull(0)" onMouseout="jull(0)"><img src="',img_url,'moon_rl1.gif" name="moon_l1" width=',moon_size2-1,' height=',moon_size,' border=0></td>');
document.write('<td title="未来へ"  onMouseDown="jull(0.1)" onMouseUp="jull(0)" onMouseout="jull(0)"><img name="moon_l" src="',img_url,'moon_rl1.gif" width=1 height=',moon_size,' border=0>');
document.write('</td><td title="過去へ"  onMouseDown="jull(-0.1)" onMouseUp="jull(0)" onMouseout="jull(0)"><img src="',img_url,'moon_r1.gif" name="moon_r" width=',moon_size2-1,' height=',moon_size,' border=0>');
document.write('</td><td title="過去へ"   onMouseDown="jull(-0.1)" onMouseUp="jull(0)" onMouseout="jull(0)"><img src="',img_url,'moon_rl.gif" name="moon_r1"  width=1 height=',moon_size,' border=0>');
document.write('</td></tr></table><br></td></tr><tr><td align=center>');
ima();

//データ表示
text_color=document.fgColor;
if(text_color=="#000000"){text_color="#111111";}


if(moon_flg[1]!="0" && moon_flg[2]!="0"){
document.write('<font size=1 color='+text_color+'>月にマウスを押すと過去や未来へ行けます</font><br>');
}
col="color:"+text_color+";background-color:#000000;border-width:0;font-size:14";
document.write('<form name="moon_form">');
document.write('<table border=0>');
if(moon_flg[1]!="0"){
document.write('<tr id="dt_tr" style="display:inline">');
}else{
document.write('<tr id="dt_tr" style="display:none">');

}
document.write('<th style="color:'+text_color+'">');
document.write(' <input type=text name="nen" size=4 value="',year, '" style="',col,'">年');
document.write(' <input type=text name="tuki" size=2 value="', keta(month), '" style="',col,'">月');
document.write(' <input type=text name="hi" size=2 value="', keta(day), '" style="',col,'">日');
document.write(' (<input type=text name="youbi" size=1 value="" style="',col,'">)');
document.write('</th></tr><table><table>');

if(moon_flg[1]*1!=0){

document.write('<tr id="dt1_tr" style="display:inline">');
}else{
document.write('<tr id="dt1_tr" style="display:none">');

}
document.write('<th style="color:'+text_color+'">');
document.write(' <input type=text name="ji" size=2 value="',keta(hour),'" style="',col,'">時');
document.write(' <input type=text name="hun" size=2 value="',keta(minute),'" style="',col,'">分');
document.write('　　月齢 <input type=text name="rei" size=4 value="" style="',col,'">');

document.write('</th></tr><table><table> ');
if(moon_flg[2]*1!=0){

document.write('<tr id="btn_tr" style="display:inline;background:'+document.bgcolor+';">');
}else{
document.write('<tr id="btn_tr" style="display:none;background:'+document.bgcolor+';">');

}
document.write('<th style="color:'+text_color+'"><input type=button  style="color:#111111;" value="未来へ" onMouseDown="jull(+0.1)" onMouseUp="jull(0)" onMouseout="jull(0)">');

document.write('<input type=button style="color:#111111;"  value="過去へ" onMouseDown="jull(-0.1)" onMouseUp="jull(0)" onMouseout="jull(0)">');
document.write('<input type=hidden name="jul"  value="">');
document.write('<input type=button style="color:#111111;"  value="現時刻" onClick="cls()">');
document.write('<input type=button style="color:#111111;"  value="入力日" onClick="keisan()"></th></tr></table>');
document.write('</td></tr></table></form>');
if(moon_flg[1]!="0" && moon_flg[2]!="0"){
document.write('<a href="http://www2a.biglobe.ne.jp/~qpon/js/index.htm?http://qpon.quu.cc/java/moon/qponmoon_b.htm" target="_new"><font color='+document.fgColor+' size=1>システム提供：ＱＰＯＮ</font></a>');
document.write('<font color='+document.fgColor+' size=1>　(算式：福原さん/</font>');
document.write('<a href="http://homepage2.nifty.com/hero-kyoei/" target="_new"><font color='+document.fgColor+' size=1>写真：Heroさん)</font></a><br>');

}

