function validate(requiredform) {
	var why = "";
	why += checkEmail(requiredform.email.value);
	why += checkUsername(requiredform.realname.value);
	why += isEmpty(requiredform.from.value, "Where are you from");
	why += isEmpty(requiredform.fromdate.value, "Date of first tour");

	var tourselect = false;

	/*
	for (var j = 0; j <= 25; j++) {
		box = requiredform.tours[j]; 
		if (box.checked){
			tourselect = true;
			break;
		}
	}

	if( !tourselect ){
		why += isEmpty(requiredform.question.value, "Notes / other questions");
	}
	*/

	if( requiredform.airport_transfer.checked ){
		why += isEmpty(requiredform.arrival_date.value, "Arrival date");
		why += isEmpty(requiredform.airport.value, "Arrival airport");
	}

	if (why != "") {
		alert(why);
		return false;
	}
	
	return true;
}

function checkEmail (strng) {
	var error="";
	if (strng == "") {
		error = "You didn't enter a contact email address.\n";
	}
	
	var emailFilter=/^.+@.+\..{2,3}$/;
	if (!(emailFilter.test(strng))) { 
		error = "Please enter a valid contact email address.\n";
	} else {
		//test email for illegal characters
		var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
		if (strng.match(illegalChars)) {
			error = "The contact email address contains illegal characters.\n";
		}
	}
	return error;    
}

// username - 4-10 chars, uc, lc, and underscore only.
function checkUsername (strng) {
	var error = "";
	if (strng == "") {
		error = "You didn't enter a contact name.\n";
	}
	return error;
}       

// non-empty textbox
function isEmpty(strng, cntrl) {
	var error = "";

	if (strng.length == 0 || strng == "??") {
		error = "You must enter a value for '" + cntrl +"'.\n"
	}
	return error;
}

function transferclick( source ){
	var x=getelement("airport_transfer_questions").style;

	if( source.checked ) {
		x.display="block"
		var y = getelement("arrival_date");
		y.select();
	}else{
		x.display="none"
	}
}

// Ok, if the source is 'friend' or 'guide', then 
// ensure the 'who' row is visible.
function checksource(source) {
	
	if( source.value == "guide" ) {
		alert("Please enter the name of the guide that referred you to us.");
		
		var x=document.getElementById("referrer_extra");
		x.select();
		
	} else {
		var x=document.getElementById("question");
		x.select();
	}
	
	return true;
}

function getelement(id){ 
    if (document.getElementById){
         return document.getElementById(id)
    }else{
        return eval('document.all.' + id)
    } 
}