/* DHTML-library 
needed for eventhandling event_init() and main navigation
extended with show/hidelayer service functions and IE4 recognition variable
$Source: /home/CVS/new_bull/common2/jscript/Attic/dhtml.js,v $
$Revision: 1.1.2.1 $
Check-In $Date: 2005/08/26 12:58:31 $
*/
// --- Resize Fix for Layers
// Opera & NS4 resize-Topnavigation Fix START
var ResizeTimer;
var origW=window.innerWidth;
var origH=window.innerHeight;

//パス設定変数
var sUriPrefix;
//OS・ブラウザ判別用変数
var DHTML = 0, DOM = 0, MS = 0, NS = 0, OP = 0, IE4 = 0, MAC = 0, NT4=0, IE6 = 0, WIN = 0;

//OS・ブラウザ判別は最初に行うようにしました 2004/11/12修正
if(document.getElementById) {
	DHTML = 1;
	DOM = 1;
}
if(document.all) {
	DHTML = 1;
	MS = 1;
}
if(document.layers) {
	DHTML = 1;
	NS = 1;
}
if (MS && !DOM){
	IE4 = 1;
}
if (navigator.userAgent.toLowerCase().indexOf("mac")>-1){
	MAC = 1;
}
if (navigator.userAgent.toLowerCase().indexOf("msie 6")>-1){
	IE6 = 1;
}
if (navigator.userAgent.toLowerCase().indexOf("windows nt;")>-1){
	NT4 = 1;
}
if (navigator.userAgent.toLowerCase().indexOf("windows")>-1){
	WIN = 1;
}
if(window.opera && document.getElementById){
	// 判別すると表示がずれる。
	// OP = 1;
}

///////////////////// 以下メソッド /////////////////////////////////////////

// Opera / NS4.x resize-Topnavigaton Fix Check 
function checkResize() {
	clearTimeout( ResizeTimer );
	if ( !OP && !NS ) return true;
	if ( OP && !(window.innerWidth==origW && window.innerHeight==origH)) location.reload();
	else if ( NS && !(window.outerWidth==origW && window.outerHeight==origH)) location.reload();
	ResizeTimer = window.setTimeout("checkResize()", 500);
	return true;
}
// Opera & NS4 (on Mac) resize-Topnavigation Fix END	

function preLoad (imgfile) {
	Cache = new Image();
	eval ("Cache.src = \"" + sUriPrefix + imgfile+"\"");
}
			
// hides corrupted HTML-Page when using Netscape-Resize-Patch
function grayOutPageOnNetscapeReload(){ 
	var grayOutAllLayer = new Layer(innerWidth);
	with(grayOutAllLayer){
		left = 0;
		top = 0;
		clip.height = innerHeight;
		clip.width = innerWidth;
		bgColor = "#e4e4e4";
		zIndex = 1000;
		document.open();
		document.write("Reloading, please wait...");
		document.close();
		visibility = "show";
	}
}

function swapImage(imgName, imgSource, layerId){//Bildwechsel
    var imageObject;
		if (NS) {
			if (layerId)
        imageObject = getImageObjectForNS4( imgName, getLayerById(layerId).document );
			else 
				imageObject = getImageObjectForNS4( imgName );
      imageObject.src = imgSource;
		} else if (document.images[imgName]) { 
			document.images[imgName].src = imgSource;
		} else if (DOM){
			document.getElementById(imgName).src = imgSource;
		}
	return true;
}

function getImageObjectForNS4(id, d){
	if (!NS) return null;
	var searchResult = null;
	if (!d) d = document;
	if (d.images[''+id+'']) searchResult = d.images[''+id+''];
	for (var i=0; !searchResult && i < d.layers.length; i++){			 
		searchResult = getImageObjectForNS4( id, d.layers[i].document );
	}
	return searchResult;
}

