﻿// client side scripts to supports the contacts area

var contacts = new function()
{
	// body is optional XHTML DOM doc  or a string (both with main element body) or null
	this.messenger = function(id, formal)
	{
		if (formal == null)
			formal = "&#160;";

		var doc = ydrBrowser.xml.document(
			"<form "
			+ ydrNamespace
			+" ydr:fieldstyle='width:40em'>"
			+"<p class='info'>This form allows you to generate an email to the selected person or distribution list.&#160; Your email address will be disclosed to the recipients.&#160; Your IP and eMail addresses will be recorded with the message in a log.&#160; This facility may not be used for spam, illegal or offensive purposes or in connection with any business or commercial activity, marketing, survey or fund raising.&#160; You will be sent a copy of this email.</p>"
			+"<p class='info'>This facility allows you to send a plain text or lightly formatted message.&#160;  If you need to send attachments or active content, use this facility to ask the recipient to tell you his or her email address and then send the information directly.</p>"		
			+"<table>"
			+"%predefined%" /* the entries here will indicate to whom the email is sent and allow the user to define the subject */
			+"</table></form>");
	
		return ydrClientScripts.messenger(id+":"+formal
		,"Message via the "+siteName+" Website" /* siteName is from boilerplate("head") */
		, doc.documentElement
		, "Current Logged in User", null, null 
		, document.getElementById("popup")
		, document.getElementById("normal")
		);			
	};
	
	var topic;
	
	// a user has pressed the change button against some data listed via xlst - so get the appropriate 
	// server side handler to deal with it
;
	this.change = function(changeTopic, rowID, fullDialogue)
	{		
		var url;
		var topic = "Change User Details";
		var buttons = "'0^Commit'-1^Cancel'";
		var responseMode="default";
		var go = true;
			
		topic=changeTopic;

		switch(topic)
		{
			case "reissueWelcome" ://stop();			
				url=rootDir+"/ydr/logon/newAccountRedo.asp?email=" + rowID; // note this misuse of rowId
				topic = "Renew Account for " + rowID;
				buttons = null;
				responseMode = "simple";

				if (fullDialogue == "fullDialogue")
				{
					ydrPopup.showRemote(rootDir+"/ydr/logon/newAccountAffirm.asp?topic=" + escape(topic)+"&url=" + escape(url));
					go=false;				
				};			
				
				break;
			
			case "PROFILE" :
				url=rootDir+"/ydr/contacts/contacts.asp?action=dialog&topic=" + topic + "&id=" + rowID
				break;
				
			default :

				url = rootDir+"/ydr/ydrCredentials.asp?action=dialog&topic=" + topic + "&id=" + rowID;
				
		};
		
		if (go)
		{
			with (ydrClientScripts.XMLHttpRequest())
			{
				open("GET", url);	
				onreadystatechange=function()
					{
						if (this.readyState == 4)	
						{	
							if ( ydrClientScripts.checkResponseOK(this.responseText))
							{
								switch (responseMode)
								{
									case "default" :
										ydrPopup.show(this.responseText, topic
											,null, ydrExclaimListClient.commit, ydrCredentialsClient.validate
											,buttons);
										break;
										
									case "simple" :
										ydrPopup.show(this.responseText, topic
											, null, function(){return 'redo'}, null
											,buttons);
								};	
							};
						};
					};
				send(null);		
			};
		};
	};	
}


