//
// 画像ダウンロードボタン作成用Javascript 2003.10.25
// 製作 http://wws.cside.com/factory/
//

function SaveExec() {
	if(! DummyFrame.location.href) return;
	DummyFrame.document.execCommand('SaveAs');
	
}
function FileSave(Pid) {
	if(! document.getElementById('DummyFrame')) {
		var dFrame = document.createElement('div');
		document.body.appendChild(dFrame);
		dFrame.innerHTML = '<iframe id="DummyFrame" src="" onload="SaveExec()" style="display:none;"></iframe>';
	}
	DummyFrame.location.href = document.getElementById(Pid).src;
}
function add_DL_button(Obj) {
// ボタンの前に<br>を入れたい場合、以下２行の行頭の//を削除すること。
var newBR = document.createElement('br');
Obj.parentNode.appendChild(newBR);

	var newButton = document.createElement('input');
	var newId = Obj.id;
	newId = newId.replace('P','B');
	newButton.setAttribute('id',newId);
	newButton.setAttribute('type','button');
	newButton.setAttribute('value','DOWNLOAD');

	Obj.parentNode.appendChild(newButton);

	newOBJ = document.getElementById(newId);

	newOBJ.onclick=function (){FileSave(Obj.id)};
	newOBJ.title="画像をダウンロードする";
// ボタンにスタイルシートを指定するには次行の要領で追加する
//	newOBJ.style.backgroundColor = '#ffffff'; //背景色の指定例（属性名に-を含む場合-を取って次の一文字を大文字にする）
	newOBJ.style.cursor = 'pointer';

}
function InitDL() {
	if(! (document.all && document.getElementById &&document.execCommand)) return;
	for(i=0;i<document.images.length;i++) {
		if(document.images[i].id.match("^P_[0-9]+")){
			add_DL_button(document.images[i]);
		}
	}
	return;
}
