
/*--------------------------------------------------------------------------------
	Home teaser random
--------------------------------------------------------------------------------*/

	document.observe('dom:loaded', function(){
		var ul = $$('div.home-teaser-random ul')[0];
		if (ul){
			ul.select('li').each(function(li, key){
				if (key == 0){ 
					li.addClassName('selected');
				} else {
					li.hide();
				}
			});
			
			setInterval(function(){
				var li = ul.down('li.selected');
				var next_li = li.next('li');
				
				li.hide();
				li.removeClassName('selected');
				
				if (!next_li){
					next_li = ul.down('li');
				}
				
				next_li.show();
				next_li.addClassName('selected');
			}, 3000);
		}
	});
		
/*--------------------------------------------------------------------------------
	Conference form validation
--------------------------------------------------------------------------------*/

	document.observe('dom:loaded', function(){
		
		if ($('conference_form')){
			$('conference_form').observe('submit', function(event){
				
				var fields = {
					'txt_title': "Please enter a title",
					'txt_first_name': "Please enter a first name",
					'txt_last_name': "Please enter a last name",
					'txt_job_title': "Please enter a job title",
					'txt_company_name': "Please enter a company name",
					'txt_address_1': "Please enter the first line of your address",
					'txt_po_box': "Please enter a P.O. Box",
					'txt_country': "Please enter a country",
					'txt_telephone': "Please enter a telephone number",
					'txt_email': "Please enter an email address",
					'agreement': "Please confirm you have read and agree to the terms and conditions"
				}
				
				for (n in fields){
					if (!validate_field(event, n, fields[n])){
						return false;
					}
				}
				
				re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
				if (!re.test($F('txt_email'))){
					event.stop();
					alert("Please enter a valid email address");
					$('txt_email').focus();
					$('txt_email').select();
				}
				
			//	$('conference_form').submit();
				
			}.bindAsEventListener(this));
		}
		
		// Onchange validate email address
		$('txt_email').observe('blur', function(){
			re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
			if (!re.test($F('txt_email'))){
				alert("Please enter a valid email address");
				$('txt_email').focus();
				$('txt_email').select();
			}
		});
		
	});
	
	function validate_field(event, id, msg)
	{
		if ($F(id)){
			return true;
		} else {
			event.stop();
			alert(msg);
			$(id).focus();
			$(id).select();
			return false;
		}
	}

