﻿// Javascript to support the operation of the Google Maps Control
// Also does some dome tweaking to make the page react correctly on
// partial post backs for collecting result data.
var bounds;
var southWest;
var northEast;
var overlays = new Array;
var productIds = new Array;
var markerCount = 0;
var rowsReturned = 0;
var submitOk = false;
var originalText;
var renderPoints = false;
var timeOutHit = false;
var timeOutId;
var productId;

// Get the location data from the server useing Googles GDownloadURL Function
function GetLocationData()
{
    // Check if we should Render Points on the screen, we may not want to if were in the
    // Middle of a zoom operation
    if (renderPoints)
    {
        // Clear any time out we are waiting for as we have just made a new request
        ClearTimeOut();
        
        // Display the progress div
        ShowProgress();
        
        // Get the bounds of the current map
        bounds = map.getBounds();
        southWest = bounds.getSouthWest();
        northEast = bounds.getNorthEast();

        // Remove any markers for the overlay array that are no longer in our
        // view port
        RemoveMarkersOutSideViewPort();
        
        // Get the product ID we have selected in the drop down
        productId = document.getElementById("products").value;

        // Download the data and call the processing function
        GDownloadUrl("CIPP_Get_Location_Data.aspx?TopLeftLong="+ northEast.lng().toString() +
                                       "&TopLeftLat=" + northEast.lat().toString() +
                                       "&BottomRightLong=" + southWest.lng().toString() +
                                       "&BottomRightLat=" + southWest.lat().toString() +
                                       "&ProductType=" + productId.toString(), ProcessDownloadedData);                                        
        
        // Set a time out to give the user a message if we don't get a response after 10 secs
        SetTimeOut();
    }    
}

// This function is called from a piece of JavaScript that is injected into the
// Page after the ajax update panel has done its work in calling the doSearch
// server side code
function move_map_to_location(position, zoomLevel)
{
    // Break up the long and Lat
    var lnglat = position.split(",");

    if (lnglat.length == 2)
    {
        var lat = parseFloat(lnglat[1]);
        var lng = parseFloat(lnglat[0]);

        var currentZoom = map.getZoom();
        var currentCenter = map.getCenter();
        
        map.setCenter(new GLatLng(lat, lng));
        map.setZoom(zoomLevel);       
    }
}

// Clears the map overlays and reset our internal array
function ClearOverlays()
{
    map.clearOverlays();
            
    // Hide the key
    mapKey.style.visibility = "hidden";
    
    overlays = new Array();
    productIds = new Array();
}

// Zoom starting don't render points
function zoom_start()
{
    // Zoom start switch of normal rendering of point
    renderPoints = false;
}

// Zoom completed render points, and display them
function zoom_complete(newZoomLevel, oldZoomLevel)
{
    renderPoints = true;    
    load_map_points();
}

// Check if we are within the points showable zoom level
function load_map_points()
{
    // Have we hit the zoom level to show point and are we zooming in 
    if (map.getZoom() <= showPointsZoomLevel)
    {
        ClearOverlays();
        HideProgress();
    }
    else
    {
        // Re-draw the location markers
        GetLocationData();
    }

}

// removes whitespace-only text node children
function CleanWhiteSpace(topLevelNode)
{
    for (var i = topLevelNode.childNodes.length - 1; i >= 0; i--)
    {
        var node = topLevelNode.childNodes[i];
        if (node.nodeType == 3)
        {
            topLevelNode.removeChild(node);
        }
    }
}

// Shows the progress bar
function ShowProgress()
{
    var div = document.getElementById("progressImage");    
    div.style.display = "";
    
    var div2 = document.getElementById("summaryDiv");
    div2.style.display = "none";
}

// Search button clicked set flag to allow it to render points
// fire the default button server side stuff to get the data
function Search_Click()
{
    ShowProgress();
    map.closeInfoWindow();
    
    renderPoints = true;
    
    // Set our submit flag
    submitOk = true;
    
    // And Call the WebForm Event of the button click
    WebForm_FireDefaultButton(event, 'doSearch');    
}

// Hides the progress bar
function HideProgress()
{
    var div = document.getElementById("progressImage");    
    div.style.display = "none";
    var summaryDiv = document.getElementById("summaryDiv");
    summaryDiv.style.display = "";
}

