function get_browser()
{
	if(document.all)
	{
		return "IE";
	}
	else if(document.getElementById)
	{
		return "NN";
	}
}

// get the browser type
var browser = get_browser();

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

var xml_request = getXmlHttpRequestObject();

function load_xml_from_string(string)
{
	// code for IE
	if (window.ActiveXObject)
	{
		var doc = new ActiveXObject("Microsoft.XMLDOM");
		doc.async = "false";
		doc.loadXML(string);
	}
	// code for Mozilla, Firefox, Opera, etc.
	else
	{
		var parser = new DOMParser();
		var doc = parser.parseFromString(string, "text/xml");
	}
	
	return doc;
}

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 get_cursor_positions(event)
{
	var x, y;

	if(browser == "IE")
	{
		x = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
		y = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop;
	}
	else if(browser == "NN")
	{
		x = event.clientX + window.scrollX;
		y = event.clientY + window.scrollY;
	}
	
	return new Array(x, y)
}

function hide_window(item_id)
{
	if(document.getElementById(item_id))
	{
		document.getElementById(item_id).style.visibility = "hidden";
	}
}

function show_window(event, item_id)
{
	var cursor_position = get_cursor_positions(event);

	if(document.getElementById(item_id))
	{
		var the_window = document.getElementById(item_id);

		the_window.style.visibility = "visible";
		the_window.style.left = cursor_position[0] + "px";
		the_window.style.top = cursor_position[1] + 20 + "px";
	}
}

function hide_help(destination_id)
{
	if(document.getElementById(destination_id))
	{
		document.getElementById(destination_id).innerHTML = "";
	}
}

function show_help(item_id, destination_id)
{
	if(document.getElementById(item_id) && document.getElementById(destination_id))
	{
		document.getElementById(destination_id).innerHTML = document.getElementById(item_id).innerHTML;
	}
}

function item_arrived(item_id)
{
	var confirmed = confirm("Please confirm that the parcel has arrived");

	if(confirmed)
	{
		document.location.replace("index.php?p=30&received="+item_id);
	}
	else
	{
		document.getElementById("consumer_"+item_id).checked = false;
	}
}

function item_collected(item_id)
{
	var confirmed = confirm("Please confirm that the parcel has been collected");

	if(confirmed)
	{
		document.location.replace("index.php?p=31&collected="+item_id);
	}
	else
	{
		document.getElementById("consumer_"+item_id).checked = false;
	}
}