var otz;
var cmt;
var is_close=0;
var ostanovka;
var y;
var x;
var fio;
var tel;

	var vsego_ost;
	var vse_ostan = new Array();

function ShowMarshrut(){

	map.setCenter(new GLatLng(54.196994,37.623367), 12);
	var polyline = new GPolyline([new GLatLng(54.163307,37.576987), new GLatLng(54.163477,37.5766), new GLatLng(54.162158,37.57513), new GLatLng(54.162007,37.575002), new GLatLng(54.16195,37.574712), new GLatLng(54.162158,37.5738), new GLatLng(54.162409,37.572459), new GLatLng(54.162698,37.570817), new GLatLng(54.162874,37.569745), new GLatLng(54.163081,37.568886), new GLatLng(54.164312,37.566086), new GLatLng(54.164676,37.565292), new GLatLng(54.16484,37.564949), new GLatLng(54.164915,37.564509), new GLatLng(54.164859,37.564305), new GLatLng(54.164764,37.564101), new GLatLng(54.164475,37.563951), new GLatLng(54.164375,37.56379), new GLatLng(54.164262,37.563597), new GLatLng(54.164187,37.563243), new GLatLng(54.164161,37.563125), new GLatLng(54.164161,37.562846), new GLatLng(54.164243,37.562664), new GLatLng(54.164884,37.561634), new GLatLng(54.165166,37.561494), new GLatLng(54.165462,37.561451), new GLatLng(54.166718,37.561827), new GLatLng(54.168194,37.562149), new GLatLng(54.167742,37.56747), new GLatLng(54.168282,37.571182), new GLatLng(54.168181,37.571483), new GLatLng(54.169406,37.572716), new GLatLng(54.169714,37.573081), new GLatLng(54.170197,37.573682), new GLatLng(54.171981,37.57556), new GLatLng(54.172917,37.575399), new GLatLng(54.178091,37.574176), new GLatLng(54.182493,37.573178), new GLatLng(54.184721,37.572652), new GLatLng(54.185079,37.572491), new GLatLng(54.185079,37.572491), new GLatLng(54.186454,37.575903), new GLatLng(54.187785,37.57939), new GLatLng(54.189311,37.583199), new GLatLng(54.189273,37.583381), new GLatLng(54.18926,37.58366), new GLatLng(54.188187,37.586503), new GLatLng(54.182424,37.601845), new GLatLng(54.18145,37.604656), new GLatLng(54.192236,37.616501), new GLatLng(54.19368,37.612853), new GLatLng(54.193968,37.61251), new GLatLng(54.198939,37.611609), new GLatLng(54.20096,37.615535), new GLatLng(54.202027,37.616544), new GLatLng(54.20288,37.617166), new GLatLng(54.204876,37.618647), new GLatLng(54.205867,37.61914), new GLatLng(54.225491,37.628496), new GLatLng(54.226256,37.62886), new GLatLng(54.226908,37.628903), new GLatLng(54.22746,37.628732), new GLatLng(54.233456,37.624269), new GLatLng(54.233744,37.625234), new GLatLng(54.234359,37.62665), new GLatLng(54.234258,37.626801), new GLatLng(54.234785,37.629097), new GLatLng(54.233054,37.640405), new GLatLng(54.235287,37.641327), new GLatLng(54.236177,37.64358), new GLatLng(54.236516,37.644074), new GLatLng(54.236578,37.644761), new GLatLng(54.236716,37.645254), new GLatLng(54.238209,37.645898), new GLatLng(54.239413,37.638216), new GLatLng(54.240228,37.633388), new GLatLng(54.241193,37.62738), new GLatLng(54.240817,37.627144)], "#0000FF", 5,0.3);
	map.addOverlay(polyline);

}

function PBB(fio, tel,is_ie){
		// document.getElementById("test").innerHTML='<img src="/wp-content/themes/tula20/images/krutilka.gif">';
		var xmlhttp = getXmlHttp()
		xmlhttp.open('GET', '/?page_id=4005&is_ie='+is_ie.toString()+'&pbb=1&fio='+fio.toString()+'&tel='+tel.toString(), true);
		
		xmlhttp.onreadystatechange = function() {
			
			if (xmlhttp.readyState == 4) {
				if(xmlhttp.status == 200) {
					var s=xmlhttp.responseText;
						//alert(s);
						document.getElementById("pbb_fio").value='';
						document.getElementById("pbb_tel").value='';
						document.getElementById("pbb_content").innerHTML='<span style="color: green;font-size: 15px;padding:10px;">Пробизнесбанк получил Вашу заявку. Менеджер банка свяжется с Вами через 15 минут. Спасибо, что воспользовались нашей заявкой.</span>';
				}
			}
		};

		xmlhttp.send(null);
}

