﻿function updateMarkers() {
//remove the existing points
map.clearOverlays();
//create the boundary for the data
var bounds = map.getBounds();
var southWest = bounds.getSouthWest();
var northEast = bounds.getNorthEast();
var getVars = 'ne=' + northEast.toUrlValue() + '&sw=' + southWest.toUrlValue()
//log the URL for testing
//GLog.writeUrl('getmarkers.php?'+getVars);
//retrieve the points using Ajax
var request = GXmlHttp.create();
request.open('GET', 'getmarkers.php?'+getVars, true);
request.onreadystatechange = function() {
if (request.readyState == 4) {
var jscript = request.responseText;
var points;
eval(jscript);
//create each point from the list

 for (i=1; i<=38; i++) {$("#oIcon" + i + "c").removeAttr("checked"); $("#oIcon" + i + "c").attr("disabled", "1");}
 

                    for (i in points) {
									
									
						
                                    var point = new GLatLng(points[i].lat,points[i].lng);
                                    
                                    var marker = createMarker(point, points[i].topic, points[i].placeid , points[i].cat, points[i].catname, points[i].dist);
									//alert(points[i].cat.categorim);
                                    map.addOverlay(marker);
									idstocheck = points[i].cat.categorim;
									$("#" + idstocheck).attr("checked", "1");
									$("#" + idstocheck).removeAttr("disabled");
								     }


         }
}

request.send(null);
}


function createMarker(point, markertitle, markerpid, cat, catname, dist) {

var marker = new GMarker(point, { icon:cat});

GEvent.addListener(marker,'mouseover',function() {
marker.openToolTip(markertitle);
}); 

GEvent.addListener(marker,'mouseout',function() {
marker.closeToolTip();
});

GEvent.addListener(marker,'click',function() {
$('div[class=mapinfo]').html("<img  align='left' style='padding:0 3px 10px 0' src='images/in.png'><a class='maplnk' href='sunum.php?pid=" + markerpid + "'>" + markertitle + "</a><br /><span style='line-height:18px;color:#777;font-weight:normal;'>Kategori: " + catname + "</span>");
}); 


marker.mycat = cat.categorim; 
//marker.myname = "p" + markerpid;                                 
gmarkers.push(marker);
return marker;
}



function calistir(cbox) {
		var thename = $(cbox).attr('id');
		//alert(thename);
		//document.getElementById("err").innerHTML = thename;
    if (cbox.checked) 	{ 
							//$(thename).removeAttr("disabled");
							$("#" + thename).attr("checked", "1");
									for (i=0; i<gmarkers.length; i++) {
											if (gmarkers[i].mycat == thename) gmarkers[i].show(); 
									}
						}
						
	else  				{ 
							//$(thename).attr("disabled", "gfgdasd"); 
							$("#" + thename).removeAttr("checked");
									for (i=0; i<gmarkers.length; i++) {
											if (gmarkers[i].mycat == thename) gmarkers[i].hide();
 									}
						}
};






//create the ToolTip overlay object
function ToolTip(marker,html,width) {
this.html_ = html;
this.width_ = (width ? width + 'px' : 'auto');
this.marker_ = marker;
}
ToolTip.prototype = new GOverlay();
ToolTip.prototype.initialize = function(map) {
var div = document.createElement("div");
div.style.display = 'none';
map.getPane(G_MAP_FLOAT_PANE).appendChild(div);
this.map_ = map;
this.container_ = div;
}
ToolTip.prototype.remove = function() {
this.container_.parentNode.removeChild(this.container_);
}

ToolTip.prototype.copy = function() {
return new ToolTip(this.html_);
}
ToolTip.prototype.redraw = function(force) {
if (!force) return;
var pixelLocation = this.map_.fromLatLngToDivPixel(this.marker_.getPoint());
this.container_.innerHTML = this.html_;
this.container_.style.position = 'absolute';
this.container_.style.left = pixelLocation.x + "px";
this.container_.style.top = pixelLocation.y + "px";
this.container_.style.width = this.width_;
this.container_.style.font = 'bold 10px/10px Tahoma, sans-serif';
this.container_.style.color = '#3b5998';
this.container_.style.border = '2px solid #f7f7f7';
this.container_.style.background = '#fff';
this.container_.style.padding = '5px';
//one line to desired width
this.container_.style.whiteSpace = 'nowrap';
if(this.width_ != 'auto') this.container_.style.overflow = 'hidden';
this.container_.style.display = 'block';
}
GMarker.prototype.ToolTipInstance = null;
GMarker.prototype.openToolTip = function(content) {
//don't show the tool tip if there is a custom info window
if(this.ToolTipInstance == null) {
this.ToolTipInstance = new ToolTip(this,content)
map.addOverlay(this.ToolTipInstance);
}
}
GMarker.prototype.closeToolTip = function() {
if(this.ToolTipInstance != null) {
map.removeOverlay(this.ToolTipInstance);
this.ToolTipInstance = null;
}
}
//harita içinde sabit alan- reklam vs.
var PromoControl = function(url) {
this.url_ = url;
};
PromoControl.prototype = new GControl(true);
PromoControl.prototype.initialize = function(map) {
var container = document.createElement("div");
$(container).attr('class', 'mapinfo');
$(container).html("<img align='left' style='padding-right:3px;' src='images/in.png'>Noktaların Üzerine Gelin ve Tıklayın!");
container.style.width='230px';
container.style.height='26px';
container.style.background='#fff';
container.style.padding='5px';

url = this.url_;
// dive komple link GEvent.addDomListener(container, "click", function() {document.location = url;});
map.getContainer().appendChild(container);
return container;
};
PromoControl.prototype.getDefaultPosition = function() {
return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(0, 0));
};
//harita içinde sabit alan- reklam vs.