// 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
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 WMODE="opaque" 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;
}

// Write cookies (triggered from Flash)
function writeCookie() {

 	var today = new Date();
 	var expire = new Date();

 	expire.setTime(today.getTime() + 3600000*24*14);

	for(i=0;i<writeCookie.arguments.length;i++) {
		ckThing = writeCookie.arguments[i] + '=' + writeCookie.arguments[i+1]
		i++
		document.cookie = ckThing + '; path=/; expires=' + expire.toGMTString()
	}
}


// Get cookies for a Flash piece
function getCookiesForFlash() {
	cookString = "?" 
	// does the visitor have a cookie? 
	if(document.cookie != "") {
		theCook = document.cookie.split("; ")
		// add each part of the cookie to a string variable
		for (i = 0; i < theCook.length; i ++) {
			cookString += theCook[i] + "&"
		}
	}
}