/*
	adcFlashMovie v1.0
		features: Outputs necessary HTML, detects flash player, and avoids Microsofts patent settlement solution.
*/
function adcFlash() {
	// sets defaults
	this.src = false;
	this.width = false;
	this.height = false;
	this.quality = false;
	this.scale = false;
	this.align = false;
	this.salign = false;
	this.wmode = false;
	this.bgcolor = false;
	this.id = false;
	this.version = 5;
	this.swliveconnect = true;
	this.play = true;
	this.loop = true;
	this.menu = true;
	this.base = false;
	this.flashvars = '';
	this.allowScriptAccess = 'always';
	this.useFSCommand = true;
	this.IEWin = false;
	if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1
		&& navigator.userAgent.indexOf("Windows 3.1") == -1 && navigator.userAgent.indexOf('Opera') == -1) {
			this.IEWin = true;
	}
	this.document = window.document;
}

// Outputs a vb detection function, if user is using MSIE on windows (which supports VBScript). Based on Macromedia's Flash Detection Routine.
if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 && (navigator.appVersion.indexOf("Win") != -1) && navigator.userAgent.indexOf('Opera') == -1) {
	document.writeln('<scr' + 'ipt language="VBScript" type="text/vbscript"\>');
	document.writeln('Function vb_detect_flash (version)');
	document.writeln('on error resume next');
	document.writeln('vb_detect_flash = IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & version))');
	document.writeln('End Function');
	document.write('</scr' + 'ipt\>');
}
// call to detect flash
function detect_flash(version) {
	if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 && (navigator.appVersion.indexOf("Win") != -1) && navigator.userAgent.indexOf('Opera') == -1) {
		return vb_detect_flash(version);
	} else if (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) {
		if (navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin) {
			var words = navigator.plugins["Shockwave Flash"].description.split(" ");
			for (var i = 0; i < words.length; ++i) {
				if (isNaN(parseInt(words[i]))) continue;
				var MM_PluginVersion = words[i];
			}
			return MM_PluginVersion >= version;
		}
	}
	return false;
}
adcFlash.prototype.detect = function() {
	return detect_flash(this.version);
}

