// ############################################
// variable used by all xmlHTTPRequest object calls
var httpReq;
// ############################################

function OnGiftSelect(giftId)
{
	//alert("OnGiftSelect param = "+giftId);
	if (giftId.length == 0)	{ return; }
	// prepare a call to the server to set this gift id into the php $_SESSION 
	// Also to read the Gift record and return formatted html to be placed into
	// the center section of the register1 page.
	
	httpReq = getNewHTTPObject();
	
	if (httpReq==null)	{
		alert (browser_support);
		return;
	}

	var strFunctionCall = generateURL('/ajax/reg1.php');
	var param = 'giftId=' + escape(giftId);
    httpReq.open('POST', strFunctionCall, true);
    httpReq.onreadystatechange = handleOnGiftSelect;
	httpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    httpReq.send(param);
	return;
}

function handleOnGiftSelect() {
	if (httpReq.readyState==4) { 
		var strResponse = httpReq.responseText;
		if (strResponse.length == 0 ) {
			alert("ERROR");
		}
		// blank out the initial state
		document.getElementById('init_state').innerHTML = '';
		// add reminder if gift not yet selected
		if (document.getElementById('RoomBlock').innerHTML == '') {
			document.getElementById('DontForget').innerHTML = '<div id="midcol_arrows"><img src="images/PickRoomArrow.png" alt="Select a pokerroom" /></div>';
		}
		else {
			document.getElementById('DontForget').innerHTML = '';
		}
		document.getElementById('GiftBlock').innerHTML = strResponse;		
	}
}

function OnRoomSelect(roomId)
{
	if (roomId.length == 0)	{ return; }
	// prepare a call to the server to set this room id into the php $_SESSION 
	// Also to read the Room record and return formatted html to be placed into
	// the center section of the register1 page.
	
	httpReq = getNewHTTPObject();
	
	if (httpReq==null) {
		alert (browser_support);
		return;
	}

	var strFunctionCall = generateURL('/ajax/reg1.php');
	var param = 'roomId=' + escape(roomId);
    httpReq.open('POST', strFunctionCall, true);
    httpReq.onreadystatechange = handleOnRoomSelect;
	httpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    httpReq.send(param);
	return;
}

function handleOnRoomSelect() {
	if (httpReq.readyState==4) { 
		var strResponse = httpReq.responseText;
		if (strResponse.length == 0 ) {
			alert("ERROR");
		}
		// blank out the initial state
		document.getElementById('init_state').innerHTML = '';
		// add reminder if gift not yet selected
		if (document.getElementById('GiftBlock').innerHTML == '') {
			document.getElementById('DontForget').innerHTML = '<div id="midcol_arrows"><img src="images/PickGiftArrow.png" alt="Select a pokerroom" /></div>';
		}
		else {
			document.getElementById('DontForget').innerHTML = '';
		}
		document.getElementById('RoomBlock').innerHTML = strResponse;
		enableTooltips('RoomBlock','div','tipdata');
	}
}