// Bit of Cross Browser code to get the value from the DOM as required
function GetText(node)
{
    if(node.text)
    {
        return node.text;
    }
    else
    {
        if (node.textContent)
        {
            return node.textContent;
        }
        else
        {
            return '';
        }
    }
}

// Get's each marker we've created and decides if it's no longer in our viewport
// If it's outside the view port remove it
function RemoveMarkersOutSideViewPort()
{
    var myListLength = overlays.length;
    
    for(var i = (myListLength - 1); i > -1; i--)
    {
        point = overlays[i].getPoint();
        icon = overlays[i].getIcon();        

        if ((point.x > northEast.x || point.x < southWest.x) ||
            (point.y > northEast.y || point.y < southWest.y))
        {
            map.removeOverlay(overlays[i]); // Remove the overlay as it's outside the view port
            overlays.splice(i,1);
            productIds.splice(i,1);
            myListLength--;
        }
    }
}

// Removes any markers in the overlays list that are not in the list passed in
// this is used to make sure we remove points from the list if the product filter mix
// changes
function RemoveMarkersNotInNewList(list)
{
    var overlay;
    var removePoint;
    var x;
    var i;
    
    // js optimisation
    var myListLength = list.length;
    var overlayListLength = overlays.length
    
    for(x = (overlayListLength - 1); x > -1; x--)
    {
        overlay = overlays[x];
        
        point = overlay.getPoint();
        pointProductId = productIds[x];
        removePoint = true;
        
        // Is this point in out list to keep
        for(i = 0; i < myListLength; i++)
        {
            newPoint = list[i].getPoint();
            
            if(newPoint.x == point.x && newPoint.y == point.y && (pointProductId == productId || productId == 'ALL'))
            {
                removePoint = false;
            }
        }
        
        if (removePoint)
        {
            map.removeOverlay(overlays[x]); // Remove the overlay as it's outside the view port
            overlays.splice(x,1);
            productIds.splice(x,1);
            overlayListLength--;
        }
    }
}

// Is their already a marker at this point for this product
function MarkerAtPoint(point, productIdToCheck)
{
    var overlayLength = overlays.length;
    
    for(var i = 0; i < overlayLength; i++)
    {
        workingPoint = overlays[i].getPoint();

        if ((point.x == workingPoint.x) && (point.y == workingPoint.y) && (productIdToCheck == productIds[i] || productId == 'ALL'))
        {
            return true;
        }
    }

    return false;
}

// Clear the Time Out Wait
function ClearTimeOut()
{
    // Clear the time out if it's set
    if (timeOutId)
    {
        window.clearTimeout(timeOutId);
    }
    
    timeOutHit = false;
}

