// Handling der Messages von Iframes

var webViewMessage = {};

webViewMessage.getOrigin = function()
{
	var o = window.location.href.split("/");
	switch (o[0])
	{
		case 'http:':
		case 'https:':
			return o[0] + "//" + o[2];
	}
	return null;
};

webViewMessage.post = function(targetWindow, message)
{
	try
	{
		//alert(webViewMessage.getOrigin() + "\r\n\r\n" + message);
		targetWindow.postMessage(message, webViewMessage.getOrigin());
	}
	catch(e)
	{
		alert('illegal target\r\n' + message);
	}
};

webViewMessage.postToSelf = function(message)
{
	webViewMessage.post(window, message);	
};
	
webViewMessage.postToParent = function(message)
{
	try
	{
		if (window.parent !== window)
		{
			//alert(typeof window.parent);
			webViewMessage.post(window.parent, message);
		}
		else
		{
			alert('target not found\r\n' + message);
		}
	}
	catch (e) 
	{
		alert('illegal target\r\n' + message);
	}
};
