var myBounds;

function loadSearchMapWithboundingbox(north,south,west,east){
  if (GBrowserIsCompatible()) {
    map = new GMap2(document.getElementById("googlemapmap"));
	map.addControl(new GLargeMapControl ());
	map.addControl(new GMapTypeControl());
	map.addControl(new GOverviewMapControl ());
	map.addControl(new AddToovControl());
	
	var swlat=parseFloat(south);//south
	var swlong=parseFloat(west);//west		
	
	var nelat=parseFloat(north);//north
	var nelong=parseFloat(east);//east
	var latlang=new GLatLng((swlat+nelat)/2,(swlong+nelong)/2);
	map.setCenter(latlang); 
	map.setZoom(map.getBoundsZoomLevel(new GLatLngBounds(new GLatLng(swlat,swlong),new GLatLng(nelat,nelong)))); 
	map.setMapType( G_SATELLITE_MAP );
	
	GEvent.addListener(map, 'mousemove', onmousemove); 
	GEvent.addListener(map, 'click', onmouseclick); 
	GEvent.addListener(map, "dragend", onmapdrag);
	GEvent.addListener(map, "moveend", onmapdrag);
	GEvent.addListener(map, "zoomend", onzoom);
	GEvent.addListener(map, "onresize", onresize);//werkt niet in IE KUT IE TOCH OOK ALTIJD
	ewindow = new EWindow(map, E_STYLE_7); 		
	map.addOverlay(ewindow);
  }
}


function loadSearchMapWithStartpoint(startlat,startlong,height) {
  if (GBrowserIsCompatible()) {
    map = new GMap2(document.getElementById("googlemapmap"));
	map.addControl(new GLargeMapControl ());
	map.addControl(new GMapTypeControl());
	map.addControl(new GOverviewMapControl ());
	map.addControl(new AddToovControl());
	if(height<=0)height=6;	
	map.setCenter(new GLatLng(startlat, startlong),height);
	
	map.setMapType( G_SATELLITE_MAP );


	GEvent.addListener(map, 'mousemove', onmousemove); 
	GEvent.addListener(map, 'click', onmouseclick); 	
	GEvent.addListener(map, "dragend", onmapdrag);
	GEvent.addListener(map, "moveend", onmapdrag);
	GEvent.addListener(map, "zoomend", onzoom);
	GEvent.addListener(map, "onresize", onresize);//werkt niet in IE
	ewindow = new EWindow(map, E_STYLE_7); 		
	map.addOverlay(ewindow);
  }
}
/*
var selectedLocationSimple = function (val){
	// create ajax request
	var country=document.getElementById('LT_country').value;
	if(!val) return ;
	if(!country)return ;
	var url = "includes/ajax/coordinates.php?country="+encodeURIComponent(country)+"&input="+encodeURIComponent(val);

	var meth = "get";
	var onSuccessFunc = function (req) {
		var xml = req.responseXML;
		var els = xml.getElementsByTagName("rs");
		if(els.length==4){// dan hebben we alle params
			var direction_lat=els[0].firstChild.nodeValue;
			var direction_long=els[1].firstChild.nodeValue;
			waitoverride=true;
			if(els[2].firstChild){
				var dec_lat=els[2].firstChild.nodeValue;
				var dec_long=els[3].firstChild.nodeValue;
				
				if(direction_lat=="S"){
					dec_lat=dec_lat*-1;
				}else{

				}

				if(direction_long=="E"){
					dec_long=dec_long*-1;
				}
			}
			
			
			disablesearch=true;
			map.setCenter(new GLatLng(dec_lat, dec_long),11);
			addwritetodiv("add","searchwithwait", 'BLABLA');
			setTimeout('searchwithwait()',1000);		

		}

	};
	var onErrorFunc = function (status) { alert("AJAX error: "+status); };

	var myAjax = new _bsn.Ajax;
	myAjax.makeRequest( url, meth, onSuccessFunc, onErrorFunc );
};

*/

