/* 
JavaScript Document
*/

//ページスクロール
var MovePageTimer;

function GetObjTag( tag_id )
{
	if( document.all && !window.opera ){
		return document.all( tag_id );
	} else if( document.getElementById ){
		return document.getElementById( tag_id );
	} else {
		return false;
	}
}

function GetBodyOffsetTop( obj_tag, offsetTop_num )
{
	if( !offsetTop_num ){ offsetTop_num = 0; }
	if( document.all && !window.opera )
	{
		if( obj_tag.tagName.toUpperCase() != "BODY" )
		{
			offsetTop_num += obj_tag.offsetTop;
			if( obj_tag.parentElement )
			{
				return GetBodyOffsetTop( obj_tag.parentElement, offsetTop_num );
			} else {
				return 0;
			}
		} else {
			return offsetTop_num;
		}
	} else {
		if( obj_tag.tagName.toUpperCase() != "BODY" )
		{
			offsetTop_num += obj_tag.offsetTop;
			if( obj_tag.parentNode )
			{
				return GetBodyOffsetTop( obj_tag.parentNode, offsetTop_num );
			} else {
				return 0;
			}
		} else {
			return offsetTop_num;
		}
	}
}

function GetBodyOffsetLeft( obj_tag, offsetLeft_num )
{
	if( !offsetLeft_num ){ offsetLeft_num = 0; }
	if( document.all && !window.opera )
	{
		if( obj_tag.tagName.toUpperCase() != "BODY" )
		{
			offsetLeft_num += obj_tag.offsetLeft;
			if( obj_tag.parentElement )
			{
				return GetBodyOffsetLeft( obj_tag.parentElement, offsetLeft_num );
			} else {
				return 0;
			}
		} else {
			return offsetLeft_num;
		}
	} else {
		if( obj_tag.tagName.toUpperCase() != "BODY" )
		{
			offsetLeft_num += obj_tag.offsetLeft;
			if( obj_tag.parentNode )
			{
				return GetBodyOffsetLeft( obj_tag.parentNode, offsetLeft_num );
			} else {
				return 0;
			}
		} else {
			return offsetLeft_num;
		}
	}
}

function GetCoords( obj_coords )
{
	if( obj_coords )
	{
		if( document.all && !window.opera ){
			if( obj_coords.obj_tag ){
//				obj_coords.x = GetBodyOffsetLeft( obj_coords.obj_tag );
//				obj_coords.y = GetBodyOffsetTop( obj_coords.obj_tag );
				obj_coords.x = obj_coords.obj_tag.offsetLeft;
				obj_coords.y = obj_coords.obj_tag.offsetTop;
			} else {
				if( document.compatMode )
				{
					obj_coords.x = ( document.compatMode == "CSS1Compat" ) ? document.body.parentNode.scrollLeft : document.body.scrollLeft;
					obj_coords.y = ( document.compatMode == "CSS1Compat" ) ? document.body.parentNode.scrollTop : document.body.scrollTop;
				} else {
					obj_coords.x = document.body.scrollLeft;
					obj_coords.y = document.body.scrollTop;
				}
			}
		} else if( document.getElementById ){
			if( obj_coords.obj_tag ){
				obj_coords.x = obj_coords.obj_tag.offsetLeft;
				obj_coords.y = obj_coords.obj_tag.offsetTop;
//				obj_coords.x = GetBodyOffsetLeft( obj_coords.obj_tag );
//				obj_coords.y = GetBodyOffsetTop( obj_coords.obj_tag );
			} else {
				obj_coords.x = window.pageXOffset;
				obj_coords.y = window.pageYOffset;
			}
		} else {
			return false;
		}
		return obj_coords;
	} else {
		return false;
	}
}

function GetMaxHeight()
{
	var win_height = 0;
	var doc_height = 0;

	if( document.all && !window.opera ){

		if( document.compatMode )
		{
			win_height = ( document.compatMode == "CSS1Compat" ) ? document.body.parentNode.clientHeight : document.body.clientHeight;
			doc_height = ( document.compatMode == "CSS1Compat" ) ? document.body.parentNode.scrollHeight : document.body.scrollHeight;
		} else {
			win_height = document.body.clientHeight;
			doc_height = document.body.scrollHeight;
		}
	} else {
		win_height = window.innerHeight;
		doc_height = document.height;
	}
	return doc_height - win_height;

}

function MovePage( to_x,to_y,form_x,form_y )
{
	var frame_num = 6;

	if (MovePageTimer){ clearTimeout(MovePageTimer); }

	var go_x = ( to_x - form_x ) / frame_num;
	if( go_x > 0 && go_x < 1 ){ go_x = 1; }
	var go_y = ( to_y - form_y ) / frame_num;
	if( go_y > 0 && go_y < 1 ){ go_y = 1; }
	form_x = Math.floor( form_x + go_x );
	if( form_x < 0 ){ form_x = 0; }
	form_y = Math.floor( form_y + go_y );
	if( form_y < 0 ){ form_y = 0; }

	window.scrollTo( form_x, form_y );


	if( ( to_x != form_x ) || ( to_y != form_y ) )
	{
		MovePageTimer = setTimeout( "MovePage("+to_x+","+to_y+","+form_x+","+form_y+")", 16 );
	}
}


function MovePageScroll( tag_id )
{
	var max_height = GetMaxHeight();
	var to_coords = new Object;

	// タグIDの座標取得
	if( tag_id ){
		if( tag_id == "top" )
		{
			to_coords.obj_tag = GetObjTag( tag_id );
			if( !to_coords.obj_tag ){ return; }
			to_coords = GetCoords( to_coords );
			if( !to_coords ){ return; }
			if( to_coords.y > max_height ){ to_coords.y = max_height; }
			to_coords.obj_tag = null;
		} else {
			to_coords.obj_tag = GetObjTag( tag_id );
			if( !to_coords.obj_tag ){ return; }
			to_coords = GetCoords( to_coords );
			if( !to_coords ){ return; }
			if( to_coords.y > max_height ){ to_coords.y = max_height; }
			to_coords.obj_tag = null;
		}
	} else {
		to_coords.x = 0;
		to_coords.y = 0;
	}

	// 現在の座標を取得
	var form_coords = new Object;
	form_coords = GetCoords( form_coords );
	if( !form_coords ){ return false; }

	if( form_coords.y > max_height ){ form_coords.y = max_height; }


	if( ( to_coords.x != form_coords.x ) || ( to_coords.y != form_coords.y ) )
	{
		MovePageTimer = setTimeout( "MovePage("+to_coords.x+","+to_coords.y+","+form_coords.x+","+form_coords.y+")", 16 );
	}
}




function chgKwColor( thisForm, objName, cName )
{
	if( document.getElementById )
	{
		objId = thisForm.elements[objName].id;
		if( thisForm.elements[objName].value == "キーワード入力" ){ document.getElementById(objId).className=cName; }
	}
}

function chgKwCreate( thisForm, objName, cName )
{
	if( document.getElementById ){
		if( thisForm.elements[objName].value == "キーワード入力" ){ thisForm.elements[objName].value = ""; }
		objId = thisForm.elements[objName].id;
		document.getElementById(objId).className=cName;
	}
}

