function isSet( variable ){
	return( typeof( variable ) != 'undefined' );
}

function validatePostcode(elem){						
	fullPostcodeRegExp = /^[A-Za-z]{1,2}[0-9]{1,2}[A-Z]? [0-9][A-Za-z][A-Za-z]$/;
	if (!fullPostcodeRegExp.test(elem.val())) {
		alert('Please enter your full postcode, ensuring there is a space between the first and second parts.');
		return false;
	}
	return true;
}

function showTab(id){
	$('#nav-tabs a').parent().removeClass("selected");
	$('#nav-tabs a[href=#' + id + ']').parent().addClass("selected");
	$('form#ReportForm fieldset').hide();
	$('form#ReportForm fieldset#'+id).show();
	document.location.hash="#" + id;
}
	

$(function(){
	
	//create tab switching when clicking on tabs
	$('#nav-tabs a').click(function(){
		showTab($(this).attr("href").replace("#",""));
		return false;
	});
	
	//append continue buttons to each tab
	$('form#ReportForm fieldset#tab_1').append('<a href="#tab_2" class="tabtoggle">Continue</a>');
	$('form#ReportForm fieldset#tab_2').append('<a href="#tab_3" class="tabtoggle">Continue</a>');
	//create tab switching when clicking on these continue buttons
	$('#ReportForm a.tabtoggle').click(function(){
		showTab($(this).attr("href").split("#")[1]);
		return false;
	});
	
	
	//show first tab
	showTab('tab_1');

	//hide other relevant items by default
	$('#dogdetails').hide();
	$('#dogbreed').hide();
	$('#catbreed').hide();

	
	//show dog breed information entry if clicked
	$('#animaltype').change(function(){
		showAnimalBreeds();
	});
	
});
 
function showAnimalBreeds() {
	if ( $('#animaltype').val() == 'Dog' ) {
		$('#dogbreed').show();
		$('#catbreed').hide();
	}
	else if ( $('#animaltype').val() == 'Cat' ) {
		$('#dogbreed').hide();
		$('#catbreed').show();
	}
	else {
		$('#dogbreed').hide();
		$('#catbreed').hide();
	}
	
	
}