﻿/*****************************************************************
/*
/* ポップアップ表示用
/*
/*****************************************************************/
function popup(path, name, width, height, position, scrollbars, resizable) {

	if( typeof(position) == "undefined" ) {
		position = "center";
	}

	if( typeof(scrollbars) == "undefined" ) {
		scrollbars = "no";
	}

	if( typeof(resizable) == "undefined" ) {
		resizable = "yes";
	}

	if(position == "center") {
		lf= (window.screen.availWidth - width) / 2;
		tp = (window.screen.availHeight - height) / 2;
	} else if(position == "right") {
		lf = window.screen.availWidth - width - 10;
		tp= 0;
	} else {
		lf= 0;
		tp = 0;
	}

	window.open("/popup.html?src="+path, name, "top="+tp+",left="+lf+",width="+width+",height="+height+",resizable="+resizable+",scrollbars="+scrollbars+",status=no,toolbar=no,directories=no,menubar=no");
}


/*****************************************************************
/*
/* ソーシャルブックマークの登録用
/*
/*****************************************************************/
function addSocialBookmark(SMB, Link, Title) {

	var title;
	var link;
	var open_url;

	// タイトルの指定が無ければ現在のHTMLのタイトルを使用
	if( Title != undefined || Title=="" )
	{
		title = encodeURIComponent(Title);
	}
	else
	{
		title = encodeURIComponent(document.title);
	}

	// リンクの指定が無ければ現在のホスト名を利用
	if( Link != undefined || Link=="" )
	{
		link = encodeURIComponent(Link);
	}
	else
	{
		link = encodeURIComponent("http://" + window.location.hostname + "/");
	}


	switch( SMB )
	{
		case "Yahoo":
			open_url = "http://bookmarks.yahoo.co.jp/bookmarklet/showpopup"
									+ "?t=" + title
									+ "&u=" + link
									+ "&opener=bm&ei=UTF-8";
			break;

		case "Google":
			open_url = "http://www.google.com/bookmarks/mark"
									+ "?op=edit"
									+ "&title=" + title
									+ "&bkmk=" + link;

			break;

		case "Hatena":
			open_url = "http://b.hatena.ne.jp/append"
									+ "?" + link;
			break;

		case "Nifty":
			open_url = "http://clip.nifty.com/create"
									+ "?title=" + title
									+ "&url=" + link;
			break;
							

		case "livedoor":
			open_url = "http://clip.livedoor.com/redirect"
									+ "?title=" + title
									+ "&link=" + link;
			break;
							

		case "delicious":
			open_url = "http://del.icio.us/post"
									+ "?title=" + title
									+ "&url=" + link;
			break;

		
		default:
			open_url = ""
			break;
	}

	window.open(open_url);
	//alert(open_url);
}


/*****************************************************************
/*
/* ブックマークの登録用
/*
/*****************************************************************/
function addBookmark(URL, Title) {
	try {
		window.external.AddFavorite(URL, Title);
	} catch(e) {
		alert("このリンクはIE(Internet Exploler)専用です");
	}
}

/*****************************************************************
/*
/* 動きのあるTOPに戻る用
/*
/*****************************************************************/
var ReturnSpeed = 1;
// スクロールスピードを設定します。
// 値が大きくなればなるほど速くなります。

function ScrollTop() {

    // ページ最上部からの距離をピクセル単位でyに代入します。
    if(navigator.appName == "Microsoft Internet Explorer" && document.compatMode == "CSS1Compat"){
      var y = document.body.parentNode.scrollTop;
    }else{
      var y = document.body.scrollTop;
    }
	

    // ReturnSpeedの値が50未満且つyが0でない場合、以下の処理を行います。
    // ・yが2以上であるなら、y*1.2を四捨五入してyに代入。
    // 　以下ならば1を代入。つまりイージングの設定。
    // 　ReturnSpeedに1を加算し、ページをスクロール。
    // 　if文が真である間これを繰り返します。
    // ページ最上部までのスクロールが完了したら変数ReturnSpeedに1を代入しリセット。
    if(ReturnSpeed < 50 && y) {
      y = (y > 2) ? Math.ceil(y*.2) : 1;
      ReturnSpeed++;
      scrollBy(0,-y);
      setTimeout("ScrollTop()",10);
    }else{
      scrollTo(0,0);
      ReturnSpeed = 1;
    }
}


/*****************************************************************
/*
/* ブラウザ強制閉じスクリプト
/*
/*****************************************************************/

function WindowForceClose() {

	window.opener = window;
	window.open(location.href,'_self');
	window.close();

}


/*****************************************************************
/*
/* XHTMLの為のIframe動的呼び出し
/*
/*****************************************************************/

function ShowIframe(Width, Height, Src, ID, Text, Scrolling) {
	
	if( typeof(Width) == "undefined" || Width=="" ) {
		Width = "100%";
	}

	if( typeof(Height) == "undefined" || Height=="" ) {
		Height = "100%";
	}

	if( typeof(Text) == "undefined" || Text=="" ) {
		Text = "ここはインラインフレームです";
	}

	if( typeof(Scrolling) == "undefined" || Scrolling=="" ) {
		Scrolling = "no";
	}

	var tag = "<iframe id='" + ID +"' src='" + Src +"' frameborder='0' width='" + Width + "' height='" + Height +"' scrolling='" + Scrolling + "'>"
							+ Text
							+ "</iframe>";
	
	document.write(tag);

}