// Takes the data downloaded from the server and Places it on the map
function ProcessDownloadedData (data, responseCode)
{               
    // Get the DOM elements we will be working with
    var summaryText = document.getElementById("resultsText");
    var resultsSummary = document.getElementById("resultsSummary");
    var mapKey = document.getElementById("mapKey"); 

    // Has the time out been hit?
    if (!timeOutHit)
    {      
        ClearTimeOut();         
        // Are we at a Zoom Level where we should show the poitns
        if (map.getZoom() > showPointsZoomLevel)
        {
            // Get the XML from the server
            var xml = GXml.parse(data);

            // Now process it by walking the DOM
            if(xml.documentElement)
            {
                var locations = xml.documentElement.getElementsByTagName("LocationRequest");
                rowsReturned = GetText(xml.documentElement.getElementsByTagName("NumberOfLocations")[0]);
                
                var newMarkers = new Array();
                
                // Javascript optimisation to prevent the length being evaluated on each loop
                var myListLength = locations.length;                
               
                for (var i = 0; i < myListLength; i++)
                {
                    var lng;
                    var lat;
                    var products = new Array;
                    var names = new Array;
                    
                    // Location Info Extract first child node, all node elements can only be accessed via index
                    // using the child nodes collection
                    CleanWhiteSpace(locations[i]); // Clean <Locations> tag

                    var xmlLocation = locations[i].childNodes[0]; // Get <LocationRequest> Tag

                    CleanWhiteSpace(xmlLocation); // Clean <LocationRequestTag>
                    
                    var lng = parseFloat(GetText(xmlLocation.childNodes[0])); // Get <Latitude> Tag
                    var lat = parseFloat(GetText(xmlLocation.childNodes[1])); // Get <Longitude> Tag
                    var geoCode = GetText(xmlLocation.childNodes[2]); // Get <Gecode> Tag (Not used at present)
                    var name = GetText(xmlLocation.childNodes[3]); // Get <Name> Tag
                    var zoomLevel = GetText(xmlLocation.childNodes[4]); // Get <ZoomLevel> Tag
                    var isStockist = GetText(xmlLocation.childNodes[5]); // Get <isStockist> Tag
                    
                    var productId;

                    // Product Info Extract 2nd child node
                    var xmlProducts = locations[i].childNodes[1]; // Get <Products> Tag

                    CleanWhiteSpace(xmlProducts); // Clean <Products> Tag

                    // Go through each product extracing the Product Items And Address Details for the product

                    if (xmlProducts.childNodes.length == 1)
                    {
                        // Single Product only
                        var product = xmlProducts.childNodes[0];
                        CleanWhiteSpace(product); // Clean <Product> Tag

                        // Go get all the data from our product
                        var companyName = GetText(product.childNodes[1]);
                        var productName = GetText(product.childNodes[2]);
                        productId = GetText(product.childNodes[3]);
                        var htmlLink = GetText(product.childNodes[4]);
                        CleanWhiteSpace(product.childNodes[5]);
                        var siteAddress = product.childNodes[5];
                        CleanWhiteSpace(product.childNodes[6]);
                        var salesOffice = product.childNodes[6];
                        CleanWhiteSpace(product.childNodes[7]);
                        var placingTracking = product.childNodes[7];

                        var pricesTelNo = GetText(salesOffice.childNodes[6]);
                        var trackingTelNo = GetText(placingTracking.childNodes[6]);


                        if (isStockist=="true") 
                        {
                            products[0] = BuildStockistTabSingleProduct(siteAddress, pricesTelNo, trackingTelNo, htmlLink, name, companyName,lng,lat);
                            names[0] = name;
                        }
                        else
                        {
                            products[0] = BuildProductTabSingleProduct(siteAddress, pricesTelNo, trackingTelNo, htmlLink, name, companyName,lng,lat);
                            names[0] = productName;

                            products[1] = BuildProductTabMoreInfo(salesOffice, placingTracking);
                            names[1] = infoWindowTabMoreInfo;
                        }                            
                    }
                    else
                    {
                        // Loop through each product ToDo : This is where you'll build the data
                        // for a multi product value, you'll need to write BuildInfoTabMultiProduct Function to return a collection of info windows
                        for(var x = 0; x < xmlProducts.childNodes.length && x < 4 ; x++)
                        {
                        
                              // Single Product only
                            var product = xmlProducts.childNodes[x];
                            CleanWhiteSpace(product); // Clean <Product> Tag

                            // Go get all the data from our product
                            var productLocationName = GetText(product.childNodes[0]);
                            var companyName = GetText(product.childNodes[1]);
                            var productName = GetText(product.childNodes[2]);
                            
                            productId = GetText(product.childNodes[3]);
                            var htmlLink = GetText(product.childNodes[4]);
                            CleanWhiteSpace(product.childNodes[5]);
                            var siteAddress = product.childNodes[5];
                            CleanWhiteSpace(product.childNodes[6]);
                            var salesOffice = product.childNodes[6];
                            CleanWhiteSpace(product.childNodes[7]);
                            var placingTracking = product.childNodes[7];

                            var pricesTelNo = GetText(salesOffice.childNodes[6]);
                            var trackingTelNo = GetText(placingTracking.childNodes[6]);

                            if (isStockist=="true") 
                            {
                                products[0] = BuildStockistTabSingleProduct(siteAddress, pricesTelNo, trackingTelNo, htmlLink, name,lng,lat);
                                names[0] = name;
                            }
                            else
                            {


                                products[x] = BuildProductTabMultiProduct(siteAddress, pricesTelNo, trackingTelNo, htmlLink, productLocationName, companyName, salesOffice, placingTracking,lng,lat);
                                names[x] = productName;
                            }

                        }
                        
                        if ( xmlProducts.childNodes.length > 5 ) 
                        {
                            products[x] = BuildTabForExtraProducts(xmlProducts);
                            //names[x] = infoWindowExtraProductsInfo;
                            names[x] = moreProductText;
                            x++;
                        }
                        
                        
                    }

                    // Create the location
                    var point = new GLatLng(lng,
                                            lat);

                    if ( xmlProducts.childNodes.length > 1 )
                    {
                        var Tooltip=name + ": " + multiProductText;
                    }                    
                    
                    if ( xmlProducts.childNodes.length == 1  && isStockist!="true" )
                    {
                        //products[x] = BuildProductTabMoreInfo(salesOffice, placingTracking);
                        //names[x] = infoWindowTabMoreInfo;
                        var Tooltip=name + ": " + productName
                    }
                    
                    if ( isStockist=="true" )
                    {
                        var Tooltip=name + ": " + GetText(siteAddress.childNodes[0]) ;
                    }
                    

                    // Now build a marker with the info window and data arrays
                    var marker = createMarker(point, zoomLevel, products, names,Tooltip ,isStockist);

                    newMarkers[newMarkers.length] = marker;
                    
                    // May need to review how this works when multi-products are being used
                    if (!MarkerAtPoint(point, productId))
                    {   
                        overlays[overlays.length] = marker;
                        productIds[productIds.length] = productId;
                        map.addOverlay(marker);
                    }              
                }                
                
                RemoveMarkersNotInNewList(newMarkers);
            }    
            
            // Do a little bit of Dom tweaking to sort styles etc.. out once data is retrieved
            // This makes the result summary and map key appear   
            mapKey.style.visibility = "visible";                
  
            var summaryString = resultsSummary.value.replace("%1",rowsReturned.toString());
            summaryText.innerHTML = summaryString;
        }
    }
    HideProgress();
}

