var ReviewHelper = Class.create();
ReviewHelper.prototype = {

    initialize: function (reviews_id, prod_id, otp)
    {
        this.reviews_id = reviews_id;
        this.prod_id = prod_id;
        this.load_icon_id = 'review_load_icon_' + this.reviews_id;
        this.err_msg_id = 'review_err_msg_' + this.reviews_id;
        this.confirm_msg = 'このレビューを削除しますか？';
        this.otp = otp;
    },

    del: function ()
    {
        // 確認する.
        res = confirm(this.confirm_msg);
        if (res == false) return false;

        $(this.err_msg_id).style.display = 'none';
        $(this.err_msg_id).innerHTML = '';

        var url = 'ajax_api.php';
        var pars = 'class=Review'
                 + '&action=delete'
                 + '&id=' + this.reviews_id
                 + '&otp=' + this.otp
                 ;
        // ロード中画像を表示する.
        this.displayLoadIcons();

        var myAjax = new Ajax.Request(
          url,
          {
            method: 'get',
            parameters: pars,
            onComplete: this.onCompleteHandlerForDelete.bind(this)
          }
        );
    },

    onCompleteHandlerForDelete: function (request)
    {
        // ロードアイコンを削除する.
        this.clearLoadIcons();

        var hash = eval('(' + request.responseText + ')');

        if (hash.res == false) {
            $(this.err_msg_id).style.display = '';
            $(this.err_msg_id).innerHTML = hash.err_msg;
            IfgUtil.doFade(this.err_msg_id);
            return;
        }

        // 商品詳細ページをリロードする.
        window.location.replace('p_info/' + this.prod_id + '/');
        //window.location.href = redirect_url + '&use_page_transfer=1';

    },

    /**
     * ロード中にロードアイコンを表示する.
     */
    displayLoadIcons: function()
    {
        $(this.load_icon_id).style.display = '';
        IfgUtil.displayLoadIcon(this.load_icon_id);
    },

    /**
     * ロードアイコンを削除する.
     *
     */
    clearLoadIcons: function()
    {
        $(this.load_icon_id).style.display = 'none';
        IfgUtil.clearLoadIcon(this.load_icon_id);
    }
};
