
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();





var DoYouTravel = DoYouTravel || {};

DoYouTravel.Config = DoYouTravel.Config || {};
DoYouTravel.Config.baseUrl = '/';
DoYouTravel.Config.wsBaseUrl = '/map/ws/';
DoYouTravel.Config.DestCountText = 'I have been to <span id="destinationcountamount">0</span> destinations';
DoYouTravel.Config.pagingValue = 10;










DoYouTravel.DropDownMenu = DoYouTravel.DropDownMenu || {};



DoYouTravel.DropDownMenu = function ( id, varname, hometown )
{      

        this.id = id;
        this.varName = varname;
        this.hometown = hometown;
        this.init();
};


DoYouTravel.DropDownMenu.prototype.init = function ()
{
        ;
};

DoYouTravel.DropDownMenu.prototype.show = function ( )
{
       var self = this;
       document.body.onclick = function () { self.hide(); return false; };
       document.getElementById(this.id + "_dropdown").className="";
}


DoYouTravel.DropDownMenu.prototype.hide = function ( )
{
       document.body.onclick = "";
       document.getElementById(this.id + "_dropdown").className="hidden";
}


DoYouTravel.DropDownMenu.prototype.parseDropDownDetails = function ( xml )
{

        if ( xml == null )
        {
                return ;
        }
        
        
        // Extract destinations
        var destinationNodes = xml.getElementsByTagName('destination');
        if ( destinationNodes != null )
        {
                this.dropdownCached = new Array();
                
                for ( var i = 0; i < destinationNodes.length; i++ )
                {
                        destinationNode = destinationNodes[i];
                        
                        
                        if ( destinationNode.getElementsByTagName('county')[0].firstChild )
                        {
                               this.dropdownCached[i] = {
                                       id: destinationNode.getElementsByTagName('id')[0].firstChild.nodeValue,
                                       ci_id: destinationNode.getElementsByTagName('id')[0].firstChild.nodeValue,
                                       city: destinationNode.getElementsByTagName('city')[0].firstChild.nodeValue,
                                       county: destinationNode.getElementsByTagName('county')[0].firstChild.nodeValue,
                                       countrycode: destinationNode.getElementsByTagName('countrycode')[0].firstChild.nodeValue,
                                       lat: destinationNode.getElementsByTagName('lat')[0].firstChild.nodeValue,
                                       lng: destinationNode.getElementsByTagName('lng')[0].firstChild.nodeValue,
                                       visits: destinationNode.getElementsByTagName('numtimes')[0].firstChild.nodeValue
                                       };
                                
                        }
                        else
                        {
                               this.dropdownCached[i] = {
                                       id: destinationNode.getElementsByTagName('id')[0].firstChild.nodeValue,
                                       city: destinationNode.getElementsByTagName('city')[0].firstChild.nodeValue,
                                       countrycode: destinationNode.getElementsByTagName('countrycode')[0].firstChild.nodeValue,
                                       lat: destinationNode.getElementsByTagName('lat')[0].firstChild.nodeValue,
                                       lng: destinationNode.getElementsByTagName('lng')[0].firstChild.nodeValue,
                                       visits: destinationNode.getElementsByTagName('numtimes')[0].firstChild.nodeValue
                                       };                                
                        }
                }
                
        }
        
        
        
}

DoYouTravel.DropDownMenu.prototype.selectDropDownItem = function ( id )
{
       this.hide();
       
       var cachedItem = this.dropdownCached[id];
              
       var dropdownValueRef = document.getElementById(this.id + "_value");
              
              
       var inputRef = document.getElementById(this.id + "_input");
       inputRef.value = cachedItem.city + ", " + cachedItem.countrycode;
              
       dropdownValueRef.value = id;
              
       if ( this.hometown != 1 && this.justdropdown != 1 )
       {
              var latlng = new GLatLng(cachedItem.lat, cachedItem.lng);
              travelmap.displaySelectedDestinationsBox(latlng, cachedItem);
       }
       
       if ( this.justdropdown == 1 )
       {
              var dropdownValueRef = document.getElementById(this.id + "_value");
              dropdownValueRef.value = cachedItem.id;
              cachedItem.ci_id = cachedItem.id;
              this.currentlySelectedItem = cachedItem;
       }
       
}


DoYouTravel.DropDownMenu.prototype.addPin = function ( )
{
       if ( this.currentlySelectedItem == null )
       {
              alert("Please select a destination from the list below before attempting to add a pin!");
              return;
       }

       var latlng = new GLatLng(this.currentlySelectedItem.lat, this.currentlySelectedItem.lng);
       
       this.currentlySelectedItem.visits = 1;
       travelmap.displaySelectedDestinationsBox(latlng, this.currentlySelectedItem);
       travelmap.changeVisitCount(this.currentlySelectedItem,1 );
       
}      

DoYouTravel.DropDownMenu.prototype.displayDropDownDetails = function ( )
{
       var dropdownResultsRef = document.getElementById ( this.id + "_results");
       
       
       var tempHTML = "";
       
       for ( var i=0; i<this.dropdownCached.length; i++ )
       {
       
              if ( this.displayCounty == 1 )
              {
              tempHTML += '<li><a href="javascript://" onclick="' + this.varName + '.selectDropDownItem(' + i +')">' + this.dropdownCached[i].city + " , " + this.dropdownCached[i].county + ", " + this.dropdownCached[i].countrycode + "</a></li>";
              }
              else
              {
              
              tempHTML += '<li><a href="javascript://" onclick="' + this.varName + '.selectDropDownItem(' + i +')">' + this.dropdownCached[i].city + " , " + this.dropdownCached[i].countrycode + "</a></li>";
              
              
              }
              
       }
       
       dropdownResultsRef.innerHTML = tempHTML;

       this.show();
       
       
       var dropdownValueRef = document.getElementById(this.id + "_value");
       
       dropdownValueRef.value = "";
}




DoYouTravel.DropDownMenu.prototype.addfromdropdown = function ( hometown, e  )
{
       var self = this;
       
       var valueRef = document.getElementById(this.id + "_value");
       
       if ( travelmap.hometownCache )
       {
              if ( travelmap.hometownCache.id == valueRef.value && hometown == 1 )
              {
                     displayViewHometown();
                     return;
              }
       
       }
       
       if ( this.dropdownCached )
       {
       if ( ( this.dropdownCached[valueRef.value] == null || valueRef.value.length < 1 ) && hometown == 1 )
       {
              alert("Please select your hometown from the list below before attempting to change it!");
              return;
       }
       }
       
       if ( this.currentlySelectedItem )
       {
       var cachedItem = this.currentlySelectedItem;
       }
       else
       {
       var cachedItem = this.dropdownCached[valueRef.value];
       }
       
       if ( e == null )
       {
              cachedItem.visits = 1;
       }
       else
       {
       
              if ( e.srcElement )
              {
                     cachedItem.visits = e.srcElement.value;
              }
              else
              {
                     cachedItem.visits = e.target.value;
              }
       
       }
       
              travelmap.toggleVisited(cachedItem, cachedItem.id, hometown);
}



DoYouTravel.DropDownMenu.prototype.doAutocompleteLookup = function ( )
{
       var self = this;
       
        var ajax = new DoYouTravel.TravelMap.AutoCompleteDropdown(
                'POST',
                DoYouTravel.Config.wsBaseUrl + 'get-cities-autocomplete.php',
                true);
                
        ajax.onSuccess = function ()
        {
                self.parseDropDownDetails(this.request.responseXML);
                self.displayDropDownDetails();
        }
        
        ajax.send('&value=' + document.getElementById(this.id + "_input").value );
       
}


DoYouTravel.DropDownMenu.prototype.autocomplete = function ( )
{
       clearTimeout(this.autocomplete_timeout);
       
       this.currentlySelectedItem = null;
       this.autocomplete_timeout = setTimeout( this.varName + ".doAutocompleteLookup()", 1000);

}



















DoYouTravel.TravelMap = DoYouTravel.TravelMap || {};


DoYouTravel.TravelMap = function ( mapSize, smaller )
{
        this.mapElementId = 'mapdata';
        this.mapSize = 1;
        this.map = null;
        this.mapDestinationMarkers = new Array();
        this.mapHometownMarker = null;
        
        this.destinationCache = new Array();
        this.hometownCache = null;
        
        this.init();
        this.initMap(mapSize, smaller);
        
        this.memberId = null;
};


DoYouTravel.TravelMap.prototype.init = function ()
{
        ;
};


DoYouTravel.TravelMap.prototype.initMap = function ( mapSize, smaller )
{
        this.mapSize = mapSize;
        
        if ( GBrowserIsCompatible() )
	{
                if ( this.mapSize == 1 ||
                        this.mapSize == 2 )
                {
                        this.map = new GMap2(
                                document.getElementById("mapdata"));   
                        this.map.setCenter(new GLatLng(37.4419, 0), 1);
                }
                else
                {
                        //var mapOptions = GMapOptions();
                        if ( smaller == 1 )
                        {
                               this.map = new GMap2(
                                       document.getElementById("mapdata"),
                                       { size: new GSize(184,164) }
                                       );
                               this.map.setCenter(new GLatLng(37.4419, 0), 0);
                               
                        }
                        else
                        {
                        
                               this.map = new GMap2(
                                       document.getElementById("mapdata"),
                                       { size: new GSize(220,200) }
                                       );
                               this.map.setCenter(new GLatLng(37.4419, 0), 0);
                               
                        }
                }
		
		var mapType = this.map.getCurrentMapType();
		mapType.getMinimumResolution = function() { return 1; }
		mapType.getMaximumResolution = function() { return 12; }
		
		if ( this.mapSize == 1 ||
                        this.mapSize == 2 )
		{
                        this.map.addControl(new GLargeMapControl());
                        this.map.addControl(new GMapTypeControl());
                        this.map.enableDoubleClickZoom();
                        
                       if ( this.mapSize == 2 )
                       {
                       
                               var self = this;
                               /*
                               GEvent.addListener(this.map, "zoomend", function() {
                                      clearTimeout(self.updateTimeout);
                                      self.updateTimeout = setTimeout("travelmap.updateDestinations()",2000);
                               });
                       
                               GEvent.addListener(this.map, "moveend", function() {
                                      clearTimeout(self.updateTimeout);
                                      self.updateTimeout = setTimeout("travelmap.updateDestinations()",2000);
                               });
                               
                               //add event for the bounding box
                               
                               GEvent.addListener(this.map, "click", function(overlay, latlng) 
                               {
                                       if (!overlay)
                                       {
                                                 self.clickRadius(latlng);
                                       }
                               });*/
                       }
                        
                        
		}
                else
                {
                        this.map.disableDragging();
                        this.map.disableInfoWindow();
                        this.map.disableDoubleClickZoom();
                        this.map.disableScrollWheelZoom();
                }
                
       }
};


