/* b_day.js */ g_opt_mo=1; g_opt_dt=1; function opt_get1(opt1) /* selectS1よりoptionを取得 */ { g_opt_mo = parseInt( opt1.options[opt1.selectedIndex].value ); } function opt_get2(opt2) /* selectS2よりoptionを取得 */ { g_opt_dt = parseInt( opt2.options[opt2.selectedIndex].value ); } function opt_check() /* optionのcheck */ { err_flg = false; switch(g_opt_mo) { case 2: if( g_opt_dt==29 || g_opt_dt==30 || g_opt_dt==31 ) { err_flg = true; } break; case 4: case 6: case 9: case 11: if( g_opt_dt==31 ) { err_flg = true; } break; default: break; } if( err_flg == false ) { birth_search(); } else { window.alert("Mistake your select!"); } } function birth_search() { happy_flg = false; today = new Date(); /* 今日の日付を取得 */ now_year = today.getYear(); /* 今日の年を取得 */ now_month = today.getMonth() + 1; /* 今日の月を取得 */ now_date = today.getDate(); /* 今日の日を取得 */ if( now_month > g_opt_mo ) { year = now_year + 1; /* 誕生日は来年 */ } else if( now_month == g_opt_mo ) { if( now_date > g_opt_dt ) { year = now_year + 1; /* 誕生日は来年 */ } else if( now_date == g_opt_dt ) { year = now_year; happy_flg = true; /* 今日が誕生日 */ } } else { year = now_year; /* 誕生日は今年 */ } b_day = new Date(year, g_opt_mo-1,g_opt_dt); /* 次の誕生日を取得 */ mil_day = b_day - today; day = Math.ceil(mil_day/86400000); /* 日数がミリ秒で出るので日数に直してある */ /* (1000mm x 60秒 x 60分 x 24H → 86400000) */ if( happy_flg == true ) { window.alert( "Happy Birthday!" ); } else { window.alert( day+" day" ); } }