function onmapdrag(){
	resetoffset();
	performsearch();
}
function onresize(){
	resetoffset();
	performsearch();
}
function onzoom(){
	resetoffset();
	setTimeout('performsearch()',1000);//express timeout hack omdat de map niet ver genoeg is uitgezoomd en daardoor search results niet kloppen	
}

var lastsearchperformed=0;
function performcleansearch(){
	ewindow.hide();
	//removeToOldMarkers();
	document.getElementById('id').value="";
	document.getElementById('cat').value="";
	lastsearchperformed=0;
	performsearch();
}

function resetoffset(){
	document.getElementById('offset').value=0;
}


function performsearch(){
	var d = new Date();
	var url;
	if(lastsearchperformed>0 && d.getTime()-lastsearchperformed<1000){
		return ;
	}
	addwritetodiv("add","search start", 'BLABLA');
	lastsearchperformed=d.getTime();

	var northeast=map.getBounds().getNorthEast();
	var southwest=map.getBounds().getSouthWest();

	var northbounds=northeast.lat();
	var eastbounds=northeast.lng();
	var southbounds=southwest.lat();
	var westbounds=southwest.lng();
	var offset=document.getElementById('offset').value;
	var showid=document.getElementById('showid').value;
	if(document.getElementById('tags_hidden')){ //assume its the standard search
		var cat=document.getElementById('cat').value;
		var id=document.getElementById('id').value;		
		var language=document.getElementById('language').options[document.getElementById('language').selectedIndex].value;
		var channel=document.getElementById('channel').options[document.getElementById('channel').selectedIndex].value;
		var tags=document.getElementById('tags_hidden').value;
		
		var startmonth=document.getElementById('startmonth').options[document.getElementById('startmonth').selectedIndex].value;
		var startyear=document.getElementById('startyear').options[document.getElementById('startyear').selectedIndex].value;
		var endmonth=document.getElementById('endmonth').options[document.getElementById('endmonth').selectedIndex].value;
		var endyear=document.getElementById('endyear').options[document.getElementById('endyear').selectedIndex].value;
		

		var location=document.getElementById('LT_location').value;
		var selectedcountryid=document.getElementById('countryselect').options[document.getElementById('countryselect').selectedIndex].value;
		
		url = "includes/ajax/search.php?northbounds="+encodeURIComponent(northbounds)+"&southbounds="+encodeURIComponent(southbounds)+"&westbounds="+encodeURIComponent(westbounds)+"&eastbounds="+encodeURIComponent(eastbounds)+"&showid="+encodeURIComponent(showid)+"&language="+encodeURIComponent(language)+"&channel="+encodeURIComponent(channel)+"&tags="+encodeURIComponent(tags)+"&offset="+encodeURIComponent(offset)+"&id="+encodeURIComponent(id)+"&cat="+encodeURIComponent(cat)+"&startmonth="+startmonth+"&startyear="+startyear+"&endmonth="+endmonth+"&endyear="+endyear+"&location="+encodeURIComponent(location)+"&selectedcountryid="+selectedcountryid;
	}else{//we are probably on the tag page :)
		var selecttagid=document.getElementById("tagid").value;

		url = "includes/ajax/search.php?northbounds="+encodeURIComponent(northbounds)+"&southbounds="+encodeURIComponent(southbounds)+"&westbounds="+encodeURIComponent(westbounds)+"&eastbounds="+encodeURIComponent(eastbounds)+"&offset="+encodeURIComponent(offset)+"&showid="+encodeURIComponent(showid)+"&tagid="+encodeURIComponent(selecttagid);
	}

	var pointer = this;
	// create ajax request
	var onSuccessFunc = function (req) {
		    removeToOldMarkers();
		    myBounds = new GLatLngBounds();
			var xml = req.responseXML;
			var entrylist="";
			writetodiv("", 'resultentrylist');
			writetodiv("","pageturner");
			writetodiv("","numsearchresults");
			removeOutOfBoundMakers();
			var numresults=0;
			if(xml.getElementsByTagName('results').length>0){
				var results = xml.getElementsByTagName('results')[0].childNodes;				
				if(results.length>0){
					
					var rs = xml.getElementsByTagName('rs');
					var info = xml.getElementsByTagName('info');
					numresults=info[0].getElementsByTagName('numresults')[0].childNodes[0].nodeValue;
					
					var searchresultstring=info[0].getElementsByTagName('searchresultstring')[0].childNodes[0].nodeValue;
					//alert(searchresultstring);
					
				
					sethreflink("http://www.toovs.com/search.php?sset="+searchresultstring+"","linktothispage");
					for(var i=0;i<rs.length;i++){// we have coords for this country

						var title=rs[i].getElementsByTagName('title')[0].childNodes[0].nodeValue;
						var description=rs[i].getElementsByTagName('description')[0].childNodes[0].nodeValue;
						var displayname=rs[i].getElementsByTagName('displayname')[0].childNodes[0].nodeValue;
						var type=rs[i].getElementsByTagName('type')[0].childNodes[0].nodeValue;
						var creationdate=rs[i].getElementsByTagName('creationdate')[0].childNodes[0].nodeValue;
						var image=rs[i].getElementsByTagName('image')[0].childNodes[0].nodeValue;
						var printable_name=rs[i].getElementsByTagName('printable_name')[0].childNodes[0].nodeValue;
						var ownerid=rs[i].getElementsByTagName('ownerid')[0].childNodes[0].nodeValue;
						var xpos=rs[i].getElementsByTagName('xpos')[0].childNodes[0].nodeValue;
						var ypos=rs[i].getElementsByTagName('ypos')[0].childNodes[0].nodeValue;
						var preferredmediaisvideo=rs[i].getElementsByTagName('preferredmediaisvideo')[0].childNodes[0].nodeValue;
						var toovid=rs[i].getElementsByTagName('id')[0].childNodes[0].nodeValue;
						var opentextbox=rs[i].getElementsByTagName('opentextbox')[0].childNodes[0].nodeValue;

						entrylist+="<div id='searchresultentry"+toovid+"' class='entry' onmouseover=\"selectitemonmap('"+toovid+"','over','"+addslashes(title)+"')\" onmouseout=\"selectitemonmap('"+toovid+"','out','')\">"+
							"<div class='imgbox'>"+
								"<div class='inner'>"+
									"<a href='toov.php?id="+toovid+"'><img src='"+image+"' width='114' height='83' alt='"+title+"' /></a>";

						if(preferredmediaisvideo=="1")	entrylist+="<div class='video'></div>";

							entrylist+="</div>"+
							"</div>"+
							"<h3><a href='toov.php?id="+toovid+"'>"+title+"</a></h3>"+
							"<p>"+description+"</p>"+
							"<div class='info'>"+
								printable_name+" | "+type+" <a href='toovlist.php?cat=user&id="+ownerid+"'>"+displayname+"</a>";

							if(creationdate)
							entrylist+=" | "+creationdate;
							
							entrylist+="</div>"+
							"</div>";
							addSearchMarker(xpos,ypos,toovid,title,opentextbox);
					}
				}

			}
			if(numresults>0){
				var resultsperpage=12;
				var resultstring="";
				var offset=parseInt(document.getElementById('offset').value);

				if(numresults>resultsperpage){
					var startpos=offset+1;
					var endpos=offset+resultsperpage;
					if(endpos>numresults)endpos=numresults;
					resultstring+="<span class='title'>"+startpos+"-"+endpos +" of "+numresults+" </span>";
					var totalnumpages=Math.ceil(numresults/resultsperpage);
					
					if(offset>0){
						resultstring+="<a href='#' onclick='return offsetclick(\"-"+resultsperpage+"\");'>prev.</a>";
					}
					if(offset+resultsperpage<numresults){
						if(offset!=0){
							resultstring+=" | ";
						}
						resultstring+="<a href='#' onclick='return offsetclick(\""+resultsperpage+"\");'>next</a>";
					}								
				}else if(numresults>0){
					resultstring+="<span class='title'>1-"+numresults+" of "+numresults+" </span>";
				}else if(numresults==0){
					resultstring+="<span class='title'>0 of 0 </span>";					
				}

				writetodiv(resultstring,"pageturner");
				
				
				writetodiv("("+numresults+")","numsearchresults");
				if(cat=="showusertoovs")
					updateScreenPosAndZoom(myBounds);
			}else{
				entrylist="<div class='entry'>No Results found in the part of the world your viewing now (Try zooming out!)</div>";
				
			}


			toggleLayer('Waiting','none');
			writetodiv(entrylist, 'resultentrylist');
	};
	var onErrorFunc = function (status) { alert("AJAX error: "+status); };
	var myAjax = new _bsn.Ajax;
	
	
	toggleLayer('Waiting','block');
	myAjax.makeRequest( url, "get", onSuccessFunc, onErrorFunc );
}

