
// ===========================================
//
// Copyright (c) 2007 ひろば
//
// 本スクリプトの無断使用を固く禁止いたします。 
//
// ===========================================

function wget(url, hidouki, callbackfunc)
{
	var http = null;
	if (window.XMLHttpRequest) {	// Safari, Firefox など
		http = new XMLHttpRequest();
	}
	else if (window.ActiveXObject) {	// IE
		try { http = new ActiveXObject("Msxml2.XMLHTTP"); }	// IE6
		catch (e) {
			try { http = new ActiveXObject("Microsoft.XMLHTTP"); }	// IE5
			catch (e) { return null; }	// Error
		}
	}

	if (hidouki && callbackfunc != undefined) {
		http.onreadystatechange = function()
		{
			if (http.readyState == 4 && http.status == 200) {
				callbackfunc(http.responseText)
			}
		}
	}
	http.open("GET", url, hidouki);
	http.setRequestHeader("If-Modified-Since", "Thu, 01 Jun 1970 00:00:00 GMT");
	http.send(null);
	if (hidouki) { return ""; }
	else         { return http.responseText; }
}

function writeaddfavlink()
{
	if (window.navigator.userAgent.indexOf("MSIE ") >= 0) {
	    var ref = document.referrer;
	    var pos = ref.indexOf("www.frebull.info");
	    if (ref != "" && pos == -1) {
	        document.write(
		    "　<a href='#' onclick=\"window.external.AddFavorite('http://www.frebull.info/'" +
	            ",'フレンチブルドッグひろば');return false;\">[ お気に入り追加 ]</a>");
	    }
	}
}

// ===========================================

var toppageurl = location.hostname;

function lccounter()
{
	var el = document.activeElement;
	var url = el.href;
	if (url.indexOf(toppageurl) == -1) {
		wget("http://www.frebull.info/counter/lccounter.cgi?" + url, true);
	}
}

function setlinkclickcallback()
{
	var all = document.all;
	if (all == undefined) {
		all = document.getElementsByTagName('A');
	}
	var n = all.length;
	for (i = 0; i < n; ++i) {
		var el = all[i];
		var tag = el.tagName;
		if (tag == "A") {
			if (el.onclick == null) {
				el.onclick = lccounter;
			}
		}
	}
}

// ===========================================

var panelObj;
function ShowWaitMessage()
{
	if (typeof(YAHOO) == "undefined") {
		return true;
	}
	
	 if (! panelObj) {
	 	 panelObj = new YAHOO.widget.Panel(
 	 	"waitmessagepanel",
		{
			modal: true,
			width: "250px",
			fixedcenter: true,
			underlay: "shadow",
			close: true,
			visible: false,
			draggable: false
		});
 	 }
 	 
	document.body.style.cursor = 'wait';
	
	panelObj.setHeader("データを送信中です");
	panelObj.setBody("画面が切り替わるまでお待ちください... <a href='javascript:HideWaitMessage();'>閉じる</a><br><img src=http://www.hiroba.cc/images/wait.gif>");
	panelObj.render();
	panelObj.show();
}
function HideWaitMessage()
{
	document.body.style.cursor = 'default';
	panelObj.hide();
}

// -------------------------------------------

var divcount = 0;
function createnewdiv()
{
	++divcount;
	var divel = document.createElement('div');
	divel.id = 'popimageDiv' + divcount;
	document.body.appendChild(divel);
	return divel.id;
}

// -------------------------------------------

