function gl_ajax_dialog(id, title, url, transparent, options) {
	if ($(id)) {
		$(id).style.display = '';
		return;
	}
	
	//Default settings
	var width				= '350';
	var height				= '100';
	var xpos				= null;
	var ypos				= 150 + document.body.scrollTop;
	var draggable			= true;
	var modal				= true;
	
	if (options) {
		if (options['width'])
			width = options['width'];
		if (options['height'])
			height = options['height']; 
		if (options['left'] != null)
			xpos = options['left'] - 8;
		if (options['top'] != null)
			ypos = options['top'] - 7 + document.body.scrollTop;	
		if (options['modal'])
			modal = true;
		if (options['not_draggable'])
			draggable = false;
	} 
	
	var dialog				= document.createElement('div');
	dialog.id				= id;
	dialog.style.zIndex		= '11'; 
	dialog.style.padding	= '0px';
	dialog.style.position	= 'absolute';
	dialog.style.overflow	= 'visible';
	dialog.style.left = dialog.style.top = '0px';
	
	dialog.innerHTML = '<div id=' + dialog.id + '_window style="padding:0px;position:absolute;overflow:visible;">'
	
	+ '<table width="' + width + '" border="0" cellspacing="0" cellpadding="0" id="' + dialog.id + '_table" style="visibility:visible;display:none;position:absolute;">'
	+ '<tr>'
	+ '<td width="12" colspan="2"' + (transparent ? '' : ' class="calculator_border"') + '><img src="'+assess_dir_level()+'images/' + (transparent ? 'calculator_top_left_corner.png' : 'spacer.gif') + '" width="12" height="24" alt="" border="0"></td>'
	+ '<td width="' + (width-24) + '" align="center"' + (transparent ? ' background="'+assess_dir_level()+'images/calculator_top.png"' : ' class="calculator_border"') + '>'
	+ '<table width="' + (width-24) + '" border="0" cellspacing="0" cellpadding="0">'
	+ '<td align="left" id="' + dialog.id + '_drag_bar"' + (draggable ? ' style="cursor: move;"' : '') + ' class="calculator_title">' + title +'</td>'
	+ '<td align="right"><a href="javascript:void(0)" onClick="removeElement(\''+dialog.id+'\');" title="Close calculator window">' + (transparent ? '<img src="'+assess_dir_level()+'images/calculator_close_button.png" width="16" height="24" alt="Close" border="0">' : 'X') + '</a></td>'
	+ '</table>'
	+ '</td>'
	+ '<td width="12" colspan="2"' + (transparent ? '' : ' class="calculator_border"') + '><img src="'+assess_dir_level()+'images/' + (transparent ? 'calculator_top_right_corner.png' : 'spacer.gif') + '" width="12" height="24" alt="" border="0"></td>'
	+ '</tr>'
	+ '<tr>'
	+ '<td width="3"' + (transparent ? ' background="'+assess_dir_level()+'images/calculator_border_pixel.png"' : ' class="calculator_border"') + '><img src="'+assess_dir_level()+'images/spacer.gif" width="3" height="1" alt="" border="0"></td>'
	+ '<td width="9" style="background-color:#eeeeee;"><img src="'+assess_dir_level()+'images/spacer.gif" width="9" height="1" alt="" border="0"></td>'
	+ '<td width="' + (width-24) + '" id="' + dialog.id + '_content" style="padding-top:9px;padding-bottom:9px;background-color:#eeeeee;">'
	
	+ '</td>'
	+ '<td width="9" style="background-color:#eeeeee;"><img src="'+assess_dir_level()+'images/spacer.gif" width="9" height="1" alt="" border="0"></td>'
	+ '<td width="3"' + (transparent ? ' background="'+assess_dir_level()+'images/calculator_border_pixel.png"' : ' class="calculator_border"') + '><img src="'+assess_dir_level()+'images/spacer.gif" width="3" height="1" alt="" border="0"></td>'
	+ '</tr>'
	+ '<tr>'
	+ '<td id="modal_window_bottom" width="' + width + '" colspan="5"' + (transparent ? ' background="'+assess_dir_level()+'images/calculator_border_pixel.png"' : ' class="calculator_border"') + '><img src="'+assess_dir_level()+'images/spacer.gif" width="1" height="3" alt="" border="0"></td>'
	+ '</tr>'
	+ '</table>'
	+ '</div>';
	
	if (modal) {
		dialog.style.backgroundImage = "url('"+assess_dir_level()+"images/spacer.gif')";
		dialog.style.width = dialog.style.height = '95%';
	}
	
	document.body.appendChild(dialog);
	
	function showDialogue() {
		
		$(dialog.id + '_table').style.visibility = 'hidden';
		$(dialog.id + '_table').style.display = '';
		
		$(dialog.id + '_table').style.left = getXPos('be_somebody_picture')+300+'px';
		var h;
		if (window.innerHeight) {
			h = parseInt(window.innerHeight);
		} else {
			h = parseInt(document.body.clientHeight);
		}
		$(dialog.id + '_table').style.top = (((h - parseInt($(dialog.id + '_table').offsetHeight))/2) + parseInt(document.body.scrollTop))+'px';
		$(dialog.id + '_table').style.display = 'none';
		$(dialog.id + '_table').style.visibility = 'visible';
		
		$(dialog.id + '_table').appear({ duration: 0.25 });
		
		if (draggable)
			new Draggable(dialog.id + '_window', {handle: dialog.id + '_drag_bar', starteffect: null, endeffect: null});
		
	}
	
	if (!url) {
		showDialogue();
		return;
	}
	
	new Ajax.Updater(dialog.id + '_content', url, { method: 'get', parameters: 'popup=' + dialog.id + '&destination=' + dialog.id + '_content', evalScripts: true, 
						 onComplete: function () {
							showDialogue();
						 }});
}