var markerarray=new Array();
var markerids=new Array();

function removeOutOfBoundMakers(){
	//	X= point.lng();
    //	Y = point.lat();

	var northeast=map.getBounds().getNorthEast();
	var southwest=map.getBounds().getSouthWest();

	var northbounds=northeast.lat();
	var eastbounds=northeast.lng();
	var southbounds=southwest.lat();
	var westbounds=southwest.lng();

	var nummarkers=markerarray.length;
	for(var i=0;i<nummarkers;i++){
		if(markerids[i]>0){
			if(markerarray[i].getPoint().lng() > westbounds
			   && markerarray[i].getPoint().lng() < eastbounds
			   && markerarray[i].getPoint().lat() > southbounds
			   && markerarray[i].getPoint().lat() < northbounds){

			   }else{
			   	map.removeOverlay(markerarray[i]);
			   	markerids[i]=0;
			   }
		}
	}
}

function addSearchMarker(xpos,ypos,id,title,opentextbox){
	var nummarkers=markerarray.length;

	for(var i=0;i<nummarkers;i++){
		if(markerids[i]==id){
			return ;
		}
	}
	markerarray[nummarkers]=new GMarker(new GPoint(xpos, ypos),toov_icon);
	
	GEvent.addListener(markerarray[nummarkers], "click", function() {
		document.location.href="/toov.php?id="+id;		
	});
	GEvent.addListener(markerarray[nummarkers], "mouseover", function() {
  		if(document.getElementById("searchresultentry"+id)){  			
  			document.getElementById("searchresultentry"+id).className="entry mOver";
  		}
  		ewindow.openOnMarker(markerarray[nummarkers],title);
	});
	GEvent.addListener(markerarray[nummarkers], "mouseout", function() {
  		if(document.getElementById("searchresultentry"+id)){
  			document.getElementById("searchresultentry"+id).className="entry";
  		}
	});

	myBounds.extend(new GLatLng(ypos,xpos));
	
	if(opentextbox=="1"){
		ewindow.openOnMarker(markerarray[nummarkers],title);
	}
	map.addOverlay(markerarray[nummarkers]);
	markerids[nummarkers]=id;
}

