﻿//Author:       Leigh Milton
//Company:      Lucrosus Software Limited
//Date Created: 06/02/2006
//Version:      3.0
//Last Modified: 02/05/2007
//Updated JS file to include additional functions mainly List View
//Copyright Notice:
//This page contains code that is Copyright Lucrosus Software Limited 2007
//You may not copy it without permission from Lucrosus Software Limited
     
//--Declare Global BizMap Variables
//var ServerLocation = 'http://mapcontrolstaging.bizmappro.com/';
var ServerLocation = 'http://mapcontrol.bizmappro.com/';
//var ServerLocation = 'http://87.194.16.107/BizMapLoad/';
var AccountKey,map,div,MapLeft,MapTop,ListLng=0,ListLat=0,CurrLng,CurrLat,MyPostion = 0,CurrZoom,CurrType,url,SubKey,SessionID;
var NewTop = 0,NewLeft= 0,ClusterCount = 0,LastSearch = '',PosSeaActive = 0,ListView = 0,PageID = 1,PageStart = 1,ViewMode = '',DuelMode = 0,PNGFixActive = false;
var browserType = '',browserVersion = '', APICategoryString = '', APIFilterString = '', APISearchValue = '', ListRtnFunc = '', MapRtnFunc = '', LoadRtnFunc = '', MapSearchLoad = 0, HasSearched = false, GeoFilter = '', ShowResultsInView = true;
var SearchLat=0,SearchLng=0,SearchPrefOverideActive = 0;
var mapDir;
var gdir;
var UniquePositionID = '';
var DirGeo = false;
var MarkerCallBackFunction = '';
var InfoScreenTemplateHTML = '';

//--Main Function Call from HTML page to return Control HTML
function BizMapLoad(AccKey,LoadReturn,ListReturn,MapReturn,OverideSearchPref,Dimensions) {

    var ControlDimensions = '';
    
    if (navigator.appName == "Microsoft Internet Explorer")
    {
        var arVersion = navigator.appVersion.split("MSIE");
        browserType = "IE";
        browserVersion = parseFloat(arVersion[1]);
        if (browserVersion >= 5.5 && browserVersion < 7)
            PNGFixActive = true;
    }
    else
    {
        browserType= "NonIE";
        browserVersion = "0";
    }
     
    AccountKey = AccKey;
    
    if (LoadReturn != null)
        LoadRtnFunc = LoadReturn;
        
    if (ListReturn != null)
        ListRtnFunc = ListReturn;
        
    if (MapReturn != null)
        MapRtnFunc = MapReturn;
    
    if (OverideSearchPref != null)
	    {
	        if (OverideSearchPref == 1) 
	            SearchPrefOverideActive = 1;
	    }
	
	if (Dimensions != null)
	    ControlDimensions = Dimensions;
                
    //Build Session Varaible
    var TdyDate = new Date()
    
    SessionID = TdyDate.getDay().toString() + TdyDate.getMonth().toString() + TdyDate.getFullYear().toString() + "_" + TdyDate.getHours().toString() + TdyDate.getMinutes().toString() + TdyDate.getSeconds().toString() + TdyDate.getMilliseconds().toString() + "_" + Math.random();
        
    ServerJavascriptRequest(ServerLocation + "BuildControlv2.aspx?acckey=" + AccountKey + "&refer=http://" + window.location.host + "&LoadMain=0&SessionID=" + SessionID + "&BT=" + browserType + "&BV=" + browserVersion + "&LR=" + LoadRtnFunc + "&OverideSearchPref=" + SearchPrefOverideActive + "&Dimensions=" + ControlDimensions);
}

//Function Called if Control Returns correctly
function BizMapLoaded() {
     document.getElementById("BizMap").innerHTML = BizMapHTML.replace(/~/g,"'");
     
     //Load Key Variables
     var Options = document.getElementById("Variables").value.split("|");

     //Check if Map and List are switch on which indicates Duel Mode
     DuelMode = parseInt(Options[9]);
     GeoFilter = Options[10];
     InfoScreenTemplateHTML = document.getElementById("information_overlay").innerHTML;

     if (Options[11] == 0)
        ShowResultsInView = false;
            
    if (parseInt(Options[6]) == 1)
        {
        HasSearched = true;
        ListView = 1;
        ViewMode = "List";
        Map_LoadListOnly(Options);
        }
    else
        {
        ViewMode = "Map";
        Map_Load(Options);
        }

               
    //Release Objects
    Options = null;
}

function PostLoadResults(ListView)
{
var Options = document.getElementById("Variables").value.split("|");
if (parseInt(Options[6]) == 1)
    {
    if (parseInt(Options[8]) == 0)
        LoadListView(PageID,PageStart);
    }
else
    {
    if (parseInt(Options[8]) == 0)
        Map_AjaxLoadPointers();
    }
}

//This function is called when LoadMain is set to 1 after show results on load is false
function BizMapLoadStartUpSearch()
{
if (ViewMode == "List")
    {
        if (LastSearch != "")
            {
            document.getElementById("txtSearch").value = LastSearch;
            LastSearch = "";
            DoSearch();
            }
        else
            LoadListView(PageID,PageStart);
     }
    
if (ViewMode == "Map")
    {
        if (LastSearch != "")
            {
            document.getElementById("txtSearch").value = LastSearch;
            LastSearch = "";
            DoSearch();
            }
        else
            Map_AjaxLoadPointers();
    }
}

//Function Called if Control Returns an error
function BizMapLoadedError() {
    document.getElementById("BizMap").innerHTML = BizMapHTML;
}

function BizMapListLoadedError() {
    document.getElementById("BizMap").innerHTML = BizMapListHTML;
}

//Function Called when show positions on load is false and search has been clicked
function BizMapLoadWithSearch() 
{   
    LastSearch = document.getElementById("txtSearch").value;
    ServerJavascriptRequest(ServerLocation + "BuildControlv2.aspx?acckey=" + AccountKey + "&refer=http://" + window.location.host + "&LoadMain=1&SessionID=" + SessionID + "&BT=" + browserType + "&BV=" + browserVersion);
}

//Main Function Call for the Loading of the Map	in Map only and Map Drive Mode
function Map_Load(Options) {        
            
    CurrLat=Options[0];
    CurrLng=Options[1];
    CurrZoom=parseInt(Options[2]);
    CurrType=parseInt(Options[3]);
    url=Options[4];
    PosSeaActive = Options[5];
  
    if (CurrType==0)
        CurrType = G_NORMAL_MAP;
    if (CurrType==1)
        CurrType = G_SATELLITE_MAP;
    if (CurrType==2)
        CurrType = G_HYBRID_MAP;
        
    if (GBrowserIsCompatible()) 
    {     
        document.getElementById("map").style.display = "";
        map = new GMap2(document.getElementById("map"));
        MapLeft = document.getElementById("map").offsetLeft;
        MapTop = document.getElementById("map").offsetTop;
        
        SetupMapOverlayFunction();
        
        if (browserType == "IE")
        	var pos = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(0,0));
	    else
         	var pos = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(0,0));
         	
        var pos1 = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(-1,-1)); 
            
        pos.apply(document.getElementById("map_overlay")); 
        pos.apply(document.getElementById("location_overlay")); 
        pos.apply(document.getElementById("drivingdirections_overlay"));
        pos.apply(document.getElementById("information_overlay"));
        pos1.apply(document.getElementById("listview_overlay"));
        document.getElementById("listview_overlay").style.width = parseInt(document.getElementById("listview_overlay").style.width) + 2 + "px" ;
        document.getElementById("listview_overlay").style.height = parseInt(document.getElementById("listview_overlay").style.height) + 2 + "px"
        document.getElementById("map").appendChild(document.getElementById("map_overlay")); 
        document.getElementById("map").appendChild(document.getElementById("location_overlay"));
        document.getElementById("map").appendChild(document.getElementById("drivingdirections_overlay"));
        document.getElementById("map").appendChild(document.getElementById("information_overlay"));
        document.getElementById("map").appendChild(document.getElementById("listview_overlay")); 

                        
        map.setCenter(new GLatLng(CurrLat, CurrLng), CurrZoom);
        map.setMapType(CurrType);

        document.getElementById("map_overlay").style.display = "none";
        document.getElementById("lblStatus").style.display = "none";
           
        GEvent.addListener(map, "dragend", function() {Map_ResetSearch(); Map_AjaxLoadPointers();});
        //GEvent.addListener(map, "zoomend", function() {Map_AjaxLoadPointers();});
    }
    
    //Release Objects
    Options = null;
    TdyDate = null;
    pos = null;
}

//Main Function Call for the Loading of the Map	in List only and List Drive Mode
function Map_LoadListOnly(Options) {     
       
    CurrLat=0;
    CurrLng=0;
    ListLng=0;
    ListLat=0;
    CurrZoom=parseInt(Options[2]);
    CurrType=parseInt(Options[3]);
    url=Options[4];
    PosSeaActive = Options[5];
      
    if (CurrType==0)
        CurrType = G_NORMAL_MAP;
    if (CurrType==1)
        CurrType = G_SATELLITE_MAP;
    if (CurrType==2)
        CurrType = G_HYBRID_MAP;
                
    document.getElementById("map_overlay").style.position = "absolute";
    //if (browserType == "IE")
    //{    
    document.getElementById("map_overlay").style.marginTop = "1px";
    document.getElementById("map_overlay").style.marginLeft = "1px";
   // }
    
    document.getElementById("map_overlay").style.display = "none";
    document.getElementById("lblStatus").style.display = "none";
    
    if (document.getElementById("txtSearch") == null)
        document.getElementById("SearchBar").style.display = "none"
        
    if (document.getElementById("Map_Toolbar") != null)
        document.getElementById("Map_Toolbar").style.display = "none";
        
    if (document.getElementById("Map_Legend") != null)
        document.getElementById("Map_Legend").style.display = "none";
        
    if (document.getElementById("Map_Overlays") != null)
        document.getElementById("Map_Overlays").style.display = "none";
    
    document.getElementById("map").style.display = "none";
    document.getElementById("listview_overlay").style.display = "";
        
    //Release Objects
    Options = null;
    TdyDate = null;
}

function SetupMapOverlayFunction()
{
         //--Google Rectangle Start Cluster OverLay
            Rectangle.prototype = new GOverlay();        		
            
            Rectangle.prototype.initialize = function(map) 
            {
                // Create the DIV representing our rectangle
                div = document.createElement("div");
                div.className = "Map_ClusterOverlay";
                div.style.position = "absolute";
                div.innerHTML = "<table width='100%' cellpadding='0' cellspacing='0' style='margin-top:2px'><tr><td align='center' style='cursor:pointer'><span class='Map_ClusterText'>" + this.number + "</span></table></td></tr>";
                // Our rectangle is flat against the map, so we add our selves to the
                // MAP_PANE pane, which is at the same z-index as the map itself (i.e.,
                // below the marker shadows)
                map.getPane(G_MAP_MAP_PANE).appendChild(div);
                this.map_ = map;
                this.div_ = div;
                
                GEvent.bindDom(this.div_,"click",this,this.onClick);
            }

            Rectangle.prototype.onClick = function()
            {
            ClusterClick(this.lat,this.lng);
            }
            
            // Remove the main DIV from the map pane
            Rectangle.prototype.remove = function() 
            {
                this.div_.parentNode.removeChild(this.div_);
            }

            // Redraw the rectangle based on the current projection and zoom level
            Rectangle.prototype.redraw = function(force) 
            {
              // We only need to redraw if the coordinate system has changed
              if (!force) return;
              
              // Now position our DIV based on the DIV coordinates of our bounds
              this.div_.style.width = this.width_ + "px";
              this.div_.style.height = this.height_ + "px";
              this.div_.style.left = this.left_ + "px";
              this.div_.style.top = this.top_ + "px";
            }
        //--Google Rectangle Map End 
}

