//DATA INTERFACE 20 Nov 2006
//JAVASCRIPT VERSION 1.0
//NIGEL'S LIB
//get element by ID shortcut
function $(theBtnId) {
	return document.getElementById(theBtnId);
}
//ajax request function
var xmlhttp = null;
function createXMLHttpRequest() {
	if (window.XMLHttpRequest) {
		xmlhttp = new XMLHttpRequest();
		if (typeof xmlhttp.overrideMimeType != 'undefined') {
			xmlhttp.overrideMimeType('text/html');
		}
	} else if (window.ActiveXObject) {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		alert('Perhaps your browser does not support XMLHttpRequests?');
	}
}
//ajax send email address function
function doAjaxPostEmail(theEmailAddress,beenSubmitted) {
	createXMLHttpRequest();
	var url = "ajaxmail.php?timestamp=" + new Date().getTime();
	var queryString = "email=" + theEmailAddress + "&BeenSubmitted=" + beenSubmitted;
	xmlhttp.open("POST", url, true);
	xmlhttp.onreadystatechange = handleStateChange;
	xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
	xmlhttp.send(queryString);
}
//END OF NIGEL'S LIB
//----
//ajax state change function for email back form
function handleStateChange() {
	if (xmlhttp.readyState == 4) {
		if (xmlhttp.status == 200) {
			$('emailMsg').innerHTML = xmlhttp.responseText;
		} else {
			$('emailMsg').innerHTML = '<strong>ERROR!</strong><br />Please try again.';
		}
	} else {
		$('emailMsg').innerHTML = '<strong>Please wait<span style="text-decoration:blink;">...</span></strong>';
	}
	$('emailBtn').disabled = "";
}
//window onload functions
window.onload = function() {
	//if browser does not support the dom then abort
	if (!document.getElementById) return false;
	//IE browser quotes fix
	if (window.ActiveXObject) { //Are we on windows Explorer
		//quote tags
		quoteTags = document.getElementsByTagName('q');
		for (i=0; i<quoteTags.length; i++) {
			quoteTags[i].innerHTML = "&#8220;" + quoteTags[i].innerHTML + "&#8221;";
		}
		// blockquote tags
		blockTags = document.getElementsByTagName('blockquote');
		for (i=0; i<blockTags.length; i++) {
			blockTags[i].getElementsByTagName('p')[0].innerHTML = "<strong style=\"color:#259;\">&#8220;</strong>" + blockTags[i].getElementsByTagName('p')[0].innerHTML + "<strong style=\"color:#259;\">&#8221;</strong>";
		}
	}
	//front Page buttons
	//financial image button
	if ($('finButton')) {
		$('finButton').getElementsByTagName('a')[1].onmouseover = function() {
			$('finButton').getElementsByTagName('a')[0].style.backgroundPosition = "0 -142px";
		}
		$('finButton').getElementsByTagName('a')[1].onmouseout = function() {
			$('finButton').getElementsByTagName('a')[0].style.backgroundPosition = "0 0";
		}
		$('finButton').getElementsByTagName('a')[1].onmousedown = function() {
			$('finButton').getElementsByTagName('a')[0].style.backgroundPosition = "0 -284px";
		}
		$('finButton').getElementsByTagName('a')[0].onmouseover = function() {
			this.style.backgroundPosition = "0 -142px";
		}
		$('finButton').getElementsByTagName('a')[0].onmouseout = function() {
			this.style.backgroundPosition = "0 0";
		}
		$('finButton').getElementsByTagName('a')[0].onmousedown = function() {
			this.style.backgroundPosition = "0 -284px";
		}
	}
	//government image button
	if ($('govButton')) {
		$('govButton').getElementsByTagName('a')[1].onmouseover = function() {
			$('govButton').getElementsByTagName('a')[0].style.backgroundPosition = "-242px -142px";
		}
		$('govButton').getElementsByTagName('a')[1].onmouseout = function() {
			$('govButton').getElementsByTagName('a')[0].style.backgroundPosition = "-242px 0";
		}
		$('govButton').getElementsByTagName('a')[1].onmousedown = function() {
			$('govButton').getElementsByTagName('a')[0].style.backgroundPosition = "-242px -284px";
		}
		$('govButton').getElementsByTagName('a')[0].onmouseover = function() {
			this.style.backgroundPosition = "-242px -142px";
		}
		$('govButton').getElementsByTagName('a')[0].onmouseout = function() {
			this.style.backgroundPosition = "-242px 0";
		}
		$('govButton').getElementsByTagName('a')[0].onmousedown = function() {
			this.style.backgroundPosition = "-242px -284px";
		}
	}
	//jump to top of page hijax
	if ($('topBtn')) {
		$('topBtn').getElementsByTagName('a')[0].onclick = function() {
			self.scroll(0,0);
			return false;
		}
	}
	//email me back form
	if ($('emailBtn')) {
		$('emailBtn').onmouseover = function() {
			this.src = 'g/sendbthv.gif';
		}
		$('emailBtn').onmousedown = function() {
			this.src = 'g/sendbtdn.gif';
		}
		$('emailBtn').onmouseout = function() {
			this.src = 'g/sendbtup.gif';
		}
		$('emailBtn').form.onsubmit = function() {
			if ($('emailBtn').form.email.value != '') {
				$('emailBtn').disabled = "disabled";
				doAjaxPostEmail($('emailBtn').form.email.value,1);
			}
			return false;
		}
	}
	//email contact form button
	if ($('contactSndBtn')) {
		$('contactSndBtn').onmouseover = function() {
			this.src = 'g/wsndbthv.gif';
		}
		$('contactSndBtn').onmousedown = function() {
			this.src = 'g/wsndbtdn.gif';
		}
		$('contactSndBtn').onmouseout = function() {
			this.src = 'g/wsndbtup.gif';
		}
		$('contactSndBtn').form.onsubmit = function() {
			$('contactSndBtn').disabled = "disabled";
			//return false;
		}
	}
	//google maps
	if ($('map')) {
		$('map').style.border = '3px double #999';
		$('map').style.height = '300px';
		$('map').style.marginBottom = '1em';
		$('map').style.marginTop = '1.2em';
		//create new map
		var map = new GMap($("map"));
		var point = new GLatLng(51.733500444785875, -0.4614901542663574);
		map.addControl(new GSmallMapControl());
		//map.addControl(new GSmallZoomControl());
		map.centerAndZoom(point, 2);
		var marker = new GMarker(point);
		map.addOverlay(marker);
		var html = "<p><img src=\"g/exoffice.jpg\" alt=\"\" width=\"210\" height=\"100\" style=\"border:1px solid #ccc;\" \/><\/p>";
		marker.openInfoWindowHtml(html);
	}
	//main image drop shadow
	if ($('mainImg')) {
		var theImgTag = $('mainImg').getElementsByTagName('img')[0];
		$('mainImg').style.height = theImgTag.height + 'px';
		$('mainImg').style.background = 'url(g/dropshad.gif) bottom right';
		$('mainImg').style.position = 'relative';
		theImgTag.style.position = 'relative';
		$('mainImg').style.top = '9px';
		$('mainImg').style.left = '4px';
		theImgTag.style.top = '-4px';
		theImgTag.style.left = '-4px';
	}
}