function limit_words(id,wordLimit) {
	var text1 = document.getElementById(id).value;
	var text2 = text1.replace(/\s+/g, ' ');
	var text3 = text2.split(' ');
	var numberOfWords = text3.length;
	if(numberOfWords > wordLimit) {
		alert("Please limit statement to 300 words less!");
		return false;
	}
	return true;
}

function checkOption() {
	var chosenOption = document.getElementById("category").value;
	if(chosenOption == "Independent Gym of the Year") {
		document.getElementById("regions").style.display = "inline";
		document.getElementById("regions").disabled = false;
	}	else {
		document.getElementById("regions").style.display = "none";
		document.getElementById("regions").disabled = true;
	}
}

function isNumber(evt) {
	var charCode = (evt.which) ? evt.which : evt.keyCode
 	if(charCode > 31 && (charCode < 48 || charCode > 57) && charCode != 37 && charCode != 39 && charCode != 46) return false;
 	return true;
}

function paymentMethod() {
	var selIndex = document.getElementById("paymentmethod").selectedIndex;
	if(selIndex == 1) {
		document.getElementById("pm_cheque").style.display = "none";
		document.getElementById("pm_card").style.display = "block";
	} else {
		document.getElementById("pm_card").style.display = "none";
		document.getElementById("pm_cheque").style.display = "block";
	}
}

function updateTotal() {
	var places = document.getElementById("places").value;
	var twoplaces = document.getElementById("twoplaces").value;
	var fourplaces = document.getElementById("fourplaces").value;
	var tables = document.getElementById("tables").value;
	
	if(places == '') document.getElementById("places").value = '0';
	if(twoplaces == '') document.getElementById("twoplaces").value = '0';
	if(fourplaces == '') document.getElementById("fourplaces").value = '0';
	if(tables == '') document.getElementById("tables").value = '0';
	
	places = parseInt(places);
	twoplaces = parseInt(twoplaces);
	fourplaces = parseInt(fourplaces);
	tables = parseInt(tables);
	
	if(twoplaces == 1) {
		alert("A minimum of 2 is required in this field");
		document.getElementById("twoplaces").value = '0';
		twoplaces = 0;
	}
	if(fourplaces < 4 && fourplaces > 1) {
		alert("A minimum of 4 is required in this field");
		document.getElementById("fourplaces").value = '0';
		fourplaces = 0;
	}
	
	var placestotal = places*75;
	var twoplacestotal = twoplaces*65;
	var fourplacestotal = fourplaces*55;
	var tablestotal = tables*400;
	var total = parseInt(placestotal+twoplacestotal+fourplacestotal+tablestotal);	
	document.getElementById("total").value = total;
}
