function $ (i) { return document.getElementById(i); }

var dailyvalue = {
	'transformed' : false,
	'nf' : {
		'total_fat' :     [50.0, 60.0, 65.0, 73.0, 80.0, 99.0],
		'saturated_fat' : [15.0, 18.0, 20.0, 24.0, 25.0, 30.0],
		'cholesterol' :   [300.0, 300.0, 300.0, 300.0, 300.0, 300.0],
		'sodium' :        [2400.0, 2400.0, 2400.0, 2400.0, 2400.0, 2400.0],
		'dietary_fiber' : [20.0, 20.0, 25.0, 25.0, 30.0, 35.0]
	},
	'click' : function() {
		var el = $('caloric_base');
		if (this.transformed || !el) return;
		this.transformed = true;
		el.innerHTML = '<select onchange="dailyvalue.change(this.value)">' +
			'<option value="0">1,500</option>' +
			'<option value="1">1,800</option>' +
			'<option value="2" selected>2,000</option>' +
			'<option value="3">2,200</option>' +
			'<option value="4">2,500</option>' +
			'<option value="5">3,000</option>' +
			'</select>';
	},
	'change': function(base) {
		base = +base;
		if (base < 0 || base > 5) return;
		var el, val, pv;
		for (var n in this.nf) if (this.nf.hasOwnProperty(n)) {
			el = $('nf_' + n);
			elpv = $('nf_' + n + '_pv');
			if (!el || !elpv) continue;
			val = parseFloat(el.innerHTML.replace(/[^0-9\.]/, ''));
			pv = Math.round((val / this.nf[n][base]) * 100);
			elpv.innerHTML = pv + '%';
		}
	}
};

function reviewcb(r) {
	if (!r || typeof r != 'object' || !r.status) {
		alert('Oops! Something went wrong.\n\nPlease try again later.');
	}
	else if (r.status == 'ok') {
		alert('Thanks for the review!\n\nYou can refresh this page to see your review.');
		reviewcb.form.reset();
		return;
	}
	else if (r.msg) {
		alert(r.msg);
	}
	Recaptcha.reload();
}

function contactcb(r) {
	if (!r || typeof r != 'object' || !r.status) {
		alert('Oops! Something went wrong.\n\nPlease try again later.');
	}
	else if (r.status == 'ok') {
		alert('Thanks for contacting! Someone will get back to you shortly.');
		contactcb.form.reset();
		return;
	}
	else if (r.msg) {
		alert(r.msg);
	}
}


function bowlclick(i) {
	$('rvwform').rating.value = i;
	location.href = '#review';
}