// Creates a marker at the given with the info data array
function createMarker(point, zoomLevel, products, names, toolTipText, isStockist)
{
    var length = products.length;
    var infoTabs = new Array;
    
    var myIcon = new GIcon();    

    myIcon.iconSize = new GSize(16, 16);
    
    myIcon.iconAnchor = new GPoint(6, 20);
    myIcon.infoWindowAnchor = new GPoint(15, 1);  
    
    if (isStockist=="true") 
    {
        myIcon.image = "Images/SiteLocationStockist.png";   
    }
    else
    {
       myIcon.image = "Images/SiteLocation1.png";   
    }
    
    // Only continue if we have the right number of items in both arrays
    if (length == names.length)
    {
        for(var i = 0; i < length; i++)
        {
            // Our info window content
            var tab = new GInfoWindowTab(names[i], products[i]);
            tab.maxWidth = 550;
            infoTabs[i] = tab ;
        }
    }
    // Place a marker at the location specified in the point
    var marker = new GMarker(point, {icon: myIcon, title: toolTipText});    
    GEvent.addListener(marker, "click", function() {
                                                        // Set a function to create the popup
                                                        marker.openInfoWindowTabsHtml(infoTabs);                                                        
                                                   });
    return marker;
}

// This creates the HTML for the first tab of the info window for a single product
function BuildProductTabSingleProduct(siteAddress, pricesTelNo, trackingTelNo, htmlLink, locationName, companyName,lng,lat)
{
    var address1 = GetText(siteAddress.childNodes[0]);
    var address2 = GetText(siteAddress.childNodes[1]);
    var address3 = GetText(siteAddress.childNodes[2]);
    var address4 = GetText(siteAddress.childNodes[3]);
    var address5 = GetText(siteAddress.childNodes[4]);
    var postCode = GetText(siteAddress.childNodes[5]);

    var sHtml = "<table class=\"infoPanelTable\" cellpadding=\"5\" cellspacing=\"4\">";
    sHtml = sHtml + "<tr><td><span>" + locationName + "</span><br>" + companyName + "</td>";
    sHtml = sHtml + "<td rowspan=\"2\"><span>" + infoWindowHeader2 + "</span><br>";
    sHtml = sHtml + address1 + "<br>";
    sHtml = sHtml + address2 + "<br>";
    sHtml = sHtml + address3 + "<br>";
    sHtml = sHtml + address4 + "<br>";
    
    if (address5.length > 0)
    {
        sHtml = sHtml + address5 + "<br>";    
    }
    
    sHtml = PopulateLongitudeLatitude(sHtml,postCode,lat,lng);
    sHtml = sHtml + "</td></tr>";
    sHtml = sHtml + "<tr><td><span>" + infoWindowHeader3 + "</span> " + pricesTelNo + "<br>";
    sHtml = sHtml + "<span>" + infoWindowHeader4 + "</span> " + trackingTelNo + "<br>";
    sHtml = sHtml + "<a target=\"_blank\" href=\"" + htmlLink + "\"/>" + htmlLink + "</a></td></tr>";
    sHtml = sHtml + "</table>";

    return sHtml;
}


