//==========================================================
//           Javascript Library [ functions.js ]
//     Copyright (C) 2001 mother inc. / System Department.
//
//           Programing by Y.TAKIMOTO
//=========================================: Mother Inc. :==
//
//----------------------------------------------------------
// 2001.10.17(v1.0)
//  ・Javascriptライブラリ作成
// 2001.11.29(v.1.2)
//  ・getHeightLAYER / getTopLAYERにて、IE4.0でおきる不具合修正
//  ・checkExistLAYERにて、Mac版IE4.5でおきる不具合修正
// 2002.1.24(v.1.3)
//	・findLAYERを追加。入れ子レイヤーに対応した:「／」で区切ること

//----------------------------------------------------------
//レイヤーオブジェクト取得関数( findLAYER )
// [ 引数 ] LayerName : レイヤーのID名
// [戻り値] なし
//----------------------------------------------------------
function findLAYER( LayerName ){
	var arrayLayer = new Array();
	var obj = document;
	var i = 0;
	arrayLayer = LayerName.split("/");
	
	LayerName = arrayLayer[arrayLayer.length - 1]
	if(document.getElementById){
		// Netscape6 & Internet Explorer5.x
		obj = obj.getElementById(LayerName)
	}else{
		if( document.all ){
			// Internet Explorer4.x
			obj = obj.all(LayerName);
		}
	}

	if( document.layers ){
		for( i=0; i<arrayLayer.length; i++ ){
			obj = obj.layers[arrayLayer[i]];
		}
	}
	
	return obj;
}

//----------------------------------------------------------
//レイヤー相対座標移動関数( moveByLAYER )
// [ 引数 ] LayerName : レイヤーのID名
//          offsetX   : レイヤーのX座標移動量
//          offsetY   : レイヤーのY座標移動量
// [戻り値] なし
//----------------------------------------------------------
function moveByLAYER( LayerName, offsetX, offsetY ){
	var obj=findLAYER(LayerName);
	if(document.getElementById){
		// Netscape6 & Internet Explorer5.x
		var obj = obj.style
		obj.left = ( parseInt(obj.left) + offsetX ) + 'px'
		obj.top  = ( parseInt(obj.top)  + offsetY ) + 'px'
	}else{
		if( document.all ){
			// Internet Explorer4.x
			obj.style.pixelLeft += offsetX;
			obj.style.pixelTop  += offsetY;
		}
	}
	if( document.layers ){
		// Netscape Communicator 4.x
		obj.moveBy( offsetX, offsetY );
	}
}

//----------------------------------------------------------
//レイヤー絶対座標移動関数( moveToLAYER )
// [ 引数 ] LayerName : レイヤーのID名
//          offsetX   : レイヤーのX座標移動量
//          offsetY   : レイヤーのY座標移動量
// [戻り値] なし
//----------------------------------------------------------
function moveToLAYER( LayerName, offsetX, offsetY ){
	var obj=findLAYER(LayerName);
	if(document.getElementById){
		// Netscape6 & Internet Explorer5.x
		var obj = obj.style
		obj.left = offsetX  + 'px'
		obj.top  = offsetY  + 'px'
	}else{
		if( document.all ){
			// Internet Explorer4.x
			obj.style.pixelLeft = offsetX;
			obj.style.pixelTop  = offsetY;
		}
	}
	if( document.layers ){
		// Netscape Communicator 4.x
		obj.moveTo( offsetX, offsetY );
	}
}

//----------------------------------------------------------
//レイヤー表示・非表示関数( ShowHideLAYER )
// [ 引数 ] LayerName : レイヤーのID名
//          Attr      : 表示・非表示属性(show:表示 hide:非表示)
// [戻り値] なし
//----------------------------------------------------------
function ShowHideLAYER( LayerName, Attr ){
	var obj=findLAYER(LayerName);
	if( Attr == 'hide' ){
		// レイヤーの非表示
		if( document.getElementById || document.all ){
			obj.style.visibility = 'hidden';
		}else if( document.layers ) obj.visibility = 'hide';
	}else{
		if( Attr == 'show' ){
			// レイヤーの表示
			if( document.getElementById || document.all ){
				obj.style.visibility = 'visible';
			}else if( document.layers ) obj.visibility = 'show';
		}else{
			if( document.getElementById || document.all ){
				obj.style.visibility = Attr;
			}else if( document.layers ) obj.visibility = Attr;
		}
	}
}

