// --------------------------------------------------
// define & global
// --------------------------------------------------

var		g_bRelease			= window.location.protocol.indexOf("http:", 0) >= 0 && window.location.hostname != 'localhost';
var		g_bIE				= (document.all) ? true : false;
//var		g_bNC				= (document.layers) ? true : false;
var		g_bNC				= !g_bIE
var		DefSiteTitle		= 'Yahoo!のごみ箱';
var		DefPathSeparator	= '/';
var		DefExtHTML			= '.html';
var		DefMailAddress		= 'info&#64;ypg&#46;jp';

// --------------------------------------------------
// object
// --------------------------------------------------

// ページ情報
function	PageInfo() {
	this.bIndex			= false;
	this.sCategoryID	= '';
	this.sCategoryName	= '';
	this.sPageID		= '';
	this.sPageName		= '';
}

// --------------------------------------------------
// function
// --------------------------------------------------

// ページ情報取得
function	getPageInfo(oPageInfo) {

	var	sHostName			= window.location.hostname;
	var	sPathName			= window.location.pathname;
	var	nPathCount;

	if		(sHostName.indexOf('ypg.jp') >= 0)				nPathCount = 1;
	else if	(sHostName.indexOf('webmania.jp') >= 0)			nPathCount = 2;
	else if	(sHostName.indexOf('xrea.com') >= 0)			nPathCount = 1;
	else													nPathCount = 2;

	var	iSiteRootIndex		= searchIndex(sPathName, DefPathSeparator, nPathCount);
	var	iCategoryRootIndex	= sPathName.lastIndexOf(DefPathSeparator, sPathName.length);
	var	sCategory			= sPathName.substring(iSiteRootIndex + 1, iCategoryRootIndex).replace(DefPathSeparator,'-');
	var	sFile				= sPathName.substring(iCategoryRootIndex + 1, sPathName.length);
	var	sPage				= sFile.substring(0, sFile.lastIndexOf(DefExtHTML));

	// トップページ
	if (iSiteRootIndex === iCategoryRootIndex) {
		oPageInfo.bIndex		= (sPage == 'index' || sPage == '');
		oPageInfo.sCategoryID	= 'top';
		oPageInfo.sCategoryName	= '';
		oPageInfo.sPageID		= sPage;
		oPageInfo.sPageName		= '';
	}

	// カテゴリインデックスページ
	else if (sPathName.length === iCategoryRootIndex + 1 || sPage == 'index') {
		oPageInfo.bIndex		= true;
		oPageInfo.sCategoryID	= sCategory;
		oPageInfo.sPageID		= 'index';
	}

	// 一般ページ
	else {
		oPageInfo.bIndex		= false;
		oPageInfo.sCategoryID	= sCategory;
		oPageInfo.sPageID		= sPage;
	}

	// ページ情報設定
	switch (oPageInfo.sCategoryID) {
	case 'info' :
		oPageInfo.sCategoryName = 'インフォメーション';
		switch (oPageInfo.sPageID) {
			case 'index' :			oPageInfo.sPageName = oPageInfo.sCategoryName;	break;
			case 'about' :			oPageInfo.sPageName = '当サイトについて';		break;
			case 'cooperation' :	oPageInfo.sPageName = '協力・情報提供';			break;
			case 'thanks' :			oPageInfo.sPageName = 'ご協力感謝';				break;
			case 'disclaimer' :		oPageInfo.sPageName = '免責事項';				break;
			case 'changes' :		oPageInfo.sPageName = '履歴';					break;
		}
		break;
	case 'notice' :
		oPageInfo.sCategoryName = 'お知らせ';
		switch (oPageInfo.sPageID) {
			case 'index' :			oPageInfo.sPageName = oPageInfo.sCategoryName;	break;
		}
		break;
	case 'mail' :
		oPageInfo.sCategoryName = '電子メール';
		switch (oPageInfo.sPageID) {
			case 'index' :			oPageInfo.sPageName = oPageInfo.sCategoryName;	break;
		}
		break;
	case 'ie' :
		oPageInfo.sCategoryName = 'Internet Explorer';
		switch (oPageInfo.sPageID) {
			case 'index' :			oPageInfo.sPageName = oPageInfo.sCategoryName;	break;
			case 'shortcutkey' :	oPageInfo.sPageName = 'ショートカットキー';		break;
		}
		break;
	case 'library' :
		oPageInfo.sCategoryName = 'ライブラリ';
		switch (oPageInfo.sPageID) {
			case 'index' :			oPageInfo.sPageName = oPageInfo.sCategoryName;	break;
			case 'colorcode' :		oPageInfo.sPageName = 'カラーコード';			break;
			case 'char_change' :	oPageInfo.sPageName = '文字変換';				break;
			case 'entity1' :		oPageInfo.sPageName = '特殊文字１';				break;
			case 'entity2' :		oPageInfo.sPageName = '特殊文字２';				break;
			case 'entity_ime' :		oPageInfo.sPageName = '特殊文字変換（IME）';	break;
		}
		break;
	case 'link' :
		oPageInfo.sCategoryName = 'リンク';
		switch (oPageInfo.sPageID) {
			case 'index' :			oPageInfo.sPageName = oPageInfo.sCategoryName;	break;
		}
		break;
	case 'YahooAccount' :
		oPageInfo.sCategoryName = 'Yahoo!登録情報';
		switch (oPageInfo.sPageID) {
			case 'index' :			oPageInfo.sPageName = oPageInfo.sCategoryName;			break;
			case 'prof_chn' :		oPageInfo.sPageName = 'プロフィール編集-HN大文字登録';	break;
			case 'ignore_self' :	oPageInfo.sPageName = '自身無視リスト登録';				break;
			case 'friend_reject' :	oPageInfo.sPageName = '友達登録拒否';					break;
		}
		break;
	case 'YahooAuctions' :
		oPageInfo.sCategoryName = 'Yahoo!オークション';
		switch (oPageInfo.sPageID) {
			case 'index' :			oPageInfo.sPageName = oPageInfo.sCategoryName;	break;
		}
		break;
	case 'YahooChat' :
		oPageInfo.sCategoryName = 'Yahoo!チャット';
		switch (oPageInfo.sPageID) {
			case 'index' :			oPageInfo.sPageName = oPageInfo.sCategoryName;	break;
			case 'colorname' :		oPageInfo.sPageName = 'カラーネーム';			break;
			case 'command' :		oPageInfo.sPageName = 'チャットコマンド';		break;
			case 'tag' :			oPageInfo.sPageName = 'チャットタグ';			break;
			case 'parameter' :		oPageInfo.sPageName = 'パラメータ解析';			break;
			case 'smiley' :			oPageInfo.sPageName = '顔文字アイコン';			break;
			case 'chn' :			oPageInfo.sPageName = 'HN大小文字変換（Java版・HTML版）'	;	break;
			case 'chn12' :			oPageInfo.sPageName = 'HN大小文字変換（Java版・HTML版）'	;	break;
			case 'chn13' :			oPageInfo.sPageName = 'HN大小文字変換（Java版・HTML版）'	;	break;
			case 'chn_mj' :			oPageInfo.sPageName = 'HN大小文字変換（MJ版）'				;	break;
		}
		break;
	case 'YahooMessages' :
		oPageInfo.sCategoryName = 'Yahoo!掲示板';
		switch (oPageInfo.sPageID) {
			case 'index' :			oPageInfo.sPageName = oPageInfo.sCategoryName;	break;
		}
		break;
	case 'YahooMessenger' :
		oPageInfo.sCategoryName = 'Yahoo!メッセンジャー';
		switch (oPageInfo.sPageID) {
			case 'index' :			oPageInfo.sPageName = oPageInfo.sCategoryName;	break;
			case 'version' :		oPageInfo.sPageName = 'バージョンの調べ方';		break;
			case 'shortcutkey' :	oPageInfo.sPageName = 'ショートカットキー';		break;
			case 'smiley' :			oPageInfo.sPageName = '顔文字アイコン';			break;
			case 'sp_font' :		oPageInfo.sPageName = '特殊フォント記号';		break;
			case 'sound' :			oPageInfo.sPageName = '効果音';					break;
			case 'im_theme' :		oPageInfo.sPageName = 'IMテーマ';				break;
			case 'crash' :			oPageInfo.sPageName = 'MJ落とし';				break;
			case 'block_chat_ad' :	oPageInfo.sPageName = '※広告ブロック用';		break;
		}
		break;
	case 'YahooGames' :
		oPageInfo.sCategoryName = 'Yahoo!ゲーム';
		switch (oPageInfo.sPageID) {
			case 'index' :			oPageInfo.sPageName = oPageInfo.sCategoryName;	break;
		}
		break;
	}

	// ページ情報未設定
	if (oPageInfo.sCategoryName	=== '')	oPageInfo.sCategoryName	= oPageInfo.sCategoryID;
	if (oPageInfo.sPageName === '')		oPageInfo.sPageName		= oPageInfo.sPageID;

	//if (!g_bRelease) {
	if (false) {
		document.writeln('<PRE>');
		document.writeln('g_bRelease        : ' + g_bRelease);
		document.writeln('g_bIE             : ' + g_bIE);
		document.writeln('g_bNC             : ' + g_bNC);
		document.writeln('                  : ' + '0         1         2         3         4');
		document.writeln('                  : ' + '01234567890123456789012345678901234567890123456789');
		document.writeln('sHostName         : ' + sHostName);
		document.writeln('sPathName         : ' + sPathName);
		document.writeln('nPathCount        : ' + nPathCount);
		document.writeln('iSiteRootIndex    : ' + iSiteRootIndex);
		document.writeln('iCategoryRootIndex: ' + iCategoryRootIndex);
		document.writeln('sCategory         : ' + sCategory);
		document.writeln('sFile             : ' + sFile);
		document.writeln('sPage             : ' + sPage);
		document.writeln('bIndex            : ' + oPageInfo.bIndex);
		document.writeln('sCategoryID       : ' + oPageInfo.sCategoryID);
		document.writeln('sCategoryName     : ' + oPageInfo.sCategoryName);
		document.writeln('sPageID           : ' + oPageInfo.sPageID);
		document.writeln('sPageName         : ' + oPageInfo.sPageName);
		document.writeln('</PRE>');
	}
}

