/*
/--------------------------------------------------\
| INSOBJ.JS                                        |
----------------------------------------------------
| Contains a function insObj(args...) to embed     |
| active controls in a HTML page on computers with |
| Microsofts kb912945 fix.                         |
|                                                  |
|                                                  |
| Version: beta 1                                  |
\--------------------------------------------------/
*/
/****************************************************************************************************************************************
************************************************************************************************************************
*****************
INSTRUCTIONS
=========================
To embed something (object, flash, applet, activex etc) in a page, follow these steps.

1.	If you're using a tool that generates an HTML tag for you - generate a sample tag to use as input to the following steps.

2.	Include this script in the head of the HTML file. Place this code between the <HEAD> and </HEAD> tags:
	<script src="insObj.js" type="text/javascript"></script>
	<script src="insObj_attributes.js" type="text/javascript"></script>

3. 	Where you want to embed the object, insert the code below. 

<script type="text/javascript">
insObj('arg1_name','arg1_value');
</script>

4.	Adjust the function arguments based on the attributes used in your sample tag. Replace the arg1_name and arg1_value above with 
	the appropriate	arguments. You can add as many comma-separated arguments (argument1, value1, argument2, value2...) as you want to the 
	function. 

5.	Adjust the tag in which the arguments are placed (object, embed or param) by editing the param arrays. These are placed in the
	insObj_attributes.js file. It's recommended to keep the default arguments in the insObj_attributes.js file - and then create new,
	edited copies with alternative configurations for the pages that need that, and reference the alternative configurations only 
	when needed. 

6.	Ready to use!

A SAMPLE IS ATTACHED IN THE insObjSample.html.



SAMPLE EMBED
=========================
Embed your Flash, ActiveX och applet using the code below. The code generates one <object>, one <embed> and a free number of <param> tags.
Add whatever arguments you like, all as arguments to the insObj function like arg1, value1, arg2, value2... The argument may be 
placed by the function into either the <object>, <embed> or <param> tags - or to any possible combination of these. Where the argument is
placed is decided by the three param arrays (sample in insObj_attributes.js). If the name of an attribute is in the array embed_attr, the argument will be placed as an attribute in the <embed> tag. If the name of the attribute is placed into the param_attr array, the argument will be placed as a <param> tag between the <object> and </object> tags. You may place an argument into all three arrays and any other combination if you like. Remember that these arrays has nothing to do with the values of the arguments, only where the argument is placed in the code.

If an attribute is not specified in any of the three arrays, it will be placed as an attribute to the <object> AND <embed> tags.

*****************************************************************************************************************************************
*****************************************************************************************************************************************

insObj(
	'classid','d27cdb6e-ae6d-11cf-96b8-444553540000',
	'codebase','http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0',
	'width','200',
	'height','200',
	'id','active',
	'align','middle',
	'allowScriptAccess','sameDomain',
	'movie','active.swf',
	'quality','high',
	'bgcolor','#ffffff',
	'name','active.swf',
	'pluginspage','http://www.macromedia.com/go/getflashplayer',
	'type','application/x-shockwave-flash',
	'src','active.swf',
); //end AC code

*/


function insObj(){
  var ret = AC_AX_GetArgs(arguments);
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
  var str = '<object ';
  for (var i in objAttrs)
    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_AX_GetArgs(args){
  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();    
//	  alert("A"+embed_attr);

	  var embedded = false;
	  // This type of attribute is an embed attribute
//	  alert("currArg "+array_indexOf(currArg,embed_attr));
	  if (array_indexOf(currArg,embed_attr)>-1) {
		  ret.embedAttrs[args[i]] = args[i+1];
		  embedded=true;
	  }
	  // This type of attribute is a object attribute
	  if (array_indexOf(currArg,object_attr)>-1) {
		  ret.objAttrs[args[i]] = args[i+1];
		  embedded=true;
	  }
	  // This type of attribute is a param
	  if (array_indexOf(currArg,param_attr)>-1) {
		  ret.params[args[i]] = args[i+1];
		  embedded=true;
	  }
	  // Default if nothing specified in arrays
	  if (!embedded) {
		  ret.objAttrs[args[i]] = ret.embedAttrs[args[i]] = args[i+1];
	  }
  }
  return ret;
}

function array_indexOf(sstr, arr) {
	for (x=0;x<arr.length;x++) {
		if (arr[x]==sstr) return x;
	}
	return -1;
}
