/**
* 画面の縦位置の設定や取得のJavaScript関数。
*
* ※画面が縦方向にスクロールした状態から次のウィンドウに行き、戻る場合、元の画面の元の縦方向の表示位置に戻る処理をおこなっている。
*
* @author sek <sekiguchis@pm.nttdata.co.jp>
* @see saveScrollTop,loadScrollTop,initScrollTop,getCookie,setCookie,clearCookie
* @version 1.00 2006/09/04 created
*/

/**
* 現在の画面の縦方向の表示位置をクッキーへ書き込む。
*
* @param string key キー（文字列）
*/
	function saveScrollTop(key) {
		if(self.pageYOffset){
			pos = self.pageYOffset;
		}
		else if(document.body) {
			if(document.body.scrollTop){
				pos = document.body.scrollTop;
			}
			else	pos = 0;
		}
		else		pos = 0;
		setCookie(key, pos);
		return true;
	}


/**
* 画面の縦方向の表示位置をクッキーから取り込み、実際の画面をその位置にセットする。
*
* @param string key キー（文字列）
*/
	function loadScrollTop(key) {
		pos = getCookie(key);
		if((pos > 0) && (self.scroll)){
			self.scroll(0, pos);
		}
		clearCookie(key);
	}


/**
* 画面の縦方向の表示位置を保存するクッキーを初期化し、次回の画面表示時には縦方向の表示位置が画面トップになるようにする。
*
* @param string key キー（文字列）
*/
	function initScrollTop(key) {
		clearCookie(key);
	}


/**
* 現在の画面の縦方向の表示位置をクッキーから取り出す。
*
* @param string key キー（文字列）
* @return string 縦方向の表示位置（数値）または空文字列
*/
	function getCookie(key) {
		tmp1 = " " + document.cookie + ";";
		xx1 = xx2 = 0;
		len = tmp1.length;
		while (xx1 < len) {
			xx2 = tmp1.indexOf(";", xx1);
			tmp2 = tmp1.substring(xx1 + 1, xx2);
			xx3 = tmp2.indexOf("=");
			if (tmp2.substring(0, xx3) == key) {
				return(unescape(tmp2.substring(xx3 + 1, xx2 - xx1 - 1)));
			}
			xx1 = xx2 + 1;
		}
		return("");
	}


/**
* 指定したキーのクッキーを自由に設定する。
*
* @param string key キー（文字列）
* @param string val 値（文字列）
*/
	function setCookie(key, val) {
		tmp = key + "=" + escape(val) + "; ";
		document.cookie = tmp;
	}


/**
* 指定したキーのクッキーをクリア（期限切れに）する。
*
* @param string key キー（文字列）
*/
	function clearCookie(key) {
		document.cookie = key + "=" + "0; expires=1-Jan-1997 00:00:00;";
	}


