var lastWin

function PopupScreenCentre(url,name,width,height,scrollbars) 
{
	var titleBarHeight, windowBorderWidth
	titleBarHeight = 24
	windowBorderWidth = 4

	var screenWidth, screenHeight
	screenWidth = 800
	screenHeight = 600

	if (window.screen) 
	{
		if (window.screen.availWidth) 
		{
			// ok browser has the appropriate properties we need to centre it
			screenWidth = window.screen.availWidth
			screenHeight = window.screen.availHeight
		}
	}

	var windowWidth = windowBorderWidth + width + windowBorderWidth
	var windowHeight = titleBarHeight + height + windowBorderWidth

	var left = (screenWidth - windowWidth) / 2
	var top = (screenHeight - windowHeight) / 2

	if(lastWin&&!lastWin.closed)
	{
		lastWin.close()
	}
	lastWin = window.open(url,name,'left='+left+',top='+top+',screenX='+left+',screenY='+top+',width='+(parseInt(width,10)+10)+',height='+(parseInt(height,10)+10)+',scrollbars=1,resizable=0,toolbar=0,location=0,directories=0,status=0,menubar=0,copyhistory=0')
}

function ImagePopup(filename) 
{
	PopupScreenCentre("attachments/" + filename, "_blank", 780, 550, 0)
}




function makeRequest(url,returnFunction) 
// example usage: makeRequest(url + "&ajax=true", function(http_request) { PickerSetResultCallback(formName, fieldName, suffix, url, searchKeyword, http_request.responseText) })
{
	url += "&cachernd=" + Math.random()
	var http_request = false;
	if (window.XMLHttpRequest) { // Mozilla, Safari, ...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) 
		{
			http_request.overrideMimeType('text/xml');
			// See note below about this line
		}
	} else if (window.ActiveXObject) 
	{ // IE
		try 
		{
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) 
		{
			try 
			{
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}

	if (!http_request) {
		alert('Giving up :( Cannot create an XMLHTTP instance. You may need to adjust your ActiveX controls settings.');
		return false;
	}
	if (typeof(returnFunction)=="string") {
		//returnFunction = returnFunction + '(http_request)';
		returnFunc = function(http_request) { eval(returnFunction + "(http_request)") }
	} else {
		returnFunc = returnFunction
	}
	http_request.onreadystatechange = function() { 
		if (http_request.readyState == 4) {
			if (http_request.status == 200) {
				//eval(returnFunction) 
				returnFunc(http_request)
			} else if (http_request.status == 500) {
  	    alert('There was a problem with the request. http_request.status['+http_request.status+']');
  	    alert(http_request.responseText);
				//window.status = 'There was a problem with the request. http_request.status['+http_request.status+']1' 
			} else {
  	    alert('There was a problem with the request. http_request.status['+http_request.status+']');
				//window.status = 'There was a problem with the request. http_request.status['+http_request.status+']2'
			}
    }
	};
	if(true || url==prompt('call:',url)) 
	{
		http_request.open('GET', url, true);
		http_request.send(null);
	}
}
