var myPopupWindow = '';

function encodeUrl(url)
{
	if (url.indexOf("?")>0)
	{
		encodedParams = "?";
		parts = url.split("?");
		params = parts[1].split("&");
		for(i = 0; i < params.length; i++)
		{
			if (i > 0)
			{
				encodedParams += "&";
			}
			if (params[i].indexOf("=")>0) //Avoid null values
			{
				p = params[i].split("=");
				encodedParams += (p[0] + "=" + escape(encodeURI(p[1])));
			}
			else
			{
				encodedParams += params[i];
			}
		}
		url = parts[0] + encodedParams;
	}
	return url;
}

function openPopupWindow(url, name, width, height)
{
	//Remove special characters from name
	name = name.replace(/\/|\-|\./gi, "");

	//Remove whitespaces from name
	var whitespace = new RegExp("\\s","g");
	name = name.replace(whitespace,"");

	//If it is already open
	if (!myPopupWindow.closed && myPopupWindow.location)
	{
		myPopupWindow.location.href = encodeUrl(url);
	}
	else
	{
		myPopupWindow= window.open(encodeUrl(url),name, "location=no, scrollbars=no, resizable=no, toolbar=no, menubar=no, width=" + width + ", height=" + height );
		if (!myPopupWindow.opener) myPopupWindow.opener = self;
	}

	 //If my main window has focus - set it to the popup
	if (window.focus) {myPopupWindow.focus()}
}

function speelonline(){
	//openPopupWindow('http://www.arendi.be/games/kassa.swf','Magic Dice', 1000, 690);
	//openPopupWindow('http://www.arendi.be/games/lob.html','Magic Dice', 1000, 690);
	openPopupWindow('http://online.magicdice.be/','Magic Dice Online', 1000, 690, 'left = 460, top = 195');
	return false;
}
