/**
 * @author David Newell
 * @version 1.1 (11-2008)
 */

// ----------------------
// Global Variables
// ----------------------

var lang = "";
var errMsg = 'There was an error with your request. Please try again later.\nIf you continue to receive this error, please <a href="mailto:tfi@thyroid-fed.org">contact us</a>.';

// ----------------------
// End Global Variables
// ----------------------


// onLoad - function run on page load
// Set of functions to run on load
function onLoad() {
	lang = getMeta("Content-Language");
}


// loadContent - get section content in selected language
// Prototype AJAX request
// section: requested section
function loadContent(section) {
	new Ajax.Request('php/load.php', {
	  method: 'get',
	  parameters: {section: section, language: lang},
	  onSuccess: function(transport){
		var response = transport.responseText || '<p>'+errMsg+'</p>';
		window.location.hash = section;
		chgContent(response);
		},
	  onFailure: function(){ alert(errMsg) }
	  });
}


// chgContent - change content
// nContent: response from Prototype AJAX request
function chgContent(nContent) {
	document.getElementById("content").innerHTML = nContent;
}


// getMeta - get value of meta tag
// metaName: name of meta tag
function getMeta(metaName) {
	var m = document.getElementsByTagName('meta'); 
	for (var i in m) {
		if (m[i].name == metaName) {
			return m[i].content;
		}
	}
}


// Prototype window load event listener - starts function onLoad
Event.observe(window, 'load', onLoad());

