﻿//Общаемся с серваком по ajax
function ServerMessage(keyword,table,name_div)
{
	var req;
	var sss;
	if (window.XMLHttpRequest)
	{
		req=new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{
		try	{req=new ActiveXObject('MSXML2.XMLHTTP.3.0');}
		catch(e){}
	}
	if(req)
	{
		req.open("post","/ajax.php",true);
		req.setRequestHeader("Content-Type"," application/x-www-form-urlencoded;");
		req.onreadystatechange=function()
		{
	   	 if (req.readyState==4 && req.status==200)
	    	{
	    		sss=req.responseText;
	    		document.getElementById(name_div).style.display='block';
	    		document.getElementById(name_div).innerHTML=sss;
	    	}
		}
		req.send('keyword='+table+'|'+encodeURIComponent(keyword));
	}
}


function ShowDiv(div)
{
	if(document.getElementById(div)!=null)
	document.getElementById(div).style.display="block";
}

function ShowHideDiv(div)
{
	if(document.getElementById(div)!=null)
	if(document.getElementById(div).style.display=='none')
	document.getElementById(div).style.display="block";
	else
	document.getElementById(div).style.display="none";
}
function HideDiv(div)
{
	if(document.getElementById(div)!=null)
	document.getElementById(div).style.display="none";
}
function VisibleDiv(div)
{
	if(document.getElementById(div)!=null)
	document.getElementById(div).style.visibility="visible";
}

function unVisibleDiv(div)
{
	if(document.getElementById(div)!=null)
	document.getElementById(div).style.visibility="hidden";
}

function ShowMenu(div)
{
	ShowDiv(div);
	$("a.submenu").animate(
	{
		opacity: 1
	},
	100
	);
}

function HideMenu(div)
{
	$("#"+div).animate(
	{
		opacity: 0.01
	},
	100
	);
	setTimeout("HideDiv('"+div+"'),100");
}

//Проверка textarea на количестов символов
function isNotMax(e,div){
	e = e || window.event;
	var target = e.target || e.srcElement;
	var code=e.keyCode?e.keyCode:(e.which?e.which:e.charCode)
	if(target.value.length > target.getAttribute('maxlength')) target.value=target.value.substr(0,target.getAttribute('maxlength'))
	if(div!="empty")
	document.getElementById(div).innerHTML=target.value.length;
	return target.value.length <= target.getAttribute('maxlength');
}

function setScroll()
{
document.body.style.overflowX='auto';
}
function SetScroll()
{
document.body.style.overflowX='auto';
}

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 (window.sidebar) t = 'Netscape';
 return {type:t,version:v};
}

function bookmark(a){
// var id_connection=document.getElementById('code_connection_user').value;
 var url = window.document.location;
 var title = window.document.title;
 var b = getBrowserInfo();
 if (b.type == 'IE') window.external.AddFavorite(url,title);
 else if (b.type == 'Opera') {
  a.href = url;
  a.rel = "sidebar";
  a.title = title;
  return true;
 }
 else if (b.type == "Netscape") window.sidebar.addPanel(title,url,"");
 else alert("Нажмите CTRL-D, чтобы добавить страницу в закладки.");
// SM1(id_connection,'addfav');
 return false;
}

function HideMap()
{
	document.getElementById('stmap1').className="activ";
	document.getElementById('stmap2').className="";
	document.getElementById('stmap3').className="";
	document.getElementById('map').innerHTML="";
	document.getElementById('map').style.background="none";
}
    function LoadGoogle() {
	document.getElementById('stmap1').className="";
	document.getElementById('stmap2').className="activ";
	document.getElementById('stmap3').className="";
	var adress=document.getElementById('adressmap').value;
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map"));
				var customUI = new GMapUIOptions();
customUI.maptypes = {};
customUI.zoom = {};
customUI.controls = {};
customUI.maptypes.normal = true;
customUI.maptypes.hybrid = false;
customUI.zoom.doubleclick = true;
customUI.zoom.scrollwheel = false;
customUI.controls.largemapcontrol3d = true;
customUI.controls.menumaptypecontrol = false;
map.setUI(customUI);
		var geocoder = new GClientGeocoder();
        function showAddress(address) {
          geocoder.getLatLng(
          address,
          function(point) {
            if (!point) {
             alert(address + " not found");
              document.getElementById("map").style.display = 'none';
            } else {
			//aasalert(adress);
			        // Create our "tiny" marker icon
			 var blueIcon = new GIcon(G_DEFAULT_ICON);
			 var title = adress;
			 blueIcon.image = "/img/pointmap.png";
		     blueIcon.iconSize = new GSize(35, 38);			 
			 blueIcon.iconAnchor = new GPoint(19, 38);
			 blueIcon.shadow =null;
			 // Set up our GMarkerOptions object
			  markerOptions = {title:title,icon:blueIcon};
			  
              map.setCenter(new GLatLng(60.127828,29.929047), 11);
			  var marker = new GMarker(new GLatLng(60.188977,29.711536), markerOptions);
              
		    GEvent.addListener(marker, "click", function() {
            marker.openInfoWindowHtml(adress);
          });
		  map.addOverlay(marker);
            }
          }
          );

        } 
		showAddress(adress);
      }
    }
	
	var map;
function LoadYandex() {

	document.getElementById('stmap1').className="";
	document.getElementById('stmap2').className="";
	document.getElementById('stmap3').className="activ";
  map = new YMaps.Map( document.getElementById("map") );
  map.removeAllOverlays();  
  var place=document.getElementById("adressmap").value;
 var geocoder = new YMaps.Geocoder(place, {results: 1, boundedBy: map.getBounds()});
 YMaps.Events.observe(geocoder, geocoder.Events.Load, function () {
  
  if (this.length()) {
  var geoPoint=this.get(0).getGeoPoint();
  var s = new YMaps.Style();
    s.iconStyle = new YMaps.IconStyle();
    s.iconStyle.offset = new YMaps.Point(-19,-38);
    s.iconStyle.href = "/img/pointmap.png";
    s.iconStyle.size = new YMaps.Point(35, 38);
  
  map.setCenter(new YMaps.GeoPoint(29.951084,60.144189), 11, YMaps.MapType.MAP);
 var placemark = new YMaps.Placemark(new YMaps.GeoPoint(29.710039,60.188964),{style: s});
	placemark.name = place;
	//placemark.description = "Описание";
	map.addOverlay(placemark); 
 /* map.addControl(new YMaps.TypeControl());
  map.addControl(new YMaps.ToolBar());*/
  map.addControl(new YMaps.Zoom());
/*  map.addControl(new YMaps.MiniMap());
  map.addControl(new YMaps.ScaleLine());*/

  map.addOverlay(placemark);
  this.get(0).setBalloonContent(this.get(0).text);
 // this.get(0).openBalloon();

    } else {
    alert("Ничего не найдено")
      }
});
}	
