
var customFieldsContainer, customLetterContainer, microsoftLetterContainer, americaWirelessContainer, customNameField, customIndustryField, customTechField

function setContainers()
	{
	if(!customFieldsContainer)	
		{
		customFieldsContainer = document.getElementById("customFields")
		}
	if(!customLetterContainer)
		{
		customLetterContainer = document.getElementById("customLetter")
		}
	if(!microsoftLetterContainer)
		{
		microsoftLetterContainer = document.getElementById("microsoftLetter")
		}
	if(!americaWirelessContainer)
		{
		americaWirelessContainer = document.getElementById("americaWirelessLetter")
		}
	if(!customNameField)
		{
		customNameField = document.getElementById("customName")
		}
	if(!customIndustryField)
		{
		customIndustryField = document.getElementById("customIndustry")
		}
	if(!customTechField)
		{
		customTechField = document.getElementById("customTech")
		}

	}

function updateCustomTemplate(sender)
	{
	setContainers()
	if(customFieldsContainer) customFieldsContainer.style.display = "block"
	if(customLetterContainer) customLetterContainer.style.display = "block"
	if(microsoftLetterContainer) microsoftLetterContainer.style.display = "none"
	if(americaWirelessContainer) americaWirelessContainer.style.display = "none"
	if(customLetterContainer)
		{
		var customSpanTags = customLetterContainer.getElementsByTagName("span")
		var customSpanTag
		for(var i = 0; i < customSpanTags.length; i++)
			{
			customSpanTag = customSpanTags[i]
			if(customSpanTag.className)
				{
				if(customSpanTag.className == "companyName")
					{
					customSpanTag.innerHTML = textToTextNode(customNameField.value)
					}
				else if(customSpanTag.className == "companyIndustry")
					{
					customSpanTag.innerHTML = textToTextNode(customIndustryField.value)
					}
				else if(customSpanTag.className == "companyTech")
					{
					customSpanTag.innerHTML = textToTextNode(customTechField.value)
					}
				}
			}
		}
	}

function textToTextNode(text)
	{
	text = text.replace("&", "&amp;")
	text = text.replace("<", "&lt;")
	text = text.replace(">", "&lt;")
	return text
	}

function revealLetter(letterName)
	{
	setContainers()
	if(customFieldsContainer) customFieldsContainer.style.display = "none"
	if(customLetterContainer) customLetterContainer.style.display = "none"
	if(letterName == "microsoftLetter")
		{
		if(microsoftLetterContainer) microsoftLetterContainer.style.display = "block"
		if(americaWirelessContainer) americaWirelessContainer.style.display = "none"
		}
	else if(letterName == "americaWirelessLetter")
		{
		if(americaWirelessContainer) americaWirelessContainer.style.display = "block"
		if(microsoftLetterContainer) microsoftLetterContainer.style.display = "none"
		}
	}