//----------------------------------------------------------
//レイヤー表示・非表示状態取得( getShowHideLAYER )
// [ 引数 ] LayerName : レイヤーのID名
// [戻り値] 状態( true : 表示 / false : 非表示 )
//----------------------------------------------------------
function getShowHideLAYER( LayerName, Attr ){
	var pty = '';
	var retFlag = false;
	var obj=findLAYER(LayerName);

	if( document.getElementById || document.all ){
		pty = obj.style.visibility;
	}else if( document.layers ) pty = obj.visibility;
	
	if( pty == 'visible' || pty == 'show' ){
		retFlag = true;
	}
	
	return retFlag;
}


//----------------------------------------------------------
//レイヤーの高さ取得( getHeightLAYER )
// [ 引数 ] LayerName : レイヤーのID名
// [戻り値] レイヤーの高さ
//----------------------------------------------------------
function getHeightLAYER( LayerName ){
	var h = 0;
	var obj=findLAYER(LayerName);
	if( document.getElementById || document.all ){
		h = obj.offsetHeight;
	}else if( document.layers ) h = obj.clip.height;

	return h;
}

//----------------------------------------------------------
//レイヤーの幅取得( getWidthLAYER )
// [ 引数 ] LayerName : レイヤーのID名
// [戻り値] レイヤーの幅
//----------------------------------------------------------
function getWidthLAYER( LayerName ){
	var w = 0;
	var obj=findLAYER(LayerName);
	if( document.getElementById || document.all){
		w = obj.offsetWidth;
	}else if( document.layers ) w = obj.clip.width;
	return w;
}

//----------------------------------------------------------
//レイヤーのY座標取得( getTopLAYER )
// [ 引数 ] LayerName : レイヤーのID名
// [戻り値] レイヤーのY座標
//----------------------------------------------------------
function getTopLAYER( LayerName ){
	var y = 0;
	var obj=findLAYER(LayerName);
	if( document.getElementById  ){
		// Netscape6 & Internet Explorer5.x
		y = parseInt(obj.style.top);
	}else{
		if( document.all    ){
			// Internet Explorer4.x
			y = obj.style.pixelTop;
		}
	}
	// Netscape Communicator 4.x
	if( document.layers ) y = obj.top;
	return y;
}

//----------------------------------------------------------
//レイヤーのX座標取得( getLeftLAYER )
// [ 引数 ] LayerName : レイヤーのID名
// [戻り値] レイヤーのX座標
//----------------------------------------------------------
function getLeftLAYER( LayerName ){
	var x = 0;
	var obj=findLAYER(LayerName);
	if( document.getElementById  ){
		// Netscape6 & Internet Explorer5.x
		x = parseInt(obj.style.left);
	}else{
		if( document.all    ){
			// Internet Explorer4.x
			x = obj.style.pixelLeft;
		}
	}
	// Netscape Communicator 4.x
	if( document.layers ) x = obj.left;
	return x;
}

//----------------------------------------------------------
//レイヤーのz-index値変更( setzIndexLAYER )
// [ 引数 ] LayerName : レイヤーのID名
//          zIndex    : z-index値(0が最背面となる)
// [戻り値] レイヤーのz-index値
//----------------------------------------------------------
function setZIndexLAYER( LayerName,zIndex ){
	var y = 0;
	var obj=findLAYER(LayerName);

	if( document.getElementById || document.all ){
		obj.style.zIndex = zIndex;
	}else if( document.layers ) document.layers[LayerName].zIndex = zIndex;

	return y;
}