DoYouTravel.TravelMap.prototype.setMemId = function ( id )
{
        this.memberId = id;
};


DoYouTravel.TravelMap.prototype.clickRadius = function (  latlng )
{
var point = this.map.fromLatLngToDivPixel(latlng);

         var nePoint = new GPoint(point.x + 20, point.y - 20);
         var swPoint = new GPoint(point.x - 20, point.y + 20);
         var ne = this.map.fromDivPixelToLatLng(nePoint);
         var sw = this.map.fromDivPixelToLatLng(swPoint);
         
         var nw = new GLatLng(ne.lat(), sw.lng());
         var se = new GLatLng(sw.lat(), ne.lng());
         
         if ( this.box != null )
         {
              this.map.removeOverlay(this.box);
         }
         
         this.box = new GPolyline([ne, se, sw, nw, ne], "#FF0000", 2, .80);
         
	
         
         this.map.addOverlay(this.box);
         
         this.displayVisitsSelectorForContents(sw,ne,latlng, point);
         
         var self = this;
         var thisEvent = GEvent.addListener(this.map, 'infowindowclose', function() {
           self.map.removeOverlay(this.box);
           GEvent.removeListener(thisEvent);
         });
         
}



DoYouTravel.TravelMap.prototype.displayVisitsSelectorForContentsResponse = function ( xml )
{

        if ( xml == null )
        {
                return ;
        }
        
        // Extract destinations
        var destinationNodes = xml.getElementsByTagName('destination');
        if ( destinationNodes != null )
        {
                this.boundingBoxCached = new Array();
                
                for ( var i = 0; i < destinationNodes.length; i++ )
                {
                        destinationNode = destinationNodes[i];
                        
                        this.boundingBoxCached[i] = {
                                id: destinationNode.getElementsByTagName('id')[0].firstChild.nodeValue,
                                city: destinationNode.getElementsByTagName('city')[0].firstChild.nodeValue,
                                countrycode: destinationNode.getElementsByTagName('countrycode')[0].firstChild.nodeValue,
                                lat: destinationNode.getElementsByTagName('lat')[0].firstChild.nodeValue,
                                lng: destinationNode.getElementsByTagName('lng')[0].firstChild.nodeValue,
                                visits: destinationNode.getElementsByTagName('numtimes')[0].firstChild.nodeValue
                                };
                
                }
                
        }
        
        
}




DoYouTravel.TravelMap.prototype.displaySelectedDestinationsBox = function ( latlng, destination )
{
       
        var lat = latlng.lat();
        var lng = latlng.lng();
        
        var tmpLat = new GLatLng(lat, lng);
        
        this.map.closeInfoWindow();
        
	var icon = new GIcon();
        icon.iconSize = new GSize(0,0);
	icon.iconAnchor = new GPoint(6, 20);
	icon.infoWindowAnchor = new GPoint(6, 20);
	var tmpmarker = new GMarker(tmpLat, icon);
	
	this.map.addOverlay(tmpmarker);
	
	var temphtml =  '<div class="popup_add"><div>Please select how many times you<br/> have been to this destination: </div><ul>';
	
               
        //lookup box cached item in destination cache to pull out existing number of visits etc
       for ( var i2=0; i2<this.destinationCache.length; i2++ )
       {
              
              if ( this.destinationCache[i2].ci_id == destination.id )
              {
                     destination = this.destinationCache[i2]; 
                     break;
              }
              
       }
 
 
       var selectHTML = '<select class="visits" onchange="destinationDropDown.addfromdropdown(0, event);">';
       
       for ( var i2=1; i2<=30; i2++ )
       {
              var visitedSelected = "";
              
              if ( i2 == destination.visits )
              {
                     visitedSelected = "selected";
              }
              
              selectHTML += '<option value="' + i2 + '" ' + visitedSelected + '>' + i2 + '</option>';
       }
       selectHTML += '</select>';
       
       
       temphtml += '<li><span>' + destination.city + ", " + destination.countrycode + "</span> " + selectHTML + "</li>";
                     
	
	temphtml += "</ul></div>";
	
	
	tmpmarker.openInfoWindowHtml(temphtml);
         
         
}











DoYouTravel.TravelMap.prototype.displaySuggestedDestinationsBox = function ( latlng )
{
        var lat = latlng.lat();
        var lng = latlng.lng();
        
        var tmpLat = new GLatLng(lat, lng);
        this.map.closeInfoWindow();
        
	var icon = new GIcon();
        icon.iconSize = new GSize(0,0);
	icon.iconAnchor = new GPoint(6, 20);
	icon.infoWindowAnchor = new GPoint(6, 20);
	this.tmpmarker = new GMarker(tmpLat, icon);
	
	this.map.addOverlay(this.tmpmarker);
	
	var temphtml =  '<div class="popup_add"><p>Add a destination to your map by<br/> selecting the number of times you<br/> have been there.</p><p>Zoom in to see more</p><ul>';
	
	
         
                
                
	
	if ( this.boundingBoxCached.length > 0 )
	{
               
               for ( var i=0; i<this.boundingBoxCached.length; i++ )
               {
                     //lookup box cached item in destination cache to pull out existing number of visits etc
                     for ( var i2=0; i2<this.destinationCache.length; i2++ )
                     {
                            
                            if ( this.destinationCache[i2].ci_id == this.boundingBoxCached[i].id )
                            {
                                   this.boundingBoxCached[i] = this.destinationCache[i2]; 
                                   break;
                            }
                            
                     }
               
               
                     var selectHTML = '<select class="visits" onchange="travelmap.toggleVisitedBoundingBox(event, ' + this.boundingBoxCached[i].id + ')">';
                     
                     for ( var i2=0; i2<=30; i2++ )
                     {
                            var visitedSelected = "";
                            
                            if ( i2 == this.boundingBoxCached[i].visits )
                            {
                                   visitedSelected = "selected";
                            }
                            
                            selectHTML += '<option value="' + i2 + '" ' + visitedSelected + '>' + i2 + '</option>';
                     }
                     selectHTML += '</select>';
                     
                     
                     temphtml += '<li><span>' + this.boundingBoxCached[i].city + ", " + this.boundingBoxCached[i].countrycode + "</span> " + selectHTML + "</li>";
                     
               }
               
	}
	else
	{
	      temphtml += "Sorry, there are no locations in this area!";
	}
	
	temphtml += "</ul></div>";
	
                
	this.tmpmarker.openInfoWindowHtml(temphtml);
        
        var self = this;
	GEvent.addListener(
                          this.map.getInfoWindow(), "closeclick", function() {
                          
                          self.map.removeOverlay(self.box);
                          });
         
}


DoYouTravel.TravelMap.prototype.displayVisitsSelectorForContents = function ( sw, ne, latlng, point )
{
         //create params for box
         var swlat = sw.lat();
         var swlng = sw.lng();
         
         var nelat = ne.lat();
         var nelng = ne.lng();
         
         var lat = latlng.lat();
         var lng = latlng.lng();
         
         
        var self = this;
        
        if ( this.radiusAJAX != null )
        {     
              this.radiusAJAX.abort();
        }
        
        this.radiusAJAX = new DoYouTravel.TravelMap.fetchDestinationsWithinBox(
                'POST',
                DoYouTravel.Config.wsBaseUrl + 'get-cities-within-box.php',
                true);
        this.radiusAJAX.onSuccess = function ()
        {
                self.displayVisitsSelectorForContentsResponse(
                        this.request.responseXML);
                        
                self.displaySuggestedDestinationsBox(latlng);
        }
        this.radiusAJAX.send('&swlat=' + swlat + '&swlng=' + swlng + '&nelat=' + nelat + '&nelng=' + nelng + '&lat=' + lat + '&lng=' + lng );

         
};


DoYouTravel.TravelMap.prototype.displayHometownMarker = function ( force )
{
        if ( this.mapHometownMarker == null || force != null )
        {
                if ( this.mapHometownMarker != null )
                {
                     this.map.removeOverlay(this.mapHometownMarker);
                }
        
                var icon = new GIcon();
                icon.iconSize = new GSize(16,16);
                icon.iconAnchor = new GPoint(8, 8);
                icon.infoWindowAnchor = new GPoint(5, 1);
                icon.image =
                        'http://doyoutravel.co.uk/map/images/hometown-16x16.gif';
                var point = new GLatLng(
                        this.hometownCache.lat,
                        this.hometownCache.lng);
                var marker = new GMarker(point,icon);
                this.hometownCache.msg = this.hometownCache.city + ', ' +
                                        this.hometownCache.countrycode +
                                        '</b><br>This is my hometown.';
                                        
                
                GEvent.addListener(
                          marker, "click", function() {
                          this.openInfoWindowHtml(travelmap.hometownCache.msg);  });
                
                
                this.map.addOverlay(marker);
                this.mapHometownMarker = marker;
        }
};



