function noframes() 
{
if (top != self) top.location.replace(self.location.href);  
}


function validemail()
{

var emailcheck  = new RegExp ("^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$");
	
if (((document.getElementById('email').value))!="")
	{

		if (!emailcheck.test(document.getElementById('email').value))
			{
				alert('Invalid format for email address.  Please try again.');
				return false;
			}
	
	}

return true
}


// map stuff

	
	var map, marker; 

	function status(msg)
	{
		document.getElementById('status').innerHTML = msg;
	}


    function loadMap(id){
      if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("map"));
        //map.setCenter(new GLatLng(51.05, -0.72), 13);
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		map.addControl(new GScaleControl());
		ajaxrequest('http://www.amerc.ac.uk/institutions.php',
					'id='+id+'&action=getxml',
						institutionMapCallback, 'GET' );
	  }
    }

	function loadMapForEntry(id)
	{
		if(GBrowserIsCompatible())
		{
			map=new GMap2(document.getElementById("map"));
			map.addControl(new GLargeMapControl());
			map.addControl(new GMapTypeControl());
			map.addControl(new GScaleControl());
			GEvent.addListener(map,'click',addLocation);
			if (id>0)
			{
				ajaxrequest
					('http://www.amerc.ac.uk/institutions.php',
					'id='+id+'&action=getxml',
						institutionMapCallback, 'GET' );
			}
			else
			{
        		map.setCenter(new GLatLng(51, 0), 7);
			}
		}
	}

	function addLocation(mrkr,location)
	{
		document.getElementById('lat').value = location.lat();	
		document.getElementById('lon').value = location.lng();	
		setLocation(location);
	}

	function setLocation(location)
	{
		if (marker)
			marker.setPoint(location);
		else
		{
			marker = new GMarker(location);
			map.addOverlay(marker);
		}
	}

	function showLocationOnMap()
	{
		var location = new GLatLng
			(
		document.getElementById('lat').value,
		document.getElementById('lon').value
			);
        map.setCenter(location, 13);
		setLocation(location);
	}

	function institutionMapCallback (xmlHTTP)
	{
		var inst = xmlHTTP.responseXML.getElementsByTagName("institution")[0];
		var lat = getTagValue(inst,'lat');
		var lon = getTagValue(inst,'lon');
        map.setCenter(new GLatLng(lat, lon), 13);
		var name = getTagValue(inst,'name');
		var p = new GLatLng(lat,lon);
		marker = new GMarker(p);
		GEvent.addListener(marker,"click",function()
			{ marker.openInfoWindowHtml(name) }
		);
	  	map.addOverlay(marker);
    }