function SelectOstanovka(ostanovka,x,y){
		
		document.getElementById("test").innerHTML='<img src="/wp-content/themes/tula20/images/krutilka.gif">';
		var xmlhttp = getXmlHttp()
		xmlhttp.open('GET', '/?page_id=4005&x='+x.toString()+'&y='+y.toString()+'&ostanovka=1&ostanovkaname='+ostanovka.toString(), true);
		
		xmlhttp.onreadystatechange = function() {
			
			if (xmlhttp.readyState == 4) {
				if(xmlhttp.status == 200) {
					var s=xmlhttp.responseText;
						document.getElementById("ostanovki").innerHTML=s;
						document.getElementById("test").innerHTML='';
				}
			}
		};

		xmlhttp.send(null);
}

function DaNet(otz,cmt){
	
	var xmlhttp = getXmlHttp()
	xmlhttp.open('GET', '?page_id=4005&dn='+otz.toString()+'&cmt='+cmt.toString(), true);
	xmlhttp.onreadystatechange = function() {
	
		if (xmlhttp.readyState == 4) {
			if(xmlhttp.status == 200) {
				var s=xmlhttp.responseText;
				
				var t=s.indexOf("feil");
				
				if (t==-1){
					var a=s.indexOf(":");
					s1=s.substring(1,a);
					s2=s.substring(a+1,s.length);
					
					if (otz==1) {document.getElementById("da"+cmt.toString()).innerHTML=s1};
					if (otz==-1) {document.getElementById("net"+cmt.toString()).innerHTML=s2};
					document.getElementById("res"+cmt.toString()).innerHTML="<strong> Спасибо! Ваш голос учтён!</strong>"
				} else {
					document.getElementById("res"+cmt.toString()).innerHTML="<strong> Оценить отзыв можно только один раз :(</strong>"
				}
				
			}
		}
	};
	
xmlhttp.send(null);
	
}

