function goodZoom() {
	var zoom=map.getZoom();
	
	
}
var shpnt;
var shed=false;
var edit;
function showPoint(lng,lat,typ) {
	if (edit=="a") {
		
	} else {
		if (shpnt) {
		map.removeOverlay(shpnt);
		}
		shed=true;
		if (typ==1) {
		  		icon=baseIcon1;
		  		var iconb=baseIcon1b;
	 	} else if (typ==2) {
		  		icon=baseIcon2;
		  		var iconb=baseIcon2b;
	  	} else if (typ==3) {
		  		icon=baseIcon3;
		  		var iconb=baseIcon3b;
	  	} else if (typ==4) {
		  		icon=baseIcon4;
		  		var iconb=baseIcon4b;
	  	} else {
	  			icon=baseIcon5;
		  		var iconb=baseIcon5b;
	  	}
		var pnt= new GPoint(lat,lng);
		shpnt = new PdMarker(pnt,iconb);	
		
		map.addOverlay(shpnt);
		
		shpnt.blink(true,300);
		shpnt.topMarkerZIndex();
	
	}
	  
}

function hidePoint() {
	if (shed==true) {
	map.removeOverlay(shpnt);
	}
	
}

function getWindowSize()
		    {
			    var e = new Object();
			    if(window.self && self.innerWidth)
			    {
				    e.width = self.innerWidth;
				    e.height = self.innerHeight;
			    }
			    else if(document.documentElement &&
		document.documentElement.clientHeight)
			    {
				    e.width = document.documentElement.clientWidth;
				    e.height = document.documentElement.clientHeight;
			    }else
			    {
				    e.width = document.body.clientWidth;
				    e.height = document.body.clientHeight;
			    }
			    return e
		    } 
var ison=false;
function changeMarker(id,icon2) {
	//if (ison==false) {
		
	for (var i in gmarkers) {
		if (gmarkers[i].id ==id) {
			map.removeOverlay (gmarkers[i].marker);
			//gmarkers[i].marker.icon.image=icon2.image; 
			
			map.addOverlay(gmarkers[i].marker);
			
		}
	}
	ison=true;
	
	//}
	
}

function clearOldMarkers() {
	try {
						if (!gmarkers) {
							mrkrCount = 0;
							return;
						}	
					
						
						//alert(gmarkers);
						for (var i in gmarkers) {
							
							if (in_array(gmarkers[i].id,mdb)) {
								 
							} else {
								
								if(gmarkers[i].handle != null)
									GEvent.removeListener (gmarkers[i].handle);
								if(gmarkers[i].marker != null) {
									map.removeOverlay (gmarkers[i].marker);	
									
								}
									delete gmarkers[i];								
							}
						}
						var nm= [];
						for (var i in gmarkers) { 
						  	if (gmarkers[i].id != null) {
							   nm[nm.length]=gmarkers[i];	
							}
							
						}
						gmarkers=nm;
	} finally {
		
		
	}
					}


function clearOldMarkers2() {
	try {
						if (!gmarkers) {
							mrkrCount = 0;
							return;
						}	
					
						
						//alert(gmarkers);
						var loadm=[];
						for (var i in gmarkers) {
							
							if (in_array(gmarkers[i].id,mdb)) {
								
							} else {
								
								if(gmarkers[i].handle != null)
									GEvent.removeListener (gmarkers[i].handle);
									delete gmarkers[i];								
							}
						}
						var nm= [];
						for (var i in gmarkers) { 
						  	if (gmarkers[i].id != null) {
							   nm[nm.length]=gmarkers[i];	
							}
							
						}
						
						
						mrkrCount=nm.length;
						markerCluster.clearMarkers();
						gmarkers=nm;
	} finally {
		
		
	}
					}


