// By Y.Shiromae

function finish_tutorial_popup() {
    $.ajax({
        type: "POST",
        url: "/api/finish_tutorial_popup/",
        dataType: "json",
        success: function(data){
            if (data.success) {
            }
        }
    });
}

function add_discovery_shop() {
    $.post('/api/add_discovery_shop/',
     {"discovery_shop_name"    : $('#discovery_shop_name').val(),
      "discovery_shop_address" : $('#discovery_shop_address').val(),
      "discovery_shop_address2": $('#discovery_shop_address2').val(),
      "discovery_shop_lat"     : $('#discovery_shop_lat').val(),
      "discovery_shop_lng"     : $('#discovery_shop_lng').val(),
      "discovery_tel_1"        : $('#discovery_tel_1').val(),
      "discovery_tel_2"        : $('#discovery_tel_2').val(),
      "discovery_tel_3"        : $('#discovery_tel_3').val()
     },
     add_discovery_shop_callback,
     'json');
}

function add_discovery_shop_callback(data, status) {
    $('#shop_form_error').hide();
    $('#shop_form_error_name').hide();
    $('#shop_form_error_address').hide();
    $('#shop_form_error_latlng').hide();

    if (status == "success") {
        if (data.success) {
            // 値を初期化
            $('#discovery_shop_name').val('');
            $('#discovery_shop_address').val('');
            $('#discovery_shop_lat').val('');
            $('#discovery_shop_lng').val('');
            $('#discovery_tel_1').val('');
            $('#discovery_tel_2').val('');
            $('#discovery_tel_3').val('');

            $('#next_id').val(data.shop_id);
            $('#next_name').val(data.shop_name);
            $('#next_area_name').val(data.shop_area_name);

            $('#shop_form').hide();
            $('#excavationNextSpot').show();
            $('html,body').animate({ scrollTop: $('#excavationNextSpot').offset().top }, 'slow','swing');

            $('#excavationNextSpot').effect( 'bounce', '', 300 );
        } else {
            var invalid_param = data.invalid_param;
            if (invalid_param.name) {
                $('#shop_form_error_name').show();
            }
            if (invalid_param.address) {
                $('#shop_form_error_address').show();
            }
            if (invalid_param.latlng) {
                $('#shop_form_error_latlng').show();
            }
            $('#shop_form_error').show();
            $('html,body').animate({ scrollTop: $('#shop_form_error').offset().top }, 'slow','swing');
        }
    } else if (status == "error") {
        // リクエスト失敗
    } else if (status == "notmodified") {
        // 更新されていない
    } else if (status == "timeout") {
        // タイムアウト
    } else if (status == "parsererror") {
        // データパースエラー
    }
}

function add_discovery_staff() {
    $.post('/api/add_discovery_staff/',
     {"discovery_shop_id"       : $('#discovery_staff_shop_id').val(),
      "discovery_contents_id"   : $('input[name=discovery_contents_id]:checked').val(),
      "discovery_staff_name"    : $('#discovery_staff_name').val(),
      "discovery_description"   : $('#discovery_description').val(),
      "discovery_cheer_reason"  : $('#discovery_cheer_reason').val(),
      "discovery_tag_id_csv"    : $('#tag_id_csv').val()
     },
     add_discovery_staff_callback,
     'json');
}

