function popupRSVP(eventid)
{
	$('rsvp_box').style.left = (document.body.clientWidth / 2 - 150) + "px";
	$('rsvp_box').style.display = "";
	$('document_modal').style.display = "";
	$('rsvp_eventid').value = eventid;
}

function hideRSVP()
{
	$('rsvp_box').style.display = "none";
	$('document_modal').style.display = "none";
}

function RSVP_list(id)
{
	var realBaseUrlWww = location.protocol + '//www.' + location.host + location.pathname + '?';
	
	/* Normal Base URL which PHP uses */
	var	baseUrl = ipb.vars['base_url'] + '&app=events&module=ajax&section=coreAjax&secure_key=' + ipb.vars['secure_hash'] + '&';
	
	var rsvp_status = "no";
	
	new Ajax.Request( baseUrl + 'type=rsvp_list',
		{
			method: 'post',
			encoding: ipb.vars['charset'],
			parameters: {
				eventid:	id
			},
			onSuccess: function(s)
			{
				$('rsvp').innerHTML = s.responseText;
			}
		}
	);
}

function RSVP()
{
	var realBaseUrlWww = location.protocol + '//www.' + location.host + location.pathname + '?';
	
	/* Normal Base URL which PHP uses */
	var	baseUrl = ipb.vars['base_url'] + '&app=events&module=ajax&section=coreAjax&secure_key=' + ipb.vars['secure_hash'] + '&';
	
	var rsvp_status = "no";
	
	if($('rsvp_status_yes').checked == 1) 
		rsvp_status = "yes";
	else if($('rsvp_status_maybe').checked == 1) 
		rsvp_status = "maybe";
	
	new Ajax.Request( baseUrl + 'type=rsvp',
		{
			method: 'post',
			encoding: ipb.vars['charset'],
			parameters: {
				eventid:	$('rsvp_eventid').value,
				status:		rsvp_status,
				comment:	$('rsvp_comment').value
			},
			onSuccess: function(s)
			{
				//alert( s.responseText );
				switch_tabs(5);
				RSVP_list($('rsvp_eventid').value);
				$('unrsvp').style.display = "";
			}
		}
	);
}

function removeRSVP(userid)
{
	
	var realBaseUrlWww = location.protocol + '//www.' + location.host + location.pathname + '?';
	
	/* Normal Base URL which PHP uses */
	var	baseUrl = ipb.vars['base_url'] + '&app=events&module=ajax&section=coreAjax&secure_key=' + ipb.vars['secure_hash'] + '&';
	
	if( confirm( "Are you sure you want to Un-RSVP?" ) )
	{
		new Ajax.Request( baseUrl + 'type=unrsvp',
			{
				method: 'post',
				encoding: ipb.vars['charset'],
				parameters: {
					eventid:	$('rsvp_eventid').value,
					userid:		userid
				},
				onSuccess: function(s)
				{
					//alert( s.responseText );
					switch_tabs(5);
					RSVP_list($('rsvp_eventid').value);
					$('unrsvp').style.display = "none";
					hideRSVP();
				}
			}
		);
	}
}

function switch_tabs(tabID) 
{
	//THESE ARE ALL THE TABS, Gamma o.0
	$('info').style.display = "none";
	$('location').style.display = "none";
	$('games').style.display = "none";
	$('faq').style.display = "none";
	$('rsvp').style.display = "none";
	$('info_tab').setAttribute("class", "");
	$('location_tab').setAttribute("class", "");
	$('games_tab').setAttribute("class", "");
	$('faq_tab').setAttribute("class", "");
	$('rsvp_tab').setAttribute("class", "");
	switch(tabID) 
	{
		case 1:
			$('info').style.display = "";
			$('info_tab').setAttribute("class", "active");
			break;
		case 2:
			$('location').style.display = "";
			$('location_tab').setAttribute("class", "active");
			break;
		case 3:
			$('games').style.display = "";
			$('games_tab').setAttribute("class", "active");
			break;
		case 4:
			$('faq').style.display = "";
			$('faq_tab').setAttribute("class", "active");
			break;
		case 5:
			$('rsvp').style.display = "";
			$('rsvp_tab').setAttribute("class", "active");
			break;
	}
}