///---八字干支--/////
function yGz(y,m,d,h,mi,zone){//年干支
 var mi=abs(mi);var zoneca=8/24-zone/24;if(zone=='')zoneca=0;
 var br=(D0(y,m,d)+(h+(mi+1)/60)/24)+zoneca;
 var rc=S(y,3,1);
 if(br<rc) //是否過立春
 y-=1;
 return round(rem(y-4,60)); 
}
function yGsz(y,m,d,h,mi,zone){//干支年公元數
 var mi=abs(mi);var zoneca=8/24-zone/24;if(zone=='')zoneca=0;
 var br=(D0(y,m,d)+(h+(mi+1)/60)/24)+zoneca;
 var rc=S(y,3,1);
 if(br<rc) //是否過立春
 y-=1;
 return y; 
}
function ysay(y){//3元
  var sany=round(rem(round((y+2726)/60),3));
 return sany; 
}
function syjy(y){//9運
  var nyi=round(rem(round((y+2726)/20+5),9));
 return nyi; 
}
function mGz(y,m,d,h,mi,zone){//月干支
 var mi=abs(mi);var zoneca=8/24-zone/24;if(zone=='')zoneca=0;
 var djr=((D0(y,m,d)+(h+(mi+1)/60)/24))+zoneca;
 if(djr>=S(y,-3,1)&&djr<S(y,-1,1))
   var gzM=10;//月
 if(djr>=S(y,-1,1)&&djr<S(y,1,1))
   var gzM=11;
 if(djr>=S(y,1,1)&&djr<S(y,3,1))
   var gzM=12;
 if(djr>=S(y,3,1)&&djr<S(y,5,1))
   var gzM=1;
 if(djr>=S(y,5,1)&&djr<S(y,7,1))
   var gzM=2;
 if(djr>=S(y,7,1)&&djr<S(y,9,1))
   var gzM=3;
 if(djr>=S(y,9,1)&&djr<S(y,11,1))
   var gzM=4;
 if(djr>=S(y,11,1)&&djr<S(y,13,1))
   var gzM=5;
 if(djr>=S(y,13,1)&&djr<S(y,15,1))
   var gzM=6;
 if(djr>=S(y,15,1)&&djr<S(y,17,1))
   var gzM=7;
 if(djr>=S(y,17,1)&&djr<S(y,19,1))
   var gzM=8;
 if(djr>=S(y,19,1)&&djr<S(y,21,1))
   var gzM=9;
 if(djr>=S(y,21,1)&&djr<S(y,23,1))
   var gzM=10;
 if(djr>=S(y,23,1)&&djr<S(y,25,1))
   var gzM=11;
 if(m==12&&djr>=S(y,25,1))
  var gzM=12;
  var gzg=gan(yGz(y,m,d,mi,zone));
 if(djr<S(y,3,1))gzg=gan((yGz(y,m,d,mi,zone))+9);
  return round(rem(12*gzg+gzM+1,60));
}
function mGza1(y,gzM){//初一為界月干支
var yGz=round(rem(y-4,60));var v=gzM;
  return round(rem(12*gan(yGz)+v+1,60));
}
function dGz(y,m,d,h){//日干支
var gzD=(h<23)?erD(y,m,d):erD(y,m,d)+1;
  return round(rem(gzD+14,60)); 
 }