// initialise the window status bar and bugfix scrollbar for MAC+IE
//ページが読み込まれた時点で呼ばれる(bodyタグ内に記述)
function initPage(windowStatus){
	if ( OP || NS ){	// Opera / NS4 Resize Patch
		clearTimeout( ResizeTimer );
		if (NS){
			origW=window.outerWidth;
			origH=window.outerHeight;
		}
		ResizeTimer = window.setTimeout("checkResize()",500);
	}
	if (MAC && MS) { window.resizeBy(0,1); window.resizeBy(0,-1); } // garanties the scrollbar on mac+IE
	
	window.status = windowStatus;
	window.defaultStatus = windowStatus;
	
	// remove the rectangle around links for IE+Win
	if (MS&&WIN) { document.onmousedown = ExplorerFix; };
	
	return true;
}

// remove the rectangle around links for IE+Win only onClick-event, TAB function remains
function ExplorerFix() {
	for (a in document.links) document.links[a].onfocus = document.links[a].blur; 
	}

// service function to get Layer-object in NS4 no matter how much surrounding layers
function getLayerObjectForNS4(id, d){
	if (!NS) return null;
	var searchResult = null;
	if (!d) d = document;
	if (d.layers[''+id+'']) searchResult = d.layers[''+id+''];
	for (var i=0; !searchResult && i < d.layers.length; i++){			 
		searchResult = getLayerObjectForNS4( id, d.layers[i].document );
	}
	return searchResult;
}
// almost like the getElem-function of DHTML.js, but can only get layer-objects
// and has advanced capabilities for NS4 using getLayerObjectForNS4()
function getLayerById(id, d){
	if (id == '' && !id ) return null;
	var layerObject = null;
	if (NS) layerObject = getLayerObjectForNS4( id, d );
	else if (MS) layerObject = document.all[''+id+''];
	else if (DOM) layerObject = document.getElementById(id);	
	return layerObject;
}

