// JavaScript Document

function trimStr(str)
{
    while(str.charAt(0) == (" ") )	
    {
	    str = str.substring(1);	
    }
    while(str.charAt(str.length-1) == " " )
    {
	    str = str.substring(0,str.length-1);	
    }	
    return str;
}

function setFocus() {
    enquiryForm.yourName.focus();
    enquiryForm.yourName.select();	
}

function checkEnquiry() {

    if (trimStr(enquiry_form.your_name.value) == ""){ 
        alert("Please give your name");
        enquiry_form.your_name.focus();
        enquiry_form.your_name.select();
        return false;
    }

    if ((trimStr(enquiry_form.your_phone.value) == "") && (trimStr(enquiry_form.your_email.value) == "" )){ 
        alert("Please provide a method of contact");
        enquiry_form.your_phone.focus();
        enquiry_form.your_phone.select();
        return false;
    }

    if (trimStr(enquiry_form.your_message.value) == ""){ 
        alert("Please write a message");
        enquiry_form.your_message.focus();
        enquiry_form.your_message.select();
        return false;
    }

    return true;
	
}

function loadPage(page){
    if(page == "directions.php"){
	    loadMap('thornboro_henge');
	}
    if(page == "thornboro.php"){
	    loadMap('thornboro_central');
	}	
}

function loadMap(strZone) {

  var intLati = 54.092925;
  var intLong = -1.403680; 
  var intZoom;
  
  if (strZone == "thornboro_henge"){
      intLati = 54.210200;
      intLong = -1.564100; 
	  intZoom = 11;
	  strInfo = "<strong>Thornborough<br />central Henge</strong><br />";
  } 
  
  if (strZone == "thornboro_central"){
      intLati = 54.210100;
      intLong = -1.564100;
      intZoom = 14;	  
  }   

  if (GBrowserIsCompatible()) {	
  
		var map = new GMap2(document.getElementById("map"));
		
		GEvent.addListener(map, "moveend", function() {
		    var centerLng = map.getCenter().lng()
		    var centerLat = map.getCenter().lat() 
        });

		map.setCenter(new GLatLng(intLati, intLong), intZoom);
		var centerLng = map.getCenter().lng()
		var centerLat = map.getCenter().lat() 
		 
		map.addControl(new GSmallMapControl());	
        //map.addControl(new GMapTypeControl()); 
		if (strZone == "thornboro_central"){
            map.setMapType(G_SATELLITE_MAP); 
        }else{
		    map.addControl(new GMapTypeControl()); 
		    map.setMapType(G_NORMAL_MAP); 

            function createMarker(point, number) {
                var marker = new GMarker(point);
                GEvent.addListener(marker, "click", function() {
                    marker.openInfoWindowHtml(strInfo);
                });
                return marker;
            }
		    var point = new GLatLng(intLati, intLong);				  
            map.addOverlay(createMarker(point, 1));
			
		}   
			
    }

}
