        var map = null;
		var token="";
        var finding = false;
        var IsRouteByClick = false;
        var IsMapActive = true;
        var popuplat;
        var popuplon;
        
        
        
        var startpt;
        var endpt;
        
        function validate() { 
			var str = ""; 
			var elements = document.getElementsByTagName('input'); 

			// loop through all input elements in form 
			for(var i = 0; i < elements.length; i++) { 

				// check if element is mandatory; ie has a pattern  
				var pattern = elements.item(i).getAttribute('pattern'); 
				if (pattern != null) { 
					var value = elements.item(i).value; 

					// validate the value of this element, using its defined pattern 
					var offendingChar = value.match(pattern); 

					// if an invalid character is found 
					if(offendingChar != null) { 

					// add up all error messages 
					str += elements.item(i).getAttribute('errorMsg') + "\n" + 
							"Invalid character(s): '" + offendingChar + "' \n"; 

					// notify user by changing background color, in this case to red 
					//elements.item(i).style.background = "red";  
					} 
				} 
			}  

			if (str != "") { 
				// do not submit the form 
				alert("ERROR ALERT!!\n" +str);  
				return false; 
			} else { 
				// form values are valid; submit 
				return true; 
			} 
		}
		
        function GetMap()
        {
            map = new VEMap('UKMap');
            map.LoadMap(new VELatLong(54.928662,-3.006462),5,'r',false,VEMapMode.Mode2D,false);
            map.AttachEvent("onchangeview", ViewChange);
            map.AttachEvent("onclick", removepopupmenu);
	        
        }
        
        function removepopupmenu(e)
        {
            document.getElementById('searchForm').style.display = "none";
            
        }
        
        function getAllStations(type)
        {
            map.DeleteAllPushpins();
            var l = new VEShapeLayer();	
            var veLayerSpec = new VEShapeSourceSpecification(VEDataType.GeoRSS, "UKDistributorsRss.xml", l);
            map.ImportShapeLayerData(veLayerSpec,onFeedLoad);
        }
        
                
         function onFeedLoad(layer)
        {
            document.getElementById('searchForm').style.display = "none";
            document.getElementById('RESULTS').style.display = "none";
            var numShapes = layer.GetShapeCount();
			for(var i=0; i < numShapes; ++i)
			{
				var s = layer.GetShapeByIndex(i);
				s.SetCustomIcon("<img src='images/gasTruckIcon.gif'/>");
			}

        }

                
        function DeletePin(pinId)
        {  
            var len = map.pushpins.length;
            var pointSetUp = false;
            
            
            if (len > 0)
            {
                for (i=0; i<len; i++)
                {
                    if (map.pushpins[i].ID == pinId)
                        pointSetUp = true;
                }
                
                try {
                    if (pointSetUp)
                        map.DeletePushpin(pinId);
                    else
                    {}
                }              
                
                catch (err)
                {
                    alert(err.message);
                }
            
            }
            else
            {}
         } 
        
                    
        function GetXmlHttp()
        {
            var x = null;
            try
            {
                x = new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch (e)
            {
                 try
                {
                    x = new ActiveXObject("Microsoft.XMLHTTP");
                }
                catch (e)
                {
                    x = null;
                }
                
            }
            
            if (!x && typeof XMLHttpRequest != "undefined")
            {
                x = new XMLHttpRequest();
            }
            
            return x;
        }
            
         function rightTrim(sString) 
         {
            while (sString.substring(sString.length-1, sString.length) == ' ')
            {
                sString = sString.substring(0,sString.length-1);
            }
            return sString;
         }
         
         function ResetFields()
         {
            document.getElementById('txtStreet').value = "";
            document.getElementById('txtCity').value = "";
            document.getElementById('txtZip').value = "";
                     
         }
         
         function BuildAddress(street,city,zip)
         {
            var address = "";
            if (street != "") {
                address += street;
                if (city != "")
                    address += ", " + city;
                else
                    return;
                    
                if (zip != "")
                    address += " " + zip + ", UK";
                else
                    address += ", UK";
             }
             else {
                if (city != "")
                {
                    address += city;
                    if (zip != "")
                      address = zip + ", UK";
                    else
                      address = city + ", UK";
                            
                }
                else {
                    if (zip != "")
                      address = zip + ", UK";
                    else 
                      return address;
                } 
             }                   
             return address;
        }
         
			var txtWhere = "";
            function FindNear()
            {
				if (document.getElementById('chkUKOutlets').checked) {
					getAllStations();
					document.getElementById("searchForm").style.display = "none";
					return;
				}
				var street = document.getElementById('txtStreet').value;
                var city = document.getElementById('txtCity').value;
                var zip = document.getElementById('txtZip').value;
			    document.getElementById("searchForm").style.display = "none";
				map.DeleteAllPushpins();
				txtWhere = "";
				
			    txtWhere = BuildAddress(street,city,zip);
			    try
			    {
                    map.Find('',txtWhere);
                }
                catch(e)
                {
                    alert("The requested location cannot be found. Check your input.");
                }
                finding = true;
                
            }
            
            function findCompleted()
            {
            finding = false;
            
            
            }

            function ViewChange()
            {
            if (finding)
                findCompleted();
            }
             
                                   
            
            
            function ShowPanel()
            {
                
                var e = window.event;
                
                if (e.srcElement.id == "imgSearch" && IsMapActive)
                {
                    document.getElementById("searchForm").style.display = "block";
                }
                
            }
            
            function GetRegionList()
			{
				var xmlhttp = GetXmlHttp();
                var url = "UKDistributorLocator.aspx?type=RegionList";
                if (xmlhttp)
                {
                    xmlhttp.onreadystatechange = function()
                    {
                        if (xmlhttp.readyState == 4)
                        {
                            //alert(xmlhttp.status);
                            if (xmlhttp.status == 200)
                            {
                                var result = xmlhttp.responseText;
                                var temp = result.split("<!");
                                result = temp[0];
                                                                
                                //eval(result);
                                document.getElementById('RESULTS').style.display = "none";
                                //document.getElementById('progress').className = "off";
                                //document.getElementById('RESULTS').innerHTML = "<xmp>" + result + "</xmp>";
                                document.getElementById('RegionList').innerHTML = result;
                            }
                        }
                    }
                    xmlhttp.Open("GET", url, true);
                    xmlhttp.send(null);
                 }
			} 

        function Close()
         {
            var eSrc = window.event.srcElement;
                
            if (eSrc.id == "imgClose")
            {
               ResetFields();
               document.getElementById('formPanel').style.display = "none";
            }
            else {
				document.getElementById('divDirections').style.display = "none";
				document.getElementById('forPrint').innerHTML = "";
				document.getElementById('divDir').style.display = "none";
				
                
            }
         }
         
         function window.onbeforeprint()
         {
			if (dd.elements["divDirections"] != null) {
              dd.elements.divDirections.hide();
            }
         }
         
         function window.onafterprint()
         {
			if (dd.elements["divDirections"] != null) {
              dd.elements.divDirections.show();
            }
         }
                 
         function printMap() {
           			
            if (window.print) {
                window.print();
                
            }
            else
                alert("Sorry, your browser doesn't support this feature.");
         }