DoYouTravel.TravelMap.prototype.processXMLCityData = function ( xml )
{
        if ( xml == null )
        {
                return ;
        }
        
        // Extract destinations
        var destinationNodes = xml.getElementsByTagName('destination');
        if ( destinationNodes != null )
        {
                this.cityCached = new Array();
                
                for ( var i = 0; i < destinationNodes.length; i++ )
                {
                        destinationNode = destinationNodes[i];
                        
                        this.cityCached[i] = {
                                id: destinationNode.getElementsByTagName('id')[0].firstChild.nodeValue,
                                city: destinationNode.getElementsByTagName('city')[0].firstChild.nodeValue,
                                countrycode: destinationNode.getElementsByTagName('countrycode')[0].firstChild.nodeValue,
                                lat: destinationNode.getElementsByTagName('lat')[0].firstChild.nodeValue,
                                lng: destinationNode.getElementsByTagName('lng')[0].firstChild.nodeValue,
                                visits: destinationNode.getElementsByTagName('numtimes')[0].firstChild.nodeValue
                                };
                
                }
                
        }
        
        
        var totalNodes = xml.getElementsByTagName('totalcount');
        
        if ( totalNodes != null &&
                totalNodes[0] != null &&
                totalNodes[0].firstChild != null )
        {
                this.totalCities = totalNodes[0].firstChild.nodeValue;
        }
};


DoYouTravel.TravelMap.prototype.displayAddDestinationListResponse = function ( xml, destzoom )
{

/*
        this.processXMLCityData(xml);
        
        if ( destzoom == 1 )
        {
              this.addMode = 1;
        }
        else
        {
              this.addMode = 0;
        }
        
        var listRef = document.getElementById("add_list_destinations");
        
        var startValueRef = document.getElementById("startaddpagingvalue");
        var startValue = startValueRef.value;
        
        var tempHTML = "<ul><li><p class=\"location\">Location</p><p class=\"visits\">No. of visits:</p></li>";
        
        var total = this.totalCities;
        
        var count = 0;
        for ( var i=0; i<this.cityCached.length; i++ )
        {
              
              if ( count >= DoYouTravel.Config.pagingValue )
              {
                     break;
              }
              
              var selectHTML = '<select onchange="travelmap.toggleVisited(event, ' + this.cityCached[i].id + ')">';
              
              for ( var i2=0; i2<=30; i2++ )
              {
                     var visitedSelected = "";
                     
                     if ( i2 == this.cityCached[i].visits )
                     {
                            visitedSelected = "selected";
                     }
                     
                     selectHTML += '<option value="' + i2 + '" ' + visitedSelected + '>' + i2 + '</option>';
              }
                     selectHTML += '</select>';
              
              tempHTML = tempHTML + '<li><a href="javascript://" onclick="travelmap.showCityAtLatLng(\'' + this.cityCached[i].city + ', ' + this.cityCached[i].countrycode + '\',' + this.cityCached[i].lat + ',' + this.cityCached[i].lng  + ', ' + this.cityCached[i].visits + ', ' +  this.cityCached[i].id + ')">' + this.cityCached[i].city + ', ' + this.cityCached[i].countrycode + '</a> ' + selectHTML + '</li>';
              count++;
        }
        
        
        tempHTML = tempHTML + "</ul>";
        
        if ( i < total )
        {
              document.getElementById("nextaddbutton").style.display = "";
        }
        else
        {
              document.getElementById("nextaddbutton").style.display = "none";
        }
        
        
        if ( startValue > 0 )
        {
              document.getElementById("previousaddbutton").style.display = "";
        }
        else
        {
              document.getElementById("previousaddbutton").style.display = "none";
        }
        
        
        listRef.innerHTML = tempHTML;
       
       */
       
        var listRef = document.getElementById("view_list");
        
        var startValueRef = document.getElementById("startpagingvalue");
        var startValue = startValueRef.value;
        
        if ( this.mapSize == 2 )
        {
                var tempHTML = '<ul id="view_list_edit">';
        }
        else
        {
                var tempHTML = "<ul>";
        }
        
        var total = this.destinationCache.length;
        
        var count = 0;
        for ( var i=startValue; i<total; i++ )
        {
                
                if ( count >= DoYouTravel.Config.pagingValue )
                {
                        break;
                }
                
                /*
                var selectHTML = '<select class="visits" onchange="travelmap.toggleVisited(event, ' + this.destinationCache[i].id + ')">';
                
                for ( var i2=0; i2<=30; i2++ )
                {
                        var visitedSelected = "";
                        
                        if ( i2 == this.cityCached[i].visits )
                        {
                            visitedSelected = "selected";
                        }
                        
                        selectHTML += '<option value="' + i2 + '" ' + visitedSelected + '>' + i2 + '</option>';
                }
                selectHTML += '</select>';
                */
                
                
                if ( this.mapSize == 2 )
                {
                        var selectHTML = '<select onchange="travelmap.toggleVisitedWithinBox(event, ' + this.destinationCache[i].ci_id + ');">';
                        
                        for ( var i2=0; i2<=30; i2++ )
                        {
                                var visitedSelected = "";
                                
                                if ( i2 == this.destinationCache[i].visits )
                                {
                                        visitedSelected = "selected";
                                }
                                
                                selectHTML += '<option value="' + i2 + '" ' + visitedSelected + '>' + i2 + '</option>';
                        }
                        selectHTML += '</select>';
                        
                        
                        tempHTML = tempHTML + '<li><a href="javascript://" onclick="travelmap.showMarkerWithId(' + this.destinationCache[i].ci_id + ')">' + this.destinationCache[i].city + ', ' +
                                this.destinationCache[i].countrycode + "</a>" + selectHTML + "</li>";
                }
                else if ( this.mapSize == 1 )
                {
                        tempHTML = tempHTML + '<li><a href="javascript://" onclick="travelmap.showMarkerWithId(' + this.destinationCache[i].ci_id + ')">' + this.destinationCache[i].city + ', ' +
                                this.destinationCache[i].countrycode + "</a></li>";
                }
                
                count++;
        }
        
        
        tempHTML = tempHTML + "</ul>";
        
        if ( i < total )
        {
              document.getElementById("nextbutton").style.display = "";
        }
        else
        {
              document.getElementById("nextbutton").style.display = "none";
        }
        
        
        if ( startValue > 0 )
        {
              document.getElementById("previousbutton").style.display = "";
        }
        else
        {
              document.getElementById("previousbutton").style.display = "none";
        }
        
        
        listRef.innerHTML = tempHTML;
       
}


DoYouTravel.TravelMap.prototype.updateDestinations = function()
{
        
        var self = this;
        
        
        /*
        var swlat = 10;
        var swlng = 20;
        var nelat = 1;
        var nelng = 12;
        var lat = 12;
        var lng = 12;
        */
        
        var bounds = this.map.getBounds();
        var swlat = bounds.getSouthWest().lat();
        var swlng = bounds.getSouthWest().lng();
        var nelat = bounds.getNorthEast().lat();
        var nelng = bounds.getNorthEast().lng(); 

        this.radiusAJAX = new DoYouTravel.TravelMap.fetchDestinationsWithinBox(
                'POST',
                DoYouTravel.Config.wsBaseUrl + 'get-cities-within-box.php',
                true);
        this.radiusAJAX.onSuccess = function ()
        {
                self.displayAddDestinationListResponse(
                        this.request.responseXML, 1);
                        
        }
        
        
        this.radiusAJAX.send('&swlat=' + swlat + '&swlng=' + swlng + '&nelat=' + nelat + '&nelng=' + nelng + '&count=' + 20 + '&start=' + document.getElementById("startaddpagingvalue").value );
}

function sortMapItems ( a, b )
{
       if ( a.city == b.city )
       {
              return 0;
       }

       var tempArray = [a.city, b.city];
       
       tempArray.sort();
       
      // alert(tempArray );
       
       if ( tempArray[0] == a.city )
       {
              return -1;
       }
       else
       {
              return 1;
       }
}