//++Map Toolbar Functions    
    //--Call By Map Toolbar Command (Zoom In) Zooms map out in by 1 Max Zoom out set to 17
    function Map_ZoomIn()
    {
        if (CurrZoom == 19)
        {
            alert("You are unable to Zoom in any further");
            return;
        }
            	
        var center = map.getCenter();
        CurrLng =center.lng();
        CurrLat =center.lat();
    	
        var ZoomLevel = map.getZoom() + 1;
        CurrZoom = ZoomLevel;
        map.setCenter(new GLatLng(CurrLat, CurrLng), CurrZoom);
        Map_AjaxLoadPointers();
        
        //Release Objects
        center = null;
        ZoomLevel = null;
    }
    	
    //--Call By Map Toolbar Command (Zoom Out) Zooms map out by 1 Min Zoom out set to 5
    function Map_ZoomOut()
    {
        if (CurrZoom == 5)
            {
            alert("You are unable to Zoom out any further");
            return;
            }
            
        var center = map.getCenter();
        CurrLng =center.lng();
        CurrLat =center.lat();
    	
        var ZoomLevel = map.getZoom() - 1;
        CurrZoom = ZoomLevel;
        map.setCenter(new GLatLng(CurrLat, CurrLng), CurrZoom);
        Map_AjaxLoadPointers();
        
        //Release Objects
        center = null;
        ZoomLevel = null;
    }

    //--Call By Map Toolbar Commands (Map,Satelite,Hybrid) to change Map Type
    function Map_ChangeType(x)
    {
        if (x==0)
            map.setMapType(G_NORMAL_MAP);
        if (x==1)
            map.setMapType(G_SATELLITE_MAP);
        if (x==2)
            map.setMapType(G_HYBRID_MAP);
    }

    //Call By Map Toolbar Command (Help) to show the Map Help
    function Map_ShowHelp()
    {
         var Options = document.getElementById("PopUpOptions").value.split("|");
         window.open(Options[4],"_blank","width=830px,menubar=no,toolbar=no,scrollbars=yes");
         
         //Release Objects
        Options = null;
    }
    