function hGz(y,m,d,h){//時干支
  var v=12*gan(dGz(y,m,d,h))+floor((h+1)/2);
  if(h==23)
    v-=12; 
  return round(rem(v,60));
}
function yjx(y2){//年9星
 var vx=round(rem(y2-2,9));
  return vx; 
}
function mjxin(y,gzM){//月9星
var yGz=mm=(y+4713)*12+gzM+6;var v=round(rem(mm,9));
  return v;
}
function jxd(y,m,d){//日九星
var jxt;var jx0,jx1,jx2,jx3,jx4;
var d0s=erJD(y,1,1);
var ds=erJD(y,m,d);//當前等效儒略日
var s_12=floor(S(y-1,12,1));//上年夏至
var s0=floor(S(y,0,1));//上年冬至
var s12=floor(S(y,12,1));//當年夏至
var s24=floor(S(y,24,1));//當年冬至
var s12a=floor(S(y+1,12,1));//下年夏至
var jxxz1=(erJD(y-1,1,1))+s_12-1;//上年夏至等效儒略日
var jk1=gzs(jxxz1);if(jk1==0)jk1=60;
var xzjz1=60-jk1;if(jk1<30)xzjz1=-jk1;//上年夏至最近甲子日反差
var jz1=(jxxz1+xzjz1);//上年夏至最近甲子等效儒略日
jx0=ds-jz1;
var jxdz1=floor(d0s+s0)-1;//上年冬至等效儒略日
var jk2=gzs(jxdz1);if(jk2==0)jk2=60;
var dzjz1=60-jk2;if(jk2<30)dzjz1=-jk2;//上年冬至最近甲子日反差
var jz2=(jxdz1+dzjz1);//上年冬至最近甲子等效儒略日
jx1=ds-jz2;
var jxxz2=floor(d0s+s12)-1;//當年夏至等效儒略日
var jk3=gzs(jxxz2);if(jk3==0)jk3=60;
var xzjz2=60-jk3;if(jk3<30)xzjz2=-jk3;//當年夏至最近甲子日反差
var jz3=(jxxz2+xzjz2);//當年夏至最近甲子等效儒略日
jx2=ds-jz3;
var jxdz2=floor(d0s+s24)-1;//當年冬至等效儒略日
var jk4=gzs(jxdz2);if(jk4==0)jk4=60;
var dzjz2=60-jk4;if(jk4<30)dzjz2=-jk4;//當年冬至最近甲子日反差
var jz4=(jxdz2+dzjz2);//當年冬至最近甲子等效儒略日
jx3=ds-jz4;
var jxxz3=(erJD(y+1,1,1)+s12a)-1;//下年夏至等效儒略日
var jk5=gzs(jxxz3);if(jk5==0)jk5=60;
var xzjz3=60-jk5;if(jk5<30)xzjz3=-jk5;//下年夏至最近甲子日反差
var jz5=(jxxz3+xzjz3);//下年夏至最近甲子等效儒略日
jx4=ds-jz5;
var jx1k=(jz2-jz1-180);var j1k=0;var j1ka=0;var jx2k=(jz3-jz2-180);var j2k=0;var j2ka=0;
var jx3k=(jz4-jz3-180);var j3k=0;var j3ka=0;var jx4k=(jz5-jz4-180);var j4k=0;var j4ka=0;
if(jx1k>=60)j1k=30;
if(jx1k==-60)j1k=-33;if(jx1k==-60)j1ka=6;
if(jx2k>=60&&jx1k==0)j2k=30;
if(jx2k==-60)j2k=-33;if(jx2k==-60||jx1k==-60)j2ka=9;
if(jx3k>=60&&jx2k==0)j3k=30;
if(jx3k==-60)j3k=-33;if(jx3k==-60||jx2k==-60)j3ka=6;
if(jx4k>=60&&jx3k==0)j4k=30;
if(jx4k==-60)j4k=-33;if(jx4k==-60||jx3k==-60)j4ka=9;

if(ds>=jz1)jxt=(jx0%9);if(ds>=jz2-j1k)jxt=(9-((jx1-j1ka)%9+1))%9;if(ds>=jz3-j2k)jxt=((jx2-j2ka)%9);if(ds>=jz4-j3k)jxt=(9-((jx3-j3ka)%9+1))%9;
if(ds>=jz5-j4k)jxt=((jx4-j4ka)%9);if(jxt<0&&y>=-4711)jxt=(jxt+9)%9;
var jxs=round(rem(jxt,9));
  return jxs;
}
function yesb(y){//年宿
  return round(rem(y-14,28)); 
}
function ysgj(y){//管局宿
var gj=28-rem((floor(((y+36)%56)/2)),28);if(gj==28)gj=0;
  return gj;
}
function mesb(y,gzM){//月宿
var mm=(y+4713)*12+gzM+7; 
var v=round(rem(mm,28));if(gzM<0) v='';
  return v;
}
function desb(jd){//日宿
  return round(rem((jd+11),28));
}