//Copyright (c) 2000 Microsoft Corporation.  All rights reserved.
//<script>

var g_RecipientXMLNode	=	null;;
var g_XML				=	null;
var g_XMLData			=	null;
var g_EditNameDialog	=	null;
var g_szDisplayName     =   "";
function window.onload()
{
	GetParams();
	BuildSelections();
	BuildCaptions();
	nameSelect.click();
}

function GetParams()
{
	var dlgArgs			= window.dialogArguments;
	g_EditNameDialog	= dlgArgs["g_EditNameDialog"];
	g_szDisplayName     = dlgArgs["g_DisplayName"];
	var tempXML		= 	new ActiveXObject("Microsoft.XMLDOM");
	var sz = dlgArgs["recipientTDData"]
	tempXML.loadXML(sz);
	g_XMLData			= tempXML;
}

function CreateOption(szDisplayName, szEmail, value)
{
	var node = window.document.createElement("OPTION");
	node.text	=	szDisplayName + "[" + szEmail + "]" ;
	node.value	=	value;
	node.displayname	= szDisplayName;
	node.email			= szEmail;
	return(node);
}

function BuildSelections()
{

	var display, email;
	var szDisplay, szEmail;
	var i;
	var node = null;
	if(g_XMLData == null)return(false);
	display		=	g_XMLData.selectNodes("a:response/a:recipients/a:item/a:displayname");
	email		=	g_XMLData.selectNodes("a:response/a:recipients/a:item/a:email");
	var rgNodes	=	g_XMLData.selectNodes("a:response/a:recipients/a:item");
	for(i=0; i < display.length; i++)
	{
		szEmail	= email[i].text;
		szDisplay = display[i].text;
		node = CreateOption(szDisplay, szEmail, i);
		nameSelect.add(node)
	}
}

function BuildCaptions()
{
	
	if(nameSelect.options.length == 0)
	{
		L_OutlookFoundMoreThanOne_Text	=	L_OutlookDoesNotRecognize_Text;
	}
	Caption_1.innerText = L_OutlookFoundMoreThanOne_Text + "\"" + g_szDisplayName + "\"";
}

function OnClick_OK()
{
	var fRet=false;
	if (optDelete.checked)
	{
        window.dialogArguments["returnedRecipientType"] = 0;	
        fRet=true;	
	}
    else
    {
    	var szSelect = nameSelect.value
	    if(szSelect == "")
	    {
	    	//if nothing to select let 'OK' close
	    	if (ANR_CONTENTS.innerText=="")
	    	{
	            this.returnValue=null;
	            self.close();
	    	}
	    	else
	    	{
	    	    alert(L_MustSelectName_Text);
	    	}    
	    	fRet = false;
	    }
	    else
	    {
	        var optionSelected = nameSelect.options[szSelect];
	        if(optionSelected != null)
	        {
	            window.dialogArguments["returnedRecipient"]			= optionSelected.text;
	            window.dialogArguments["returnedRecipientName"]		= optionSelected.displayname;
	            window.dialogArguments["returnedRecipientEmail"]	= optionSelected.email;
            }
            fRet=true;
        }
    }

	if (true == fRet)
	{
	    this.returnValue=true;
	    self.close();
    }
    return(fRet);
}

function OnClick_Cancel()
{
	this.returnValue = null;
    self.close();
}

function OnClick_Help()
{

}

function nameSelect_ondblclick()
{
	OnClick_OK();
}

function EditRecip_OnClick()
{
	if(g_EditNameDialog == null)
	{
		alert("Error anr dialog >> EditRecip_OnClick >> g_EditNameDialog == null");
		return;
	}
	var szDialog=	g_EditNameDialog;
	var option	=	null;
	var szName	=	"";
	var szEmail =	"";
	var retOpt	=	null;
	if(nameSelect.options.length != 0)
	{
		option = nameSelect.options[nameSelect.selectedIndex];
		if(option != null)
		{
			szName	=	option.displayname;
			szEmail =	option.email;
		}
	}
	var rgParams=	new Array();
		rgParams["displayname"]	=	szName;
		rgParams["email"]		=	szEmail;
		rgParams["type"]		=	"SMTP";
		var hWin = window.showModalDialog(szDialog, rgParams,"dialogHeight:160px;dialogWidth:500px;status:no;resizable:no;help:no;scroll:no;")       
	if(rgParams["displayname"] != "" && rgParams["email"] != "" && rgParams["type"] != "")	
	{
		retOpt = CreateOption(rgParams["displayname"], "[" + rgParams["email"] + "]", nameSelect.options.length)
		nameSelect.add(retOpt)	
	}
}
function NYI()
{

}