/*++++++++++++++++++++++++++++++++++++++++++++++++++++++*
 *
 *  Fsiki JavaScript 2006
 *  http://www.fsiki.com/
 *  New Window JavaScript
 *
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++*/

/*
 *  openType : [1:target="_blank"][2:window.open(this.href)]
 *  checkArea : 適用するエリアのid(ページ全体なら [checkArea = ''])
 *  exclusionStr : 除外する文字列(リンクすべてに適用するなら [exclusionStr = new Array()])
 *  inclusionClassName : 除外文字列を含んでいても<a class="nw">テキスト</a>と書かれていれば適用する。
 *  anchorObject : 表示するオブジェクト(テキストの場合[var anchorObject = 'テキスト';])
*/
var openType = 2;
var checkArea = '';
var exclusionStr = new Array('tmk-web');
var inclusionClassName = 'nw'; 
var anchorObject = '<img src="img/newwin.png" alt="新しいウインドウで開く" title="新しいウインドウで開く" />';

window.onload = function(){newWin();}

var isIE = (document.documentElement.getAttribute("style") == document.documentElement.style);

function newWin(){
	if(checkArea == ''){
		var anchors = document.getElementsByTagName('a');
	}else{
		var anchors = document.getElementById(checkArea).getElementsByTagName('a');
	}
	for(i = 0; i < anchors.length; i++){
		var exNum = 0;
		var anchor = anchors[i];
		var aInner = anchor.innerHTML;
		var ahref = anchor.href;
		if(aInner.indexOf('<img') == -1){
			for(j = 0; j < exclusionStr.length; j++){
				eAnchor = exclusionStr[j];
				if((ahref.indexOf(eAnchor) == -1 || anchor.className == inclusionClassName) & anchor.href != ''){
					exNum++;
				}
			}
			if(exNum ==  exclusionStr.length){
				var winAnchor = document.createElement('a');
				winAnchor.innerHTML = anchorObject;
				winAnchor.href = anchor.href;
				winAnchor.className = 'newWin';
				if(openType == 1){
					winAnchor.setAttribute('target','_blank');
				}else if(openType == 2){
					if(isIE) {
						winAnchor.setAttribute('onclick',new Function('window.open(this.href,\'\',\'status=yes,scrollbars=yes,directories=yes,menubar=yes,resizable=yes,toolbar=yes\'); return false;'));
					}else{
						winAnchor.setAttribute('onclick','window.open(this.href,\'\',\'status=yes,scrollbars=yes,directories=yes,menubar=yes,resizable=yes,toolbar=yes\'); return false;');
					}
				}
				anchor.parentNode.insertBefore(winAnchor,anchor);
				anchor.parentNode.replaceChild(winAnchor,anchor);
				winAnchor.parentNode.insertBefore(anchor,winAnchor);
				var i = i + 1;
			}
		}
	}
}

