var $ = glow.dom.get;

function validate_email(email) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)) {
		return true;
	}
	alert("Please make sure you have entered a valid email address.");
	return false;
}

function empDivReady(width, objId, skin, playlist, path) {
	var emp,
		height;
	var aIgnorePaths = [
			escape("http"),
			escape("/iplayer")
		],
		bPrependPath = true,
		sPlaylistURL;
	switch(width) {
		case "512":
			height = "323";
			break;
		case "448":
			height = "287";
			break;
		case "256":
			height = "179";
			break;
		default:
			return;
	}

	for (i = 0; i < aIgnorePaths.length; i++) {
		if(playlist.indexOf(aIgnorePaths[i]) == 0) { bPrependPath = false; }
	}
	sPlaylistURL = ((bPrependPath)? path + "/media/emp/playlists/" : "") + playlist + ((bPrependPath)? ".xml" : "");
	
	emp = new glow.embed.Flash(empUrl, "#"+objId, empFlashReq, {
		width: width+"px",
		height: height+"px",
		params: {
			flashVars:	{
				playlist: sPlaylistURL,
				config_settings_skin: skin
			}
		},
		message: function() {
			var p = navigator.platform.toLowerCase();
			if (p.indexOf("win") || p.indexOf("mac") || p.indexOf("linux")) {	// Is Desktop OS?
				return "In order to see this video, you must have <a href=\"/webwise/askbruce/articles/download/howdoidownloadflashplayer_1.shtml\">Flash 9</a> or greater installed.  Visit BBC Webwise for full instructions.";
			}
			else if (p.indexOf("wii") || p.indexOf("playstation") || p.indexOf("iphone")) {	// Is iPlayer supported Device
				return "Sorry, you are trying to view this video on a device which requires a special video format. We are unable to supply that format on this site at the moment, but BBC video for your device can be viewed at <a \"/iplayer/\">BBC iPlayer</a>.";
			}
			else {	// Unsupported Device
				return "Sorry, you are trying to view this video on a device which requires a special video format. Unfortunately, we are unable to supply that format on this site at the moment.";
			}
		}
	});
	emp.embed();
}