function ValidateComment() {
	var isValid = true;

	var inputName = document.getElementById('id_name');
	var spanNameReq = document.getElementById('spanNameReq');
	var inputEmail = document.getElementById('id_email');
	var spanEmailReq = document.getElementById('spanEmailReq');
	var spanEmailInvalid = document.getElementById('spanEmailInvalid');
	var inputWebsite = document.getElementById('id_website');
	var spanWebsiteInvalid = document.getElementById('spanWebsiteInvalid');
	var inputComment = document.getElementById('id_comment');
	var spanCommentReq = document.getElementById('spanCommentReq');
	
	if (inputName.value.length == 0)
	{
		spanNameReq.style.display = '';
		isValid = false;
	}
	else
	{
		spanNameReq.style.display = 'none';
	}

	if (inputEmail.value.length == 0)
	{
		spanEmailReq.style.display = '';
		isValid = false;
		
		spanEmailInvalid.style.display = 'none';
	}
	else
	{
		spanEmailReq.style.display = 'none';

		var filter = new RegExp('^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$');
		if (!filter.test(inputEmail.value))
		{
			spanEmailInvalid.style.display = '';
			isValid = false;
		}	
		else
		{
			spanEmailInvalid.style.display = 'none';
		}
	}
		
	if (inputComment.value.length == 0)
	{
		spanCommentReq.style.display = '';
		isValid = false;
	}
	else
	{
		spanCommentReq.style.display = 'none';
	}
	
	if (inputWebsite.value.length > 0)
	{
		var filter = new RegExp('^(https?://)?[a-zA-Z0-9.-/]+\.[a-zA-Z]{2,4}$');
		if (!filter.test(inputWebsite.value))
		{
			spanWebsiteInvalid.style.display = '';
			isValid = false;
		}	
		else
		{
			spanWebsiteInvalid.style.display = 'none';
		}
	}
	
	return isValid;
}

function MarkersLayer(opt) {
	this.setValues(opt);
	
	this.markerPos = [];
	this.activeMarkerId = -1;
};
MarkersLayer.prototype = new google.maps.OverlayView;

MarkersLayer.prototype.onAdd = function() {
	var pane = this.getPanes().overlayLayer;
	
	this.canvas = document.createElement('canvas');
	pane.appendChild(this.canvas);
	if (typeof G_vmlCanvasManager != 'undefined') 
        this.canvas = G_vmlCanvasManager.initElement(this.canvas);		
	this.canvas.style.left = '0px';
	this.canvas.style.top = '0px';
	this.canvas.width = this.width;
	this.canvas.style.width = this.canvas.width;
	this.canvas.height = this.height;
	this.canvas.style.height = this.canvas.height;
	this.canvas.style.position = 'absolute';
	
	this.canvasTooltip = document.createElement('canvas');
	pane.appendChild(this.canvasTooltip);
	if (typeof G_vmlCanvasManager != 'undefined') 
        this.canvasTooltip = G_vmlCanvasManager.initElement(this.canvasTooltip);
	this.canvasTooltip.style.left = '0px';
	this.canvasTooltip.style.top = '0px';
	this.canvasTooltip.width = this.tooltipWidth;
	this.canvasTooltip.style.width = this.canvasTooltip.width;
	this.canvasTooltip.height = this.tooltipHeight;
	this.canvasTooltip.style.height = this.canvasTooltip.height;
	this.canvasTooltip.style.position = 'absolute';
	this.canvasTooltip.style.display = 'none';
};

MarkersLayer.prototype.onRemove = function() {
	this.canvas.parentNode.removeChild(this.canvas);
	
	google.maps.event.removeListener(this.listener);
};