DoYouTravel.TravelMap.prototype.displayAddDestinationList = function ()
{

        var listRef = document.getElementById("view_list");
        
        var startValueRef = document.getElementById("startpagingvalue");
        var startValue = startValueRef.value;
        
        if ( this.mapSize == 2 )
        {
                var tempHTML = '<ul id="view_list_edit">';
        }
        else
        {
                var tempHTML = "<ul>";
        }
        
        var total = this.destinationCache.length;
        
        //sort the destination cache alphabetically
        
        this.destinationCache.sort(sortMapItems);
        
        var count = 0;
        for ( var i=startValue; i<total; i++ )
        {
                
                if ( count >= DoYouTravel.Config.pagingValue )
                {
                        break;
                }
                
                
                if ( this.mapSize == 2 )
                {
                        var selectHTML = '<select onchange="travelmap.toggleVisitedWithinBox(event, ' + this.destinationCache[i].ci_id + ');">';
                        
                        for ( var i2=0; i2<=30; i2++ )
                        {
                                var visitedSelected = "";
                                
                                if ( i2 == this.destinationCache[i].visits )
                                {
                                        visitedSelected = "selected";
                                }
                                
                                selectHTML += '<option value="' + i2 + '" ' + visitedSelected + '>' + i2 + '</option>';
                        }
                        selectHTML += '</select>';
                        
                        
                        tempHTML = tempHTML + '<li><a class="placelink" href="javascript://" onclick="travelmap.showMarkerWithId(' + this.destinationCache[i].ci_id + ')">' + this.destinationCache[i].city + ', ' +
                                this.destinationCache[i].countrycode + "</a>" + selectHTML + "&nbsp;&nbsp;<a class=\"removelink\" onclick=\"travelmap.removeItemDestCache(" + this.destinationCache[i].id + ")\">Remove</a></li>";
                }
                else if ( this.mapSize == 1 )
                {
                        tempHTML = tempHTML + '<li><a href="javascript://" onclick="travelmap.showMarkerWithId(' + this.destinationCache[i].ci_id + ')">' + this.destinationCache[i].city + ', ' +
                                this.destinationCache[i].countrycode + "</a></li>";
                }
                
                count++;
        }
        
        
        tempHTML = tempHTML + "</ul>";
        
        if ( i < total )
        {
              document.getElementById("nextbutton").style.display = "";
        }
        else
        {
              document.getElementById("nextbutton").style.display = "none";
        }
        
        
        if ( startValue > 0 )
        {
              document.getElementById("previousbutton").style.display = "";
        }
        else
        {
              document.getElementById("previousbutton").style.display = "none";
        }
        
        
        listRef.innerHTML = tempHTML;

}

DoYouTravel.TravelMap.prototype.nextPlaces = function ( )
{
       
       var startValueRef = document.getElementById("startpagingvalue");
       startValueRef.value = parseInt(startValueRef.value) + parseInt(DoYouTravel.Config.pagingValue);
       
       this.displayDestinationList();
       
}


DoYouTravel.TravelMap.prototype.previousPlaces = function ( )
{
       
       var startValueRef = document.getElementById("startpagingvalue");startValueRef.value = parseInt(startValueRef.value) - parseInt(DoYouTravel.Config.pagingValue);
       
       this.displayDestinationList();
       
}

DoYouTravel.TravelMap.prototype.nextAddPlaces = function ( )
{
       
       var startValueRef = document.getElementById("startpagingvalue");
       startValueRef.value = parseInt(startValueRef.value) + parseInt(DoYouTravel.Config.pagingValue);
       
       
    //   if ( this.addMode == 0 )
       {
              travelmap.displayAddDestinationList();
       }
     /*  else if ( this.addMode == 1 )
       {
              this.updateDestinations();
       }*/
}


DoYouTravel.TravelMap.prototype.previousAddPlaces = function ( )
{
       
       var startValueRef = document.getElementById("startpagingvalue");startValueRef.value = parseInt(startValueRef.value) - parseInt(DoYouTravel.Config.pagingValue);
       
       /*if ( this.addMode == 0 )
       {*/
              travelmap.displayAddDestinationList();
       /*}
       else if ( this.addMode == 1 )
       {
              this.updateDestinations();
       }*/
}

DoYouTravel.TravelMap.prototype.showMarkerWithId = function ( id, dontzoom )
{
        var travelItem;
        var marker;
        
        for ( var i=0; i<this.destinationCache.length; i++ )
        {
              if ( this.destinationCache[i].ci_id == id )
              {
                     travelItem = this.destinationCache[i];
                     break;
              }
        }
        
        for ( var i=0; i<this.mapDestinationMarkers.length; i++ )
        {     
              if ( this.mapDestinationMarkers[i].ci_id == id )
              {
                     marker = this.mapDestinationMarkers[i];
                     break;
              }
        }
        
        if ( travelItem && marker )
        {

        marker.openInfoWindowHtml(travelItem.msg)
        
        var point = marker.getPoint();
        
        if ( !dontzoom )
        {
              this.map.setZoom(5);
        }
        this.map.panTo(point);
        
        }
}


DoYouTravel.TravelMap.prototype.showCityAtLatLng = function ( name, lat, lng, visits, id , hometown, marker)
{
        var tmpLat = new GLatLng(lat, lng);
        
        this.map.closeInfoWindow();
        this.map.setZoom(8);
        this.map.panTo(tmpLat);
        
        this.map.closeInfoWindow();
	
        var icon = new GIcon();
        icon.iconSize = new GSize(20,20);
        icon.iconAnchor = new GPoint(6, 20);
        icon.infoWindowAnchor = new GPoint(5, 1);
   
                        
	
	if ( marker != null )
	{     
	      //need to display a marker                            
	      if ( BrowserDetect.browser == 'Explorer' && BrowserDetect.version == 6)
              {    
                     icon.image =
                          'http://doyoutravel.co.uk/map/images/blue-pushpin-20x20.gif';
              }
              else
              {
                     icon.image =
                          'http://doyoutravel.co.uk/map/images/blue-pushpin-20x20.png';
              }
              
	}
	
	var tmpmarker = new GMarker(tmpLat, icon);
	
	
	this.map.addOverlay(tmpmarker);
	
        if ( this.mapSize == 2 )
        {
                var selectHTML = '<select class="visits" onchange="travelmap.toggleVisitedWithinBox(event, ' + id + ');">';
                      
                for ( var i2=0; i2<=30; i2++ )
                {
                        var visitedSelected = "";
                        
                        if ( i2 == visits )
                        {
                                visitedSelected = "selected";
                        }
                        
                        selectHTML += '<option value="' + i2 + '" ' + visitedSelected + '>' + i2 + '</option>';
                }
                selectHTML += '</select>';
        }
	
	
	var extratext = "";
	if ( visits != null && visits != 0 && hometown != 1 )
	{
                if ( visits == 1 )
                {
                        extratext = '</b>';
                        if ( this.mapSize == 2 )
                        {
                                extratext += selectHTML;
                        }
                        extratext += '<br/>I have been here once.';
                        if ( this.mapSize == 2 )
                        {
                                extratext += '<br/><a class="remove" onclick="travelmap.removeItem(' + id + ')">Remove this destination.</a>';
                        }
                }
                else
                {
                        extratext = '</b>';
                        if ( this.mapSize == 2 )
                        {
                                extratext += selectHTML;
                        }
                        extratext += '<br/>I have been here ' + 
                                visits + ' times.';
                        if ( this.mapSize == 2 )
                        {
                                extratext += '<br/><a class="remove" onclick="travelmap.removeItem(' + id + ')">Remove this destination.</a>';
                        }
                }
	}
	
	if ( visits == 0 && this.mapSize == 2 )
	{
                var selectHTML = '<select class="visits" onchange="travelmap.toggleVisitedWithinBox(event, ' + id + ',0, 1);">';
                
                for ( var i2=0; i2<=30; i2++ )
                {
                        var visitedSelected = "";
                        
                        if ( i2 == visits )
                        {
                                visitedSelected = "selected";
                        }

                        selectHTML += '<option value="' + i2 + '" ' + visitedSelected + '>' + i2 + '</option>';
                }
                selectHTML += '</select>';
                
                extratext = selectHTML;
	}
	
	if ( hometown == 1 )
	{
	      extratext = "</b><br/>This is my hometown.";
	}
	
	
	if ( marker != null )
	{
              //make it clickable
              GEvent.addListener(tmpmarker,
                                        "click", function() {
                                        this.openInfoWindowHtml("<b>" + name + "</b>" + extratext); });
	}
	
	tmpmarker.openInfoWindowHtml("<b>" + name + "</b>" + extratext);
}

DoYouTravel.TravelMap.prototype.removeItem = function( id )
{
       var item = null;
       
       for ( var i=0; i<this.cityCached.length; i++ )
       {      
              
              if ( this.cityCached[i].id == id )
              {
                     item = this.cityCached[i];
              }
              
       }
       
       if ( item != null )
       {
              this.removeDestinationMarker(item);
              
              this.changeVisitCount(item, 0, 0);
              
              this.map.closeInfoWindow();
       }
       
       
}

DoYouTravel.TravelMap.prototype.removeItemDestCache = function( id )
{
       var item = null;
       
       for ( var i=0; i<this.destinationCache.length; i++ )
       {      
              
              if ( this.destinationCache[i].id == id )
              {
                     item = this.destinationCache[i];
              }
              
       }
       
       if ( item != null )
       {
       
              this.removeDestinationMarker(item);
              
              this.changeVisitCountDestCache(item, 0, 0);
              
              this.map.closeInfoWindow();
       }
       
       
}


