
/*
 * jquery.recommendProduct.js
 * @author k.kitahara
 */


$(function(){

    /** 設定 *********************************************************************/
    document.URL.match(/^http[s]?:\/\/[^/]+\/pf\/([^/^?]+)/);
    var p_param = RegExp.$1;
    var params = [
        {
            'php_fnc'     : 'recommend-product',            // サーバー側PHPアクション名
            'ajax_params' : 'pro=' + p_param,                             // Ajaxリクエストパラメータ
            'js_fnc'      : null,                          // リクエストデータ処理関数
            'html_id'     : 'recommendProductArea'          // 埋め込み先タグのID名
        }
    ];
    /** 設定ここまで *************************************************************/


    /** 実行 */
    $.each(params, function(key, param) {
        //alert(document.URL)
        //(document.URL.replace(/^(http[s]?:\/\/[^/]+).+$/,"$1"));
        //exit;
        ajax_exec(param.php_fnc, param.ajax_params, param.js_fnc, param.html_id);
    });

    /** カスタムfunction ********************************************************/
    /** HTML出力 */

    /** カスタムfunctionここまで ************************************************/

    /** Ajaxリクエスト */
    function ajax_exec(url, param, fnc, html_id) {
        $.ajax({
            type: "GET",
            data: param,
            url: document.URL.replace(/^(http[s]?:\/\/[^/]+).+$/,"$1") + "/ajax/product/" + url,
            dataType: "json",
            success: function(jsonData){
                /** 処理関数指定がある場合 */

                /** 埋め込みID指定がある場合 */
                if (typeof html_id == "string") {
                    $('#' + html_id).html(jsonData);
                }
            },
            error : function(){
                return false;
            }
        });
        return;
    }
});

