// JavaScript Document

function validateForm() {
	var okSoFar = true;
	with (document.bookingform) {
		if (courseid.value == "" && okSoFar) {
			okSoFar = false;
			alert("Please select a programme.");
			courseid.focus();
		}
		if (name.value == "" && okSoFar) {
			okSoFar = false;
			alert("Please enter the delegate's name.");
			name.focus();
		}
		if (company.value == "" && okSoFar) {
			okSoFar = false;
			alert("Please enter the Company.");
			company.focus();
		}
		if (job_title.value == "" && okSoFar) {
			okSoFar = false;
			alert("Please inform the delegate's job title.");
			job_title.focus();
		}
		if (department.value == "" && okSoFar) {
			okSoFar = false;
			alert("Please enter the delegate's department.");
			department.focus();
		}
		if (tel.value == "" && okSoFar) {
			okSoFar = false;
			alert("Please enter a contact telephone number.");
			tel.focus();
		}
		if (okSoFar) {
			if (ValidateEmail() == false) {
				okSoFar = false;
			}
		}
		if (referral.value == "" && okSoFar) {
			okSoFar = false;
			alert("Please select 'where did you hear from us.'");
			referral.focus();
		}
		if (BillingSurname.value == "" && okSoFar) {
			okSoFar = false;
			alert("Please enter the surname of the person in charge of billing.");
			BillingSurname.focus();
		}
		if (BillingFirstnames.value == "" && okSoFar) {
			okSoFar = false;
			alert("Please enter the first name(s) of the person in charge of billing.");
			BillingFirstnames.focus();
		}
		if (BillingAddress1.value == "" && okSoFar) {
			okSoFar = false;
			alert("Please enter the billing address.");
			BillingAddress1.focus();
		}
		if (BillingCity.value == "" && okSoFar) {
			okSoFar = false;
			alert("Please enter the billing city.");
			BillingCity.focus();
		}
		if (BillingPostCode.value == "" && okSoFar) {
			okSoFar = false;
			alert("Please enter the billing post code.");
			BillingPostCode.focus();
		}
		if (country.value == "" && okSoFar) {
			okSoFar = false;
			alert("Please select the billing country.");
			country.focus();
		}
		if (country.value == "US" && okSoFar) {
			if (billingstate.value == "0") {
				okSoFar = false;
				alert("Please select the billing state.");
				billingstate.focus();
			}
		}

		if (terms_check.checked == 0 && okSoFar) {
			okSoFar = false;
			alert("Please read and accept the General Booking Conditions to proceed.");
			terms_check.focus();
		}
		if (okSoFar == false)
			return false;// submit();
	}
}

function aniViewer2(html, width, height) {
	mini1 = window.open(html, 'aniViewer2', 'width=' + width + ',height='
			+ height + ',marginwidth=0,marginheight=0,border=0,scrollbars=yes');
}
function openDir(form) {
	window.location = (form.dir.options[form.dir.selectedIndex].value);
}

function echeck(str) {

	var at = "@"
	var dot = "."
	var lat = str.indexOf(at)
	var lstr = str.length
	var ldot = str.indexOf(dot)
	if (str.indexOf(at) == -1) {
		alert("Invalid E-mail address")
		return false
	}

	if (str.indexOf(at) == -1 || str.indexOf(at) == 0
			|| str.indexOf(at) == lstr) {
		alert("Invalid E-mail address")
		return false
	}

	if (str.indexOf(dot) == -1 || str.indexOf(dot) == 0
			|| str.indexOf(dot) == lstr) {
		alert("Invalid E-mail address")
		return false
	}

	if (str.indexOf(at, (lat + 1)) != -1) {
		alert("Invalid E-mail address")
		return false
	}

	if (str.substring(lat - 1, lat) == dot
			|| str.substring(lat + 1, lat + 2) == dot) {
		alert("Invalid E-mail address")
		return false
	}

	if (str.indexOf(dot, (lat + 2)) == -1) {
		alert("Invalid E-mail address")
		return false
	}

	if (str.indexOf(" ") != -1) {
		alert("Invalid E-mail address")
		return false
	}

	return true
}

function ValidateEmail() {
	var emailID = document.bookingform.delegate_email;

	if ((emailID.value == null) || (emailID.value == "")) {
		alert("Please Enter your Email address")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value) == false) {
		// emailID.value=""
		emailID.focus()
		return false
	}
	return true
}
