﻿<!--
$(function(){
	$("form").submit(function(){
		//エラーの初期化
		$("p.error").remove();
		$("table td").removeClass("error");

		$(":tel,text,textarea").filter(".validate").each(function(){
		//必須項目のチェック
			$(this).filter(".required").each(function(){
				if($(this).val()==""){
				$(this).parent().prepend("<p class='error'>▼ 必須項目です　<img src='img/hisu2.jpg' alt='必須' align='top'></p>")
				}
			})


		//数値のチェック／必須1
			$(this).filter(".number1").each(function(){
				if(isNaN($(this).val())){
				$(this).parent().prepend("<p class='error'>数値のみ入力可能です（半角数字のみ）</p>")
				}
				if($(this).val()==""){
				$(this).parent().prepend("<p class='error'>必須項目1です</p>")
				}
			})
		//数値のチェック／必須2
			$(this).filter(".number2").each(function(){
				if(isNaN($(this).val())){
				$(this).parent().prepend("<p class='error'>数値のみ入力可能です（半角数字のみ）</p>")
				}
				if($(this).val()==""){
				$(this).parent().prepend("<p class='error'>必須項目2です</p>")
				}
			})

		//数値のチェック／必須
			$(this).filter(".number").each(function(){
				if(isNaN($(this).val())){
				$(this).parent().prepend("<p class='error'>数値のみ入力可能です（半角数字のみ）</p>")
				}
				if($(this).val()==""){
				$(this).parent().prepend("<p class='error'>必須項目です</p>")
				}
			})

		//数値のチェック3
			$(this).filter(".number3").each(function(){
				if(isNaN($(this).val())){
				$(this).parent().prepend("<p class='error'>数値のみ入力可能です（半角数字のみ）</p>")
				}
			})
		//メールアドレスのチェック
			$(this).filter(".mail").each(function(){
				if($(this).val() && !$(this).val().match(/.+@.+\..+/g)){										$(this).parent().prepend("<p class='error'>● メールアドレスの形式が異なります</p>")					}
				if($(this).val()==""){
				$(this).parent().prepend("<p class='error'>▼ 必須項目です　<img src='img/hisu2.jpg' alt='必須' align='top'></p>")
				}
			})
		//メールアドレス確認のチェック
			$(this).filter(".mail_check").each(function(){
				if($(this).val() && $(this).val()!=$("input[name="+$(this).attr("name").replace(/^(.+)_check$/, "$1")+"]").val()){
				$(this).parent().prepend("<p class='error'>メールアドレスと入力内容（確認）が異なります</p>")					}
			})
		})

		//ラジオボタンのチェック
		$(":radio").filter(".validate").each(function(){
			$(this).filter(".required").each(function(){
				if($(":radio[name="+$(this).attr("name")+"]:checked").size() == 0){
					$(this).parent().prepend("<p class='error'>▼ 選択してください　<img src='img/hisu2.jpg' alt='必須' align='top'></p>")
				}
			})
		})
		//チェックボックスのチェック
		$(".checkboxRequired").each(function(){
			if($(":checkbox:checked",this).size()==0){
				$(this).prepend("<p class='error'>▼ 選択してください　<img src='img/hisu2.jpg' alt='必須' align='top'></p>")
			}
		})
		// その他項目のチェック
		$(".validate.add_text").each(function(){
			if($(this).attr("checked")==true && $("input[name="+$(this).attr("name").replace(/^(.+)$/, "$1_text")+"]").val()==""){
			$(this).prepend("<p class='error'>その他の項目を入力してください。</p>")
			}
		})

		//セレクトメニュのチェック
		$(":option").filter(".validate").each(function(){
			$(this).filter(".select").each(function(){
				if($(":option[name="+$(this).attr("name")+"]:selected").val() == ""){
					$(this).parent().prepend("<p class='error'>▼ 選択してください　<img src='img/hisu2.jpg' alt='必須' align='top'></p>")
				}
			})
		})

			//エラーの際の処理
		if($("p.error").size() > 0){
			$('html,body').animate({ scrollTop: $("p.error:first").offset().top-40 }, 'slow');
			$("p.error").parent().addClass("error");
			return false;
		}
	})
})
-->