DoYouTravel.TravelMap.prototype.displayDestinationMarker = function ( item )
{

                        var icon = new GIcon();
                        icon.iconSize = new GSize(20,20);
                        icon.iconAnchor = new GPoint(6, 20);
                        icon.infoWindowAnchor = new GPoint(5, 1);
                        
                        if( item.visits == 1 )
                        {
                        
                            if ( BrowserDetect.browser == 'Explorer' && BrowserDetect.version == 6)
                            {    
                                   icon.image =
                                        'http://doyoutravel.co.uk/map/images/blue-pushpin-20x20.gif';
                            }
                            else
                            {
                                   icon.image =
                                        'http://doyoutravel.co.uk/map/images/blue-pushpin-20x20.png';
                            }
                        }
                        else if( item.visits >= 2 &&
                                item.visits <= 3 )
                        {
                        
                            if ( BrowserDetect.browser == 'Explorer' && BrowserDetect.version == 6)
                            {
                                icon.image =
                                        'http://doyoutravel.co.uk/map/images/grn-pushpin-20x20.gif';
                            }
                            else
                            {
                                icon.image =
                                        'http://doyoutravel.co.uk/map/images/grn-pushpin-20x20.png';
                            }
                        }
                        else if( item.visits >= 4 &&
                                item.visits <= 5 )
                        {
                            if ( BrowserDetect.browser == 'Explorer' && BrowserDetect.version == 6)
                            {
                                icon.image =
                                        'http://doyoutravel.co.uk/map/images/red-pushpin-20x20.gif';
                            }
                            else
                            {
                                icon.image =
                                        'http://doyoutravel.co.uk/map/images/red-pushpin-20x20.png';
                            }
                        }
                        else
                        {
                            if ( BrowserDetect.browser == 'Explorer' && BrowserDetect.version == 6)
                            {
                                icon.image =
                                        'http://doyoutravel.co.uk/map/images/ylw-pushpin-20x20.gif';
                            }
                            else
                            {
                                icon.image =
                                        'http://doyoutravel.co.uk/map/images/ylw-pushpin-20x20.png';
                            }
                        }
                        
                        var point = new GLatLng(
                                item.lat,
                                item.lng);
                        //var marker = new GMarker(point,icon);
                        
                        i = this.mapDestinationMarkers.length;
                        
                        
                        //check destination cache for existing item
                        var foundInCache = false;
                        
                        var cachedId = 0;
                        
                        
                        for ( var i=0; i<this.destinationCache.length; i++ )
                        {
                              
                              if ( this.destinationCache[i].ci_id == item.ci_id )
                              {
                                   cachedId = i;
                                   foundInCache = true;
                                   break;
                              }
                              
                              
                        }
                        
                        
                        if ( foundInCache == false )
                        {
                            cachedId = (this.destinationCache.push(item)-1);
                        }
                        else
                        {
                            this.destinationCache[cachedId] = item;
                        }
                        
                        
                        this.mapDestinationMarkers[cachedId] =
                                new GMarker(point, icon);
                                
                        if ( this.mapSize == 0 )
                        {
                                var mapDiv = document.getElementById('mapdata');
                                GEvent.addListener(this.mapDestinationMarkers[i],
                                        "click", function() {
                                        mapDiv.onclick();  });
                        }
                        else
                        {
                                var marker = this.mapDestinationMarkers[i];
                                
                                
                             var selectHTML = '<select class="visits" onchange="travelmap.toggleVisitedWithinBox(event, ' + item.ci_id + ');">';
                                   
                             for ( var i2=0; i2<=30; i2++ )
                             {
                                    var visitedSelected = "";
                                    
                                    if ( i2 == item.visits )
                                    {
                                           visitedSelected = "selected";
                                    }
                                       
                                       selectHTML += '<option value="' + i2 + '" ' + visitedSelected + '>' + i2 + '</option>';
                             }
                             selectHTML += '</select>';
                                
                                this.destinationCache[cachedId].msg = '<b>' + item.city + ', ' +
                                        item.countrycode +
                                        '</b>' + selectHTML +  '<br>I have been here ' + 
                                        item.visits + ' times.' + '<br/><a class="remove" onclick="travelmap.removeItemDestCache(' + this.destinationCache[cachedId].id + ')">Remove this destination.</a>';;
                                        
                                this.mapDestinationMarkers[cachedId].id = cachedId;
                                this.mapDestinationMarkers[cachedId].ci_id = item.ci_id;
                                
                                var self = this;
                                        
                                GEvent.addListener(
                                        this.mapDestinationMarkers[cachedId], "click", function() {
                                        travelmap.showMarkerWithId(this.ci_id,1 );  });
                        }
                        
                        this.map.addOverlay(this.mapDestinationMarkers[cachedId]);
                        //this.mapDestinationMarkers[i] = marker;
                        
                        //this.displayDestinationList();
                        var countAmountRef = document.getElementById("destinationcountamount");
                       
                        if ( countAmountRef != null )
                        {
                             countAmountRef.innerHTML = this.destinationCache.length;
                        }

}



DoYouTravel.TravelMap.prototype.removeDestinationMarker = function ( item )
{
                        marker = null;
                        for ( var i=0; i<this.mapDestinationMarkers.length; i++ )
                        {
                               if ( this.mapDestinationMarkers[i].ci_id == item.ci_id ||  !this.mapDestinationMarkers[i].ci_id )
                               {
                                   this.map.removeOverlay(this.mapDestinationMarkers[i]);
                               }
                        }
                        
                        for ( var i=0; i<this.destinationCache.length; i++ )
                        {
                               
                               if ( this.destinationCache[i].ci_id == item.id )
                               {
                                   this.destinationCache.splice(i);
                               }
                               
                        }
                        
                        var countAmountRef = document.getElementById("destinationcountamount");
                       
                        if ( countAmountRef != null )
                        {
                             countAmountRef.innerHTML = this.destinationCache.length;
                        }

}


DoYouTravel.TravelMap.prototype.removeDestinationMarkerDestCache = function ( item )
{
                        
                        marker = null;
                        for ( var i=0; i<this.mapDestinationMarkers.length; i++ )
                        {
                               if ( this.mapDestinationMarkers[i].ci_id == item.ci_id )
                               {
                                   this.map.removeOverlay(this.mapDestinationMarkers[i]);
                                   break;
                               }
                        }
                        
                        
                        for ( var i=0; i<this.destinationCache.length; i++ )
                        {
                               
                               if ( this.destinationCache[i].ci_id == item.ci_id )
                               {
                                   this.destinationCache.splice(i, 1);
                               }
                               
                        }
                        
                        var countAmountRef = document.getElementById("destinationcountamount");
                       
                        if ( countAmountRef != null )
                        {
                             countAmountRef.innerHTML = this.destinationCache.length;
                        }

}



DoYouTravel.TravelMap.prototype.displayDestinationMarkers = function ()
{
        if ( this.destinationCache != null )
        {
                for ( var i = 0; i < this.destinationCache.length; i++ )
                {
                        var icon = new GIcon();
                        icon.iconSize = new GSize(20,20);
                        icon.iconAnchor = new GPoint(6, 20);
                        icon.infoWindowAnchor = new GPoint(5, 1);
                        
                        
                        if( this.destinationCache[i].visits == 1 )
                        {
                        
                            if ( BrowserDetect.browser == 'Explorer' && BrowserDetect.version == 6)
                            {    
                                   icon.image =
                                        'http://doyoutravel.co.uk/map/images/blue-pushpin-20x20.gif';
                            }
                            else
                            {
                                   icon.image =
                                        'http://doyoutravel.co.uk/map/images/blue-pushpin-20x20.png';
                            }
                        }
                        else if( this.destinationCache[i].visits >= 2 &&
                                this.destinationCache[i].visits <= 3 )
                        {
                        
                            if ( BrowserDetect.browser == 'Explorer' && BrowserDetect.version == 6)
                            {
                                icon.image =
                                        'http://doyoutravel.co.uk/map/images/grn-pushpin-20x20.gif';
                            }
                            else
                            {
                                icon.image =
                                        'http://doyoutravel.co.uk/map/images/grn-pushpin-20x20.png';
                            }
                        }
                        else if( this.destinationCache[i].visits >= 4 &&
                                this.destinationCache[i].visits <= 5 )
                        {
                            if ( BrowserDetect.browser == 'Explorer' && BrowserDetect.version == 6)
                            {
                                icon.image =
                                        'http://doyoutravel.co.uk/map/images/red-pushpin-20x20.gif';
                            }
                            else
                            {
                                icon.image =
                                        'http://doyoutravel.co.uk/map/images/red-pushpin-20x20.png';
                            }
                        }
                        else
                        {
                            if ( BrowserDetect.browser == 'Explorer' && BrowserDetect.version == 6)
                            {
                                icon.image =
                                        'http://doyoutravel.co.uk/map/images/ylw-pushpin-20x20.gif';
                            }
                            else
                            {
                                icon.image =
                                        'http://doyoutravel.co.uk/map/images/ylw-pushpin-20x20.png';
                            }
                        }
                        
                        var point = new GLatLng(
                                this.destinationCache[i].lat,
                                this.destinationCache[i].lng);
                        //var marker = new GMarker(point,icon);
                        this.mapDestinationMarkers[i] =
                                new GMarker(point, icon);
                        
                        if ( this.mapSize == 0 )
                        {
                                var mapDiv = document.getElementById('mapdata');
                                GEvent.addListener(this.mapDestinationMarkers[i],
                                        "click", function() {
                                        mapDiv.onclick();  });
                        }
                        else
                        {
                                var marker = this.mapDestinationMarkers[i];
                                
                                this.destinationCache[i].msg = '<b>' + this.destinationCache[i].city + ', ' +
                                        this.destinationCache[i].countrycode +
                                        '</b>';
                                        
                                if ( this.mapSize == 2 )
                                {
                                        var selectHTML = '<select class="visits" onchange="travelmap.toggleVisitedWithinBox(event, ' + this.destinationCache[i].ci_id + ');">';
                                           
                                        for ( var i2=0; i2<=30; i2++ )
                                        {
                                               var visitedSelected = "";
                                               
                                               if ( i2 == this.destinationCache[i].visits )
                                               {
                                                      visitedSelected = "selected";
                                               }
                                               
                                               selectHTML += '<option value="' + i2 + '" ' + visitedSelected + '>' + i2 + '</option>';
                                        }
                                        selectHTML += '</select>';
                                           
                                        this.destinationCache[i].msg+= selectHTML;
                                }
                                        
                                        
                                        
                                this.destinationCache[i].msg += '<br>I have been here ';
                                if ( this.destinationCache[i].visits == 1 )
                                {
                                        this.destinationCache[i].msg +=
                                                'once.';
                                }
                                else
                                {
                                        this.destinationCache[i].msg +=
                                                this.destinationCache[i].visits +
                                                ' times.';
                                }
                                
                                this.mapDestinationMarkers[i].id = i;
                                
                                
                                 if ( this.mapSize == 2 )
                                 {
                                this.destinationCache[i].msg += '<br/><a class="remove" onclick="travelmap.removeItemDestCache(' + this.destinationCache[i].id + ')">Remove this destination.</a>';
                                 }
                                
                                
                                
                                this.mapDestinationMarkers[i].ci_id = this.destinationCache[i].ci_id;
                                
                                var self = this;
                                        
                                GEvent.addListener(
                                        this.mapDestinationMarkers[i], "click", function() {
                                        
                                        travelmap.showMarkerWithId(this.ci_id,1);
                                        } );
                        }
                        
                        this.map.addOverlay(this.mapDestinationMarkers[i]);
                        //this.mapDestinationMarkers[i] = marker;
                }
        }
};