/*
関数名  ：eMBLayer
処理概要：レイヤークラス
パラメタ：レイヤーのId
戻り値  ：なし
*/
// START: eMBLayer - Object
function eMBLayer ( id ) {
	//--- data member(メンバー変数)----
	// can be used if direct access on the layer-object is required
	//レイヤーオブジェクトへの直接アクセスが必要とされる場合に使用する
	this.object = getLayerById( id ); 
	// the id of the layer as a string
	//レイヤーのIDを文字列として取得することができる
	this.id = id; 
	
}
eMBLayer.prototype = {
	// returns true if layer was found, else false, object.isObject()
	//オブジェクトが存在する場合にtrue,存在しない場合にfalseを返す
	isObject: function() {
		return ( (this.object==null)?false:true );
	},

	// returns the parent layer as an eMBLayer object, object.getParentLayer()
	//eMBLayerオブジェクトとして親レイヤーを返す
	getParentLayer: function() {
		// returns the parent-eMBLayer of the layer with the given id as an object
		//オブジェクトがNULLではないかを確認
		if (!this.isObject()){
			return null;
		}

		//初期化
		var parentLayerObject = null;

		if (NS){
			parentLayerObject = new eMBLayer( this.object.parentLayer.name );
		}else if (MS){
			var parentObject = this.object.parentElement;
			while (parentObject && parentObject.parentElement && parentObject.tagName.toLowerCase() != "div"){
				parentObject = parentObject.parentElement;
			}
			if (parentObject && parentObject.tagName.toLowerCase() != "div"){
				parentObject = null;
			}
		}else if (DOM){
			var parentObject = this.object.parentNode ;
			while (parentObject && parentObject.parentNode && !((parentObject.nodeType==1 || OP) && parentObject.tagName.toLowerCase()=="div") )
				parentObject = parentObject.parentNode ;
			if ( !( parentObject && (parentObject.nodeType==1 || OP) && parentObject.tagName.toLowerCase()=="div") ) parentObject = null;
		}
		return (new eMBLayer(null)).convertLayerToEmbLayer( parentObject );
	},

	// converts an usual layer object to an eMBLayer object, 
	// targetEmbLayerObject.convertLayerToEmbLayer( sourceLayerObject )
	convertLayerToEmbLayer : function( layerObject ) {
		this.object = layerObject;
		this.id = this.getId();
		return this;
	},

	// writes the id of the calling object into the "id"-property
	getId : function() {
		if ( !this.isObject() ) return null;
		if (MS || DOM) return this.object.id;
		else if (NS) return this.object.name;
	},

	// object.show()
	show : function() {
		if ( !this.isObject() ) return true;
		if (NS) this.object.visibility = "show";
		else if (MS || DOM) this.object.style.visibility = "visible";
	},

	// object.hide()
	hide : function() {
		if ( !this.isObject() ) return true;
		if (NS) this.object.visibility = "hide";
		else if (MS || DOM) this.object.style.visibility = "hidden";
	},

	// sets the background color of the caling eMBLayer, object.setBgColor("#ffffff")
	setBgColor : function( newColor ) {
		if ( !this.isObject() ) return true;
		if (NS) this.object.bgColor = newColor;
		else this.object.style.backgroundColor = newColor;
	},

	// set x Position of the layer, object.setX( int-Value )
	setX : function( newXPosition ) {
		if ( !this.isObject() ) return true;
		if (NS) this.object.left = newXPosition;
		else if (MS || DOM) this.object.style.left=newXPosition+"px";
	},

	// set y Position of the layer, object.setY( int-Value )
	setY : function( newYPosition ) {
		if ( !this.isObject() ) return true;
		if (NS) this.object.top = newYPosition;
		else if (MS || DOM) this.object.style.top = newYPosition+"px";
	},
	
	// retrieves x Position of the layer, relative to parent element, object.getX()
	getX : function() {
		var w = -1;
		if ( !this.isObject() ) return w;
		if (MS || DOM) w = this.object.offsetLeft;
		else if (NS) w = this.object.left;
		return w;
	},

	// retrieves y Position of the layer, relative to parent element, object.getY()
	getY : function() {
		var w = -1;
		if ( !this.isObject() ) return w;
		if (MS || DOM) w = this.object.offsetTop;
		else if (NS) w = this.object.top;
		return w;
	},

	// retrieves y Position of the layer, relative to browser window, object.setAbsoluteX()
	getAbsoluteY : function() {
		var absTop = 0;
		if ( !this.isObject() ) return -1;
		var layerObject = this;
		if (NS) return this.object.pageY;
		while( layerObject.isObject() ){
			absTop = absTop + layerObject.getY();
			layerObject = layerObject.getParentLayer();
		}
		return absTop;
	},

	
	// retrieves the width of the layer, object.getWidth()
	getWidth : function() {
		var w = -1;
		if ( !this.isObject() ) return w;
		if (DOM && !OP) this.object.style.width = "auto"; // needed but can reset a layers size in strict HTML4.01
		if (IE4 || OP) w = this.object.style.pixelWidth;
		else if (MS || (DOM && !OP)) w = this.object.offsetWidth; // IE5+ & NS6
		else if (NS) w = this.object.clip.width;
		return w;
	},

	// retrieves the height of the layer, object.getHeight()
	getHeight : function() {
		var w = -1;
		if ( !this.isObject() ) return w;
		if (DOM && !OP) this.object.style.height = "auto";
		if (MS || (DOM && !OP)) w = this.object.offsetHeight;
		else if (NS) w = this.object.clip.height;
		else if (OP) w = this.object.style.pixelHeight;
		return w;
	},

	
	// setting width and height for layers
	// used on initalization and when positioning highlight layers
	// on Mozilla 0.9x+ don't use getWidth or getHeight (on the same layer) after this function, this
	// would shrink layer size to its contents size
	//レイヤーの横幅・縦幅を設定する
	// sets the size for the layer, object.setSize( int-Value width, int-Value height )
	setSize : function( newWidth, newHeight ) {
		//オブジェクトがNULLではないかを確認
		if ( !this.isObject() ) return true;
		if (!NS){
			with (this.object.style) {
				if (MS || OP){
					pixelWidth = newWidth;
					pixelHeight = newHeight;
				}	else if (DOM && !OP){		
					width = newWidth+"px";
					height = newHeight+"px";
				}
			}
		} else if (NS){
			this.object.resizeTo(newWidth, newHeight);
			with(this.object.clip){
				top = 0;
				left = 0;
				width = newWidth;
				height = newHeight;
			}
		}
	}

}
// END: eMBLayer - Object

