function database(json){
	var pi = new dbplugin(json); // プラグイン

	var ini = pi.ini(json);
	var jname = ini.jsonname;
	var a = ini.jsondata;
	var aleng = ini.jsonleng;

	var jstag = pi.jstag(document);
	var jsflag = pi.jsflag(jstag, aleng);

	var jstitle = jsflag.title;
	var tmpl = jsflag.tmpl;
	var loop = jsflag.loop;

	if(jname == ''){

	// TEMPLATE  !! SAMPLE (not in use) !! //
	}else if(jname == 'ProMobile 新着記事'){
		if(tmpl == 'default'){
			var code, b, i;
			code = '<table class="archiveTable"><thead><th>記事タイトル</th><th nowrap>著者名</th><th>公開日</th></thead><tbody>';
			for(i=0; i<loop; i++){
				b = a[i];
				code += '<tr><th class="' + b.type + '"><a href="' + b.link + '">' + b.title + '</a></th><td nowrap>' + b.writer + '</td><td nowrap>' + b.dcdate + '</td></tr>';
			}
			code += '</tbody></table>';
			code += '<div class="andmore">&raquo; <a href="/promobile/past.html">これ以前の記事</a></div>';
			document.write(code);

		}else if(tmpl == 'A'){ // 記事下カテゴリ別
			var pTags, strongTags, category, code, b, i, j;
			pTags = document.getElementById('mainBox2').getElementsByTagName("p");
			strongTags = pTags[0].getElementsByTagName("strong");
			category = strongTags[0].innerHTML;
			category = category.replace('「','').replace('」記事一覧','');

			code = '<table class="archiveTable"><thead><th>記事タイトル</th><th nowrap>著者名</th><th>公開日</th></thead><tbody>';
			j = 0;
			for(i=0; i<aleng; i++){
				b = a[i];
				if((b.type == category) && (j<loop)) {
					code += '<tr><th><a href="' + b.link + '">' + b.title + '</a></th><td nowrap>' + b.writer + '</td><td nowrap>' + b.dcdate + '</td></tr>';
					j++;
				}
			}
			code += '</tbody></table>';
			code += '<div class="andmore">&raquo; <a href="/promobile/past.html">これ以前の記事</a></div>';
			if (j==0) {
				code = '<p>このカテゴリの記事は <a href="/promobile/past.html">過去記事一覧</a> からご覧ください</p>';
			}
			document.write(code);
		}else{}
	}else{}
}

function kankyo_instruction(json){
	var pi = new dbplugin(json); // プラグイン

	var ini = pi.ini(json);
	var jname = ini.jsonname;
	var a = ini.jsondata;
	var aleng = ini.jsonleng;

	if(jname == ''){

	// TEMPLATE //
	}else if(jname == '環境メディア枠'){
			var code, b, i, j, icon;
			code = '<div class="rc-other rc-kankyo"><div class="cbox"><h2>環境メディア</h2><div>';
			for(i=0; i<aleng; i++){
				b = a[i];
				if(i==0){
					icon = (b.icon.slice(0,1) == '/')? imgSrv + b.icon : b.icon ;
					code += '<p><span class="iconbg"><a href="' + b.link + '" onClick="designCnt(\'ep_rcKankyo_ico\');" class="icon"><img src="' + icon + '" alt="' + b.title + '"></a></span>';
					code += '<strong><a href="' + b.link + '" onClick="designCnt(\'ep_rcKankyo_ttl1\');">' + b.title + '</a></strong><br>' + b.abstract + '<br clear="all"><span></span></p><ul class="linkset">';
				}else{
					j = i+1;
					code += '<li><a href="' + b.link + '" onClick="designCnt(\'ep_rcKankyo_ttl' + j + '\');">' + b.title + '</a></li>';
				}
			}
			code += '</ul></div></div></div>';
			document.write(code);
	}else{}
}


/* プラグイン
-----------------------------------------------------*/
function dbplugin(json){}

dbplugin.prototype.ini = function(json){ // 初期設定
	return ({
		'jsonname':json['name'], // 名称
		'jsondata':json['data'], // データ
		'jsonleng':json['data'].length - 1 // データ数
	});
}

dbplugin.prototype.jstag = function(e){ // 自分自身のスクリプトタグ参照
	if(e.nodeName.toLowerCase() == 'script') return e;
	return arguments.callee(e.lastChild)
}

dbplugin.prototype.jsflag = function(e, leng){ // スクリプトタグのタイトル取得
	if(e.getAttribute('title')){
		var t = e.getAttribute('title');
		if(t.match(/^tmpl\=([A-Z])\,loop\=\d*$/)){
			t = t.split(',');
			var m = t[0].replace('tmpl=','');
			var l = parseInt(t[1].replace('loop=',''));
			if(leng < l){
				l = leng;
			}
		}else if(t.match(/^tmpl\=([A-Z])$/)){
			var m = t.replace('tmpl=','');
			var l = leng;
		}else if(t.match(/^loop\=\d*$/)){
			var m = 'default';
			var l = parseInt(t.replace('loop=',''));
			if((leng) < l){
				l = leng;
			}
		}else{
			var m = 'default';
			var l = leng;
		}
	}else{
		var m = 'default';
		var l = leng;
	}
	return {'title':t,'tmpl':m,'loop':l};
}



