var STANDARD_ANALYSIS_TEXT = '<p>A <strong>Standard diet analysis</strong> provides you with information on the following nutrients:</p>';
var STANDARD_NUTRIENTS = [
	'Digestible Energy',
	'Protein',
	'Calcium',
	'Phosphorous',
	'Copper',
	'Zinc',
	'Selenium',

	'Vitamin A',
	'Vitamin E' ];

var COMPREHENSIVE_ANALYSIS_TEXT = '<p>A <strong>Comprehensive diet analysis</strong> provides you with information on the following nutrients:</p>';
var COMPREHENSIVE_NUTRIENTS = [
	'Digestible Energy',
	'Protein',
	'Lysine',
	'Calcium',
	'Phosphorous',
	'Copper',
	'Zinc',
	'Selenium',
	'Manganese',
	'Iodine',
	'Iron',
	'Sodium',
	'Chloride',
	'Magnesium',
	'Potassium',
	'Vitamins A and E',

	'Vitamins B1, B2 and Folate' ];


function informedSubmit(event) {
	event.stop();
	if (!validateInformed())
		alert('Please fill in all the fields before pressing Submit');
	else {
		$('informedForm').hide();
		$('informedSaving').show();
		$('informed').request( {
			onComplete : function(transport) {
				$('informedSaving').hide();
				$('informedSaved').update(transport.responseText);
				$('informedSaved').show();
				if ($('informedClose'))
					$('informedClose').observe('click', informedClose);
			}
		});
		try {
			pageTracker._setDomainName('.feedxl.com');
			pageTracker._trackPageview('/informed/save.php');
		} catch (e) {}
		optimiserTracker._trackPageview('/3567938469/goal');
	}
}

function validateInformed() {
	return $FF('name').trimall() != '' && $FF('email').trimall() != '';
}

function informedClose(event) {
	$('informedClose').stopObserving('click', informedClose);
	myLightbox.end();
}

function mt_lightboxLoadedEvent(event) {
	if (event.memo.initiatorId == 'informedLink') {
		$('informedSubmit').observe('click', informedSubmit);
		if (document.body && document.body.id)
			$('informedPage').value = document.body.id;
		try {
			pageTracker._setDomainName('.feedxl.com');
			pageTracker._trackPageview('/informed/');
		} catch (e) {}
	}
}

function mt_lightboxUnloadedEvent(event) {
	if (event.memo.initiatorId == 'informedLink') {
		$('informedSubmit').stopObserving('click', informedSubmit);
	}
}

function mt_domLoaded() {
	var s = STANDARD_ANALYSIS_TEXT + '<ul>';
	var lif = function(e) {
		s += '<li>' + e + '</li>';
	};
	STANDARD_NUTRIENTS.each(lif);
	s += '</ul>';
	var ttSet = function(e) {
		e.writeAttribute('title', s);
		e.addClassName('autoTooltip');
	};
	$$('.tt_mtStandardAnalysis').each(ttSet);

	s = COMPREHENSIVE_ANALYSIS_TEXT + '<ul>';
	COMPREHENSIVE_NUTRIENTS.each(lif);
	s += '</ul>';
	$$('.tt_mtComprehensiveAnalysis').each(ttSet);
	Tooltip.registerTooltips();
}

function mt_tooltipShowEvent(event) {
	var id = '??unknown??';
	if (event.memo.initiator.id)
		id = event.memo.initiator.id;
	else {
		var ih = event.memo.initiator.innerHTML.trimall();
		if (ih != '')
			id= ih;
	}
	try { pageTracker._trackEvent('Tooltips', id); } catch (e) {}
}

function mt_signup(o) {
	if (Object.isElement(o)) {
		// form
		if ($('__signup_form_input_country') == null) {
			var ce = new Element('input');
			ce.id = '__signup_form_input_country';
			ce.type = 'hidden';
			ce.name = 'country';
			ce.value = COUNTRY_CODE;
			o.insert({ bottom: ce });
		}
		o.submit();
	} else if (Object.isString(o)) {
		var url = 'http://my.feedxl.com/auth/newUser.fxl?country=' +
			COUNTRY_CODE +
			'&ap=' + o +
			(arguments.length > 1 ? 't=' + arguments[1] : '');
		window.location = url;
	}
}

document.observe('xp:lightboxLoaded', mt_lightboxLoadedEvent);
document.observe('xp:lightboxUnloading', mt_lightboxUnloadedEvent);
document.observe('xp:tooltipShow', mt_tooltipShowEvent);
document.observe('dom:loaded', mt_domLoaded);

// misc MT variables, included to stop errors, we don't use them
var captcha_timer;
var commenter_name;
var commenter_blog_ids;
var is_preview;
var mtcmtmail;
var mtcmtauth;
var mtcmthome;

