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 = '<embed class = "'+classNM+'"';
	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];
				thisEmbdText = thisEmbdText+' 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]+'"'; 					
			}	
			
			thisParamText = thisParamText+'<param name = "'+typename+'" id = "'+typename+'" value = "'+aVals[i]+'" />';
		}
		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]+'"';
		}

		if(thisEmbdText!= '')
			thisEmbdText = thisEmbdText+'></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)
	{
		if (classid&&classid.indexOf('clsid:')<0)
			classid = 'clsid:'+classid;

		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;
}
