function validateLodgeForm(id,lodge_availability,terrace_availability,pavilion_availability){
	var form = $(id);
	var children = form.getElementsByTagName('input');
	var total = 0;
	for (var i=0; i < children.length; i++) {
		if (children[i].getAttribute("type") == "text") {
			if (children[i].id == "lodge" && children[i].value > parseInt(lodge_availability) && parseInt(lodge_availability) > 0 ) {
				alert('Please select less than ' + (parseInt(lodge_availability) + 1) + ' lodge tickets.');
				return false;
			};
			if (children[i].id == "terrace" && children[i].value > parseInt(terrace_availability) && parseInt(terrace_availability) > 0) {
				alert('Please select less than ' + (parseInt(terrace_availability) + 1) + ' terrace tickets.');
				return false;
			};
			if (children[i].id == "pavilion" && children[i].value > parseInt(pavilion_availability) && parseInt(pavilion_availability) > 0) {
				alert('Please select less than ' + (parseInt(pavilion_availability) + 1) + ' pavilion tickets.');
				return false;
			};
			total = total + children[i].value;
		};
	};
	
	if (total > 0) {
		return true;
	}else{
		alert("Please select at least 1 ticket");
	};
	
	return false;
}

function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}
