$(document).ready(function() {
   
    //Attach validation to form submit
    $('#venue_enquiry_form').submit(function(evt) {
        if(!validate($(this))) {
            evt.preventDefault();    
        }    
    });
});

// bog standard form validation
function validate(f) {
	errors = "";
    
	if($('input[name=company]',f).val() == "") {
		errors += "\n- Company Name";
	}
	if($('input[name=first_name]',f).val() == "") {
		errors += "\n- First Name";
	}
	if($('input[name=surname]',f).val() == "") {
		errors += "\n- Surname";
	}
	if($('input[name=phone]',f).val() == "") {
		errors += "\n- Telephone";
	}
	if($('input[name=email]',f).val() == "") {
		errors += "\n- Email";
	}
	
	if(errors) {
		errors = "Please make sure to complete the following required fields:\n" + errors;
		alert(errors);
		return false;
	}
	
	return true;
	
}

// select all venue checkboxes
function all_venues() {
	f = document.forms[0];
	
	for(i=0;i<f.length;i++) {
		if(f[i].name == "venues[]") {
			f[i].checked = true;
		}
	}
}
