// Gets the current href
var currentHref = window.location.href;
var lastBackslashIndex = currentHref.lastIndexOf("/");
if (lastBackslashIndex != -1)
{
	if (lastBackslashIndex < currentHref.length - 1)
	{
		currentHref = currentHref.substring(lastBackslashIndex + 1,  currentHref.length);
	} 
}

var targetUID = null;

// Performs a check if we are at a user profile page
var profilePageStr = "profile.php?id=";
var profilePageStrIndex = currentHref.indexOf(profilePageStr);
if (profilePageStrIndex != -1)
{
	var uidEndIndex = currentHref.indexOf("&", profilePageStrIndex + profilePageStr.length);
	if (uidEndIndex != - 1)
	{
		if (currentHref.indexOf("&v=") == uidEndIndex)
		{
			if (currentHref.indexOf("&v=feed") == uidEndIndex)
			{
				targetUID = currentHref.substring(profilePageStrIndex + profilePageStr.length, uidEndIndex);
			}
		}
		else
		{
			targetUID = currentHref.substring(profilePageStrIndex + profilePageStr.length, uidEndIndex);
		}
	}
	else
	{
		targetUID = currentHref.substring(profilePageStrIndex + profilePageStr.length, currentHref.length);
	}
}
else
{
	// Performs another check if we are at a user profile page
	if (currentHref.indexOf(".php") == -1)
	{
		var uidEndIndex = currentHref.indexOf("?");
		if (uidEndIndex != - 1)
		{
			if (currentHref.indexOf("?v=") == uidEndIndex)
			{
				if (currentHref.indexOf("?v=feed") == uidEndIndex)
				{
					targetUID = currentHref.substring(0, uidEndIndex);
				}	
			}
			else
			{
				targetUID = currentHref.substring(0, uidEndIndex);
			}
		}
	}
}

var result = null;
if (targetUID != null)
{
    var elements = document.getElementsByName('message');
    if (elements)
    {
        if (elements.length > 0)
        {
            var message = elements[0];
            if (message)
            {
                // Modifies the page with events
                message.onfocus = function()
                                {
                                    scroll(0, 146);
                                    window.location.href="fbevent://composeWallPostTouchedForUID=" + targetUID;
                                };
                result = targetUID;
            }
        }
    }
	
}
result;