function in_array(item,arr) {
						for(p=0;p<arr.length;p++) if (item == arr[p]) return true;
						return false;
					}
			
					function extractDataFromLocation()
						{
						if (window.location) {
						var loc=window.location;
						
						loc=loc.toString();
						loc = loc.split("#");
						if (loc[1]) {
						loc=loc[1];
							if (loc.length > 0) {								
								var ar = loc.split("&");								
								for (var i = 0; i < ar.length; i++) {
									var a = ar[i].split("=");									
									
									urlparse[a[0]]=parseFloat(a[1]);									
								}								
							}
								}
							return urlparse;
								}
						}

function getUrl() {
					center=map.getCenter();
						var x='#';
						zoom=map.getZoom();
						x+='sw='+center.y+'&ne='+center.x+'&zoom='+zoom;
						return x;
					}
									
					function showAddress(address) {
					  if (address =='') {
					  } else {
				      if (geocoder) {
				        geocoder.getLatLng(
				          address,
				          function(point) {
				            if (!point) {
				             
				            } else {
				              map.setCenter(point, 10);
				              //var marker = new GMarker(point);
				              //map.addOverlay(marker);
				             // marker.openInfoWindowHtml(address);
				            }
				          }
				            
				        );
				            }
				      }
}	
			

move=8;
totalcnt=0;
num=1;

function movePositionsForward() {
	
	
	var total=Math.ceil(totalcnt/((perpage)+1));
	if (num<total) {
		num=num+1;
	} else {

	}
	
	if (num<total) {
		$('movef').style.display='';
	} else {
		$('movef').style.display='none';	
		
	}
		
	
	for (i=0;i<=totalcnt;i++) {
		if ($('svizit'+i)) {
			$('svizit'+i).style.display='none';
		}
	}
	for (i=((num*perpage)-perpage);i<=((num*perpage));i++) {
		if ($('svizit'+i)) {
			$('svizit'+i).style.display='';
		}
	}	
	
	
	$('moveb').style.display='';
	
	$('hpcur').innerHTML=(num).toString();
	
}

function movePositionsBackward() {
	
	if (num>1) {
		num=num-1;
	} else {
	
	}
	
	if (num>1) {
		$('moveb').style.display='';
	} else {
		$('moveb').style.display='none';	
		
	}
		
	
	for (i=0;i<=totalcnt;i++) {
		if ($('svizit'+i)) {
			$('svizit'+i).style.display='none';
		}
	}
	for (i=((num*perpage)-perpage);i<=((num*perpage));i++) {
		if ($('svizit'+i)) {
			$('svizit'+i).style.display='';
		}
	}
	
	$('movef').style.display='';
	$('hpcur').innerHTML=(num).toString();
	
}

function movePositionsForwarda() {
	
	for (i=(move-perpage);i<=move;i++) {
		$('svizit'+i).style.display='none';
		
	}
	
	
	
	
	for (i=(move+1);i<=(move+(perpage+1));i++) {
		if ($('svizit'+i)) {
			$('svizit'+i).style.display='';
		}
	}
	if (totalcnt>(move+(perpage+2))) {
		togo=move+(perpage+1);
		move+=(perpage+1);
		
	} else {
		togo=totalcnt;
		$('movef').style.display='none';
	}
	
	num=num+1;
	$('moveb').style.display='';
	$('hpcur').innerHTML=(num).toString();
	
}

function movePositionsBackwarda() {
	
	for (i=(move);i<=move+(perpage+1);i++) {
		if ($('svizit'+i)) {
			$('svizit'+i).style.display='none';
		}
	}
	
	for (i=(move-perpage);i<=move;i++) {
		if ($('svizit'+i)) {
			$('svizit'+i).style.display='';
		}
	}
	
	if (move>perpage) {
		move=move-perpage;
		$('moveb').style.display='';
	} else {
		$('moveb').style.display='none';
	}
	num=num-1;
	$('movef').style.display='';
	$('hpcur').innerHTML=(num).toString();
	
}


function help(a) {
Effect.Appear(a,
	{ duration: 0.3});
}