// ページ初期処理
function	init(oPageInfo) {

	// ページ情報取得
	getPageInfo(oPageInfo);

	// トップページ
	if (oPageInfo.sCategoryID == "top")	return;

	// タイトル設定
	var	s = "";
	if (oPageInfo.bIndex) {
		s += " - " + oPageInfo.sCategoryName;
	}
	else {
		if (oPageInfo.sCategoryID != "info") {
			s += " - " + oPageInfo.sCategoryName;
		}
		s += " - " + oPageInfo.sPageName;
	}
	document.title = DefSiteTitle + s;
}

// ページ終了処理
function	term(oPageInfo) {

}

// ヘッダー出力
function	writeHeader(oPageInfo) {

	document.writeln('<A name="pagetop"></A>');

	// トップページ
	if (oPageInfo.sCategoryID == "top")	return;

	// ページメインタイトル
	document.writeln('<DIV class="center">');
	document.writeln('	<CENTER>');
	document.writeln('<P>');
	if (oPageInfo.bIndex) {
		document.writeln('<H1 class="pagetitle">' + oPageInfo.sCategoryName + '</H1>');
	}
	else {
		document.writeln('<H1 class="pagetitle">' + oPageInfo.sPageName + '</H1>');
	}
	document.writeln('</P>');
	document.writeln('	</CENTER>');
	document.writeln('</DIV>');

	// サイトマップ
	writeSiteMap(oPageInfo);
	if (g_bNC) document.writeln('<BR>');
}