function removeToOldMarkers(){
	ewindow.hide();
	var nummarkers=markerarray.length;
	for(var i=0;i<nummarkers;i++){
		if(markerids[i]>0){
			map.removeOverlay(markerarray[i]);
			markerids[i]=0;
		}
	}
	markerarray=new Array();

}

function showtag(tagid){
	var selecttagid=document.getElementById("tagid");
	if(selecttagid){
		selecttagid.value=tagid;
		removeToOldMarkers();
		performsearch();
	}
	return false;
}

function switchshowfilter(newid){
	var selecthref=document.getElementById(newid);
	if(selecthref){
		document.getElementById("showall").className="";
		document.getElementById("showdone").className="";
		document.getElementById("showtodo").className="";
		document.getElementById("showoffer").className="";
		selecthref.className="current";
		document.getElementById("showid").value=newid;
		removeToOldMarkers();
		performsearch();
	}
	return false;
}


function updatetagsvalue(){
	var tags=document.getElementById("tags");
	if(tags){
		document.getElementById("tags_hidden").value=tags.value;
		performsearch();
	}

}

function offsetclick(increment){
	var offset=document.getElementById('offset');
	if(offset){
		offset.value=parseInt(offset.value)+parseInt(increment);
	}
	performsearch();
	return false;
}

