﻿/* <![CDATA[ */
var c_intBusinessCategoryID = 0;
       
        
        this.displayLoadingText = function(blnDisplay) {
				var strID = "MapLoadingText";  
	    var objMapViewer = new clsJPMapViewer(document.getElementById("MapControl").clientWidth,document.getElementById("MapControl").clientHeight,document.getElementById("MapControl"));

				if (document.getElementById(strID)) {
					var oSpan=document.getElementById(strID);
				}
				else {
					var oSpan=document.createElement("div");
					objMapViewer.container.appendChild(oSpan);
					oSpan.id = strID;
				}  
				if (blnDisplay) 
				{
					var oDiv = document.createElement("div");
					oDiv.className = "mapitem";
					oSpan.appendChild(oDiv);
                    oDiv.innerHTML ='<h1>LOADING....</h1>';
					//oDiv.innerHTML = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab\#version=6,0,29,0\" width=\"150\" height=\"150\" VIEWASTEXT><param name=\"movie\" value=\"images/loadingmap.swf\" /><param name=\"wmode\" value=\"transparent\" /><param name=\"quality\" value=\"high\" /><embed src=\"images/loadingmap.swf\" wmode=\"transparent\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\"150\" height=\"150\"></embed></object>";
				
					oDiv.style.left = 450;//Math.ceil(this.mapViewer.width / 2) - 60;
					oDiv.style.top = 300;//Math.ceil(this.mapViewer.height / 2) - 70;   
				}
				else {
					oSpan.innerHTML = "";
				} 
			}

function clsJPMapViewer(strWidth, strHeight, objContainer) {
			this.width=strWidth;
			this.height=strHeight;
			this.container=objContainer;
			
			//function: initialise
			//Purpose: Initialise the size of the map viewer
			this.initialise=function () {
				this.container.style.width=this.width;
				this.container.style.height=this.height;
			}
		}
		


function DisplayItems(intBusinessCategoryID)
{
//debugger;
if (c_FetchData == 1){

    c_intOtherBusiness = 1;
      
    // Use new Map Variables to set viewable area.
    var GMap = WhatsGoogleMap;
    var resultsDiv = document.getElementById("MapResults");
    var mapBounds = GMap.map.getBounds();
        
    var southWestPoint = new LatLng;
    southWestPoint = mapBounds.getSouthWest();
    southWestPoint = LatLngToOSRef(southWestPoint.y, southWestPoint.x);
        
    var northEastPoint = new LatLng;
    northEastPoint = mapBounds.getNorthEast();
    northEastPoint = LatLngToOSRef(northEastPoint.y, northEastPoint.x);
    
//  Use new Map Variables to set viewable area.    
    var intStartX = southWestPoint.easting;
    var intStartY = northEastPoint.northing;
    var intEndX = northEastPoint.easting;
	var intEndY = southWestPoint.northing;
    
    c_intBusinessCategoryID = intBusinessCategoryID

    if (GMap.map.getZoom()<11){
        resultsDiv.innerHTML = 'You need to zoom in before we can show the selected venues.';
        }
    else{
        resultsDiv.innerHTML = 'Searching...';
        window.status = "Retrieving Business Information ....";
        this.displayLoadingText(true);
   
        wctlVenueDetails.GetBusinesses(parseInt(intStartX), parseInt(intEndX), parseInt(intStartY), parseInt(intEndY), intBusinessCategoryID, Callback)
    }
}
}
// New Callback Function
function Callback(objResponse){
//debugger;
    var GMap = WhatsGoogleMap;
    var resultsDiv = document.getElementById("MapResults");
    
   var IconPath ;
    if (c_intBusinessCategoryID == 1){
        IconPath = '/Images/Map/Restaurants.png';
    }
    
        if (c_intBusinessCategoryID == 0){
        IconPath = '/Images/Map/Hotelsinns.png';
    }
    
        if (c_intBusinessCategoryID == 2){
        IconPath = '/Images/Map/Cinemas.png';
    }

	 if (c_intBusinessCategoryID == 3){
        IconPath = '/Images/Map/Venues.png';
    } 
   
    // if error stop.
    if (objResponse.error != null){return;}
    
    var objPOIs = new Array();
    
    objPOIs = objResponse.value;
 
    // Clears the map and recreates the POI
    GMap.removePreviousLayers();
    var markerCount = 1;
        
    for (var i=0;i<objPOIs.length;i++){
    var name;
    var address1;
    var address2;
    var district;
    var town;
    var county;
    var postcode;
    var telephone;
       
    markerCount+=1;
    
    if(objPOIs[i].Name != ""){name=objPOIs[i].Name}else{name=''};
    if(objPOIs[i].Address1 != ""){address1=objPOIs[i].Address1 + ', '}else{address1=''}
    if(objPOIs[i].Address2 != ""){address2=objPOIs[i].Address2 + ', '}else{address2=''}
    if(objPOIs[i].District != ""){district=objPOIs[i].District + ', '}else{district=''}
    if(objPOIs[i].Town != ""){town=objPOIs[i].Town + ', '}else{town=''}
    if(objPOIs[i].County != ""){county=objPOIs[i].County + ', '}else{county=''}
    if(objPOIs[i].Postcode != ""){postcode=objPOIs[i].Postcode + ', '}else{postcode=''}
    if(objPOIs[i].Telephone != ""){telephone=objPOIs[i].Telephone}else{telephone=''}
 
        var lngLatCoord = new OSRef(objPOIs[i].CoordinateX, objPOIs[i].CoordinateY);
        
        GMap.createTemplatedMarkerWithIcon(lngLatCoord.toLatLng().lat, lngLatCoord.toLatLng().lng, '', IconPath, '', '<div class="MapBubble"><h1>'+name+'</h1><h2>Telephone: '+telephone+'</h2>'+address1+address2+district+town+county+postcode+'</div>', 32, 32);
        
        GMap.addDoubleClickDestination(markerCount, '/venuedetails.aspx?BusinessType='+c_intBusinessCategoryID+'&VenueId='+objPOIs[i].VenueDetailsID);
    }

   //Re-added the div status, as most people disable statusbar text changes.
    if (markerCount > 1){
        resultsDiv.innerHTML = 'Found ('+(markerCount -1 )+') Results';}
    else{
        resultsDiv.innerHTML = 'No Results Found';
    }
    
this.displayLoadingText(false);
     
    window.status = "Done.";                                                      
}

function ReturnToMainFrame(){
    var GMap = WhatsGoogleMap;
    GMap.map.returnToSavedPosition();
}

function ClearSearchResults() {
    var GMap = WhatsGoogleMap;

    // Clears the map and recreates the motor
    GMap.removePreviousLayers();

    c_intOtherBusiness = 0;

    var resultsDiv = document.getElementById("MapResults");
    resultsDiv.innerHTML = '';

}

/* ]]> */