// 基本となる値を取得
	
	// 画像の入っているフォルダ名
	base_pass="http://203.141.15.106/fisheye_bw/";
	base_pass_color="http://203.141.15.110/fisheye/";
	error_img="../060319/error_img.png";
	
	mode = "3";
	
	// 日付を取得
	year = (new Date()).getFullYear();
	month = (new Date()).getMonth();
	month = month+1;
	date = (new Date()).getDate();

	// 時間を取得
	hours = (new Date()).getHours();
	minutes = (new Date()).getMinutes();
	seconds = (new Date()).getSeconds();
	
	// 公開遅れ対策用に10秒引く
	seconds = eval(seconds-10);

function xmode(img_id,xmode) {
	mode = xmode;
	change_img_bform(img_id);
}

// 桁合わせ関数
function formatNum(format,Num) {
	format = format-1;
	format=Math.pow(10,format);
	if(Num<format) {
		if (Num<=0){
			// 0または負の数を与えられたときにブラウザをハングさせないため
			x = 1;
		}else{
			x = Num;
		}
		while (x<format) {
			Num = 0+""+Num;
			x = x+""+0;
		}
	}
	return Num;
}

// ページをロードした時の処理
function page_onload(id) {
	change_img(id);
}

// 表示変更関数
function change_img_bform(id) {
	// フォームの値を取得する
	year = parseFloat(document.changeform.year.value);
	month = parseFloat(document.changeform.month.value);
	date = parseFloat(document.changeform.date.value);
	hours = parseFloat(document.changeform.hours.value);
	minutes = parseFloat(document.changeform.minutes.value);
	seconds = parseFloat(document.changeform.seconds.value);
	
	// 表示を適用
	change_img(id);
}


// 表示変更関数
function change_img_bbutton(id,yea,mon,dat,hou,min,sec) {
	// 入力された数値を足す
	year = eval(year+yea);
	month = eval(month+mon);
	if (mon) {
		time_sum_month();
		m_date = m_Date(year);
		if (date > m_date[month]) {
			date = m_date[month];
		}
	}
	date = eval(date+dat);
	hours = eval(hours+hou);
	minutes = eval(minutes+min);
	seconds = eval(seconds+sec);
	
	// 表示を適用
	change_img(id);
}

// 表示変更関数
function change_img(img_id) {
		// 秒を5秒区切りにする
		seconds = seconds/5;
		seconds = Math.floor(seconds);
		seconds = seconds*5
	
	// 時間値適正化
	time_sum();
	
	// 桁あわせ
	year = formatNum("4",year);
	month = formatNum("2",month);
	date = formatNum("2",date);
	hours = formatNum("2",hours);
	minutes = formatNum("2",minutes);
	seconds = formatNum("2",seconds);
	
	// フォームに値を適用
	document.getElementById("year").value=year;
	document.getElementById("month").value=month;
	document.getElementById("date").value=date;
	document.getElementById("hours").value=hours;
	document.getElementById("minutes").value=minutes;
	document.getElementById("seconds").value=seconds;
	
	// 状況を判断
	img1 = "";
	img2 = "";
	if (mode == 4) {
		img1 = "1";
	} else if (mode == 3) {
		if (hours >= 7 && hours < 17) {
			img1 = "1";
		} else {
			img2 = "1";
		}
	} else if (mode == 2) {
		img1 = "1";
		img2 = "1";
	} else if (mode == 1) {
		img2 = "1";
	}
	
	// 表示用タグ生成
	messe1 = "";
	messe2 = "";
	if (img1 == "1") {
		xseconds = seconds;
		seconds = "";
		messe1 = year+""+month+""+date+"/"+year+""+month+""+date+""+hours+""+minutes+seconds+".jpg";
		messe1 = "<img src=\""+base_pass_color+messe1+"\" />";
		seconds = xseconds;
	}
	if (img2 == "1") {
		if (hours >= 7 && hours < 17) {
			messe2 = "<img src=\""+error_img+"\" />";
		} else {
			messe2 = year+""+month+""+date+"/"+year+""+month+""+date+""+hours+""+minutes+seconds+".jpg";
			messe2 = "<img src=\""+base_pass+messe2+"\" />";
		}
	}
	
	// 表示
	document.getElementById(img_id).innerHTML=messe2+messe1;
}

// 時間値適正化関数
function time_sum() {
	if (seconds >= 60) {
		while (seconds >= 60) {
			minutes = minutes+1;
			seconds = seconds-60;
		}
	} else if (seconds < 0) {
		while (seconds < 0) {
			minutes = minutes-1;
			seconds = seconds+60;
		}
	}
	
	if (minutes >= 60) {
		while (minutes >= 60) {
			hours = hours+1;
			minutes = minutes-60;
		}
	} else if (minutes < 0) {
		while (minutes < 0) {
			hours = hours-1;
			minutes = minutes+60;
		}
	}
	
	if (hours >= 24) {
		while (hours >= 24) {
			date = date+1;
			hours = hours-24;
		}
	} else if (hours < 0) {
		while (hours < 0) {
			date = date-1;
			hours = hours+24;
		}
	}
	
	time_sum_month();
	
	m_date = m_Date(year);
	a_month = month;
	if (date > m_date[a_month]) {
		while (date > m_date[a_month]) {
			month = month+1;
			time_sum_month();
			a_month = month-1;
			m_date = m_Date(year);
			date = eval(date+"-"+m_date[a_month]);
		}
	} else if (date <= 0) {
		while (date <= 0) {
			month = month-1;
			time_sum_month();
			a_month = month;
			m_date = m_Date(year);
			date = eval(date+"+"+m_date[a_month]);
		}
	}
}

function time_sum_month() {
	if (month > 12) {
		while (month > 12) {
			year = year+1;
			month = month-12;
		}
	} else if (month <= 0) {
		while (month <= 0) {
			year = year-1;
			month = month+12;
		}
	}
}

// 月最終日取得関数
function m_Date (mD_year) {
	if (mD_year%400 == 0) {
		feb = "29";
	} else if (mD_year%100 == 0) {
		feb = "28";
	} else if (mD_year%4 == 0) {
		feb = "29";
	} else {
		feb = "28";
	}
	var m_date = new Array("31","31",feb,"31","30","31","30","31","31","30","31","30","31");
	return m_date;
}