function selectitemonmap(toovid,action,title){
	var nummarkers=markerarray.length;
	for(var i=0;i<nummarkers;i++){
		if(markerids[i]==toovid){
			var newmarker;
			if(action=="over")
				newmarker=new GMarker(new GPoint(markerarray[i].getPoint().lng() , markerarray[i].getPoint().lat()),martini_icon);			
			else
				newmarker=new GMarker(new GPoint(markerarray[i].getPoint().lng() , markerarray[i].getPoint().lat()),toov_icon);


			map.removeOverlay(markerarray[i]);
			markerarray[i]=newmarker;
			map.addOverlay(markerarray[i]);
			if(action=="over")
				ewindow.openOnMarker(markerarray[i],title);
			return ;
		}
	}
}


function resizemap() {
	var m=document.getElementById("googlemapmap");
	var d = getDimensions();
	var windowHeight = getWindowHeight();
	m.style.height = (windowHeight - d.top - 230) + "px";
	
}

function Dimensions(left, top, width, height) {
	this.left = left;
	this.top = top;
	this.width = width;
	this.height = height;
}

function getDimensions(control) {
	var tmp = control;
	var left = 0;
	var top = 0;

	while (tmp != null) {
		left += tmp.offsetLeft;
		top += tmp.offsetTop;
		tmp = tmp.offsetParent;
	}

	return new Dimensions(left, top, 0, 0);
}

function getWindowHeight()
{
	var windowHeight=0;
	if (typeof(window.innerHeight)=='number')
		windowHeight=window.innerHeight;
	else if (document.documentElement&&document.documentElement.clientHeight)
		windowHeight=document.documentElement.clientHeight;
	else if (document.body&&document.body.clientHeight)
		windowHeight=document.body.clientHeight;

	return windowHeight;
}

function getWindowWidth()
{
	var windowWidth=0;
	if (typeof(window.innerWidth)=='number')
		windowWidth=window.innerWidth;
	else if (document.documentElement&&document.documentElement.clientWidth)
		windowWidth=document.documentElement.clientWidth;
	else if (document.body&&document.body.clientWidth)
		windowWidth=document.body.clientWidth;

	return windowWidth;
}

var mouselat=0;
var mouselng=0;
var draggingmarker=false;
var uniquetid=-10000;//negatieve ids staan niet in db :)
var newmarkerarray=new Array();
var newmarkerids=new Array();

function newQuickToovMarker(point,title,typeid,initiallyclosed,newmarkerid){
	
	var nummarkers=newmarkerarray.length;
	if(newmarkerid)
		newmarkerids[nummarkers]=newmarkerid;
	else
		newmarkerids[nummarkers]=uniquetid++;
	
	newmarkerarray[nummarkers]=new GMarker(point, {draggable: true});
	var xpos=point.x;
	var ypos=point.y;
	newmarkerarray[nummarkers].enableDragging();	
	
	GEvent.addListener(newmarkerarray[nummarkers], "click", function() {
		newmarkerarray[nummarkers].openInfoWindowHtml(getinfowindowcontent(newmarkerids[nummarkers],newmarkerarray[nummarkers].getPoint(),title,typeid));
	});	
	GEvent.addListener(newmarkerarray[nummarkers], "dragend", function() {
		newmarkerarray[nummarkers].openInfoWindowHtml(getinfowindowcontent(newmarkerids[nummarkers],newmarkerarray[nummarkers].getPoint(),title,typeid));
	});	
	GEvent.addListener(newmarkerarray[nummarkers], "dragstart", function() {
		map.closeInfoWindow()

	});	
	
	map.addOverlay(newmarkerarray[nummarkers]); 	
	if(!initiallyclosed)	
		newmarkerarray[nummarkers].openInfoWindowHtml(getinfowindowcontent(newmarkerids[nummarkers],newmarkerarray[nummarkers].getPoint(),title,typeid));
}