DoYouTravel.TravelMap.prototype.getHometown = function ()
{
        var self = this;
        var ajax = new DoYouTravel.TravelMap.Hometown(
                'POST',
                DoYouTravel.Config.wsBaseUrl + 'get-hometown.php',
                true);
        ajax.onSuccess = function ()
        {
                self.getHometownResponse(
                        this.request.responseXML);
        }
        ajax.send('');
};


DoYouTravel.TravelMap.prototype.getHometownResponse = function ( xml )
{
        this.processXMLMapData(xml);
};


DoYouTravel.TravelMap.prototype.getVisitedDestinations = function ()
{
        var self = this;
        var ajax = new DoYouTravel.TravelMap.VisitedDestinations(
                'POST',
                DoYouTravel.Config.wsBaseUrl + 'get-visited-destinations.php',
                true);
        ajax.onSuccess = function ()
        {
                self.getVisitedDestinationsResponse(
                        this.request.responseXML);
        }
        ajax.send('');
};


DoYouTravel.TravelMap.prototype.getVisitedDestinationsResponse = function ( xml )
{
        this.processXMLMapData(xml);
};





DoYouTravel.TravelMap.prototype.populateMap = function ()
{
        //alert('DoYouTravel.TravelMap.populateMap called');
        var self = this;
        
        var url = DoYouTravel.Config.wsBaseUrl + 'get-map-data.php';
        if ( this.memberId != null )
        {
                url += '?memid=' + this.memberId;
        }
        var ajax = new DoYouTravel.TravelMap.MapData(
                'POST',
                url,
                true);
        ajax.onSuccess = function ()
        {
                self.populateMapResponse( this.request.responseXML);
        }
        ajax.send('');
};


DoYouTravel.TravelMap.prototype.populateMapLarge = function ()
{
        var self = this;
        
        var url = DoYouTravel.Config.wsBaseUrl + 'get-map-data.php';
        if ( this.memberId != null )
        {
                url += '?memid=' + this.memberId;
        }
        
        var ajax = new DoYouTravel.TravelMap.MapData(
                'POST',
                url,
                true);
        ajax.onSuccess = function ()
        {
                self.populateMapResponse( this.request.responseXML);
                self.displayDestinationList();
        }
        ajax.send('');
        
};


DoYouTravel.TravelMap.prototype.populateEditMap = function ()
{
        var self = this;
        var ajax = new DoYouTravel.TravelMap.MapData(
                'POST',
                DoYouTravel.Config.wsBaseUrl + 'get-map-data.php',
                true);
        ajax.onSuccess = function ()
        {
                self.populateMapResponse( this.request.responseXML);
                self.displayAddDestinationList();
        }
        ajax.send('');
        
};



DoYouTravel.TravelMap.prototype.populateGenericMapDetails = function ()
{
        DoYouTravel.TravelMap.prototype.populateMap();
       
};



DoYouTravel.TravelMap.prototype.populateMapResponse = function ( xml )
{
        //alert('DoYouTravel.TravelMap.populateMapResponse called');
        this.processXMLMapData(xml);
        this.redraw();
};


DoYouTravel.TravelMap.prototype.processXMLMapData = function ( xml )
{
        if ( xml == null )
        {
                return ;
        }
        
        
        // Extract hometown
        var hometownNode = xml.getElementsByTagName('hometown');
        if ( hometownNode != null )
        {
                hometownNode = hometownNode[0];
                if ( hometownNode.getElementsByTagName('id').length != 0 &&
                        hometownNode.getElementsByTagName('id')[0].firstChild != null &&
                        hometownNode.getElementsByTagName('id')[0].firstChild.nodeValue != null )
                {
                        this.hometownCache = {
                                id: hometownNode.getElementsByTagName('id')[0].firstChild.nodeValue,
                                city: hometownNode.getElementsByTagName('city')[0].firstChild.nodeValue,
                                countrycode: hometownNode.getElementsByTagName('countrycode')[0].firstChild.nodeValue,
                                lat: hometownNode.getElementsByTagName('lat')[0].firstChild.nodeValue,
                                lng: hometownNode.getElementsByTagName('lng')[0].firstChild.nodeValue,
                                visits: 1
                                };
                        
                        if ( this.mapSize == 2 )
                        {
                                document.getElementById("myhometown").innerHTML = '<a href="javascript://" onclick="travelmap.showCityAtLatLng(\'' + this.hometownCache.city.replace("\'","\\\'") + ', ' + this.hometownCache.countrycode + '\',' + this.hometownCache.lat + ',' + this.hometownCache.lng  + ', ' + this.hometownCache.visits + ', ' +  this.hometownCache.id + ',1 )">' + this.hometownCache.city + ", " + this.hometownCache.countrycode + '</a>';
                        }
                }
        }
        
        // Extract visited destinations
        var destinationNodes = xml.getElementsByTagName('destination');
        if ( destinationNodes != null )
        {
                this.destinationCache = new Array();
                for ( var i = 0; i < destinationNodes.length; i++ )
                {
                        destinationNode = destinationNodes[i];
                        
                        this.destinationCache[i] = {
                                id: destinationNode.getElementsByTagName('id')[0].firstChild.nodeValue,
                                ci_id: destinationNode.getElementsByTagName('ci_id')[0].firstChild.nodeValue,
                                city: destinationNode.getElementsByTagName('city')[0].firstChild.nodeValue,
                                countrycode: destinationNode.getElementsByTagName('countrycode')[0].firstChild.nodeValue,
                                lat: destinationNode.getElementsByTagName('lat')[0].firstChild.nodeValue,
                                lng: destinationNode.getElementsByTagName('lng')[0].firstChild.nodeValue,
                                visits: destinationNode.getElementsByTagName('numtimes')[0].firstChild.nodeValue
                                };
                
                }
                
                var countref = document.getElementById("destinationcounttext");
                
                if ( countref != null )
                {
                     countref.innerHTML = DoYouTravel.Config.DestCountText;
                }
                
                var countAmountRef = document.getElementById("destinationcountamount");
                
                if ( countAmountRef != null )
                {
                     countAmountRef.innerHTML = destinationNodes.length;
                }
        }
        
};


DoYouTravel.TravelMap.prototype.redraw = function ()
{
        this.map.clearOverlays();
        
        if ( this.hometownCache != null )
        {
                this.displayHometownMarker();
        }
        
        if ( this.destinationCache != null )
        {
                this.displayDestinationMarkers();
        }
};


DoYouTravel.TravelMap.prototype.showMessage = function ( message )
{
        
        document.getElementById("mapmessages").innerHTML = '<div class="mapmessage">' + message + "</div>";
        
}

DoYouTravel.TravelMap.prototype.changeVisitCount = function ( item, visits )
{
       var self = this;
       var ajax = new DoYouTravel.TravelMap.AddRemoveVisited(
               'POST',
               DoYouTravel.Config.wsBaseUrl + 'add-remove-visited.php',
               true);
       
       var mode = "";
       
       //fetch count
       
       if ( visits == 0 )
       {//visits is 0, remove it from database
              mode = "remove";
       }
       else
       {//doesnt exist, add it
              mode = "add";
       }
       
       //find the object containing the city details from cache
       var foundCity = item;
       

              if ( mode == "add" )
              {
                     this.displayDestinationMarker(item);
                     
                     
                     ajax.onSuccess = function ()
                     {
                             DoYouTravel.TravelMap.prototype.showMessage( item.city + " has been added to your map.");
                             
                             travelmap.displayAddDestinationList();
                     }
              }
              else
              {
                     this.removeDestinationMarker(item);
                     
                     ajax.onSuccess = function ()
                     {
                             DoYouTravel.TravelMap.prototype.showMessage( item.city + " has been removed from your map.");
                             
                             travelmap.displayAddDestinationList();
                     }
              }
              
              
              ajax.send('&mode=' + mode + '&ci_id=' + item.id + "&visits=" + visits + "&hometown=0");
              
};




DoYouTravel.TravelMap.prototype.changeVisitCountDestCache = function ( item, visits )
{
       var self = this;
       var ajax = new DoYouTravel.TravelMap.AddRemoveVisited(
               'POST',
               DoYouTravel.Config.wsBaseUrl + 'add-remove-visited.php',
               true);
       
       var mode = "";
       
       //fetch count
       
       if ( visits == 0 )
       {//visits is 0, remove it from database
              mode = "remove";
       }
       else
       {//doesnt exist, add it
              mode = "add";
       }
       
       //find the object containing the city details from cache
       var foundCity = item;
       

              if ( mode == "add" )
              {
                     this.displayDestinationMarker(item);
                     
                     
                     ajax.onSuccess = function ()
                     {
                             DoYouTravel.TravelMap.prototype.showMessage( item.city + " has been added to your map.");
                             
                             travelmap.displayAddDestinationList();
                     }
              }
              else
              {
                     this.removeDestinationMarkerDestCache(item);
                     
                     ajax.onSuccess = function ()
                     {
                             DoYouTravel.TravelMap.prototype.showMessage( item.city + " has been removed from your map.");
                             
                             travelmap.displayAddDestinationList();
                     }
              }
              
              
              ajax.send('&mode=' + mode + '&ci_id=' + item.ci_id + "&visits=" + visits + "&hometown=0");
              
};


