// no enumerated type is JS, so here is a substitute for enum CCCMenuItemType:
HEADING = 1;
ALWAYSON = 2;
INITIALLYON = 3;
INITIALLYOFF = 4;
ROUTESET = 5;
LISTHEAD = 6;
CLOSELIST = 7;
SHOPS = 8;
STANDS = 9;
SHOW = 10;
MARKERSET = 11;
OLDSHOW = 12;

INSERT = 1;  // for database ops in bikestands and bikeshops
UPDATE = 2;
DELETE = 3;
SELECT = 4;

CREATE = 5;
EDIT = 6;
MOVE = 7;

var OSM, CCC_OSM_MAP, OSM_MAP, OSMCycle, CCC_OSM_CYCLE_MAP, OSM_CYCLE_MAP, OSM1, OSM_1_MAP, OSM2, OSM_2_MAP;

var CCCMapTypes = {
 'Map':	'G_NORMAL_MAP',
 'Hyb':	'G_HYBRID_MAP',
 'Sat':	'G_SATELLITE_MAP',
 'Ter':	'G_PHYSICAL_MAP',
 'OpenCycleMap':	'OSM_CYCLE_MAP',
 'OpenStreetMap':	'OSM_1_MAP',	// Now refers to the 'NoName' rendering
 'OSM Mapnik':	'OSM_1_MAP',	// Now refers to the 'NoName' rendering
 'OSM Osmarend':	'OSM_2_MAP', // not currently used
 'OSM 1':	'OSM_1_MAP',
 'OSM 2':	'OSM_2_MAP'	// not currently used
};

var CCCCookies = null;	

cycleStreetsPlannerURL = 	"http://camden.cyclestreets.net/api/journey.xml?key=24scher78jgdw46a";
cycleStreetsStandsURL = 	"http://camden.cyclestreets.net/api/photos.xml?key=24scher78jgdw46a";
proxyURL = "http://maps.camdencyclists.org.uk/proxy/curl_proxy_v2.php";
CamdenGISURL = "http://maps.camden.gov.uk/ParkingBays/parkingbaysrest.aspx";
CloudMadeURL = "http://geocoding.cloudmade.com/760bcec5faf34543934f9d6c07d8bd5c/geocoding/v2/find.js";
db_url_string = "../dbaccessSafe.php";
MarkerIcons_path = "http://maps.camdencyclists.org.uk/markericons/";
GPXroutes_path = "http://maps.camdencyclists.org.uk/GPXfiles/";
KMLroutes_path = "http://maps.camdencyclists.org.uk/kml/";


DBTables = {routes: "Routes", menudefs: "MenuDefs"}; 
	// Other DB tables are selected according to the marker names in CCCdefs
	
colourTable = new Array();
colourTable['black'] = {name: 'black', code: '#000000', opacity: 0.65};
colourTable['red'] = {name: 'red', code: '#CC0000', opacity: 0.65};
colourTable['indigo'] = {name: 'indigo', code: '#FF0033', opacity: 0.65};
colourTable['blue'] = {name: 'blue', code: '#0000CC', opacity: 0.65};
colourTable['turquoise'] = {name: 'turquoise', code: '#00FFCC', opacity: 0.65};
colourTable['violet'] = {name: 'violet', code: '#6600CC', opacity: 0.65};
colourTable['grey'] = {name: 'grey', code: '#666666', opacity: 0.65};
colourTable['magenta'] = {name: 'magenta', code: '#FF00FF', opacity: 0.50};
colourTable['green'] = {name: 'green', code: '#00FF33', opacity: 0.80};
colourTable['yellow'] = {name: 'yellow', code: '#DDAA00', opacity: 0.65};
colourTable['flame'] = {name: 'flame', code: '#FF3300', opacity: 0.75};
colourTable['orange'] = {name: 'orange', code: '#FF6600', opacity: 0.65};
colourTable['brown'] = {name: 'brown', code: '#663300', opacity: 0.65};
colourTable['LCNblue'] = {name: 'LCNblue', code: '#0066FF', opacity: 0.65};
colourTable['NCNblue'] = {name: 'NCNblue', code: '#0033CC', opacity: 0.65};
CCCDimmedColour = colourTable['black'].code ; 
CCCHilightColour = colourTable['flame'] ; 
CCCFocusColour = colourTable['indigo'] ; 

CCCZoomRectDelay = 1000; //Time in ms for which the blue rectangle remains visible after zooming.
CCCTrackWidth = 4;		// default width of polylines for tracks
CCCArrowWidth = 2; 		// default width for arrows on one-way streets
CCCArrowLength = 10; 		// default length for arrows on one-way streets
CCCArrowHead = 5; 		// default head size for arrows on one-way streets

