 			var map;						//set up our map var
            var mgr;						//set up our markermanager var
            var addmarker;		
            var selectedListItem;  			           
            var allmarkers 			= [];	//our markers array (initial set up of markers, replacing markers (list)
            var bigmarkers 			= [];	//array for replacing small markers with big markers
            var smallmarkers 		= [];	//array for replacing small markers with big markers
            var ratings				= [];   //array for our rating items
            var minZoom				= 5;	//set minimumzoomlevel, used when readding markers (list)
            var maxZoomMap			= 17;	//set maxzoomlevel, used when readding markers (list)
            var maxZoomOther		= 19;	//set maxzoomlevel, we can zoom in more when sattelite map is showing
			var mapDefaultZoom 		= 7;	//set defaultzoomlevel, used when initiating map and readding markers (list)
			var addLocationZoom 	= 13; 	//set zoomlevel when adding location
			var windowCloseListener = '';
			var managerWindowCloseListener = '';
			var foundLocationZoom 	= 15; 	//set zoomlevel when found location
			var mapCenter 			= new GLatLng(52.373812,4.890951) //our mapcenter, update per locale
            var geocoder 			= new GClientGeocoder();

			var iconSmallWidth 		= 12;
			var iconSmallHeight 	= 12;
			var iconBigWidth 		= 24;
			var iconBigHeight 		= 35;
			var iconUrlStart		= "img/marker_";
			var iconColor			= "_red";
			var iconUrlEnd			= ".png";
            
            var name 		= '';
		    var address 	= '';
		    var postcode	= '';
		    var city  		= '';
		    var description = '';
		    var type		= '';
		    var telephone	= '';
		    var mobile		= '';
		    var email 		= '';
		    var website		= '';
		    var monfri		= '';
		    var mon			= '';
		    var tue			= '';
		    var wed			= '';
		    var thu			= '';
		    var fri			= '';
		    var sat			= '';
		    var sun			= '';
		    var longitude   = '';
		    var latitude 	= '';
		    var access      = '';
		    var cleanliness = '';
		    var size		= '';
		    var comfort		= '';
		    var discretion	= '';
		    var message		= '';
		    var byName		= '';
		    var byEmail		= '';	
		    var byFrom		= '';
		    var byOptIn		= '';
		    var addType		= '';
		    var action		= '';
		    
			function load() {
              if (GBrowserIsCompatible()) {
                map = new GMap2(document.getElementById("map"));
                restrictZoomLevels(map, minZoom, maxZoomMap)
                map.addControl(new GLargeMapControl3D());
                map.addControl(new GMapTypeControl());
                map.setCenter(mapCenter,mapDefaultZoom);
                restrictZoomLevels(map, minZoom, maxZoomMap);
                
                mgr = new MarkerManager(map, {
                  trackMarkers: true
                });
                setTimeout(setupLocationBrowseMarkers, 0);
                getList();
				
				GEvent.addListener(map, 'maptypechanged', 
		            function(){ 
		            	if(map.getCurrentMapType().getName() == 'Map'){
							restrictZoomLevels(map, minZoom, maxZoomMap);
						}else{
							restrictZoomLevels(map, minZoom, maxZoomOther);
						}
		            }
				);
              }
            }
                     
            function setupLocationBrowseMarkers() {
              allmarkers.length = 0;
              for (var i in locationLayer) {
                if (locationLayer.hasOwnProperty(i)) {
                  var layer = locationLayer[i];
                  var markers = [];
                  for (var j in layer["places"]) {
                    if (layer["places"].hasOwnProperty(j)) {
                      var place = layer["places"][j];
                      var id = place["id"];
                      var color = place["color"];
                      var icon = getIcon('small',color);
					  var posn = new GLatLng(place["posn"][0], place["posn"][1]);
                      
                      var marker = createMarker(id,icon,posn,color);
                      markers.push(marker);
                      allmarkers[id] = marker;
                    }
                  }
                  mgr.addMarkers(markers, layer["zoom"][0], layer["zoom"][1]);
                }
                
              }
              mgr.refresh();
            }
            
            function setupLocationListMarkers(json,modified) {
				map.setCenter(mapCenter,mapDefaultZoom);
				var locationListData = eval('(' + json + ')');	
				var locationListData;
				if(modified == true){
					for(var i=0; i<bigmarkers.length; i++) {
						var id = allmarkers[bigmarkers[i].id].id;
						var oldColor = allmarkers[bigmarkers[i].id].name;
	                    var posn = allmarkers[bigmarkers[i].id].getLatLng();
	                    var icon = getIcon('small',oldColor);
	                    var smallmarker = createMarker(id,icon,posn,oldColor);
						
						mgr.removeMarker(allmarkers[bigmarkers[i].id]);	
						mgr.addMarker(smallmarker,minZoom,maxZoomMap)
						allmarkers[id] = smallmarker;
					}
				}
				
				bigmarkers.length = 0;
				for(var i=0; i<locationListData["markers"].length; i++) {
					var place = locationListData["markers"][i];
                    var id = place["id"];
                    var color = place["color"];
                    var posn = new GLatLng(place["posn"][0], place["posn"][1]);
                    var icon = getIcon('big',color);
                       
                    var bigmarker = createMarker(id,icon,posn,color);
                   	if(allmarkers[id] != undefined){
                   		mgr.removeMarker(allmarkers[id]);
                   	}
                   	
					allmarkers[id] = bigmarker;
					bigmarkers.push(bigmarker);
					
					mgr.addMarker(bigmarker,minZoom,maxZoomMap);
				}
			}	
				
			function setupSearchResultMarkers(json,modified,defaultZoom) {
				mgr.clearMarkers();
				
				var locationListData = eval('(' + json + ')');	
				var bounds = new GLatLngBounds;
				
				//smallmarkers.length = 0;
				for (var i = 0; i < locationListData["small-markers"].length; i++) {
					var place = locationListData["small-markers"][i];
					var id = place["id"];
					var color = place["color"];
					var posn = new GLatLng(place["posn"][0], place["posn"][1]);
					var icon = getIcon('small',color);
					var smallmarker = createMarker(id, icon, posn);
					allmarkers[id] = smallmarker;
					mgr.addMarker(smallmarker,minZoom,maxZoomMap);
					bounds.extend(posn);
				}
				
				bigmarkers.length = 0;
				for(var i=0; i<locationListData["markers"].length; i++) {
					var place = locationListData["markers"][i];
                    var id = place["id"];
                    var color = place["color"];
                    var posn = new GLatLng(place["posn"][0], place["posn"][1]);
                    var icon = getIcon('big',color);
                       
                    var bigmarker = createMarker(id,icon,posn);
                   	mgr.removeMarker(allmarkers[id]);
					allmarkers[id] = bigmarker;
					mgr.addMarker(bigmarker,minZoom,maxZoomMap);
					bounds.extend(posn);
				} 
				
				if(defaultZoom == true){
					map.setCenter(mapCenter,mapDefaultZoom);
                	restrictZoomLevels(map, minZoom, maxZoomMap);
				}else{
					if(bounds.isEmpty() == false){
						map.setZoom((map.getBoundsZoomLevel(bounds)-1));
						map.setCenter(bounds.getCenter()); 
					}
				}
				
				
			}	
			
			/**
			 * create our marker
			 * createMarker(): creates marker with a click listener which opens up 
			 * the info for that marker through an ajax request.
			 */
            function createMarker(id,icon,posn,color) {
            	var infoWindowContent;
            	var marker = new GMarker(posn, {
                	id: id,
               		name: color,
                	icon: icon,
                	draggable: false
              	});
              	
				GEvent.addListener(marker, 'click',
		            function(){
		            	$.ajax({
				  			url: "location-details.php?id="+marker.id,
				  			cache: false,
				  			success: function(html){
				    			map.openInfoWindowHtml(marker.getLatLng(),html);
				  			}
						}); 
					 	highlightListItem(marker.id);
		            }
				);			  
              return marker;
            }
			
            /**
			 * Show marker info
			 * Load in our marker info through ajax when user clicks on list item.
			 */
			function showMarkerInfo(markerId){
				highlightListItem(markerId);
				map.closeInfoWindow();
				$.ajax({
				  	url: "location-details.php?id="+markerId,
				  	cache: false,
				  	success: function(html){
				    	map.openInfoWindowHtml(allmarkers[markerId].getLatLng(),html);
					}
				});
			}
           	
           	function reportLocation(id){
           		map.closeInfoWindow();
				$.post( "location-report.php",
						{ id: id },
						function(html){
							map.openInfoWindowHtml(allmarkers[id].getLatLng(),html);
		  		});		
           	}
			
			function submitReport(id){
           		var message	= $('#message').val();
		    	var byName 	= $('#by-name').val();
		    	var byEmail	= $('#by-email').val();	
				if($('#by-opt-in').attr("checked") == true){
		    		byOptIn = '1';
		    	}else{
		    		byOptIn = '0';
		    	}
					$.post( "location-report.php",
						{ id: id, message: message, byName: byName, byEmail: byEmail, byOptIn: byOptIn, action: 'add' },
						function(html){
							map.openInfoWindowHtml(allmarkers[id].getLatLng(),html);	
						}
					);
           	}

            function showMarkers() {
              mgr.show();
            }
            
            function hideMarkers() {
              mgr.hide();
            }
            
            function clearMarkers() {
              mgr.clearMarkers();
            }
            
            function reloadMarkers() {
              setupLocationMarkers();
            }
            
            function toggleMarkers() {
              mgr.toggle();
            }
            
			function getList() {
				//load top
            	$.post( "list-top.php",
						function(html){
				    		$("#top-content").html(html);
				  		});
				  		
				//load in our locations and display then in the lefthand menu
            	$.post( "locations-list.php",
						function(html){
				    		$("#location-list").html(html);
				    		setupLocationListMarkers($('#json').text(),true);				  
				  		});
			}
			
			function getModifiedList(order,start) {
				map.closeInfoWindow();
				//load in our locations and display then in the lefthand menu
            	$.post( "locations-list.php",
						{ order: order, start: start},
						function(html){
				    		$("#location-list").html(html);
				    		setupLocationListMarkers($('#json').text(),true);				  
				  		});		
			}

			function getSearchResults(searchValue,order,start) {
				map.closeInfoWindow();
				if(searchValue == false){
					var searchValue = $('#searchField').val();	
				}
				if(order == false){ 
					var order = 'rating';	
				}
				
				//load in our locations and display then in the lefthand menu
            	$.post( "locations-search.php",
						{ data: searchValue, order: order, start: start},
						function(html){
				    		$("#location-list").html(html);
				    		if(searchValue == '%'){
				    			setupSearchResultMarkers($('#json').text(),true,true);				  
				    		}else{
				    			setupSearchResultMarkers($('#json').text(),true,false);				  
				    		}
				    		
				  		});	
			}
									
            function highlightListItem(listItemId) {
				var iconSrcArray;
				var iconSrc;
				var newIconSrc;
				var starSrcArray;
				var starSrc;
				var newStarSrc;
							
				if (selectedListItem != null) {
					$('#result'+selectedListItem).css("color","#0E5Fd8");
					$('#result'+selectedListItem).css("background-color","#f4f4f7");
					if(iconSrc = $('#icon'+selectedListItem).attr("src") != undefined){
						iconSrc = $('#icon'+selectedListItem).attr("src").replace("_active", "");
						$('#icon'+selectedListItem).attr("src",iconSrc);
					}
					if($('#stars'+selectedListItem).attr("src") != undefined){
						starsSrc = $('#stars'+selectedListItem).attr("src").replace("_active", "");
						$('#stars'+selectedListItem).attr("src",starsSrc);
					}
				}
				$('#result'+listItemId).css("color","#FFF");
				$('#result'+listItemId).css("background-color","#689CFF");
				
				if ($('#icon' + listItemId).attr("src") != undefined) {
					iconSrcArray = $('#icon' + listItemId).attr("src").split("/");
					iconSrc = iconSrcArray[iconSrcArray.length - 1];
					
					newIconSrc = iconSrc.match(/[^\.]+/) + "_active.gif";
					$('#icon' + listItemId).attr("src", "img/" + newIconSrc);
				}
				if($('#stars'+listItemId).attr("src") != undefined){
					starSrcArray = $('#stars'+listItemId).attr("src").split("/");
					starSrc = starSrcArray[starSrcArray.length-1];
					
					newStarsSrc = starSrc.match(/[^\.]+/) + "_active.gif";
					$('#stars'+listItemId).attr("src","img/"+newStarsSrc);
				}
			
				selectedListItem = listItemId;
			}	
			
			/*
			 *  Here our functions for adding in a new loction.
			 * 
			 * 
			 */
			function addLocation(){
				map.closeInfoWindow();
				$.post("list-top.php",
					{ action: 'addlocation' },
					function(html){
						$("#top-content").html(html);
					}
				);
				toggle('list-middle,location-list');
	            hideMarkers();
			    map.setZoom(addLocationZoom);
			    createInputMarker(map.getCenter());
            }
            
            function returnToBrowse(type){
				if(type == 'search'){
					window.location.reload();
				}else{	
					$.post( "list-top.php",
						function(html){
							$("#top-content").html(html);
					});
					toggle('list-middle,location-list');
					showMarkers();
			    	map.setCenter(mapCenter,mapDefaultZoom);
				} 
            }
													
          	//create a marker with an input form
		    function createInputMarker(point) {  		
				addmarkerIcon = new GIcon(G_DEFAULT_ICON);
				addmarkerIcon.infoWindowAnchor = new GPoint(5,5);
				
				addmarker = new GMarker(point,{icon:addmarkerIcon, draggable:true});
				
				windowCloseListener = GEvent.bind(map, "infowindowclose", map, function() {
                	GEvent.removeListener(windowCloseListener);
                	returnToBrowse();
                	map.removeOverlay(addmarker);
	            });

				// Close window when dragging starts, if the search option is not used
				GEvent.addListener(addmarker, "dragstart", function() {
					GEvent.removeListener(windowCloseListener);
					
					name 		= $('#add-name').val();
			    	address 	= $('#add-address').val();
			    	postcode	= $('#add-postcode').val();
			    	city  		= $('#add-city').val();
			    	description = $('#add-description').val();
			    	type		= $('#add-type').val();
			    	telephone	= $('#add-telephone').val();
			    	mobile		= $('#add-mobile').val();
			    	email 		= $('#add-email').val();
			    	website		= $('#add-website').val();
			    	monfri		= $('#add-mon-fri-open-hour').val()+'.'+$('#add-mon-fri-open-min').val()+' - '+$('#add-mon-fri-close-hour').val()+'.'+$('#add-mon-fri-close-min').val();
			    	mon			= $('#add-mon-open-hour').val()+'.'+$('#add-mon-open-min').val()+' - '+$('#add-mon-close-hour').val()+'.'+$('#add-mon-close-min').val();
			    	tue			= $('#add-tue-open-hour').val()+'.'+$('#add-tue-open-min').val()+' - '+$('#add-tue-close-hour').val()+'.'+$('#add-tue-close-min').val();
			    	wed			= $('#add-wed-open-hour').val()+'.'+$('#add-wed-open-min').val()+' - '+$('#add-wed-close-hour').val()+'.'+$('#add-wed-close-min').val();
			    	thu			= $('#add-thu-open-hour').val()+'.'+$('#add-thu-open-min').val()+' - '+$('#add-thu-close-hour').val()+'.'+$('#add-thu-close-min').val();
			    	fri			= $('#add-fri-open-hour').val()+'.'+$('#add-fri-open-min').val()+' - '+$('#add-fri-close-hour').val()+'.'+$('#add-fri-close-min').val();
			    	sat			= $('#add-sat-open-hour').val()+'.'+$('#add-sat-open-min').val()+' - '+$('#add-sat-close-hour').val()+'.'+$('#add-sat-close-min').val();
			    	sun			= $('#add-sun-open-hour').val()+'.'+$('#add-sun-open-min').val()+' - '+$('#add-sun-close-hour').val()+'.'+$('#add-sun-close-min').val();
			    	longitude   = $('#add-longitude').val();
			    	latitude 	= $('#add-latitude').val();
			    	action  	= $('#add-action').val();
			    	country		= $('#add-country').val();
					
					map.closeInfoWindow();
				});
							        
		        // Open window when dragging stops
				GEvent.addListener(addmarker, "dragend", function() {
					//load in step 2
					$.post( "add-location.php",
						{ name: name, address: address, postcode: postcode, city: city, country: country, description: description, type: type, telephone: telephone, mobile: mobile, email: email, website: website, monfri: monfri, mon: mon, tue: tue, wed: wed, thu: thu, fri: fri, sat: sat, sun: sun, longitude: longitude, latitude: latitude, action: action },
						function(html){
							addmarker.openInfoWindowHtml(html);
							
							if(monfri != '00.00 - 00.00' || mon != '00.00 - 00.00' || tue != '00.00 - 00.00' || wed != '00.00 - 00.00' || thu != '00.00 - 00.00' || fri != '00.00 - 00.00' || sat != '00.00 - 00.00' || sun != '00.00 - 00.00'){
								toggle('add-opening,add-opening-link');
							}	
							if(mon != '00.00 - 00.00' || tue != '00.00 - 00.00' || wed != '00.00 - 00.00' || thu != '00.00 - 00.00' || fri != '00.00 - 00.00'){
								toggle('add-weekdays-link,add-weekdays,add-mon-fri-label,add-mon-fri-open-hour,add-mon-fri-open-min,add-mon-fri-close-hour,add-mon-fri-close-min,mon-fri-till');
							}
							setupRating();
						}
					);
					windowCloseListener = GEvent.bind(map, "infowindowclose", map, function() {
                		GEvent.removeListener(windowCloseListener);
                		map.removeOverlay(addmarker);
                		returnToBrowse();
	            	});
				});
		        
		        //add marker and show form
		        map.addOverlay(addmarker);
		        $.ajax({
				  url: "add-location.php",
				  cache: false,
				  success: function(html){
				    addmarker.openInfoWindowHtml(html);
				  }
				});
		       
		    }
		    
		    function submitStep1(){
		    	var geoMessage = '';
		    	
		    	name 		= $('#add-name').val();
		    	address 	= $('#add-address').val();
		    	postcode	= $('#add-postcode').val();
		    	city  		= $('#add-city').val();
		    	addType		= $('input[name=add]:checked').val();		 
		    	
			    if(addType == 'address'){
			    	geocoder.getLocations(
			    		address+', '+postcode+', '+city, 
			    		function(response){
			    			if(!response || response.Status.code != 200){
			    				geoMessage = 'notFoundAddress';
			    			}else{
			    				geoAddress_GL = response.Placemark[0].address;
								geoAddress_array = geoAddress_GL.split(",");
								geoCountryName					= '';
								geoAdministrativeAreaName		= '';
								geoSubAdministrativeAreaName	= '';
								geoLocalityName					= '';
								geoDependentLocalityName		= '';
								geoThoroughfare 				= '';
								geoPostalCode					= '';
								geoAccuracy 					= '';
	
								doAddressLoop(response.Placemark[0].AddressDetails);
								
			    				latitude	= response.Placemark[0].Point.coordinates[1];
			    				longitude	= response.Placemark[0].Point.coordinates[0];
			    								    						
			    				addpoint = new GLatLng(latitude,longitude);
			    						
			    				addmarker.setLatLng(addpoint);
			    				addmarker.enableDragging();
			    				map.setCenter(addpoint,foundLocationZoom);
			    			}
			    			//load in step 2
			    			GEvent.removeListener(windowCloseListener);
							$.post( "add-location.php",
								{ addMode: 'address', geoMessage: geoMessage, name: name, address: address, postcode: postcode, city: city, country: geoCountryNameCode, latitude: latitude, longitude: longitude, action: 'step2', addType: addType },
								function(html){
									addmarker.openInfoWindowHtml(html);	
									setupRating();	
									windowCloseListener = GEvent.bind(map, "infowindowclose", map, function() {
									    GEvent.removeListener(windowCloseListener);
	                					map.removeOverlay(addmarker);
	                					returnToBrowse();
									});	
			    			});			
			    		});				
			    	}else{	
			    		geocoder.getLocations(
			    			addmarker.getLatLng(),
			    			function(response){
			    				if(!response || response.Status.code != 200){
			    					geoMessage = 'notFoundDrag';
			    				}else{
			    					markerLatLng = addmarker.getLatLng().toString().split(',');
									latitude = markerLatLng[0].replace('(','');
									longitude = markerLatLng[1].replace(')','');
			    				
			    					geoAddress_GL = response.Placemark[0].address;
									geoAddress_array = geoAddress_GL.split(",");
									geoCountryNameCode				= '';
									geoCountryName					= '';
									geoAdministrativeAreaName		= '';
									geoSubAdministrativeAreaName	= '';
									geoLocalityName					= '';
									geoDependentLocalityName		= '';
									geoThoroughfare 				= '';
									geoPostalCode					= '';
									geoAccuracy 					= '';
									
									doAddressLoop(response.Placemark[0].AddressDetails);
																					
			    					address			= geoAddress_array[0];
			    					postcode		= geoPostalCode;
			    					city			= geoDependentLocalityName;
			    				}
			    				//load in step 2
						        $.post( "add-location.php",
									{ addMode: 'drag', geoMessage: geoMessage, name: name, address: address, postcode: postcode, city: city, country: geoCountryNameCode, latitude: latitude, longitude: longitude, action: 'step2', addType: addType },
									function(html){
										GEvent.removeListener(windowCloseListener);
										addmarker.openInfoWindowHtml(html);	
										setupRating();
										windowCloseListener = GEvent.bind(map, "infowindowclose", map, function() {
									    	GEvent.removeListener(windowCloseListener);
	                						map.removeOverlay(addmarker);
	                						returnToBrowse();
										});				  
								});
			    			}
			    		);
			    	}
			    
		    }
		    
		    function submitStep2(){
		    	name 		= $('#add-name').val();
		    	address 	= $('#add-address').val();
		    	postcode	= $('#add-postcode').val();
		    	city  		= $('#add-city').val();
		    	description = $('#add-description').val();
		    	type		= $('#add-type').val();
		    	telephone	= $('#add-telephone').val();
		    	mobile		= $('#add-mobile').val();
		    	email 		= $('#add-email').val();
		    	website		= $('#add-website').val();
		    	monfri		= $('#add-mon-fri-open-hour').val()+'.'+$('#add-mon-fri-open-min').val()+' - '+$('#add-mon-fri-close-hour').val()+'.'+$('#add-mon-fri-close-min').val();
			   	mon			= $('#add-mon-open-hour').val()+'.'+$('#add-mon-open-min').val()+' - '+$('#add-mon-close-hour').val()+'.'+$('#add-mon-close-min').val();
			   	tue			= $('#add-tue-open-hour').val()+'.'+$('#add-tue-open-min').val()+' - '+$('#add-tue-close-hour').val()+'.'+$('#add-tue-close-min').val();
			   	wed			= $('#add-wed-open-hour').val()+'.'+$('#add-wed-open-min').val()+' - '+$('#add-wed-close-hour').val()+'.'+$('#add-wed-close-min').val();
			   	thu			= $('#add-thu-open-hour').val()+'.'+$('#add-thu-open-min').val()+' - '+$('#add-thu-close-hour').val()+'.'+$('#add-thu-close-min').val();
			   	fri			= $('#add-fri-open-hour').val()+'.'+$('#add-fri-open-min').val()+' - '+$('#add-fri-close-hour').val()+'.'+$('#add-fri-close-min').val();
			   	sat			= $('#add-sat-open-hour').val()+'.'+$('#add-sat-open-min').val()+' - '+$('#add-sat-close-hour').val()+'.'+$('#add-sat-close-min').val();
			    sun			= $('#add-sun-open-hour').val()+'.'+$('#add-sun-open-min').val()+' - '+$('#add-sun-close-hour').val()+'.'+$('#add-sun-close-min').val();
		    	longitude   = $('#add-longitude').val();
		    	latitude 	= $('#add-latitude').val();
		    	country 	= $('#add-country').val();
				
				var i = 0;
				
				if($(".access-star:checked").val() != undefined){
					ratings[1] = $(".access-star:checked").val();
					i++;
				}
				if($(".cleanliness-star:checked").val() != undefined){
					ratings[2] = $(".cleanliness-star:checked").val();
					i++;
				}
				if($(".size-star:checked").val() != undefined){
					ratings[3] = $(".size-star:checked").val();
					i++;
				}
				if($(".comfort-star:checked").val() != undefined){
					ratings[4] = $(".comfort-star:checked").val();
					i++;
				}
				if($(".discretion-star:checked").val() != undefined){
					ratings[5] = $(".discretion-star:checked").val();
					i++;
				}
				
				if(i > 0 && i < 5){
					alert('please rate all options');
				}else{
					$.post( "add-location.php",
						{ name: name, address: address, postcode: postcode, city: city, country: country, description: description, type: type, telephone: telephone, mobile: mobile, email: email, website: website, monfri: monfri, mon: mon, tue: tue, wed: wed, thu: thu, fri: fri, sat: sat, sun: sun, longitude: longitude, latitude: latitude, access: ratings[1], cleanliness: ratings[2], size: ratings[3], comfort: ratings[4], discretion: ratings[5], action: 'step3' },
							function(html){
					    	addmarker.disableDragging();
					    	GEvent.removeListener(windowCloseListener);
					    	addmarker.openInfoWindowHtml(html);	
					    	windowCloseListener = GEvent.bind(map, "infowindowclose", map, function() {
								GEvent.removeListener(windowCloseListener);
                				map.removeOverlay(addmarker);
                				returnToBrowse();
							});				  
					  });
				}			
		    }
		    
			function submitStep3(step){
				name 		= $('#add-name').val();
		    	address 	= $('#add-address').val();
		    	postcode	= $('#add-postcode').val();
		    	city  		= $('#add-city').val();
		    	description = $('#add-description').val();
		    	type		= $('#add-type').val();
		    	telephone	= $('#add-telephone').val();
		    	mobile		= $('#add-mobile').val();
		    	email 		= $('#add-email').val();
		    	website		= $('#add-website').val();
		    	monfri		= $('#add-monfri').val();
		    	mon			= $('#add-mon').val();
		    	tue			= $('#add-tue').val();
		    	wed			= $('#add-wed').val();
		    	thu			= $('#add-thu').val();
		    	fri			= $('#add-fri').val();
		    	sat			= $('#add-sat').val();
		    	sun			= $('#add-sun').val();
		    	longitude   = $('#add-longitude').val();
		    	latitude 	= $('#add-latitude').val();
		    	country 	= $('#add-country').val();
		    	
		    	access      = $('#add-access').val();
		    	cleanliness = $('#add-cleanliness').val();
		    	size		= $('#add-size').val();
		    	comfort		= $('#add-comfort').val();
		    	discretion	= $('#add-discretion').val();
		    					
			    $.post( "add-location.php",
					{ name: name, address: address, postcode: postcode, city: city, country: country, description: description, type: type, telephone: telephone, mobile: mobile, email: email, website: website, monfri: monfri, mon: mon, tue: tue, wed: wed, thu: thu, fri: fri, sat: sat, sun: sun, longitude: longitude, latitude: latitude, access: access, cleanliness: cleanliness, size: size, comfort: comfort, discretion: discretion, byName: byName, byEmail: byEmail, byFrom: byFrom, byOptIn: byOptIn, action: step },
						function(html){
						    GEvent.removeListener(windowCloseListener);
						    addmarker.openInfoWindowHtml(html);	
							setupRating();
							if(step == 'step2'){
								if(monfri != '00.00 - 00.00' || mon != '00.00 - 00.00' || tue != '00.00 - 00.00' || wed != '00.00 - 00.00' || thu != '00.00 - 00.00' || fri != '00.00 - 00.00'){
									setTimeout("toggle('add-opening,add-opening-link');", "1000");
								}
								if(mon != '00.00 - 00.00' || tue != '00.00 - 00.00' || wed != '00.00 - 00.00' || thu != '00.00 - 00.00' || fri != '00.00 - 00.00'){
									setTimeout("toggle('add-weekdays-link,add-weekdays,add-mon-fri-label,add-mon-fri-open-hour,add-mon-fri-open-min,add-mon-fri-close-hour,add-mon-fri-close-min,mon-fri-till');", "1000");			
								}
							}else{
								addmarker.disableDragging();
							}
							
						    windowCloseListener = GEvent.bind(map, "infowindowclose", map, function() {
								GEvent.removeListener(windowCloseListener);
                				map.removeOverlay(addmarker);
                				returnToBrowse();
						});					  
				});

		    }
			
		    function submitStep4(){
		    	name 		= $('#add-name').val();
		    	address 	= $('#add-address').val();
		    	postcode	= $('#add-postcode').val();
		    	city  		= $('#add-city').val();
		    	description = $('#add-description').val();
		    	type		= $('#add-type').val();
		    	telephone	= $('#add-telephone').val();
		    	mobile		= $('#add-mobile').val();
		    	email 		= $('#add-email').val();
		    	website		= $('#add-website').val();
		    	monfri		= $('#add-monfri').val();
		    	mon			= $('#add-mon').val();
		    	tue			= $('#add-tue').val();
		    	wed			= $('#add-wed').val();
		    	thu			= $('#add-thu').val();
		    	fri			= $('#add-fri').val();
		    	sat			= $('#add-sat').val();
		    	sun			= $('#add-sun').val();
		    	longitude   = $('#add-longitude').val();
		    	latitude 	= $('#add-latitude').val();
		    	country 	= $('#add-country').val();
		    	
		    	access      = $('#add-access').val();
		    	cleanliness = $('#add-cleanliness').val();
		    	size		= $('#add-size').val();
		    	comfort		= $('#add-comfort').val();
		    	discretion	= $('#add-discretion').val();
		    	
		    	byName      = $('#add-added-by-name').val();
		    	byEmail 	= $('#add-added-by-email').val();
		    	byFrom		= $('#add-added-by-from').val();
		    	
		    	if($('#add-opt-in').attr("checked") == true){
		    		byOptIn = '1';
		    	}else{
		    		byOptIn = '0';
		    	}
		    	
			    $.post( "add-location.php",
					{ name: name, address: address, postcode: postcode, city: city, country: country, description: description, type: type, telephone: telephone, mobile: mobile, email: email, website: website, monfri: monfri, mon: mon, tue: tue, wed: wed, thu: thu, fri: fri, sat: sat, sun: sun, longitude: longitude, latitude: latitude, access: access, cleanliness: cleanliness, size: size, comfort: comfort, discretion: discretion, byName: byName, byEmail: byEmail, byFrom: byFrom, byOptIn: byOptIn, action: 'step5' },
					function(html){
						addmarker.disableDragging();
						GEvent.removeListener(windowCloseListener);
						addmarker.openInfoWindowHtml(html);	
						windowCloseListener = GEvent.bind(map, "infowindowclose", map, function() {
							GEvent.removeListener(windowCloseListener);
                			map.removeOverlay(addmarker);
                			returnToBrowse();
						});					  
				});
				
		    }
		     
		    function backToStep1(){
		    	name 		= $('#add-name').val();
		    	address 	= $('#add-address').val();
		    	postcode	= $('#add-postcode').val();
		    	city  		= $('#add-city').val();
		    	
		    	//go back to step 1
		    	$.post( "add-location.php",
						{ addMode: 'address', name: name, address: address, postcode: postcode, city: city, action: 'step1' },
							function(html){
					    	GEvent.removeListener(windowCloseListener);
					    	addmarker.openInfoWindowHtml(html);	
					    	windowCloseListener = GEvent.bind(map, "infowindowclose", map, function() {
								GEvent.removeListener(windowCloseListener);
                				map.removeOverlay(addmarker);
                				returnToBrowse();
							});					  
				});	

		    }
			
		    function enableAddAddress(){
		    	$('#add-address').attr("disabled", false); 
		    	$('#add-postcode').attr("disabled", false);
		    	$('#add-city').attr("disabled", false);
		    }
		    
		    function disableAddAddress(){
		    	$('#add-address').attr("disabled", true); 
		    	$('#add-address').val(''); 
		    	$('#add-postcode').attr("disabled", true);
		    	$('#add-postcode').val(''); 
		    	$('#add-city').attr("disabled", true);
		    	$('#add-city').val(''); 
		    }
			
			function toggle(ids){
				var toggleids = ids.split(',');
				
				for( i=0; i < toggleids.length; i++){
					if(toggleids[i] == 'add-mon-fri' || toggleids[i] == 'add-mon-fri-label'){
						$('#'+toggleids[i]).css({'display' :'none', 'height' : '0', 'background-color' : '#000' });
					}else{
						$('#'+toggleids[i]).toggle();
					}
					
				}
			}
			
			function toggleView(){
				if($('#view-map').css("display") == 'none'){
					map.setMapType(G_SATELLITE_MAP);
				}else{
					map.setMapType(G_NORMAL_MAP);
				}
				$('#view-sattelite').toggle();
				$('#view-map').toggle();
			}
			
			function searchMessage(toggle){
				if(toggle == 'clear'){
					$('#searchField').css({'color' :'#000'});
					$('#searchField').val('');	
				}
			}
			
			/*
			 *  Here our rating functions
			 * 
			 * 
			 */
        	function setupRating(id,type){			
				$('#rating-form').css({'display' :'block'});
				$('#rating-table').css({'display' :'none'});
				$('#rate').css({'display' :'none'});
				
				$(function(){
					$('.access-star').rating({
						focus: function(value, link){
					    	var tip = $('#hover-access');
					    	tip[0].data = tip[0].data || tip.html();
					    	tip.html(link.title || 'value: '+value);
						},
						blur: function(value, link){
							var tip = $('#hover-access');
					    	$('#hover-access').html(tip[0].data || '');
						}
					});
				});
				$(function(){
					$('.cleanliness-star').rating({
						focus: function(value, link){
					    	var tip = $('#hover-cleanliness');
					    	tip[0].data = tip[0].data || tip.html();
					    	tip.html(link.title || 'value: '+value);
						},
						blur: function(value, link){
					    	var tip = $('#hover-cleanliness');
					    	$('#hover-cleanliness').html(tip[0].data || '');
					  	}
					});
				});
				$(function(){
					$('.size-star').rating({
						focus: function(value, link){
					    	var tip = $('#hover-size');
					    	tip[0].data = tip[0].data || tip.html();
					    	tip.html(link.title || 'value: '+value);
					  	},
					  blur: function(value, link){
					    var tip = $('#hover-size');
					    $('#hover-size').html(tip[0].data || '');
					  }
					 });
				});
				$(function(){
					 $('.comfort-star').rating({
					 	focus: function(value, link){
					    	var tip = $('#hover-comfort');
					    	tip[0].data = tip[0].data || tip.html();
					    	tip.html(link.title || 'value: '+value);
					  	},
					  	blur: function(value, link){
					    	var tip = $('#hover-comfort');
					    	$('#hover-comfort').html(tip[0].data || '');
					  	}
					 });
				});
				$(function(){
					 $('.discretion-star').rating({
					 	focus: function(value, link){
					    	var tip = $('#hover-discretion');
					    	tip[0].data = tip[0].data || tip.html();
					    	tip.html(link.title || 'value: '+value);
					  	},
					  	blur: function(value, link){
					  		var tip = $('#hover-discretion');
					   		$('#hover-discretion').html(tip[0].data || '');
					  	}
						});
				});
				
				if(type == 'view'){
					//submit our results
	 				$('#rating-form').submit(function(){
	  					var i = 0;
	  					$('input',this).each(function(){
	   						if(this.checked){
	   							i++;
	   							ratings[i] = this.value; 								
							}
						});
						if(i < 5){
							alert('please rate all options');
						}else{
	            			$.post("process.php",
									{ action: "rating", id: id, access: ratings[1], cleanliness: ratings[2], size: ratings[3], comfort: ratings[4], discretion: ratings[5]},
									function(html){
					    				$("#rating-table-input").html(html);
					    			});	
						}
							
	  					return false;
	 				});
				} 
				
			}