MarkersLayer.prototype.draw = function() {
	var projection = this.getProjection();
	if (projection != null) {
		var mapBounds = this.map.getBounds();
		var posNE = projection.fromLatLngToDivPixel(mapBounds.getNorthEast());
		var posSW = projection.fromLatLngToDivPixel(mapBounds.getSouthWest());
		
		this.canvas.style.left = (posSW != null ? posSW.x : 0) + 'px';
		this.canvas.style.top = (posNE != null ? posNE.y : 0) + 'px';
				
		var dctx = this.canvas.getContext('2d');
		dctx.clearRect(0, 0, this.canvas.width, this.canvas.height);			
		for (var i = 0; i < this.markerPos.length; i++) {
			if (this.markerPos[i] != null) {
				if (mapBounds.contains(this.markerPos[i].latLng)) {
					var markerDivPos = projection.fromLatLngToDivPixel(this.markerPos[i].latLng);
					dctx.fillStyle = (i == 0 ? 'rgba(160,160,160,1)' : 'rgba(127,211,88,1)');
					dctx.beginPath();
					dctx.arc(markerDivPos.x - posSW.x,markerDivPos.y - posNE.y,this.markerRadius,0,Math.PI*2,true);
					dctx.fill();
					dctx.fillStyle = 'rgba(0,0,0,1)';
					dctx.beginPath();
					dctx.arc(markerDivPos.x - posSW.x,markerDivPos.y - posNE.y,this.markerRadius,0,Math.PI*2,true);
					dctx.stroke();
					this.markerPos[i].visible = true;
				}
				else {
					this.markerPos[i].visible = false;
				}
			}
		}
	}
};

MarkersLayer.prototype.onMouseover = function(e) {
	var projection = this.getProjection();
	var mouseDivPos = projection.fromLatLngToDivPixel(e.latLng);
	var halfRadius = this.markerRadius / 2;
	var mapBounds = this.map.getBounds();
	var posNE = projection.fromLatLngToDivPixel(mapBounds.getNorthEast());
	var posSW = projection.fromLatLngToDivPixel(mapBounds.getSouthWest());
	for (var i = this.markerPos.length; i > 0; i--) {
		if (this.markerPos[i] != null && this.markerPos[i].visible) {
			var markerDivPos = projection.fromLatLngToDivPixel(this.markerPos[i].latLng);
			
			if (mouseDivPos.x >= (markerDivPos.x - halfRadius) &&
				mouseDivPos.x <= (markerDivPos.x + halfRadius) && 
				mouseDivPos.y >= (markerDivPos.y - halfRadius) &&
				mouseDivPos.y <= (markerDivPos.y + halfRadius))
			{
				if (this.activeMarkerId < 0) {
					this.canvasTooltip.style.left = (markerDivPos.x + 20) + 'px';
					this.canvasTooltip.style.top = (markerDivPos.y - 25) + 'px';
					
					var dctx = this.canvasTooltip.getContext('2d');
					dctx.clearRect(0, 0, this.canvasTooltip.width, this.canvasTooltip.height);
					dctx.fillStyle = 'rgba(255,255,255, 0.7)';
 					dctx.fillRect (0, 0, this.canvasTooltip.width, this.canvasTooltip.height);
					var img = new Image();
					img.onload = function(){
						dctx.drawImage(img, 0, 0);
					};
					img.src = this.markerPos[i].thumbUrl;
					
					this.canvas.style.cursor = 'pointer';
					this.canvasTooltip.style.display = 'block';					
					this.activeMarkerId = this.markerPos[i].id;
				}
				
				return;
			}
		}
	}
	
	this.canvas.style.cursor = '';
	this.canvasTooltip.style.display = 'none';
	this.activeMarkerId = -1;
};

MarkersLayer.prototype.onClick = function() {
	if (this.activeMarkerId > 0) {
		document.location.href = '/' + this.activeMarkerId + '/';
	}
};

MarkersLayer.prototype.onEditClick = function(e) {
	this.addMarkerPos(0, e.latLng.lat(), e.latLng.lng(), '');
	this.draw();
	
	if (this.editLatId != null)
		$('#' + this.editLatId).val(e.latLng.lat());
	if (this.editLonId != null)
		$('#' + this.editLonId).val(e.latLng.lng());	
};

MarkersLayer.prototype.addMarkerPos = function(id, lat, lon, thumbUrl) {
	var latLng = new google.maps.LatLng(lat, lon);
	this.markerPos[id] = { id:id, latLng:latLng, thumbUrl:thumbUrl };
}