	window.addEvent('domready', function() {
		var message = $$('#confirm');
		message.each(function(msg) {
			var fx = new Fx.Styles(msg, {duration:3000, wait:false, transition: Fx.Transitions.Sine.easeInOut});
			fx.start({'opacity': [0.9, 0], 'height': 0});
		});
	});

	function newCategory(cat) {
		var hidden = $$('.category');
		hidden.each(function(hide) {
			hide.addClass('hide');
		});
		$('cat_name').disabled = true;
		$('cat_name').removeClass('required');
		if (cat.options[cat.options.selectedIndex].value == 0) {
			hidden.each(function(hide) {
				hide.removeClass('hide');
			});
			$('cat_name').disabled = false;
			$('cat_name').addClass('required');
		}
	}
	
	function addOptions(elm, obj) {

		for (var count = elm.options.length-1; count >= 0; count--)
			elm.options[count] = null;
	
		obj.each(function(optn) {
			//var optionItem = new Option(optn.name, optn.id, false, false);
			var item = new Element('option').setHTML(optn.name);
			item.value = optn.id;
			item.inject(elm);
		});	
	}
	
	function startDrawing(poly, name, onUpdate, color) {
		map.addOverlay(poly);
		poly.enableEditing({onEvent: "mouseover"});
		poly.disableEditing({onEvent: "mouseout"});
		poly.show();
		GEvent.addListener(poly, "lineupdated", function(latlng, index) {
			createVertices(poly, name);
		});
		GEvent.addListener(poly, "endline", function() {
			if (formVal) {
				formVal.reset();
				formVal.ignoreField(name+'_added');
			}
			GEvent.addListener(poly, "click", function(latlng, index) {
				if (typeof index == "number") {
					poly.deleteVertex(index);
				} 
				else
					createVertices(poly, name);
			});

		});
	}
	
	function createVertices(poly, name) {
		// Get all existing hidden vars and delete
		var vertices = $('holes').getElements('.vertex'+name);
		vertices.each(function(vertex) { 
			vertex.destroy();
		});

		// Loop the points, encode into nasty hidden variable
		var vcount = poly.getVertexCount();
		for (var i =0; i < vcount; i++) {
			var vertex = poly.getVertex(i);
			var lon = vertex.lng();
			var lat = vertex.lat();
			
			// Now add the new
			var hidden = new Element('input', {'type': 'hidden', 'class': 'vertex'+name, 'name': name+'_vertices[]', 'id': 'vertex_'+i, 'value': lon+','+lat});
			hidden.inject('holes', 'inside');
		}
	}

