var openPopupWindow;

function openPopup(url, returnValueTextBoxID) {
	url += "&ReturnValueTextBoxID=" + returnValueTextBoxID;
	
	if(openPopupWindow) {
    if(!openPopupWindow.closed) {openPopupWindow.focus();}
  }	
  
	var openPopupWindow = window.open(url, returnValueTextBoxID, "center=yes,width=430,height=520,modal=yes,alwaysRaised=yes");		
}

function showNavigate(id, extraParams, returnValue, returnValueTextBoxID){
	if ( extraParams != null && extraParams != "" )
		extraParams = "&" + extraParams;	
	else 
		extraParams = "";
		
	var url = "manage.php?p=ListingNavigatePopup&ReturnValue=" + escape(returnValue) + extraParams;
	
	if (id != null)
		url += "&ID=" + id.toString();

	return openPopup(url, returnValueTextBoxID);
	
	return false;
}

function showNavigateOnComplete(obj) {
	var url = obj.value;
	window.document.location.assign(url);
}

function openRecipientSelector(id) {
	var idsContainer = document.getElementById(id);
	
	var url = "manage.php?p=RecipientSelectorPopup&RecipientIDs=" + idsContainer.value;
	
	openPopup(url, id);
	
	return false;
}

function openRecipientSelectorOnComplete(idsContainer) {		
	var namesContainer = document.getElementById(idsContainer.id + "_Text");
	
	var parts = idsContainer.value.split("|");
	
	var ids = parts[0];
	var displayNames = parts[1].split(";");
	var emails = parts[2].split(";");
	
	idsContainer.value = ids;
	
	var names = "";
	for ( i = 0; i < displayNames.length; i++ ) {
		if ( displayNames[i] == "" )
			continue;
		names += "<a href=\"mailto:" + emails[i] + "\">" + displayNames[i] + "</a>; ";
	}
	namesContainer.innerHTML = names;
}