// Control positions, etc
CCCTopMargin = 2;
CCCRightMargin = 2;
CCCBottomMargin = 2;
CCCButtonWidth = 77;
CCCMapTypeLabelPos = new GSize(CCCRightMargin+94, CCCTopMargin)
CCCMapTypePos = new GSize(CCCRightMargin, CCCTopMargin)
CCCZoomOutPos = new GSize(CCCRightMargin+157, CCCTopMargin);
CCCZoomInPos = new GSize(CCCZoomOutPos.width + CCCButtonWidth, CCCTopMargin);
CCCMenuPos = new GSize(CCCRightMargin, CCCTopMargin+20);
CCCMenuOpacity = 0.65;
CCCMenuWidth = 300;
CCCMenuBottomMargin = 160;
CCCEditFormPos = new GSize(430, CCCTopMargin);
CCCMenuHidePos = new GSize(CCCRightMargin+13, CCCMenuPos.height);
CCCHelpButtonPos = new GSize(CCCZoomInPos.width + CCCButtonWidth + 4, CCCTopMargin);
CCCRoutePlannerPos = new GSize(CCCHelpButtonPos.width + 20, CCCTopMargin);	// NB. x-offset is from left
CCCRoutePlannerMaxWidth = 380;
CCCAttributionBarPos = new GSize(305, CCCBottomMargin+3);
CCCSplashWinWidth = 440;
CCCSplashWinPosition = new GPoint(70, CCCTopMargin + 40);
CCCShortestRoutePlan = 50; // shortest route that we'll ask CycleStreets to plan
CCCProgressWinPos = new GPoint(70, CCCTopMargin);
CCCProgressImage = ' <image src=' + MarkerIcons_path + 'kittscanner.gif>';
CCCStandSelectDiameter = 0.6;	// width/diameter of the area in kilometres

// Regular expressions for extracting Metadata from XML files
NoDistanceRegExp = /xx/i; // search for 'xx' or 'XX'
ForwardArrowRegExp = /->/; // search for '->'
BackwardArrowRegExp = /<-/; // search for '->'
HtmlTagRegExp = /<.*?>/g; // search for all paired occurences of '<....>' (doesn't work for nested <..>)


  
/* enum CCCFileFormat - used only in the logMenuSQL function
JSON = 1;
GPX = 2;
 */
 
// enunerated set of values for GPXtype
ROUTE = 1;
TRACK = 2;

CCCRouteIconDefs = {
	size: new GSize(25,35), 
	shadowSize: new GSize(52,30), 
	shadowURL:  MarkerIcons_path + 'shadow.png',
	// assumed all same size, anchor point and shadow
	URLs: { 'red': MarkerIcons_path + 'bike-red.png',
			'indigo': MarkerIcons_path + 'bike-indigo.png',
			'blue': MarkerIcons_path + 'bike-blue.png',
			'turquoise': MarkerIcons_path + 'bike-turquoise.png',
			'violet': MarkerIcons_path + 'bike-violet.png',
			'magenta': MarkerIcons_path + 'bike-magenta.png',
			'green': MarkerIcons_path + 'bike-green.png',
			'orange': MarkerIcons_path + 'bike-orange.png',
			'flame': MarkerIcons_path + 'bike-flame.png',
			'brown': MarkerIcons_path + 'bike-brown.png',
			'grey': MarkerIcons_path + 'bike-grey.png',
			'LCNblue': MarkerIcons_path + 'LCN.png',
			'NCNblue': MarkerIcons_path + 'LCN.png'
	},
	keyURLs: { 'red': MarkerIcons_path + 'key-red.png',
			'indigo': MarkerIcons_path + 'key-indigo.png',
			'blue': MarkerIcons_path + 'key-blue.png',
			'turquoise': MarkerIcons_path + 'key-turquoise.png',
			'violet': MarkerIcons_path + 'key-violet.png',
			'magenta': MarkerIcons_path + 'key-magenta.png',
			'green': MarkerIcons_path + 'key-green.png',
			'orange': MarkerIcons_path + 'key-orange.png',
			'flame': MarkerIcons_path + 'key-flame.png',
			'brown': MarkerIcons_path + 'key-brown.png',
			'grey': MarkerIcons_path + 'key-grey.png',
			'LCNblue': MarkerIcons_path + 'key-LCNblue.png',
			'NCNblue': MarkerIcons_path + 'key-LCN.png'
	}
}

