// JavaScript Document

function Submit(page) {

	if(typeof document.documentElement.style.maxHeight != "undefined") {

        var err_flag = false;

        //エラーの初期化
        $("p.error").remove();
        $("dl dd").removeClass("error");
        
        $(":text,textarea").filter(".validate").each(function(){
            
            //必須項目のチェック
            $(this).filter(".required").each(function(){
                if($(this).val()==""){
                    $(this).parent().append("<p class='error'></p>")
                    err_flag = true;
                }
            })
            
            //数値のチェック
            $(this).filter(".number").each(function(){
                if(isNaN($(this).val())){
                    $(this).parent().append("<p class='error'>数値のみ入力可能です</p>")
                    err_flag = true;
                }
            })
            
            //メールアドレスのチェック
            $(this).filter(".mail").each(function(){
                if($(this).val() && !$(this).val().match(/.+@.+\..+/g)){
                    $(this).parent().append("<p class='error'>メールアドレスの形式が異なります</p>")
                    err_flag = true;
                }
            })
            
            //メールアドレス確認のチェック
            $(this).filter(".mail_check").each(function(){
                if($(this).val() && $(this).val()!=$("input[name="+$(this).attr("name").replace(/^(.+)_check$/, "$1")+"]").val()){
                    $(this).parent().append("<p class='error'>メールアドレスと内容が異なります</p>")
                    err_flag = true;
                }
            })
            
        })

        //ラジオボタンのチェック
        $(":radio").filter(".validate").each(function(){
            $(this).filter(".required").each(function(){
                if($("input[name="+$(this).attr("name")+"]:checked").size() == 0){
                    $(this).parent().append("<p class='error'>選択してください</p>")
                    err_flag = true;
                }
            })
        })
        
        //チェックボックスのチェック
        $(".checkboxRequired").each(function(){
            if($(":checkbox:checked",this).size()==0){
                $(this).append("<p class='error'>選択してください</p>")
                    err_flag = true;
            }
        })
        
        // その他項目のチェック
        $(".validate.add_text").each(function(){
            if($(this).attr("checked")==true && $("input[name="+$(this).attr("name").replace(/^(.+)$/, "$1_text")+"]").val()==""){
                $(this).parent().append("<p class='error'>その他の項目を入力してください。</p>")
                    err_flag = true;
            }
        })


        //エラーの際の処理
        if($("p.error").size() > 0){
                $('html,body').animate({ scrollTop: $("p.error:first").offset().top-40 }, 'slow');
                $("p.error").parent().addClass("error");
                return false;
        }

        if(err_flag == false) {
            document.form1['page'].value = page;
	        document.form1.submit();
        }

	} else {
		document.form1['page'].value = page;
		document.form1.submit();
	}

}