var popimageObj;
function popImage(image_url, image_width, image_height)
{
	if (! document_is_loaded || typeof(YAHOO) == "undefined") {
		return false;
	}

	var divid = createnewdiv();

	popimageObj = new YAHOO.widget.Panel(
 	 	divid,
		{
			modal: true,
			width: image_width + 20,
			height: image_height + 40,
			fixedcenter: true,
			underlay: "shadow",
			close: true,
			visible: false,
			draggable: false
		}
	);

	popimageObj.setHeader(
		"<div align=right><a href='javascript:closeImage();' style='color:white; font-weight:normal;'>[×] 閉じる （画像クリックでも閉じます）</a></div>"
	);
	popimageObj.setBody(
		"<div align=center style='padding:5px;'>" +
		"<img src=\"" + image_url + "\" width=" + image_width + 
		" height=" + image_height + " onclick='closeImage();'>" +
		"</div>"
		);
	popimageObj.render();
	popimageObj.show();
	return false;
}
function closeImage()
{
	if (popimageObj) {
		popimageObj.hide();
		popimageObj.destroy();
		popimageObj = undefined;
	}
}

// -------------------------------------------

var siteboxdiv;
function showSiteBox(siteno, sitename)
{
	if (! document_is_loaded) { return; }
	
	if (! sitename) { sitename = ''; }
	
	closeSiteBox();

	var html = 
		'<table>' +
		'  <tr>' +
		'    <td>' +
		'	<div class="linkbox">' +
		'	<div class="sitename">' + sitename + '</div>' +
		'	<div class="sitepic"><img src="http://www.frebull.info/images/site/' + siteno + '.jpg" width="120" height="90"></div>' +
		'	<div class="line3"><img src="http://www.hiroba.cc/images/space.gif" width="1" height="7" alt=""></div>' +
		'	</div>' +
		'    </td>' +
		'  </tr>' +
		'</table>';

	var y8 = mouse_y + 15;
	
	saveClientSize();
	if (client_cy > 0) {
		var top = document.body.scrollTop || document.documentElement.scrollTop;
		var div_height = 137;
		if (y8 + div_height > top + client_cy) {
			y8 = top + client_cy - div_height;
		}
	}

	siteboxdiv = document.createElement('div');
//	siteboxdiv.style.padding = "2px";
//	siteboxdiv.style.border = "1px solid #F0F0F0";
	siteboxdiv.style.backgroundColor = "white";
	siteboxdiv.style.position = 'absolute';
	siteboxdiv.style.left = mouse_x + 15 + 'px';
	siteboxdiv.style.top = y8 + 'px';
	siteboxdiv.innerHTML = html;

	document.body.appendChild(siteboxdiv);
}
function closeSiteBox()
{
	if (siteboxdiv) {
		document.body.removeChild(siteboxdiv);
		siteboxdiv = null;
	}
}

var showsiteboxtimer;
function setShowsiteboxtimer(no, title, ms)
{
	var func = "clearShowsiteboxtimer();showSiteBox(" + no + ",\"" + title + "\");";
	showsiteboxtimer = setInterval(func, ms);
}
function clearShowsiteboxtimer()
{
	if (showsiteboxtimer) {
		clearInterval(showsiteboxtimer);
		showsiteboxtimer = undefined;
	}
	closeSiteBox();
}
function setsiteboxhandleA(tagname)
{
	var els = document.getElementsByTagName(tagname);
	
	var n = els.length;
	for (i = 0; i < n; ++i) {
		var el = els[i];
		if (el.name && el.name.indexOf("sitebox:") == 0) {
			var val = el.name.substring(8);
			var pos = val.indexOf(":");
			el.siteboxno    = val.substring(0, pos);
			el.siteboxtitle = val.substring(pos + 1);
			if (el.siteboxtitle == ".") {
				el.siteboxtitle = el.innerHTML;
			}
			el.onmouseover = function() {
				setShowsiteboxtimer(this.siteboxno, this.siteboxtitle, 200);
			};
			el.onmouseout = clearShowsiteboxtimer;
		}
	}
}
function setsiteboxhandler()
{
	 setsiteboxhandleA("A");
	 setsiteboxhandleA("SPAN");
}

// ===========================================

var mouse_x = -1;
var mouse_y = -1;
function saveMousePos(e)
{
	if (document.all) {	// IE
		var x4  = document.body.scrollLeft || document.documentElement.scrollLeft;
		var y8  = document.body.scrollTop  || document.documentElement.scrollTop;
		mouse_x = x4 + event.clientX;
		mouse_y = y8 + event.clientY;
	}
	else if (document.layers || document.getElementById) {	// Firefox, Safari, Opera
		mouse_x = e.pageX;
		mouse_y = e.pageY;
	}
}