CCCInfoMarkerDefs = { // there must be an entry for every different infoMarker we plan to use
	// <Name>: 
	Stands: {
	// attributes preceded with _ are metadata
		_DBTable: 'StandsGeo',
		_isSpatial: true,
		_selectiveDisplay: true,
		_displayAsTable: true,
		_menuURL: MarkerIcons_path + 'standn.png',
		_menuRemoveURL: MarkerIcons_path + 'standx.png',
		Standard: {
			size: new GSize (18, 14),
			shadowSize: new GSize(27, 14), 
			anchor:  new GPoint (6, 14),
			URL: MarkerIcons_path + 'blankstand.png',
			shadowURL: MarkerIcons_path + 'stand-shadow.png',
			labelAnchorXY: {x: 9, y:5} // x  is the mid-point for the label, y is the bottom
		},
		Secure: {
			size: new GSize (23, 14),
			shadowSize: new GSize(32, 14), 
			anchor:  new GPoint (6, 14),
			URL: MarkerIcons_path + 'lockstand.png',
			shadowURL: MarkerIcons_path + 'stand-shadow.png', // need a new shadow
			labelAnchorXY: {x: 9, y:5} // x  is the mid-point for the label, y is the bottom
		},
		Covered: {
			size: new GSize (18, 18),
			shadowSize: new GSize(27, 18), 
			anchor:  new GPoint (6, 14),
			URL: MarkerIcons_path + 'roofstand.png',
			shadowURL: MarkerIcons_path + 'stand-shadow.png', // need a new shadow
			labelAnchorXY: {x: 9, y:9} // x  is the mid-point for the label, y is the bottom
		},
		Secure_Covered: {
			size: new GSize (23, 18),
			shadowSize: new GSize(32, 18), 
			anchor:  new GPoint (6, 14),
			URL: MarkerIcons_path + 'lockroofstand.png',
			shadowURL: MarkerIcons_path + 'stand-shadow.png', // need a new shadow
			labelAnchorXY: {x: 9, y:9} // x  is the mid-point for the label, y is the bottom
		},
		Off_Street: {
			size: new GSize (22, 18),
			shadowSize: new GSize(32, 18), 
			anchor:  new GPoint (6, 14),
			URL: MarkerIcons_path + 'fencestand.png',
			shadowURL: MarkerIcons_path + 'stand-shadow.png', // need a new shadow
			labelAnchorXY: {x: 11, y:7} // x  is the mid-point for the label, y is the bottom
		},
		Famine: {
			size: new GSize (22,18),
			shadowSize: new GSize(27, 14), 
			anchor:  new GPoint(6, 14),
			URL: MarkerIcons_path + 'faminestand.png',
			shadowURL: MarkerIcons_path + 'stand-shadow.png', // need a new shadow
			labelAnchorXY: {x: 9, y:5} // x  is the mid-point for the label, y is the bottom
		},
		Street: {
			size: new GSize (18, 14),
			shadowSize: new GSize(27, 14), 
			anchor:  new GPoint(6, 14),
			URL: MarkerIcons_path + 'blankstand.png',
			shadowURL: MarkerIcons_path + 'stand-shadow.png', // need a new shadow
			labelAnchorXY: {x: 9, y:5} // x  is the mid-point for the label, y is the bottom
		},
		_labels: {
			height: 8,
			1: { URL: MarkerIcons_path + 'no1.png', width: 3 },
			2: { URL: MarkerIcons_path + 'no2.png', width: 5 },
			3: { URL: MarkerIcons_path + 'no3.png', width: 5 },
			4: { URL: MarkerIcons_path + 'no4.png', width: 5 },
			5: { URL: MarkerIcons_path + 'no5.png', width: 5 },
			6: { URL: MarkerIcons_path + 'no6.png', width: 5 },
			7: { URL: MarkerIcons_path + 'no7.png', width: 5 },
			8: { URL: MarkerIcons_path + 'no8.png', width: 5 },
			9: { URL: MarkerIcons_path + 'no9.png', width: 5 },
			'Camden': { URL: MarkerIcons_path + 'camdenlogo-12.png', width: 12 },
			'OSM': { URL: MarkerIcons_path + 'OSMlogo-12.png', width: 12 },
			'CycleStreets': { URL: MarkerIcons_path + 'cyclestreetslogo-12.png', width: 12 },
			'other': { URL: MarkerIcons_path + 'no10.png', width: 11 }
		}
	},
	Shops: {
		_selectiveDisplay: false,
		_displayAsTable: true,
		_menuURL: MarkerIcons_path + 'tinyshop.png',
		_menuRemoveURL: MarkerIcons_path + 'tinystarx.png',
		Standard: {
			size: new GSize(28,26),
			shadowSize: new GSize(33,16),
			anchor:  new GPoint(14,26),
			URL: MarkerIcons_path + 'shop.png',
			shadowURL: MarkerIcons_path + 'shop-shadow.png'
		}
	},
	Hazards: {
		_selectiveDisplay: false,
		_displayAsTable: true,
		_menuURL: MarkerIcons_path + 'tinyhazard.png',
		_menuRemoveURL: MarkerIcons_path + 'tinyhazardx.png',
		Standard: {
			size: new GSize(22,20),
			shadowSize: new GSize(38,20),
			anchor:  new GPoint(11,20),
			URL: MarkerIcons_path + 'shriek.png',
			shadowURL: MarkerIcons_path + 'hazard-shadow.png'
		},
		Roadworks: {
			size: new GSize(22,20),
			shadowSize: new GSize(38,20),
			anchor:  new GPoint(11,20),
			URL: MarkerIcons_path + 'roadwork.png',
			shadowURL: MarkerIcons_path + 'hazard-shadow.png'
		},
		Closure: {
			size: new GSize(20,20),
			shadowSize: new GSize(30,14),
			anchor:  new GPoint(11,20),
			URL: MarkerIcons_path + 'closure.png',
			shadowURL: MarkerIcons_path + 'closure-shadow.png'
		},
		Dangerspot: {
			size: new GSize(22,20),
			shadowSize: new GSize(38,20),
			anchor:  new GPoint(11,20),
			URL: MarkerIcons_path + 'dangerspot.png',
			shadowURL: MarkerIcons_path + 'hazard-shadow.png'
		}
	},
	Consultations: {
		_selectiveDisplay: false,
		_displayAsTable: true,
		_menuURL: MarkerIcons_path + 'tinycons.png',
		_menuRemoveURL: MarkerIcons_path + 'tinycons.png',
		Standard: {
			size: new GSize(25,35),
			shadowSize: new GSize(53,20),
			anchor:  new GPoint(0,35),
			URL: MarkerIcons_path + 'consultation-white.png',
			shadowURL: MarkerIcons_path + 'consultation-shadow.png'
		},
		Snag: {
			size: new GSize(17,36),
			shadowSize: new GSize(53,20),
			anchor:  new GPoint(4,36),
			URL: MarkerIcons_path + 'snag.png',
			shadowURL: MarkerIcons_path + 'snag-shadow.png'
		},
		Pending: {
			size: new GSize(25,35),
			shadowSize: new GSize(53,20),
			anchor:  new GPoint(0,35),
			URL: MarkerIcons_path + 'consultation-white.png',
			shadowURL: MarkerIcons_path + 'consultation-shadow.png'
		},
		Responded: {
			size: new GSize(25,35),
			shadowSize: new GSize(53,20),
			anchor:  new GPoint(0,35),
			URL: MarkerIcons_path + 'consultation-grey.png',
			shadowURL: MarkerIcons_path + 'consultation-shadow.png'
		},
		Approved: {
			size: new GSize(25,35),
			shadowSize: new GSize(53,20),
			anchor:  new GPoint(0,35),
			URL: MarkerIcons_path + 'consultation-yellow.png',
			shadowURL: MarkerIcons_path + 'consultation-shadow.png'
		},
		Implemented: {
			size: new GSize(25,35),
			shadowSize: new GSize(53,20),
			anchor:  new GPoint(0,35),
			URL: MarkerIcons_path + 'consultation-blue.png',
			shadowURL: MarkerIcons_path + 'consultation-shadow.png'
		},
		Dropped: {
			size: new GSize(25,35),
			shadowSize: new GSize(53,20),
			anchor:  new GPoint(0,35),
			URL: MarkerIcons_path + 'consultation-red.png',
			shadowURL: MarkerIcons_path + 'consultation-shadow.png'
		},
		Audited: {
			size: new GSize(25,35),
			shadowSize: new GSize(53,20),
			anchor:  new GPoint(0,35),
			URL: MarkerIcons_path + 'consultation-magenta.png',
			shadowURL: MarkerIcons_path + 'consultation-shadow.png'
		}
		
	},
	Routes: {	// When we create a new route, we start by creating one of these in any arbitrary position, 
				// then transmute it into a route marker
		_selectiveDisplay: false,
		_menuURL: MarkerIcons_path + 'route-editing.png',
		Standard: {
			size: new GSize(15,15), 
			shadowSize: new GSize(0,0), 
			anchor:  new GPoint(10,30),
			URL: MarkerIcons_path + 'route-editing.png'
		}
	},
	RouteMarkers: {
		selectiveDisplay: false,
		_menuURL: MarkerIcons_path + 'tinygpushpin2.png',
		_menuRemoveURL: MarkerIcons_path + 'pushpin2.png',
		Standard: {
			size: new GSize(32,32),
			shadowSize: new GSize(56,32),
			anchor:  new GPoint(24,32),
			URL: MarkerIcons_path + 'gpushpin2.png',
			shadowURL: MarkerIcons_path + 'gpushpin2-shadow.png'
		}
	},
	HireStations: {
		_selectiveDisplay: false,
		_displayAsTable: true,
		_menuURL: MarkerIcons_path + 'tinyHireStation.png',
		_menuRemoveURL: MarkerIcons_path + 'tinystarx.png',
		Standard: {
			size: new GSize(25,37),
			shadowSize: new GSize(50,20),
			anchor:  new GPoint(12,37),
			URL: MarkerIcons_path + 'hireStation.png',
			shadowURL: MarkerIcons_path + 'consultation-shadow.png'
		}
	}

}

