﻿/*
デバッグフラグ
*************************************/

var _debug                         = false;

/*
データJSON
*************************************/
var data_json_path                   = "common/data/product_json.js";

/*
データ挿入ID
*************************************/
var menu_section_id                   = "randomBtn";
var prodcut_section_id                = "bukkenBox";


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var flg_ad_json               = false;

//データランダム
function RDM(){
	RMD_DataLoad();
}

//データロード後コールバック
var RMD_Data_Load_CallBack = function(){
	//ランダムシード
	var data_length            = RMD_MENU_DATA.entry.length;
	var rseed                  = new Array();
	for(var i=0;i<data_length;i++) rseed[i] = i;
	rseed.shuffle();

	document.getElementById(menu_section_id).innerHTML    = RMD_random_menu_data(rseed);
	document.getElementById(prodcut_section_id).innerHTML = RMD_random_product_data(rseed);
}

//メニュー領域生成
function RMD_random_menu_data(rs){
	var MENU_DATA              = RMD_MENU_DATA.entry;
	var template_html          = RMD_MENU_DATA.template;
	var html                   = "";

	for(var i=0;i<MENU_DATA.length;i++){
		var temp_html           = template_html;
		temp_html               = temp_html.replace(/#menu_class#/g,MENU_DATA[rs[i]].menu_class);
		temp_html               = temp_html.replace(/#menu_form_name#/g,MENU_DATA[rs[i]].menu_form_name);
		temp_html               = temp_html.replace(/#menu_form_id#/g,MENU_DATA[rs[i]].menu_form_id);
		temp_html               = temp_html.replace(/#menu_form_value#/g,MENU_DATA[rs[i]].menu_form_value);
		html                   += temp_html;
	}
	
	return html;
}

//データ領域生成
function RMD_random_product_data(rs){
	var PRODUCT_DATA           = RMD_PRODUCT_DATA.entry;
	var template_html          = RMD_PRODUCT_DATA.template;
	var html                   = "";

	for(var i=0;i<PRODUCT_DATA.length;i++){
		var temp_html           = template_html;
		temp_html               = temp_html.replace(/#product_id#/g,PRODUCT_DATA[rs[i]].product_id);
		temp_html               = temp_html.replace(/#product_name#/g,PRODUCT_DATA[rs[i]].product_name);
		temp_html               = temp_html.replace(/#product_copy#/g,PRODUCT_DATA[rs[i]].product_copy);
		temp_html               = temp_html.replace(/#product_image#/g,PRODUCT_DATA[rs[i]].product_image);
		temp_html               = temp_html.replace(/#product_place#/g,PRODUCT_DATA[rs[i]].product_place);
		temp_html               = temp_html.replace(/#product_access#/g,PRODUCT_DATA[rs[i]].product_access);
		html                   += temp_html;
	}
	
	return html;
}

//配列ランダマイズ
Array.prototype.shuffle = function() {
    var i = this.length;
    while(i){
        var j = Math.floor(Math.random()*i);
        var t = this[--i];
        this[i] = this[j];
        this[j] = t;
    }
    return this;
}



//データロード
function RMD_DataLoad(){
	if(!flg_ad_json){
		document.write('<script type="text/javascript" src="' + data_json_path + '"></script>');
	} else {
		RMD_Data_Load_CallBack();
	}
}