//----------------------------------------------------------
//ウインドウのサイズ取得( getSize )
// [ 引数 ] Attr : 取得プロパティ( width : 横幅 height:縦幅 )
// [戻り値] ウインドウのサイズ
//----------------------------------------------------------
function getSize( Attr ){
	var size=0;

	if( Attr == 'width' ){
		if( window.innerWidth ){
			size = window.innerWidth;
		}else{
			size = document.body.clientWidth;
		}
	}else{
		if( Attr == 'height' ){
			if( window.innerHeight ){
				size = window.innerHeight;
			}else{
				size = document.body.clientHeight;
			}
		}
	}
	return size;
}

//----------------------------------------------------------
//レイヤーの有無チェック ( checkExistLAYER )
// [ 引数 ] LayerName : レイヤーのID名
// [戻り値] レイヤーの有無状況(true : あり / false :　なし )
//----------------------------------------------------------
function checkExistLAYER( LayerName ){
	var checkFlag = false;
	var uAgent  = navigator.userAgent.toUpperCase();
	var obj=findLAYER(LayerName);
	var arrayLayer = new Array();

	if( document.getElementById ){
		if( obj != null ){
			checkFlag = true;
		}
	}else{
		if( document.all ){
			if( uAgent.indexOf("MAC") >= 0 ){
				arrayLayer = LayerName.split("/");
				LayerName = arrayLayer[arrayLayer.length - 1]
				if( document[LayerName] ){
					checkFlag = true;
				}
			}else{
				if( obj ){
					checkFlag = true;
				}
			}
		}
	}
	if( document.layers ){
		if( obj ){
			checkFlag = true;
		}
	}
	return checkFlag;
}

//----------------------------------------------------------
//表示領域の左上座標[X座標]( getScrollLeft )
// [ 引数 ] なし
// [戻り値] X座標
//----------------------------------------------------------
function getScrollLeft(){
	var left=0;

	if( document.all ){
		left = document.body.scrollLeft;
	}else{
		left = window.pageXOffset;
	}
	return left;
}

//----------------------------------------------------------
//表示領域の左上座標[Y座標]( getScrollTop )
// [ 引数 ] なし
// [戻り値] Y座標
//----------------------------------------------------------
function getScrollTop(){
	var top=0;

	if( document.all){
		top = document.body.scrollTop;
	}else{
		top = window.pageYOffset;
	}
	return top;
}

//----------------------------------------------------------
//Cookieを保持する( setCookie )
// [ 引数 ] cookieID     : クッキーID
//          cookieValue  : クッキーの文字列
//          cookieExpire : クッキー保持期間
//          cookiePath   : クッキー保持パス
// [ 引数 ] 結果(true : 成功 / false : 失敗 )
//----------------------------------------------------------
function setCookie( cookieID, cookieValue, cookieExpire, cookiePath ){

	var retFlag = false;
	var expireDateNow;
	var strCookie;
	
	strCookie = '';
	if( cookieID != null ){
		strCookie = cookieID + "=" + escape(cookieValue) + ";"
		if( cookieExpire != null ){
			cookieExpire = eval( cookieExpire );
			expireDateNow = new Date();
			expireDateNow.setDate( expireDateNow.getDate() + ( cookieExpire * 60 * 60 * 24 ) );
			strExpire = expireDate.toGMTString();
			strCookie += "expires=" + strExpire + ";";
		}
		if( cookiePath != null && cookiePath != "" ){
			strCookie = "path" + cookiePath + ";";
		}
		
		document.cookie = strCookie;
		retFlag = true;
	}
	return retFlag;
}

//----------------------------------------------------------
//Cookieを取得する( getCookie )
// [ 引数 ] cookieID     : クッキーID
// [ 引数 ] クッキー文字列
//----------------------------------------------------------
function getCookie( cookieID ){
	var strCookie = '';
	var st = 0, ed = 0;
	var retString = '';
	
	if( document.cookie != '' && cookieID != null ){
		cookieID += "=";
		strCookie = document.cookie + ";";
		
		st = strCookie.indexOf( cookieID );
		if( st != -1 ){
			ed = strCookie.indexOf(";" , st );
			retString = unescape( strCookie.substring( st + cookieID.length, ed ) );
		}
	}
	return retString;
}