function add_discovery_staff_callback(data, status) {
    $('#staff_form_error').hide();
    $('#staff_form_error_tag_id').hide();
    $('#staff_form_error_name').hide();
    $('#staff_form_error_contents_id').hide();
    $('#staff_form_error_description').hide();
    $('#staff_form_error_cheer_reason').hide();

    if (status == "success") {
        if (data.success) {
            $('#discovery_staff_shop_id').val('');
            $('#discovery_contents_id').val('');
            $('#discovery_staff_name').val('');
            $('#discovery_description').val('');
            $('#discovery_cheer_reason').val('');
            // タグリストの初期化
            $('#tag_id_csv').val('');
            $("#tag_length").html(10);
            $('#tag_select_count').html(0);
            $("#selectedTagBox").html("");
            $("#popup_tag :checkbox:checked").attr("checked",false);
            $("#popup_tag :checkbox").next("label").css({"font-weight":"", "background":""});
            $("div#popup_tag").children("p.parentCategory").children("img").attr("src","/img/common/dot_icon_plus.gif");
            $("div#popup_tag").children("p.parentCategory").next("div").slideUp();

            $('#staff_form').hide();
            $('html,body').animate({ scrollTop: ($('#excavationSearch').offset().top - 30) }, 'slow','swing');
            $('#user_comment').prepend(data.display_html);
            $('.discovery_user_box_'+data.id).effect( 'bounce', '', 300 );
            if (data.login_user_id > 0) {
                $('#ohineri30').fadeIn(1000);
                setTimeout(function(){
                    $('#ohineri30').fadeOut(1000);
                },1800);
            }
        } else {
            var invalid_param = data.invalid_param;
            if (invalid_param.tag_id) {
                $('#staff_form_error_tag_id').show();
            }
            if (invalid_param.name) {
                $('#staff_form_error_name').show();
            }
            if (invalid_param.contents_id) {
                $('#staff_form_error_contents_id').show();
            }
            if (invalid_param.description) {
                $('#staff_form_error_description').show();
            }
            if (invalid_param.cheer_reason) {
                $('#staff_form_error_cheer_reason').show();
            }
            $('#staff_form_error').show();
            $('html,body').animate({ scrollTop: $('#staff_form_error').offset().top }, 'slow','swing');
        }
    } else if (status == "error") {
        // リクエスト失敗
    } else if (status == "notmodified") {
        // 更新されていない
    } else if (status == "timeout") {
        // タイムアウト
    } else if (status == "parsererror") {
        // データパースエラー
    }
}

function get_discovery_shop() {
    var state = $('#loading_display').is(":hidden");
    if (state == false) {
        // 検索中
        return false;
    }

    $('#loading_display').show();
    discovery_shop_searching = 1;
    $('#excavationShopDrop').show();
    $('#excavationShopDropAdd').hide();
    $('#discovery_shop_display_area').empty();
    $.post('/api/search_discovery_shop/', {"discovery_shop_pref_id" : $('#discovery_shop_pref_id').val(), "discovery_shop_area_id" : $('#discovery_shop_area_id').val(), "discovery_shop_area" : $('#discovery_shop_area_form').val(), "discovery_shop_keyword" : $('#discovery_shop_keyword_form').val()}, discovery_shop_callback, 'json');
}

function discovery_shop_callback(data, status) {
    if (status == "success") {
        if (data.success) {

            $('#discovery_shop_display_area').html(data.display_html);
            $('.change_color').hover(function() {
                $(this).css('background','#f5efd0');
            }, function() {
                $(this).css('background','');
            });
            $('#excavationShopDrop').slideDown();
            // 「地図を表示」文字列にマウスを合わせると、GoogleMapが表示される。

            $('.mapPopupButton').hover(function(){
                var latlng_array = $(this).attr('rel').split(',');
                var latlng       = new google.maps.LatLng(latlng_array[1], latlng_array[2]);

                var myOptions = {
                  zoom: 14,
                  center: latlng,
                  mapTypeId: google.maps.MapTypeId.ROADMAP
                };
                var searchMap = new google.maps.Map(document.getElementById("mapPopup_"+latlng_array[0]), myOptions);
                var searchMarker = new google.maps.Marker({
                    map: searchMap,
                    position: latlng,
                    draggable: false
                });
                var mapPopup = $(this).parent().children('div.mapPopup');
                mapPopup.css('display','block');
                google.maps.event.trigger(searchMap, 'resize');
                searchMap.setCenter(latlng);
            },function(){
                $(this).parent().children('div.mapPopup').css('display','none');
            });
        }
    } else if (status == "error") {
        // リクエスト失敗
    } else if (status == "notmodified") {
        // 更新されていない
    } else if (status == "timeout") {
        // タイムアウト
    } else if (status == "parsererror") {
        // データパースエラー
    }
    $('#excavationShopDropAdd').show();
    $('#loading_display').hide();
}