function helpoff(a) {
Effect.Fade(a,
	{ duration: 0.3});
}
var myp;
var imgload;

function updater(id,par,id1,id2) {
	if ($('loader')) {
	$('loader').style.display='';
	}
	var showcil = new Ajax.Updater(
				id, 
				'/m/'+par+'/'	,
					{
					method: 'post', 
					onComplete: hideload(),
					evalScripts:true,
					postBody:'&id='+id1+'&id2='+id2				
				});
}

hideload = function() {
	if ($('loader')) {
		$('loader').style.display='none';
	}
}



function checkNazev() {
	
	$("loader").style.display='';

	if ($('name').value=='') {
		$('name').className="mustfill";
		
	} 
	
	if ($('type')) {
	if ($('type').value=='') {
		$('type').className="mustfill";
		
	} 
	}
	
	var response= new Ajax.Updater(
						'talk',
						'/ajax/name/?name='+$('name').value,
						{method:
							'post', 
							onComplete: changeName,
							evalScripts:true

						});
	
}
function changeName() {
	var x=$('talk').innerHTML;
	
	if (x=="") {
		
	} else {
		
		talk();
		
	}
	$("loader").style.display='none';

	return cansave;
}

function talk() {
	
	Effect.Appear("maintalk");
	
}

var notahlo=false;
function createslider(num,val) {
new Control.Slider('sliderhandle'+num,'slider'+num,
{
range: $R(0, 10),
values: [0,1,2,3,4,5,6,7,8,9,10],
sliderValue: val,
onChange:function(v){
notahlo=true;
$('val_'+num).value=v;
}});
}




function savePoint() {
	var point=myp.getPoint();
	var zoom=map.getZoom();
	if ($('gpsx')) {
	$('gpsx').value=point.y;
	$('gpsy').value=point.x;
	$('zoom').value=zoom;
	}
}

function changePoint() {
				
	 new Ajax.Request(
						'/ajax/sour/?x='+$('gpsx').value+'&y='+$('gpsy').value,
						{method:
							'post', 
							onSuccess:changePoint2
						});
}

var changePoint2 = function(t) {
		  var x=t.responseText;
		  var y=x.split(";");
		  $('gpsx').value=y[0];
		  $('gpsy').value=y[1];
		  myPoint($('gpsy').value,$('gpsx').value);
			var pnt=new GPoint($('gpsy').value,$('gpsx').value);
}

function changePointEdit() {
				
	 new Ajax.Request(
						'/ajax/sour/?x='+$('gps_x').value+'&y='+$('gps_y').value,
						{method:
							'post', 
							onSuccess:changePointEdit2
						});
}

var changePointEdit2 = function(t) {
		  var x=t.responseText;
		  var y=x.split(";");
		  $('gps_x').value=y[0];
		  $('gps_y').value=y[1];
}

function updatePoint() {
	
					var pnt= map.getCenter();
				
				if (myp) map.removeOverlay(myp);
				myp = new GMarker(pnt, {draggable:true});
				
				
				 GEvent.addListener(myp, "dragend", function() {
				 	
				 	if ($('photoload')) {
				 		$('photoload').innerHTML='<img src="/templates/1/img/ajaxphoto.gif" />';
						$('photoload').style.display='';
					}
					if ($('helptext')) {
						$('helptext').innerHTML='';
						
					}
					$('helpme').style.display='none';
					if ($('gpsx')) {
						
					} else if ($('sgps')) {
						$('sgps').style.display='';
					} else {
						updater("info","addform");
						
					}
					if ($('sgps')) {
						$('sgps').style.display='';
					}
				 	var point=myp.getPoint();
				 	savePoint();
				 	updater('phototn','phototn',point.x,point.y);
					    new Ajax.Request(
						'/ajax/locate/'+point.x+'/'+point.y,
						{method:
							'post', 
							evalScripts:true,
							onSuccess:changeKeywords
						});return false;
					
						
		  				
					  });	
				map.addOverlay(myp);
				
}