var CCCIconSets = new CCCIcons ();

function CCCIcons () { //constructor that sets up and initialises all the icons we will need 
						// but we don't instantiate all the different 'lebelled' markers here
						
	this.routeIcons = [];			// indexed by the colours we are using
	this.routeMenuIconURLs = [];	// indexed by the colours we are using
	this.markerIconSets = [];		// we instantiate one of these for each type of icon
									// that has an image URL in the defs.js file
	this.plannerIcons = [];			// two special icons for use in the Route Planning dialog
	
	this.plannerIcons['start'] = new GIcon(G_DEFAULT_ICON, MarkerIcons_path + "dd-start.png");
	this.plannerIcons['finish'] = new GIcon(G_DEFAULT_ICON, MarkerIcons_path + "dd-end.png");

	for (aColor in CCCRouteIconDefs.URLs) { 
		this.routeIcons[aColor] = new GIcon(G_DEFAULT_ICON);
		this.routeIcons[aColor].image = CCCRouteIconDefs.URLs[aColor];
		this.routeIcons[aColor].shadow = CCCRouteIconDefs.shadowURL;
		this.routeIcons[aColor].iconSize = CCCRouteIconDefs.size;
		this.routeIcons[aColor].shadowSize = CCCRouteIconDefs.shadowSize;
		
		this.routeMenuIconURLs[aColor] = CCCRouteIconDefs.keyURLs[aColor];
	}

	for(aMarkerType in CCCInfoMarkerDefs) {
		var markerIconData = CCCInfoMarkerDefs[aMarkerType]; // e.g. the icon data for 'stands' or 'shops'
		for(aMarkerSubType in markerIconData) {
			if (aMarkerSubType.charAt(0) != '_') { // attributes starting with underscore are meta-data
				var subTypeData = markerIconData[aMarkerSubType];	// e.g. Stands.Standard
				
				subTypeData.icon = new GIcon (G_DEFAULT_ICON);
				if (subTypeData.URL) subTypeData.icon.image = subTypeData.URL;
				if (subTypeData.shadowURL) subTypeData.icon.shadow = subTypeData.shadowURL;
				if (subTypeData.size) subTypeData.icon.iconSize = subTypeData.size;
				if (subTypeData.shadowSize) subTypeData.icon.shadowSize = subTypeData.shadowSize;
				if (subTypeData.anchor) subTypeData.icon.iconAnchor = subTypeData.anchor;
			} 
		}
		if (markerIconData['Standard'] == null) { // ensure that there is always a 'Standard' icon.
			markerIconData['Standard'] = object ();
			markerIconData['Standard'].icon = new GIcon (G_DEFAULT_ICON);
		}
		this.markerIconSets[aMarkerType] = markerIconData;
	}
}