// This creates the HTML for the first tab of the info window for a single product
function BuildStockistTabSingleProduct(siteAddress, pricesTelNo, trackingTelNo, htmlLink, locationName,lng,lat)
{
    var address1 = GetText(siteAddress.childNodes[0]);
    var address2 = GetText(siteAddress.childNodes[1]);
    var address3 = GetText(siteAddress.childNodes[2]);
    var address4 = GetText(siteAddress.childNodes[3]);
    var address5 = GetText(siteAddress.childNodes[4]);
    var postCode = GetText(siteAddress.childNodes[5]);
    var TelNo = GetText(siteAddress.childNodes[6]);
    var techTelephone = GetText(siteAddress.childNodes[7]);

    var sHtml = "<table class=\"infoPanelTable\" cellpadding=\"5\" cellspacing=\"4\">";
    sHtml = sHtml + "<tr><td><span>" + locationName + "</span><br>";
    sHtml = sHtml + "<br>" + address1 + "<br>";
    sHtml = sHtml + address2 + "<br>";
    sHtml = sHtml + address3 + "<br>";
    sHtml = sHtml + address4 + "<br>";
    
    if (address5.length > 0)
    {
        sHtml = sHtml + address5 + "<br>";
    }
    
    sHtml = PopulateLongitudeLatitude(sHtml,postCode,lat,lng);
    sHtml = sHtml + TelNo + "<br><br>";
    sHtml = sHtml + "<a target=\"_blank\" href=\"" + htmlLink + "\"/>" + htmlLink + "</a><br>";
    sHtml = sHtml +"Technical Contact : " + techTelephone + "</td></tr>";
    sHtml = sHtml + "</table>";

    return sHtml;
}