//++Map Helper Functions
    function Map_PositionFromSearch()
    {
        MapSearchLoad=0;
        var bounds = new GLatLngBounds();       
        var point = new GLatLng(MBMinLat,MBMinLng);
        bounds.extend(point);
        point = new GLatLng(MBMaxLat,MBMaxLng);
        bounds.extend(point);
        
        if (CurrZoom == map.getBoundsZoomLevel(bounds))
            Map_AjaxLoadPointers();
        else
            {
            CurrZoom = map.getBoundsZoomLevel(bounds)-1;
            if (SearchType == 'PostCode' && CurrZoom > 16)
                CurrZoom = 16;
            
            if (SearchType == 'City' && CurrZoom > 11)
                CurrZoom = 11;
                  
           
            map.setZoom(CurrZoom); 
            
            Map_AjaxLoadPointers();
            }
    }   

    //Called from Ajax Load Markers if there are Clusters and then adds Overlays
    function PlotClusters()
        {
        for (i =0;i<=Clusters.length-1;i++)
            {
            var NorthEast = map.fromLatLngToDivPixel(new GLatLng(parseFloat(Clusters[i][5]),parseFloat(Clusters[i][6])));
            
            var RectTop;
            var RectLeft;
      
            RectTop = parseInt(NorthEast.y) - (parseInt(Clusters[i][2])/2);
            RectLeft = parseInt(NorthEast.x) - (parseInt(Clusters[i][3])/2);
      
            map.addOverlay(new Rectangle(RectTop,RectLeft,Clusters[i][3],Clusters[i][2],Clusters[i][4],true,Clusters[i][5],Clusters[i][6]));
            //map.addOverlay(new Rectangle(parseInt(Clusters[i][1]) + NewTop,parseInt(Clusters[i][0]) + NewLeft,Clusters[i][3],Clusters[i][2],Clusters[i][4],true));
            ClusterCount = ClusterCount + parseInt(Clusters[i][4]);
            }
        }
        
    //Called from Ajax Load Markers to loop through array and plot markers
    function PlotMarkers()
    {   
        var i = 0; 
        for (i =0;i<=Markers.length-1;i++)
            PlotPoint (parseInt(Markers[i][0]),Markers[i][1],Markers[i][2],Markers[i][3],Markers[i][4],Markers[i][5],Markers[i][6],Markers[i][7],Markers[i][8],Markers[i][9],Markers[i][10],Markers[i][11],Markers[i][12],Markers[i][13],Markers[i][14],Markers[i][15],Markers[i][16],Markers[i][17],Markers[i][18],Markers.length,i,Markers[i][20],Markers[i][21],Markers[i][22],Markers[i][23])
        
	    document.getElementById("map_overlay").style.display = "none";
	    if (ShowResultsInView)
	        document.getElementById("MapInfo").innerHTML = "Results In View:" + parseInt(Markers.length + ClusterCount) + "&nbsp;&nbsp;";
    }

    //Called from Ajax Load Markers if there are no Markers so That the Overlay is closed
    function NoMarkers()
    {
        document.getElementById("map_overlay").style.display = "none";
        if (ShowResultsInView)
	        document.getElementById("MapInfo").innerHTML = "Results In View:" + parseInt(ClusterCount) + "&nbsp;&nbsp;";
    }
    
    //--Function Called from the Load Markers Script Indicating an error
    function LoadMarkerError()
    {
	        document.getElementById("lblStatus").innerHTML = "Error: Loading map positions please try again<BR><BR>[<a href='javascript:CloseDiv()'>close x</a>]";
            document.getElementById("imgInformation").src = ServerLocation + "images/Critical.jpg"
    }

    //--Call to Plot the Point and Display Info Window on click
    function PlotPoint(UniqueID,UniqueIdentifier,ShtName,Add1,Add2,Add3,Add4,PostCode,CntName,CntNumber,CntEmail,LinkURL,ImageID,MarkerID,MarkerH,MarkerW,lat,lng,ShtDesc,TotalPoints,ArrID,ImageURL,Add5,Add6,CntEmailSubject)
    {    
        var Options = document.getElementById("PopUpOptions").value.split("|");
        var Fields = document.getElementById("FieldSelection").value.split("|");
        var WindowHeader = "";
	    var WindowHTML = "";
	    var WindowInfoHTML = "";
	    var RowSpn = 1;
	    var MapMarker = new GIcon();
	    var colspan = 1;
    	
	    WindowHeader += "<TABLE align='left' class='PopUp_Tbl' border='0'>";
	    
	    for (i=0;i<=Fields.length-2;i++)
	        {
	        switch (Fields[i+1])
	            {
	                case "ShortName":
	                    WindowHTML += "<TR><TD align='left' class='" + Fields[i] + "'>" + ShtName + "</TD></TR>";
	                    RowSpn = RowSpn +1;
	                    break;
	                case "AddressLine1":
	                    WindowHTML += "<TR><TD align='left' class='" + Fields[i] + "'>" + Add1 + "</TD></TR>";
	                    RowSpn = RowSpn +1;
	                    break;
	                case "AddressLine2":
	                    if (Add2.length != 0) {WindowHTML += "<TR><TD align='left' class='" + Fields[i] + "'>" + Add2 + "</TD></TR>";
	                    RowSpn = RowSpn +1};
	                    break;
	                case "AddressLine3":
	                    if (Add3.length != 0) {WindowHTML += "<TR><TD align='left' class='" + Fields[i] + "'>" + Add3 + "</TD></TR>";
	                    RowSpn = RowSpn +1};
	                    break;
	                case "AddressLine4":
	                    if (Add4.length != 0) {WindowHTML += "<TR><TD align='left' class='" + Fields[i] + "'>" + Add4 + "</TD></TR>";
	                    RowSpn = RowSpn +1};
	                    break;
	                case "AddressLine5":
	                    if (Add5.length != 0) {WindowHTML += "<TR><TD align='left' class='" + Fields[i] + "'>" + Add5 + "</TD></TR>";
	                    RowSpn = RowSpn +1};
	                    break;
	                case "AddressLine6":
	                    if (Add6.length != 0) {WindowHTML += "<TR><TD align='left' class='" + Fields[i] + "'>" + Add6 + "</TD></TR>";
	                    RowSpn = RowSpn +1};
	                    break;
	                case "PostCode":
	                    WindowHTML += "<TR><TD align='left' class='" + Fields[i] + "'>" + PostCode + "</TD></TR>";
	                    RowSpn = RowSpn +1;
	                    break;
	                case "ContactName":
	                    if (CntName.length != 0) {WindowHTML += "<TR><TD align='left' class='" + Fields[i] + "'>" + CntName + "</TD></TR>";
	                    RowSpn = RowSpn +1};
	                    break;
	                case "ContactNumber":
	                    if (CntNumber.length != 0) {WindowHTML += "<TR><TD align='left' class='" + Fields[i] + "'>" + CntNumber + "</TD></TR>";
	                    RowSpn = RowSpn +1};
	                    break;  
	                case "ContactEmail":
	                    if (CntEmail.length != 0)
	                        {
	                        if (CntEmailSubject.length != 0)
	                            WindowHTML += "<TR><TD align='left' class='" + Fields[i] + "'><a href='mailto:" + CntEmail + "?subject=Re: " + CntEmailSubject + "'>" + CntEmail + "</a></TD></TR>";
	                        else
	                            WindowHTML += "<TR><TD align='left' class='" + Fields[i] + "'><a href='mailto:" + CntEmail + "'>" + CntEmail + "</a></TD></TR>";
	                        RowSpn = RowSpn +1;
	                        }
	                    break;
	            }
	        i++
	        }
	    	        
	    if (parseInt(Options[1]) == 1)
	        {
	        WindowHTML += "<TR><TD valign='center' align='left' class='PopUp_Links'><img SRC='" + ServerLocation + "images/Directions.png' />&nbsp;<a href='javascript:ShowDirections(" + parseInt(ArrID) + ")'>Get Directions</a></TD></TR>";
	        RowSpn = RowSpn +1;
	        }	
	      
	    if (ImageID != 0 || ImageURL.length != 0)
	        {
	        if (ImageID != 0)
	        {
	            if (PNGFixActive == true)
	                WindowHeader += "<TR><TD valign='top' rowspan=" + RowSpn + "><img class='PopUp_Image' src='" + ServerLocation + "images/blank.gif'  style=\"filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + ServerLocation + "ImageServer.aspx?id=" + ImageID + "', sizingMethod='fixed')\"></img></TD></TR>";
	            else
	                WindowHeader += "<TR><TD valign='top' rowspan=" + RowSpn + "><img class='PopUp_Image' src='" + ServerLocation + "ImageServer.aspx?id=" + ImageID + "'></img></TD></TR>";
	        }
	        else
	            WindowHeader += "<TR><TD valign='top' rowspan=" + RowSpn + "><img  class='PopUp_Image' src='" + ImageURL + "'></img></TD></TR>";
	        colspan=2;
	        }
	        
	    WindowHTML += "<TR><TD colspan=" + colspan + "><HR></TD></TR>";
	    WindowHTML += "<TR><TD colspan=" + colspan + " align='center' class='PopUp_Links'>"
	    WindowHTML += "::&nbsp;<a href='javascript:LocatePosition(" + lat + "," + lng + "," + UniqueID + ",null)'>Zoom to Location</a>&nbsp;&nbsp;"
	    
	    if (DuelMode == 1)
	        WindowHTML += "::<a href='javascript:CenterPosition(" + lat + "," + lng + "," + parseInt(ArrID) + ")'>Centre on Position</a>&nbsp;&nbsp;"
    	
	    if (LinkURL.length != 0 && parseInt(Options[0]) == 1)
	        {
	        if (LinkURL.substring(0,10) == "javascript")
	            WindowHTML += "::&nbsp;<a href=\"" + LinkURL + "\">" + Options[7] + "</a>";
	        else
	            {
	            if (LinkURL.substring(0,17) == "InformationScreen")
	                WindowHTML += "::&nbsp;<a href=javascript:ShowInformationScreen(" + parseInt(ArrID) + ")>" + Options[7] + "</a>";
	            else
	                WindowHTML += "::&nbsp;<a href=javascript:JumpToDetails(\'" + LinkURL + "\',\'" + Options[5] + "\',\'" + UniqueIdentifier + "\')>" + Options[7] + "</a>";
	            }
	        }
    	    
	    WindowHTML += "</TD></TR>";
    	
	    WindowHTML += "</TABLE>";
    		
	    WindowInfoHTML += "<TABLE align='left' class='PopUp_InfoTbl'>"
	    WindowInfoHTML += "<TR><TD class='PopUp_InfoLabel'>" + Options[6] + "</TD></TR>"
	    //WindowInfoHTML += "<TR><TD><textarea class='PopUp_InfoTxt' id='txtShortDesc'>" + ShtDesc + "</textarea></TD></TR>"
	    WindowInfoHTML += "<TR><TD><div class='PopUp_InfoTxt' id='txtShortDesc'>" + ShtDesc + "</div></TD></TR>"
	    WindowInfoHTML += "</TABLE>"
    		    	
        var point = new GLatLng(lat,lng);        
        var marker = new GMarker(point,MapMarker);
        
	    MapMarker.image = ServerLocation + "ImageServer.aspx?id=" + MarkerID + "&xxx=.png";
	    MapMarker.shadow = "";
	    MapMarker.iconSize = new GSize(MarkerW, MarkerH);
        MapMarker.shadowSize = new GSize(0, 0);
        MapMarker.iconAnchor = new GPoint(parseInt(MarkerW/2), parseInt(MarkerH/2));
        MapMarker.infoWindowAnchor = new GPoint(0, 0);
        marker.uniqueid = UniqueID;
        marker.BizMapUniqueRef = UniqueIdentifier;
        map.addOverlay(marker);
        
        var infoTabs = 
        [
          new GInfoWindowTab("Information", WindowHeader+WindowHTML),
          new GInfoWindowTab("Description", WindowInfoHTML)
        ];
        
        if ((parseInt(MyPostion) == parseInt(UniqueID)) || (parseInt(Options[2]) == 1 && parseInt(TotalPoints) == 1))
            {
                if (parseInt(Options[3]) == 1)
                    marker.openInfoWindowTabsHtml(infoTabs);
                else
                    marker.openInfoWindowHtml(WindowHeader+WindowHTML);
            }

        if (parseInt(parseInt(Options[3])) == 1)
            GEvent.addListener(marker, "click", function() {LogStat(marker.BizMapUniqueRef,3); MyPostion = marker.uniqueid; MarkerCallBack(); marker.openInfoWindowTabsHtml(infoTabs);});
        else
            GEvent.addListener(marker, "click", function() {LogStat(marker.BizMapUniqueRef,3); MyPostion = marker.uniqueid; MarkerCallBack(); marker.openInfoWindowHtml(WindowHeader+WindowHTML);});             
            

    }
    
    function MarkerCallBack()
    {
        eval(MarkerCallBackFunction);
    }
    
    //--Show Directions Div for Map View
    function ShowDirections(ArrID)
    {
    var WindowDirectionHTML = "";
    var WindowHeight;
    var WindowWidth;
    var SearchValue;
    
    if (document.getElementById("txtSearch") != null)
        SearchValue = document.getElementById("txtSearch").value;
    else
        SearchValue = APISearchValue;
        
    document.getElementById("listview_overlay").style.display = "none";

    WindowWidth = parseInt(document.getElementById("drivingdirections_overlay").style.width);

    //Build Directions HTML
    WindowDirectionHTML += "<TABLE align='center' style='margin-left:10px;margin-right:10px;width:"
    WindowDirectionHTML += parseInt(WindowWidth) - 20 + "px' class='PopUp_DirectionTbl'>"
    WindowDirectionHTML += "<TR><TD class='PopUp_DirectionLabel'>Starting Location:</TD></TR>"
    WindowDirectionHTML += "<TR><TD class='PopUp_DirectionText'><input id='txtDirStart' type='text' class='PopUp_DirectionTextBox' />&nbsp;e.g Post Code or Town</TD></TR>"
    WindowDirectionHTML += "<TR><TD style='height:4px'></TD></TR>"
    WindowDirectionHTML += "<TR><TD class='PopUp_DirectionLabel'>Finishing Location:</TD></TR>"
    WindowDirectionHTML += "<TR><TD class='PopUp_DirectionText'>" + Markers[ArrID][2] + ", " + Markers[ArrID][3] + ", " + Markers[ArrID][7]  +  "</TD></TR>"
    WindowDirectionHTML += "<TR><TD><input id='txtDirEnd' type='hidden' value='" + Markers[ArrID][2] + ", " + Markers[ArrID][3] + ", " + Markers[ArrID][7] + "@" + Markers[ArrID][16] + "," + Markers[ArrID][17] + "' /><input id='txtPosID' type='hidden' value='" + Markers[ArrID][1] + "' /></TD></TR>"
    WindowDirectionHTML += "<TR><TD align='center'><input  class='PopUp_DirectionButton' id='BtnDirections' type='button' value='Get Directions' onclick='javascript:GetDirections()' />&nbsp;<input  class='PopUp_DirectionButton' id='BtnDirections' type='button' value='Cancel Directions' onclick='javascript:CancelDirections()' /></TD></TR>"
    WindowDirectionHTML += "</TABLE>"
     	
    document.getElementById("drivingdirections_overlay").style.display = "";
    document.getElementById("drivingdirections_overlay").innerHTML = WindowDirectionHTML;
    
    if (SearchValue != "")
        document.getElementById("txtDirStart").value = SearchValue;
        
    //Release Objects
    WindowDirectionHTML = null;
    WindowHeight = null;
    WindowWidth = null;

	if (ListView == 1)
		document.getElementById("map").style.display = "none";
    }

    //--Called from Directions DIV to load Google directions
    function GetDirections()
    {
    if (document.getElementById("txtDirStart").value == "")
        {
        alert("Please Enter Starting Locations");
        document.getElementById("txtDirStart").focus();
        return;
        }
     
      DirectionsGeoStart()
      //window.open(ServerLocation + "BizMapDirections.aspx?saddr=" + document.getElementById("txtDirStart").value + "&daddr=" + document.getElementById("txtDirEnd").value + "&Param=" + document.getElementById("AccID").value + "|" + SessionID + "|" + document.getElementById("txtPosID").value);
    //window.open("http://maps.google.co.uk/maps?f=d&hl=en&saddr=" + document.getElementById("txtDirStart").value + ", UK" + "&daddr=" + document.getElementById("txtDirEnd").value + ", UK");
    }
    
    function DirectionsGeoStart()
    {
        DirGeo = true;
        var request = url + '&url=' + window.location.host + '&q=' + document.getElementById("txtDirStart").value + "&SessionID=" + SessionID; ; 
        ServerJavascriptRequest(request);
    }
    
    function GeoResultsDirections()
    {  
        var DirLat;
        var DirLng;
        var DirSearchValue;
        DirGeo = false;
        
        DirSearchValue = document.getElementById("txtDirStart").value
        
        if (parseInt(ErrorCode) == 300)
            {
                if (parseInt(ResultCount) == 0)
                    {
                    alert("Unable to find a match for [" + DirSearchValue + "], please try again");
                        document.getElementById("drivingdirections_overlay").style.display = "none";  
                        if (ListView == 1)
                            {
                            if (ViewMode == "List")
                                document.getElementById("listview_overlay").style.display = "";  
                            if (ViewMode == "Map")
                                 document.getElementById("map").style.display = "";  
                            }
                    return;
    	            }
    	            
    	        if (parseInt(ResultCount) == 1)
	                {
                    DirLat = Results[0][1];
                    DirLng = Results[0][2];
                    var rtnSearchTxt = Results[0][4];
                    //'--Correct Spelling
                    if (rtnSearchTxt != '')
                        DirSearchValue = rtnSearchTxt; 
	                }

		        if (parseInt(ResultCount) > 1)
	                {
                    alert("Unable to find a match for [" + DirSearchValue + "], please try again");
                    document.getElementById("drivingdirections_overlay").style.display = "none";  
                        if (ListView == 1)
                            {
                            if (ViewMode == "List")
                                document.getElementById("listview_overlay").style.display = "";  
                            if (ViewMode == "Map")
                                 document.getElementById("map").style.display = "";  
                            }
                    return;
	                }
            }
        else
            {
            alert("Error (" + ErrorCode + "): " + ErrorMsg + ", Unable to search");
            document.getElementById("drivingdirections_overlay").style.display = "none";  
                if (ListView == 1)
                    {
                    if (ViewMode == "List")
                        document.getElementById("listview_overlay").style.display = "";  
                    if (ViewMode == "Map")
                         document.getElementById("map").style.display = "";  
                    }
            return;
            }
              
        document.getElementById("drivingdirections_overlay").style.display = "none";  
        if (ListView == 1)
            {
            if (ViewMode == "List")
                document.getElementById("listview_overlay").style.display = "";  
            if (ViewMode == "Map")
                 document.getElementById("map").style.display = "";  
            }
                        
        window.open(ServerLocation + "BizMapDirections.aspx?saddr=" + DirSearchValue.replace(/&/g,"and") + "@" + DirLat + "," + DirLng + "&daddr=" + document.getElementById("txtDirEnd").value.replace(/&/g,"and") + "&Param=" + document.getElementById("AccID").value + "|" + SessionID + "|" + document.getElementById("txtPosID").value);
    }
    
    
    
    //--Called from Directions DIV to close DIV
    function CancelDirections()
    {
    document.getElementById("drivingdirections_overlay").style.display = "none";

    if (ListView == 1)
        {
        if (ViewMode == "List")
            document.getElementById("listview_overlay").style.display = "";  
        if (ViewMode == "Map")
            document.getElementById("map").style.display = "";  
        }
    }

    //Called from Multi Results Search
    function LocateResult(x,y)
    {
        CurrLat = x;
        CurrLng = y;
        SearchLat = x;
        SearchLng = y;
        //CurrZoom = 11;
        HasSearched = true;
       
        CloseDiv()
        if (GeoFilter != '')
            {
                if (document.getElementById(GeoFilter).value != 'No Preferences')
                    MapSearchLoad = 1;

            }  
        else
            CurrZoom = 11;
            
        map.setCenter(new GLatLng(CurrLat, CurrLng), CurrZoom);
        Map_AjaxLoadPointers();
    }

    function LocateResultList(x,y)
    {
        ListLat = x;
        ListLng = y;
	    document.getElementById("location_overlay").style.display = "none";
	    LoadListView(PageID,PageStart);

    }

    //Called from Multi Position Search and Info to Load Position
    function LocatePosition(x,y,UniqueID,UniqueRef)
    {
        document.getElementById("listview_overlay").style.display = "none";
        CurrLat = x;
        CurrLng = y;
        SearchLat = 0;
        SearchLng = 0;
        CurrZoom = 15;
        CloseDiv()
        map.setCenter(new GLatLng(CurrLat, CurrLng), CurrZoom);
        LastSearch = "";
        map.closeInfoWindow();
        Map_AjaxLoadPointers();
        MyPostion = parseInt(UniqueID);
         if (UniqueRef != null)
            LogStat(UniqueRef,2);
    }
    
    //Called from Pop Up to Center on Location and get Distance To
    function CenterPosition(x,y,ArrID)
    {
        if (document.getElementById("txtSearch") != null)
        	document.getElementById("txtSearch").value = Markers[ArrID][7];
        
        ListLat = x;
        ListLng = y;
            
        if (ListView == 1)
        {
            ShowListView();
            LoadListView(PageID,PageStart);
        }     
        else
            {
            CurrLat = x;
            CurrLng = y;
            //map.setCenter(new GLatLng(CurrLat, CurrLng), CurrZoom);
            DoSearch();
            }
    }
    
    //Called from Info Window to Zoom to Location
    function JumpToLocation(lat,lng)
    {
        map.closeInfoWindow();
        CurrLat = lat;
        CurrLng = lng;
        CurrZoom = 15;
        map.setCenter(new GLatLng(CurrLat, CurrLng), CurrZoom);
        Map_AjaxLoadPointers();
    }
    
    //Called from Info Window to Show Details
    function JumpToDetails(LinkURL,Target,UniqueRef)
    {
    
    LogStat(UniqueRef,7);
    window.open(LinkURL,Target);
    }

    //--Function Called from Preference Button
    function ApplyPref(APICall)
    {
        UniquePositionID = ''; 
        //If function not called from API clear filter and category string
        if (APICall == null)
            {
            APIFilterString = '';
            APICategoryString = '';
            }
        
        if (document.getElementById("drivingdirections_overlay") != null)
            document.getElementById("drivingdirections_overlay").style.display = "none";
        
        if (document.getElementById("information_overlay") != null)
            document.getElementById("information_overlay").style.display = "none";
        
        if (ListView == 1)
        {
            ShowListView();
            DoSearchListView();
            return;
        }
        else
        {
             LoadMapView(); 
             MyPostion = 0;
             map.closeInfoWindow();
             DoSearch();
        }
    }
    
    //Function Called from Overlay Button
    function ApplyOverlays()
    {
        if (document.getElementById("information_overlay") != null)
            HideInformationScreen()
        
        MyPostion = 0;
        map.closeInfoWindow();
        Map_AjaxLoadPointers();
    }
    
    //--Function Called from Search Button
    function DoSearch(APICall)
    {	

    var SearchValue;
    UniquePositionID = '';        
    //If function not called from API clear filter and category string and set search value
    if (APICall == null)
	{
	    if (SearchPrefOverideActive == 0)
	    {
	        APIFilterString = '';
            APICategoryString = '';
        }
            
		if (document.getElementById("txtSearch") != null)
        		SearchValue = document.getElementById("txtSearch").value;
	}
    else
	{
		SearchValue = APISearchValue;
		if (document.getElementById("txtSearch") != null) {document.getElementById("txtSearch").value = SearchValue};	
	}


     if (ListView == 1)
            {
            ShowListView();
            DoSearchListView(APICall);
            LastSearch = SearchValue;
            return;
            }
        else
            LoadMapView(); 
            
        MyPostion = 0;
        map.closeInfoWindow();
        if (SearchValue == "")
            {
                //MapSearchLoad = 1;
                Map_AjaxLoadPointers();
                return;
            }
       
        if (SearchValue == LastSearch)
            {
                if (GeoFilter != '')
                {
                    if (document.getElementById(GeoFilter).value != 'No Preferences')
                    {
                        MapSearchLoad = 1;
                        Map_AjaxLoadPointers();
                        return;
                    }

                }
                else
                {
                    Map_AjaxLoadPointers();
                    return;
                }
            }
        
        document.getElementById("map_overlay").style.display = "";
        document.getElementById("lblStatus").style.display = "";
        document.getElementById("imgInformation").src = ServerLocation + "images/wait.gif";
        document.getElementById("lblStatus").innerHTML = "Searching for [" + SearchValue + "], Please Wait...";
        
        Map_AjaxSearch();
        LastSearch = SearchValue;
    }

    //Called from Ajax Geocoder
    function GeoResults()
    {

    if (DirGeo)
        {
        GeoResultsDirections();
        return;
        }
    
    if (ListView == 1)
            {
            GeoResultsListView();
            return;
            }
            
    var ShowMultiDiv = false;
    var MultiResultH = "";
    var MultiResultD = "";
    var MultiPositionH = "";
    var MultiPositionD = "";
    var SearchValue;
    
    if (document.getElementById("txtSearch") != null)
        SearchValue = document.getElementById("txtSearch").value;
    else
        SearchValue = APISearchValue;

    if (parseInt(ErrorCode) == 300)
        {
            if (parseInt(ResultCount) == 0)
            {
                document.getElementById("lblStatus").innerHTML = "Unable to find a match for [" + SearchValue + "], please try again<BR><BR>[<a href='javascript:CloseDiv()'>close x</a>]";
	            document.getElementById("imgInformation").src = ServerLocation + "images/Information.jpg"
	        }
    	    
	        if (parseInt(ResultCount) == 1)
	        {
                CurrLat = Results[0][1];
                CurrLng = Results[0][2];
                SearchLat = Results[0][1];
                SearchLng = Results[0][2];
                rtnSearchTxt = Results[0][4];
                
                if (rtnSearchTxt != '')
                    {
                    if (document.getElementById("txtSearch") != null)
                        document.getElementById("txtSearch").value = rtnSearchTxt;
                    else
                        APISearchValue = rtnSearchTxt;
                    }
                    
                HasSearched = true;
               
                if (parseInt(ResultPositionCount) == 0)
                    {
                    if (GeoFilter != '')
                    {
                        if (document.getElementById(GeoFilter).value == 'No Preferences')
                        {
                             CurrZoom = Results[0][3]
                                
                             map.setCenter(new GLatLng(CurrLat, CurrLng), CurrZoom);
                             Map_AjaxLoadPointers();
                        }
                        else
                        {
                            CurrZoom = Results[0][3]
                            
                            MapSearchLoad = 1;
                            map.setCenter(new GLatLng(CurrLat, CurrLng), CurrZoom);
                            Map_AjaxLoadPointers();
                        }
                    }
                    else
                        {
                         CurrZoom = Results[0][3]
                            
                         map.setCenter(new GLatLng(CurrLat, CurrLng), CurrZoom);
                         Map_AjaxLoadPointers();
                        }                 
                    document.getElementById("map_overlay").style.display = "none";
                    }
                else
                    {
                    MultiResultD += '<a href=javascript:onclick=LocateResult(' + Results[0][1] + ',' + Results[0][2] + ') style="font-size: 10pt;font-family: Tahoma, Arial;">- ' + Results[0][0] + '</a><br>';					
                    MultiResultH = "<FONT style='font-size: 9pt;font-family: Tahoma, Arial;font-weight: bold;' align=center>Your Search Has Returned " + ResultCount + " Locations<BR>Please Select One of the Below</font><br><br>"		        				        
                    }
	        }
    	    
	        if (parseInt(ResultCount) > 1)
	        {
                for (var i = 0; i < Results.length; i++) 
                    MultiResultD += '<a href=javascript:onclick=LocateResult(' + Results[i][1] + ',' + Results[i][2] + ') style="font-size: 10pt;font-family: Tahoma, Arial;">- ' + Results[i][0] + '</a><br>';					

                MultiResultH = "<FONT style='font-size: 9pt;font-family: Tahoma, Arial;font-weight: bold;' align=center>Your Search Has Returned " + ResultCount + " Locations<BR>Please Select One of the Below</font><br><br>"		        				        
                
                ShowMultiDiv = true;
	        }


		    if (parseInt(ResultPositionCount) > 0)
		    {
                for (var i = 0; i < PositionResults.length; i++) 
                    MultiPositionD += '<a href=javascript:onclick=LocatePosition(' + PositionResults[i][2] + ',' + PositionResults[i][3] + ',' + PositionResults[i][0] + ',null) style="font-size: 10pt;font-family: Tahoma, Arial;">- ' + PositionResults[i][1] + '</a><br>';					

                MultiPositionH = "<FONT style='font-size: 9pt;font-family: Tahoma, Arial;font-weight: bold;' align=center>Your Search Has Returned " + PositionResults.length + " Positions<BR>Please Select One of the Below</font><br><br>"
                
                ShowMultiDiv = true
		    }

            if (ShowMultiDiv == true)
            {
	            document.getElementById("location_overlay").style.display = "";
                document.getElementById("location_overlay").innerHTML = MultiResultH + MultiResultD + "<BR>" + MultiPositionH + MultiPositionD + "<P align='right'>[<a href='javascript:CloseDiv()' style='font-size: 9pt;font-family: Tahoma, Arial;'>close x</a>]</p>";
                document.getElementById("map_overlay").style.display = "none";
            }
        }
    else
        {
            document.getElementById("lblStatus").innerHTML = "Error (" + ErrorCode + "): " + ErrorMsg + ", Unable to search<BR><BR>[<a href='javascript:CloseDiv()'>close x</a>]";
            document.getElementById("imgInformation").src = ServerLocation + "images/Critical.jpg"
        }
    }

    //--Function Call to call the GeoCode with the search and return XML Information	
    function Map_AjaxSearch()
    {
    var SearchValue;
    
    //Check if Multi Result window is shown if so close it
    if (document.getElementById("location_overlay").style.display == "")
        document.getElementById("location_overlay").style.display = "none";
        
    if (document.getElementById("txtSearch") != null)
        SearchValue = document.getElementById("txtSearch").value;
    else
        SearchValue = APISearchValue;
        
    if (PosSeaActive == 1)
    {
        var chkOption;
        var ddOption;
        var SearchString = "";
        
        for (i=1;i<=9;i++)
            {
            chkOption = document.getElementById("chkOption" + i);
            if (chkOption != null)
                {
                if (chkOption.checked == true)
                    SearchString += "1|";
                else
                    SearchString += "0|";
                }
            else
                    SearchString += "0|";
            }

        for (i=1;i<=9;i++)
            {
            ddOption = document.getElementById("ddOption" + i);
            if (ddOption != null)
                {
                SearchString += ddOption.value + "|";
                }
             else
                SearchString += "|";
            } 
       
        if (APIFilterString != "" && APICategoryString != "")
            SearchString = APICategoryString + APIFilterString
        
        var request = url + '&url=' + window.location.host + '&q=' + SearchValue +
	    "&SearchOpt=" + SearchString + "&SessionID=" + SessionID; 
    }
    else
        var request = url + '&url=' + window.location.host + '&q=' + SearchValue + "&SessionID=" + SessionID; ; 

//document.getElementById("txtKFCSearch").value = request;
    ServerJavascriptRequest(request);
    }
    
    //--Function Call to reset Search Txt Box when Map Driven
    function Map_ResetSearch()
    {
        SearchLat = 0;
        SearchLng = 0;
        
        HasSearched=false;
        LastSearch = "";
        if (document.getElementById("txtSearch") != null)
            document.getElementById("txtSearch").value = "";
    }
    
	//--Function Call to server to load pointers
    function Map_AjaxLoadPointers()
    {	
    if (map.getZoom() < 5 && map.getZoom() > 0)
        {
        map.clearOverlays();
        alert("You are unable to zoom out any further");
        map.setCenter(new GLatLng(CurrLat, CurrLng), CurrZoom);
        return;
        }

    if (map.getInfoWindow().isHidden() == true)
        MyPostion = 0;
    
    if (SearchLat != 0 && SearchLng != 0)
        {
        CurrLat = SearchLat;
        CurrLng = SearchLng;
        map.setCenter(new GLatLng(CurrLat,CurrLng));
        }
        
    ClusterCount = 0;	
    document.getElementById("map_overlay").style.display = "";
    document.getElementById("lblStatus").style.display = "";
    document.getElementById("imgInformation").src = ServerLocation + "images/wait.gif";
    document.getElementById("lblStatus").innerHTML = "Plotting Map Positions Please Wait...";
    					
    var StartPosition = map.fromContainerPixelToLatLng(new GPoint(0,0));
    var StartPixelPosition = map.fromLatLngToDivPixel(new GLatLng(parseFloat(StartPosition.lat()),parseFloat(StartPosition.lng())));

    var MapSize = map.getSize();
    var MapWidth = parseInt(MapSize.width);
    var MapHeight = parseInt(MapSize.height);
    var Markerurl = "";
    var chkOption;
    var ddOption;
    var SearchString = "";
    var OverlayString = "";
    
        for (i=1;i<=9;i++)
            {
            chkOption = document.getElementById("chkOption" + i);
            if (chkOption != null)
                {
                if (chkOption.checked == true)
                    SearchString += "1|";
                else
                    SearchString += "0|";
                }
            else
                    SearchString += "0|";
                    
            chkOption = document.getElementById("chkOverlay" + i);
            
            if (chkOption != null)
                {
                if (chkOption.checked == true)
                    OverlayString += "1|";
                else
                    OverlayString += "0|";
                }
            else
                    OverlayString += "0|";
            
            }

        for (i=1;i<=9;i++)
            {
            ddOption = document.getElementById("ddOption" + i);
            if (ddOption != null)
                {
                if (GeoFilter == "ddOption" + i)
                {
                    if (HasSearched == false)
                        SearchString += "|";
                     else
                        SearchString += ddOption.value + "|";
                }
                else
                    SearchString += ddOption.value + "|";
                }
             else
                SearchString += "|";
                
            ddOption = document.getElementById("ddOverlay" + i)
            if (ddOption != null)
                {
                OverlayString += ddOption.value + "|";
                }
             else
                OverlayString += "|";
            }

        if (APIFilterString != "" && APICategoryString != "")
            SearchString = APICategoryString + APIFilterString
              
        NewLeft = StartPixelPosition.x;
        NewTop = StartPixelPosition.y;

        var bounds = map.getBounds();
        var southWest = bounds.getSouthWest();
        var northEast = bounds.getNorthEast();

       
        MarkerURL = ServerLocation + "BizMapLoadMarkersv2.aspx?AId=" + document.getElementById("AccID").value + 
        "&AltAId=" + document.getElementById("AltAccID").value +
        "&SId=" + SessionID + 
        "&SLat=" + StartPosition.lat() + 
        "&SLng=" + StartPosition.lng() +
        "&NELat=" + northEast.lat() + 
        "&NELng=" + northEast.lng() +
        "&SWLat=" + southWest.lat() + 
        "&SWLng=" + southWest.lng() +
        "&MW=" + MapWidth +
        "&MH=" + MapHeight +
        "&MZ=" + map.getZoom() +
        "&SOpt=" + SearchString.replace(/&/g,"~amp~") +
        "&OOpt=" + OverlayString.replace(/&/g,"~amp~") +
        "&MR=" + MapRtnFunc +
        "&SL=" + MapSearchLoad +
        "&UPosID=" + UniquePositionID
        
        CurrLat = CurrLat;
        CurrLng = CurrLng;
        
        if (parseInt(ListView) == 1)
            MarkerURL += "&CLat=" + ListLat + "&CLng=" + ListLng;
        else
            MarkerURL += "&CLat=" + CurrLat + "&CLng=" + CurrLng;
        
        ServerJavascriptRequest(MarkerURL);
    }
	
    
    function LoadListView(PgID,PgStart)
    {   
        var chkOption;
        var ddOption;
        var SearchString = "";
        var DirectoryString = "";
        
        for (i=1;i<=9;i++)
            {
            chkOption = document.getElementById("chkOption" + i);
            if (chkOption != null)
                {
                if (chkOption.checked == true)
                    SearchString += "1|";
                else
                    SearchString += "0|";
                }
            else
                    SearchString += "0|";
            }

        for (i=1;i<=9;i++)
            {
            ddOption = document.getElementById("ddOption" + i);
            if (ddOption != null)
                {
		        if (GeoFilter == "ddOption" + i)
                {
                    if (HasSearched == false)
                        SearchString += "|";
                     else
                        SearchString += ddOption.value + "|";
                }
                else
                    SearchString += ddOption.value + "|";
		        }
             else
                SearchString += "|";
            } 
        
        if (APIFilterString != "" && APICategoryString != "")
            SearchString = APICategoryString + APIFilterString
            
            if (ListView == 1)
	            var MapDriven = 0;
            else
                {
	            var MapDriven = 1;     
	            ListLat = CurrLat;
	            ListLng = CurrLng;
	            }

    	if (document.getElementById("txtProdServ") != null)
    	    {
    	    if (document.getElementById("txtProdServ").value != "")
    	        DirectoryString += "&KWSearch=1&KWords=" + document.getElementById("txtProdServ").value;
    	    else
    	        DirectoryString += "&KWSearch=0&KWords=";
    	    }
    	else
    	    DirectoryString += "&KWSearch=0&KWords=";
    	    
    	if (document.getElementById("txtCompany") != null)
    	    {
    	    if (document.getElementById("txtCompany").value != "")
    	        DirectoryString += "&SNSearch=1&SNName=" + document.getElementById("txtCompany").value;
    	    else
    	        DirectoryString += "&SNSearch=0&SNName=";
    	    }
    	else
    	    DirectoryString += "&SNSearch=0&SNName=";
    	    
    	var SearchValue;
    
        if (document.getElementById("txtSearch") != null)
            SearchValue = document.getElementById("txtSearch").value;
        else
            SearchValue = APISearchValue;

        if (HasSearched == false)
        {
            ListLat = 0;
            ListLng = 0;
        }
                                        
        var request = ServerLocation + "BuildAdditionalInfo.aspx?Type=List" +
                                       "&PgStart=" + PgStart + 
                                       "&PgID=" + PgID + 
                                       "&AId=" + document.getElementById("AccID").value + 
                                       "&AltAId=" + document.getElementById("AltAccID").value +
                                       "&CurrLat=" + ListLat + 
                                       "&CurrLng=" + ListLng + 
                                       "&SearchOpt=" + SearchString.replace(/&/g,"~amp~") +
                                       "&MapDriven=" + MapDriven +
                                       "&SessionID=" + SessionID +
                                       "&DivWidth=" + document.getElementById("listview_overlay").style.width +
                                       DirectoryString + "&LF=" + ListRtnFunc + "&BT=" + browserType + "&BV=" + browserVersion + "&ST=" + SearchValue + "&UPosID=" + UniquePositionID;
                                                                          
        ServerJavascriptRequest(request);        
           
    }
    
    function BizMapListLoaded() 
    {
        document.getElementById("listview_overlay").innerHTML = BizMapListHTML.replace(/~/g,"'");    
        document.getElementById("listview_overlay").style.display = "";
        document.getElementById("listview_overlay").scrollTop=0;
    }

    function MapLoadListView()
    {
    ViewMode = "List";
    
    if (document.getElementById("drivingdirections_overlay") != null)
        document.getElementById("drivingdirections_overlay").style.display = "none";
        
    if (document.getElementById("information_overlay") != null)
        HideInformationScreen()
        
    if (document.getElementById("imgMapView") != null) 
    {
        if (PNGFixActive)
        {
            PNGFixIEUpdateTag(document.getElementById("imgMapView"),ServerLocation + "images/MapTab.png")
            PNGFixIEUpdateTag(document.getElementById("imgListView"),ServerLocation + "images/ListTabSelected.png")
        }   
        else
        {
            document.getElementById("imgListView").src = ServerLocation + "images/ListTabSelected.png"
            document.getElementById("imgMapView").src = ServerLocation + "images/MapTab.png"
        }
    }
    
    document.getElementById("listview_overlay").style.display = "";

    if (document.getElementById("txtSearch") == null)
        document.getElementById("SearchBar").style.display = "none"
        
    if (document.getElementById("Map_Toolbar") != null)
        document.getElementById("Map_Toolbar").style.display = "none";
        
    document.getElementById("MapInfo").style.display = "none";
    if (document.getElementById("Map_Legend") != null)
        document.getElementById("Map_Legend").style.display = "none";
       
    if (document.getElementById("Map_Overlays") != null)
        document.getElementById("Map_Overlays").style.display = "none";  
        
    if (document.getElementById("PrintResults") != null)
        document.getElementById("PrintResults").style.display = "";
        
    if (ListView == 1)
        document.getElementById("map").style.display = "none";
    else
	    LoadListView(1,1);
    }
    
     function ShowListView()
    {
    ViewMode = "List";
    
    if (document.getElementById("information_overlay") != null)
        HideInformationScreen()

    //--Show Map View and Hide List View
    if (PNGFixActive)
    {
        if (document.getElementById("imgListView") != null)
            PNGFixIEUpdateTag(document.getElementById("imgListView"),ServerLocation + "images/ListTabSelected.png")

        if (document.getElementById("imgMapView") != null)            
            PNGFixIEUpdateTag(document.getElementById("imgMapView"),ServerLocation + "images/MapTab.png")
    }   
    else
    {
        if (document.getElementById("imgListView") != null)
            document.getElementById("imgListView").src = ServerLocation + "images/ListTabSelected.png"
        
        if (document.getElementById("imgMapView") != null)
            document.getElementById("imgMapView").src = ServerLocation + "images/MapTab.png"
    }
    
        
    document.getElementById("map").style.display = "none";
    
    document.getElementById("MapInfo").style.display = "none";
    
    if (document.getElementById("txtSearch") == null)
        document.getElementById("SearchBar").style.display = "none"
        
    if (document.getElementById("Map_Toolbar") != null)
        document.getElementById("Map_Toolbar").style.display = "none";
    
    if (document.getElementById("Map_Legend") != null)
        document.getElementById("Map_Legend").style.display = "none";
        
    if (document.getElementById("Map_Overlays") != null)
        document.getElementById("Map_Overlays").style.display = "none";
        
    if (document.getElementById("PrintResults") != null)
        document.getElementById("PrintResults").style.display = "";
        
    document.getElementById("listview_overlay").style.display = "";
    }

    function LoadMapView()
    {
    ViewMode = "Map";
    
    if (document.getElementById("drivingdirections_overlay") != null)
        document.getElementById("drivingdirections_overlay").style.display = "none";
        
    if (document.getElementById("information_overlay") != null)
        HideInformationScreen()
    
    if (document.getElementById("imgListView") != null)
    {
        if (PNGFixActive)
        {
                PNGFixIEUpdateTag(document.getElementById("imgListView"),ServerLocation + "images/ListTab.png")
                PNGFixIEUpdateTag(document.getElementById("imgMapView"),ServerLocation + "images/MapTabSelected.png")
        }   
        else
        {
            document.getElementById("imgListView").src = ServerLocation + "images/ListTab.png"
            document.getElementById("imgMapView").src = ServerLocation + "images/MapTabSelected.png"
        }
     }
            
    document.getElementById("listview_overlay").style.display = "none";
    
    if (document.getElementById("Map_Legend") != null)
        document.getElementById("Map_Legend").style.display = "";
        
    if (document.getElementById("Map_Overlays") != null)
        document.getElementById("Map_Overlays").style.display = "";

    if (document.getElementById("txtSearch") == null)
        document.getElementById("SearchBar").style.display = ""
        
    if (document.getElementById("Map_Toolbar") != null)        
        document.getElementById("Map_Toolbar").style.display = "";
        
    if (document.getElementById("PrintResults") != null)
        document.getElementById("PrintResults").style.display = "none";
        
    document.getElementById("MapInfo").style.display = "";
    
    if (ListView == 1)
        {
        document.getElementById("map").style.display = "";
        map = new GMap2(document.getElementById("map"));
        document.getElementById("map_overlay").style.top = parseInt(document.getElementById("map").offsetTop)  + "px";
        document.getElementById("map_overlay").style.left = parseInt(document.getElementById("map").offsetLeft)  + "px";
     
        //Check If Lat/Lng is 0 and set to defaults
        if (typeof(BMinLat) == 'undefined' && typeof(BMinLng) == 'undefined')
        {
            var Options = document.getElementById("Variables").value.split("|");
            CurrLat=Options[0];
            CurrLng=Options[1];
            CurrZoom=parseInt(Options[2]);
            map.setCenter(new GLatLng(CurrLat,CurrLng),CurrZoom);
        }
        else
        {
            if (BMinLat == 0 && BMinLng == 0)
                {
                var Options = document.getElementById("Variables").value.split("|");
                CurrLat=Options[0];
                CurrLng=Options[1];
                CurrZoom=parseInt(Options[2]);
                map.setCenter(new GLatLng(CurrLat,CurrLng),CurrZoom);
                }
            else
                {
                map.setCenter(new GLatLng(0,0),0);
                
                var bounds = new GLatLngBounds();       
                var point = new GLatLng(BMinLat,BMinLng);
                bounds.extend(point);
                point = new GLatLng(BMaxLat,BMaxLng);
                bounds.extend(point);
                       
		if (map.getBoundsZoomLevel(bounds) < 5)
                    map.setZoom(5);
                else 
	            map.setZoom(map.getBoundsZoomLevel(bounds));

                CurrLat = (bounds.getNorthEast().lat() + bounds.getSouthWest().lat()) /2;
                CurrLng = (bounds.getNorthEast().lng() + bounds.getSouthWest().lng()) /2;
                }
        }
           
        map.setCenter(new GLatLng(CurrLat,CurrLng));
        map.setMapType(CurrType);
        
        SetupMapOverlayFunction();
        
        Map_AjaxLoadPointers();
	    GEvent.addListener(map, "dragend", function() {Map_AjaxLoadPointers();});
        //GEvent.addListener(map, "zoomend", function() {Map_AjaxLoadPointers();});
        }        
    
    }

    function LoadPage(x)
    {
    PageID = x;
    LoadListView(PageID,PageStart);
    }

    function NextNavPage(x)
    {
    if (ViewMode == 'Map')
    {
    alert("Unable to complete action in Map Mode");
    return;
    }
           
    PageID = x;
    PageStart = PageStart + 1
    LoadListView(PageID,PageStart);
    }

    function PrevNavPage(x)
    {
    if (ViewMode == 'Map')
    {
    alert("Unable to complete action in Map Mode");
    return;
    }
           
    PageID = x;
    PageStart = PageStart - 1
    LoadListView(PageID,PageStart);
    }

    function ShowDirectionsListView(LatLng,ShortName,UniqueID)
    {
    var WindowDirectionHTML = "";
    var WindowHeight;
    var WindowWidth;
    var SearchValue;
    
    if (document.getElementById("txtSearch") != null)
        SearchValue = document.getElementById("txtSearch").value;
    else
        SearchValue = APISearchValue;
        
    WindowWidth = parseInt(document.getElementById("drivingdirections_overlay").style.width);

    //Build Directions HTML
    WindowDirectionHTML += "<TABLE align='center' style='margin-left:10px;margin-right:10px;width:"
    WindowDirectionHTML += parseInt(WindowWidth) - 20 + "px' class='PopUp_DirectionTbl'>"
    WindowDirectionHTML += "<TR><TD class='PopUp_DirectionLabel'>Starting Location:</TD></TR>"
    WindowDirectionHTML += "<TR><TD class='PopUp_DirectionText'><input id='txtDirStart' type='text' style='width:90px' />&nbsp;e.g Post Code or Town</TD></TR>"
    WindowDirectionHTML += "<TR><TD style='height:4px'></TD></TR>"
    WindowDirectionHTML += "<TR><TD class='PopUp_DirectionLabel'>Finishing Location:</TD></TR>"
    WindowDirectionHTML += "<TR><TD class='PopUp_DirectionText'>" + ShortName +  "</TD></TR>"
    WindowDirectionHTML += "<TR><TD><input id='txtDirEnd' type='hidden' value='" + ShortName + "@" + LatLng + "' /><input id='txtPosID' type='hidden' value='" + UniqueID + "' /></TD></TR>"
    WindowDirectionHTML += "<TR><TD align='center'><input  class='PopUp_DirectionButton' id='BtnDirections' type='button' value='Get Directions' onclick='javascript:GetDirections()' />&nbsp;<input  class='PopUp_DirectionButton' id='BtnDirections' type='button' value='Cancel Directions' onclick='javascript:CancelDirections()' /></TD></TR>"
    WindowDirectionHTML += "</TABLE>"

    if (ListView == 1)

    {
        document.getElementById("map").style.display = "none";	
        document.getElementById("listview_overlay").style.display = "none";	
    }
        
    document.getElementById("drivingdirections_overlay").style.display = "";
    document.getElementById("drivingdirections_overlay").innerHTML = WindowDirectionHTML;
    if (SearchValue != "")
        document.getElementById("txtDirStart").value = SearchValue;

    }

    function DoSearchListView(APICall)
    {
    PageID = 1;
    PageStart = 1;  
    var SearchValue;
    
    if (APICall == null)
	{
		if (document.getElementById("txtSearch") != null)
        	SearchValue = document.getElementById("txtSearch").value;
	}
    else
	{
		SearchValue = APISearchValue;
		if (document.getElementById("txtSearch") != null) {document.getElementById("txtSearch").value = SearchValue}
	}

    if (SearchValue == "")
            {
                ListLat = 0;
                ListLng = 0;
                LoadListView(PageID,PageStart)
                return;
            }
            
        if (SearchValue == LastSearch)
            {
                LoadListView(PageID,PageStart)
                return;
            }
    
    document.getElementById("map_overlay").style.display = "";
    document.getElementById("lblStatus").style.display = "";
    document.getElementById("imgInformation").src = ServerLocation + "images/wait.gif";
    document.getElementById("lblStatus").innerHTML = "Searching for [" + SearchValue + "], Please Wait...";

    Map_AjaxSearch();
    }

    function GeoResultsListView()
    {
    var ShowMultiDiv = false;
    var MultiResultH = "";
    var MultiResultD = "";
    var MultiPositionH = "";
    var MultiPositionD = "";
    var SearchValue;
    
    if (document.getElementById("txtSearch") != null)
        SearchValue = document.getElementById("txtSearch").value;
    else
        SearchValue = APISearchValue;
    

    if (parseInt(ErrorCode) == 300)
        {
            if (parseInt(ResultCount) == 0)
            {
                document.getElementById("lblStatus").innerHTML = "Unable to find a match for [" + SearchValue + "], please try again<BR><BR>[<a href='javascript:CloseDiv()'>close x</a>]";
	            document.getElementById("imgInformation").src = ServerLocation + "images/Information.jpg"
	        }
    	    
	        if (parseInt(ResultCount) == 1)
	        {
                ListLat = Results[0][1]
                ListLng = Results[0][2]
                var rtnSearchTxt = Results[0][4];
                //'--Correct Spelling
                if (rtnSearchTxt != '')
                    {
                    if (document.getElementById("txtSearch") != null)
                        document.getElementById("txtSearch").value = rtnSearchTxt;
                    else
                        APISearchValue = rtnSearchTxt;
                    }
                    
                
                LoadListView(PageID,PageStart);
                document.getElementById("map_overlay").style.display = "none";      
	        }

		if (parseInt(ResultCount) > 1)
	        {
                for (var i = 0; i < Results.length; i++) 
		    {
		    if (ListView == 1)
	                    MultiResultD += '<a href=javascript:onclick=LocateResultList(' + Results[i][1] + ',' + Results[i][2] + ') style="font-size: 10pt;font-family: Tahoma, Arial;">- ' + Results[i][0] + '</a><br>';					
		    else
			    MultiResultD += '<a href=javascript:onclick=LocateResult(' + Results[i][1] + ',' + Results[i][2] + ') style="font-size: 10pt;font-family: Tahoma, Arial;">- ' + Results[i][0] + '</a><br>';					
	            }

                MultiResultH = "<FONT style='font-size: 9pt;font-family: Tahoma, Arial;font-weight: bold;' align=center>Your Search Has Returned " + ResultCount + " Locations<BR>Please Select One of the Below</font><br><br>"		        				        
                
                ShowMultiDiv = true;
	        }

		if (ShowMultiDiv == true)
            	{
		if (ListView == 1)
			{
			document.getElementById("listview_overlay").style.display = "none";
		        document.getElementById("location_overlay").style.display = "";
        	        document.getElementById("location_overlay").innerHTML = MultiResultH + MultiResultD + "<BR>" + MultiPositionH + MultiPositionD + "<P align='right'>[<a href='javascript:CloseDiv()' style='font-size: 9pt;font-family: Tahoma, Arial;'>close x</a>]</p>";
                	document.getElementById("map_overlay").style.display = "none";
			}
            	}
        }
    else
        {
            document.getElementById("lblStatus").innerHTML = "Error (" + ErrorCode + "): " + ErrorMsg + ", Unable to search<BR><BR>[<a href='javascript:CloseDiv()'>close x</a>]";
            document.getElementById("imgInformation").src = ServerLocation + "images/Critical.jpg"
        }
    }