// フッター出力
function	writeFooter(oPageInfo) {

	// トップページ以外
	if (oPageInfo.sCategoryID != "top") {
		// サイトマップ
		writeSiteMap(oPageInfo);
	}

	document.writeln('<DIV class="center">');
	document.writeln('	<CENTER>');

	// カウンター
	writeCounter(oPageInfo);

	// トップページ
	if (oPageInfo.sCategoryID == "top" && oPageInfo.bIndex) {
		document.writeln('<TABLE>');
		document.writeln('<TR style="font-size:smaller">');
		document.writeln('<TD> | </TD>');
		document.writeln('<TD><A href="mailto:' + DefMailAddress + '">管理者へメール</A>');
		document.writeln('<TD> | </TD>');
		document.writeln('<TD><A href="./info/about.html">当サイトについて</A></TD>');
		document.writeln('<TD> | </TD>');
		document.writeln('<TD><A href="./info/cooperation.html">協力・情報提供</A></TD>');
		document.writeln('<TD> | </TD>');
		document.writeln('<TD><A href="./info/disclaimer.html">免責事項</A></TD>');
		document.writeln('<TD> | </TD>');
		document.writeln('</TR>');
		document.writeln('</TABLE>');
	}

	document.writeln('<HR class="footer">');
	document.writeln('<ADDRESS>');
	document.writeln('  Copyright (C) 2001-2006, Yahoo Pioneer Group, All Rights Reserved.');
	document.writeln('</ADDRESS>');
	document.writeln('<SPAN style="font-size:smaller">無断転載を禁じます</SPAN>');

	document.writeln('	</CENTER>');
	document.writeln('</DIV>');
	document.writeln('<BR>');
	document.writeln('<A name="pagebottom"></A>');
}

