function new_cap( ele ) {

	if( document.getElementById ) {
		var target = document.getElementById( 'cap' );
		var thesrc = target.src;
		var thesrc = thesrc.substring( 0, thesrc.lastIndexOf( '?' ) );
		target.src = thesrc + '?' + Math.round( Math.random() * 100000 );
	} else {
		alert( 'Sorry, cannot auto-reload image\nSubmit the form or refresh the page and a new image will be loaded' );
	}
	ele.blur();
	return false;
}
function mailTo( e, m ) {

	return 'info';
	//if( ! e ) var e = 'service';
	//if( ! m ) var m = 'Enquiry via web site...';
	//var d = 'f5media.co.uk';
	//return '<a href="mailto:' + e + '@' + d + '?subject=' + m + '" title="Send us an e-mail">' + e + '@' + d + '</a>';
}

window.onload = externalLinks;

function externalLinks() {

	// switch all external links, pdf or word docs to load in new window
	if( ! document.getElementsByTagName ) { return; }

	// regex for file extensions
	var anchorRegex = /\.(pdf|doc)$/i;
	var anchors = document.getElementsByTagName( 'a' );

	//if( window.location.hostname.indexOf( 'www.' ) == -1 ) {
	//	window.location.hostname = 'www.' + window.location.hostname;
	//}

	for( var i = 0; i < anchors.length; i++ ) {
		var anchor = anchors[ i ];
		if( anchor.getAttribute( 'href' ) ) {
			if( anchor.hostname.indexOf( 'f5' ) < 0 || anchorRegex.test( anchor.pathname ) ) {
				anchor.target = '_blank';
			}
		}
	}

}

function verifyForm( theForm ) {

	for( i=0; i<theForm.elements.length; i++ ) {
		var theFld = theForm.elements[i];
		var reqFld = ( theFld.id.indexOf( '_Req' ) != -1 ) ? true : false;
		var valSet = ( theFld.value == 0 || theFld.value == '' ) ? false : true;
		var fldChop = theFld.id.split( '_Req' );
		var fldName = fldChop[0].split( '_' ).join( ' ' );

		if( reqFld == true && valSet == false ) {
			alert( fldName + ' cannot be left blank' );

			if( theFld.type == 'text' || theFld.type == 'textarea' ) {
				theFld.focus();
				theFld.select();
			} else {
				theFld.focus();
			}
			return false;
		}

		if( fldName.indexOf( 'E-mail' ) != -1 ) {
			if( !/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test( theFld.value )) {
				alert( fldName + ' ' + theFld.value + ' is not in a recognised format' );
				theFld.focus();
				theFld.select();
				return false;
			}
		}
	}

	var btns = document.getElementsByTagName( 'input' );
	for( btn=0; btn<btns.length; btn++ ) {

		if( btns[ btn ].type == 'submit' ) {
			btns[ btn ].disabled = true;
			btns[ btn ].value = 'Sending...';
		}
	}

	return true;
}

function checkRef() {

	// check for ref string on contact form
	var queryStr = location.search.split( '=' );
	var checkFld = document.getElementById( queryStr[ 1 ] );

	if( checkFld ) {
		checkFld.checked = true;
	}
}