function myPoint(x,y) {
	
	totalover=false;
	imgload='a';
	//loadMarkers();
	
	if (treefocus==undefined) {		
		var nx="";
	} else {
		var nx=treefocus;
	}
	
				if ($('photoload')) {
						$('photoload').style.display='';
				}
				if (x==undefined) {
					updater("info","addform",nx);
					var pnt= map.getCenter();
				} else {
					var pnt=new GPoint(x,y);
				}
				if (myp) map.removeOverlay(myp);
				myp = new GMarker(pnt, {draggable:true});
				
				
				 GEvent.addListener(myp, "dragend", function() {
				 	
				 	if ($('photoload')) {
				 		$('photoload').innerHTML='<img src="/templates/1/img/ajaxphoto.gif" />';
						$('photoload').style.display='';
					}
					if ($('helptext')) {
						$('helptext').innerHTML='';
						
					}
					$('helpme').style.display='none';
					if ($('sgps')) {
						$('sgps').style.display='';
					} else if ($('gpsx')) {
					} else {
						
						//updater("info","addform");
						
					}
					if ($('sgps')) {
						$('sgps').style.display='';
					}
				 	var point=myp.getPoint();
				 	savePoint();
				 	
				 	updater('phototn','phototn',point.x,point.y);
					    new Ajax.Request(
						'/ajax/locate/'+point.x+'/'+point.y,
						{method:
							'post', 
							evalScripts:true,
							onSuccess:changeKeywords
						});return false;
					
						
		  				
					  });	
					  
				map.addOverlay(myp);
				
				var point=myp.getPoint();
				map.panTo(point);
				/*
				 new Ajax.Request(
						'/ajax/locate/'+point.x+'/'+point.y,
						{method:
							'post', 
							onSuccess:changeKeywords
						});
		  
		  	  updater('phototn','phototn',point.x,point.y);
			 */
		  
			
				
				
}
var changeKeywords = function(t) {
//		  /alert(t.responseText);
		  var x=t.responseText;
		  $('keywds').innerHTML=x;
		  var y=x.split(", ");
		  var str="";
		  for (i=1;i<=(y.length-1);i++) {
		  	if (y[i]!=="undefined") {
		  		str=str+ y[i]+", ";
		  	}
		  }
		 
		  $('keywords_city').value=y[0];
		  $('keywords_system').value=str;
		  
}


function showFriends(url) {
	new Ajax.Request(
	url,
	{method:
		'post', 
		onSuccess:friendsResponse
	});return false;
}

var friendsResponse = function(t) {
		  $('friends').innerHTML=t.responseText;
		  
		 
}

function showhelp(a) {
			   document.getElementById('helper').style.display='block';	
				document.getElementById('helper').innerHTML=a;
				//Effect.Appear('helper',{duration:.2});
}
			