var detect = navigator.userAgent.toLowerCase();
var browser,thestring;

function getBrowser() {
	if (checkIt('msie') || checkIt('internet explorer')) {
		browser = "IE";
	} else if (!checkIt('compatible') || checkIt('firefox')) {
		browser = "Mozilla";
		if (checkIt('firefox'))
			browser = "Firefox";
	} else {
		browser = "Unknown";
	}
	return browser;
}

function checkIt(string) {
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}

function removeElement(e) {
	var a = isArray(e) ? e : [e];
	for (var i = 0; i < a.length; i++) {
		if (!isObject(a[i])) {
			a[i] = $(a[i]);
			if (!isObject(a[i]))
				continue;
		}
		if (a[i].parentNode)
			a[i].parentNode.removeChild(a[i]);
	}
}

function isArray (a) {
	if (typeof(a) == "object")
		return (is_numeric(a.length));
	return false;
}

function isObject(a) {
	return (typeof(a) == "object");
}

// get positions of elements
function getXPos(imgID) {
	return getRealLeft(imgID);
	//if not using IE
	if (getBrowser()!="IE") return $(imgID).x;
	else return getRealLeft(imgID);//else, using Internet explorer
}

function getYPos(imgID) {
	return getRealTop(imgID);
	if (getBrowser()!="IE") return $(imgID).y;
	else return getRealTop(imgID);
}

// position detection in IE
function getRealLeft(imgElem) {
	var el = isObject(imgElem) ? imgElem : $(imgElem);
	if (!el)
		return;
	xPos = el.offsetLeft;
	tempEl = el.offsetParent;
	while (tempEl != null) {
		xPos += tempEl.offsetLeft;
		tempEl = tempEl.offsetParent;
	}
	return xPos;
}

function getRealTop(imgElem) {
	var el = isObject(imgElem) ? imgElem : $(imgElem);
	yPos = el.offsetTop;
	tempEl = el.offsetParent;
	while (tempEl != null) {
		yPos += tempEl.offsetTop;
		tempEl = tempEl.offsetParent;
	}
	return yPos;
} 

function submit_form(which_form, destination, actn) {
	var params = '';
	for(x=0;x<document.forms[which_form].elements.length;x++) {
		params += document.forms[which_form].elements[x].name + '=' + escape(document.forms[which_form].elements[x].value) + '&';
	}
	params += 'destination='+destination;
	new Ajax.Updater(destination, actn, { method: 'get', parameters: params, evalScripts: true});
}