// サイトマップ出力
function	writeSiteMap(oPageInfo) {

	document.writeln('<P>');
	document.writeln('<DIV class="sitemap">');
	document.write('サイトマップ　〔<A href="../">' + DefSiteTitle + '</A>〕>');

	if (oPageInfo.bIndex) {
		document.write('〔<SPAN style="color:red">' + oPageInfo.sCategoryName + '</SPAN>〕');
	}
	else {
		if (oPageInfo.sCategoryID != "info") {
			document.write('〔<A href="./">' + oPageInfo.sCategoryName + '</A>〕>');
		}
		document.write('〔<SPAN style="color:red">' + oPageInfo.sPageName + '</SPAN>〕');
	}

	document.writeln('</DIV>');
	document.writeln('</P>');
}

// 工事中出力
function	writeKouji(oPageInfo) {

	var	sImgUrl;

	// トップページ
	if (oPageInfo.sCategoryID == "top") {
		sImgUrl = "./images/kouji.gif";
	}
	// トップページ以外
	else {
		sImgUrl = "../images/kouji.gif";
	}

	document.writeln('<P>');
	document.writeln('<DIV class="center">');
	document.writeln('	<CENTER>');
	document.writeln('  <TABLE style="width:50%">');
	document.writeln('    <TR>');
	document.writeln('      <TD style="text-align:center;width:33%"><IMG src="' + sImgUrl + '" alt="工事中"></TD>');
	document.writeln('      <TD style="text-align:center;font-size:x-large;width:34%">工事中</TD>');
	document.writeln('      <TD style="text-align:center;width:33%"><IMG src="' + sImgUrl + '" alt="工事中"></TD>');
	document.writeln('    </TR>');
	document.writeln('  </TABLE>');
	document.writeln('	</CENTER>');
	document.writeln('</DIV>');
	document.writeln('</P>');
}