function open_discovery_staff_from(id, name, area, genre, genre_icon) {

    $('#excavationShopDrop').hide();
    $('#shop_form').hide();
    $('#genre_icon').attr("src", genre_icon);
    $('#discovery_staff_shop_id').val(id);
    $('#discovery_staff_shop_name').html(name);
    $('#discovery_staff_area').html(area);
    
    $('#staff_form').slideDown();
    $('html,body').animate({ scrollTop: $('#staff_form').offset().top }, 'slow','swing');
}



function get_shop_search() {
    $('#shopol').empty();
    $("div#load_progress").html('<img src="/img/common/loading.gif" width="32" height="32" alt="Now Loading..." />');
    $.post('/api/discovery_shop_search/', {"area" : $('#discovery_area').val(), "keyword" : $('#discovery_keyword').val()}, discovery_shop_search_callback, 'json');
}

function discovery_shop_search_callback(data, status) {
    $("div#load_progress").html('');
    if (status == "success") {
        if (data.success) {
            $('#shopol').empty();
            // リクエスト成功
            var shop_list   = data.response;
            var list_exists = false;
            for (key in shop_list) {
                list_exists = true;
                
                var id         = shop_list[key]['Gid'];
                var name       = shop_list[key]['Name'];
                var address    = shop_list[key]['Property']['Address'];
                var lng_lat    = shop_list[key]['Geometry']['Coordinates'].split(",");
                $('#shopol').append("<li class=\"clearfix\"><a href=\"/discovery/index/" +id+ "/\">\
                <div class=\"shopData clearfix\">\
                <div class=\"left\">\
                <p class=\"ph\"><img src=\"../../img/fromDB/shop_view/main_thumb.jpg\" width=\"75\" /></p>\
                </div>\
                <div class=\"center\">\
                <div class=\"profile\">\
                <p class=\"name\">" +name+ "</p>\
                <p class=\"address\">" +address+ "</p>\
                </div>\
                </div>\
                <div class=\"right\">\
                <div class=\"staff\">\
                <ol class=\"staffol\">\
                </ol>\
                </div>\
                </div>\
                </div>\
                </a>\
                </li>");
/*
//                <div class=\"shopMap\">\
//                <p class=\"map\">地図を表示</p>\
//                <div class=\"mapPopup\">\
//                <iframe width=400 height=400 id=\"map_" +id+ "\" src=\"http://maps.google.co.jp/maps?f=q&source=s_q&hl=ja&geocode=&q=" +lng_lat[1]+ "," +lng_lat[0]+ "&ll=" +lng_lat[1]+ "," +lng_lat[0]+ "&output=embed&iwloc=B\"></iframe>\
//                </div>\
//                </div>\
*/
            }
            // 「地図を表示」文字列にマウスを合わせると、GoogleMapが表示される。
            $('p.map').hover(function(){
                $(this).parent().children('div.mapPopup').css('display','block');
            },function(){
                $(this).parent().children('div.mapPopup').css('display','none');
            });
            
            if (list_exists == false) {
                $('#shopol').append('検索結果は見つかりませんでした。');
            }

        }
    } else if (status == "error") {
        // リクエスト失敗
    } else if (status == "notmodified") {
        // 更新されていない
    } else if (status == "timeout") {
        // タイムアウト
    } else if (status == "parsererror") {
        // データパースエラー
    }
}

$(document).ready(function(){
    $('#zip_code_search').click(function(){
        var zip_code = $('#zip_code1').val() + $('#zip_code2').val();
        $.getJSON( '/api/zip_code/' + zip_code, function (data) {
                $('#address').val(data.city_name + data.address);
                $('#current_pref_id').val(data.pref_id);
            }
        );
    });
});

$(document).ready(function(){
    $('#shop_zip_code_search').click(function(){
        var zip_code = $('#zip_code1').val() + $('#zip_code2').val();
        $.getJSON( '/api/zip_code/' + zip_code, function (data) {
                $('#address').val(data.city_name + data.address);
                $('#pref_id').val(data.pref_id);
            }
        );
    });
});

$(document).ready(function(){
  $("input[id*='send_message_']").keypress(function (e) {
      if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
          var id = this.id;
          id = id.replace('send_message_', "");
          send_comment(id)
      }
  });
});