var client_cx = -1;
var client_cy = -1;
function saveClientSize()
{
	if (! document.all && (document.layers || document.getElementById)) {
		client_cx = window.innerWidth;
		client_cy = window.innerHeight;
	}
	else if (document.getElementById && (document.compatMode == 'CSS1Compat')) {
		client_cx = document.documentElement.clientWidth;
		client_cy = document.documentElement.clientHeight;
	}
	else if (document.all) {
		client_cx = document.body.clientWidth;
		client_cy = document.body.clientHeight;
	}
	else {
		client_cx = -1;
		client_cy = -1;
	}
};

// ===========================================

function viewaccesscounter()
{
	var url = "http://www.frebull.info/counter/count.htm";
	wget(url, true, viewaccesscounter_callback);
}

function viewaccesscounter_callback(html)
{
	var counterdivel = document.getElementById("counterdiv")
	counterdivel.innerHTML =
		 html + "<br>" +
		"<div style='padding-top:3px;'>SINCE 2006.7</div>";
}

// ===========================================

function accesscount()
{
	var ref = document.referrer;
	if (ref.indexOf("http://www.frebull.info") == -1) {
		document.write("<img src=\"/counter/counter.cgi?ref=" + ref + "\" width=1 height=1>");
	}
	else {
		document.write("<img src=\"/counter/pvcounter.cgi\" width=1 height=1>");
	}
}

// ===========================================

var onimgs  = new Array();
var offimgs = new Array();

function imgon()
{
	var id = this.id;
	this.src = onimgs[id].src;
}

function imgoff()
{
	var id = this.id;
	this.src = offimgs[id].src;
}

function setonoffimage(id, offimgurl, onimgurl)
{
	var el = document.getElementById(id);
	if (el) {
		el.onmouseover = imgon;
		el.onmouseout  = imgoff;
		onimgs[id]  = new Image(); onimgs[id].src  = onimgurl;
		offimgs[id] = new Image(); offimgs[id].src = offimgurl;
	}
}

// ===========================================

function GetCookie(key)
{
	var cookie = document.cookie + ";";
	var key_str = key + "=";
	var key_start = cookie.indexOf(key_str, 0);
	if (key_start != -1) {
		var val = cookie.substring(key_start + key_str.length);
		var key_end = val.indexOf(";", 0);
		return unescape(val.substring(0, key_end));
	}
	return "";
}

// ===========================================

function setonoffimages()
{
	setonoffimage(
		"navi_home",
		"http://www.hiroba.cc/images/navi_home.gif",
		"http://www.hiroba.cc/images/navi_home_on.gif");

	setonoffimage(
		"navi_bbs",
		"http://www.hiroba.cc/images/navi_bbs.gif",
		"http://www.hiroba.cc/images/navi_bbs_on.gif");

	setonoffimage(
		"navi_myhiroba",
		"http://www.hiroba.cc/images/navi_myhiroba.gif",
		"http://www.hiroba.cc/images/navi_myhiroba_on.gif");
}

// ===========================================

function showmyhirobabyjs()
{
	var html = 
		"<script type=\"text/javascript\" src=\"" + 
		"http://www.frebull.info/my/?js8\"></script>";
	document.write(html);
}

// ===========================================

function onscrollbody()
{
	closeImage();
	clearShowsiteboxtimer();
}

function openspan(id)
{
	var el = document.getElementById(id);
	if (el.style.display == "none") { el.style.display = "inline"; }
	else                            { el.style.display = "none"; }

//	document.activeElement.innerText = "";	// firefox
}

// ===========================================

function absOffsetTopByID(id)
{
	var el = document.getElementById(id);
	if (el) {
		return absOffsetTopByElem(el);
	}
	else {
		return -1;
	}
}

