// SMCrunch2 Version 2.0.1, Copyright (C) Smart Media Ltd 2001-2005. All Rights Reserved.
//
// !!! Note: JScript by default
//
/// (c) Copyright Smart Media Limited, 2008-2011.
///
///This Software is provided under a license and may not be modified, copied or altered in any
///way by Licensee's own personnel or by any third party. This Software or parts of it,
///or its documentation may not be provided, copied, printed out or otherwise made available to
///any other person. Any attempt to copy, modify or reverse engineer the Software is strictly
///prohibited.
///
///This Software may only be used on the equipment it is licensed for.
///
///Title, copyright and all other proprietary rights in the Software and the Documentation and all
///parts and copies thereof shall remain vested with Smart Media Limited.
///
///This Software and information in it is subject to change without notice.
var minlat = null;
var maxlat = null;
var minlng = null;
var maxlng = null;
var allPoints = new Array();
var latLngStore = new Array();
function addp(name, html, lat, lng, options, infooptions)
{
if( name == null )
name = '';
else
name = name.replace(/&amp;/g,'&');
if( maxlat == null || lat > maxlat ) maxlat = lat;
if( minlat == null || lat < minlat ) minlat = lat;
if( maxlng == null || lng > maxlng ) maxlng = lng;
if( minlng == null || lng < minlng ) minlng = lng;
var point = new GLatLng(lat,lng);
if( options == null )
options = { title: name };
else
options.title = name;
var marker = new GMarker(point,options);
GEvent.addListener(marker,"click",function() {marker.openInfoWindowHtml(html,infooptions);});
return marker;
}
function getMidLat()
{
if( maxlat != null && minlat != null )
return (maxlat+minlat)/2;
else
return null;
}
function getMidLng()
{
if (maxlng != null && minlng != null )
return (maxlng+minlng)/2;
else
return null;
}
function ltrim(s)
{
if (s == "" || s==null)
return "";
for (var i = 0;i < s.length;i++)
{
if (s.charAt(i) != ' ')
break;
}
if (i >= s.length)
return "";
return s.substring(i);
}
function rtrim(s)
{
if (s == "" || s ==null)
return "";
for (var i = s.length-1;i >= 0;i--)
{
if (s.charAt(i) != ' ')
break;
}
if (i < 0)
return "";
return s.substring(0, i+1);
}
function trim(s)
{
if (s == "" || s == null)
return "";
return ltrim(rtrim(s));
}
function validate_search(f)
{
if(f.eventmaps.checked)
f.showmap.value='Y';
else
f.showmap.value='N';
if(f.eventtype.selectedIndex == 0)
f.eventtype.value = '';
if(f.eventaudience.selectedIndex == 0)
f.eventaudience.value = '';
if(f.eventarea.selectedIndex == 0)
f.eventarea.value = '';
if(f.eventkeyword.value == 'Keywords')
f.eventkeyword.value = '';
f.submit();
}
function validate_postsearch(f)
{
if(f.eventpostcode.value == 'Your postcode')
f.eventpostcode.value = null;
var v = f.eventpostcode.value;
v = trim(v);
f.eventpostcode.value = v;
if( v != '' )
{
var geocoder = new GClientGeocoder();
var address = v+',UK';
geocoder.getLatLng(address,function(point){
if(!point)
{
alert( v+" is not a recognised postcode");
f.eventpostcode.focus();
return false;
}
else
{
var lat = point.lat();
var long = point.lng();
f.lat.value = lat;
f.long.value = long;
if( f.lat.value != '' && f.long.value != '' )
f.submit();
}
}
)
return false;
}
else
{
alert('Please enter a postcode');
f.eventpostcode.focus();
return false;
}
}
function inputreturn(vform, e)
{
var keynum;
var keychar;
if(window.event) 
keynum = e.keyCode;
else if(e.which) 
keynum = e.which;
keychar = String.fromCharCode(keynum);
if(keychar.charCodeAt(0)==13)
{
vform.onsubmit(vform);
return false;
}
}
function showHideMap()
{
var mapdiv = document.getElementById('map');
var adiv = document.getElementById('showmap');
if(adiv.className=='open')
{
adiv.className = "closed";
mapdiv.style.display='none';
}
else
{
adiv.className = "open";
mapdiv.style.display='block';
}
}
function addPointToArray(point)
{
var found = null;
if(latLngStore != null && typeof(latLngStore) != 'undefined')
{
var check = latLngStore[point.lat+','+point.long];
if(check != null && typeof(check) == 'integer')
{
if(allPoints[check] != null && typeof(allPoints[check]) != 'undefined')
found = check;
}
}
if(allPoints != null && typeof(allPoints) != 'undefined' && found == null)
{
for(var i=0;i<allPoints.length;i++)
{
var pt = allPoints[i];
if(pt.lat == point.lat && pt.long == point.long)
{
found = i;
break;
}
}
}
if(found != null)
allPoints[found].disp += point.disp;
else
{
var idx = allPoints.push(point);
if(latLngStore != null && typeof(latLngStore) != 'undefined')
latLngStore[point.lat+','+point.long] = idx;
}
}
function createPoint(name, display, lat, long, options, infooptions)
{
var o      = new Object();
o.name = name;
o.disp = display;
o.lat  = lat;
o.long = long;
o.options = options;
o.infooptions = infooptions;
addPointToArray(o);
}
function createPopulateMap(id, bubbleclass, ll, zlevel)
{
if (GBrowserIsCompatible())
{
var map = new GMap2(id);
map.addMapType(G_NORMAL_MAP);
if( bubbleclass == null ) bubbleclass = 'mapbubble';
for(var i=0;i<allPoints.length;i++)
{
if(i == 0 && ll == null)
map.setCenter(new GLatLng(allPoints[0].lat, allPoints[0].long), (zlevel == null?11:zlevel));
else if(i == 0)
map.setCenter(ll, (zlevel == null?11:zlevel));
map.addOverlay(addp(allPoints[i].name, '<div class="'+bubbleclass+'"><dl>'+allPoints[i].disp+'</dl></div>',
allPoints[i].lat, allPoints[i].long, allPoints[i].options, allPoints[i].infooptions));
}
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
map.addControl(new GMapTypeControl());
var nlat = getMidLat();
var nlng = getMidLng();
if( nlat != null && nlng != null )
{
var bl = new GLatLng(minlat, minlng);
var tr = new GLatLng(maxlat, maxlng);
var bounds = new GLatLngBounds(bl,tr);
if(zlevel == null)
map.setZoom(map.getBoundsZoomLevel(bounds));
if(ll == null)
map.panTo(new GLatLng(nlat, nlng));
}
}
}
function createmarker_v3(lat, long, icon, title)
{
var marker = new google.maps.Marker({
position: new google.maps.LatLng(lat, long),
title: title,
icon: icon
});
return marker;
}
function createDirctionRequest(origin, destination)
{
var dr = {origin: origin,
destination: destination,
travelMode: google.maps.DirectionsTravelMode.DRIVING,
unitSystem: google.maps.DirectionsUnitSystem.IMPERIAL};
return dr;
}
function singleMap_createRoute(start, end)
{
var request = createDirctionRequest(start, end);
var dirDisplay = this.dirDisplay;
this.dirService.route(request, function(result, status)
{
if (status == google.maps.DirectionsStatus.OK)
{
dirDisplay.setDirections(result);
}
else
{
alert("Invalid postcode or address.");
}
});
}
function singleMap_create()
{
var options = {
zoom: this.zoom,
center: this.centre,
mapTypeId: this.mapTypeId,
scaleControl: this.scaleControl
}
this.map = new google.maps.Map(document.getElementById(this.mapid), options);
this.setPoints();
this.dirService = new google.maps.DirectionsService();
this.dirDisplay = new google.maps.DirectionsRenderer();
this.dirDisplay.setMap(this.map);
this.geocoder = new google.maps.Geocoder();
}
function singleMap_addPoint(marker)
{
if(marker != null)
{
this.points.push(marker);
}
}
function singleMap_setPoints()
{
var plen = this.points.length;
for(var p=0;p<plen;p++)
{
this.points[p].setMap(this.map);
}
}
function singleMap_showDirections(dirid)
{
var dir_div = document.getElementById(dirid);
this.dirDisplay.setPanel(dir_div);
dir_div.style.display = 'block';
}
function singleMap()
{
this.zoom = 15;
this.mapTypeId = google.maps.MapTypeId.ROADMAP;
this.scaleControl = false;
this.mapid = "map";
this.points = new Array();
this.create = singleMap_create;
this.addPoint = singleMap_addPoint;
this.setPoints = singleMap_setPoints;
this.createRoute = singleMap_createRoute;
this.showDirections = singleMap_showDirections;
}
function submitroute(form, map, dirid)
{
var geoRetFun = function(results, status)
{
if (status == google.maps.GeocoderStatus.OK)
{
map.createRoute(results[0].geometry.location, map.points[0].position)
map.showDirections(dirid);
}
else
{
alert("Invalid postcode or address.");
}
}
map.geocoder.geocode( { 'address': form.start.value}, geoRetFun);
return false;
}

