var prefId;     // 都道府県のID
var mcodeId;    // 市区町村のID

// 必要なIDの取得処理
$(function() {
  prefId    = $("select").eq(1).attr('id');
  mcodeId   = $("select").eq(2).attr('id');
});

// 都道府県セレクタ変更時の処理
$(document).ready(
  function() {
    $("#" + prefId).change(
      function() {
        $.get("/candidates/getMunicipalityList/"
          + $(this).val(), function(data) {
          $("#" + mcodeId).removeClass("errorTxt");
          $("p[htmlfor=" + mcodeId + "]").text('');
          $("#" + mcodeId).html(data);
        });
    });
});

/*
// Jobの場合
$(document).ready(
  function() {
    $("#JobPostCode01").keyup(
      function() {
        var pCode       = $(this).val();
        var pCodeLength = pCode.length;
        if (pCodeLength == 7) {
          if (pCode != $("#JobPrefectureNo").attr('pcode')) {
            $.get("/candidates/getPref/"
              + $(this).val(), function(data) {
              if (data != ""){
                $("#JobPrefectureNo").val(data);
              }
            });

            $.get("/candidates/getMNameList/"
              + $(this).val(), function(data) {
              if (data != ""){
                $("#JobMcode").html(data);
                $("#JobMcode").removeClass("errorTxt");
                $("p[htmlfor=JobMcode]").text('');
              } else {
                //DBよりデータが取得できなかった場合の処理
                // ToDoNothing
              }
            });

            $.get("/candidates/getMNumber/"
              + $(this).val(), function(data) {
              if (data != ""){
                $("#JobAddress").val(data);
                $("#JobAddress").removeClass("errorTxt");
                $("p[htmlfor=JobAddress]").text('');
              }
            });
          }

          $("#JobPrefectureNo").attr('pcode', pCode);
        }
    });
});

// Landingの場合
$(document).ready(
  function() {
    $("#LandingPostCode01").keyup(
      function() {
        var pCode       = $(this).val();
        var pCodeLength = pCode.length;
        if (pCodeLength == 7){
          if (pCode != $("#LandingPrefectureNo").attr('pcode')) {
            $.get("/candidates/getPref/"
              + $(this).val(), function(data) {
              if (data != ""){
                $("#LandingPrefectureNo").val(data);
              }
            });

            $.get("/candidates/getMNameList/"
              + $(this).val(), function(data) {
              if (data != ""){
                $("#LandingMcode").html(data);
                $("#LandingMcode").removeClass("errorTxt");
                $("p[htmlfor=LandingMcode]").text('');
              } else {
                //DBよりデータが取得できなかった場合の処理
                // ToDo Nothing
              }
            });

            $.get("/candidates/getMNumber/"
              + $(this).val(), function(data) {
              if (data != ""){
                $("#LandingAddress").val(data);
                $("#LandingAddress").removeClass("errorTxt");
                $("p[htmlfor=LandingAddress]").text('');
              }
            });
          }
          $("#LandingPrefectureNo").attr('pcode', pCode);
        }
    });
});

// Contentの場合
$(document).ready(
  function() {
    $("#ContentPostCode01").keyup(
      function() {
        var pCode       = $(this).val();
        var pCodeLength = pCode.length;
        if (pCodeLength == 7){
          if (pCode != $("#ContentPrefectureNo").attr('pcode')) {
            $.get("/candidates/getPref/"
              + $(this).val(), function(data) {
              if (data != ""){
                $("#ContentPrefectureNo").val(data);
              }
            });

            $.get("/candidates/getMNameList/"
              + $(this).val(), function(data) {
              if (data != ""){
                $("#ContentMcode").html(data);
                $("#ContentMcode").removeClass("errorTxt");
                $("p[htmlfor=ContentMcode]").text('');
              } else {
                //DBよりデータが取得できなかった場合の処理
                // ToDoNothing
              }
            });

            $.get("/candidates/getMNumber/"
              + $(this).val(), function(data) {
              if (data != ""){
                $("#ContentAddress").val(data);
                $("#ContentAddress").removeClass("errorTxt");
                $("p[htmlfor=ContentAddress]").text('');
              }
            });
          }
          $("#ContentPrefectureNo").attr('pcode', pCode);
        }
    });
});

// Candidateの場合
$(document).ready(
  function() {
    $("#CandidatePostCode01").keyup(
      function() {
        var pCode       = $(this).val();
        var pCodeLength = pCode.length;
        if (pCodeLength == 7){
          if (pCode != $("#CandidatePrefectureNo").attr('pcode')) {
            $.get("/candidates/getPref/"
              + $(this).val(), function(data) {
              if (data != ""){
                $("#CandidatePrefectureNo").val(data);
              }
            });

            $.get("/candidates/getMNameList/"
              + $(this).val(), function(data) {
              if (data != ""){
                $("#CandidateMcode").html(data);
                $("#CandidateMcode").removeClass("errorTxt");
                $("p[htmlfor=CandidateMcode]").text('');
              } else {
                //DBよりデータが取得できなかった場合の処理
                // ToDo Nothing
              }
            });

            $.get("/candidates/getMNumber/"
              + $(this).val(), function(data) {
              if (data != ""){
                $("#CandidateAddress").val(data);
                $("#CandidateAddress").removeClass("errorTxt");
                $("p[htmlfor=CandidateAddress]").text('');
              }
            });
          }
          $("#CandidatePrefectureNo").attr('pcode', pCode);
        }
    });
}); */
