function input_marrige(inp)
{

	if(inp == 1) {
		if(window.document.fm_contact.elements['cym'].checked==true) {
			window.document.fm_contact.myy.value = "";
			window.document.fm_contact.mmm.value = "";
		}
	} else {
		window.document.fm_contact.elements['cym'].checked=false;
	}
}

function input_inv(inp)
{
	if(inp == 1) {
		if(window.document.fm_contact.elements['cni'].checked==true) {
			window.document.fm_contact.nin.value = "";
		}
	} else {
		window.document.fm_contact.elements['cni'].checked=false;
	}
}


function input_exec()
{
	if(window.document.fm_contact.lnj.value == "") {
		alert("お名前(姓)を入力してください。");
		window.document.fm_contact.lnj.focus();
		return;
	}
	if(window.document.fm_contact.fnj.value == "") {
		alert("お名前(名)を入力してください。");
		window.document.fm_contact.fnj.focus();
		return;
	}


	if(window.document.fm_contact.lnf.value == "") {
		alert("フリガナ(姓)を入力してください。");
		window.document.fm_contact.lnf.focus();
		return;
	}
	if(window.document.fm_contact.fnf.value == "") {
		alert("フリガナ(名)を入力してください。");
		window.document.fm_contact.fnf.focus();
		return;
	}

	if( window.document.fm_contact.zi1.value=="" || window.document.fm_contact.zi2.value == "") {
		alert("郵便番号を入力してください。");
		window.document.fm_contact.zi1.focus();
		return;
	}
	if(window.document.fm_contact.add.value == "") {
		alert("ご住所を入力してください。");
		window.document.fm_contact.add.focus();
		return;
	}

	if(window.document.fm_contact.tel.value == "") {
		alert("電話番号を入力してください。");
		window.document.fm_contact.tel.focus();
		return;
	}

	if(window.document.fm_contact.mal.value == "") {
		alert("メールアドレスを入力してください。");
		window.document.fm_contact.mal.focus();
		return;
	}
	if(window.document.fm_contact.mal.value!="") {
		str = window.document.fm_contact.mal.value;
		var tmp = str.match("^[0-9A-Za-z._-]+@[0-9A-Za-z.-]+$");
		if (tmp != str){
			alert("メールアドレスを正しく入力してください");
			window.document.fm_contact.mal.focus();
			return;
		}
	}

	if( window.document.fm_contact.byy.value != "" ||
		window.document.fm_contact.bmm.value != "" ||
		window.document.fm_contact.bdd.value != "") {
		var v_birth = window.document.fm_contact.byy.value + '/' + window.document.fm_contact.bmm.value + '/' + window.document.fm_contact.bdd.value;
		if(ckDate(v_birth) == false) {
			alert("生年月日を正しく入力してください");
			window.document.fm_contact.byy.focus();
			return;
		}
	}

	if(window.document.fm_contact.elements['cym'].checked==false) {
		if(window.document.fm_contact.myy.value != "" || window.document.fm_contact.mmm.value != "") {
			var v_marrige = window.document.fm_contact.myy.value + '/' + window.document.fm_contact.mmm.value + '/01';
			if(ckDate(v_marrige)==false) {
				alert("挙式予定時期を正しく入力してください");
				window.document.fm_contact.myy.focus();
				return;
			}
		}
	}

	if(window.document.fm_contact.elements['cni'].checked==false) {
		if(window.document.fm_contact.nin.value != "") {
			if(isNumeric(window.document.fm_contact.nin.value)==false){
				alert("ご招待予定人数は数字を入力してください");
				window.document.fm_contact.nin.focus();
				return;
			}
		}
	}

	if(!confirm("入力した内容を送信します。よろしいですか？")) {
		return;
	}

	window.document.fm_contact.action="contactus_send.php";
	window.document.fm_contact.submit();
}

//半角数字チェック
function isNumeric(num){
	if(isNaN(num)==true){
		return false;
	}
	return true;
}

//半角英数字チェック
function isAlphaNumeric(str) {
	if( str.match( /[^A-Za-z0-9\s.-]+/ ) ) {
		return false;
	}
	return true;
}

//半角英数字チェック
function isTelNumeric(str) {
	if( str.match( /[^0-9\s.-]+/ ) ) {
		return false;
	}
	return true;
}

//半角英字チェック
function isAlpha(str) {
	if( str.match( /[^A-Za-z\s.-]+/ ) ) {
		return false;
	}
	return true;
}

//半角ｶﾀｶﾅチェック
function isKana(str) {
	if( str.match( /[^｡-ﾟ]+/ ) ) {
		return false;
	}
	return true;
}

//全角チェック
function checkIsZenkaku(str) {
	for(var i=0; i<str.length; i++){
		/* 1文字ずつ文字コードをエスケープし、その長さが4文字以上なら全角 */
		var len=escape(str.charAt(i)).length;
		if(len>=4){
			return true;
		}
	}
	return false;
}

/**************************************************************** 
* 機　能： 入力された値が日付でYYYY/MM/DD形式になっているか調べる 
* 引　数： datestr　入力された値 
* 戻り値： 正：true　不正：false 
****************************************************************/ 
function ckDate(datestr) { 
	// 正規表現による書式チェック
	if ( !datestr.match(/^\d{4}\/[\d]+\/[\d]+$/) ) {
		return false;
	}
	var parts = datestr.split( "/" );
	var vYear = Number(parts[0]); 
	var vMonth = Number(parts[1]) - 1;
	var vDay = Number(parts[2]);

	// 月,日の妥当性チェック
	if(vMonth >= 0 && vMonth <= 11 && vDay >= 1 && vDay <= 31) {
		var vDt = new Date(vYear, vMonth, vDay);
		if(isNaN(vDt)){
			return false;
		}else if(vDt.getFullYear() == vYear && vDt.getMonth() == vMonth && vDt.getDate() == vDay){
			return true;
		}else{
			return false;
		}
	}else{
		return false;
	}
}
