function checkTix (min, max) {
	var ok = false;
	var i, input;
	for (i = min; i <= max; i++) {
		input = document.getElementById ('tix' + i);
		if (input.value) {
			ok = true;
			break;
		}
	}
	
	if (!ok) {
		alert ('Please select one or more tickets to order.');
		return false;
	}
	
	return true;
}


function checkQuiz() {
	var ok = true;
	for (i = 1; i < 8; i++) {
		if (!document.getElementById ('q' + i).value) {
			ok = false;
		}
	}
	
	if (ok) {	
		if (!document.getElementById ('qname').value || !isEmail (document.getElementById ('qemail').value)) {
			ok = false;
		}
	}
	
	if (!ok) {
		alert ('Please answer all seven questions and give your name and a valid email address.');
		return false;
	}
	
	return true;
}


function checkContact() {
	if (!document.getElementById('forename').value) {
		alert ('Please give your first name.');
		document.getElementById('forename').focus();
		return false;
	}
	if (!document.getElementById('surname').value) {
		alert ('Please give your last name.');
		document.getElementById('surname').focus();
		return false;
	}
	if (!isEmail (document.getElementById('email').value)) {
		alert ('Please give a valid email address.');
		document.getElementById('email').focus();
		return false;
	}
	return true;
}


// check whether email address is valid
// argument: email address
// returns: boolean
function isEmail (str) {
	// if the string's empty, no good
	if (!str) {
		return false;
	}

	// disallowed characters: if we find any of these, no good
	var iChars = ' *|,"<:>[]{}`\';()&$#%';
	for (var i = 0; i < str.length; i++) {
		if (iChars.indexOf(str.charAt(i)) != -1) {
			return false;
		}
	}
	
	// position in string of @
	var iAt = str.indexOf('@');
	// position in string of second @ (if any)
	var jAt = str.indexOf('@', iAt + 1);
	// position in string of last .
	var iDot = str.lastIndexOf('.');
	// if @ is absent or first character, or there's more than one @
	// or the last . is too near the end or too close to @,
	// no good
	if (iAt < 1 || jAt != -1 || iDot > str.length - 3 || iDot - iAt < 2) {
		return false;
	}
	
	// otherwise, fine!
	return true;
}