$(document).ready(function(){
  $("input[id*='staff_send_message_']").keypress(function (e) {
      if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
          var id = this.id;
          id = id.replace('staff_send_message_', "");
          send_comment_by_staff(id)
      }
  });
});

$(document).ready(function(){
  $("input[id*='shop_send_message_']").keypress(function (e) {
      if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
          var id = this.id;
          id = id.replace('shop_send_message_', "");
          send_comment_by_shop(id)
      }
  });
});

$(document).ready(function(){
/*
  $(':input:text')
    .blur(function(){
      var $$=$(this);
      if($$.val()=='' || $$.val()==$$.attr('title')){
        $$.css('color', '#999')
          .val($$.attr('title'));
      }
    })
    .focus(function(){
      var $$=$(this);
      if($$.val()==$$.attr('title')){
        $(this).css('color', '#000')
               .val('');
      }
    })
    .parents('form:first').submit(function(){
    var $$=$('#text');
    if($$.val()==$$.attr('title')){
      $$.triggerHandler('focus');
    }
  }).end()
  .blur();
*/
});

function replaceNewFace(type, name, shop_name, blood_type, position, pickup_image, shop_file_name) {
    var prefix = 'new_' + type;
    $('#' + prefix + '_name').html(name);
    $('#' + prefix + '_shop_name').html(shop_name);
    $('#' + prefix + '_blood_type').html(blood_type);
    $('#' + prefix + '_position').html(position);
    $('#' + prefix + '_pickup_image').attr("src", pickup_image);
    $('#' + prefix + '_shop_image').attr("src","/img/shop/gallery/" + shop_file_name);
}

function disp_comment_box(activity_id) {
    $('#resbox_' + activity_id).show();
    $('#send_message_' + activity_id).focus();
}

function disp_staff_comment_box(activity_id) {
    $('#resbox_' + activity_id).show();
    $('#staff_send_message_' + activity_id).focus();
}

function like(activity_id) {
    $.post('/api/like/' + activity_id, null, like_toggle, 'json');
}

function like_toggle(data, status) {
    if (status == "success") {
        if (data.success) {
            // リクエスト成功
            if (data.response) {
                $('#like_' + data.activity_id).html('いいね！を取り消す');
            } else {
                $('#like_' + data.activity_id).html('いいね！');
            }
            $('#iineCount_'+data.activity_id).html(data.like_count+'人');
        }
    } else if (status == "error") {
        // リクエスト失敗
    } else if (status == "notmodified") {
        // 更新されていない
    } else if (status == "timeout") {
        // タイムアウト
    } else if (status == "parsererror") {
        // データパースエラー
    }
}

function activity_delete(mode, activity_id) {
    if(confirm('メッセージを削除しますがよろしいですか？')){
        $.post('/api/activity/delete/' + mode + '/' + activity_id, null, activity_delete_callback, 'json');
    } else {
        return false;
    }
}

function activity_delete_callback(data, status) {
    if (status == "success") {
        if (data.success) {
            $('#activity_' + data.activity_id).slideUp();
        }
    } else if (status == "error") {
        // リクエスト失敗
    } else if (status == "notmodified") {
        // 更新されていない
    } else if (status == "timeout") {
        // タイムアウト
    } else if (status == "parsererror") {
        // データパースエラー
    }
}

function get_next_genre(no, class_name, element) {
    var selected_id = $('#' + element.id).val();

    switch (class_name) {
        case 'big':
            $('#genre_id' + no + '_big').empty();
            $('#genre_id' + no + '_middle').empty();
            $('#genre_id' + no + '_small').empty();
            $('#genre_id' + no + '_big_span').hide();
            $('#genre_id' + no + '_middle_span').hide();
            $('#genre_id' + no + '_small_span').hide();
            break;
        case 'middle':
            $('#genre_id' + no + '_middle').empty();
            $('#genre_id' + no + '_small').empty();
            $('#genre_id' + no + '_middle_span').hide();
            $('#genre_id' + no + '_small_span').hide();
            break;
        case 'small':
            $('#genre_id' + no + '_small').empty();
            $('#genre_id' + no + '_small_span').hide();
            break;
    }

    $.post('/api/genre/' + class_name + '/' + selected_id + '/' + no + '/', null, callback_next_genre, 'json');
}

