function isEmailValid(szEmail) {
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	return filter.test(szEmail)
}

function checkVal(oField, szValue) {
	if (oField.value == szValue) {
		oField.select();
	}
	else if (oField.value == "") {
		oField.value = szValue
	}
}

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
}

$(document).ready(function(){
	setActivePanelByFragment(self.document.location.hash.substring(1));

	$(".course-tab A").click(function(e) {
		// Set active tab	
		$(".course-tab").removeClass("current");
		$($(this).parents("LI")).addClass("current");
		
		// Set active panel
		$(".course-panel").removeClass("current-panel");	
		setActivePanelByClass($(this).attr("class"));
	});
	
	$(".course-panel A").click(function(e) {
		// Set active panel
		$(".course-panel").removeClass("current-panel");	
		setActivePanelByClass($(this).attr("class"));
	});
});

function setActivePanelByFragment(activeFragment) {
	$(".course-panel").removeClass("current-panel");	
	
	switch (activeFragment) {
		case "introduction":
			$($(".btn-showintro").parents("LI")).addClass("current");	
			$(".introduction-panel").addClass("current-panel");
			break;
			
		case "programme":
			$($(".btn-showprogramme").parents("LI")).addClass("current");	
			$(".programme-panel").addClass("current-panel");
			break;
			
		case "registration-notes":
			$($(".btn-showregnotes").parents("LI")).addClass("current");	
			$(".regnotes-panel").addClass("current-panel");
			break;
			
		case "booking-form":
			$($(".btn-showbooking").parents("LI")).addClass("current");	
			$(".booking-panel").addClass("current-panel");
			break;
			
		default:
			$($(".btn-showintro").parents("LI")).addClass("current");	
			$(".introduction-panel").addClass("current-panel");
			break;
	}
}

function setActivePanelByClass(activeClass) {
	$(".course-panel").removeClass("current-panel");
	$(".course-tab").removeClass("current");
	
	switch (activeClass) {
		case "btn-showintro":
			$($(".btn-showintro").parents("LI")).addClass("current");	
			$(".introduction-panel").addClass("current-panel");
			break;
			
		case "btn-showprogramme":
			$($(".btn-showprogramme").parents("LI")).addClass("current");	
			$(".programme-panel").addClass("current-panel");
			break;
			
		case "btn-showregnotes":
			$($(".btn-showregnotes").parents("LI")).addClass("current");
			$(".regnotes-panel").addClass("current-panel");
			break;
			
		case "btn-showbooking":
			$($(".btn-showbooking").parents("LI")).addClass("current");	
			$(".booking-panel").addClass("current-panel");
			break;
			
		default:
			$($(".btn-showintro").parents("LI")).addClass("current");	
			$(".introduction-panel").addClass("current-panel");
			break;
	}
}

function testCheckupValid(oForm) {
	var bValid = true;
	
	if ((oForm.txtName.value.toString().length<=2) || (oForm.txtName.value=="Name")){
		bValid = false;
		alert("Please enter your name");
		oForm.txtName.focus();
	}
	
	else if ((oForm.txtCompany.value.toString().length<=2) || (oForm.txtCompany.value=="Company Name")){
		bValid = false;
		alert("Please enter your company name");
		oForm.txtCompany.focus();
	}
	
	else if ((oForm.txtPhone.value.toString().length<=2) || (oForm.txtPhone.value=="Phone Number")){
		bValid = false;
		alert("Please enter your phone number");
		oForm.txtPhone.focus();
	}
	
	else if ((oForm.txtEmail.value.toString().length<=2) || (oForm.txtEmail.value=="Email Address")){
		bValid = false;
		alert("Please enter your email address");
		oForm.txtEmail.focus();
	}
	
	else if (!isEmailValid(oForm.txtEmail.value)) {
		bValid = false;
		alert("Please enter a valid email address")
		oForm.txtEmail.focus();
	}
	
	else if (oForm.cboEmployees.value=="False"){
		bValid = false;
		alert("Please enter select the number of employees in the company");
		oForm.cboEmployees.focus();
	}
	
	else if ((oForm.txtPostcode.value.toString().length<=2) || (oForm.txtPostcode.value=="Postcode")){
		bValid = false;
		alert("Please enter your postcode");
		oForm.txtPostcode.focus();
	}
	
	return bValid;
}