//v1.0
//Copyright 2006 Adobe Systems, Inc. All rights reserved.

// Developer:		Nole Mailey
// Source:			http://www.macromedia.com/devnet/activecontent/articles/devletter.html
// Description:		This script creates the object, embed, and params tags through name value pairs. The purpose purpose we're using it
//					it for is to bypass the latest security feature in the IE6 browser which requires the user to click the movie to
//					to activate it which is caused by embedded <object> and <embed> tags directly in the document.
// Date Sourced:	April 17, 2006
// Usage:			For Flash, include this file and call the AC_FL_RunContent() function with the attributes and corresponding values one
//					after the other for all parameters passed within the <object> and <embed> tags (inlucding the <parameter> names
//					and values.
//
//					AC_FL_RunContent( 	'classid', 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000',
//						'codebase', 'https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0',
//						'width', '<%= knWidth %>', etc..., etc...);
// Modified By:		Nole mailey
// Date Modified:	April 17, 2006
// Modifications:	Remove the second parameter (".swf"), from the AC_GetArgs() function call in AC_FL_RunContent() as it appends
//					the parameter to the end of the flash filename. We're already passing this in the ASP calls.
// Modified By:		Nole Mailey
// Date Modified:	April 18, 2006
// Modifications:	Added an if statement to prevent the "type" attribute from being added within the OBJECT tag.
//					Otherwise the type attribute is added within the OBJECT tag which breaks in IE5 on the MAC.


function AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}

function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
  var str = '<object ';
  for (var i in objAttrs)
  	if(i == "type") {		// See Date Modified April 18, 2006
		continue;
	} else {
    	str += i + '="' + objAttrs[i] + '" ';
	}
  str += '>';
  for (var i in params)
    str += '<param name="' + i + '" value="' + params[i] + '" /> ';
  str += '<embed ';
  for (var i in embedAttrs)
    str += i + '="' + embedAttrs[i] + '" ';
  str += ' ></embed></object>';

  document.write(str);
}

function AC_FL_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, "", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"			// See Date Modified April 17, 2006
     , "application/x-shockwave-flash"
    );
for(object in ret.objAttrs)
{
	document.swrite
}
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_SW_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
     , null
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    

    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":	
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblClick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "id":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}
