
function EmbedFlash()
{
	ActiveXGenerateObj("EmbedFlash()", "clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA", arguments);
}

// Implements ActiveXGenerateObj() function. This is a generic function used to generate
// object/embed/param tags. It is used by higher level api functions.

/************** LOCALIZABLE GLOBAL VARIABLES ****************/

var MSG_EvenArgs = 'The %s function requires an even number of arguments.'
                 + '\nArguments should be in the form "atttributeName","attributeValue",...';
var MSG_SrcRequired = "The %s function requires that a src be passed in as one of the arguments.";

/******************** END LOCALIZABLE **********************/

// Substitutes values for %s in a string.
// Usage: ActiveXsprintf("The %s function requires %s arguments.","foo()","4");
function ActiveXsprintf(str)
{
	for (var i=1; i < arguments.length; i++)
	{
		str = str.replace(/%s/,arguments[i]);
	}
	return str;
}
		
// Checks that args, the argument list to check, has an even number of 
// arguments. Alerts the user if an odd number of arguments is found.
function ActiveXcheckArgs(args,callingFn)
{
	var retVal = true;
	// If number of arguments isn't even, show a warning and return false.
	if (parseFloat(args.length/2) != parseInt(args.length/2))
	{
	    alert(ActiveXsprintf(MSG_EvenArgs,callingFn));
		retVal = false;
	}
	return retVal;
}
	
function ActiveXGenerateObj(callingFn, classid, args)
{

	if (!ActiveXcheckArgs(args,callingFn))
	{
		return;
	}

  // Initialize variables
	var tagStr = '';
	var currArg = '';
	var closer = '/>';
	var srcFound = false;
	var embedStr = '<embed';
	var paramStr = '';
	var embedNameAttr = '';
	var objStr = '<object classid="' + classid + '"';

  // Spin through all the argument pairs, assigning attributes and values to the object,
  // param, and embed tags as appropriate.
	for (var i=0; i < args.length; i=i+2)
	{
	    currArg = args[i].toLowerCase();    

		if (currArg == "src")
		{
			paramStr += '<param name="' + args[i] + '" value="' + args[i+1] + '"' + closer + '\n';
			embedStr += ' ' + args[i] + '="' + args[i+1] + '"';
			srcFound = true;
		}
		else if (   currArg == "width" 
				|| currArg == "height" 
				|| currArg == "align" 
				|| currArg == "vspace" 
				|| currArg == "hspace" 
				|| currArg == "class" 
				|| currArg == "title" 
				|| currArg == "accesskey" 
	              || currArg == "tabindex")
	    {
			objStr += ' ' + args[i] + '="' + args[i+1] + '"';
			embedStr += ' ' + args[i] + '="' + args[i+1] + '"';
		}
		else if (currArg == "id")
		{
			objStr += ' ' + args[i] + '="' + args[i+1] + '"';
			// Only add the name attribute to the embed tag if a name attribute 
			// isn't already there. This is what Dreamweaver does if the user
			// enters a name for a movie in the PI: it adds id to the object
			// tag, and name to the embed tag.
			if (embedNameAttr == "")
			embedNameAttr = ' name="' + args[i+1] + '"';
		}
		else if (currArg == "name")
		{
			objStr += ' ' + args[i] + '="' + args[i+1] + '"';
			// Replace the current embed tag name attribute with the one passed in.
			embedNameAttr = ' ' + args[i] + '="' + args[i+1] + '"';
		}    
		// This is an attribute we don't know about. Assume that we should add it to the 
		// param and embed strings.
		else
		{
			paramStr += '<param name="' + args[i] + '" value="' + args[i+1] + '"' + closer + '\n'; 
			embedStr += ' ' + args[i] + '="' + args[i+1] + '"';
		}
	}

	// Tell the user that a src is required, if one was not passed in.
	if (!srcFound)
	{
	    alert(ActiveXsprintf(MSG_SrcRequired,callingFn));
	    return;
	}

	if (embedNameAttr)
		embedStr += embedNameAttr;	

	// Close off the object and embed strings
	objStr += '>\n';
	embedStr += '></embed>\n'; 

	// Assemble the three tag strings into a single string.
	tagStr = objStr + paramStr + embedStr + "</object>\n"; 

	document.write(tagStr);
}
