var isIE=document.all;

function CreateAndActivateControl(DivID,classNM,clsid,width,height,codebase,pNames,pValues,noEmText)
{		
	var d=document.getElementById(DivID);
	var aNames=new Array();
	var aVals=new Array();
	var objData=thisParamText=reqAttribs=mimetype=typename=thisEmbdText='';
	var thisObjectText='<object class="'+classNM+'"';
	var thisEmbdText='';
	var thisEmbdDataText = '';
	aNames=pNames.split('|');
	aVals=pValues.split('|');
	var needWidth=needHeight=true; 
	var widthString=heightString='';

	if(aNames.length == aVals.length)
	{	
		for(var i=0; i<aNames.length; i++)
		{
			if(aVals[i] == 'empty_string')
				aVals[i]='';			
			
			// we need this to get the names right ex.mimetype == type
			typename=aNames[i]; 
			
			if (aNames[i].toLowerCase().indexOf('src') == 0)
			{
				objData=aVals[i];
				if (!isIE)
					thisEmbdDataText=' data="'+objData+'"';
			}

			if(aNames[i].toLowerCase().indexOf('mimetype')>-1)
			{
				mimetype=aVals[i];
				typename='type';
			}
			if(aNames[i].toLowerCase().indexOf('width') == 0 && aVals[i] != "")
			{
				needWidth=false;
				widthString=' width="'+aVals[i]+'"';
			}	
			if(aNames[i].toLowerCase().indexOf('height') == 0 && aVals[i] != "")
			{
				needHeight=false;
				heightString=' height="'+aVals[i]+'"'; 					
			}	

			// custom fix to deal with FF 6.0 not working with Flash when wmode other than "window" and shockwave file has buttons
			// this fix can be edited to add other versions of FF and images if necessary
			// expect a future FF or Flash patch will correct and this can be removed.
			// FPT 09/09/2011
			if (navigator.userAgent.indexOf("Firefox/6.")>-1 && typename=="wmode") {
				aVals[i]="window";			
			} 
			
			thisParamText=thisParamText+'<param name="'+typename+'" value="'+aVals[i]+'" />';	// TParker 24-Nov-2008 - removed stray 'id' attribute
		}
		
		if (!isIE) // no need to do this for IE
		{
			for(var i=0;i<aNames.length;i++)
			{
				if(aVals[i] == 'empty_string')
					aVals[i]='';
					
				// we need this to get the names right ex.mimetype == type	
				typename=aNames[i]; 
				
				if(aNames[i].toLowerCase().indexOf('mimetype')>-1)
					typename='type';
		
				thisEmbdText = thisEmbdText+' '+typename+'="'+aVals[i]+'"';
			}
		
			thisEmbdText = '<embed class="' + classNM + '"' + thisEmbdDataText + thisEmbdText + '>' + '<noembed>' + noEmText + '</noembed></embed>';
		}

		if(isIE)
			reqAttribs=buildObjReqParams(clsid,null,null,codebase);
		else
			reqAttribs=buildObjReqParams(null,objData,mimetype,codebase);

		if(needWidth==true)
			thisObjectText=thisObjectText + ' width="' + width + '"';

		if(needHeight==true)
			thisObjectText=thisObjectText + ' height="' + height + '"';
			
		thisObjectText=thisObjectText + widthString + heightString + reqAttribs + '>' + thisParamText + thisEmbdText + noEmText + '</object>';
	}
	else
		thisObjectText="Initialization of the object failed";

	d.innerHTML=thisObjectText;
}

function buildObjReqParams(classid,objData,mimetype,codebase)
{
	var str='';

	if (isIE && classid)
	{
		if (classid.indexOf('clsid:') < 0)
			classid = 'clsid:' + classid;

		if (classid.length > 0)
			str=str+' classid="'+classid+'"';
	}

	if (objData)
		str=str+' data="'+objData+'"';
	
	if(mimetype)
		str=str+' type="'+mimetype+'"';

	if(codebase)
	{
		if(mimetype!= 'application/x-shockwave-flash')
			str=str+' codebase="'+codebase+'"';
	}
	return str;
}

