//	open external links in a new window - replaces target="_blank"
	function externalLinks () { 
		if ( ! document.getElementsByTagName ) return; 
		var anchors = document.getElementsByTagName("a"); 
		for ( var i=0; i < anchors.length; i++ ) { 
			var anchor = anchors[i]; 
			if ( anchor.getAttribute("href") && anchor.getAttribute("rel") == "external" ) anchor.target = "_blank"; 
		} 
	} 

//	preload images
	function preload_images () {
		arImageSrc = new Array ();
		arImageList = new Array ();
		for (counter in arImageSrc) {
			arImageList[counter] = new Image();
			arImageList[counter].src = arImageSrc[counter];
		}
	}

//	show a rollover thumb
	function thumb_on(el) {
		var thumb = document.getElementById('thumb_' + el);
		thumb.src = 'media/images/projects/on_' + el + '.jpg';
	}
	
//	restore a rollover thumb
	function thumb_off(el) {
		var thumb = document.getElementById('thumb_' + el);
		thumb.src = 'media/images/projects/sml_' + el + '.jpg';	
	}

//	show a large project image
	function show_project(el) {
		var num_el = parseInt(el);
		var caption_array = new Array();
		caption_array[1] = 'Hanging stair in steel';
		caption_array[2] = 'Terraced flats';
		caption_array[3] = 'Commercial office';
		caption_array[4] = 'Private residence';
		caption_array[5] = 'Grandstand';
		caption_array[6] = 'Ecological terraced housing';
		caption_array[7] = 'Private pool &amp; spa';
		caption_array[8] = 'Access stair';
		caption_array[9] = 'Restaurant interior';
		caption_array[10] = 'Rural house interior';
		caption_array[11] = 'Private villa';
		caption_array[12] = 'Rural office';
		caption_array[13] = 'Low energy urban housing';
		caption_array[14] = 'Hanging stair in steel';
		caption_array[15] = 'Bar interior';
		caption_array[16] = 'Stair &amp; shelf';
		caption_array[17] = 'Domestic extension';
		caption_array[18] = 'Column detail';
		caption_array[19] = 'Private stair';
		caption_array[20] = 'Domestic extension';
		caption_array[21] = 'Balustrade';
		caption_array[22] = 'High rise';
		caption_array[23] = 'Domestic pool';
		caption_array[24] = 'Bar front';
		caption_array[25] = 'Studded copper';
		
		document.getElementById('large_image').src = 'media/images/projects/lrg_' + el + '.jpg';
		document.getElementById('caption').innerHTML = caption_array[num_el];

	}

//	when a field receives the focus
	function field_focus(el) {
		var field = document.getElementById(el);
		if ( field.value == el ) {
			field.value = '';
		}
	}

//	when a field looses the focus
	function field_blur(el) {
		var field = document.getElementById(el);
		if ( field.value == '' ) {
			field.value = el;	
		}
	}

//	validate the contact form data
	function validate_form() {
		var error_message = "Sorry, some of the information appears to be missing or incorrect...\n\n";
		var errors = 0;
		var name = document.getElementById('Name');
		var email = document.getElementById('Email');
		var enquiry = document.getElementById('Enquiry');
		if ( name.value == 'Name' || name.value == '' ) {
			error_message += "- you have not entered your name\n";
			errors = 1;
		}
		if ( email.value == 'Email' || email.value == '' ) {
			error_message += "- you have not entered your email address\n";
			errors = 1;
		}
		if ( email.value != 'Email' && email.value != '' && /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email.value) === false ) {
			error_message += "- the email address you have entered does not appear to be correct\n";
			errors = 1;
		}
		if ( enquiry.value == 'Enquiry' || enquiry.value == '' ) {
			error_message += "- you have not entered an enquiry";
			errors = 1;
		}
		if ( errors == 1 ) {
			alert( error_message );
			return false;
		} else {
			return true;
		}
	}

//	perform the following functions when the page loads
	window.onload = function(e) {
		externalLinks();
	}