// JavaScript Document
function addPageEventListener()
{
	if(window.addEventListener) 
	{
		if(typeof messageReceiveFunction =='function')
		{
			window.addEventListener('message',messageReceiveFunction,false);
		}
	} 
	else if(window.attachEvent) 
	{
		if(typeof messageReceiveFunction =='function')
		{
			window.attachEvent('onmessage', messageReceiveFunction);
		}
	}
}

function messageReceiveFunction(e)
{
	if(e.origin=='https://test.justonehotel.com' || e.origin=='https://www.justonehotel.com' || e.origin==undefined)//opera has data but undefined origin
	{
		checkMember(e.data.substring(4));
	}
}

function checkMember(info)
{
	//have to decode first because ie and ff behave differently
	membId = encodeURIComponent(decodeURIComponent(info));
	url = encodeURIComponent(decodeURIComponent(document.location.href));
	queryString = "eId="+membId;
	queryString +="&referrer="+url;
	myAjaxObj = new renamedAjax('/ajax/sessionRebuild.php', doNothing); 
	myAjaxObj.send('POST', queryString);
}

function doNothing(resp)
{
	if(resp!='') 
	{
		if(document.getElementById('welcome'))
		{document.getElementById('welcome').innerHTML = resp;}
		else if(document.getElementById('testWelcome'))
		{document.getElementById('testWelcome').innerHTML = resp;}
	}
}

function getUserInfo(value)
{
	if(	window.location.hash.substr(0,5)=='#:||:')
	{
		var val = window.location.hash.substring(5);
		if ( !value || value=='' )
		{
			value = '#';
		}
		window.location.hash = value;
		checkMember(val);
	}
}

//function clearMessage()
//{
//	if(window.location.hash.length>1)
//	{window.location.hash = '#';}
//}