//Copyright (c) 2000 Microsoft Corporation.  All rights reserved.
//<script>
var fFinished=false;

document.onclick= doc_onclick

function doc_onclick()
{
	var A_Link = null;
	if(event.srcElement.tagName=="FONT")
	{
		A_Link = event.srcElement.parentElement;
	}
	else if(event.srcElement.tagName=="A")
	{
		A_Link = event.srcElement
	}

	if( null != A_Link )
	{
		//parse the href right now
		var str     =   A_Link.outerHTML;
		var lookStr =   "href=\""
		var index1  =   str.indexOf(lookStr)
		var substr  =   str.substring(index1 + lookStr.length, str.length);
		lookStr     =   "\"";       
		index1      =   substr.indexOf(lookStr);
		substr  =   substr.substring(0,index1 + lookStr.length-1);      
		top.parent.location = substr
		event.returnValue=false
		event.cancelBubble=true;
		return(false);
	}
}

function onCbClick(szCommand, varValue )
{
	if(event.button == 2)
	{
		return(false);
	}

	switch(szCommand.toUpperCase())
	{
		case "CLOSE":
			FinishAttachments(false);
		break;
		case "HELP":
			if(null != idHelpLinkText)
			{
				top.open(idHelpLinkText.innerText,"OutlookWebAccessHelp","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width="+500+",height="+400)
			}
		break;
	}
	event.returnValue=false
	event.cancelBubble=true;
}

function window.onload()
{
	FinishAttachments(true);
}

function window.onunload()
{
	if(fFinished)
	{
		return(false);
	}
	fFinished=true;
	FinishAttachments(true);
}

function SubmitAttachForm(cmdVal)
{
	if(!document || !document.attachForm)
	{
		return(false);
	}

	if( 0 == document.getElementsByName('attachFile')[0].value.length )
	{
		return( false );
	}
	document.attachForm.submit();
}

function SubmitRemoveForm(cmdVal)
{
	if(!document || !document.removeForm || !document.removeForm.Cmd)
	{
		return(false);
	}
	document.removeForm.Cmd.value = cmdVal;
	document.removeForm.submit();
}

function FinishAttachments(noclose)
{
	fFinished=true;
	if( !window || !window.parent 
		|| !idAttachmentsTable 
		|| !window.parent.g_WindowOpener 
		|| !window.parent.g_WindowOpener.argVal 
		|| !window.parent.g_WindowOpener.argVal.document
		|| !window.parent.g_WindowOpener.argVal.document.body   
		)
	{
		return(false);
	}

	objAttachments = window.parent.g_WindowOpener.argVal.document.all("idAttachmentWell");
	if(!objAttachments)
	{
		return(false);
	}

	var rePath = /(<A href=\")[^"]*\//ig;
	var szAttachments = idViewAttachments.innerHTML.replace( rePath, '$1' );

	var objSuppress = window.parent.g_SuppressList.argVal;
	if( null != objSuppress )
	{
		for( key in objSuppress )
		{
			var szFile = objSuppress[key];
			var re = new RegExp( '<IMG [^>]+>&nbsp;<A href="'+ szFile + '" [^>]+><FONT [^>]+>[^<]+</FONT></A> ',"i")
			var reList = new RegExp( '<FONT [^>]+>'+szFile+'</FONT>', "i" );
			szAttachments = szAttachments.replace( re, "" );

			if( !noclose )
			{
				continue;
			}

			for( var i = idAttachmentsTable.children.length - 2; i >= 0; i-=2)
			{
				if( reList.test(idAttachmentsTable.children[i].children[2].innerHTML) )
				{
					// Delete <BR>
					idAttachmentsTable.children[i+1].outerHTML = "";
					// Delete checkbox and text
					idAttachmentsTable.children[i].outerHTML = "";
					break;
				}
			}
		}
	}

	objAttachments.style.display = idCurList.style.display = ( 0 == szAttachments.length ) ? "none" : "";
	objAttachments.innerHTML = szAttachments;

	if(!noclose)
	{
		window.parent.close();
	}
}



