
//start of google maps code (map)

    var map;

    var kml_camera = new GGeoXml("http://www.solwayenergygateway.co.uk/kml/kml_email.kml");
    var draggedYN = 'N'; 
    var geocoder = null;
    var smallMapPoint;
    var Smap;
    var Mark = '1';



function onLoad() {

  if (GBrowserIsCompatible()) 
  
  	{
	
	    map = new GMap2(document.getElementById("map"));
	    map.addControl(new GMapTypeControl());
	    map.addControl(new GSmallMapControl());
	    map.setCenter(new GLatLng(54.82759016780595, -3.40576171875), 9,G_HYBRID_MAP); 
	    geocoder = new GClientGeocoder();
	    map.addOverlay(kml_camera);
	    map.enableContinuousZoom();      
        map.enableScrollWheelZoom();
		

	}
	

   
} 



function onLoad_1() {

  if (GBrowserIsCompatible()) 
  
  	{
	
	    Smap = new GMap2(document.getElementById("Smap"));
	  //  Smap.addControl(new GMapTypeControl());
	    Smap.addControl(new GSmallMapControl());
	    Smap.setCenter(new GLatLng(54.82759016780595, -3.40576171875), 6,G_HYBRID_MAP); 
	    geocoder = new GClientGeocoder();
	    Smap.addOverlay(kml_camera);
	    Smap.enableContinuousZoom();      
        Smap.enableScrollWheelZoom();

	}
	

   
} 





 function showAddress(address) 
  {
   if (geocoder) 
     {
       geocoder.getLatLng(
       address,
          function(point) 
             {
               if (!point) 
                {
                 // alert(address + " was not found \nPlease try again");
                  document.input_db.Name_1.focus;
                  document.getElementById("noPostcode").value = address;
                } 
             
               else 
                    {
                    
                                  
                     // change the number in red below to zoom in further when plotting your point
                    // map.setCenter(point, 16);
                    
				         
				         
                     var marker = new GMarker(point, {draggable: true});
                     //map.addOverlay(marker);
                     




                    //check to see if icon has moved
                        GEvent.addListener(marker, "dragstart", function() 
                        {
					      	map.closeInfoWindow();
					    });
					
					    GEvent.addListener(marker, "dragend", function() 
					    {
					     	//marker.openInfoWindowHtml("TEST");
					     	
					     	                    var LatLong = new Array();
							                    LatLongArray = marker.getLatLng().toString().split(' ');
							                   
							                    //alert(LatLongArray);

							                    var Lat=LatLongArray[0];
							                    Lat = Lat.replace(/\(/,"");
							                    Lat = Lat.replace(/\,/,"");
							                    
							                    //alert(Lat)
							                    
							                    var Long=LatLongArray[1];
							                    Long = Long.replace(/\)/,"");
							                    Long = Long.replace(/\,/,"");
							                    
							                   // alert(LatLongArray);
							                    
							                   document.getElementById("placemark").value = Long+","+Lat+",0";
							                    
							                  //  document.getElementById("placemark").value = Long+","+Lat+",0";
							                    //document.getElementById("placemark").value = LatLongArray;
							                    

					     					//marker.openInfoWindowHtml("TEST");
					     			
					     	
							 		//alert (document.getElementById("placemark").value);
									
									draggedNY = 'Y';
								
								
								//marker.setLatLng(getCenter());
					     			
					    });




         
                     
                     map.setCenter(point, 12);
                               
					//alert (Mark);	
		       
		       
		       
		       
					 if(Mark == '1') 
				         { 
				
                    		map.addOverlay(marker);
                    	//	alert ("created marker");
                    		Mark = '0';
                    	//	marker.openInfoWindowHtml("TEST");
                    		map.removeOverlay(kml_camera);
                    //	alert (Mark);
                    
                         }
                         
                         
                     else 
                     
						{
						
		     		map.setCenter(new GLatLng(54.901882187385006, -3.4716796875), 5,G_HYBRID_MAP); 
						//showAddress(document.getElementById("address").value)
						//54.901882187385006, -3.4716796875
						
						
						
							//	alert (getCenter());
							
							//var newcent = map.getCenter();
						//	map.removeOverlay(marker);
						//	map.marker.setLatLng(new GLatLng(54.901882187385006, -3.4716796875));
						//	alert("before move");
							
							
						//	 map.removeOverlay(marker);
							
                   			//  var marker = new GMarker(point, {draggable: true});
									
						//	map.addOverlay(marker);
							
							
							//marker.setLatLng(new GLatLng(55.378051, -3.435973));
							
							//marker.openInfoWindowHtml("TEST");
							
							//alert (marker.getLatLng() );//setLatLng(getCenter());
							
							//	alert ((new GLatLng(55.378051, -3.435973)));
							
						//	marker.openInfoWindowHtml("TEST");
                     		
						}  
                    
                    // convert the point on the map to be passed to the the array for entry into form
                    

                    
                    
                    var center = point;
                    
                    //alert(point+" "+center)
                    
                    
                    
                    // .001000    need to add this to the long and lat to offset the pointer slightly (harder to track down postcode from the lat + long then.
                    
                    
                    
                    var LatLong = new Array();
                    LatLongArray = center.toString().split(' ');
                    
                    
                    var Lat=LatLongArray[0];
                    Lat = Lat.replace(/\(/,"");
                    Lat = Lat.replace(/\,/,"");
                    
                    var Long=LatLongArray[1];
                    Long = Long.replace(/\)/,"");
                    Long = Long.replace(/\,/,"");
                    
                    document.getElementById("placemark").value = Long+","+Lat+",0";
                    

                    
                   // document.getElementById("noPostcode").value = address;
                    
                    document.getElementById("postcode_tab").value = address;
                    
                    
                    
                    //END ALERT BOX    alert("END");
                   // alert('"END');
                    
                    }
             });
             
            
      } 
 }
 
 
 
 
 
 
 
 
//end of google maps code (map)
