var ModalDialogWindow;
var ModalDialogInterval;
var ModalDialog = new Object;

ModalDialog.value = '';
ModalDialog.eventhandler = '';

function refresh_page()
{
	document.location.replace(document.location.href);
}

function ModalDialogMaintainFocus()
{
	try
	{
		if (ModalDialogWindow.closed)
		{
			window.clearInterval(ModalDialogInterval);
			eval(ModalDialog.eventhandler);
			return;
		}

//			ModalDialogWindow.focus();
	}
	catch (everything)
	{

	}
}

function ModalDialogRemoveWatch()
{
	ModalDialog.value = '';
	ModalDialog.eventhandler = '';
}

function ModalDialogShow(page_to_show, do_refresh)
{
	var do_refresh = (do_refresh == null) ? true : do_refresh;

	ModalDialogRemoveWatch();

	if(do_refresh === true)
	{
		ModalDialog.eventhandler = "refresh_page()";
	}

	var args='width=800,height=610,left=325,top=300,toolbar=0,';
	args += 'location=0,status=0,menubar=0,scrollbars=1,resizable=0'; 

	ModalDialogWindow=window.open("","",args);
	ModalDialogWindow.document.open('');
	ModalDialogWindow.document.location = page_to_show;
	ModalDialogWindow.document.close();
	ModalDialogWindow.focus();
	ModalDialogInterval = window.setInterval("ModalDialogMaintainFocus()", 5);
}

function getXmlHttpRequestObject()
{
	if (window.XMLHttpRequest)
	{
		return new XMLHttpRequest();
	}
	else if(window.ActiveXObject)
	{
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		return false;
	}
}

var xml_request = getXmlHttpRequestObject();

var refresh_client = false;

function start_refresh_client_profile()
{
	refresh_client = setInterval('refresh_client_profile()', 10000);
}

function refresh_client_profile()
{
	if ((xml_request.readyState == 4) || (xml_request.readyState == 0))
	{
		var current_profile_id = document.getElementById('current_client_id').innerHTML;

		xml_request.open("POST", "refresh_client_profile.php", true);
		xml_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xml_request.onreadystatechange = refresh_client_profile_response;
		xml_request.send("id=" + current_profile_id);
	}
}

function refresh_client_profile_response()
{
	if(xml_request.readyState == 4)
	{
		document.getElementById('client_profile').innerHTML = xml_request.responseText;
	}
}