// カウンター出力
function	writeCounter(oPageInfo) {

	var	sBuff, sRef, sScr, s;
	var	i;

	sBuff = escape(document.referrer);
	sRef = "";
	for (i = 0; i < sBuff.length; i++) {
		s = sBuff.charAt(i);
		sRef += (s == '+') ? '%2B' : s;
	}

	sScr = screen.width + ',' + screen.height + ',' + screen.colorDepth;

	if (!g_bRelease) {
		document.writeln('カウンター位置');
	}
	else if (oPageInfo.sCategoryID == "top") {
		if (oPageInfo.bIndex) {
			document.writeln('<IMG src="./cgi-bin/counter/count.cgi?LOG=index&MODE=a&DIGIT=8&FONT=indicator&REF=',sRef,'&SCR=',sScr,'" alt="カウンター">');
		}
		else {
			document.writeln('<IMG class="hide" src="./cgi-bin/counter/count.cgi?LOG=',oPageInfo.sPageID,'&MODE=a&DIGIT=8&FONT=indicator&REF=',sRef,'&SCR=',sScr,'" alt="カウンター">');
		}
	}
	else if (oPageInfo.sCategoryID == "test") {
		document.writeln('<IMG src="../cgi-bin/counter/count.cgi?LOG=',oPageInfo.sCategoryID,'-',oPageInfo.sPageID,'&MODE=a&DIGIT=8&FONT=indicator&REF=',sRef,'&SCR=',sScr,'" alt="カウンター">');
	}
	else {
		document.writeln('<IMG class="hide" src="../cgi-bin/counter/count.cgi?LOG=',oPageInfo.sCategoryID,'-',oPageInfo.sPageID,'&MODE=a&DIGIT=8&FONT=indicator&REF=',sRef,'&SCR=',sScr,'" alt="カウンター">');
	}
	document.writeln('<BR>');
}

// お気に入り追加
function	addFav () {
	external.AddFavorite('http://ypg.jp/',DefSiteTitle);
}

// Java版MJ起動
function openJavaMJ() {

	var		sURL	= "http://java.yahoo.co.jp/jmessenger/messenger1.html";

	var		wMJ = window.open(sURL, 'messenger_home_yj', 'width=230,height=400,resizable=yes,scrollbars=yes');
	if (wMJ != null) {
		if (wMJ.opener == null) {
			wMJ.opener = self;
		}
		window.name = 'myYahooRoot';
		wMJ.location.href = sURL;
	}
	return false;
}

// s1の中のn番目にあるs2のインデックス
function	searchIndex(s1, s2, n) {

	var	nIndex, i;

	nIndex = -1;

	for (i = 0; i < n; i++) {
		nIndex = s1.indexOf(s2, nIndex + 1)
	}

	return nIndex;
}

// サーチデータ検索
function	search(sKey) {
	var	sSearch = location.search;
	var	nIndex	= sSearch.search('[?&]' + sKey + '=');
	if (nIndex == -1)	return null;
	var	nStart	= nIndex + sKey.length + 2;
	var	nEnd		= sSearch.indexOf('&',nStart);
	if (nEnd == -1)	nEnd = sSearch.length;

	return sSearch.substring(nStart,nEnd);
}

// 一時的クッキー
function	tempCookie(sKey, sValue) {
	if ((sKey != null) && (sValue != null))	{
		document.cookie = sKey + '=' + sValue;
		return true;
	}
	return false;
}

// クッキーセット
function	setCookie(sKey, sValue) {
	setCookie2(sKey, sValue, null);
}

// クッキーセット
function	setCookie2(sKey, sValue, sDay) {
	if ((sKey != null) && (sValue != null)) {
		var expDay = 'Wed, 01 Jan 2020 18:56:35 GMT';
		if (sDay != null) {
			sDay = eval(sDay);
			var setDay = new Date();
			setDay.setTime(setDay.getTime() + (sDay * 1000 * 60 * 60 * 24));
			expDay = setDay.toGMTString();
		}
		document.cookie = sKey + '=' + escape(sValue) + ';expires=' + expDay;
		return true;
	}
	return false;
}

// クッキー削除
function	deleteCookie(sKey) {
	document.cookie = sKey + '=;expires=Thu,01-Jan-70 00:00:01 GMT';
	return true;
}

// クッキー取得
function getCookie(sKey, sValue) {
	sValue.value = '';
	sKey += '=';
	var	theCookie = document.cookie+";";
	var	start = theCookie.indexOf(sKey);
	if (start != -1) {
		var	end = theCookie.indexOf(';', start);
		sValue.value = unescape(theCookie.substring(start + sKey.length, end));
		return true;
	}
	return false;
}