/* メールマガジンタイトル取得
-----------------------------------------------------*/
function cutStrTitle(str,num){ // 文字列をバイト数でカット
	var estr = escape(str);
	var ostr = "";
	
	for(var i=0,len=0;i<estr.length;i++){
		len++;
		ostr = ostr + estr.charAt(i);
		if(estr.charAt(i) == "%"){
			i++;
			ostr = ostr + estr.charAt(i);
			if(estr.charAt(i) == "u"){
				ostr = ostr + estr.charAt(i+1) + estr.charAt(i+2) + estr.charAt(i+3) + estr.charAt(i+4);
				i+=4;
				len++;
			}
		}
		if(len >= num-3){
			return unescape(ostr)+"...";
		}
	}
	return unescape(ostr);
}

function getMailData(json){
	var data = json['data'];
	if(!data) return false;
	var dataleng = data.length -1;
	var code = '';
	
	var currentScript = (function(e){ // コールバック関数実行後自分自身のSCRIPTタグ参照
		if(e.nodeName.toLowerCase() == 'script') return e;
		return arguments.callee(e.lastChild)
	})(document);
	
	// title,loop要素の判別
	if(currentScript.getAttribute('title')){
		var jstitle =currentScript.getAttribute('title');
		if(jstitle.match(/^tmpl\=([A-Z])\,loop\=\d*$/)){
			jstitle = jstitle.split(',');
			var tmpl = jstitle[0].replace('tmpl=','');
			var loop = parseInt(jstitle[1].replace('loop=',''));
			if(dataleng < loop) loop = datalengh;
		}else if(jstitle.match(/^tmpl\=([A-Z])$/)){
			var tmpl = jstitle.replace('tmpl=','');
			var loop = dataleng;
		}else if(jstitle.match(/^loop\=\d*$/)){
			var tmpl = 'default';
			var loop = parseInt(jstitle.replace('loop=',''));
			if(dataleng < loop) loop = dataleng;
		}else{
			var tmpl = 'default';
			var loop = dataleng;
		}
	}else{
		var tmpl = 'default';
		var loop = dataleng;
	}
	
	if(tmpl == 'default'){	// 検索窓横用
		var cTag = (pageDirType == 'articles') ? 'mail_ep_art_sb' : 'mail_ep_index_sb';
		code += '<div id="lnavInfoBox">';
		for(var i = 0; i < loop; i++){
			var title = data[i]['title'];
			code += '<p><a href="' + data[i]['link'] + '" title="' + data[i]['title'] + '" onclick="' + "var s=s_gi('" + ThisSite + "');" + 's.eVar17=' + "'" + cTag + "';s.tl(this,'o','" + cTag + "'" + ');">' + cutStrTitle(data[i]['title'],60) + '</a></p>';
		}
		code += '</div>';
		document.write(code);
	}else if(tmpl == 'A'){	// 右カラム用
		var cTag = (pageDirType == 'articles') ? 'mail_ep_art_rc' : 'mail_ep_index_rc';
		code += '<div class="box-out" id="infoMailMag"><div class="box-in"><div class="box-bar"><div><strong>メールマガジンのお知らせ</strong></div></div>';
		code += '<div class="box-body">';
		code += '<p><a href="https://mailmag.itmedia.co.jp/enterprise/backnumber.html"><img src="' + imgSrv + '/images0509/rc_itmid_mailmag.gif" width="40" height="40" align="left"></a><strong><a href="https://mailmag.itmedia.co.jp/enterprise/backnumber.html" onclick="' + "var s=s_gi('" + ThisSite + "');"+ 's.eVar17=' + "'" + cTag + "';s.tl(this,'o','" + cTag + "'" + ');">企業を変革するビジネス視点のメールマガジンを毎朝配信中!!</a></strong></p>';
		code += '<ul class="fileset linkset">';
		for(var i = 0; i < loop; i++){
			code += '<li><a href="' + data[i]['link'] + '" title="' + data[i]['title'] + '" onclick="' + "var s=s_gi('" + ThisSite + "');"+ 's.eVar17=' + "'" + cTag + "';s.tl(this,'o','" + cTag + "'" + ');">' + cutStrTitle(data[i]['title'],45) + '</a></li>';
		}
		code += '</ul>';
		code += '<div class="andmore"><a href="https://mailmag.itmedia.co.jp/enterprise/backnumber.html" onclick="' + "var s=s_gi('" + ThisSite + "');"+ 's.eVar17=' + "'" + cTag + "';s.tl(this,'o','" + cTag + "'" + ');">&raquo; ご購読はこちら</a></div><br clear="all"></div></div></div>';
		document.write(code);
	}else {
	}
};



