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};
}