function callback_next_genre(data, status) {
    if (status == "success") {
        if (data.success) {
            // リクエスト成功
            var genre_list = data.response;
            var no         = data.setting.no;
            var class_name = data.setting.class_name;
            var id         = data.setting.id;

            var optionItems = new Array();
            for (key in genre_list) {
                optionItems.push('<option value="' + key + '">' + genre_list[key] + '</option>');
            }
            $('#genre_id' + no + '_' + class_name).append(optionItems.join());
            $('#genre_id' + no + '_' + class_name + "_span").show();
        }
    } else if (status == "error") {
        // リクエスト失敗
    } else if (status == "notmodified") {
        // 更新されていない
    } else if (status == "timeout") {
        // タイムアウト
    } else if (status == "parsererror") {
        // データパースエラー
    }
}

function send_comment_by_shop(activity_id) {
    text_key = '#shop_send_message_' + activity_id;
    $.post('/api/send_comment/' + activity_id +'/shop/', {send_message: $(text_key).val()}, add_comment_box, 'json');
    $(text_key).val('');
}

function send_comment_by_staff(activity_id) {
    text_key = '#staff_send_message_' + activity_id;
    $.post('/api/send_comment/' + activity_id +'/staff/', {send_message: $(text_key).val()}, add_comment_box, 'json');
    $(text_key).val('');
}

function send_comment(activity_id) {
    text_key = '#send_message_' + activity_id;
    $.post('/api/send_comment/' + activity_id, {send_message: $(text_key).val()}, add_comment_box, 'json');
    $(text_key).val('');
}

function add_comment_box(data, status) {
    if (status == "success") {
        if (data.success) {
            // リクエスト成功
            $(data.response).insertBefore('#resbox_' + data.activity_id);
        }
    } else if (status == "error") {
        // リクエスト失敗
    } else if (status == "notmodified") {
        // 更新されていない
    } else if (status == "timeout") {
        // タイムアウト
    } else if (status == "parsererror") {
        // データパースエラー
    }
}

function add_notice( notice_word )
{
    if( $('#notice_1').val() == "" ) {
        $('#notice_1').val(notice_word);
    }else if( $('#notice_2').val() == "" && $('#notice_1').val() != notice_word ) {
        $('#notice_2').val(notice_word);
    }else if( $('#notice_3').val() == "" && $('#notice_1').val() != notice_word && $('#notice_2').val() != notice_word ) {
        $('#notice_3').val(notice_word);
    }else if( $('#notice_4').val() == "" && $('#notice_1').val() != notice_word && $('#notice_2').val() != notice_word && $('#notice_3').val() != notice_word) {
        $('#notice_4').val(notice_word);
    }else if( $('#notice_5').val() == "" && $('#notice_1').val() != notice_word && $('#notice_2').val() != notice_word && $('#notice_3').val() != notice_word && $('#notice_4').val() != notice_word ) {
        $('#notice_5').val(notice_word);
    }
}

function get_city_list(pref_id, select_id) {
    $('#' + select_id).empty();
    $.post('/api/city_data/' + pref_id + '/' + select_id + '/', null, callback_city_data, 'json');
}

function callback_city_data(data, status) {
    if (status == "success") {
        if (data.success) {
            // リクエスト成功
            var city_list  = data.response;
            var id         = data.setting.element_id;

            var optionItems = new Array();
            for (key in city_list) {
                optionItems.push('<option value="' + key + '">' + city_list[key] + '</option>');
            }
            $('#' + id).append(optionItems.join());
        }
    } else if (status == "error") {
        // リクエスト失敗
    } else if (status == "notmodified") {
        // 更新されていない
    } else if (status == "timeout") {
        // タイムアウト
    } else if (status == "parsererror") {
        // データパースエラー
    }
}

function get_area_list(pref_id, select_id) {
    $('#' + select_id).empty();
    $.post('/api/area_data/' + pref_id + '/' + select_id + '/', null, callback_area_data, 'json');
}

