/*******************************************************************************
 * file name	: head.js
 * 				: 
 * created by	: 2006.01.18 - A.Inamura
 * modyfiy		: 2006.01.18 - A.Inamura - 新規作成
 ******************************************************************************/


/***********************************************************
 * function name	: setMenu
 *					: メニューボタンの初期設定
 * params			: -
 * return			: -
 **********************************************************/
if (document.images) { 

	// 設定開始（使用する画像を設定してください） 

	// 画像1 
	var img1on = new Image();
	img1on.src = "../img/menu01_on.jpg"; // ポイント時の画像
	var img1off = new Image();
	img1off.src = "../img/menu01_off.jpg"; // 通常の画像

	// 画像2 
	var img2on = new Image();
	img2on.src = "../img/menu02_on.jpg";
	var img2off = new Image();
	img2off.src = "../img/menu02_off.jpg";


	// 画像3 
	var img3on = new Image();
	img3on.src = "../img/menu03_on.jpg";
	var img3off = new Image();
	img3off.src = "../img/menu03_off.jpg";

	// 画像4 
	var img4on = new Image();
	img4on.src = "../img/menu04_on.jpg";
	var img4off = new Image();
	img4off.src = "../img/menu04_off.jpg";

	// 画像5 
	var img5on = new Image();
	img5on.src = "../img/menu05_on.jpg";
	var img5off = new Image();
	img5off.src = "../img/menu05_off.jpg";

	// 設定終了 

}

/***********************************************************
 * function name	: onMause()
 *					: メニューボタンポイント時の表示処理
 * params			: -
 * return			: -
 **********************************************************/

// ポイント時の処理 
function onMause(name) { 
	if (document.images) { 
		document.images[name].src = eval(name + 'on.src'); 
	} 
	return false;
} 

/***********************************************************
 * function name	: offMause()
 *					: メニューボタン開放時の表示処理
 * params			: -
 * return			: -
 **********************************************************/
function offMause(name) { 
	if (document.images) { 
		document.images[name].src = eval(name + 'off.src'); 
	} 
} 


/***********************************************************
 *					: メッセージ定義
 **********************************************************/
var arrMsgBox = new Array();

arrMsgBox[1] = '%1%を入力して下さい。';
arrMsgBox[2] = '%1%を選択してください。';
arrMsgBox[3] = '%1%は半角数値で入力して下さい。';
arrMsgBox[4] = '%1%は半角数値又は「-」で入力して下さい。';
arrMsgBox[5] = '%1%の書式に誤りがあります。';
arrMsgBox[6] = '%1%は%2%桁で入力して下さい。';

/***********************************************************
 * function name	: getMsg
 *					: メッセージを取得する
 * params			: メッセージ番号
 * params			: 変換文字1
 * params			: 変換文字2
 **********************************************************/
function getMsg(no, rep1, rep2) {
	var msg = arrMsgBox[no];
	msg = msg.replace('%1%', rep1);
	msg = msg.replace('%2%', rep2);
	alert(msg);
	return false;
}

/***********************************************************
 * function name	: validForm
 *					: 入力フォームの内容をチェックする
 * params			: フォームオブジェクト
 * return			: 正常:true／異常:false
 **********************************************************/
