
function get_write_token_piree_js(bo_table, piree_cafe_n, board_cate_n)
{
    var token = "";

    $.ajax({
        type: "POST",
        url: piree_cafe_url+"/piree.cafe.board.write_token.php",
        data: {
               "bo_table": bo_table,
               "piree_cafe_n": piree_cafe_n,
               "board_cate_n": board_cate_n
        },
        cache: false,
        async: false,
        dataType: "json",
        success: function(data) {
            if(data.error) {
                alert(data.error);
                if(data.url)
                {
                    document.location.href = data.url;
                }

                return false;
            }

            token = data.token;
        }
    });

    return token;
}

$(function() {
    $(document).on("click", "form[name=piree_cafe_board_write] input:submit, form[name=piree_cafe_board_write] button:submit, form[name=piree_cafe_board_write] input:image", function() {
        var pform = this.form;

        if (typeof(pform.bo_table) == "undefined") {
            return;
        }

        var bo_table = pform.bo_table.value;
        var piree_cafe_n = pform.piree_cafe_n.value;
        var board_cate_n = pform.board_cate_n.value;
        var token = get_write_token_piree_js(bo_table, piree_cafe_n, board_cate_n);

        if(!token) {
            alert("토큰 정보가 올바르지 않습니다.x11");
            return false;
        }

        var $pform = $(pform);

        if(typeof pform.token === "undefined")
            $pform.prepend('<input type="hidden" name="token" value="">');

        $pform.find("input[name=token]").val(token);

        return true;
    });
});