DoYouTravel.TravelMap.prototype.toggleVisited = function ( e, id, hometown )
{

       var self = this;
       var ajax = new DoYouTravel.TravelMap.AddRemoveVisited(
               'POST',
               DoYouTravel.Config.wsBaseUrl + 'add-remove-visited.php',
               true);
       
       if ( hometown == null )
       {
              hometown = 0;
       }
       
       var mode = "";
       
       //fetch count
       var visits = 0;
       
       if ( e.visits != null )
       {
              visits = e.visits;
       
       }
       else
       {
              
              if ( e.srcElement )
              {
                     visits = e.srcElement.value;
              }
              else
              {
                     visits = e.target.value;
              }
              
       }
       
       if ( visits == 0 )
       {//visits is 0, remove it from database
              mode = "remove";
       }
       else
       {//doesnt exist, add it
              mode = "add";
       }
       
       //find the object containing the city details from cache
       var foundCity = null;
       
       for ( var i=0; i<this.destinationCache.length; i++ )
       {
              if ( this.destinationCache[i].ci_id == id )
              {
                     foundCity = this.destinationCache[i];
                     break;
              }
       }
       
       
       if ( e.visits != null )
       {
              
              e.ci_id = id;
              
              var self = this;
              ajax.onSuccess = function ()
              {
                     if ( hometown == 0 )
                     {
                            self.displayDestinationMarker(e);
                            DoYouTravel.TravelMap.prototype.showMessage( "You have saved the number of times you have been to " + e.city );
                     }
                     else
                     {//is hometown
                            self.hometownCache = e;
                            self.displayHometownMarker(1);
                            displayViewHometown();
                            DoYouTravel.TravelMap.prototype.showMessage( e.city + " has been saved as your hometown.");
                     }
                      
                      travelmap.displayAddDestinationList();
                      travelmap.map.closeInfoWindow();
              }
              
              
              ajax.send('&mode=' + mode + '&ci_id=' + id + "&visits=" + visits  + "&hometown=" + hometown);
              
              
       }
       else if ( foundCity == null )
       {
              return;
       }
       else
       {
              foundCity.visits = visits;
              foundCity.ci_id = id;
              
              if ( mode == "add" )
              {
                     this.displayDestinationMarker(foundCity);
                     
                     
                     ajax.onSuccess = function ()
                     {
                             DoYouTravel.TravelMap.prototype.showMessage( foundCity.city + " has been added to your map.");
                             travelmap.displayAddDestinationList();
                     }
              }
              else
              {
                     this.removeDestinationMarker(foundCity);
                     
                     ajax.onSuccess = function ()
                     {
                             DoYouTravel.TravelMap.prototype.showMessage( foundCity.city + " has been removed from your map.");
                             travelmap.displayAddDestinationList();
                     }
              }
              
              
              ajax.send('&mode=' + mode + '&ci_id=' + id + "&visits=" + visits + "&hometown=" + hometown);
              
       }
       
};




DoYouTravel.TravelMap.prototype.toggleVisitedBoundingBox = function ( e, id, hometown )
{
       var self = this;
       var ajax = new DoYouTravel.TravelMap.AddRemoveVisited(
               'POST',
               DoYouTravel.Config.wsBaseUrl + 'add-remove-visited.php',
               true);
       
       if ( hometown == null )
       {
              hometown = 0;
       }
       
       var mode = "";
       
       //fetch count
       var visits = 0;
        
       if ( e.visits != null )
       {
              visits = e.visits;
       
       }
       else
       {
              
              if ( e.srcElement )
              {
                     visits = e.srcElement.value;
              }
              else
              {
                     visits = e.target.value;
              }
              
       }
       
       if ( visits == 0 )
       {//visits is 0, remove it from database
              mode = "remove";
       }
       else
       {//doesnt exist, add it
              mode = "add";
       }
       
       //find the object containing the city details from cache
       var foundCity = null;
       
       for ( var i=0; i<this.boundingBoxCached.length; i++ )
       {
              if ( this.boundingBoxCached[i].id == id )
              {
                     foundCity = this.boundingBoxCached[i];
                     break;
              }
       }
       
                        
       
       //this.map.closeInfoWindow();
       this.map.removeOverlay(self.box);
       
       
       if ( e.visits != null )
       {
              
              e.ci_id = id;
              if ( hometown == 0 )
              {
                     this.displayDestinationMarker(e);
              }
              else
              {
                     this.hometownCache = e;
                     this.displayHometownMarker(1);
              }
                     
              ajax.onSuccess = function ()
              {
                      DoYouTravel.TravelMap.prototype.showMessage( e.city + " has been added to your map.");
              }
              
              
              ajax.send('&mode=' + mode + '&ci_id=' + id + "&visits=" + visits  + "&hometown=" + hometown);
              
              
       }
       else if ( foundCity == null )
       {
              return;
       }
       else
       {
              foundCity.visits = visits;
              foundCity.ci_id = id;
              
              if ( mode == "add" )
              {
                     this.displayDestinationMarker(foundCity);
                     
                     
                     ajax.onSuccess = function ()
                     {
                             DoYouTravel.TravelMap.prototype.showMessage( foundCity.city + " has been added to your map.");
                             
                             travelmap.displayAddDestinationList();
                     }
              }
              else
              {
                     this.removeDestinationMarker(foundCity);
                     
                     ajax.onSuccess = function ()
                     {
                             DoYouTravel.TravelMap.prototype.showMessage( foundCity.city + " has been removed from your map.");
                             travelmap.displayAddDestinationList();
                     }
              }
              
              
              ajax.send('&mode=' + mode + '&ci_id=' + id + "&visits=" + visits + "&hometown=" + hometown);
              
       }
       
};



DoYouTravel.TravelMap.prototype.toggleVisitedWithinBox = function ( e, id, hometown, notadded )
{
       var self = this;
       var ajax = new DoYouTravel.TravelMap.AddRemoveVisited(
               'POST',
               DoYouTravel.Config.wsBaseUrl + 'add-remove-visited.php',
               true);
       
       if ( hometown == null )
       {
              hometown = 0;
       }
       
       var mode = "";
       
       //fetch count
       var visits = 0;
       
       if ( e.visits != null )
       {
              visits = e.visits;
       
       }
       else
       {
              
              if ( e.srcElement )
              {
                     visits = e.srcElement.value;
              }
              else
              {
                     visits = e.target.value;
              }
              
       }
       
       if ( visits == 0 )
       {//visits is 0, remove it from database
              mode = "remove";
       }
       else
       {//doesnt exist, add it
              mode = "add";
       }
       
       //find the object containing the city details from cache
       var foundCity = null;
       
       if ( notadded == null )
       {
              
              for ( var i=0; i<this.destinationCache.length; i++ )
              {
                     if ( this.destinationCache[i].ci_id == id )
                     {
                            foundCity = this.destinationCache[i];
                            break;
                     }
              }
              
       }
       else
       {
              for ( var i=0; i<this.cityCached.length; i++ )
              {
                     if ( this.cityCached[i].id == id )
                     {
                            foundCity = this.cityCached[i];
                            break;
                     }
              }
       }
       
       
       if ( self.box )
       {
              this.map.removeOverlay(self.box);
       }
       
       this.map.closeInfoWindow();
       
       
       if ( e.visits != null )
       {
              
              e.ci_id = id;
              if ( hometown == 0 )
              {
                     this.displayDestinationMarker(e);
              }
              else
              {
                     this.hometownCache = e;
                     this.displayHometownMarker(1);
              }
                     
              ajax.onSuccess = function ()
              {
                      DoYouTravel.TravelMap.prototype.showMessage( e.city + " has been added to your map.");
              }
              
              
              ajax.send('&mode=' + mode + '&ci_id=' + id + "&visits=" + visits  + "&hometown=" + hometown);
              
              
       }
       else if ( foundCity == null )
       {
              return;
       }
       else
       {
              foundCity.visits = visits;
              foundCity.ci_id = id;
              
              if ( mode == "add" )
              {
                     this.displayDestinationMarker(foundCity);
                     
                     
                     ajax.onSuccess = function ()
                     {
                             DoYouTravel.TravelMap.prototype.showMessage( "You have saved the number of times you have been to " + foundCity.city);
                             
                             travelmap.displayAddDestinationList();
                     }
              }
              else
              {
                     this.removeDestinationMarker(foundCity);
                     
                     ajax.onSuccess = function ()
                     {
                             DoYouTravel.TravelMap.prototype.showMessage( foundCity.city + " has been removed from your map.");
                             
                             travelmap.displayAddDestinationList();
                     }
              }
              
              
              ajax.send('&mode=' + mode + '&ci_id=' + id + "&visits=" + visits + "&hometown=" + hometown);
              
       }
       
};


DoYouTravel.TravelMap.Hometown = function ( method, url, options )
{
        this.init(method, url, options);
}

DoYouTravel.TravelMap.Hometown.prototype = new EPSILON.Ajax('', '', '');
DoYouTravel.TravelMap.Hometown.constructor = DoYouTravel.TravelMap.Hometown;
DoYouTravel.TravelMap.Hometown.superclass = EPSILON.Ajax.prototype;

DoYouTravel.TravelMap.Hometown.prototype.onSuccess = function ()
{
        return true;
};


DoYouTravel.TravelMap.VisitedDestinations = function ( method, url, options )
{
        this.init(method, url, options);
}

