// IHM pop-up notice control code

// set pop up state here
//   0 => no pop up
//   1 => pop up once a day
//   2 => pop up always

popup = 0;

//---------- -------------------------------------
// Check if DOM is supported
//---------- -------------------------------------
(document.getElementById) ? dom = true : dom = false;

//---------- -------------------------------------
// Dismiss popup function
//---------- -------------------------------------
function hide_popup() {
	if (dom) {document.getElementById("notice").style.visibility='hidden';}
}

//---------- -------------------------------------
// Display popup function
//---------- -------------------------------------
function show_popup() {
	if (dom) {document.getElementById("notice").style.visibility='visible';}
}

// -----------------------------------------------
// Set location of popup then display it
// -----------------------------------------------
function place_popup() {

	if (dom) {								// place in middle of the page
		Notice = document.getElementById("notice");
		Nhght = Notice.clientHeight;					// popup height
		Nwdth = Notice.clientWidth;						// popup width
		Whght = document.documentElement.clientHeight;	// window height
		Wwdth = document.documentElement.clientWidth;	// window width

		Notice.style.top  = (Whght/2 - Nhght/2) + "px";
		Notice.style.left = (Wwdth/2 - Nwdth/2) + "px";
	}

// show notice after short delay (1sec)
	window.setTimeout("show_popup()", 500);
}

// -----------------------------------------------
// show popup notice if it hasn't been seen today
// -----------------------------------------------
function showNotice() {

	if (popup == 1 && document.cookie.indexOf("IhmNotice") == -1) {

		// set expire date to mid-night today
		expireTime = new Date;
		expireTime.setDate(expireTime.getDate() + 1);
		expireTime.setHours(0);
		expireTime.setMinutes(0);
		expireTime.setSeconds(0);

		// set a cookie that expires at mid-night
		document.cookie = "IhmNotice=popup control;expires="+expireTime.toGMTString();
		// locate the popup in the middle of the window and show it
		place_popup();

	} else if (popup == 2) {	// always show the popup
		place_popup();
	}

}

