/***************************************************************
SYSTEM : 生地屋本店
TITLE : ダイナミックHTMLの定義
SCRIPT : script.jsp
VERSION : Ver1.0.14
LANGUAGE : JavaScript1.3
CODESET : Shift_JIS
EXPLAIN : クライアント画面共通の動きを定義する。
AUTHOR : yap
CREATED : 2006/11/09 as Ver1.0.1
UPDATED : 2007/11/15 as Ver1.0.13
UPDATED : 2012/04/17 as Ver1.0.14
***************************************************************/
/***************************************************************
カレンダーの表示
holidays=休日(m/d,-m/d,…)
(m:月 d:日 頭が-の場合は平日 順不同)
<使用例> calender("1/2,1/3,8/15,8/16,12/30,12/31");
***************************************************************/
function calender(holidays) {
//定休日の定義(0:日,1:月,2:火,3:水,4:木,5:金,6:土 複数は,で区切る)
var myRegular = [0,6]; //日曜休日
//文字色の定義
var myColTod = "#009900"; //今日の文字色
var myColHol = "#FF0000"; //祝日の文字色
var myColSun = "#FF0000"; //日曜の文字色
var myColSat = "#0000FF"; //土曜の文字色
var myColWee = "#000000"; //平日の文字色
//背景色の定義
var myBakHol = "#FFE0E0"; //休日のセル色
var myBakOpn = "#FFFFFF"; //営業日のセル色
var myBakFst = "#FFE0E0"; //祝日のセル色
var myBakNor = "#FFFFFF"; //通常日のセル色
var myBakInv = "#EEEEEE"; //無効日のセル色
//曜日名の定義
var myWeekTbl = new Array("日", "月", "火", "水", "木", "金", "土");
//休日の設定
var myHoliTbl = new Array();
if(holidays) {
var myStr = new Array();
myStr = holidays.split(",");
for(i = 0; i < myStr.length; i++) {
ret = myStr[i].match(/^\s*(-?)\s*(\d{1,2})\s*\/\s*(\d{1,2})\s*$/g);
if(ret) {
key = eval(RegExp.$2) + "/" + eval(RegExp.$3);
myHoliTbl[key] = (RegExp.$1 == "-")? 2: 1;
}
}
}
//定休日の設定
var myRegTbl = new Array();
for(i = 0; i < myRegular.length; i++) {
myRegTbl[myRegular[i]] = 1;
}
//今月/翌月/翌々月分のカレンダー表示
for(mm = 0; mm < 3; mm++) {
//初期設定
myMonthTbl = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); //月テーブル定義
myDate = new Date(); //今日の日付取得
myToday = myDate.getDate(); //日を取得
myDate.setDate(1); //日付を1日に変更
myDate.setMonth(myDate.getMonth() + mm); //表示月の設定
myYear = myDate.getYear(); //西暦年を取得
if(myYear < 1900) myYear += 1900; //西暦の調整
if(((myYear % 4) == 0 && (myYear % 100) != 0) || (myYear % 400) == 0) myMonthTbl[1] = 29; //うるう年の調整
myMonth = myDate.getMonth(); //月を取得(0〜11)
myWeek = myDate.getDay(); //1日の曜日を取得
myTblLine = Math.ceil((myWeek + myMonthTbl[myMonth]) / 7); //カレンダーの行数
myTable = new Array(7 * myTblLine); //表のセル数分定義
//カレンダーの計算
for(i = 0; i < 7 * myTblLine; i++) myTable[i] = " "; //myTableの初期化
for(i = 0; i < myMonthTbl[myMonth]; i++) myTable[i + myWeek] = i + 1; //日付の設定
//カレンダーヘッダの表示
document.write("
");
document.write("
");
document.write("", myYear, "年 ", myMonth + 1, "月 |
");
//カレンダー見出しの表示
document.write("");
for(i = 0; i < 7; i++) {
document.write("");
if(i == 0) document.write(""); //日曜の文字色
else if(i == 6) document.write(""); //土曜の文字色
else document.write(""); //平日の文字色
document.write(myWeekTbl[i], " | ");
}
document.write("
");
//カレンダー日付の表示
for(i = 0; i < myTblLine; i++) {
document.write("");
for(j = 0; j < 7; j++) {
myDay = myTable[j + (i * 7)];
myStrDate = myYear + "/" + (myMonth + 1) + "/" + myDay;
myHoliName = ktHolidayName(myStrDate);
document.write(""); //休日のセル色
else if(myHoliTbl[myStrMD] == 2) document.write("bgcolor='" + myBakOpn + "'>"); //営業日のセル色
else if(myHoliName) document.write("bgcolor='" + myBakFst + "'>"); //祝日のセル色
else if(myRegTbl[j] == 1) document.write("bgcolor='" + myBakHol + "'>"); //定休日のセル色
else document.write("bgcolor='" + myBakNor + "'>"); //通常日のセル色
} else document.write("bgcolor='" + myBakInv + "'>"); //無効日のセル色
if(mm == 0 && myDay == myToday) document.write(""); //今日の文字色
else if(myHoliName) document.write(""); //祝日の文字色
else if(j == 0) document.write(""); //日曜の文字色
else if(j == 6) document.write(""); //土曜の文字色
else document.write(""); //平日の文字色
document.write(myDay, " | ");
}
document.write("
");
}
document.write("
");
document.write("
");
}
document.write(" ※ピンク色の日は休業日です。営業時間 8:45-12:00 13:00-16:45
");
}
/***************************************************************
出荷予定日の計算
***************************************************************/
function ship() {
//何日以降の出荷日になるか指定(haisoとteikyuを足した数を6以下にすること)
haiso = 3;
//定休日の場合に加算する日数(haisoとteikyuを足した数を6以下にすること)
teikyu = 1;
//日曜定休は0、月曜は1、火曜は2…と指定
youbi = 0;
//曜日名の定義
D = new Array("日", "月", "火", "水", "木", "金", "土");
//出荷日の計算
T = new Date();
Y = T.getDay();
Y = Y + eval(haiso);
if (Y >= 7) Y = Y - 7;
Y2 = youbi + eval(haiso);
//リードタイムの計算
if((Y >= youbi) & (Y <= Y2)) {
otodoke = eval(haiso) + eval(teikyu);
} else {
otodoke = eval(haiso);
}
//出荷予定日の表示
T.setTime(T.getTime() + (otodoke * 24 * 60 * 60 * 1000));
myMonth = T.getMonth() + 1;
myDate = T.getDate();
myDay = D[T.getDay()];
document.write("本日ご注文の一番早い発送日は通常");
document.write(myMonth + '月' + myDate + '日(' + myDay + ')');
document.write("です。お急ぎの方はお申し出下さい!できるだけ対応します。
");
}
/***************************************************************
懸賞情報の表示
***************************************************************/
function prize(term, base) {
//期間の設定
if(term < 1) term = 10;
//起算日の設定
if(base) {
ret = base.match(/^\s*(\d{4})\s*\/\s*(\d{1,2})\s*\/\s*(\d{1,2})\s*$/g);
if(ret) {
reckon = new Date(eval(RegExp.$1), eval(RegExp.$2) - 1, eval(RegExp.$3), 0, 0, 0);
} else reckon = new Date(2007, 0, 2, 0, 0, 0); //2007/01/02
} else reckon = new Date(2007, 0, 2, 0, 0, 0); //2007/01/02
//現在日付の取得
now = new Date();
today = new Date(now.getYear(), now.getMonth(), now.getDate() - 1, 0, 0, 0);
//締切日の計算
if(reckon > today) {
today = reckon;
} else {
diff = Math.floor((today - reckon) / (24 * 60 * 60 * 1000));
diff = term - (diff % term);
today.setTime(today.getTime() + (diff * 24 * 60 * 60 * 1000));
}
myYear = today.getYear();
if(myYear < 1900) myYear += 1900;
myMonth = today.getMonth() + 1;
myDate = today.getDate();
if(myMonth < 10) strMonth = "0" + myMonth; else strMonth = myMonth;
if(myDate < 10) strDate = "0" + myDate; else strDate = myDate;
filename = myYear + strMonth + strDate;
//締切日の表示
document.write(" 懸賞は" + term + "日ごとに連続でやっています。今回は" + myMonth + "月" + myDate + "日までです。");
document.write("ここをクリックでプレゼントページへ!");
document.write("
\n");
}
/***************************************************************
最終更新日の表示
***************************************************************/
function update() {
//曜日名の定義
youbi = new Array("日", "月", "火", "水", "木", "金", "土");
//更新日の取得
lastDate = new Date(document.lastModified);
lastYear = lastDate.getYear();
lastMonth = lastDate.getMonth() + 1;
lastDay = lastDate.getDate();
lastWeek = youbi[lastDate.getDay()];
lastHours = lastDate.getHours();
lastMinutes = lastDate.getMinutes();
if(lastYear < 1900) lastYear += 1900;
if(lastMinutes < 10) lastMinutes = "0" + lastMinutes;
//更新日の表示
document.write("このページは " + lastYear + "年" + lastMonth + "月" + lastDay + "日(" + lastWeek + ") " + lastHours + ":" + lastMinutes + " 更新済み");
}
/***************************************************************
アクセスログの記録
***************************************************************/
function acclog() {
document.write("
");
}
/***************************************************************
アクセスログの記録
***************************************************************/
function google() {
_uacct = "UA-781894-1";
urchinTracker();
}
/***************************************************************
祝日の計算
CopyRight(C) K.Tsunoda(AddinBox) 2001 All Rights Reserved.
( http://www.h3.dion.ne.jp/~sakatsu/index.htm )
この祝日判定コードは『Excel:kt関数アドイン』で使用している
VBAマクロを[JavaScript]に移植したものです。
この関数では、2007年施行の改正祝日法(昭和の日)までを
サポートしています(9月の国民の休日を含む)。
(*1)このコードを引用するに当たっては、必ずこのコメントも
一緒に引用する事とします。
(*2)他サイト上で本マクロを直接引用する事は、ご遠慮願います。
【 http://www.h3.dion.ne.jp/~sakatsu/holiday_logic.htm 】
へのリンクによる紹介で対応して下さい。
(*3)[ktHolidayName]という関数名そのものは、各自の環境に
おける命名規則に沿って変更しても構いません。
***************************************************************/
MONDAY = 1;
TUESDAY = 2;
WEDNESDAY = 3;
// JavaScriptで扱える日付は1970/1/1〜のみ
//cstImplementTheLawOfHoliday = new Date("1948/7/20"); // 祝日法施行
//cstAkihitoKekkon = new Date("1959/4/10"); // 明仁親王の結婚の儀
cstShowaTaiso = new Date("1989/2/24"); // 昭和天皇大喪の礼
cstNorihitoKekkon = new Date("1993/6/9"); // 徳仁親王の結婚の儀
cstSokuireiseiden = new Date("1990/11/12"); // 即位礼正殿の儀
cstImplementHoliday = new Date("1973/4/12"); // 振替休日施行
// [prmDate]には "yyyy/m/d"形式の日付文字列を渡す
function ktHolidayName(prmDate)
{
MyDate = new Date(prmDate);
HolidayName = prvHolidayChk(MyDate);
if (HolidayName == "") {
if (MyDate.getDay() == MONDAY) {
// 月曜以外は振替休日判定不要
// 5/6(火,水)の判定はprvHolidayChkで処理済
// 5/6(月)はここで判定する
if (MyDate.getTime() >= cstImplementHoliday.getTime()) {
YesterDay = new Date(MyDate.getFullYear(),
MyDate.getMonth(),(MyDate.getDate()-1));
HolidayName = prvHolidayChk(YesterDay);
if (HolidayName != "") {
HolidayName_ret = "振替休日";
} else {
HolidayName_ret = "";
}
} else {
HolidayName_ret = "";
}
} else {
HolidayName_ret = "";
}
} else {
HolidayName_ret = HolidayName;
}
return HolidayName_ret;
}
//===============================================================
function prvHolidayChk(MyDate)
{
MyYear = MyDate.getFullYear();
MyMonth = MyDate.getMonth() + 1; // MyMonth:1〜12
MyDay = MyDate.getDate();
// JavaScriptで扱える日付は1970/1/1〜のみで祝日法施行後なので下記は不要
// if (MyDate.getTime() < cstImplementTheLawOfHoliday.getTime()) {
// return ""; // 祝日法施行(1948/7/20)以前
// } else;
Result = "";
switch (MyMonth) {
// 1月 //
case 1:
if (MyDay == 1) {
Result = "元日";
} else {
if (MyYear >= 2000) {
NumberOfWeek = Math.floor((MyDay - 1) / 7) + 1;
if ((NumberOfWeek == 2) && (MyDate.getDay() == MONDAY)) {
Result = "成人の日";
} else;
} else {
if (MyDay == 15) {
Result = "成人の日";
} else;
}
}
break;
// 2月 //
case 2:
if (MyDay == 11) {
if (MyYear >= 1967) {
Result = "建国記念の日";
} else;
} else {
if (MyDate.getTime() == cstShowaTaiso.getTime()) {
Result = "昭和天皇の大喪の礼";
} else;
}
break;
// 3月 //
case 3:
if (MyDay == prvDayOfSpringEquinox(MyYear)) { // 1948〜2150以外は[99]
Result = "春分の日"; // が返るので、必ず≠になる
} else;
break;
// 4月 //
case 4:
if (MyDay == 29) {
if (MyYear >= 2007) {
Result = "昭和の日";
} else {
if (MyYear >= 1989) {
Result = "みどりの日";
} else {
Result = "天皇誕生日";
}
}
} else {
if (MyDay == 30) { // 4月30日 2019年過ぎたら削除
Result = "休日";
}
// JavaScriptで扱える日付は1970/1/1〜のみなので下記は不要
// if (MyDate.getTime() == cstAkihitoKekkon.getTime()) {
// Result = "皇太子明仁親王の結婚の儀"; // (=1959/4/10)
// } else;
}
break;
// 5月 //
case 5:
switch ( MyDay ) {
case 1: // 5月1日 2019年過ぎたら削除
Result = "休日";
break;
case 2: // 5月2日 2019年過ぎたら削除
Result = "休日";
break;
case 3: // 5月3日
Result = "憲法記念日";
break;
case 4: // 5月4日
if (MyYear >= 2007) {
Result = "みどりの日";
} else {
if (MyYear >= 1986) {
if (MyDate.getDay() > MONDAY) {
// 5/4が日曜日は『只の日曜』、月曜日は『憲法記念日の振替休日』(〜2006年)
Result = "国民の休日";
} else;
} else;
}
break;
case 5: // 5月5日
Result = "こどもの日";
break;
case 6: // 5月6日
if (MyYear >= 2007) {
if ((MyDate.getDay() == TUESDAY) || (MyDate.getDay() == WEDNESDAY)) {
Result = "振替休日"; // [5/3,5/4が日曜]ケースのみ、ここで判定
} else;
} else;
break;
}
break;
// 6月 //
case 6:
if (MyDate.getTime() == cstNorihitoKekkon.getTime()) {
Result = "皇太子徳仁親王の結婚の儀";
} else;
break;
// 7月 //
case 7:
if (MyYear >= 2003) {
NumberOfWeek = Math.floor((MyDay - 1) / 7) + 1;
if ((NumberOfWeek == 3) && (MyDate.getDay() == MONDAY)) {
Result = "海の日";
} else;
} else {
if (MyYear >= 1996) {
if (MyDay == 20) {
Result = "海の日";
} else;
} else;
}
break;
// 9月 //
case 9:
//第3月曜日(15〜21)と秋分日(22〜24)が重なる事はない
MyAutumnEquinox = prvDayOfAutumnEquinox(MyYear);
if (MyDay == MyAutumnEquinox) { // 1948〜2150以外は[99]
Result = "秋分の日"; // が返るので、必ず≠になる
} else {
if (MyYear >= 2003) {
NumberOfWeek = Math.floor((MyDay - 1) / 7) + 1;
if ((NumberOfWeek == 3) && (MyDate.getDay() == MONDAY)) {
Result = "敬老の日";
} else {
if (MyDate.getDay() == TUESDAY) {
if (MyDay == (MyAutumnEquinox - 1)) {
Result = "国民の休日";
} else;
} else;
}
} else {
if (MyYear >= 1966) {
if (MyDay == 15) {
Result = "敬老の日";
} else;
} else;
}
}
break;
// 10月 //
case 10:
if (MyYear >= 2000) {
NumberOfWeek = Math.floor(( MyDay - 1) / 7) + 1;
if ((NumberOfWeek == 2) && (MyDate.getDay() == MONDAY)) {
Result = "体育の日";
} else;
} else {
if (MyYear >= 1966) {
if (MyDay == 10) {
Result = "体育の日";
} else;
} else;
}
break;
// 11月 //
case 11:
if (MyDay == 3) {
Result = "文化の日";
} else {
if (MyDay == 23) {
Result = "勤労感謝の日";
} else {
if (MyDate.getTime() == cstSokuireiseiden.getTime()) {
Result = "即位礼正殿の儀";
} else;
}
}
break;
// 12月 //
case 12:
if (MyDay == 23) {
if (MyYear >= 1989) {
Result = "天皇誕生日";
} else;
} else;
break;
}
return Result;
}
//===================================================================
// 春分/秋分日の略算式は
// 『海上保安庁水路部 暦計算研究会編 新こよみ便利帳』
// で紹介されている式です。
function prvDayOfSpringEquinox(MyYear)
{
if (MyYear <= 1947) {
SpringEquinox_ret = 99; //祝日法施行前
} else {
if (MyYear <= 1979) {
// Math.floor 関数は[VBAのInt関数]に相当
SpringEquinox_ret = Math.floor(20.8357 +
(0.242194 * (MyYear - 1980)) - Math.floor((MyYear - 1980) / 4));
} else {
if (MyYear <= 2099) {
SpringEquinox_ret = Math.floor(20.8431 +
(0.242194 * (MyYear - 1980)) - Math.floor((MyYear - 1980) / 4));
} else {
if (MyYear <= 2150) {
SpringEquinox_ret = Math.floor(21.851 +
(0.242194 * (MyYear - 1980)) - Math.floor((MyYear - 1980) / 4));
} else {
SpringEquinox_ret = 99; //2151年以降は略算式が無いので不明
}
}
}
}
return SpringEquinox_ret;
}
//=====================================================================
function prvDayOfAutumnEquinox(MyYear)
{
if (MyYear <= 1947) {
AutumnEquinox_ret = 99; //祝日法施行前
} else {
if (MyYear <= 1979) {
// Math.floor 関数は[VBAのInt関数]に相当
AutumnEquinox_ret = Math.floor(23.2588 +
(0.242194 * (MyYear - 1980)) - Math.floor((MyYear - 1980) / 4));
} else {
if (MyYear <= 2099) {
AutumnEquinox_ret = Math.floor(23.2488 +
(0.242194 * (MyYear - 1980)) - Math.floor((MyYear - 1980) / 4));
} else {
if (MyYear <= 2150) {
AutumnEquinox_ret = Math.floor(24.2488 +
(0.242194 * (MyYear - 1980)) - Math.floor((MyYear - 1980) / 4));
} else {
AutumnEquinox_ret = 99; //2151年以降は略算式が無いので不明
}
}
}
}
return AutumnEquinox_ret;
}