if (xhr_enabled()) {

	function addNameList(ido){
		var popup = jQuery('#namelist-popup');
		
		// ie6 can't handle 'fixed' so use 'absolute'
		var IE6 = false /*@cc_on || @_jscript_version < 5.7 @*/;
		var position = IE6 ? 'absolute' : 'fixed';
		
		if (popup.length == 0) {
			jQuery.ajax({
				type: 'GET',
				//contentType: 'text/html',
				url: '/Names/namelist_pop.php',
				cache: false,
				dataType: 'text',
				data: {id: ido},
				success: function(data) {
					// check for login error
					//alert(data);
					if (data == 'LOGIN_ERROR') {
						// redirect to login page
						window.location.href = '/user/login.php?id=' + ido;
						return;
					}
	
					// otherwise, html is the popup contents
					jQuery('<div id="namelist-popup"></div>').html(data).css({
						position: position,
						top: '250px',
						left: Math.max(0, (window.innerWidth || document.body.clientWidth) - 240),
						width: '200px',
						cursor: 'move',
						'z-index': 10000
					}).draggable({
						// need to maintain fixed positioning
						start: function(){
							jQuery('#dragHelper').css('position', position);
						},
						stop: function(){
							jQuery(this).css('position', position);
						},
						cancel: 'div.namelist-scroll'
					}).appendTo('body');
					namelist_pop_scroll();
				},
				error: function(xhr, status, error) {
					alert('status: '+status+"\nxhr.status: "+xhr.status);//+"\nresponseText:"+xhr.responseText);
				}
			});
		}
		else {
			// get the info for that name ID, and add to namelist in the background
			jQuery.ajax({
				dataType: 'json',
				cache: false,
				type: 'GET',
				contentType: "application/json",
				url: '/_assets/inc/namelist_ajax.php', 
				data: { method: 'addNameByID', id: ido }, 
				success: function(data){
					if (data.nid == parseInt(data.nid)) {
						// add row to the table
						var table = jQuery('.namelist-table', popup);
						
						if (data.gender == 'F') 
							var classColor = 'girlpink';
						else if (data.gender == 'M') 
							var classColor = 'boyblue';
						else 
							var classColor = 'either';
						
						var row = jQuery('<tr></tr>').addClass(classColor).appendTo(table);
						jQuery('<td></td>').text(data.name).appendTo(row);
					}
					jQuery('#namelist-msg').html(data.msg);
					namelist_pop_scroll();
				}
			});
		}
	}
	
	function namelist_pop_scroll() {
		var th = $('table.namelist-table').outerHeight();
		var sh = $('div.namelist-scroll').innerHeight();
		if (th>sh) $('div.namelist-scroll').scrollTop(th-sh);
	}
	
	function namelist_pop_close(){
		jQuery('#namelist-popup').remove();
		return false;
	}
	
} // xhr_enabled
