//画像マウスオーバー
$(function(){
    $(".rollover").mouseover(function(){
        $(this).attr("src",$(this).attr("src").replace(/^(.+)(\.[a-z]+)$/, "$1_on$2"))
    }).mouseout(function(){
        $(this).attr("src",$(this).attr("src").replace(/^(.+)_on(\.[a-z]+)$/, "$1$2"))
    }).each(function(){
        $("<img>").attr("src",$(this).attr("src").replace(/^(.+)(\.[a-z]+)$/, "$1_on$2"))
    })
});

//テーブルストライプ
$(function(){
    $("table.stripe tr:even").addClass("even");
    $("table.stripe tr:odd").addClass("odd");
    $("table.plan tr:even").addClass("even");
}
);

//_blank処理
$(function () {
    $('.blank').click(function(){
        window.open(this.href, '_blank');
        return false;
    });
});

//フォームの処理////////////
$(function(){
    $("form").submit(function(){
    
        //エラーの初期化
        $("p.error").remove();
        $("td").removeClass("error");
        
        $(":text,textarea").each(function(){
            
            //必須項目のチェック
            $(this).each(function(){
                if($(this).val()==""){
                    $(this).parent().prepend("<p class='error'>必須項目です</p>")
                }
            })
            
            //数値のチェック
            $(this).filter(".number").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>")
                }
            })
            
            //メールアドレス確認のチェック
            $(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").each(function(){
          $(this).filter(".radio").each(function(){
            if($(":radio[name="+$(this).attr("name")+"]:checked").size() == 0){
              $(this).parent().prepend("<p class='error'>連絡方法を選択してください</p>")
              }
           })
        });
        
        //エラーの際の処理
        if($("p.error").size() > 0){
          $('html,body').animate({ scrollTop: $("p.error:first").offset().top-40 }, 'slow');
          $("p.error").parent().addClass("error");
          return false;
          }
       }
 )
});