function ShowOnMap(x)
{
ViewMode = "Map";

//--Show Map View and Hide List View
document.getElementById("map").style.display = "";

//--If Information Div Here Hide
if (document.getElementById("information_overlay") != null)
    HideInformationScreen()

if (document.getElementById("txtSearch") == null)
    document.getElementById("SearchBar").style.display = ""
        
if (document.getElementById("Map_Toolbar") != null)
    document.getElementById("Map_Toolbar").style.display = "";

if (document.getElementById("Map_Legend") != null)
    document.getElementById("Map_Legend").style.display = "";
    
if (document.getElementById("Map_Overlays") != null)
    document.getElementById("Map_Overlays").style.display = "";
    
if (document.getElementById("PrintResults") != null)
        document.getElementById("PrintResults").style.display = "none";
    
document.getElementById("listview_overlay").style.display = "none";

//--Centre Map on Position
CurrLat = parseFloat(Positions[x][16]);
CurrLng = parseFloat(Positions[x][17]);
CurrZoom = 14;

map = new GMap2(document.getElementById("map"));
map.setCenter(new GLatLng(CurrLat, CurrLng), CurrZoom);
map.setMapType(CurrType);
        
//--Plot Point
var Options = document.getElementById("PopUpOptions").value.split("|");
var Fields = document.getElementById("FieldSelection").value.split("|");
var WindowHeader = "";
var WindowHTML = "";
var WindowInfoHTML = "";
var RowSpn = 1;
var MapMarker = new GIcon();
var colspan = 1;
	
	WindowHeader += "<TABLE align='left' class='PopUp_Tbl'>";
	
	for (i=0;i<=Fields.length-2;i++)
	        {
	        switch (Fields[i+1])
	            {
	                case "ShortName":
	                    WindowHTML += "<TR><TD align='left' class='" + Fields[i] + "'>" + Positions[x][2] + "</TD></TR>";
	                    RowSpn = RowSpn +1;
	                    break;
	                case "AddressLine1":
	                    WindowHTML += "<TR><TD align='left' class='" + Fields[i] + "'>" + Positions[x][3] + "</TD></TR>";
	                    RowSpn = RowSpn +1;
	                    break;
	                case "AddressLine2":
	                    if (Positions[x][4].length != 0) {WindowHTML += "<TR><TD align='left' class='" + Fields[i] + "'>" + Positions[x][4] + "</TD></TR>";
	                    RowSpn = RowSpn +1};
	                    break;
	                case "AddressLine3":
	                    if (Positions[x][5].length != 0) {WindowHTML += "<TR><TD align='left' class='" + Fields[i] + "'>" + Positions[x][5] + "</TD></TR>";
	                    RowSpn = RowSpn +1};
	                    break;
	                case "AddressLine4":
	                    if (Positions[x][6].length != 0) {WindowHTML += "<TR><TD align='left' class='" + Fields[i] + "'>" + Positions[x][6] + "</TD></TR>";
	                    RowSpn = RowSpn +1};
	                    break;
	                case "AddressLine5":
	                    if (Positions[x][21].length != 0) {WindowHTML += "<TR><TD align='left' class='" + Fields[i] + "'>" + Positions[x][21] + "</TD></TR>";
	                    RowSpn = RowSpn +1};
	                    break;
	                case "AddressLine6":
	                    if (Positions[x][22].length != 0) {WindowHTML += "<TR><TD align='left' class='" + Fields[i] + "'>" + Positions[x][22] + "</TD></TR>";
	                    RowSpn = RowSpn +1};
	                    break;
	                case "PostCode":
	                    WindowHTML += "<TR><TD align='left' class='" + Fields[i] + "'>" + Positions[x][7] + "</TD></TR>";
	                    RowSpn = RowSpn +1;
	                    break;
	                case "ContactName":
	                    if (Positions[x][8].length != 0) {WindowHTML += "<TR><TD align='left' class='" + Fields[i] + "'>" + Positions[x][8] + "</TD></TR>";
	                    RowSpn = RowSpn +1};
	                    break;
	                case "ContactNumber":
	                    if (Positions[x][9].length != 0) {WindowHTML += "<TR><TD align='left' class='" + Fields[i] + "'>" + Positions[x][9] + "</TD></TR>";
	                    RowSpn = RowSpn +1};
	                    break;  
	                case "ContactEmail":
	                    if (Positions[x][10].length != 0)
	                        {
	                        if (Positions[x][23].length != 0)
	                            WindowHTML += "<TR><TD align='left' class='" + Fields[i] + "'><a href='mailto:" + Positions[x][10] + "?subject=Re: " + Positions[x][23] + "'>" + Positions[x][10] + "</a></TD></TR>";
	                        else
	                            WindowHTML += "<TR><TD align='left' class='" + Fields[i] + "'><a href='mailto:" + Positions[x][10] + "'>" + Positions[x][10] + "</a></TD></TR>";
	                        RowSpn = RowSpn +1;
	                        }
	                    break;
	            }
	        i++
	        }
	
	LogStat(Positions[x][1],2)         
	if (parseInt(Options[1]) == 1)
	    {   
	    WindowHTML += "<TR><TD valign='center' align='left' class='PopUp_Links'><img SRC='" + ServerLocation + "images/Directions.png' />&nbsp;<a href=\"" + Positions[x][19].replace(/~/g,"\'") + "\">Get Directions</a></TD></TR>";
	    RowSpn = RowSpn +1;
	    }
	if (Positions[x][12] != 0 || Positions[x][20].length != 0)
	    {
	    if (Positions[x][12] != 0)
	    {
	        if (PNGFixActive == true)
	            WindowHeader += "<TD valign='top' rowspan=" + RowSpn + "><img class='PopUp_Image' src='" + ServerLocation + "images/blank.gif'  style=\"filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + ServerLocation + "ImageServer.aspx?id=" + Positions[x][12] + "', sizingMethod='fixed')\"></img></TD>";
	        else
	            WindowHeader += "<TD valign='top' rowspan=" + RowSpn + "><img class='PopUp_Image' src='" + ServerLocation + "ImageServer.aspx?id=" + Positions[x][12] + "'></img></TD>";
	    }
	    else
	        WindowHeader += "<TD valign='top' rowspan=" + RowSpn + "><img class='PopUp_Image' src='" + Positions[x][20] + "'></img></TD>";
	        
	    colspan=2;
	    }
	    
	WindowHTML += "<TR><TD colspan=" + colspan + "><HR></TD></TR>";
	WindowHTML += "<TR><TD colspan=" + colspan + " align='left' class='PopUp_Links'>"
	//WindowHTML += "::&nbsp;<a href='javascript:LocatePosition(" + lat + "," + lng + "," + UniqueID + ")'>Zoom to Location</a>&nbsp;&nbsp;&nbsp;&nbsp;"
	
	WindowHTML += "::&nbsp;<a href='javascript:ShowListView()'>Return to List View</a>&nbsp;&nbsp;&nbsp;&nbsp;"
	
	if (Positions[x][11].length != 0 && parseInt(Options[0]) == 1)
	        {
	        if (Positions[x][11].substring(0,10) == "javascript")
	            WindowHTML += "::&nbsp;<a href=\"" + Positions[x][11] + "\">" + Options[7] + "</a>";
	        else if (Positions[x][11].substring(0,17) == "InformationScreen")
	            WindowHTML += "";
	        else
	            WindowHTML += "::&nbsp;<a href=javascript:JumpToDetails(\'" + Positions[x][11] + "\',\'" + Options[5]  + "\',\'" + Positions[x][1] + "\')>" + Options[7] + "</a>";
	        }
	    
	WindowHTML += "</TD></TR>";
	
	WindowHTML += "</TABLE>";
		
	WindowInfoHTML += "<TABLE align='left' class='PopUp_InfoTbl'>"
	WindowInfoHTML += "<TR><TD class='PopUp_InfoLabel'>" + Options[6] + "</TD></TR>"
	//WindowInfoHTML += "<TR><TD><textarea class='PopUp_InfoTxt' id='txtShortDesc'>" + Positions[x][18] + "</textarea></TD></TR>"
	WindowInfoHTML += "<TR><TD><div class='PopUp_InfoTxt' id='txtShortDesc'>" + Positions[x][18] + "</div></TD></TR>"
	WindowInfoHTML += "</TABLE>"
	
    	
    var point = new GLatLng(Positions[x][16],Positions[x][17]);        
    var marker = new GMarker(point,MapMarker);		    	
	MapMarker.image = ServerLocation + "ImageServer.aspx?id=" + Positions[x][13];
	MapMarker.shadow = "";
	MapMarker.iconSize = new GSize(Positions[x][15], Positions[x][14]);
    MapMarker.shadowSize = new GSize(0, 0);
    MapMarker.iconAnchor = new GPoint(parseInt(Positions[x][15]/2), parseInt(Positions[x][14]/2));
    MapMarker.infoWindowAnchor = new GPoint(0, 0);
    marker.uniqueid = Positions[x][0];
    map.addOverlay(marker);

    WindowInfoHTML = WindowInfoHTML.replace(/~/,"'");

    var infoTabs = 
    [
      new GInfoWindowTab("Information", WindowHeader+WindowHTML),
      new GInfoWindowTab("Description", WindowInfoHTML)
    ];
    
            if (parseInt(Options[3]) == 1)
                marker.openInfoWindowTabsHtml(infoTabs);
            else
                marker.openInfoWindowHtml(WindowHeader+WindowHTML);
                
    if (parseInt(parseInt(Options[3])) == 1)
        GEvent.addListener(marker, "click", function() {MyPostion = marker.uniqueid; marker.openInfoWindowTabsHtml(infoTabs);});
    else
        GEvent.addListener(marker, "click", function() {MyPostion = marker.uniqueid; marker.openInfoWindowHtml(WindowHeader+WindowHTML);});                      
}