// This creates the HTML for the first tab of the info window for a single product
function BuildProductTabMultiProduct(siteAddress, pricesTelNo, trackingTelNo, htmlLink, locationName, companyName, salesOffice, placingTracking,lng,lat)
{
    var address1 = GetText(siteAddress.childNodes[0]);
    var address2 = GetText(siteAddress.childNodes[1]);
    var address3 = GetText(siteAddress.childNodes[2]);
    var address4 = GetText(siteAddress.childNodes[3]);
    var address5 = GetText(siteAddress.childNodes[4]);
    var postCode = GetText(siteAddress.childNodes[5]);
     // Get the Sales office details
    var salesAddress1 = GetText(salesOffice.childNodes[0]);
    var salesAddress2 = GetText(salesOffice.childNodes[1]);
    var salesAddress3 = GetText(salesOffice.childNodes[2]);
    var salesAddress4 = GetText(salesOffice.childNodes[3]);
    var salesAddress5 = GetText(salesOffice.childNodes[4]);
    var salesPostCode = GetText(salesOffice.childNodes[5]);
    var salestelNo = GetText(salesOffice.childNodes[6]);
    var salesEmail = GetText(salesOffice.childNodes[8]);

    // Get the Tracking orders details
    var trackingAddress1 = GetText(placingTracking.childNodes[0]);
    var trackingAddress2 = GetText(placingTracking.childNodes[1]);
    var trackingAddress3 = GetText(placingTracking.childNodes[2]);
    var trackingAddress4 = GetText(placingTracking.childNodes[3]);
    var trackingAddress5 = GetText(placingTracking.childNodes[4]);
    var trackingPostCode = GetText(placingTracking.childNodes[5]);
    var trackingTelNo = GetText(placingTracking.childNodes[6]);
    var trackingEmail = GetText(placingTracking.childNodes[8]);

    var sHtml = "<table class=\"infoPanelTable\" cellpadding=\"5\" cellspacing=\"4\">";
    sHtml = sHtml + "<tr><td><span>" + locationName + "</span><br>" + companyName + "</td>";
    sHtml = sHtml + "<td rowspan=\"2\"><span>" + infoWindowHeader2 + "</span><br>";
    sHtml = sHtml + address1 + "<br>";
    sHtml = sHtml + address2 + "<br>";
    sHtml = sHtml + address3 + "<br>";
    sHtml = sHtml + address4 + "<br>";
    
    if (address5.length > 0)
    {
        sHtml = sHtml + address5 + "<br>";
    }
        
    sHtml = PopulateLongitudeLatitude(sHtml,postCode,lat,lng);
    sHtml = sHtml + "</td></tr>"; 
    sHtml = sHtml + "<tr><td><span>" + infoWindowHeader3 + "</span> " + pricesTelNo + "<br>";
    sHtml = sHtml + "<span>" + infoWindowHeader4 + "</span> " + trackingTelNo + "<br>";
    sHtml = sHtml + "<a target=\"_blank\" href=\"" + htmlLink + "\"/>" + htmlLink + "</a></td></tr>";
    sHtml = sHtml + "<tr><td>";
    sHtml = sHtml + "<span>" + infoWindowHeader4 + "</span><br>";
    sHtml = sHtml + trackingAddress1 + "<br>";
    sHtml = sHtml + trackingAddress2 + "<br>";
    sHtml = sHtml + trackingAddress3 + "<br>";
    sHtml = sHtml + trackingAddress4 + "<br>";
    
    if (trackingAddress5.length > 0)
    {
        sHtml = sHtml + trackingAddress5 + "<br>";
    }
    
    sHtml = sHtml + trackingPostCode + "<br>";  
    sHtml = sHtml + trackingTelNo + "<br>";
    sHtml = sHtml + trackingEmail + "</td>";
    //sHtml = sHtml + "<td>&nbsp;</td>";
    sHtml = sHtml + "<td><span>" + infoWindowHeader5 + "</span><br>";
    sHtml = sHtml + salesAddress1 + "<br>";
    sHtml = sHtml + salesAddress2 + "<br>";
    sHtml = sHtml + salesAddress3 + "<br>";
    sHtml = sHtml + salesAddress4 + "<br>";
    
    if (salesAddress5.length > 0)
    {
        sHtml = sHtml + salesAddress5 + "<br>";
    }
    
    sHtml = sHtml + salesPostCode + "<br>";
    sHtml = sHtml + salestelNo + "<br>";
    sHtml = sHtml + salesEmail + "</td></td>";
    sHtml = sHtml + "</table>";

    return sHtml;
}

