/** アラートウインドウポップアップ機能 **********************************/

// グローバル変数初期化
var ns6=document.getElementById&&!document.all?1:0;

var DIV_IDS_A = "alert_window";

var current;		//イベント発生元オブジェクト
var timerID;

// _dom : kind of DOM.
//        IE4 = 1, IE5+ = 2, NN4 = 3, NN6+ = 4, others = 0
var _dom = document.all?(document.getElementById?2:1):
(document.getElementById?4:
(document.layers?3:0));


//オーバーレイ背景準備
function setTranslucent4a() {
	createAlertPopupWindow();
	createTranslucent();
	var e = document.getElementById(DIV_IDS_A);
		
	if (!e) {
		var objBody = document.getElementsByTagName("body").item(0);
		
		var objDiv = document.createElement("div");
		objDiv.id = DIV_IDS_A;
	 	objBody.appendChild(objDiv);
	}
}

function createTranslucent () {
	var e = document.getElementById('translucent');
	
	if (!e) {
		var objBody = document.getElementsByTagName("body").item(0);
	
		var objTranslucent = document.createElement("div");
		objTranslucent.setAttribute('id','translucent');
		objTranslucent.style.display = 'none';
		objTranslucent.style.position = 'absolute';
		objTranslucent.style.top = '0';
		objTranslucent.style.left = '0';
	 	objTranslucent.style.width = '100%';
	 	objTranslucent.style.zIndex = 900;

		objBody.insertBefore(objTranslucent, objBody.firstChild);
	}
}
	
function createAlertPopupWindow() {
	var e = document.getElementById('alert_window');
	
	if (!e) {
		var str = '';
		
		str += '<table width="270" border="0" cellspacing="0" cellpadding="0"><tr><td>';
		str += '<div class="bgBorderballoonA07">';
		str += '<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr>';
		str += '<td align="right" id="closeAlert1">';
		str += '<a href="javascript:clearPopAlert();"><img src="/popup/imgs/btn_close.gif" alt="閉じる" width="16" height="16"><\/a>';
		str += '<\/td>';
		str += '<\/tr><\/table>';
		str += '<\/div>';
		str += '<div class="bgBorder01">';
		str += '<table width="100%" border="0" cellspacing="0" cellpadding="0">';
		str += '<tr>';
		str += '<td width="43"><img src="/popup/imgs/icon_error_003.gif" alt="エラー" width="33" height="33" /><\/td>';
		str += '<td id="alertMsg"><\/td>';
		str += '<\/tr><\/table>';
		str += '<div class="marginT10">';
		str += '<table width="100%" border="0" cellspacing="0" cellpadding="0">';
		str += '<tr>';
		str += '<td align="center"  id="closeAlert2">';
		str += '<a href="javascript:clearPopAlert();"><img src="/cmn/imgs/btn_041.gif" alt="OK" width="136" height="32" /><\/a>';
		str += '<\/td>';
		str += '<\/tr><\/table><\/div><\/div><\/td><\/tr><\/table>'

		
		var objBody = document.getElementsByTagName("body").item(0);
		var objDiv = document.createElement("div");
		objDiv.id = 'alert_window';
		objDiv.style.visibility = 'hidden';
		objDiv.style.position = 'absolute';
		objDiv.style.top = '0px';
		objDiv.style.left = '0px';
		objDiv.innerHTML = str;
		objBody.appendChild(objDiv);

	}
}

//イベント
function alertPop(msgTitle) {
	var buttonRel = 'alert_window';
	var objBtn;

	setTranslucent4a();
	document.getElementById("alertMsg").innerHTML= msgTitle;

	current = document.getElementById(buttonRel);

	clearPopAlert();
	
	var arrayPageSize = getPageSize();
	var scrollHeight = getScrollHeight();
	var scrollWidth = getScrollWidth();
	var windowWidth = arrayPageSize[2];
	var windowHeight = arrayPageSize[3];

	//本体表示位置取得
	var popTop = (windowHeight / 2) + scrollHeight - (getDivHeight(current) / 2);
	current.style.top = popTop + 'px';
	// windowWidthだとスクロールバー幅の分、中心がずれるので使用できるならclientWidthを使用する
	var popWindowWidth = document.body.clientWidth != null ? document.body.clientWidth : windowWidth;
	var popLeft = (popWindowWidth / 2) - (getDivWidth(current) / 2);

	current.style.left = popLeft + 'px';
	
	var objBody = document.getElementsByTagName("body").item(0);
	objBody.setAttribute('className', 'showpopup01');
	
	//本体表示
	timerID = setInterval('showAlertPop("' + buttonRel + '")', 200);
}

//ポップアップ表示
function showAlertPop (targetID) {
	clearInterval(timerID);
	var showContext = ns6?document.getElementById(targetID):document.all(targetID);

	showContext.style.visibility = "visible";
	showContext.style.zIndex = 1000;

}


//ポップアップ全消去
function clearPopAlert() {
	var showContext;
	
	var objBody = document.getElementsByTagName("body").item(0);
	objBody.setAttribute('className', 'def');
	var objTranslucent = ns6?document.getElementById('translucent'):document.all('translucent');
	if (objTranslucent) {
		objTranslucent.style.display = 'none';
	}
	
	var divId = DIV_IDS_A;
	showContext = ns6?document.getElementById(divId):document.all(divId);
	if (showContext) {
		showContext.style.visibility = "hidden";
	}
	
	//タイマーIDをクリア
	if(timerID) clearInterval(timerID);
}

//タグ縦サイズ取得
function getDivHeight(div){
	// _dom : kind of DOM.
	//        IE4 = 1, IE5+ = 2, NN4 = 3, NN6+ = 4, others = 0
	if(_dom==4 || _dom==2) return div.offsetHeight;
	if(_dom==1)            return div.style.pixelHeight;
	if(_dom==3)            return div.clip.height;
	return 0;
}

//タグ横サイズ取得
function getDivWidth (div){
	// _dom : kind of DOM.
	//        IE4 = 1, IE5+ = 2, NN4 = 3, NN6+ = 4, others = 0
	if(_dom==4 || _dom==2) return div.offsetWidth;
	if(_dom==1)            return div.style.pixelWidth;
	if(_dom==3)            return div.clip.width;
	return 0;
}


//ページ縦スクロールサイズ取得
function getScrollHeight() {
	var scrollHeight;
	if (self.pageYOffset) {
		scrollHeight = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		scrollHeight = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		scrollHeight = document.body.scrollTop;
	}
	return scrollHeight;
}

//ページ横スクロールサイズ取得
function getScrollWidth() {
	var scrollWidth;
	if (self.pageXOffset) {
		scrollWidth = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollLeft){	 // Explorer 6 Strict
		scrollWidth = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		scrollWidth = document.body.scrollLeft;
	}
	return scrollWidth;
}


//ページ縦横サイズ、ウィンドウ縦横サイズ取得
function getPageSize(){
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