DoYouTravel.TravelMap.VisitedDestinations.prototype = new EPSILON.Ajax('', '', '');
DoYouTravel.TravelMap.VisitedDestinations.constructor = DoYouTravel.TravelMap.VisitedDestinations;
DoYouTravel.TravelMap.VisitedDestinations.superclass = EPSILON.Ajax.prototype;

DoYouTravel.TravelMap.VisitedDestinations.prototype.onSuccess = function ()
{
        return true;
};



DoYouTravel.TravelMap.AddDestinations = function ( method, url, options )
{
        this.init(method, url, options);
}

DoYouTravel.TravelMap.AddDestinations.prototype = new EPSILON.Ajax('', '', '');
DoYouTravel.TravelMap.AddDestinations.constructor = DoYouTravel.TravelMap.AddDestinations;
DoYouTravel.TravelMap.AddDestinations.superclass = EPSILON.Ajax.prototype;

DoYouTravel.TravelMap.AddDestinations.prototype.onSuccess = function ()
{
        return true;
};




DoYouTravel.TravelMap.AutoCompleteDropdown = function ( method, url, options )
{
        this.init(method, url, options);
}

DoYouTravel.TravelMap.AutoCompleteDropdown.prototype = new EPSILON.Ajax('', '', '');
DoYouTravel.TravelMap.AutoCompleteDropdown.constructor = DoYouTravel.TravelMap.AutoCompleteDropdown;
DoYouTravel.TravelMap.AutoCompleteDropdown.superclass = EPSILON.Ajax.prototype;

DoYouTravel.TravelMap.AutoCompleteDropdown.prototype.onSuccess = function ()
{
        return true;
};




DoYouTravel.TravelMap.MapData = function ( method, url, options )
{
        this.init(method, url, options);
}

DoYouTravel.TravelMap.MapData.prototype = new EPSILON.Ajax('', '', '');
DoYouTravel.TravelMap.MapData.constructor = DoYouTravel.TravelMap.MapData;
DoYouTravel.TravelMap.MapData.superclass = EPSILON.Ajax.prototype;

DoYouTravel.TravelMap.MapData.prototype.onSuccess = function ()
{
        return true;
};


DoYouTravel.TravelMap.AddRemoveVisited = function ( method, url, options )
{
        this.init(method, url, options);
}

DoYouTravel.TravelMap.AddRemoveVisited.prototype = new EPSILON.Ajax('', '', '');
DoYouTravel.TravelMap.AddRemoveVisited.constructor = DoYouTravel.TravelMap.AddRemoveVisited;
DoYouTravel.TravelMap.AddRemoveVisited.superclass = EPSILON.Ajax.prototype;

DoYouTravel.TravelMap.AddRemoveVisited.prototype.onSuccess = function ()
{
        return true;
};



DoYouTravel.TravelMap.fetchDestinationsWithinBox = function ( method, url, options )
{
        this.init(method, url, options);
}

DoYouTravel.TravelMap.fetchDestinationsWithinBox.prototype = new EPSILON.Ajax('', '', '');
DoYouTravel.TravelMap.fetchDestinationsWithinBox.constructor = DoYouTravel.TravelMap.fetchDestinationsWithinBox;
DoYouTravel.TravelMap.fetchDestinationsWithinBox.superclass = EPSILON.Ajax.prototype;

DoYouTravel.TravelMap.fetchDestinationsWithinBox.prototype.onSuccess = function ()
{
        return true;
};

DoYouTravel.TravelMap.fetchDestinationsWithinBox.prototype.onAbort = function ()
{
        return true;
};


DoYouTravel.TravelMap.prototype.displayDestinationList = function ()
{
        var listRef = document.getElementById("view_list");
        
        var startValueRef = document.getElementById("startpagingvalue");
        var startValue = startValueRef.value;
        
        if ( this.mapSize == 2 )
        {
                var tempHTML = '<ul id="view_list_edit">';
        }
        else
        {
                var tempHTML = "<ul>";
        }
        
        var total = this.destinationCache.length;
        
        var count = 0;
        for ( var i=startValue; i<total; i++ )
        {
                
                if ( count >= DoYouTravel.Config.pagingValue )
                {
                        break;
                }
                
                /*
                var selectHTML = '<select class="visits" onchange="travelmap.toggleVisited(event, ' + this.destinationCache[i].id + ')">';
                
                for ( var i2=0; i2<=30; i2++ )
                {
                        var visitedSelected = "";
                        
                        if ( i2 == this.cityCached[i].visits )
                        {
                            visitedSelected = "selected";
                        }
                        
                        selectHTML += '<option value="' + i2 + '" ' + visitedSelected + '>' + i2 + '</option>';
                }
                selectHTML += '</select>';
                */
                
                
                if ( this.mapSize == 2 )
                {
                        var selectHTML = '<select onchange="travelmap.toggleVisitedWithinBox(event, ' + this.destinationCache[i].ci_id + ');">';
                        
                        for ( var i2=0; i2<=30; i2++ )
                        {
                                var visitedSelected = "";
                                
                                if ( i2 == this.destinationCache[i].visits )
                                {
                                        visitedSelected = "selected";
                                }
                                
                                selectHTML += '<option value="' + i2 + '" ' + visitedSelected + '>' + i2 + '</option>';
                        }
                        selectHTML += '</select>';
                        
                        
                        tempHTML = tempHTML + '<li><a href="javascript://" onclick="travelmap.showMarkerWithId(' + this.destinationCache[i].ci_id + ')">' + this.destinationCache[i].city + ', ' +
                                this.destinationCache[i].countrycode + "</a>" + selectHTML + "</li>";
                }
                else if ( this.mapSize == 1 )
                {
                        tempHTML = tempHTML + '<li><a href="javascript://" onclick="travelmap.showMarkerWithId(' + this.destinationCache[i].ci_id + ')">' + this.destinationCache[i].city + ', ' +
                                this.destinationCache[i].countrycode + "</a></li>";
                }
                
                count++;
        }
        
        
        tempHTML = tempHTML + "</ul>";
        
        if ( i < total )
        {
              document.getElementById("nextbutton").style.display = "";
        }
        else
        {
              document.getElementById("nextbutton").style.display = "none";
        }
        
        
        if ( startValue > 0 )
        {
              document.getElementById("previousbutton").style.display = "";
        }
        else
        {
              document.getElementById("previousbutton").style.display = "none";
        }
        
        
        listRef.innerHTML = tempHTML;
}









DoYouTravel.Utils = DoYouTravel.Utils || {};

DoYouTravel.Utils.setErrorMessage = function ( xmlmsg, nodeId, elementId )
{
        var errMsg = '';
        
        var node =
                xmlmsg.getElementsByTagName(
                nodeId)[0];
        if ( node.hasChildNodes() )
        {
                errMsg = node.firstChild.nodeValue;
        }
        
        document.getElementById(elementId).innerHTML =
                errMsg;
};



function showAdd ( )
{
       
       document.getElementById("add_tab").className = "menuActive";
       document.getElementById("view_tab").className = "menuInActive";
       
       document.getElementById("view_list").style.display = "none";
       document.getElementById("add_list").style.display = "";
       
       document.getElementById("view_buttons").style.display = "none";
       document.getElementById("add_buttons").style.display = "";
}


function showView ( )
{
       
       document.getElementById("add_tab").className = "menuInActive";
       document.getElementById("view_tab").className = "menuActive";
       
       document.getElementById("view_list").style.display = "";
       document.getElementById("add_list").style.display = "none";
       
       
       document.getElementById("view_buttons").style.display = "";
       document.getElementById("add_buttons").style.display = "none";
}

function displayChangeHometown ( )
{
       document.getElementById("hometown_displayer").style.display = "none";
       document.getElementById("hometown_changer").style.display = "";
       
       
       var dropdownValueRef = document.getElementById("hometown_value");
              
              
       var inputRef = document.getElementById("hometown_input");
       
       if ( travelmap.hometownCache )
       {
              inputRef.value = travelmap.hometownCache.city + ", " + travelmap.hometownCache.countrycode;
       
              dropdownValueRef.value = travelmap.hometownCache.id;
       
       }
}

function displayViewHometown ( )
{
       document.getElementById("hometown_displayer").style.display = "";
       document.getElementById("hometown_changer").style.display = "none";
       
       document.getElementById("myhometown").innerHTML = travelmap.hometownCache.city + ", " + travelmap.hometownCache.countrycode;
       
}
/*
function testredbox ( )
{

          travelmap.map.newbox = new GPolyline([new GLatLng(22.0, 56.0), new GLatLng(5.0, 56.0), new GLatLng(5.0, 28.0), new GLatLng(22.0, 58.0), new GLatLng(22.0, 56.0)], "#FF0000", 2, 10);
         
	
         
         travelmap.map.addOverlay(travelmap.map.newbox);
         
         alert("there should be a red box on the map now");
*/

/*
                        var icon = new GIcon();
                        icon.iconSize = new GSize(40,40);
                        icon.iconAnchor = new GPoint(6, 20);
                        icon.infoWindowAnchor = new GPoint(5, 1);
                        
                        
                        if ( BrowserDetect.browser == 'Explorer' && BrowserDetect.version == 6)
                        {    
                                   icon.image =
                                        'http://doyoutravel.co.uk/map/images/redbox.png';
                        }
                        else
                        {
                               icon.image =
                                    'http://doyoutravel.co.uk/map/images/redbox.png';
                        }


                        var point = new GLatLng(
                                40.2,
                                40.2);
                        var marker = new GMarker(point,icon);
                        
                        alert(marker);
                        
	travelmap.map.addOverlay(marker);
}*/