// outputs appropriate html for the viewing browser
adcFlash.prototype.output_flash = function() {
	//initialize all local variables
	var props, propsBool, params, paramsBool, i;

	if (this.IEWin) {
		this.document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"');
		this.document.write(' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+this.version+',0,0,0"');
		
		props = new Array('width','height','id','name','align');
		propsBool = '';
		params = new Array('quality','scale','salign','wmode','allowScriptAccess','base','bgcolor');
		paramsBool = new Array('play','loop','menu','swliveconnect');
	} else {
		this.document.write('<embed');
		
		props = new Array('width','height','id','name','align','quality','scale','salign','wmode','bgcolor','base','allowscriptaccess');
		propsBool = new Array('play','loop','menu','swliveconnect');
		params = '';
		paramsBool = '';
	}
	// output  properties
	for (i=0; i<props.length; i++) {
		if (this[props[i]]) this.document.write(' '+props[i]+'='+this[props[i]]);
	}
	// output boolean based properties
	for (i=0; i<propsBool.length; i++) {
		this.document.write(' '+propsBool[i]+'='+((this[propsBool[i]])?'true':'false'));
	}
	// little code for IE
	if (this.IEWin) this.document.writeln('>');
	// output param based properties
	for (i=0; i<params.length; i++) {
		if (this[params[i]]) this.document.writeln('<param name="'+params[i]+'" value="'+ this[params[i]] +'">');
	}
	// output boolean param based properties
	for (i=0; i<paramsBool.length; i++) {
		if (this[paramsBool[i]]) {
			this.document.write('<param name="'+paramsBool[i]+'" value="true">');
		} else {
			this.document.write('<param name="'+paramsBool[i]+'" value="false">');
		}
	}
	
	// outputs the rest of the platform specific stuff
	if (this.IEWin) {
		this.document.write('<param name="movie" value="'+ this.src);
		if (this.flashvars) {
			this.document.writeln('?'+this.flashvars+'">');
			this.document.write('<param name="flashvars" value="'+this.flashvars);
		}
		this.document.writeln('">');
		this.document.writeln('</obj'+'ect>');
	} else {
		this.document.write(' src="'+ this.src);
		if (this.flashvars) this.document.write('?'+this.flashvars+'" flashvars="'+this.flashvars);
		this.document.writeln('" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">'+'</embe'+'d>');
	}
}

// dummy function to be replaced by user the user defined function
adcFlash.prototype.DoFSCommand = function(command, args) {
	return true;
}
adcFlash.prototype.output_fscommand = function() {
	if (this.IEWin) {
		this.document.writeln('<'+'scr'+'ipt  language="VBScript" type="text/vbscript"'+'>');
		this.document.writeln('on error resume next');
		this.document.writeln('Sub '+ this.id +'_FSCommand(ByVal command, ByVal args)');
		this.document.writeln('  call '+this.id+'__DoFSCommand(command, args)');
		this.document.writeln('end sub');
		this.document.writeln('</'+'scr'+'ipt'+'>');
	}
	this.document.writeln('<'+'scr'+'ipt language="JavaScript" type="text/javascript"'+'>');
	this.document.write('function '+this.id);
	if (this.IEWin) document.write('_');
	this.document.writeln('_DoFSCommand(command, args) {');
	if (document.all) {
		this.document.writeln(' document.all["'+this.id+'"].javascriptObj.FS_handler(command, args);');
	} else if (document.getElementById) {
		this.document.writeln(' document.getElementById("'+this.id+'").javascriptObj.FS_handler(command, args);');
	}
	this.document.writeln('}');
	this.document.writeln('</'+'scr'+'ipt'+'>');
}

// this will figure out which parts to output (fscommand, flash html, etc.) and out them
adcFlash.prototype.output =  function() {
	if (this.swliveconnect) this.output_fscommand();
	this.output_flash();
}

/*****************************
* Query string parsing stuff *
*****************************/
/*
Webmonkey GET Parsing Module
Language: JavaScript 1.0

The parsing of GET queries is fundamental
to the basic functionality of HTTP/1.0.
This module parses GET with JavaScript 1.0.

Source: Webmonkey Code Library
(http://www.hotwired.com/webmonkey/javascript/code_library/)

Author: Patrick Corcoran
Author Email: patrick@taylor.org
*/

function createRequestObject() {

  var FORM_DATA = new Object();
    // The Object ("Array") where our data will be stored.

  separator = ',';
    // The token used to separate data from multi-select inputs

  query = '' + this.location;
  qu = query
    // Get the current URL so we can parse out the data.
    // Adding a null-string '' forces an implicit type cast
    // from property to string, for NS2 compatibility.

  query = query.substring((query.indexOf('?')) + 1);
    // Keep everything after the question mark '?'.

  if (query.length < 1) { return false; }  // Perhaps we got some bad data?

  keypairs = new Object();
  numKP = 1;
    // Local vars used to store and keep track of name/value pairs
    // as we parse them back into a usable form.

  while (query.indexOf('&') > -1) {
    keypairs[numKP] = query.substring(0,query.indexOf('&'));
    query = query.substring((query.indexOf('&')) + 1);
    numKP++;
      // Split the query string at each '&', storing the left-hand side
      // of the split in a new keypairs[] holder, and chopping the query
      // so that it gets the value of the right-hand string.
  }

  keypairs[numKP] = query;
    // Store what's left in the query string as the final keypairs[] data.

  for (i in keypairs) {
    keyName = keypairs[i].substring(0,keypairs[i].indexOf('='));
      // Left of '=' is name.
    keyValue = keypairs[i].substring((keypairs[i].indexOf('=')) + 1);
      // Right of '=' is value.
    while (keyValue.indexOf('+') > -1) {
      keyValue = keyValue.substring(0,keyValue.indexOf('+')) + ' ' + keyValue.substring(keyValue.indexOf('+') + 1);
        // Replace each '+' in data string with a space.
    }

    keyValue = unescape(keyValue);
      // Unescape non-alphanumerics

    if (FORM_DATA[keyName]) {
      FORM_DATA[keyName] = FORM_DATA[keyName] + separator + keyValue;
        // Object already exists, it is probably a multi-select input,
        // and we need to generate a separator-delimited string
        // by appending to what we already have stored.
    } else {
      FORM_DATA[keyName] = keyValue;
        // Normal case: name gets value.
    }
  }

  return FORM_DATA;
}