//	XmlHttpRequest.prototype.param = null;
//	GXmlHttp.prototype.param = null;
	GMarker.prototype.name = "";
	GMarker.prototype.address = "";
	GMarker.prototype.id = 0;
	GMarker.prototype.type=0;
	GMarker.prototype.nickname="";
	GMarker.prototype.info="";
	GMarker.prototype.stamp="";
	GMarker.prototype.showInfo = function()
	{
		this.openInfoWindowHtml( 
		"<table border=0><tr bgcolor='#0000FF'><th><font color='#FFFFFF'>" + this.name + "</th></tr>" +
		"<tr><td bgcolor='#CCFFFF'>" + this.address + "</td></tr>" +
		"<tr><td bgcolor='#CCFFFF'>" + types[this.type] + "</td></tr>" +
		"<tr><td bgcolor='#CCFFFF'>" + this.info + "</td></tr>"+
		"<tr><td bgcolor='#FFFFFF' align='right'><font color='#808080' size='1'>By " + this.nickname + 
		"&nbsp;&nbsp;"+this.stamp+"</font></td></tr>"+
		"<tr><td bgcolor='#FFFFFF'><font size='2'><a href='javascript:map.closeInfoWindow()'>Close</a>&nbsp;"+
		"<a href='javascript:markers.showedit("+this.id+");'>Edit</a></font></td></tr>"+
		"</table>"
		 );
	}
	GMarker.prototype.showedit = function()
	{
		this.openInfoWindowHtml( getPointMenu( this.getPoint(),13,this.address,this,"edit") );
		//alert( this.info.replace(/<a href="(.*)">.*<\/a>/g,"$1").replace(/<br>/g,"") );
	}
	
	function Markers(map)
	{
		this.points = new Array();
		this.bounds = null;
		this.updateBounds(map);
		this.showpoint=0;
//		this.getNewPoints(map);
		return this;
	}

	Markers.prototype.updateBounds = function(map)
	{
		a = 1.5/2;
		
		ctr = map.getCenter();
		sz = map.getBounds().toSpan();
		
		sw = new GLatLng( ctr.lat()-sz.lat()*a, ctr.lng()-sz.lng()*a, false);
		ne = new GLatLng( ctr.lat()+sz.lat()*a, ctr.lng()+sz.lng()*a, false);
		this.bounds = new GLatLngBounds(sw,ne);
	}

	Markers.prototype.parse=function(text)
	{
		line=text.split("<$>");
		for(i in line)
		{
			fields = line[i].split("<>");
			if( fields.length > 2 )
			{
				id = parseInt( fields[0] );
				if( this.points[id] )
				{
					this.points[id].name = fields[1];
					this.points[id].address = fields[4];
					this.points[id].type=fields[5];
					this.points[id].id = id;
					this.points[id].info = fields[6];
					this.points[id].nickname = fields[7];
					this.points[id].stamp = fields[8];
				}
				else
				{
					point = new GPoint( fields[2], fields[3] );
					marker = new GMarker(point,icons[parseInt(fields[5])]);
					marker.name = fields[1];
					marker.address = fields[4];
					marker.id = parseInt(fields[0]);
					marker.type=fields[5];
					marker.info = fields[6];
					marker.nickname = fields[7];
					marker.stamp = fields[8];
					
					this.points[ marker.id ] = marker;
					map.addOverlay( marker );
				}
			}
		}
		this.showtypeall();
		if( this.showpoint > 0 )
		{
			if( this.points[ this.showpoint ] )
			{
				this.points[ this.showpoint ].showInfo();
				showComments( this.showpoint );
				this.showpoint = 0;
			}
		}
		//this.show();
	}
/*
	Markers.prototype.show=function()
	{
		//map.clearOverlays();
		for(id in this.points)
		{
			map.addOverlay( this.points[id] );
			GEvent.addListener(map,"mouseover",function(marker)
			{
				if( marker )
					if( marker.type > 0 )
						marker.show();
			});
		}
	}
*/
	Markers.prototype.remove = function()
	{
		for(id in this.points)
		{
			if( ! this.bounds.contains( this.points[id].getPoint() ) )
			{
				map.removeOverlay( this.points[id] );
				delete this.points[id];
				continue;
			}
		}
	}
	
	Markers.prototype.checkDepart = function(map)
	{
		if( !this.bounds.containsBounds( map.getBounds() ) )
		{
			this.updateBounds(map);
			this.remove();
//			document.getElementById('debug').innerHTML = ":";
//			for( id in this.points)
//			{
//				document.getElementById( 'debug' ).innerHTML += this.points[id].id + " ";
//			}
			this.getNewPoints();
			return true;
		}
		return false;
	}

	Markers.prototype.getNewPoints = function()
	{
		document.getElementById('signal').innerHTML="<font color='red'>[Access]</font>"+zoom;
		var request= GXmlHttp.create();
		var url="ajx_getpoints.php?minx="+this.bounds.getSouthWest().lng()+"&miny="+this.bounds.getSouthWest().lat()+"&maxx="+this.bounds.getNorthEast().lng()+"&maxy="+this.bounds.getNorthEast().lat();
		request.open("GET",url, true);
		request.onreadystatechange = function()
		{
			if( request.readyState == 4 )
			{
				document.getElementById('signal').innerHTML="";
				if( markers )
					markers.parse( request.responseText );
/*				for( id in markers.points )
				{
					document.getElementById( 'debug' ).innerHTML += markers.points[id].id+" ";
				}
*/			}
		}
		request.send(null);
	}
	Markers.prototype.showedit = function(id)
	{
		this.points[id].showedit();
	}

	Markers.prototype.showtype = function(type,flg)
	{
		for(id in this.points)
		{
			if( this.points[id].type == type )
			{
				if( flg==true )
					this.points[id].show();
				else
					this.points[id].hide();
			}
		}
	}
	
	Markers.prototype.showtypeall = function()
	{
		for(id in this.points)
		{
			if( document.getElementById('cb_legend_'+this.points[id].type) )
			{
				flg = document.getElementById('cb_legend_'+this.points[id].type).checked;
				if( flg )
					this.points[id].show();
				else
					this.points[id].hide();
			}
		}
	}