function hidehelp() {
				//Effect.Fade('helper',{duration:.2});
	   document.getElementById('helper').style.display='none';
}


			
			var mx;
			var my;
			
			// Detect if the browser is IE or not.
			// If it is not IE, we assume that the browser is NS.
			var IE = document.all?true:false
			
			// If NS -- that is, !IE -- then set up for mouse capture
			if (!IE) document.captureEvents(Event.MOUSEMOVE)
			
			// Set-up to use getMouseXY function onMouseMove
			
			
			// Temporary variables to hold mouse x-y pos.s
			var tempX = 0
			var tempY = 0
			
			// Main function to retrieve mouse x-y pos.s
			
			function getMouseXY(e) {
			  if (IE) { // grab the x-y pos.s if browser is IE
			    tempX = event.clientX + document.body.scrollLeft
			    tempY = event.clientY + document.body.scrollTop
			  } else {  // grab the x-y pos.s if browser is NS
			    tempX = e.pageX
			    tempY = e.pageY
			  }  
			  // catch possible negative values in NS4
			  if (tempX < 0){tempX = 0}
			  if (tempY < 0){tempY = 0}  
			  // show the position values in the form named Show
			  // in the text fields named MouseX and MouseY
			  mx = tempX
			  my = tempY
			  document.getElementById('helper').style.left=tempX +30+"px";
  			  document.getElementById('helper').style.top=tempY+"px";	
  			  
			  return true
			}
			
			function setMousePos() {
			frameWidth = self.innerWidth;
			frameHeight = self.innerHeight;
			var pulka=frameWidth/2;
			
			if (mx>pulka) {
			
				$("helpme").style.left=mx-300;			
			} else {
			
				$("helpme").style.left=mx+30;
			}
			
			var pulka=frameHeight/2;
			var of=document.body.scrollTop;
			
			if ((my-of)<pulka) {
				$("helpme").style.top=my+50;
				
			} else {
			
				$("helpme").style.top=my-150;		
			
			
			}
			}
			
			function help10(a) {
				if (a =='') {
					
				} else {
				$('helpme').innerHTML='<div id="inhelp"><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="150" height="150"><param name="movie" value="/templates/1/swf/'+a+'.swf"><param name="quality" value="high"><param name="loop" value="0"><embed src="/templates/1/swf/'+a+'.swf" width="150" height="150" loop="0" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" menu="false"></embed></object></div>';
				}
				
				Effect.Appear('helpme');
				timeHide();
			}
			
			function timeHide() {
				setTimeout("hideme()",20000);
			}
			
			function hideme() {
				Effect.Fade("helpme");
			}
			
			function openDetail(id,id2) {
				if (edit=="a") {
					id2="editgps";
				}
				if ($('infotop')) {
				//	$('infotop').style.display='none';
				}
				updater("info","detail",id,id2)
			}
			
			function openDetailP(id,id2) {
				if (edit=="a") {
					id2="editgps";
				}
				if ($('infotop')) {
					$('infotop').style.display='none';
				}
				updater("info","detailp",id,id2)
			}
			
			
			function fSetActiveItem(name){
						
				
						WebServiceUrl='/ajax/mapify/?name='+name;
						GDownloadUrl(WebServiceUrl, function(data, responseCode)
						{
							if((200==responseCode)&&(0!=data.length))
							{
								
								var xmlPolylines = data
								
								if (xmlPolylines.length > 0) {
									
										var raw = data;
										try {
											var iStart = 0;
											var arePoints = false;
											var polylineLevels = "";
											//File structure is [encoded Levels<br>encoded Polylines<br>...]
											do {
												var iEnd = raw.indexOf("<br>", iStart);
												if (false == arePoints) {//Levels
													polylineLevels = raw.substring(iStart, iEnd);
													arePoints = true;
												}
												else {//Points
													var polygon = new GPolygon.fromEncoded({
														polylines: [{
															color: "#ffff00",
															weight: 2,
															
															points: raw.substring(iStart, iEnd),
															levels: polylineLevels,
															zoomFactor: 2,
															numLevels: 18
														}],
														fill: true,
														color: " #ffff00",
														opacity: 0.3,
														outline: true
													});
													
													
													
													arePoints = false;
													
												}
												iStart = iEnd + 4;//jump above '<br>' to the next polylines
											}
											while (raw.length > iStart)
											
										} 
										catch (e) {
											
										}
										 var cnt=polygon.getVertexCount();
										 var str='';
										 for (i=0;i<=cnt-1;i++) {
										  	 var vertex=polygon.getVertex(i);
										     str=str+vertex.x+' '+vertex.y+', ';
										  }
										 
										 $('body').value=str;
										 
										 map.addOverlay(polygon);
										 polygon.enableEditing({onEvent: "mouseover"});
  										polygon.disableEditing({onEvent: "mouseout"});

				  						GEvent.addListener(polygon, "lineupdated", function() {
				  							savePoints();
				  						
				  						});
									}//for
								
											
							}//if
							
								
						});					
					};

	