/**
 * オンロードイベント設定
 */
window.onload = init;
// GoogleAnalyze
var includeJsCount = 0;
var includeJsTimerId;
var includeJsUacct;

/**
 * 初期処理
 */
function init() {

	// **** Check-Local-Test ****
	if (location.hostname.match(/^(127~|local)/)) {
		window.defaultStatus = 'Local-Test';
		return false;
	}

	// **** Check-Admin-Cookie ****
	var site_admin = false;
	if (location.search == '?site_admin') {
		// **** Set-Admin-Cookie ****
		document.cookie = "site_admin=1; path=/; expires=Tue, 1-Jan-2030 00:00:00 GMT;"
		site_admin = true;
		alert("管理人判定設定");
	} else if (location.search == '?site_admin_delete') {
		// **** Delete-Admin-Cookie ****
		document.cookie = "site_admin=1; path=/; expires=Sat, 1-Jan-2000 00:00:00 GMT;"
		site_admin = false;
		alert("管理人判定削除");
	} else {
		// **** Check-Admin-Cookie ****
		var ck_ary = document.cookie.split("; ");
		for (var i=0; i<ck_ary.length; i++) {
			if (ck_ary[i].match(/^site_admin/)) {
				site_admin = true;
			}
		}
	}

	// **** Check-Analyzer ****
	if (site_admin == true) {
		window.defaultStatus = 'Online-Test';
	} else {
		siteAnalyzer();
	}
}


/**
 * アクセス解析処理
 * [Google Analytics] www.ecoup.info
 */
function siteAnalyzer() {
	if (!document.createElement) return false;
	
	// script要素作成
	var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
	var elm1 = document.createElement('SCRIPT');
	elm1.setAttribute('type', 'text/javascript');
	elm1.setAttribute('src', gaJsHost + 'google-analytics.com/ga.js');
	document.body.appendChild(elm1);

	// [Google]アクセス解析処理ID
	if (location.hostname.match(/^www.animegif.net/))   includeJsUacct = "UA-655713-1";
	if (location.hostname.match(/^www.1000i.info/))     includeJsUacct = "UA-655713-2";
	if (location.hostname.match(/^www.ecoup.info/))     includeJsUacct = "UA-655713-3";
	if (location.hostname.match(/^www.rebbs.info/))     includeJsUacct = "UA-655713-4";
	if (location.hostname.match(/^www.sozai83.info/))   includeJsUacct = "UA-655713-5";
	if (location.hostname.match(/^www.hp-server.info/)) includeJsUacct = "UA-655713-6";
	if (location.hostname.match(/^www.rws21.com/))      includeJsUacct = "UA-655713-7";
	if (location.hostname.match(/^gif.animegif.net/))   includeJsUacct = "UA-655713-9";
	if (location.hostname.match(/^www.wsj21.net/))      includeJsUacct = "UA-655713-10";
	if (location.hostname.match(/^www.hosizora.org/))   includeJsUacct = "UA-655713-11";

	// script要素作成
	siteAnalyzerTag();
	//// [Xrea] siteAnalyzerXreaAnalyzer();
	//if (location.hostname.match(/^www.animegif.net/)) {
	//	siteAnalyzerXreaAnalyzer();
	//}
	// setAnchorTarget();
	setAnchorTarget();
}

/**
 * [Google]アクセス解析処理ID
 */
function siteAnalyzerTag() {

	try {
		var pageTracker = _gat._getTracker(includeJsUacct);
		pageTracker._initData();
		pageTracker._trackPageview();
		clearInterval(includeJsTimerId);
	} catch(e) {
		if (includeJsCount++ < 5) {
			includeJsTimerId = setInterval('siteAnalyzerTag()', 500)
		} else {
			clearInterval(includeJsTimerId);
		}
	}
}


/**
 * [Xrea]アクセス解析処理ID
 */
function siteAnalyzerXreaAnalyzer() {
	if (!document.createElement) return false;
	
	// **** AccessAnalyzer Powerd XREA ****
	// <script type='text/javascript' src='/com/ana.js'></script>
	// <noscript><img alt='' width='0' height='0' src='http://w1.ax.xrea.com/l.f?id=100524356&url=X'></noscript>
	var ID = "100524356";
	var AD = 4;
	var FRAME = 0;

	// script要素作成
	//var elm1 = document.createElement('SCRIPT');
	//elm1.setAttribute('type', 'text/javascript');
	//elm1.setAttribute('src', 'http://j1.ax.xrea.com/l.j?id=' + ID);
	//document.body.appendChild(elm1);
	//document.write('<script type="text/javascript" src="http://j1.ax.xrea.com/l.j?id=' + ID + '"></script>');

	// status
	//window.defaultStatus = arguments.callee.toString().match(/function (\w+)/)[1];
	//window.defaultStatus = arguments.callee.caller.toString().match(/function (\w+)/)[1];
}


/**
 * Anchor Target [rel="_blank"]
 */
function setAnchorTarget() {
	if (!document.createElement) return false;

	if (document.getElementsByName) {
		var tag_a = document.getElementsByTagName('a');
		for (var i=0; i<tag_a.length; i++) {
			if (tag_a[i].getAttribute('rel') == '_blank') {
				tag_a[i].target = '_blank';
			}
		}
	}
}

