//Copyright (c) 2000 Microsoft Corporation.  All rights reserved.
//<script>
var g_arAttachUrl = null;
var g_objXMLHTTP = null;
var g_szEMId_ = "EMMultimediaDivId_";
var g_szEMName = "EMultimediaObj";
var g_szEMCLSID = "CLSID:6532D0B1-5C10-11D3-9D66-00C04F68AC7D";
var g_szEMVer='6,0,4208,0';
var g_szEMCodeBase = g_szVirtualRoot +'/controls/emclient.cab';
var g_szEMAudGif = 'em2bb222b9$6bd1$4467$bb02$27ee5a705255';
var g_szEMVidGif = 'em3c6b81f4$6e81$4cbc$a04c$bbb054095532';
var g_szEMgid = "";
var g_nMMobjs = 0;
var g_fEMgif = false;

function getMediaElements(objDOM)
{
	var objs = objDOM.getElementsByName(g_szEMName);
	if( null == objs )
	{
		var oItem = objDOM.body.all.EMultimediaObj;
		if( null != oItem  )
		{
			objs = new Array( oItem );
		}
	}
	return objs;
}

function inlineAttachments( objDOM )
{
	if( 0 == inlineAttachments.fInitial )
	{
		inlineAttachments.fInitial = 1;

		var rgAttachments = g_rgInlines;

		if( null != g_rgInlines )
		{
			var key;

			for( key in g_rgInlines )
			{
				if( -1 != g_rgInlines[ key ].indexOf(g_szEMAudGif) )
				{
					g_fEMgif = true;
					break;
				}
			}
		}

		g_arAttachUrl = new Array();
		var i = 0;

		var objs = getMediaElements( objDOM );

		var reSec = /\?.*/;
		var reMulti = /([0-9]_multipart\/)+/;

		if( null != objs  )
		{
			var e = new Enumerator( objs );
			for (;!e.atEnd();e.moveNext())
			{
				var objItem = e.item();

				var szCid = objItem.id;
				if( null == szCid )
				{
					continue;
				}

				szCid = szCid.replace( reSec, "" );
				szCid = szCid.replace( reMulti, "" );

				var szAttachUrl = rgAttachments[ szCid ];
				if( null != szAttachUrl )
				{
					g_arAttachUrl[ szCid ] = szAttachUrl.replace( /.*\/([^?]*)\?.*$/, "$1" );
					i++;
				}
			}
		}
		if( 0 == i )
		{
			g_arAttachUrl = null;
		}
	}
	
	return( g_arAttachUrl );
}
inlineAttachments.fInitial = 0;

function AddMMObjTags( objDOM )
{
	var oInlines = inlineAttachments( objDOM );
	if( null == oInlines )
	{
		return;
	}

	var objs = getMediaElements( objDOM );
	var oAttachments = document.all("idAttachmentWell");

	if( null != objs  )
	{

		var szBase = "";
		var obj = window.document.all.tags('BASE');
		if( obj && obj.length )
		{
			szBase = obj[0].href;
		}

		var reSec = /\?.*/;
		var reMulti = /([0-9]_multipart\/)+/;
		var e = new Enumerator( objs );
		for (;!e.atEnd();e.moveNext())
		{
			var objItem = e.item();
			if( "IMG" == objItem.tagname && null != objItem.id )
			{
				var szCid = objItem.id.replace( reSec, "");
				szCid = szCid.replace( reMulti, "" );

				szFile = oInlines[ szCid ];
				if( szFile )
				{
					objItem.style.behavior = 'url(#EMConduct#' + g_szEMgid + ')';

					if( oAttachments )
					{
						// Remove the attachment element from the attachment well.
						var re = new RegExp( '<IMG [^>]+>&nbsp;<A href="'+ szBase + szFile + '" [^>]+><FONT [^>]+>[^<]+</FONT></A>',"i")
						oAttachments.innerHTML = oAttachments.innerHTML.replace( re, "" );
					}
				}
			}
		}
	}
}

function ctrlMedia_ResolveRef(val)
{
	var szBase = "";
	var reLocal = /^\w:/;
	var reMimeURL = /([^?]+)/;
	if( !reLocal.test( val ) )
	{
		var obj = window.document.all.tags('BASE');
		if( obj && obj.length )
		{
			szBase = obj[0].href;
		}
		var rgVal = reMimeURL.exec( val );
		if( null != rgVal )
		{
			val = rgVal[1];
		}
	}
	return( szBase + val );
}

function ctrlMedia_AddEventFor( szEvent, szScript )
{
	var objScript = document.createElement('Script');
	if( null != objScript )
	{
		objScript.language = 'javascript';
		objScript.text     = szScript;
		objScript.htmlFor  = 'ctrlMedia';
		objScript.event    = szEvent;
		document.body.appendChild( objScript );
	}
}

function ctrlMedia_positionUpdate()
{
	if( null != g_ctrlMedia )
	{
		var y = document.body.clientHeight;
		if( !g_ctrlMedia._fHide )
		{
			y -= g_ctrlMedia.clientHeight;
		}
		with( g_ctrlMedia.parentElement.runtimeStyle )
		{
			posTop = y;
			posLeft = g_ctrlMedia._offset;
		}
	}
}

function ctrlMedia_Command( nCmd )
{
	var objItem = g_ctrlMedia.parentElement;
	switch(nCmd)
	{
		case 2:
			Record( 0 );
			return( true );
		case 1:
		case 3:
		default:
			g_ctrlMedia._fHide = false;
			ctrlMedia_positionUpdate();
			break;
		case 4:
			g_ctrlMedia._fHide = true;
			ctrlMedia_positionUpdate();
			break;
	}
	return( false );
}

