addLoadEvent(function() {
	var keywordInput = $("keywords");
	if (keywordInput) {
		var keywordHelpers = getElementsByClassName("keyword_helper");
		var nkh = keywordHelpers.length;
		
		for (i=0; i < nkh; i++) {
			keywordHelpers[i].onclick = function() {
				addKeywordToInput(this.innerHTML);
				return false;
			}
		}
	}
	
	// Adjust suggested keywords based on the selected pillar.
	var pillar = $("pillar");
	if (pillar) {
		// Set the initial suggestions.
		var keywordSpan = $("keywords_" + pillar.options[pillar.selectedIndex].value);
		if (keywordSpan)
			keywordSpan.style.visibility = 'visible'; 
		// Change the suggestions every time the pillar selection changes.
		pillar.onchange = function() {
			var selectedPillar = pillar.options[pillar.selectedIndex].value;
			for (i = 1; i <= 6; i++) {
				if (i == selectedPillar) {
					$("keywords_" + i).style.visibility = 'visible'; 					
					$("keywords_" + i).style.width = '800px';	
				} else {
					$("keywords_" + i).style.visibility = 'hidden';
					$("keywords_" + i).style.width = '0px'; 					
				}
			}
		}
	}
});

function addKeywordToInput(kw) {
	var keywordInput = $("keywords");
	if (kw.indexOf(" ") >= 0)
		kw = '"' + kw + '"';
	
	if (keywordInput.value.indexOf(kw) == -1) {
		keywordInput.value += " " + kw;
	}
}
