function GetWindowHeight()
{
	var currWinHeight;
		
	if (window.innerHeight) {//FireFox with correction for status bar at bottom of window
		currWinHeight = window.innerHeight;
	} else if (document.documentElement.clientHeight) {//IE 7 with correction for address bar
		currWinHeight = document.documentElement.clientHeight;
	} else if (document.body.offsetHeight) {//IE 4+
		currWinHeight = document.body.offsetHeight + 10;
	}
	return currWinHeight - 10; // 10 - horizontal scrollbar height
}

function GetPageHeight()
{
	var iebody = (document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body;
	var pageTop = document.all ? iebody.scrollTop : pageYOffset;
	return pageTop + GetWindowHeight();
}

function GetPageTop()
{
	var iebody = (document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body;
	var pageTop = document.all ? iebody.scrollTop : pageYOffset;
	return pageTop;
}

function display_dialog(div_id)
{
	// you must have empty div named 'form_div'; sample code is given below
	// <div id="form_div" style="left:-5000px; height: auto; background: url(<inp2:m_TemplatesBase module="custom" />img/absolute_background.gif); opacity: .2; filter: alpha(opacity=20); position:absolute; top:0px; width:100%; height:100%; z-index:5;">&nbsp;</div>
	// also check that you have absolute_background.gif image in your project
	document.getElementById('form_div').style.left = 0;
	document.getElementById('form_div').style.top = 0;
	document.getElementById('form_div').style.height = GetPageHeight() + 'px';
	
	if (!document.all) {
		var $winW = window.innerWidth;
		var $winH = window.innerHeight;
	}
	else {
		var $winW = window.document.body.offsetWidth;
		var $winH = window.document.body.offsetHeight;
	}
	
	$winH = GetPageHeight() - GetPageTop();
	
	document.getElementById(div_id).style.display = 'block';
	
	var div_w = document.getElementById(div_id).offsetWidth;
	var div_h = document.getElementById(div_id).offsetHeight;
	
	var left = Math.round(($winW - div_w)/2) + 'px';
	var top = Math.round(($winH - div_h)/2 + GetPageTop()) + 'px';
	
	document.getElementById(div_id).style.top = top;
	document.getElementById(div_id).style.left = left;
}

function close_dialog(div_id)
{
	document.getElementById('form_div').style.left = '-5000px';
	document.getElementById(div_id).style.display = 'none';
}

// this part implements js alert and confirm divs

var fnc_to_call = false;
var opened_msg_box = false;

function show_message(msg_type, msg, function_to_call)
{
	document.getElementById(msg_type + '_msg').innerHTML = msg;
	display_dialog(msg_type + '_div');
	fnc_to_call = function_to_call;
	opened_msg_box = msg_type;
}

//<div id="confirm_div" style="position: absolute; display: none; z-index: 10; border: 1px solid #777; padding: 15px; width: auto; height: auto; overflow: hidden; background-color: #fff; text-align: center;">
//	<span id="confirm_msg"></span>
//	&nbsp;&nbsp;
//	<input type="button" class="button" id="confirm_button_yes" value="<inp2:m_Phrase label="la_Yes" />" onclick="close_dwin(true);" />
//	<input type="button" class="button" id="confirm_button_no" value="<inp2:m_Phrase label="la_No" />" onclick="close_dwin(false);" />
//</div>

function confirm_d(msg, function_to_call)
{
	show_message('confirm', msg, function_to_call);
	document.getElementById('confirm_button_no').focus();
}

//<div id="alert_div" style="position: absolute; display: none; z-index: 10; border: 1px solid #777; padding: 15px; width: auto; height: auto; overflow: hidden; background-color: #fff; text-align: center;">
//	<span id="alert_msg"></span>
//	&nbsp;&nbsp;
//	<input type="button" class="button" id="alert_close_button" value="<inp2:m_Phrase label="la_Ok" />" onclick="close_dwin(true);" />
//</div>

function alert_d(msg, function_to_call)
{
	show_message('alert', msg, function_to_call);
	document.getElementById('alert_close_button').focus();
}

function close_dwin(ret_value)
{
	close_dialog(opened_msg_box + '_div');
	setTimeout(fnc_to_call.replace('#RET#', ret_value ? 'true' : 'false'), 50);
	fnc_to_call = false;
	opened_msg_box = false;
}