function getXmlHttp(){
  var xmlhttp;
  try {
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (e) {
    try {
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (E) {
      xmlhttp = false;
    }
  }
  if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
    xmlhttp = new XMLHttpRequest();
  }
  return xmlhttp;
}

function RandomObject(){
	
	//document.getElementById("krutilka").innerHTML="<img src='http://tula-foto.ru/wpspin_dark.gif'>";
	var xmlhttp = getXmlHttp()
	xmlhttp.open('GET', '/?page_id=4005&random=1', true);
	xmlhttp.onreadystatechange = function() {
	
		if (xmlhttp.readyState == 4) {
			if(xmlhttp.status == 200) {
				var s=xmlhttp.responseText;
				var a=s.indexOf("|");
				var b=s.indexOf("*");
				
				var foto = s.substring(0,a-1);
				var text = s.substring(a+1,b-1);
				document.getElementById("sluch_object").innerHTML=foto;
				document.getElementById("sluch_object_name").innerHTML=text;
				
				document.getElementById("sluch_otz").innerHTML=s.substring(b+1);;
				//document.getElementById("sluch_otz").innerHTML='1';
				
				//document.getElementById("krutilka").innerHTML="";
			}
		}
	};
	
xmlhttp.send(null);

}

function Suggest(){
	
	var s=document.getElementById("search").value;
	if ((s.length>=3) && (is_close==0)){
	
		var xmlhttp = getXmlHttp()
		xmlhttp.open('GET', '?page_id=4005&suggest=1&sug_text='+s, true);
		xmlhttp.onreadystatechange = function() {
	
			if (xmlhttp.readyState == 4) {
				if(xmlhttp.status == 200) {
					var s=xmlhttp.responseText;
					if (s.length>=10){
						document.getElementById("suggest_result").innerHTML=s;
						document.getElementById("suggest_close").innerHTML='x';
						document.getElementById("suggest_footer").innerHTML='&nbsp;';
					} else {
						NoFocus();
					}
				}
			}
		};
	
	xmlhttp.send(null);	
	
		//document.getElementById("suggest_result").innerHTML=document.getElementById("s").value;
	} else if (s.length<3){
		document.getElementById("suggest_result").innerHTML="";
		document.getElementById('suggest_close').innerHTML="";
		document.getElementById('suggest_footer').innerHTML="";
	}
}

function CloseSuggest(){
		
		document.getElementById('suggest_result').style.display='none';
		document.getElementById('suggest_close').style.display='none';
		document.getElementById('suggest_footer').style.display='none';
		is_close=1;
	}
	
function NoFocus(){
		document.getElementById("suggest_result").innerHTML="";
		document.getElementById('suggest_close').innerHTML="";
		document.getElementById('suggest_footer').innerHTML="";
}

function TestAlert(){
	alert('111');
}

var mas = new Array();
var markers = new Array();

function but1(x,y,txt,cat,nazvan,id) {
mas[q]=txt;

		var p = 0;
		for (var i = 0; i < mas.length-1; i++) {
		if (txt==mas[i]) {p=p+1;}
		} 
		if (p==0)
		{
		var icon = new GIcon();
		icon.image = "n"+cat.toString()+".png";
		icon.shadow = "mm_20_shadow.png";
		icon.iconSize = new GSize(17, 22);
		icon.shadowSize = new GSize(22, 20);
		icon.iconAnchor = new GPoint(6, 20);
		icon.infoWindowAnchor = new GPoint(5, 1);
		var point = new GLatLng(x,y);	
		var marker = new GMarker(point,{icon: icon, title:nazvan});
		map.closeInfoWindow();
		map.addOverlay(marker);
		markers[q]=(marker);
		marker.bindInfoWindowHtml("<a href=?p="+id.toString()+">"+nazvan+"</a>");
		marker.openInfoWindow("<a href=?p="+id.toString()+">"+nazvan+"</a>");
		q=q+1;	
		} 
}

function but2(x,y,txt,cat,nazvan,id) {
mas[q]=txt;

		var p = 0;
		for (var i = 0; i < mas.length-1; i++) {
		if (txt==mas[i]) {p=p+1;}
		} 
		if (p==0)
		{
		var icon = new GIcon();
		icon.image = "n"+cat.toString()+".png";
		icon.shadow = "mm_20_shadow.png";
		icon.iconSize = new GSize(17, 22);
		icon.shadowSize = new GSize(22, 20);
		icon.iconAnchor = new GPoint(6, 20);
		icon.infoWindowAnchor = new GPoint(5, 1);
		var point = new GLatLng(x,y);	
		var marker = new GMarker(point,{icon: icon, title:nazvan});
		map.closeInfoWindow();
		map.addOverlay(marker);
		markers[q]=(marker);
		marker.bindInfoWindowHtml("<a href=?t="+id.toString()+">"+nazvan+"</a>");
		marker.openInfoWindow("<a href=?t="+id.toString()+">"+nazvan+"</a>");
		q=q+1;	
		} 
}

function ubr(txt){
			for (var i = 0; i < q; i++) {
				if (mas[i]==txt){
				map.closeInfoWindow();
				markers[i].hide();
				mas[i]=0;
				}
			}
}

function getBrowserInfo() {
 var t,v = undefined;
 if (window.opera) t = 'Opera';
 else if (document.all) {
  t = 'IE';
  var nv = navigator.appVersion;
  var s = nv.indexOf('MSIE')+5;
  v = nv.substring(s,s+1);
 }
 else if (navigator.appName) t = 'Netscape';
 return {type:t,version:v};
}
 
function bookmark(a){
 var url = window.document.location;
 var title = window.document.title;
 var b = getBrowserInfo();
 if (b.type == 'IE' && 7 > b.version && b.version >= 4) window.external.AddFavorite(url,title);
 else if (b.type == 'Opera') {
  a.href = url;
  a.rel = "sidebar";
  a.title = url+','+title;
  return true;
 }
 else if (b.type == "Netscape") window.sidebar.addPanel(title,url,"");
 else alert("Нажмите CTRL-D, чтобы добавить страницу в закладки.");
 return false;
}

