var calc_text_obj = null;
var calc_text_left_obj = null;
var calc_text_right_obj = null;

function init_common_dialogs(theme_color, font_color, base_url)
{
var div_obj = document.createElement('div');
div_obj.id = "calculate_text_obj";
div_obj.style.visibility = 'hidden';
div_obj.style.position = 'absolute';
div_obj.style.left = '0px';
div_obj.style.top = '0px';
//div_obj.style.width = '0px';
div_obj.style.height = '0px';

str += '<table style="font-size: 10pt; font-family: arial;" border="0" cellspacing="0" cellpadding="0" border="0">';
str += '	<tr>';
str += '		<td id="calculate_text_left_obj" align="left" valign="top">';
str += '		</td>';
str += '		<td id="calculate_text_right_obj" align="left" valign="bottom">&nbsp;';
str += '		</td>';
str += '	</tr>';
str += '	<tr>';
str += '		<td id="calculate_text_bottom_obj" align="left" valign="top">';
str += '		</td>';
str += '		<td align="left" valign="bottom">&nbsp;';
str += '		</td>';		
str += '	</tr>';
str += '</table>';

div_obj.innerHTML = str;
document.body.appendChild(div_obj);
calc_text_obj = div_obj;

calc_text_left_obj = document.getElementById('calculate_text_left_obj');
calc_text_right_obj = document.getElementById('calculate_text_right_obj');
calc_text_bottom_obj = document.getElementById('calculate_text_bottom_obj');


div_obj = document.createElement('div');
div_obj.id = "confirm_dialog";
div_obj.style.display = 'none';
div_obj.style.backgroundColor = theme_color; 
div_obj.style.color = font_color;
div_obj.style.border = '1px outset white';
div_obj.style.zIndex = 150;
div_obj.style.position = 'absolute';
div_obj.style.left = '0px';
div_obj.style.top = '0px';
div_obj.style.width = '0px';
div_obj.style.height = '0px';

var str = '';
str +=	'<table border="0" cellspacing="0" cellpadding="0" width="100%" height="100%">';
str +=	'	<tr>';
str +=	'		<td align="center" valign="middle" height="24">';
str +=	'			<table bgcolor="#88AACC" style="color: black; font-size: 10pt" border="0" cellspacing="4" cellpadding="0" width="100%" height="100%">';
str +=	'				<tr>';
str +=	'					<td id="confirm_dialog_header" width="100%" onmousedown="dialog_start_dragging(document.getElementById(\'confirm_dialog\'),event);" style="cursor: move; text-align:left;font-weight: bold" >';
str +=	'					</td>';
str +=	'					<td style="text-align:right; font-family: arial; font-size: 10pt" align="right" valign="middle">';
str +=	'						<img src="'+base_url+'/_images/comment_close.gif" onclick="cancel_confirm_dialog();" style="cursor: pointer; cursor: hand;" title="Click here to close this box">';
str +=	'					</td>';
str +=	'				</tr>';
str +=	'			</table>';
str +=	'		</td>';
str +=	'	</tr>';
str +=	'	<tr>';
str +=	'		<td height="100%">';
str +=	'			<table style="font-size: 10pt" border="0" cellspacing="5" cellpadding="0" width="100%" height="100%">';
str +=	'				<tr>';
str +=	'					<td id="confirm_dialog_text" align="center" valign="top">';
str +=	'					</td>';
str +=	'				</tr>';
str +=	'				<tr>';
str +=	'					<td align="center" valign="top">';
str +=	'						<table border="0" cellspacing="0" cellpadding="0" height="25">';
str +=	'							<tr>';
str +=	'								<td align="right" valign="top">';
str +=	'									<button onclick="ok_confirm_dialog()" id="confirm_dialog_ok" style="width: 60px;">Ok</button>';
str +=	'								</td>';
str +=	'								<td align="center" valign="top" width="10">';
str +=	'								</td>';
str +=	'								<td align="left" valign="top">';
str +=	'									<button onclick="cancel_confirm_dialog()" id="confirm_dialog_cancel" style="width: 60px;">Cancel</button>';
str +=	'								</td>';
str +=	'							</tr>';
str +=	'						</table>';
str +=	'					</td>';
str +=	'				</tr>';
str +=	'			</table>';
str +=	'		</td>';
str +=	'	</tr>';
str +=	'</table>';
div_obj.innerHTML = str;
document.body.appendChild(div_obj);

div_obj = document.createElement('div');
div_obj.id = "alert_dialog";
div_obj.style.display = 'none';
div_obj.style.backgroundColor = theme_color; 
div_obj.style.color = font_color;
div_obj.style.border = '1px outset white';
div_obj.style.zIndex = 150;
div_obj.style.position = 'absolute';
div_obj.style.left = '0px';
div_obj.style.top = '0px';
div_obj.style.width = '0px';
div_obj.style.height = '0px';

str = '';							
str +='<table border="0" cellspacing="0" cellpadding="0" width="100%" height="100%">';
str +='	<tr>';
str +='		<td align="center" valign="middle" height="24">';
str +='			<table style="background-color: #88AACC; color: black; font-size: 10pt" border="0" cellspacing="4" cellpadding="0" width="100%" height="100%">';
str +='				<tr>';
str +='					<td id="alert_dialog_header" width="100%" onmousedown="dialog_start_dragging(document.getElementById(\'alert_dialog\'),event);" style="cursor: move; text-align:left;font-weight: bold" >';
str +='						Message';
str +='					</td>';
str +='					<td style="text-align:right; font-family: arial; font-size: 10pt" align="right" valign="middle">';
str +='						<img src="'+base_url+'/_images/comment_close.gif" onmouseup="close_alert_dialog();" style="cursor: pointer; cursor: hand;" title="Click here to close this box">';
str +='					</td>';
str +='				</tr>';
str +='			</table>';
str +='		</td>';
str +='	</tr>';
str +='	<tr>';
str +='		<td height="100%">';
str +='			<table style="font-size: 10pt" border="0" cellspacing="5" cellpadding="0" width="100%" height="100%">';
str +='				<tr>';
str +='					<td id="alert_dialog_text" align="center" valign="top">';
str +='					</td>';
str +='				</tr>';
str +='				<tr>';
str +='					<td align="center" valign="top">';
str +='						<button id="alert_dialog_ok" onclick="close_alert_dialog();" width="60">Ok</button>';
str +='					</td>';
str +='				</tr>';
str +='			</table>';
str +='		</td>';
str +='	</tr>';
str +='</table>';
div_obj.innerHTML = str;
document.body.appendChild(div_obj);
}

