// Allow a communications check with flash.external.ExternalInterface
function ping(token) {
	return token;
}

// Stretch the specified flash object by setting its height and width to 100%.
function stretchFlashObject(id) {
	// stretching means setting the flash container's dimensions to 100%
	var stretch= function(elem) {
		elem.setAttribute('width','100%');
		elem.setAttribute('height','100%');		
	}
	// look for an <object> with this id
	var obj= document.getElementById(id);
	if(null != obj) {
		// check that this is an 'object' element
		if(obj.tagName.toLowerCase() != 'object') {
			alert("stretchFlashObject: expected <object>, found <" + obj.tagName + ">");
			return;
		}
		stretch(obj);
	}
	// look for <embed> elements with src="<id>.swf"
	var embeds= document.getElementsByTagName('embed');
	for(var index= 0; index < embeds.length; index++) {
		var embed= embeds[index];
		if(embed.getAttribute('src') == id+'.swf') stretch(embed);
	}
}

// Return the query string appended to the current page's URL, if any
function getUrlQuery() {
	var query= window.location.search;
	// remove a leading '?'
	return (0 == query.length) ? query : query.substr(1);	
}

// Open a new window. The available features are documented at
// http://www.devguru.com/Technologies/ecmascript/quickref/win_open.html
var overlay= null;
var windowParams= null;
function hideOverlay() {
	if(null != overlay) overlay.style.display= 'none';
	window.focus();
}
function openWindowNow() {
	window.open(windowParams['url'],windowParams['name'],windowParams['features']);
	hideOverlay();
}
function openWindow(url,name,features,prompt) {
	// the following won't work because it triggers popup blockers
	//window.open(url,name,features);
	// instead, we need the user to trigger the new window via direct (non-flash) input
	windowParams= { url: url, name: name, features: features };
	if(null == overlay) {
		overlay= document.createElement('div');
		overlay.style.position= 'fixed';
		overlay.style.left= '0px';
		overlay.style.top= '0px';
		overlay.style.width= '100%';
		overlay.style.height= '100%';
		overlay.style.backgroundColor= '#171717';
		
		var inputStrip= document.createElement('div');
		inputStrip.style.position= 'absolute';
		inputStrip.style.bottom= '48px';
		inputStrip.style.left= '0px';
		inputStrip.style.width= '100%';
		inputStrip.style.padding= '16px 0';
		inputStrip.style.backgroundColor= '#ccc';
		inputStrip.style.color= '#171717';
		inputStrip.style.textAlign= 'center';
		inputStrip.style.fontFamily= '"Arial Black","Helvetica",arial,sans-serif';
		inputStrip.style.cursor= 'default';
		inputStrip.innerHTML= '<div>' + prompt + '</div>';

		var okDiv= document.createElement('div');
		okDiv.style.margin= '8px 0';
		okDiv.style.cursor= 'pointer';
		okDiv.innerHTML= 'ok';
		okDiv.onclick= openWindowNow;
		inputStrip.appendChild(okDiv);

		var cancelDiv= document.createElement('div');
		cancelDiv.style.margin= '8px 0';
		cancelDiv.style.cursor= 'pointer';
		cancelDiv.innerHTML= 'cancel';
		cancelDiv.onclick= hideOverlay;
		inputStrip.appendChild(cancelDiv);

		overlay.appendChild(inputStrip);
		document.body.appendChild(overlay);
	}
	else {
		overlay.style.display= 'block';
	}
}

// Set the location of the current window
function setLocation(url) {
	window.location= url;
}
