var week = new Array("日", "月", "火", "水", "木", "金", "土")
var sy = 1583

function dw(j)
{
  return week[(j+1)%7]
}

function Int(x)
{
  return Math.floor(x+(x < 0 ? 1 : 0))
}
 
function J_day(iy, jm, kd)
{
  var tmp = jm < 3 ? -1 : 0
  return kd-32075+Int( 1461*(iy+4800+tmp)/4 )+Int( 367*(jm-2-tmp*12)/12 )-Int( 3*( Int( (iy+4900+tmp)/100 ) )/4 )
//  return kd-32075+Int( 1461*(iy+4800+Int( (jm-14)/12) )/4 )+Int( 367*(jm-2-Int( (jm-14)/12 )*12)/12 )-Int( 3*( Int( (iy+4900+Int( (jm-14)/12 ))/100 ) )/4 )
}

function date(jul)
{
  var l, n, iy, jm, kd
  l = jul+68569
  n = Int(4*l/146097)
  l -= Int((146097*n+3)/4)
  iy = Int(4000*(l+1)/1461001)
  l -= Int(1461*iy/4)-31
  jm = Int(80*l/2447)
  kd = l-Int(2447*jm/80)
  l = Int(jm/11)
  jm = jm+2-12*l
  iy = 100*(n-49)+iy+l
  return iy+"/"+jm+"/"+kd
}

function invalidInt(x, ll, ul)
{
  var temp = parseFloat(x)
  if (isNaN(temp)) {
    alert("数値でないか，入力が不完全です")
    return 1
  }
  else if (temp != parseInt(x) || temp <= 0) {
    alert("年月日などは正整数でなくてはいけません")
    return 1
  }
  else if (temp < ll || temp > ul) {
    alert("入力値は "+temp+" ですが，"+ll+" 以上，"+ul+" 以下でなくてはなりません")
    return 1
  }
  return 0
}

function calc(f)
{
  var y1, m1, d1, w1, j1, y2, m2, d2, w2, j2, diff
  f.diff.value = f.w1.value = f.w2.value = ""
  if (invalidInt(f.y1.value, sy, 9999)) return
  if (invalidInt(f.m1.value, 1, 12)) return
  if (invalidInt(f.d1.value, 1, 31)) return
  if (invalidInt(f.y2.value, sy, 9999)) return
  if (invalidInt(f.m2.value, 1, 12)) return
  if (invalidInt(f.d2.value, 1, 31)) return
  y1 = eval(f.y1.value)
  m1 = eval(f.m1.value)
  d1 = eval(f.d1.value)
  y2 = eval(f.y2.value)
  m2 = eval(f.m2.value)
  d2 = eval(f.d2.value)
  j1 = J_day(y1, m1, d1)
  j2 = J_day(y2, m2, d2)
  if (y1+"/"+m1+"/"+d1 != date(j1)) {
    alert(y1+"/"+m1+"/"+d1+" などというような日は存在しません")
    return
  }
  if (y2+"/"+m2+"/"+d2 != date(j2)) {
    alert(y2+"/"+m2+"/"+d2+" などというような日は存在しません")
    return
  }
  diff = j2-j1+1
  f.diff.value = diff
  f.w1.value = dw(j1)
  f.w2.value = dw(j2)
}

    function calc2()
    {
        with(document.f2)
        {
            if(diff.value >= 8)
                dtc1.value = eval( ( (document.f2.diff.value) - 7 ) * 1000 ) + eval( (document.f3.unit1.value) * 7 );
            else if(diff.value >= 8)
                dtc1.value = eval(document.f3.unit1.value) * eval(document.f2.diff.value);
            else if(diff.value > 0)
                dtc1.value = eval(document.f3.unit1.value) * eval(document.f2.diff.value);
            else
            {
                dtc1.value = "計算不可能";
                alert("正しい数値を入力してください。");
            }
        }
    }

function display_df()
{
document.f2.difs.value = eval(document.f2.diff.value) - 1;
}
	
function prev()
{
	myTBL0.rows[0].cells[1].innerHTML = document.f3.data2.value +"〜"+document.f3.data4.value;
	myTBL0.rows[1].cells[1].innerHTML = document.f2.difs.value+"泊"+document.f2.diff.value+"日";
	myTBL0.rows[2].cells[1].innerHTML = document.f3.goods.value;
}

function display(f){
  i=document.f1.select1.selectedIndex;
  document.f2.y1.value = document.f1.select1.options[i].text;
  i=document.f1.select2.selectedIndex;
  document.f2.m1.value = document.f1.select2.options[i].text;
  i=document.f1.select3.selectedIndex;
  document.f2.d1.value = document.f1.select3.options[i].text;
  i=document.f1.select4.selectedIndex;
  document.f2.y2.value = document.f1.select4.options[i].text;
  i=document.f1.select5.selectedIndex;
  document.f2.m2.value = document.f1.select5.options[i].text;
  i=document.f1.select6.selectedIndex;
  document.f2.d2.value = document.f1.select6.options[i].text;
}

function display_k(){
  document.f3.id.value = document.form1.id_k.value;
  document.f3.goods.value = document.form1.goods_k.value;
  document.f3.unit1.value = document.form1.unit_k.value;
}
function display_c(){
  document.f3.id.value = document.form1.id_c.value;
  document.f3.goods.value = document.form1.goods_c.value;
  document.f3.unit1.value = document.form1.unit_c.value;
}
function display_o(){
  document.f3.id.value = document.form1.id_o.value;
  document.f3.goods.value = document.form1.goods_o.value;
  document.f3.unit1.value = document.form1.unit_o.value;
}
function display_n(){
  document.f3.id.value = document.form1.id_n.value;
  document.f3.goods.value = document.form1.goods_n.value;
  document.f3.unit1.value = document.form1.unit_n.value;
}

function display2(){
  document.f3.data1.value = document.f2.difs.value+"泊"+document.f2.diff.value+"日";
  document.f3.data2.value = document.f2.y1.value+"年"+document.f2.m1.value+"月"+document.f2.d1.value+"日";
  document.f3.data3.value = document.f2.y1.value+"年"+document.f2.m1.value+"月"+document.f2.d1.value+"日";
  document.f3.data4.value = document.f2.y2.value+"年"+document.f2.m2.value+"月"+document.f2.d2.value+"日";
  document.f3.data5.value = document.f3.goods.value;
  document.f3.data6.value = document.f2.dtc1.value;
  document.f3.data7.value = document.f2.dis1.value;
  document.f3.data8.value = eval(document.f2.dtc1.value) + eval(document.f2.dis1.value);
}

function sendData()
{
  text = document.f3.data1.value;
  parent.p2.dataFunc(text,1);
  text = document.f3.data2.value;
  parent.p2.dataFunc(text,2);
  text = document.f3.data3.value;
  parent.p2.dataFunc(text,3);
  text = document.f3.data4.value;
  parent.p2.dataFunc(text,4);
  text = document.f3.data5.value;
  parent.p2.dataFunc(text,5);
  text = document.f3.data6.value;
  parent.p2.dataFunc(text,6);
  text = document.f3.data7.value;
  parent.p2.dataFunc(text,7);
  text = document.f3.data8.value;
  parent.p2.dataFunc(text,8);
  location.href = "p2.html";
}

function jump1(){
setTimeout('top.location.href="../../map.html"',0);
}