function window_confirm(header, msg, ok_func, cancel_func)
{
//find out the size of the msg string
var high = get_text_height(msg) + 70;
var wide = get_text_width(msg) + 20;
wide = Math.max(100, wide);
var confirm_dialog_obj = document.getElementById('confirm_dialog');
var confirm_dialog_text_obj = document.getElementById('confirm_dialog_text');
var confirm_dialog_ok_obj = document.getElementById('confirm_dialog_ok');
var confirm_dialog_cancel_obj = document.getElementById('confirm_dialog_cancel');
var confirm_dialog_header_obj = document.getElementById('confirm_dialog_header');

if(confirm_dialog_obj == null || confirm_dialog_text_obj == null || confirm_dialog_ok_obj == null || confirm_dialog_cancel_obj == null || confirm_dialog_header_obj == null)
	return;

disable_screen(true);
confirm_dialog_obj.style.display = 'none';
confirm_dialog_obj.style.left = (screen.availWidth - wide)/2;
confirm_dialog_obj.style.top = (screen.availHeight - high)/2 + document.body.scrollTop;
confirm_dialog_obj.style.width = wide + 'px';
confirm_dialog_obj.style.height = high + 'px';
confirm_dialog_text_obj.innerHTML = msg;
confirm_dialog_header_obj.innerHTML = header;

//alert(wide + "," + high);
if(ok_func != null)
	{
	confirm_dialog_ok_obj.name = ok_func;
	}
else
	{
	confirm_dialog_ok_obj.name = '';
	}	
	
if(cancel_func != null)
	{
	confirm_dialog_cancel_obj.name = cancel_func.toString();
	}
else
	{
	confirm_dialog_cancel_obj.name = '';
	}
		
confirm_dialog_obj.style.display = '';
}

function ok_confirm_dialog()
{
var func = document.getElementById('confirm_dialog_ok').name;
if(func != '' && func != null)
	{
	setTimeout(func, 10);
	}
close_confirm_dialog();
}

function cancel_confirm_dialog()
{
var func = document.getElementById('confirm_dialog_cancel').name;
if(func != '' && func != null)
	{
	setTimeout(func, 10);
	}
close_confirm_dialog();
}

function close_confirm_dialog()
{
disable_screen(false);
var confirm_dialog_obj = document.getElementById('confirm_dialog');
confirm_dialog_obj.style.display = 'none';
}

function close_alert_dialog()
{
disable_screen(false);
var alert_dialog_obj = document.getElementById('alert_dialog');
alert_dialog_obj.style.display = 'none';
}

function show_alert_dialog(header, msg)
{
//find out the size of the msg string
var high = get_text_height(msg) + 70;
var wide = get_text_width(msg) + 20;
wide = Math.max(100, wide);
var alert_dialog_obj = document.getElementById('alert_dialog');
var alert_dialog_text_obj = document.getElementById('alert_dialog_text');
var alert_dialog_header_obj = document.getElementById('alert_dialog_header');

if(alert_dialog_obj == null || alert_dialog_text_obj == null || alert_dialog_header_obj == null)
	return;
disable_screen(true);
alert_dialog_obj.style.display = 'none';
alert_dialog_obj.style.left = (screen.availWidth - wide)/2;
alert_dialog_obj.style.top = (screen.availHeight - high)/2 + document.body.scrollTop;
alert_dialog_obj.style.width = wide + 'px';
alert_dialog_obj.style.height = high + 'px';
alert_dialog_text_obj.innerHTML = msg;
//alert(wide + "," + high);
if(header != null)
	{
	alert_dialog_header_obj.innerHTML = header;
	}
alert_dialog_obj.style.display = '';
}

function get_text_width(str, css_style)
{
calc_text_obj.style.display = 'none';
calc_text_left_obj.innerHTML = str;
calc_text_obj.style.display = '';
var x = findPosX(calc_text_right_obj);
x = x - findPosX(calc_text_left_obj);
//obj.style.display = 'none';
return x;
}

function get_text_height(str, css_style)
{
calc_text_obj.style.display = 'none';
calc_text_left_obj.innerHTML = str;
calc_text_obj.style.display = '';
var y = findPosY(calc_text_bottom_obj);
y = y - findPosY(calc_text_left_obj);
//obj.style.display = 'none';
return y;
}