// JavaScript Document


addListener(window, 'load', function() {

	initialize();

	document.getElementById("mail_edit").onclick = function () {
		changeViewBlock();
	}

	if(document.getElementById("mail_cancel")) {
		document.getElementById("mail_cancel").onclick = function() {
			var action = confirm("申し込みを中止します！");
			if(action ) {
				window.location.href = "http://170thanniversary.yosikawaya.com/chara-form.html";
			}
			else {
				return false;
			}
		}
	}

	document.getElementById("mail_approval").onclick = function () {
		if(document.getElementById("mail_approval").checked) {
			document.getElementById("mail_preview").disabled = false;
		}
		else{
			document.getElementById("mail_preview").disabled = true;
		}
	}

	document.getElementById("mail_form").onsubmit = function () {
		return Check(this);
	}

});

/* ----------------------------------------------------------------------
 . 確認ページの表示の切り替え
---------------------------------------------------------------------- */

function changeViewBlock() {

	document.getElementById("resultDatas").style.display = "none";

	document.getElementById("chara-datas").style.display = "block";
	document.getElementById("user-datas").style.display = "block";
	document.getElementById("info-datas").style.display = "block";


	document.getElementById("message-check").style.display = "none";
	document.getElementById("message-edit").style.display = "block";
	document.getElementById("pp_approval").style.display = "block";

	document.getElementById("checkBtn").style.display = "inline";
	document.getElementById("editBtn").style.display = "none";
	document.getElementById("submitBtn").style.display = "none";

}




function initialize(obj) {

	if(document.getElementById("mail_approval").checked) {
		document.getElementById("mail_preview").disabled = false;
	}
	else{
		document.getElementById("mail_preview").disabled = true;
	}

}

/* ----------------------------------------------------------------------
 . 
---------------------------------------------------------------------- */
function Check(FmName){

	if ( !checkNull ( FmName.mail_chara1, "「かもしかの湯イメージキャラクターの名前」が入力されていません！", "" ) ) { return false; }
	if ( !checkNull ( FmName.mail_chara2, "「さるあみの湯イメージキャラクターの名前」が入力されていません！", "" ) ) { return false; }
	if ( !checkNull ( FmName.mail_author, "「お名前」が入力されていません！", "" ) ) { return false; }
	if ( !checkNull ( FmName.mail_birthday, "「お誕生日」が入力されていません！", "" ) ) { return false; }
	if ( !checkEmpZipCd ( FmName.mail_zipcode, "「郵便番号」の形式が正しくありません！\n「960-0282」の形式で入力してください。", "" ) ) { return false; }
	if ( !checkSelect ( FmName.mail_ken, "「都道府県」が選択されていません！" ) ) { return false; }
	if ( !checkNull ( FmName.mail_address1, "「市区町村郡/番地」が入力されていません！", "" ) ) { return false; }
	if ( !checkMail ( FmName.mail_email, "「メールアドレス」が入力されていません！", "「メールアドレス」の形式が正しくありません！\n「abcd@example.jp」の形式で入力してください。", "" ) ) { return false; }

	if ( !checkEmpPhoneMobile ( FmName.mail_telHome, "「電話番号」の形式が正しくありません！\n「024-542-3604」の形式で入力してください。", "" ) ) { return false; }

}