//--Global Functions--
function ServerJavascriptRequest(request)
{      
    request += "&rnd=" + Math.random();
    var head = document.getElementsByTagName("head").item(0);    
    var script = document.createElement("script");    
    script.setAttribute("type", "text/javascript");    
    script.setAttribute("src", request); 
    head.appendChild(script);
}

function ClusterClick(lat,lng)
{
    if (CurrZoom >= 18)
        {
            alert("You are unable to Zoom in any further");
            return;
        }
        
    map.closeInfoWindow();
    CurrLat = lat;
    CurrLng = lng;
    CurrZoom = map.getZoom() + 2;
    map.setCenter(new GLatLng(CurrLat, CurrLng), CurrZoom);
    Map_AjaxLoadPointers();
}

function CloseDiv()
{
    document.getElementById("map_overlay").style.display = "none";
    document.getElementById("location_overlay").style.display = "none";
    LastSearch = "";
    
    if (ListView == 1)
        {
        if (ViewMode == "List")
            document.getElementById("listview_overlay").style.display = "";  
        if (ViewMode == "Map")
            document.getElementById("map").style.display = "";  
        }
}

function DisableEnter(e)
{
    var key;

    if(window.event)
      key = window.event.keyCode;     //IE
    else
      key = e.which;     //firefox

    if(key == 13)
      return false;
    else
      return true;
}