function callback_area_data(data, status) {
    if (status == "success") {
        if (data.success) {
            // リクエスト成功
            var area_list  = data.response;
            var id         = data.setting.element_id;

            var optionItems = new Array();
            for (key in area_list) {
                optionItems.push('<option value="' + key + '">' + area_list[key] + '</option>');
            }

            $('#' + id).append(optionItems.join());
        }
    } else if (status == "error") {
        // リクエスト失敗
    } else if (status == "notmodified") {
        // 更新されていない
    } else if (status == "timeout") {
        // タイムアウト
    } else if (status == "parsererror") {
        // データパースエラー
    }
}

function get_tag_list(tag_type, select_id) {
    $('#' + select_id).empty();
    $.post('/api/tag_data/' + tag_type + '/' + select_id + '/' + $('#contents_id').val() + '/', null, callback_tag_data, 'json');
}

function callback_tag_data(data, status) {
    if (status == "success") {
        if (data.success) {
            // リクエスト成功
            var tag_list   = data.response;
            var id         = data.setting.element_id;

            var optionItems = new Array();
            for (key in tag_list) {
                optionItems.push('<option value="' + key + '">' + tag_list[key] + '</option>');
            }

            $('#' + id).append(optionItems.join());
        }
    } else if (status == "error") {
        // リクエスト失敗
    } else if (status == "notmodified") {
        // 更新されていない
    } else if (status == "timeout") {
        // タイムアウト
    } else if (status == "parsererror") {
        // データパースエラー
    }
}


function change_staff_view(staff_id) {
    $.ajax({
      url: "/api/shop_staff_view/" + staff_id + "/",
      cache: false,
      success: function(html){
        $("#staff_block").html(html);
      }
    });
}

function disp_shop_staff_thumbnail(mode) {
    $("#thumb_all").hide();
    $("#thumb_musume").hide();
    $("#thumb_danshi").hide();
    $("#shopTopStaffSubNavi_all").removeClass("focus");
    $("#shopTopStaffSubNavi_musume").removeClass("focus");
    $("#shopTopStaffSubNavi_danshi").removeClass("focus");
    $("#thumb_" + mode).show();
    $("#shopTopStaffSubNavi_" + mode).addClass("focus");
}

function change_top_staff_view(staff_id) {
    $.ajax({
      url: "/api/top_staff_view/" + staff_id + "/",
      cache: false,
      success: function(html){
        $("#staff_block").html(html);
      }
    });
}


function post_important_data(mode) {
    var mode_status = false;
    if (mode == 'name') {
        var data = {shop_name:$('#important_shop_name').val(), shop_kana:$('#important_shop_kana').val()};
        mode_status = true;
    } else if (mode == 'tel') {
        var tel_array = {}; // ここで連想配列を代入
        tel_array["1"] = $('#important_tel_1').val();
        tel_array["2"] = $('#important_tel_2').val();
        tel_array["3"] = $('#important_tel_3').val();
        var data = {tel:tel_array};
        mode_status = true;
    } else if (mode == 'address') {
        var data = {pref_id:$('#important_pref_id').val(), address:$('#important_address1').val(), address_detail:$('#important_address2').val()};
        mode_status = true;
    }
    if (mode_status) {
        $.post('/api/change_important_data/' + mode + '/', data, callback_important_data, 'json');
    }
}

function callback_important_data(data, status) {
    var success_status = false;
    if (status == "success") {
        if (data.success) {
            success_status = true
            var mode       = data.mode;
            if (mode == 'name') {
                $('#important_shop_name_text').html(data.valid_field_key.shop_name)
                $('#important_shop_kana_text').html(data.valid_field_key.shop_kana)
                $('#important_name').hide();
                $('#important_name_base').show();
                $('#important_name_change_info').show();
            } else if (mode == 'tel') {
                $('#important_tel_1_text').html(data.valid_field_key.tel[1]);
                $('#important_tel_2_text').html(data.valid_field_key.tel[2]);
                $('#important_tel_3_text').html(data.valid_field_key.tel[3]);
                $('#important_tel').hide();
                $('#important_tel_base').show();
                $('#important_tel_change_info').show();
            } else if (mode == 'address') {
                var pref_name = $("#important_pref_id option[value='" +data.valid_field_key.pref_id+ "']").text();
                $('#important_pref_name_text').html(pref_name);
                $('#important_address_text').html(data.valid_field_key.address);
                $('#important_address_detail_text').html(data.valid_field_key.address_detail);
                $('#important_address').hide();
                $('#important_address_base').show();
                $('#important_address_change_info').show();
            }
        }
    } else if (status == "error") {
        // リクエスト失敗
    } else if (status == "notmodified") {
        // 更新されていない
    } else if (status == "timeout") {
        // タイムアウト
    } else if (status == "parsererror") {
        // データパースエラー
    }
    $('#important_error').hide();
    $('#important_success').hide();
    if (success_status) {
        $('#important_success').show();
    } else {
        $('#important_error').show();
    }
}

