/*******************************
 * メールアドレスチェック
 *
 * モジュール開発
 * by 側嶋康博
 * on 2010/02/12
 *
 *******************************/
function chk_email(str) {
	part = str.split("@");
	if (part.length != 2) {
		return false;
	}
	ele = part[1].split(".");
	if (ele.length < 2) {
		return false;
	}
	if (part[0].match(/^[0-9a-zA-Z\-_\.]*$/) == null) {
		return false;
	}
	if (part[1].match(/^[0-9a-zA-Z\-_\.]*$/) == null) {
		return false;
	}
	return true;
}

/*******************************
 * 電話番号チェック
 *
 * モジュール開発
 * by 側嶋康博
 * on 2010/02/12
 * 
 *******************************/
function chk_telfax(str) {
	c = "";
	for (i = 0; i < str.length; i++) {
		d = str.substr(i,1);
		if (d == "+")	continue;
		if (d == "(")	continue;
		if (d == ")")	continue;
		if (d == "-")	continue;
		if (d == " ")	continue;
		c += d;
	}
	if (c.length < 9 || c.length > 11)	return false;
	if (c.match(/^[0-9]*$/) == null)		return false;
	return true;
}

/*******************************
 * 郵便番号チェック
 *
 * モジュール開発
 * by 側嶋康博
 * on 2010/02/12
 *
 *******************************/
function chk_zip(str) {
	if (str.length != 8)	return false;
	part = str.split("-");
	if (part[0].length != 3 && part[1].length != 4)				return false;
	if (part[0].match(/^[0-9][0-9][0-9]$/) == null)				return false;
	if (part[1].match(/^[0-9][0-9][0-9][0-9]$/) == null)	return false;
	return true;
}

/*******************************
 * フォーム入力項目チェック
 *
 * モジュール開発
 * by 側嶋康博
 * on 2010/02/12
 *
 *******************************/
function formcheck() {
	/*****************************
	 * 必須項目チェック
	 *****************************/
	str_tel = document.getElementById('NeoForm').tel.value;
	str_fax = document.getElementById('NeoForm').fax.value;
	str_email = document.getElementById('NeoForm').email.value;
	str_email2 = document.getElementById('NeoForm').email2.value;
	str_zip = document.getElementById('NeoForm').zip.value;

	if (document.getElementById('NeoForm').fname.value == "") {
		alert("Family Name（姓）を英語で入力してください");
		document.getElementById('NeoForm').fname.focus();
		return false;
	}
	else if (document.getElementById('NeoForm').lname.value == "") {
		alert("Given Name（名）を英語で入力してください");
		document.getElementById('NeoForm').lname.focus();
		return false;
	}
	else if (document.getElementById('NeoForm').attr6.value == "") {
		alert("氏名を日本語（漢字）で入力してください");
		document.getElementById('NeoForm').attr6.focus();
		return false;
	}
	else if (document.getElementById('NeoForm').company.value == "") {
		alert("Affiliation/Institution（所属）を英語で入力してください");
		document.getElementById('NeoForm').company.focus();
		return false;
	}
	else if (document.getElementById('NeoForm').attr7.value == "") {
		alert("所属を日本語（漢字）で入力してください");
		document.getElementById('NeoForm').attr7.focus();
		return false;
	}
	else if (document.getElementById('NeoForm').zip.value == "") {
		alert("郵便番号を選択してください");
		document.getElementById('NeoForm').zip.focus();
		return false;
	}
	else if (!chk_zip(str_zip)) {
		alert("郵便番号を正しく入力してください");
		document.getElementById('NeoForm').zip.focus();
		return false;
	}
	else if (document.getElementById('NeoForm').pref.value == "0") {
		alert("都道府県名を選択してください");
		document.getElementById('NeoForm').pref.focus();
		return false;
	}
	else if (document.getElementById('NeoForm').address.value == "") {
		alert("住所（市区町村・番地）を入力してください");
		document.getElementById('NeoForm').address.focus();
		return false;
	}
	else if (document.getElementById('NeoForm').attr8.value == "") {
		alert("Address（住所）を英語で入力してください");
		document.getElementById('NeoForm').attr8.focus();
		return false;
	}
	else if (document.getElementById('NeoForm').tel.value == "") {
		alert("電話番号を入力してください");
		document.getElementById('NeoForm').tel.focus();
		return false;
	}
	else if (!chk_telfax(str_tel)) { // Phone Check
		alert("半角数字と記号で電話番号を正しく入力してください");
		document.getElementById('NeoForm').tel.focus();
		return false;
	}
	else if (str_fax != "" && !chk_telfax(str_fax)) { // Fax Check
		alert("半角数字と記号でFAX番号を正しく入力してください");
		document.getElementById('NeoForm').fax.focus();
		return false;
	}
	else if (document.getElementById('NeoForm').email.value == "") {
		alert("メールアドレスを入力してください");
		document.getElementById('NeoForm').email.focus();
		return false;
	}
	else if (!chk_email(str_email)) { // Email Check
		alert("半角数字と記号でメールアドレスを正しく入力してください");
		document.getElementById('NeoForm').email.focus();
		return false;
	}
	else if (!chk_email(str_email2)) { // Email Check
		alert("半角数字と記号でメールアドレスを正しく入力してください");
		document.getElementById('NeoForm').email2.focus();
		return false;
	}
	if (str_email != str_email2) {
		alert("メールアドレスが一致しません");
		document.getElementById('NeoForm').email2.focus();
		return false;
	}
	if (document.getElementById('NeoForm').attr1.value != "0"
		&& document.getElementById('NeoForm').attr1.value != "1"
		&& document.getElementById('NeoForm').attr1.value != "2") {
		alert("適切な同伴者数（0,1,2）を入力してください");
		document.getElementById('NeoForm').attr1.focus();
		return false;
	}
	/**** 同伴者が0人の場合 ****/
	if (document.getElementById('NeoForm').attr1.value == "0") {
		if (document.getElementById('NeoForm').attr2.value != "" || document.getElementById('NeoForm').attr3.value != "") {
			alert("同伴者情報と人数との不一致があります");
			document.getElementById('NeoForm').attr1.focus();
			return false;
		}
	}
	/**** 同伴者が1人の場合 ****/
	else if (document.getElementById('NeoForm').attr1.value == "1") {
		if (document.getElementById('NeoForm').attr2.value == "" || document.getElementById('NeoForm').attr3.value != "") {
			alert("同伴者情報と人数との不一致があります");
			document.getElementById('NeoForm').attr1.focus();
			return false;
		}
	}
	/** 同伴者が2人の場合 **/
	else if (document.getElementById('NeoForm').attr1.value == "2") {
		if (document.getElementById('NeoForm').attr2.value == "" || document.getElementById('NeoForm').attr3.value == "") {
			alert("同伴者情報と人数との不一致があります");
			document.getElementById('NeoForm').attr1.focus();
			return false;
		}
	}
	else {
		return confirm("フォームを送信してもいいですか？");
	}
	return true;
}