function EnableEnter(e)
{
    var key;

    if(window.event)
      key = window.event.keyCode;     //IE
    else
      key = e.which;     //firefox

    if(key == 13)
      {
      //Check Current Options to establish what needs to be changed
      var Options = document.getElementById("Variables").value.split("|");
      if (parseInt(Options[7]) == 0 && parseInt(Options[8]) == 0)
        BizMapLoadWithSearch();
      else
        DoSearch();
      return false;
      }
    else
      return true;    
}

//-----------Google Maps Function for Adding an Overlay----------//
function Rectangle(top,left,width,height,number,showback,lat,lng) 
{        
    this.top_ = top  || 0;
    this.left_ = left || 0;
    this.width_ = width || 0;
    this.height_ = height || 0;
    this.number = number || "";
    this.showback = showback || false;
    this.lat = lat;
    this.lng = lng;
}

function ShowListLoadMessage()
{
    document.getElementById("BizMap").innerHTML = BizMapHTML.replace(/~/g,"'");
    document.getElementById("listview_overlay").innerHTML = onLoadMessage;    
    document.getElementById("listview_overlay").style.display = "";
}

function ShowHideOverlays()
{
    if (document.getElementById("MapOverlaysTbl").style.display == "")
        {
        document.getElementById("MapOverlaysTbl").style.display = "none"
        if (PNGFixActive)
            PNGFixIEUpdateTag(document.getElementById("MapOverlayChevron"),ServerLocation + "images/DownChevron.png")
        else
            document.getElementById("MapOverlayChevron").src = ServerLocation + "images/DownChevron.png"
        }
    else
        {
        document.getElementById("MapOverlaysTbl").style.display = ""
        if (PNGFixActive)
            PNGFixIEUpdateTag(document.getElementById("MapOverlayChevron"),ServerLocation + "images/UpChevron.png")
        else
            document.getElementById("MapOverlayChevron").src = ServerLocation + "images/UpChevron.png"
        }
}

