if( typeof XMLHttpRequest == "undefined" ) XMLHttpRequest = function() {
	try { return new ActiveXObject("Msxml2.XMLHTTP.6.0") } catch(e) {}
	try { return new ActiveXObject("Msxml2.XMLHTTP.3.0") } catch(e) {}
	try { return new ActiveXObject("Msxml2.XMLHTTP") } catch(e) {}
	try { return new ActiveXObject("Microsoft.XMLHTTP") } catch(e) {}
	throw new Error( "This browser does not support XMLHttpRequest." )
};

var attendkey = false;
var attendselecteddiv = '';
var attendcurid = '';

String.prototype.trim = function() {
	var x=this;
	x=x.replace( /^\s*/, "" );
	x=x.replace( /\s*$/, "" );
	return x;
}


function attendeesLoadContent(id) {	
	attendkey = id;

	loadContentAttendees();
	attendcurid = id;
}

var insert_url2 = shoutbox_showurl + 'insert_attendee.php';
var load_url2 = shoutbox_showurl + 'fetch_attendees.php';
var remove_url2 = shoutbox_showurl + 'remove_attendee.php';

function ajax2(url, data) {
	var request = new XMLHttpRequest();
	request.open("POST", url, true);

	request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

	request.onreadystatechange = function(){
		if(request.readyState == 4){
			// Get the data from the server's response

			if ( request.responseText != '' ) {
				// update the shoutbox thread
				
				document.getElementById('attendees-box-content').innerHTML = request.responseText;
			}
			else {
				// display the javascript error
				alert( 'There was an error sending the add request... please re-load the page and try again.' );
			}
		}
	}

	request.send(data);
}

function loadContentAttendees() {

	var limit = document.attendeesForm.limit.value;
	
	postdata2 = 'key=' + attendkey;
	
	if ( limit != '' ) {
		postdata2 = postdata2 + '&limit=' + limit;
	}
	
	ajax2( load_url2, postdata2 );
}

function addAttendee() {

	var pid = document.attendeesForm.pid.value;

	postdata='key=' + attendkey;

	if ( pid != '' ) {
	      postdata = postdata + '&pid=' + pid;
	}
	
	
	var limit = document.attendeesForm.limit.value;
	
	if ( limit != '' ) {
		postdata = postdata + '&limit=' + limit;
	}
	
	ajax2( insert_url2, postdata );

	return false;
}

function removeAttendee() {
	// do nothing
	
	var pid = document.attendeesForm.pid.value;

	if ( pid == '' ) {
		pid = '0';
	}

	postdata='key=' + attendkey;

	postdata = postdata + '&pid=' + pid;

	
	var limit = document.attendeesForm.limit.value;
	
	if ( limit != '' ) {
		postdata = postdata + '&limit=' + limit;
	}
		
	ajax2( remove_url2, postdata );

	return false;
}
