/* ******************************************************************************
	入力フォーム内容確認スクリプト
****************************************************************************** */
/* ==============================================================================
	Stringオブジェクト拡張
============================================================================== */
String.prototype.trim = function() {
	return this.replace(/(^\s+|\s+$)/g,'');
}
String.prototype.sanitize = function() {
	var str = this;
	str = str.replace(/&/g,"&amp;");
	str = str.replace(/</g,"&lt;");
	str = str.replace(/>/g,"&gt;");
	str = str.replace(/\"/g,"&quot;");
	str = str.replace(/\'/g,"&#39;");
	return str;
}
/* ==============================================================================
	フォーム基本機能
============================================================================== */
var Confirm = new Object();	//メッセージ格納用

function onFocus(owner) {
	owner.style.backgroundColor='#9C8B4A';
	owner.style.color='ffffff';
}
function onLostFocus(owner) {
	owner.style.backgroundColor='#ffffff';
	owner.style.color='000000';
}
/* ==============================================================================
	入力フォーム・サブミット
============================================================================== */
function onEntryFormSubmit() {
	var strMsg = "";
	var objFormTop = document.Entry;
	/* --------------------------------------------------------------------------
		入力内容検査
	-------------------------------------------------------------------------- */
	if( document.Entry.person_name.value.trim()=="" ) {
		strMsg = "　　氏名\n";
		document.Entry.person_name.focus();
	}
	if( document.Entry.zip_code1.value.trim()=="" ) {
 		if( strMsg == "" ) {
			document.Entry.zip_code1.focus();
		}
		strMsg = strMsg + "　　郵便番号\n";
	}else{
		if( document.Entry.zip_code2.value.trim()=="" ) {
			if( strMsg == "" ) {
				document.Entry.zip_code2.focus();
			}
			strMsg = strMsg + "　　郵便番号\n";
		}
	}
	if( document.Entry.address.value.trim()=="" ) {
		if( strMsg == "" ) {
			document.Entry.address.focus();
		}
		strMsg = strMsg + "　　住所\n";
	}
	if( document.Entry.tel_code1.value.trim()=="" ) {
		if( strMsg == "" ) {
			document.Entry.tel_code1.focus();
		}
		strMsg = strMsg + "　　電話番号\n";
	}else{
		if( document.Entry.tel_code2.value.trim()=="" ) {
			if( strMsg == "" ) {
				document.Entry.tel_code2.focus();
			}
			strMsg = strMsg + "　　電話番号\n";
		}else{
			if( document.Entry.tel_code3.value.trim()=="" ) {
				if( strMsg == "" ) {
					document.Entry.tel_code3.focus();
				}
				strMsg = strMsg + "　　電話番号\n";
			}
		}
	}
	if( document.Entry.age.value.trim()=="" ) {
		if( strMsg == "" ) {
			document.Entry.age.focus();
		}
		strMsg = strMsg + "　　年齢\n";
	}
	if( document.Entry.mail_master.value.trim()=="" ) {
		if( strMsg == "" ) {
			document.Entry.mail_master.focus();
		}
		strMsg = strMsg + "　　メールアドレス\n";
	}
	if( strMsg != "" ) {
		strMsg = "下記の項目が入力されていないため、送信できません。\n\n" +
					strMsg + "\n" +
					"上記の項目は、応募をお受けする際に必要な情報となりますので、\n" +
					"お手数をおかけ致しますが、漏れなく入力して頂きますよう、お願い致します。";
		alert( strMsg );
		return;
	}
	/* --------------------------------------------------------------------------
		全データをサニタイズ
	-------------------------------------------------------------------------- */
	objFormTop.person_name.value = objFormTop.person_name.value.sanitize();
	objFormTop.zip_code1.value = objFormTop.zip_code1.value.sanitize();
	objFormTop.zip_code2.value = objFormTop.zip_code2.value.sanitize();
	objFormTop.address.value = objFormTop.address.value.sanitize();
	objFormTop.tel_code1.value = objFormTop.tel_code1.value.sanitize();
	objFormTop.tel_code2.value = objFormTop.tel_code2.value.sanitize();
	objFormTop.tel_code3.value = objFormTop.tel_code3.value.sanitize();
	objFormTop.age.value = objFormTop.age.value.sanitize();
	objFormTop.mail_master.value = objFormTop.mail_master.value.sanitize();
	document.Entry.submit();
}
/* ==============================================================================
	確認フォーム・サブミット
============================================================================== */
function onConfirmFormSubmit() {
	var objFormTop = document.Entry;
	/* --------------------------------------------------------------------------
		入力内容検査
	-------------------------------------------------------------------------- */
	if( document.Entry.mail_confirm.value.trim()=="" ) {
		alert( Confirm.confirmMailNotInputErrorMessage );
		document.Entry.mail_confirm.focus();
		return;
	}
	/* --------------------------------------------------------------------------
		MailAddress
	-------------------------------------------------------------------------- */
	if( document.Entry.mail_master.value.trim() != document.Entry.mail_confirm.value.trim() ) {
		var strErrMessage = 
				Confirm.mailAddressChkErrorMessage01 + document.Entry.mail_master.value.trim() + "\n" +
				Confirm.mailAddressChkErrorMessage02 + document.Entry.mail_confirm.value.trim() + "\n\n" +
				Confirm.mailAddressChkErrorMessage03;
		alert( strErrMessage );
	} else {
		document.Entry.submit();
	}
}
