var url = "http://varldenidag.unity.se/popupPlayer.jsp";
var myWindow = null;
var backupWindow = null;
var url = null;
var popupCalledAutomatically = false;
var delay = 1000;

function openWindow(frameUrl, calledAutomatically) {
	url = frameUrl;
	if (myWindow == null)
	{
		if (calledAutomatically == true) {
			popupCalledAutomatically = true;
			backupWindow = window.open("http://varldenidag.unity.se/popupPlayer.jsp?framesrc="+url, null, "status = 1, height = 470, width = 840, resizable = 0" );
			var rem2 = backupWindow.document.getElementById("remoteid");
			if (rem2 == null)
				{
					timedCount2();
				} else {
					backupWindow.setFrameSrc(url);
					backupWindow.focus();
				}
			
			return;
		} else {
			myWindow=window.open("http://varldenidag.unity.se/popupPlayer.jsp?framesrc="+url, null, "status = 1, height = 470, width = 840, resizable = 0" );
		}	
	} else {
	}
	var rem = myWindow.document.getElementById("remoteid");
	if (rem == null)
	{
		timedCount();
	} else {
		myWindow.setFrameSrc(url);
		myWindow.focus();
	}
}
function clearWindow() {
	myWindow = null;
}
function timedCount()
{
	var rem = null;
	if (myWindow == null) 
		{}
	else {
		rem = myWindow.document.getElementById("remoteid");
	}
	
	if (rem == null)
	{
		t=setTimeout("timedCount()",delay);
	} else {
		if (myWindow == null) {
		} else {
			myWindow.setFrameSrc(url);
			myWindow.focus();
		}
	}
}
function timedCount2()
{
	var rem = null;
	if (backupWindow == null) {}
	else {
		rem = backupWindow.document.getElementById("remoteid");
	}
	
	if (rem == null)
	{
		t=setTimeout("timedCount2()",delay);
	} else {
		if (backupWindow == null) {
		} else {
			backupWindow.setFrameSrc(url);
			backupWindow.focus();
		
		}
	}
}
function popupLoadDone(resp) {
	
	if (myWindow == null)
	{
		if (popupCalledAutomatically == true) {
			popupCalledAutomatically = false;
			return;
		}
		openWindow(url, true);
	}
}