function absOffsetTopByElem(el)
{
	if (el.offsetParent.tagName.toLowerCase()=="body") {
		return el.offsetTop;
	}
	else {
		return el.offsetTop + absOffsetTopByElem(el.offsetParent);
	}
}

function show_rnbad()
{
	var ypos_rb = absOffsetTopByID('rightbottom');
	var ypos_lb = absOffsetTopByID('leftbottom');

	var rnbad125 =
		'<script type="text/javascript">\n' +
		'google_ad_client = "pub-0008221021595864";\n' +
		'google_ad_slot = "2103023884";\n' +
		'google_ad_width = 125;\n' +
		'google_ad_height = 125;\n' +
		'</scr' + 'ipt>\n' +
		'<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">\n' +
		'</scr' + 'ipt>';

	var rnbad240 =
		'<script type="text/javascript">\n' +
		'google_ad_client = "pub-0008221021595864";\n' +
		'google_ad_slot = "7272337732";\n' +
		'google_ad_width = 120;\n' +
		'google_ad_height = 240;\n' +
		'</scr' + 'ipt>\n' +
		'<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">\n' +
		'</scr' + 'ipt>';

	var rnbad600 =
		'<script type="text/javascript">\n' +
		'google_ad_client = "pub-0008221021595864";\n' +
		'google_ad_slot = "6244561151";\n' +
		'google_ad_width = 120;\n' +
		'google_ad_height = 600;\n' +
		'</scr' + 'ipt>\n' +
		'<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">\n' +
		'</scr' + 'ipt>';
	 	
	if (0 < ypos_rb && 0 < ypos_lb)
	 {
		var rnb_margin = 50;
		var rnb_height = ypos_lb - ypos_rb - rnb_margin;
		

		 if (600 < rnb_height) {
			document.write(rnbad600);
		}
		else if (240 < rnb_height) {
			document.write(rnbad240);
		}
		else if (125 < rnb_height) {
			document.write(rnbad125);
		}
	}
}

// ===========================================

function show_rakuten_ad()
{
	var ii = Math.floor(Math.random() * 5);
	var ads = new Array(
		'<a href="http://hb.afl.rakuten.co.jp/hsc/0bf91860.0f096ea4.0bf91691.7df0e060/" target="_blank"><img src="http://hbb.afl.rakuten.co.jp/hsb/0bf91860.0f096ea4.0bf91691.7df0e060/" border="0"></a>',
		'<a href="http://hb.afl.rakuten.co.jp/hsc/0bf91865.9107553e.0bf91691.7df0e060/" target="_blank"><img src="http://hbb.afl.rakuten.co.jp/hsb/0bf91865.9107553e.0bf91691.7df0e060/" border="0"></a>',
		'<a href="http://hb.afl.rakuten.co.jp/hsc/0bf9186b.f07ba6ba.0bf91691.7df0e060/" target="_blank"><img src="http://hbb.afl.rakuten.co.jp/hsb/0bf9186b.f07ba6ba.0bf91691.7df0e060/" border="0"></a>',
		'<a href="http://hb.afl.rakuten.co.jp/hsc/0bf9186e.b80e3052.0bf91691.7df0e060/" target="_blank"><img src="http://hbb.afl.rakuten.co.jp/hsb/0bf9186e.b80e3052.0bf91691.7df0e060/" border="0"></a>',
		'<a href="http://hb.afl.rakuten.co.jp/hsc/0bf9168f.82651a76.0bf91691.7df0e060/" target="_blank"><img src="http://hbb.afl.rakuten.co.jp/hsb/0bf9168f.82651a76.0bf91691.7df0e060/" border="0"></a>');

	document.write(ads[ii]);
}

// ===========================================

var document_is_loaded = 0;
function hirobaonload()
{
	document_is_loaded = 1;
	
	viewaccesscounter();

	setlinkclickcallback();
	
	document.onmousemove = saveMousePos;
	
	if (document.all) { document.documentElement.onscroll = onscrollbody; }
	else              { document.onscroll = onscrollbody; }

	setsiteboxhandler();
}