function validForm(objform) {
	// 申込み内容
	if ( objform.info[0].checked == false && objform.info[1].checked == false ) {
		getMsg( '2', '申込み内容' );
		objform.info[0].focus();
		return false;
	}

	// お名前
	if ( objform.namekanji.value == '' ) {
		getMsg( '1', 'お名前' );
		objform.namekanji.focus();
		return false;
	}

	// お名前(フリガナ)
	if ( objform.namekana.value == '' ) {
		getMsg( '1', 'お名前(フリガナ)' );
		objform.namekana.focus();
		return false;
	}

	// 性別
	if ( objform.sex[0].checked == false && objform.sex[1].checked == false) {
		getMsg( '2', '性別' );
		objform.sex[0].focus();
		return false;
	}

	// 郵便番号(上)
//	if ( objform.zipcode1.value == '' ) {
//		getMsg( '1', '郵便番号(前半)' );
//		objform.zipcode1.focus();
//		return false;
//	} else {
//		if ( objform.zipcode1.value.length != 3 ) {
//			getMsg( '6', '郵便番号(前半)', '3' );
//			objform.zipcode1.focus();
//			return false;

//		} else if (!isNumber(objform.zipcode1.value) ) {
//			getMsg( '3', '郵便番号(前半)' );
//			objform.zipcode1.focus();
//			return false;
//		}
//	}

	// 郵便番号(下)
//	if ( objform.zipcode2.value == '' ) {
//		getMsg( '1', '郵便番号(後半)' );
//		objform.zipcode2.focus();
//		return false;
//	} else {
//		if ( objform.zipcode2.value.length != 4 ) {
//			getMsg( '6', '郵便番号(後半)', 4 );
//			objform.zipcode2.focus();
//			return false;

//		} else if ( !isNumber(objform.zipcode2.value)) {
//			getMsg( '3', '郵便番号(後半)' );
//			objform.zipcode2.focus();
//			return false;
//		}
//	}

	// 都道府県
//	if ( objform.add1.selectedIndex == 0 ) {
//		getMsg( '2', '都道府県' );
//		objform.add1.focus();
//		return false;
//	}

	// 区市町村
//	if ( objform.add2.value == '' ) {
//		getMsg( '1', '区市町村' );
//		objform.add2.focus();
//		return false;
//	}

	// 番地
//	if ( objform.add3.value == '' ) {
//		getMsg( '1', '番地' );
//		objform.add3.focus();
//		return false;
//	}

	// 電話番号とEMailの両方が入力されていない場合
	if (  objform.tel.value == '' && objform.mail.value == ''  ) {
		getMsg( '1', 'お電話番号又はメールアドレス' );
		objform.tel.focus();
		return false;
	}


	// 電話番号
//	if ( objform.tel.value == '' ) {
//		getMsg( '1', 'お電話番号' );
//		objform.tel.focus();
//		return false;
//	}

	// EMail
	if (objform.mail.value != '' ) {
		if (!isEMail(objform.mail.value)) {
			getMsg( '5', 'メールアドレス' );
			objform.mail.focus();
			return false;
		}
	}


//	if ( !isTel( objform.tel.value ) ) {
//		getMsg( '4', 'お電話番号' );
//		objform.tel.focus();
//		return false;
//	}

	// FAX
//	if ( objform.fax.value != '' ) {
//		if ( !isTel( objform.fax.value ) ) {
//			getMsg( '4', 'FAX' );
//			objform.fax.focus();
//			return false;
//		}
//	}


	// 受講コース
	var classFlg = false;
	for ( i = 0; objform.cls.length; i++ ) {
		if ( objform.cls[i].checked == true ) {
			classFlg=true;
			break;
		}
	}

	if ( !classFlg ) {
		getMsg( '2', '受講コース' );
		objform.cls[0].focus();
		return false;
	}

	if (objform.inf1_day.value == '') {
		getMsg( '1', '第一希望日' );
		objform.inf1_day.focus();
		return false;
	}

	if ( objform.inf1_starth.selectedIndex == 0 ) {
		getMsg( '2', '第一希望日時(開始)' );
		objform.inf1_starth.focus();
		return false;
	}

	if ( objform.inf1_endh.selectedIndex == 0 ) {
		getMsg( '2', '第一希望日時(終了)' );
		objform.inf1_endh.focus();
		return false;
	}

	objform.inf1.value = objform.inf1_day.value + " " + objform.inf1_starth.value + "〜" + objform.inf1_endh.value;

	var day2='';
	var starth2='';
	var endh2='';
	if (objform.inf2_day.value == '') {
		day2 = '指定日無し';
	} else {
		day2 = objform.inf2_day.value;
	}

	if ( objform.inf2_starth.selectedIndex == 0 ) {
		starth2 = '指定時間無し〜';
	} else {
		starth2 = objform.inf2_starth.value+'〜';
	}

	if ( objform.inf2_endh.selectedIndex == 0 ) {
		endh2 = '指定時間無し'
	} else {
		endh2 = objform.inf2_endh.value;
	}

	objform.inf2.value = day2+' '+starth2+endh2;

//	if ( objform.inf1.value == '' ) {
//		getMsg( '1', '第一希望（日時）' );
//		objform.inf1.focus();
//		return false;
//	}
	objform.submit();
}

function isEMail(emailStr) {
	if ("" == emailStr) { return true; }
	var emailPat   = /^(.+)@(.+)$/;
	var userPat    = /^[a-zA-Z0-9\._-]+$/;
	var domainPat  = /^[a-zA-Z0-9\.-]+$/;
	var invalid0   = /^(.+)\.(.+)\.(.+)$/;
	var invalid1   = /^\.(.+)/;
	var invalid2   = /(.+)\.$/;
	var invalid3   = /\.\./;
	var eMailArray = emailStr.match(emailPat);
	if ( eMailArray == null ) { return false; }
	var user = eMailArray[1];
	var dom = eMailArray[2];
	if ( user.match(userPat) == null || user.match(invalid1) != null || user.length < 1 ) {
		return false;
	}
	if ( dom.match(domainPat) == null
		|| dom.indexOf('.') == -1
		|| dom.length < 4
		|| dom.match(invalid1) != null
		|| dom.match(invalid2) != null
		|| dom.match(invalid3) != null ) {
		return false;
	}
	return true;
}

function isNumber(sStr) {
	sChk = "0123456789";
	for ( i = 0; i < sStr.length; i++ ) {
		if ( sChk.indexOf(sStr.charAt(i)) == -1 ) {
			return false;
		}
	}
	return true;
}

function isTel(sStr) {
	sChk = "0123456789-";
	for ( i = 0; i < sStr.length; i++ ) {
		if ( sChk.indexOf(sStr.charAt(i)) == -1 ) {
			return false;
		}
	}
	return true;
}

function setSch(year, month, day, w, obj) {
	if ( w == 1 ) {
		return false;
	}

	var frm=window.opener.document.entryForm;

	var str="";
	var arrWeek = new Array("日","月","火","水","木","金","土"); 

	str = year+"年"+month+"月"+day+"("+arrWeek[w]+")";
//	alert(str);

	if (obj==1) {
		frm.inf1_day.value=str;
	} else {
		frm.inf2_day.value=str;
	}
	window.close();
}

function openCal(obj) {
	window.open(
		"cal.php?obj="+obj,
		"inf1_day",
		"menubar=0,location=0,toolbar=0, width=250,height=320");
}

function winOpen(url, width, height) {
	win01=window.open(url, "", "width="+width+",height="+height+",scrollbars=yes");  
}

