
function fetchDirectory(directory) {
	opt = directory.selectedIndex;
	page = "local-business-directories.php?book=" + directory.options[opt].value;
	if (page != "") {
		window.location = page
	}
}

function fetchMap(directory) {
	opt = directory.selectedIndex;
	page = "local-maps.php?book=" + directory.options[opt].value;
	if (page != "") {
		window.location = page
	}
}

function fancyBorder(formelement) {
	formelement.style.borderStyle='solid';
	formelement.style.borderColor='navy';
	formelement.style.borderWidth='1px';
}

function plainBorder(formelement) {
	formelement.style.borderStyle='solid';
	formelement.style.borderColor='#007CC4';
	formelement.style.borderWidth='1px';
}

function doSearch() {
	var xmlhttp;
	xmlhttp = null;

	who = document.search.who.value;
	what = document.search.what.value;
	where = document.search.where.value;
	if (!who && !what) {
		alert("No values entered");
		document.search.what.focus();
		return;
	}

	who = escape(who);
	what = escape(what);

	if (window.XMLHttpRequest) {
		// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else if (window.ActiveXObject) {
		// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (xmlhttp!=null) {
		xmlhttp.onreadystatechange=function () {
			if (xmlhttp.readyState==4) {// 4 = "loaded"
				document.getElementById('content').innerHTML=xmlhttp.responseText;
			}
		}
		url = "search.php?who=" + who + "&what=" + what + "&where=" + where;
		xmlhttp.open("GET",url,true);
		xmlhttp.send(null);
	}
}

function showThem(who, what, where) {
	var xmlhttp;
	xmlhttp = null;

	who = escape(who);
	what = escape(what);

	if (window.XMLHttpRequest) {
		// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else if (window.ActiveXObject) {
		// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (xmlhttp!=null) {
		xmlhttp.onreadystatechange=function () {
			if (xmlhttp.readyState==4) {// 4 = "loaded"
				document.getElementById('content').innerHTML=xmlhttp.responseText;
			}
		}
		url = "results.php?who=" + who +"&what=" + what + "&where=" + where;
		xmlhttp.open("GET",url,true);
		xmlhttp.send(null);
	}
}

function show(url) {
	var xmlhttp;
	xmlhttp = null;

	if (window.XMLHttpRequest) {
		// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else if (window.ActiveXObject) {
		// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (xmlhttp!=null) {
		xmlhttp.onreadystatechange=function () {
			if (xmlhttp.readyState==4) {// 4 = "loaded"
				document.getElementById('content').innerHTML=xmlhttp.responseText;
				if (url.indexOf("contact.php") != -1) {				
					hqMap();
				}
				if (url.indexOf("maps.php") != -1) {				
					lat = document.getmap.lat.value;
					long = document.getmap.long.value;
					zoom = document.getmap.zoom.value;
					generalMap(lat, long, zoom);
				}
				if (url.indexOf("more.php") != -1) {				
					lat = document.getmap.lat.value;
					long = document.getmap.long.value;
					zoom = document.getmap.zoom.value;
					icon = document.getmap.icon.value;
					privateMap(lat, long, zoom, icon);
				}
			}
		}
		xmlhttp.open("GET",url,true);
		xmlhttp.send(null);
	}
}

function hqMap() {
	lat = 51.443723306215325;
	long = -2.610347270965576;
	zoom = 15;
	if (GBrowserIsCompatible()) {
		var map = new GMap2(document.getElementById("hqmap"));
		map.addControl(new GSmallMapControl());
		map.setCenter(new GLatLng(lat, long), zoom);
		var icon = new GIcon();
		icon.image ="images/wearehere.png";
		icon.iconSize = new GSize(70, 50);
		icon.iconAnchor = new GPoint(35, 47);
		icon.infoWindowAnchor = new GPoint(35, 20);
		var point = new GLatLng(lat, long);
		var marker = new GMarker(point, icon);
		GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml("You can contact us on<br>Bristol (<b>0117</b>)<b> 923 1122</b><br>Or use the email form below<br>We're waiting for your call !");});
		map.addOverlay(marker);
	}
}

function privateMap(lt, lg, zm, icon) {
	lat = parseFloat (lt);
	long = parseFloat (lg);
	zoom = parseInt (zm);
	if (GBrowserIsCompatible()) {
		var map = new GMap2(document.getElementById("privatemap"));
		map.addControl(new GSmallMapControl());
		map.setCenter(new GLatLng(lat, long), zoom);
		if (icon == "Yes") {
			var icon = new GIcon();
			icon.image ="images/wearehere.png";
			icon.iconSize = new GSize(70, 50);
			icon.iconAnchor = new GPoint(35, 47);
			icon.infoWindowAnchor = new GPoint(35, 20);
			var point = new GLatLng(lat, long);
			var marker = new GMarker(point, icon);
			map.addOverlay(marker);
		}
	}
}

function generalMap(lt, lg, zm) {
	lat = parseFloat (lt);
	long = parseFloat (lg);
	zoom = parseInt (zm);
	if (GBrowserIsCompatible()) {
		var map = new GMap2(document.getElementById("generalmap"));
		map.setCenter(new GLatLng(lat, long), zoom);
		map.addControl(new GSmallMapControl());
		map.addControl( new GOverviewMapControl(new GSize(100,100)));		
		map.addControl(new GMapTypeControl());
	}
}