function PopulateLongitudeLatitude(sHtml,PostCode,lat,lng)
{
    sHtml = sHtml + PostCode + "<br><br>";
    sHtml = sHtml + "<b>" + infoWindowHeader6 + "</b><br>"
    sHtml = sHtml + infoWindowHeader7 + lng + "<br>"
    sHtml = sHtml + infoWindowHeader8 + lat + "<br>" 
    return sHtml;
}
// Thsi creates the HTML for the second tab of the info window (more info) for a single product
function BuildProductTabMoreInfo(salesOffice, placingTracking)
{
    var sHtml = "<table class=\"infoPanelTable\" cellpadding=\"5\" cellspacing=\"4\">";

    // Get the Sales office details
    var salesAddress1 = GetText(salesOffice.childNodes[0]);
    var salesAddress2 = GetText(salesOffice.childNodes[1]);
    var salesAddress3 = GetText(salesOffice.childNodes[2]);
    var salesAddress4 = GetText(salesOffice.childNodes[3]);
    var salesAddress5 = GetText(salesOffice.childNodes[4]);
    var salesPostCode = GetText(salesOffice.childNodes[5]);
    var salestelNo = GetText(salesOffice.childNodes[6]);
    var salesEmail = GetText(salesOffice.childNodes[8]);


    // Get the Tracking orders details
    var trackingAddress1 = GetText(placingTracking.childNodes[0]);
    var trackingAddress2 = GetText(placingTracking.childNodes[1]);
    var trackingAddress3 = GetText(placingTracking.childNodes[2]);
    var trackingAddress4 = GetText(placingTracking.childNodes[3]);
    var trackingAddress5 = GetText(placingTracking.childNodes[4]);
    var trackingPostCode = GetText(placingTracking.childNodes[5]);
    var trackingTelNo = GetText(placingTracking.childNodes[6]);
     var trackingEmail = GetText(placingTracking.childNodes[8]);


    // Create the info tab HTML for the tracking section
    sHtml = sHtml + "<tr><td>";
    sHtml = sHtml + "<span>" + infoWindowHeader4 + "</span><br>";
    sHtml = sHtml + trackingAddress1 + "<br>";
    sHtml = sHtml + trackingAddress2 + "<br>";
    sHtml = sHtml + trackingAddress3 + "<br>";
    sHtml = sHtml + trackingAddress4 + "<br>";
    
    if (trackingAddress5.length > 0)
    {
        sHtml = sHtml + trackingAddress5 + "<br>";
    }
    
    sHtml = sHtml + trackingPostCode + "<br>";
    sHtml = sHtml + "<br>";
    sHtml = sHtml + trackingTelNo + "<br>";
    sHtml = sHtml + trackingEmail + "</td>";
    sHtml = sHtml + "<td>&nbsp;</td>";
    sHtml = sHtml + "<td><span>" + infoWindowHeader5 + "</span><br>";
    sHtml = sHtml + salesAddress1 + "<br>";
    sHtml = sHtml + salesAddress2 + "<br>";
    sHtml = sHtml + salesAddress3 + "<br>";
    sHtml = sHtml + salesAddress4 + "<br>";
    
    if (salesAddress5.length > 0)
    {
        sHtml = sHtml + salesAddress5 + "<br>";
    }
    
    sHtml = sHtml + salesPostCode + "<br>";
    sHtml = sHtml + "<br>";
    sHtml = sHtml + salestelNo + "<br>";
    sHtml = sHtml + salesEmail + "</td></td>";
    sHtml = sHtml + "</table>";
    return sHtml;
}


// Thsi creates the HTML for the second tab of the info window (more info) for a single product
function BuildTabForExtraProducts(xmlProducts)
{



var sHtml = "<table class=\"infoPanelTable\" cellpadding=\"5\" cellspacing=\"4\">";
    sHtml = sHtml + "<tr><td>";
    //sHtml = sHtml + "<span>" + infoWindowHeader6 + "</span><br>";
sHtml = sHtml + "<span> Other Products which could not fit in the result :</span><br>";
    // Loop through each product ToDo : This is where you'll build the data
    // for a multi product value, you'll need to write BuildInfoTabMultiProduct Function to return a collection of info windows
    for(var x = 4; x < xmlProducts.childNodes.length ; x++)
    {
    
       // Single Product only
        var product = xmlProducts.childNodes[x];
        CleanWhiteSpace(product); // Clean <Product> Tag

        // Go get all the data from our product
        var productName = GetText(product.childNodes[2]);
         sHtml = sHtml + productName + "<br>";
    }
    

    sHtml = sHtml + "</td>";
    sHtml = sHtml + "<td>&nbsp;</td>";
    sHtml = sHtml + "</table>";
    return sHtml;
}



// ToDo : Creates our custom info tab for multi products...
function BuildInfoTabMultiProduct(products, names)
{
    return "";
}

// Body load method to initialise the google maps object
function load() 
{   
    // Is the Browser Compatible with goolge maps   
    if (GBrowserIsCompatible()) 
    {
        // Get the DIV we render the map in
        map = new GMap2(document.getElementById("map"));

        if(map)
        {
            // Now setup all the google map properties
            map.enableContinuousZoom();
            map.setCenter(new GLatLng( startLat, startLong ), startZoomLevel);   

            map.addControl( new GLargeMapControl());
            map.addControl(new GMapTypeControl());
            map.addControl(new GOverviewMapControl(new GSize(100, 100)));  

            // Add our event listeners
            GEvent.addListener(map, "zoomstart", zoom_start);
            GEvent.addListener(map, "zoomend", zoom_complete);
            GEvent.addListener(map, "moveend", load_map_points);     
                    
            // Store the heading text before we do any searches so we
            // can put it back if we then zoom out to a level where we don't
            // display point data
            originalText = document.getElementById("resultsSummary").value.replace("%1","0");
        }
    }
}  

