
function receiveMessage(event){
	data = event.data;
	if(!event.data.hasOwnProperty("username")){
		return
	}
		
	
    name_div = document.getElementById("logged_in_as");
    name_div.innerHTML = "<b>Welcome: </b>" + data.username;
    messages_div = document.getElementById("messages");
    messages = data.messages;
    msg_length = messages.length;
    var msg_html = "";
    for (var i = 0; i < msg_length; i++) {
        message = messages[i];
        msg_html += "<h2>" + message['title'] + "</h2>";
        msg_html += message.message;
    }
    messages_div.innerHTML = msg_html;	// Write messages to the page
}
window.addEventListener("message", receiveMessage, false);
