// JavaScript Document
function writeContacts(contacts)
{
	if (contacts !== null && contacts !== "")
	{
		var allContacts = new Array();
		var finalContacts = new Array();
		// if more than one contact has been selected, the names will be separated by a break.  		// This is used so if the user doesn't have javascript enabled, the contacts will each 		// appear on a separate line.
		// Change contact separation delimiter to one character to make it easier to work
		// with.
		if (contacts.indexOf("<br />") !== -1)
		{
			allContacts = (contacts.replace("<br />", "~"));
		}
		
		// if there are multiple contacts, separate them into an array.
		if (allContacts.indexOf("~") !== -1)
		{
			finalContacts = allContacts.split("~");
		}
		
		var contactInfo = new Array();
		var x;
	
		document.write("<table>");
		for (x in allContacts)
		{
			// separate the name and phone number for each contact, put them into the 
			// table and write the table.
			contactInfo = allContacts[x].split(" - ");
			document.write("<tr><td>" + contactInfo[0] + "</td><td>" + contactInfo[1] + "</td></tr>");
		}
		document.write("</table>");
	}
}

function writeContacts(contacts, other_contacts)
{
	// contacts contains the contact name(s), call the basic writeContacts function to write
	// these out.
	if (contacts.indexOf("no_contact") === -1)
	{
		writeContacts(contacts);
	}
	else if (other_contacts !== null && other_contacts !== "" && other_contacts !== "undefined")
	{ // contact information has been entered into the other_contact_person field because
	// it's not listed in the dropdown list called contact_person or a phone number has 
	// changed.
		var allContacts = new Array();
		allContacts = other_contacts;
		// There is more than one contact in the other_contact_person field
		if (allContacts.indexOf(";") !== -1)
		{
			// format contact information into something that the other writeContacts
			// function will understand.
			allContacts = (other_contacts.replace(";", "~"));
		}
		writeContacts(allContacts);
	}
}
