/*************************************************
 * POPUP用のJavascript
 * 2009.02.03 AZIA S.Sato
 *************************************************/
var PAGE_OFFSET_X = 10;
var PAGE_OFFSET_Y = 10;
var popupHelpLayerId = 'widget-help';

//-------------------------------------------------------------------
// PopupHelp widget
//-------------------------------------------------------------------
var popupHelpLayerId = 'widget-help';

function showPopupHelp(e, text, positionX, positionY) {
	if (positionX == null) {
		positionX = PAGE_OFFSET_X;
	} else {
		positionX = positionX + PAGE_OFFSET_X;
	}
	if (positionY == null) {
		positionY = PAGE_OFFSET_Y;
	} else {
		positionY = positionY + PAGE_OFFSET_Y;
	}
	
	showWidgetByPosition(Event.pointerX(e), Event.pointerY(e), popupHelpLayerId, positionX, positionY, text);
}

function hidePopupHelp() {
	hideWidget(popupHelpLayerId);
}

//-------------------------------------------------------------------
// Util function
//-------------------------------------------------------------------
function setWidgetVisibility(layer_id, show_flag) {
	visibility = 'hidden';
	if (show_flag) {
		visibility = 'visible';
	}
	if (document.all) {
		//IE
		$(layer_id).style.visibility = visibility;
	} else if (document.getElementById) {
		//NN
		$(layer_id).style.visibility = visibility;
	} else {
		//NN4
		visibility = ('visible' == visibility) ? 'show' : 'hide';
		$(layer_id).style.visibility = visibility;
	}
}
function setWidgetLayerPosition(layer_id, left, top) {
	if (document.all) {
		//IE
		$(layer_id).style.left	= left;
		$(layer_id).style.top	= top;
	} else if (document.getElementById) {
		//NN
		$(layer_id).style.left	= left + "px";
		$(layer_id).style.top	= top  + "px";
	} else {
		//NN4
		$(layer_id).style.left	= left;
		$(layer_id).style.top	= top;
	}
}
function showWidget(e, layer_id, positionX, positionY) {
	mouse_x = Event.pointerX(e);
	mouse_y = Event.pointerY(e);
	scroll_y= (document.all) ? document.body.scrollTop: pageYOffset;
	
	setWidgetLayerPosition(layer_id, mouse_x + positionX, mouse_y + positionY + scroll_y);
	
	setWidgetVisibility(layer_id, 'true');
}
function showWidgetByPosition(mouse_x, mouse_y, layer_id, positionX, positionY, text) {
	scroll_y= 0;
	
	if (text != null) {
		$(layer_id).innerHTML = text;
	}
	
	setWidgetLayerPosition(layer_id, mouse_x + positionX, mouse_y + positionY + scroll_y);
	
	setWidgetVisibility(layer_id, true);
}
function hideWidget(layer_id) {
	setWidgetVisibility(layer_id, false);
}
function setWidgetInnerHTML(element_id, text) {
	if(document.all) {
		document.all(element_id).innerHTML = text;
	} else if(document.getElementById) {
		document.getElementById(element_id).innerHTML = text;
	}
}
function wait(condition, func) {
	if (condition()) {
		func()
	} else {
		var f = function() { wait(condition, func) };
		setTimeout(f, 100);
	}
}

// ポップアップ用 html を出力しておく
document.write('<div id="'+popupHelpLayerId+'"></div>');