function getinfowindowcontent(markerid,point,title,typeid){
	var selected1="",selected2="",selected3="";
	if(typeid){
		typeid=parseInt(typeid);
		if(typeid==1){
			selected1=" CHECKED ";
		}else if(typeid==2){
			selected2=" CHECKED ";
		}else if(typeid==3){
			selected3=" CHECKED ";
		}
	}
	if(!title)
		title="";
		
	var infowindowcontent="";
infowindowcontent+="<div class=\"forms_start\">";
	infowindowcontent+="<fieldset class=\"start\">";
	infowindowcontent+="<li>";
	infowindowcontent+="<label for=\"title\">Title:</label>";
	infowindowcontent+="<input type=\"text\" name=\"titleInfoWindow\" id=\"titleInfoWindow\" value=\""+title+"\"/>";
	infowindowcontent+="</li>";
	infowindowcontent+="<li class=\"radioset\">";
	infowindowcontent+="<input class=\"radio\" type=\"radio\" name=\"sectionInfoWindow\" id=\"sectionInfoWindow\" value=\"1\""+selected1+"/>";
	infowindowcontent+="<label for=\"sect_did\">DONE</label>";
	infowindowcontent+="<input class=\"radio\" type=\"radio\" name=\"sectionInfoWindow\" id=\"sectionInfoWindow\" value=\"2\""+selected2+"/>";
	infowindowcontent+="<label for=\"sect_todo\">TO DO</label>";
	infowindowcontent+="<input class=\"radio\" type=\"radio\" name=\"sectionInfoWindow\" id=\"sectionInfoWindow\" value=\"3\""+selected3+"/>";
	infowindowcontent+="<label for=\"sect_offer\">SUGGEST</label>";
	infowindowcontent+="</li>";
	infowindowcontent+="</fieldset>";
	infowindowcontent+="<div class=\"tsubmit\">";
	
	infowindowcontent+="<input class=\"button\" onclick=\"javascript:deleteinfotoov('"+markerid+"')\"type=\"button\" name=\"form_submitD\" value=\"DELETE\"/>";
	infowindowcontent+="<input class=\"button\" onclick='javascript:map.closeInfoWindow()' type=\"button\" name=\"form_submitC\" value=\"CANCEL\"/>";
	infowindowcontent+="<input class=\"button\" onclick=\"javascript:saveinfotoov('"+markerid+"','"+point.y+"','"+point.x+"')\" type=\"button\" name=\"form_submitS\" value=\"SAVE\"/>";
	infowindowcontent+="</div>";
infowindowcontent+="</div>";
	return infowindowcontent;
}

function deleteinfotoov(markerid){
	map.closeInfoWindow();	
	for(var i=0;i<newmarkerids.length;i++){
		if(newmarkerids[i]==markerid){
			map.removeOverlay(newmarkerarray[i]);
		}		
	}	
	if(markerid>0){
		toggleLayer('Waiting','block');
		var url = "/includes/ajax/aequicktoov.php?cat=remove&markerid="+encodeURIComponent(markerid);
		var onSuccessFunc = function (req) {
				var xml = req.responseXML;
				if(xml.getElementsByTagName('results').length>0){
					var results = xml.getElementsByTagName('results')[0].childNodes;
				
					if(results.length>0){
						toggleLayer('Waiting','none');
					}
				}
		};
		var onErrorFunc = function (status) { alert("AJAX error: "+status); };
		var myAjax = new _bsn.Ajax;
		myAjax.makeRequest( url, "get", onSuccessFunc, onErrorFunc );	
	}
}

