function hyvesAuth()
{
	shareHash = Math.round(((new Date()).getTime()-Date.UTC(1970,0,1))/1000);
	window.open('http://217.67.248.105/~babyverg/hyvesAuth.php?shareHash=' + shareHash, 'windowpopup', 'width=500, height=400, toolbar=false');
	getShareData(shareHash);
}

function hyvesAuthResult( hyvesToken, userId )
{
	$$('#bc_viewer')[0].hyvesAuthResult( hyvesToken, userId );
}

function authorizeFB() {
	shareHash = Math.round(((new Date()).getTime()-Date.UTC(1970,0,1))/1000);
	window.open('http://217.67.248.105/~babyverg/authorizefb/index.php?shareHash=' + shareHash, 'windowpopup', 'width=800, height=600, toolbar=false');
	getShareData(shareHash);
}

function authorizeFBResult() {
	$$('#bc_viewer')[0].authorizeFBResult();
}

function getShareData(shareHash) {
	$.get('http://217.67.248.105/~babyverg/getShareData.php?shareHash='+ shareHash, function(data) {
		if (data == "")
		{
			setTimeout("getShareData(shareHash);",2000);
		}
		else {
			if (data.hyvesId == 0)
			{
				authorizeFBResult();
			}
			else
			{	
				token = data.hyvesToken.replace('%-', '=');
				hyvesAuthResult( token, data.hyvesId );
			}
		}
	});
}

function openTAFMailPreview()
{
	window.open('http://217.67.248.105/~babyverg/mailpreview.html', 'preview', 'status=1,toolbar=0,location=0,menubar=0,directories=0,resizable=0,scrollbars=1,height=640,width=640');
}
