//--------------------------------------------------------------
function invite_accept(id,id_challenge,LC_ROOT,wnd) {
	document.getElementById('invite_'+id).innerHTML='';
	var xmlhttp = CreateXmlHttpReq(XmlHttpHandler);
	XmlHttpPOST(xmlhttp, '/de/invitation.php','action=delete&id='+id);
	betroom_come(id_challenge,'challenge_list', wnd, LC_ROOT);
	block_invite_resresh=1;
}
//--------------------------------------------------------------
function invite_accept_termin(id,id_challenge) {
	document.getElementById('invite_'+id).innerHTML='';
	var xmlhttp = CreateXmlHttpReq(XmlHttpHandler);
	XmlHttpPOST(xmlhttp, '/de/invitation.php','action=delete&id='+id);
	window.location.href='/de/challengelist_termininfo.php?id='+id_challenge;
}
//--------------------------------------------------------------
function invite_team_accept(id) {
	window.location.href='/de/invitation.php?action=invite_team_accept&id='+id;
}
//--------------------------------------------------------------
function invite_tournament_team_accept(id) {
	window.location.href='/de/invitation.php?action=invite_tournament_team_accept&id='+id;
}
//-----------shared for all type of invitations-----------------
function invite_reject(id) {
	document.getElementById('invite_'+id).innerHTML='';
	var xmlhttp = CreateXmlHttpReq(XmlHttpHandler);
	XmlHttpPOST(xmlhttp, '/de/invitation.php','action=delete&id='+id);
	block_invite_resresh=1;
}
//--------------------------------------------------------------
function invite_term_accept(id_challenge) {
	document.getElementById('invite_'+id_challenge).innerHTML='';
	var xmlhttp = CreateXmlHttpReq(XmlHttpHandler);
	XmlHttpPOST(xmlhttp, '/de/invitation.php','action=termin_accept&id_challenge='+id_challenge);
	block_invite_resresh=1;
}
//--------------------------------------------------------------
function invite_term_reject(id_challenge) {
	document.getElementById('invite_'+id_challenge).innerHTML='';
	var xmlhttp = CreateXmlHttpReq(XmlHttpHandler);
	XmlHttpPOST(xmlhttp, '/de/invitation.php','action=termin_reject&id_challenge='+id_challenge);
	block_invite_resresh=1;
}
//--------------------------------------------------------------
var xmlhttp_invite_busy=null;
var xmlhttp_invite=null;
var xmlhttp_invite_timeout=null;
var block_invite_resresh=null;
var content_length_last=0;

// Time wait for invite from user
var invite_checker=16000;
//--------------------------------------------------------------
function invite_checking_handler() {
	clearTimeout(xmlhttp_invite_timeout);
	xmlhttp_invite_timeout=setTimeout('run_invite_checking()', invite_checker);
	if (xmlhttp_invite.readyState != 4 || xmlhttp_invite.status != 200) {
		return;
	}
	xmlhttp_invite_busy=null;
	if (block_invite_resresh) {
		block_invite_resresh=0;
		return;
	}
	var responseHeader = xmlhttp_invite.getAllResponseHeaders();
	var content=xmlhttp_invite.responseText;
	if (content_length_last!=content.length) {
		var xml = xmlhttp_invite.responseXML.documentElement;
		if (xml == null) return;
		if (document.getElementById('invite_area'))
		document.getElementById('invite_area').innerHTML=xml.childNodes[0].firstChild.nodeValue;
		if (document.getElementById('actual_challenges_area'))
		document.getElementById('actual_challenges_area').innerHTML=xml.childNodes[1].firstChild.nodeValue;
		content_length_last=content.length;
	}

	var start_betroom = parseResponseHeader("start_betroom", responseHeader);
	if (start_betroom==1)
	{
		var termin_id_challenge = parseResponseHeader("termin_id_challenge", responseHeader);
		var wnd = parseResponseHeader("wnd", responseHeader);
		var LC_ROOT = parseResponseHeader("LC_ROOT", responseHeader);

		betroom(termin_id_challenge,LC_ROOT);
		//		betroom_come(termin_id_challenge,'challenge_list',wnd,LC_ROOT);
	}

	var start_other_betroom = parseResponseHeader("start_other_betroom", responseHeader);
	if (start_other_betroom==1)
	{
		var termin_id_challenge = parseResponseHeader("termin_id_challenge", responseHeader);
		var wnd = parseResponseHeader("wnd", responseHeader);
		var LC_ROOT = parseResponseHeader("LC_ROOT", responseHeader);

		//		betroom(termin_id_challenge,LC_ROOT);
		betroom_come(termin_id_challenge,'challenge_list',wnd,LC_ROOT);
	}
}

function run_invite_checking()
{
	xmlhttp_invite_busy=1;
	xmlhttp_invite = CreateXmlHttpReq(invite_checking_handler);
	XmlHttpPOST(xmlhttp_invite, '/de/invitation.php','');
}
run_invite_checking();
