function URLEncode(url) {
	if (url.indexOf("%") >= 0 || url.indexOf("+") >= 0) {
		return url;
	}

	var SAFECHARS = "0123456789" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz" + "-_.!~*'()";
	var HEX = "0123456789ABCDEF";		
	var encoded = "";
	for (var i = 0; i < url.length; i++) {
		var ch = url.charAt(i);
		if (ch == " ") {
			encoded += "+";
		} else if (SAFECHARS.indexOf(ch) != -1) {
			encoded += ch;
		} else {
			var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	}		
	return encoded;
}

function nwrOndemand() {
	var args = nwrOndemand.arguments;
	if (args.length >= 2) {
		var seekable = true;
		var title = (args[0] != null && args[0] != 'null' && args[0] != '') ? args[0] : null;
		var moreInfo = (args[1] != null && args[1] != 'null' && args[1] != '') ? args[1] : null;
		var streamSrc = args[2];

		var url = "http://www.nwrweb.com/player/show/metro.tv.se/ondemand";
		url += "?ondemand=" + URLEncode(streamSrc);
		url += "&ondemandSeekable=true";
		//if (seekTo > 0) url += "&ondemandSeekTo=" + seekTo;
		if (title != null) url += "&ondemandTitle=" + URLEncode(title);
		if (moreInfo != null) url += "&ondemandMoreInfo=" + URLEncode(moreInfo);

		var player = window.open(url, "NWRPlayer", "width=537,height=424,scrollbars=no,resizable=no");
		player.focus();

	}
}

function openPlayer() {
	var args = openPlayer.arguments;
	var url = "http://www.nwrweb.com/player/show/metro.radio.se/";
	if (args.length > 0)
		url += args[0];
	var player = window.open(url, "NWRPlayer", "width=537,height=424,scrollbars=no,resizable=no");
	player.focus();
}