//worldtime.js -- Copyright (c)2004 Jun Amanai. All rights reserved.
//Unauthorized reproduction, distribution, modification, performance of this program is strictly prohibited.

function DSStart(arg_year) {
	res=new Date(arg_year, 2, 1, 2, 0, 0);	//３月１日午前２時
	j=0;
	for(i=1;i<=14;i++) {
		res.setDate(i);
		if(res.getDay()==0){
			j++;
			if(j>=2) break;
		}
	}
	return res.getTime();	//３月第２日曜午前２時
}

function DSEnd(arg_year) {
	res=new Date(arg_year, 10, 1, 1, 0, 0);	//１１月１日午前１時
	for(i=1;i<=7;i++) { res.setDate(i); if(res.getDay()==0) break; }
	return res.getTime();	//１１月第一日曜午前１時
}

function localtime(tnow, tz, flg, yf) {
	var pad  = '';
	var nav2=""+navigator.userAgent+"";
	var nav=nav2.toLowerCase();
	if(nav.match(/mac/i) == 'mac'){ pad="　　　　　　" }
	tnum = tnow+(tzoff+tz)*60*1000;
	if ((flg!=0)&&(dss<=tnum)&&(dse>tnum)) tnum+=60*60*1000;
	t=new Date(); t.setTime(tnum);
	year = t.getFullYear()%100; if(year <10) year ="0"+year;
	year2= t.getFullYear()-1988;
	month= t.getMonth()+1; if(month<10) month="0"+month;
	day  = t.getDate();    if(day  <10) day  ="0"+day;
	hour = t.getHours();   if(hour <10) hour ="0"+hour;
	min  = t.getMinutes(); if(min  <10) min  ="0"+min;
	sec  = t.getSeconds(); if(sec  <10) sec  ="0"+sec;
	if(yf!=0) return pad+"日本時間： 平成"+year2+"年"+month+"月"+day+"日  "+hour+":"+min;
	else	  return "カリフォルニア時間： "+month+"/"+day+"/"+year+"  "+hour+":"+min;
}

function update_clock() {
	now = new Date();
	n_t = now.getTime();
	self.document.clock.tokyo.value=localtime(n_t, 9*60, 0, 1);	//GMT+0900
	self.document.clock.calif.value=localtime(n_t,-8*60, 1, 0);	//GMT-0800
	setTimeout('update_clock()',1000);
}

today=new Date();
tzoff=today.getTimezoneOffset();
year=today.getFullYear();
dss=DSStart(year);
dse=DSEnd(year);