function ShowHideLegend()
{
    if (document.getElementById("MapLegendTbl").style.display == "")
        {
        document.getElementById("MapLegendTbl").style.display = "none"
        if (PNGFixActive)
            PNGFixIEUpdateTag(document.getElementById("MapLegendChevron"),ServerLocation + "images/DownChevron.png")
        else
            document.getElementById("MapLegendChevron").src = ServerLocation + "images/DownChevron.png"
        }
    else
        {
        document.getElementById("MapLegendTbl").style.display = ""
        if (PNGFixActive)
            PNGFixIEUpdateTag(document.getElementById("MapLegendChevron"),ServerLocation + "images/UpChevron.png")
        else
            document.getElementById("MapLegendChevron").src = ServerLocation + "images/UpChevron.png"
        }
}

function PNGFixIEUpdateTag(img,imgsrc)
{  
         if (imgsrc == null) 
            var imgSrc = img.src;
         else
            var imgSrc = imgsrc;
             
         var imgID = (img.id) ? "id='" + img.id + "' " : "";
         var strNewHTML = "<img " + imgID + " src='" + img.src + "' border='0' "
         + " style=\""
         + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
         + "(src=\'" + imgSrc + "\', sizingMethod='fixed');\"/>";
         img.outerHTML = strNewHTML;
}

//--API Support Functions--//
//This functions are there to support native development calls//
function SetControlView(ViewType)
{
    if (ViewType == 'List')
        MapLoadListView();

    if (ViewType == 'Map')
        LoadMapView();
}

function SetMapMode(ModeType)
{
if (ViewMode == 'List')
    {
    alert("Unable to complete action in List Mode");
    return;
    }
    
    if (ModeType=='Road')
        map.setMapType(G_NORMAL_MAP);
    if (ModeType=='Satellite')
        map.setMapType(G_SATELLITE_MAP);
    if (ModeType=='Hybrid')
        map.setMapType(G_HYBRID_MAP);
}

function SetMapZoom(Direction,ZoomLevel)
{
if (ViewMode == 'List')
    {
    alert("Unable to complete action in List Mode");
    return;
    }

var center = map.getCenter();
CurrLng =center.lng();
CurrLat =center.lat();
        
if (Direction != null)
    {   	
        if (Direction == '+')
            CurrZoom = map.getZoom() + 1;
        
        if (Direction == '-')
            CurrZoom = map.getZoom() - 1;
    }

if (ZoomLevel != null)
    {
        CurrZoom = parseInt(ZoomLevel);
    }
       
map.setCenter(new GLatLng(CurrLat, CurrLng), CurrZoom);
Map_AjaxLoadPointers();
}

function UpdatePreferences(PrefValue1,PrefValue2,PrefValue3,PrefValue4,PrefValue5,PrefValue6,PrefValue7,PrefValue8,PrefValue9,GeoMapBoundary)
{
APICategoryString = '';
APIFilterString = '';

BuildPrefString(PrefValue1,1);
BuildPrefString(PrefValue2,2);
BuildPrefString(PrefValue3,3);
BuildPrefString(PrefValue4,4);
BuildPrefString(PrefValue5,5);
BuildPrefString(PrefValue6,6);
BuildPrefString(PrefValue7,7);
BuildPrefString(PrefValue8,8);
BuildPrefString(PrefValue9,9);

if (GeoMapBoundary != null)
	MapSearchLoad = 1;

ApplyPref(1)
}