function saveinfotoov(markerid,lat,lng){
	var title= document.getElementById('titleInfoWindow').value;
	if(!title){
		alert('invalid title');
		return ;
	}
	
	var sectionObj=document.getElementsByName('sectionInfoWindow');
	var section=0;	
	var sectionObjL = sectionObj.length;
	for(var i = 0; i < sectionObjL; i++) {
		if(sectionObj[i].checked) {
			section=sectionObj[i].value;
		}
	}
	if(section==0){
		alert('Please choose a type DONE/TO DO/SUGGEST');
		return ;
	}
	
	var newmarkerid=0;
	for(var i=0;i<newmarkerids.length;i++){
		if(newmarkerids[i]==markerid){
			newmarkerarray[i].openInfoWindowHtml("Saving...");
			savequicktoov(lat,lng,title,section,markerid);
			newmarkerid=newmarkerids[i];//deze is geupdate door de savequicktoov;
			map.removeOverlay(newmarkerarray[i]);
		}		
	}
	map.closeInfoWindow();	
	newQuickToovMarker(new GLatLng(lat,lng),title,section,true,newmarkerid);
	
}


function onmousemove(point){
	if(point.y && draggingmarker){
	    mouselat = point.y.toFixed(6); 
    	mouselng = point.x.toFixed(6); 
    	draggingmarker.setPoint(point);
	}
}

function onmouseclick(marker,point){
	
	if(marker){
		//dont have to do anything now
	}else if(draggingmarker){
		map.removeOverlay(draggingmarker);
		draggingmarker=false;		
		newQuickToovMarker(point);
	}
	
}

function AddToovControl() {
}
AddToovControl.prototype = new GControl();

AddToovControl.prototype.initialize = function(map) {
	var container = document.createElement("div");
	
	var atcdiv = document.createElement("div");
	this.setButtonStyle_(atcdiv);
	container.appendChild(atcdiv);
	atcdiv.appendChild(document.createTextNode("Add Toov"));
	
	GEvent.addDomListener(atcdiv, "click", function() {		
		draggingmarker=new GMarker(new GLatLng(mouselng,mouselat), {draggable: true});
		draggingmarker.enableDragging();
		map.addOverlay(draggingmarker); 

	});
	

	map.getContainer().appendChild(container);
	return container;
}

// By default, the control will appear in the top left corner of the
// map with 7 pixels of padding.
AddToovControl.prototype.getDefaultPosition = function() {
	return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(70, 7));
}

// Sets the proper CSS for the given button element.
AddToovControl.prototype.setButtonStyle_ = function(button) {
	button.style.textDecoration = "underline";
	button.style.color = "#690";
	button.style.backgroundColor = "white";
	button.style.font = "small Arial";
	button.style.border = "1px solid black";
	button.style.padding = "2px";
	button.style.marginBottom = "2px";
	button.style.textAlign = "center";
	button.style.width = "6em";
	button.style.cursor = "pointer";
}


function savequicktoov(lat,lng,title,section,markerid){
	toggleLayer('Waiting','block');
	var url = "/includes/ajax/aequicktoov.php?cat=add&lat="+encodeURIComponent(lat)+"&lng="+encodeURIComponent(lng)+"&title="+encodeURIComponent(title)+"&section="+encodeURIComponent(section)+"&markerid="+encodeURIComponent(markerid);
	var onSuccessFunc = function (req) {
			var xml = req.responseXML;
			if(xml.getElementsByTagName('results').length>0){
				var results = xml.getElementsByTagName('results')[0].childNodes;
				
				if(results.length>0){
					
					var rs = xml.getElementsByTagName('rs');
					if(rs.length==3){
						var resultstats=rs[0].childNodes[0].nodeValue;
						if(resultstats!="ok"){							
							alert(rs[1].childNodes[0].nodeValue);							
						}else{
							
							for(var i=0;i<newmarkerids.length;i++){
								if(newmarkerids[i]==markerid){
									newmarkerids[i]=rs[2].childNodes[0].nodeValue;
								}
							}
						}
					}
					toggleLayer('Waiting','none');
				}
			}
	};
	var onErrorFunc = function (status) { alert("AJAX error: "+status); };
	var myAjax = new _bsn.Ajax;
	myAjax.makeRequest( url, "get", onSuccessFunc, onErrorFunc );
}
