/*****************************************************/
/**  整数の判断                                     **/
/*****************************************************/
/**  引数  valInt - 判断すべき数値                  **/
/**                                                 **/
/**  作成日時 2006-07-25                            **/
/**  更新日時 2006-07-25                            **/
/*****************************************************/
//整数の判断
function chkInt(valInt){
	if(0 == valInt/4 - Math.floor(valInt/4)){
		return true
	} else {
		return false
	}
}

/*****************************************************/
/**  日付リストのイニシャライズ                     **/
/*****************************************************/
/**  作成日時 2006-07-25                            **/
/**  更新日時 2006-07-25                            **/
/*****************************************************/
function createList(){
today = new Date();
year = new Array();
day_list = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 29);

	//年月日変数に格納
	y = today.getFullYear();
	m = today.getMonth() + 1;
	d = today.getDate();


	//年リスト構築
	document.write('<SELECT NAME="Year" onBlur="chgList_d()">')
	for(i=0; i<5 ;i++){
		year[i] = y;
		if(i==0){
			document.write('<Option Selected Value="'+ year[i] +'">',year[i]);
		} else {
			document.write('<Option Value="'+ year[i] +'">',year[i]);
		}
		y = y + 1;
	}
	document.write('</SELECT>年');

	//月リスト構築
	document.write('<SELECT NAME="Month" onBlur="chgList_d()">')
	for(i=1; i-1<12 ;i++){
		if(m != i){
			document.write('<Option Value="' + i + '">',i)
		} else {
			document.write('<Option Selected Value="' + i + '">',i)
		}
	}
	document.write('</SELECT>月')

	//日リスト構築
	document.write('<SELECT NAME="Day">')

	//閏年のチェック
	y = today.getFullYear();

	if(m != 2){
		days = day_list[m - 1]
	} else if(chkInt(y)) {
		days = day_list[12]
	} else {
		days = day_list[m - 1]
	}

	for(i=0; i<days ;i++){
		if (d != i-1){
			document.write('<Option Value="' + (i+1) + '">',i+1)
		} else {
			document.write('<Option Selected Value="' + (i+1) + '">',i+1)
		}
	}
	document.write('</SELECT>日')
}

/*****************************************************/
/**  年月を変えたとき、日付のリストを変える処理     **/
/*****************************************************/
/**  作成日時 2006-07-25                            **/
/**  更新日時 2006-07-25                            **/
/*****************************************************/
function chgList_d(){
today = new Date();
year = new Array();
day_list = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 29);

	//変数に格納
	y = today.getFullYear();
	m = today.getMonth() + 1;
	d = today.getDate();
	sel_y = document.Form1.Year.selectedIndex + y	//選択年
	sel_m = document.Form1.Month.selectedIndex + 1	//選択月
	sel_d = document.Form1.Day.selectedIndex + 1	//選択日
	len = document.Form1.Day.length					//変更前の日の数

	//閏年のチェック

	if(sel_m != 2){
		days = day_list[sel_m - 1]
	} else if(chkInt(sel_y)) {
		days = day_list[12]
	} else {
		days = day_list[sel_m - 1]
	}

	if(days != len){
		if(days < len) {
			for(i=len; i>=days; i--){
				document.Form1.Day.options[i] = null
			}
		} else {
			for(i=len; i<=days; i++){
				document.Form1.Day.options[i-1] = new Option(i,i)
			}
		}
	}
}

/*****************************************************/
/**  入力チェック及び最終確認                       **/
/*****************************************************/
/**  作成日時 2006-07-25                            **/
/**  更新日時 2006-07-25                            **/
/*****************************************************/
function inputcheck(){
today_y = String(today.getFullYear())		//今日の年
today_m = String(today.getMonth() + 1)		//今日の月
today_d = String(today.getDate())			//今日の日
sel_y = String(document.Form1.Year.value)	//選択された年
sel_m = String(document.Form1.Month.value)	//選択された月
sel_d = String(document.Form1.Day.value)	//選択された日

//月日の二桁化
if(today_m.length == 1){today_m = "0" + today_m}
if(today_d.length == 1){today_d = "0" + today_d}
if(sel_m.length == 1){sel_m = "0" + sel_m}
if(sel_d.length == 1){sel_d = "0" + sel_d}

//数値として両日付を合算
today_ymd = today_y + today_m + today_d
sel_ymd = sel_y + sel_m + sel_d

	if(document.Form1.Name.value == ""){
		alert('氏名を入力してください')
		document.Form1.Name.focus()
		return false
	}
	if(document.Form1.Zip1.value == ""){
		alert('郵便番号を入力してください')
		document.Form1.Zip1.focus()
		return false
	}
	if(document.Form1.Zip2.value == ""){
		alert('郵便番号を入力してください')
		document.Form1.Zip2.focus()
		return false
	}
	if(document.Form1.Address.value == ""){
		alert('住所を入力してください')
		document.Form1.Address.focus()
		return false
	}
	if(document.Form1.Person.value == ""){
		alert('人数を入力してください')
		document.Form1.Person.focus()
		return false
	}
	if(sel_ymd<=today_ymd){
		alert("日付が予約できない日になっています。")	
		return false
	}
	if(document.Form1.Tel.value == ""){
		alert('電話番号を入力してください')
		document.Form1.Tel.focus()
		return false
	}
	if(document.Form1.Tel.value == ""){
		alert('電話番号を入力してください')
		document.Form1.Tel.focus()
		return false
	}
	if(document.Form1.Mail.value == ""){
		alert('メールアドレスを入力してください')
		document.Form1.Mail.focus()
		return false
	}

	//メール文章作成
	document.Form1.SendData.value = createMail()
	
	res = confirm('以下の内容で予約させていただきます。\n' +
			'確認出来次第当方よりメールを送らせていただきます。\n\n' +
			document.Form1.SendData.value + '\n\n' +
			'よろしければ、OKをクリックしてください')
	if(res == false){
		return false
	}
	return true
}

/*****************************************************/
/**  メール添付用文章作成                           **/
/*****************************************************/
/**  作成日時 2006-07-25                            **/
/**  更新日時 2006-07-25                            **/
/*****************************************************/
function createMail(){
mailtext = new String()

mailtext = mailtext + 
	document.Form1.Name.value + '様\n' + 
	'〒' + document.Form1.Zip1.value + '-' + document.Form1.Zip2.value + "\n" +
	document.Form1.Address.value + '\n' +
	document.Form1.Person.value + '名\n\n' +
	'-ご予約日時-\n' +
	document.Form1.Year.value + '年' + document.Form1.Month.value + '月' + document.Form1.Day.value + '日\n' +
	document.Form1.Time.value + '\n\n' +
	'-ご連絡先-\n' + 
	document.Form1.Tel.value + '\n' +
	document.Form1.Mail.value + '\n\n' +
	'-ご要望-\n' +
	document.Form1.Message.value

	return mailtext
}