function GeoSearch(SearchTxt,PrefValue1,PrefValue2,PrefValue3,PrefValue4,PrefValue5,PrefValue6,PrefValue7,PrefValue8,PrefValue9,GeoMapBoundary)
{
APICategoryString = '';
APIFilterString = '';

if (SearchTxt != null)
    APISearchValue = SearchTxt;
else
    APISearchValue = '';

BuildPrefString(PrefValue1,1);
BuildPrefString(PrefValue2,2);
BuildPrefString(PrefValue3,3);
BuildPrefString(PrefValue4,4);
BuildPrefString(PrefValue5,5);
BuildPrefString(PrefValue6,6);
BuildPrefString(PrefValue7,7);
BuildPrefString(PrefValue8,8);
BuildPrefString(PrefValue9,9);

if (GeoMapBoundary != null)
	MapSearchLoad = 1;

DoSearch(1)
}

function PositionSearch(PositionID)
{
    UniquePositionID = PositionID;
    
    if (ListView == 1)
        {
        ShowListView();
        LoadListView(PageID,PageStart);
        }
    else
        {
        LoadMapView();
        Map_AjaxLoadPointers();
        }
}

function BuildPrefString(PrefValue,PrefID)
{
var chkOption;
var ddOption;

if (PrefValue != null)
    {
        if (PrefValue.substring(0,1) == 'C')
        {
            APICategoryString += PrefValue.substring(2,PrefValue.length) + "|";
            APIFilterString += "|";
	        chkOption = document.getElementById("chkOption" + PrefID);
	        if (chkOption != null)
		    {
		        if (PrefValue.substring(2,PrefValue.length) == 1)
			        chkOption.checked = true;
		    }
		
        }
        
        if (PrefValue.substring(0,1) == 'F')
        {
            APIFilterString += PrefValue.substring(2,PrefValue.length) + "|";
            APICategoryString += "0|";
	        ddOption = document.getElementById("ddOption" + PrefID);
	        if (ddOption != null)
		    {
			    if (PrefValue.substring(2,PrefValue.length) != '')
				    ddOption.value = PrefValue.substring(2,PrefValue.length);
		    }
        }
    }
else
    {
            APICategoryString += "0|";
            APIFilterString += "|";
    }
}

//API Print functions - This should be called from the page that has the control
function ShowPrintAbleList(WidthReq,WindowURL,WindowName,WindowFeatures,Type,MaxResult,PosID)
{

var chkOption;
var ddOption;
var SearchString = "";
var DirectoryString = "";

if (MaxResult == null)
    MaxResult = -1;
    
if (PosID == null)
    PosID = '';
            
for (i=1;i<=9;i++)
    {
    chkOption = document.getElementById("chkOption" + i);
    if (chkOption != null)
        {
        if (chkOption.checked == true)
            SearchString += "1|";
        else
            SearchString += "0|";
        }
    else
            SearchString += "0|";
    }

for (i=1;i<=9;i++)
    {
    ddOption = document.getElementById("ddOption" + i);
    if (ddOption != null)
        {
        if (GeoFilter == "ddOption" + i)
        {
            if (HasSearched == false)
                SearchString += "|";
             else
                SearchString += ddOption.value + "|";
        }
        else
            SearchString += ddOption.value + "|";
        }
     else
        SearchString += "|";
    } 
        
if (APIFilterString != "" && APICategoryString != "")
    SearchString = APICategoryString + APIFilterString
        	
if (document.getElementById("txtProdServ") != null)
    {
    if (document.getElementById("txtProdServ").value != "")
        DirectoryString += "1|" + document.getElementById("txtProdServ").value;
    else
        DirectoryString += "0|";
    }
else
    DirectoryString += "0|";
    
if (document.getElementById("txtCompany") != null)
    {
    if (document.getElementById("txtCompany").value != "")
        DirectoryString += "|1|" + document.getElementById("txtCompany").value;
    else
        DirectoryString += "|0|";
    }
else
    DirectoryString += "|0|";
    	    
var SearchValue;

if (document.getElementById("txtSearch") != null && APISearchValue == '')
    SearchValue = document.getElementById("txtSearch").value;
else
    SearchValue = APISearchValue;
    
if (ListView == 1)
    var MapDriven = 0;
else
    var MapDriven = 1;     
       	 
var Params = ''
Params += document.getElementById("AccID").value + '|';

if (HasSearched == false)
{
    Params += '0|';
    Params += '0|';
}
else
{
    Params += ListLat + '|';
    Params += ListLng + '|';
}


Params += SessionID + '|';
Params += WidthReq + '|';
Params += browserType + '|';
Params += browserVersion + '|';
Params += SearchValue + '|';
Params += SearchString.replace(/&/g,"~amp~") + DirectoryString + '|';
Params += MapDriven + '|'
Params += MaxResult + '|'
Params += PosID + '|'
Params += document.getElementById("AltAccID").value;

if (WindowURL == null)
    {
    if (Type == "P")
        WindowURL = ServerLocation + 'BizMapPrintView.aspx';
        
    if (Type == "T")
        {
        WindowURL = ServerLocation + 'BuildSatNavFile.aspx';
        WindowFeatures = "width=700px,height=300px,scrollbars=yes";
        }
        
    if  (Type == "R")
        {
        WindowURL = ServerLocation + 'BizMapRSSFeed.aspx';
        WindowFeatures = "";
        WindowName = "_blank"
        }
    }
    
window.open(WindowURL + "?Params=" + Params + "&AccKey=" + AccountKey,WindowName,WindowFeatures);
}

//API Print function - This should be called from the Print Page
function LoadPrintView(ParameterString,CallBackFunction)
{
document.getElementById("BizMapPrintList").innerHTML = "<span style='font-family:arial;font-size:12pt;font-weight:bold'>Loading Please Wait...</span>"
var request = ServerLocation + "BuildPrintView.aspx" +
                                       "?Params=" + ParameterString + "&PF=" + CallBackFunction;
ServerJavascriptRequest(request);     
}

//API Driving Directions
function LoadDrivingDirections(StartAddress,EndAddress,WindowName,WindowFeatures)
{
window.open(ServerLocation + "BizMapDirections.aspx?saddr=" + StartAddress + "&daddr=" + EndAddress + "&Param=" + document.getElementById("AccID").value + "|" + SessionID + "|0",WindowName,WindowFeatures);
}

//API Print function - This is called from the Print Build Page to indicate data available
function BizMapPrintLoaded()
{
document.getElementById("BizMapPrintList").innerHTML = BizMapPrintHTML;
}

//API Print function - This is called from the Print Build Page to indicate data error
function BizMapPrintLoadedError()
{
document.getElementById("BizMapPrintList").innerHTML = BizMapPrintHTML;
}

//Stats Function to record when actions happen
function LogStat(PosID,StatID)
{
var request = ServerLocation + "BizMapStatLog.aspx?AID=" + document.getElementById("AccID").value + "&PosID=" + PosID + "&StatID=" + StatID;
ServerJavascriptRequest(request)
}

//Load Information Div on Request
function ShowInformationScreen(x)
{
        var TemplateHTML = InfoScreenTemplateHTML;
        var ReplaceString;
        document.getElementById("information_overlay").style.display = "";
      
        if (ViewMode == "List")
            {
            document.getElementById("listview_overlay").style.display = "none"; 

            TemplateHTML = TemplateHTML.replace(/BMTemplate_UniqueIdentifier/g, Positions[x][1]);
            TemplateHTML = TemplateHTML.replace(/BMTemplate_ShortName/g, Positions[x][2]);
            TemplateHTML = TemplateHTML.replace(/BMTemplate_AddressLine1/g, Positions[x][3]);
            TemplateHTML = TemplateHTML.replace(/BMTemplate_AddressLine2/g, Positions[x][4]);
            TemplateHTML = TemplateHTML.replace(/BMTemplate_AddressLine3/g, Positions[x][5]);
            TemplateHTML = TemplateHTML.replace(/BMTemplate_AddressLine4/g, Positions[x][6]);
            TemplateHTML = TemplateHTML.replace(/BMTemplate_PostCode/g, Positions[x][7]);
            TemplateHTML = TemplateHTML.replace(/BMTemplate_ContactNumber/g, Positions[x][9]);
            TemplateHTML = TemplateHTML.replace(/BMTemplate_ContactEmail/g, Positions[x][10]);
            TemplateHTML = TemplateHTML.replace(/BMTemplate_ShortDescription/g, Positions[x][18]);
            TemplateHTML = TemplateHTML.replace(/BMTemplate_InformationField1/g, Positions[x][21]);
            TemplateHTML = TemplateHTML.replace(/BMTemplate_InformationField2/g, Positions[x][22]);
            
            if (DuelMode == 1)
                TemplateHTML = TemplateHTML.replace(/BMFunction_ShowOnMap/g, 'javascript:LoadMapView(); LocatePosition(' + Positions[x][16] + ',' + Positions[x][17] + ',' + Positions[x][0] + ',\'' + Positions[x][1] + '\')');
            else
                TemplateHTML = TemplateHTML.replace(/BMFunction_ShowOnMap/g, 'javascript:ShowOnMap(' + x + ')');
            }
            
        if (ViewMode == "Map")
            {
            if (ListView == 1)
                document.getElementById("map").style.display = "none";  
            
            TemplateHTML = TemplateHTML.replace(/BMTemplate_UniqueIdentifier/g, Markers[x][1]);
            TemplateHTML = TemplateHTML.replace(/BMTemplate_ShortName/g, Markers[x][2]);
            TemplateHTML = TemplateHTML.replace(/BMTemplate_AddressLine1/g, Markers[x][3]);
            TemplateHTML = TemplateHTML.replace(/BMTemplate_AddressLine2/g, Markers[x][4]);
            TemplateHTML = TemplateHTML.replace(/BMTemplate_AddressLine3/g, Markers[x][5]);
            TemplateHTML = TemplateHTML.replace(/BMTemplate_AddressLine4/g, Markers[x][6]);
            TemplateHTML = TemplateHTML.replace(/BMTemplate_PostCode/g, Markers[x][7]);
            TemplateHTML = TemplateHTML.replace(/BMTemplate_ContactName/g, Markers[x][8]);
            TemplateHTML = TemplateHTML.replace(/BMTemplate_ContactNumber/g, Markers[x][9]);
            TemplateHTML = TemplateHTML.replace(/BMTemplate_ContactEmail/g, Markers[x][10]);
            TemplateHTML = TemplateHTML.replace(/BMTemplate_LinkURL/g, Markers[x][11]);
            TemplateHTML = TemplateHTML.replace(/BMTemplate_ShortDescription/g, Markers[x][18]);
            TemplateHTML = TemplateHTML.replace(/BMTemplate_InformationField1/g, Markers[x][21]);
            TemplateHTML = TemplateHTML.replace(/BMTemplate_InformationField2/g, Markers[x][22]);
            TemplateHTML = TemplateHTML.replace(/BMFunction_ShowOnMap/g, 'javascript:HideInformationScreen()');
            }
            
           
            TemplateHTML = TemplateHTML.replace(/BMFunction_CloseInformationScreen/g, 'javascript:HideInformationScreen()');
                
            document.getElementById("information_overlay").innerHTML = TemplateHTML;     
}

function HideInformationScreen()
{
    document.getElementById("information_overlay").style.display = "none";
    
    if (ViewMode == "List")
        document.getElementById("listview_overlay").style.display = "";  
    if (ViewMode == "Map")
        {
        if (ListView == 1)
            document.getElementById("map").style.display = "";  
        }
}

function ShowSmallGoogleMapControl()
{
	map.removeControl(new GSmallMapControl());
	map.addControl(new GSmallMapControl());
}