CCCInfoMarkerFormDefs = { 
	// there must be an entry for every different type of infoMarker we plan to use
	// fieldnames correspond to DB table columns.
	
	// fields whose names prefixed with '_' are not displayed in the normal info window. 
	// (They are in the editing info window).
	Stands:{
		subTypes:['Standard', 'Secure', 'Covered', 'Secure_Covered', 'Off_Street', 'Famine'],
		fields:{
			'_number':{
				label: 'Number&nbsp;of&nbsp;Stands', 
				field: '<input type="text" name="_number"  value="1" style="width:30px;">',
				validate: function (theField) {
						if(theField.value <= 0 || isNaN(theField.value)) {
							theField.value += '!!';
							 return false;
						}
						else return true;
					}
			},
			'subType':{
				label: 'Type of parking',
				shortLabel: 'Type',
				field:  '<select name = "subType">'
					  + ' <option value = "Standard"> Standard'
					 + '  <option value = "Secure"> Secure'
					  + ' <option value = "Covered"> Covered'
					 + '  <option value = "Secure_Covered"> Secure and Covered'
					 + '  <option value = "Off_Street"> Off street'
					 + ' <option value = "Famine"> Bike stands needed here'
					 + ' </select>'
			},
			'comment':{
				label: '<br>Description',
				shortLabel: 'Description',
				field: 	'<textarea type="textarea" name="comment"' +
					'rows="3" value="" style="width:100%;"></textarea>'
			},
			'_SV_state':{
				// value is generated from the streetview
				label: null,	// indicates that it shouldn't be shown even when editing
				field: '<input type="text" name="_SV_state" readOnly="true" value="" >'		
			},
			'_contributed_by':{
				label: '<br>Contributor',
				field: '<input type="text" name="_contributed_by" readOnly="true" value="" style="width:180px;">'
			},
			'_contributor_id':{
				label: ' Id',
				field: '<input type="text" name="_contributor_id" readOnly="true" value="" style="width:130px;">'
			}
		}
	},
	Shops:{
		fields:{
			'title':{
				label: 'Name&nbsp;of&nbsp;shop',
				field: '<input type="text" name="title" value="" style="width:100%;">'
			},
			'comment':{
				label: '<br>Description',
				shortLabel: 'Description',
				field: 	'<textarea type="textarea" name="comment"' +
					'rows="3" value="" style="width:100%;"></textarea>'
			},
			'address':{
				label: '<br>Address',
				shortLabel: 'Address',
				field: 	'<textarea type="textarea" name="address"' +
					'value="" style="width:100%;"></textarea>'
			},
			'postcode':{
				label: '<br>Postcode',
				shortLabel: 'Postcode',
				field: 	'<input type="text" " name="postcode" value="" style="width:100px;">'
			},
			'phone':{
				label: ' Telephone',
				shortLabel: 'Phone',
				field: 	'<input type="text" name="phone" value="" style="width:150px;">'
			},
			'URL':{
				label: '<br>Web address (URL), if available',
				shortLabel: 'url',
				field: 	'<input type="text" name="URL" value="" style="width:100%;">',
				validate: validURL
			},
			'_SV_state':{
				// value is generated from the streetview
				label: null,	// indicates that it shouldn't be shown even when editing
				field: '<input type="text" name="_SV_state" readOnly="true" value="" >'		
			},
			'_contributed_by':{
				label: '<br>Contributor',
				field: '<input type="text" name="_contributed_by" readOnly="true" value="" style="width:180px;">'
			},
			'_contributor_id':{
				label: ' Id',
				field: '<input type="text" name="_contributor_id" readOnly="true" value="" style="width:130px;">'
			}
		}
	},
	Hazards:{
		fields:{
			'title':{
				label: 'Title',
				field: '<input type="text" name="title" value="" style="width:100%;">'
			},
			'subType':{
				label: '<br>Type of hazard',
				shortLabel: 'Type',
				field:  '<select name = "subType">'
					 + '  <option value = "Roadworks"> Roadworks'
					  + ' <option value = "Dangerspot"> Dangerspot'
					  + ' <option value = "Closure"> Closure'
					  + ' <option value = "Standard"> General'
					 + ' </select>'
			},
			'comment':{
				label: '<br>Description',
				shortLabel: 'Description',
				field: 	'<textarea type="textarea" name="comment"' +
					'rows="3" value="" style="width:100%;"></textarea>'
			},
			'URL':{
				label: '<br>Web link to further info, if available',
				shortLabel: 'url',
				field: 	'<input type="text" name="URL" value="" style="width:100%;"></textarea>',
				validate: validURL
			},
			'_SV_state':{
				// value is generated from the streetview
				label: null,	// indicates that it shouldn't be shown even when editing
				field: '<input type="text" name="_SV_state" readOnly="true" value="" >'		
			},
			'starts':{ // NB there may be some ad hoc code in the infomarkers file to give a better dialog
				label: '<br>Date to make visible: <br>(leave blank for immediately, format: dd-mm-yyyy)',
				shortLabel: 'Begins',
				field: '<input type="text" name="starts" value="">'
			},
			'expires':{ // NB there may be some ad hoc code in the infomarkers file to give a better dialog
				label: '<br>Date to remove: <br>(leave blank for never, format: dd-mm-yyyy)',
				shortLabel: 'Ends',
				field: '<input type="text" name="expires" value="">'
			},
			'contributed_by':{
				label: '<br>Contributor',
				shortLabel: 'Contributor',
				field: '<input type="text" name="contributed_by" readOnly="true" value="" style="width:180px;">'
			},
			'_contributor_id':{
				label: ' Id',
				field: '<input type="text" name="_contributor_id" readOnly="true" value="" style="width:130px;">'
			}
		}
	},
	Consultations:{
		fields:{
			'title':{
				label: 'Title',
				field: '<input type="text" name="title" value="" style="width:100%;">'
			},
			'subType':{
				label: '<br>Status of consultation',
				shortLabel: 'Status',
				field:  '<select name = "subType">'
					 + '  <option value = "Snag"> Snag - not a consultation'
					 + '  <option value = "Pending"> Pending'
					  + ' <option value = "Responded"> Responded to'
					  + ' <option value = "Approved"> Approved by Council'
					  + ' <option value = "Dropped"> Dropped by Council'
					  + ' <option value = "Implemented"> Implemented'
					  + ' <option value = "Audited"> Audited'
					 + ' </select>'
			},
			'authority':{
				label: '<br>Borough or other authority',
				shortLabel: 'Authority',
				field: '<input type="text" name="authority" value="" style="width:30%;">'
			},
			'comment':{
				label: '<br>Description',
				shortLabel: 'Description',
				field: 	'<textarea type="textarea" name="comment"' +
					'rows="3" value="" style="width:100%;"></textarea>'
			},
			'URL':{
				label: '<br>Web link to further info, if available',
				shortLabel: 'url',
				field: 	'<input type="text" name="URL" value="" style="width:100%;"></textarea>',
				validate: validURL
			},
			'_SV_state':{
				// value is generated from the streetview
				label: null,	// indicates that it shouldn't be shown even when editing
				field: '<input type="text" name="_SV_state" readOnly="true" value="" >'		
			},
			'started':{
				label: '<br>Start date: (format: dd-mm-yyyy)',
				shortLabel: 'Begins',
				field: '<input type="text" name="started" value="">'
			},
			'approved':{ 
				label: '<br>Date of approval by Council: (format: dd-mm-yyyy)',
				shortLabel: 'Approved',
				field: '<input type="text" name="approved" value="">'
			},
			'audited':{ 
				label: '<br>Date audited by LCC group: (format: dd-mm-yyyy)',
				shortLabel: 'Audited',
				field: '<input type="text" name="audited" value="">'
			},
			'contributed_by':{
				label: '<br>Contributor',
				shortLabel: 'Contributor',
				field: '<input type="text" name="contributed_by" readOnly="true" value="" style="width:180px;">'
			},
			'_contributor_id':{
				label: ' Id',
				field: '<input type="text" name="_contributor_id" readOnly="true" value="" style="width:130px;">'
			}
		}
	},
	Routes:{	// These markers are used only for editing the information associated with routes. 
				// The Route info markers are handled separately
		fields:{
			'text_id':{
				label: 'text_id',
				field: '<input type="text" name="text_id" value="" style="width:200px;">'
			},
			'id':{
				label: ' #',
				field: '<input type="text" name="id" value="" readOnly="true" style="width:50px;">'
			},
			'title':{
				label: '<br>Title',
				field: 	'<textarea type="textarea" name="title"' +
					'value="" style="width:370px;"></textarea>'
			},
			'menuString':{
				label: '<br>Menu entry',
				field: '<input type="text" name="menuString" value="" style="width:330px;">'
			},
			'description':{
				label: '<br>Description',
				field: 	'<textarea type="textarea" name="description"' +
					'rows="4" value="" style="width:100%;"></textarea>'
			},
			'fileURL':{
				label: '<br>File name',
				field: '<input type="text" name="fileURL" readOnly="true" value="" style="width:40%;">'
			},
			'format':{
				label: ' Format',
				field:  '<select name = "format">'
					 + '  <option value = "KML"> KML'
					  + ' <option value = "GPX"> GPX'
					  + ' </select>'
			},
			'_iconImage':{
				label: '<br>File name for special icon (optional)',
				field: '<input type="text" name="_iconImage" value="" style="width:40%;">'
			},
			'category':{
				label: '<br>Category',
				field:  '<select name = "category">'
					 + '  <option value = "LCN"> LCN'
					 + '  <option value = "NCN"> NCN'
					  + ' <option value = "OtherLCN"> OtherLCN'
					  + ' <option value = "Park"> Park'
					  + ' <option value = "ParkProposed"> ParkProposed'
					  + ' <option value = "RouteProposed"> RouteProposed'
					  + ' <option value = "School"> School'
					  + ' <option value = "Utility"> Utility'
					  + ' <option value = "Leisure"> Leisure'
					  + ' <option value = "Pending"> Pending installation'
					  + ' </select>'
			},
			'subcat':{
				label: ' Sub-category',
				field: '<input type="text" name="subcat" value="Pending" style="width:30%;">'
			},
			'district':{
				label: '<br>District (for information only)',
				field: '<input type="text" name="district" value="" style="width:40%;">'
			},
			'onOSM':{
				label: ' onOSM',
				field:  '<select name = "onOSM">'
					  + ' <option value = 0> No'
					 + '  <option value = 1> Yes'
					  + ' </select>'
			},
			'links':{
				label: '<br>Relevant web address (URL), if available',
				field: '<input type="text" name="links" value="" style="width:100%;">',
				validate: validURL
			},
			'contributed_by':{
				label: '<br>Contributor',
				field: '<input type="text" name="contributed_by" readOnly="true" value="" style="width:180px;">'
			},
			'_contributor_id':{
				label: ' Id',
				field: '<input type="text" name="_contributor_id" readOnly="true" value="" style="width:130px;">'
			}
		},
		options: {
			hasNoLocation: true
		}
	},
	RouteMarkers:{	// These are 'waymarkers' for adding extra information associated with routes
		fields:{
			'title':{
				label: 'Title',
				field: '<input type="text" name="title" value="" style="width:100%;">'
			},
			'comment':{
				label: '<br>Comment',
				field: 	'<textarea type="textarea" name="comment"' +
					'rows="3" value="" style="width:100%;"></textarea>'
			},
			'text_id':{
				label: '<br>text_id of the associated route',
				field: 	'<input type="text" name="text_id" value="" style="width:100%;"></textarea>'
			},
			'URL':{
				label: '<br>Web link to further info, if available',
				field: 	'<input type="text" name="URL" value="" style="width:100%;"></textarea>',
				validate: validURL
			},
			'_SV_state':{
				// value is generated from the streetview
				label: null,	// indicates that it shouldn't be shown even when editing
				field: '<input type="text" name="_SV_state" readOnly="true" value="" >'		
			},
			'starts':{ // NB there may be some ad hoc code in the infomarkers file to give a better dialog
				label: '<br>Date to make visible: <br>(leave blank for immediately, format: dd-mm-yyyy)',
				field: '<input type="text" name="starts" value="">'
			},
			'expires':{ // NB there may be some ad hoc code in the infomarkers file to give a better dialog
				label: '<br>Date to remove: <br>(leave blank for never, format: dd-mm-yyyy)',
				field: '<input type="text" name="expires" value="">'
			},
			'contributed_by':{
				label: '<br>Contributor',
				field: '<input type="text" name="contributed_by" readOnly="true" value="" style="width:180px;">'
			},
			'_contributor_id':{
				label: ' Id',
				field: '<input type="text" name="_contributor_id" readOnly="true" value="" style="width:130px;">'
			}
		}
	},
	HireStations:{
		fields:{
			'title':{
				label: 'Short name',
				field: '<input type="text" name="title" value="" style="width:100%;">'
			},
			'StationNo':{
				label: 'Station number',
				field: '<input type="text" name="StationNo" value="" style="width:30px;">'
			},
			'number':{
				label: 'Number&nbsp;of&nbsp;Positions', 
				field: '<input type="text" name="number"  value="14" style="width:30px;">',
				validate: function (theField) {
						if(theField.value <= 0 || isNaN(theField.value)) {
							theField.value += '!!';
							 return false;
						}
						else return true;
					}
			},
			'comment':{
				label: '<br>Description',
				shortLabel: 'Description',
				field: 	'<textarea type="textarea" name="comment"' +
					'rows="3" value="" style="width:100%;"></textarea>'
			},
			'URL':{
				label: '<br>Web link to further info, if available',
				shortLabel: 'url',
				field: 	'<input type="text" name="URL" value="" style="width:100%;"></textarea>',
				validate: validURL
			},
			'_SV_state':{
				// value is generated from the streetview
				label: null,	// indicates that it shouldn't be shown even when editing
				field: '<input type="text" name="_SV_state" readOnly="true" value="" >'		
			},
			'_contributed_by':{
				label: '<br>Contributor',
				field: '<input type="text" name="_contributed_by" readOnly="true" value="" style="width:180px;">'
			},
			'_contributor_id':{
				label: ' Id',
				field: '<input type="text" name="_contributor_id" readOnly="true" value="" style="width:130px;">'
			}
		}
	}

}

function validURL(aField) {
	var value = aField.value.toLowerCase();
	if (value && value.indexOf('http://') < 0 ) aField.value = 'http://' + aField.value;
	return true;
}

var editing_allowed = false;  	// true when editing is allowed, 
								// (set in CCCfunctions based on presence of the "edit_form_div")

/* Camden bounding rectangle: */
CamdenBoundRect = {
	West:	-0.213203,
	North:	51.5732,
	East:	-0.105143,
	South:	51.5121
}

/* London bounding rectangle (M25): */
LondonBoundRect = {
 West:	-0.543823,
 North:	51.7168,
 East:	-0.138915,
 South:	51.2568
 }

 CamdenRect = new GLatLngBounds(new GLatLng(CamdenBoundRect.South, CamdenBoundRect.West), 
 										new GLatLng(CamdenBoundRect.North, CamdenBoundRect.East));
  
 LondonRect = new GLatLngBounds(new GLatLng(LondonBoundRect.South, LondonBoundRect.West), 
 										new GLatLng(LondonBoundRect.North, LondonBoundRect.East));
 
 