function disp_search_form(type) {
    if (type == 'shop') {
        $('#shop_search_tab').removeClass('focus');
        $('#staff_search_tab').removeClass('focus');

        $('#shop_search_tab').addClass('focus');
        $('#search_form_staff').hide();
        $('#search_form').show();
    } else if (type == 'staff') {
        $('#shop_search_tab').removeClass('focus');
        $('#staff_search_tab').removeClass('focus');

        $('#staff_search_tab').addClass('focus');
        $('#search_form').hide();
        $('#search_form_staff').show();
    } else {
        return false;
    }
}

function resetStaffSearch() {
    $('#tag_type').val(0);
    
    $('#tag_id').empty();
    var optionItems = new Array();
    optionItems.push('<option value="0">指定なし</option>');
    $('#tag_id').append(optionItems.join());
}



function get_more_data(type, category, target_id, last_id) {
    var data = {type:type, category:category, target_id:target_id, last_id:last_id};

    $.post('/api/getMoreData/', data, callback_get_more_data, 'json');
}

function callback_get_more_data(data, status) {
    var success_status = false;
    if (status == "success") {
        if (data.success) {
            success_status = true
            var response    = data.response;
            var last_id     = data.last_id;
            var next_exists = data.next_exists;
            $('#more_disp').before(response);
            $('#more_disp_last_id').val(last_id);
            if (next_exists == false) {
                $('#more_disp').hide();
            }

            // コメントボックスのイベント追加
            $("input[id*='send_message_']").keypress(function (e) {
                if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
                    var id = this.id;
                    id = id.replace('send_message_', "");
                    send_comment(id)
                }
            });
            $("input[id*='staff_send_message_']").keypress(function (e) {
                if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
                    var id = this.id;
                    id = id.replace('staff_send_message_', "");
                    send_comment_by_staff(id)
                }
            });
            $("input[id*='shop_send_message_']").keypress(function (e) {
                if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
                    var id = this.id;
                    id = id.replace('shop_send_message_', "");
                    send_comment_by_shop(id)
                }
            });
            $().piroBox_ext({
                piro_speed : 200,
                bg_alpha : 0.5,
                piro_scroll : true
            });
        }
    } else if (status == "error") {
        // リクエスト失敗
    } else if (status == "notmodified") {
        // 更新されていない
    } else if (status == "timeout") {
        // タイムアウト
    } else if (status == "parsererror") {
        // データパースエラー
    }
}

function get_discovery_more_data(type, category, target_id, last_id) {
    var data = {type:type, category:category, target_id:target_id, last_id:last_id};

    $.post('/api/getMoreDiscoveryStaffData/', data, callback_get_discovery_more_data, 'json');
}

function callback_get_discovery_more_data(data, status) {
    var success_status = false;
    if (status == "success") {
        if (data.success) {
            success_status = true
            var response    = data.response;
            var last_id     = data.last_id;
            var next_exists = data.next_exists;
            $('#moreButton').before(response);
            $('#more_disp_discovery_staff_last_id').val(last_id);
            if (next_exists == false) {
                $('#moreButton').hide();
            }
        }
    } else if (status == "error") {
        // リクエスト失敗
    } else if (status == "notmodified") {
        // 更新されていない
    } else if (status == "timeout") {
        // タイムアウト
    } else if (status == "parsererror") {
        // データパースエラー
    }
}

