// $Header: /work/cvs/funbrain/html/funbrain/brain/MathBrain/brain.js,v 1.6 2005/05/16 18:04:31 jkinney Exp $

// Return query string portion of given URL
// Apply prefix to return value only if return value not zero length
function fb_getqstr(url, prefix)
{
  var parsed = url.split('?');
  var qstr_parms = '';
  if (parsed.length > 1)
    qstr_parms = parsed[1];
  if (prefix.length == 0)
    return qstr_parms;

  if (qstr_parms.length > 1)
    return prefix + qstr_parms;

  return '';
}

// Generate code to embed Flash movie.
// Arguments are
//	Movie URL
//	Object attributes (generally width & height)
//	Background color
//      Opacity - set to opaque to allow Eyeblasters to be top layer
function fb_openFlash(movie, attr, bgcolor, opacity)
{
 var codebase = 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0';
 var pluginspage = 'http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash';

 document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"');
 document.write(' codebase="' + codebase + '" ' + attr + '>\n');
 document.write('<param name="movie" value="' + movie + '" />\n');
 document.write('<param name="quality" value="high">\n');
 document.write('<param name="bgcolor" value="' + bgcolor + '">\n');
 document.write('<param name="wmode" value="' + opacity + '">\n');
 document.write('<embed src="' + movie + '" quality="high" bgcolor="' + bgcolor + '" ' +
                  attr + 'type="application/x-shockwave-flash"' +
                  ' pluginspage="' + pluginspage + '">\n');
 document.write('</object>\n');
}

// Set up QueryString object
var fb_qstr = new Object();
fb_qstr.keys = new Array();
fb_qstr.values = new Array();

function fb_qstr_parse()
{
        var query = window.location.search.substring(1);
        var pairs = query.split("&");

        for (var i=0;i<pairs.length;i++)
        {
                var pos = pairs[i].indexOf('=');
                if (pos >= 0)
                {
                        var argname = pairs[i].substring(0,pos);
                        var value = pairs[i].substring(pos+1);
                        fb_qstr.keys[fb_qstr.keys.length] = argname;
                        fb_qstr.values[fb_qstr.values.length] = value;
                }
        }

}

// Get value from query string corresponding to given name
function fb_qstr_value(key)
{
	fb_qstr_parse();

        var value = null;
        for (var i=0;i<fb_qstr.keys.length;i++)
        {
                if (fb_qstr.keys[i]==key)
                {
                        value = fb_qstr.values[i];
                        break;
                }
        }
        return value;
}

// Allow for client 1x1 pixel tracking for games, brain game over logos, and specialized ads that can't do their own tracking
function loadTrackingPixel(URLtoTrigger)
{
	dcord = Math.random() * 100000000;
	dcpix = new Array();
	dcpix[0] = new Image();
	dcpix[0].src = URLtoTrigger + '?ord=' + dcord;
}
