
// make sure the form meets with our approval
function validate(f) {
	errors = "";
	
	// run our checks
	if(f.name.value == "") { errors += "\n- Must complete the Name field."; }
	if(f.email.value == "") { errors += "\n- Must complete the Email field."; }
	if(f.email.value != f.email_confirm.value) { errors += "\n- Your Emails don't match."; }
	
	categories = false;
	locations = false;
	bands = false;
	for(i=0;i<f.length;i++) {
		if((f[i].type == "checkbox") && f[i].checked) {
			if(f[i].name == "category_ids[]") { categories = true; }
			if(f[i].name == "location_ids[]") { locations = true; }
			if(f[i].name == "salary_bands[]") { bands = true; }
		}
	}
	
	if(!categories) { errors += "\n- Must select at least one sector."; }
	if($('#jbe_locs_tree').hasClass('treeview') && ! locations) { errors += "\n- Must select at least one location."; }
	if(!bands) { errors += "\n- Must select at least one salary band."; }
	
	// if error found, complain
	if(errors != "") {
		errors = "The following problems were found with your details:\n" + errors + "\n\nPlease correct and try again.";
		alert(errors);
		return false;
	}
	
	// otherwise cool, let's go
	else {
		return true;
	}
}

// transform a couple of nested category lists into tree things
$(document).ready(function(){
	$("#jbe_cats_tree").treeview({ collapsed: true });
	$("#jbe_locs_tree").treeview({ collapsed: true });
});

