var cook_expires=new Date();cook_expires.setTime(cook_expires.getTime()+(30*24*60*60*1000));function SetCookie(name,value,path){document.cookie=name+"="+escape(value)+
((cook_expires==null)?"":("; expires="+cook_expires.toGMTString()))+"; path="+path;}
function getCookieVal(offset){var endstr=document.cookie.indexOf(";",offset);if(endstr==-1)endstr=document.cookie.length;return unescape(document.cookie.substring(offset,endstr));}
function GetCookie(name){var arg=name+"=";var alen=arg.length;var clen=document.cookie.length;var i=0;while(i<clen){var j=i+alen;if(document.cookie.substring(i,j)==arg)return getCookieVal(j);i=document.cookie.indexOf(" ",i)+1;if(i==0)break;}
return null;}
var ymap_loaded=new Array();var ymap_visible=new Array();var ymap_points=new Array();var ymap_placemarks=new Array();var ymap_bounds;function ymap_show_hide(id,gps){if(ymap_visible[id]==1){document.getElementById('ymap_title_'+id).innerHTML='показать на карте';document.getElementById('ymap_canvas_'+id).style.display='none';document.getElementById('ymap_canvas_'+id).style.width='0px';document.getElementById('ymap_canvas_'+id).style.height='0px';document.getElementById('ymap_canvas_'+id).style.margin='0px';ymap_visible[id]=0;}
else{document.getElementById('ymap_title_'+id).innerHTML='скрыть карту';document.getElementById('ymap_canvas_'+id).style.display='block';document.getElementById('ymap_canvas_'+id).style.height='300px';document.getElementById('ymap_canvas_'+id).style.width='100%';ymap_visible[id]=1;if(ymap_loaded[id]==undefined){ymap(id,gps);ymap_loaded[id]=1;}}}
function ymap(id,gps){var map=new YMaps.Map(document.getElementById('ymap_canvas_'+id));var GeoPoint;if(gps.length>5){var address=gps.split(',');var gps2=address[1]+','+address[0];GeoPoint=new YMaps.GeoPoint(address[0],address[1]);show_map(id,map,GeoPoint);}
else{var address=document.getElementById('ymap_adr_'+id).innerHTML;var geocoder=new YMaps.Geocoder(address);YMaps.Events.observe(geocoder,geocoder.Events.Load,function(){if(this.length()){GeoPoint=this.get(0).getGeoPoint();show_map(id,map,GeoPoint);}else{alert("Ничего не найдено")}});YMaps.Events.observe(geocoder,geocoder.Events.Fault,function(error){alert("Произошла ошибка: "+error.message)});}}
function show_map(id,map,GeoPoint){var zoomControl=new YMaps.Zoom({customTips:[{index:1,value:"Мелко"},{index:9,value:"Средне"},{index:16,value:"Крупно"}]});map.setCenter(GeoPoint);map.setZoom(15);map.addControl(zoomControl);var placemark=new YMaps.Placemark(GeoPoint);placemark.name='\<b\> '+document.getElementById('ymap_firmname_'+id).innerHTML+'\<\/b\>';placemark.description='\<br\>адрес: \<b\> '+document.getElementById('ymap_adr_'+id).innerHTML+'\<\/b\>\<br\>телефоны:\<b\> '+document.getElementById('ymap_phone_'+id).innerHTML+'\<\/b\>';map.addOverlay(placemark);placemark.openBalloon();}
function add_ypoint(map,id,gps){var GeoPoint=0;if(gps.length>5){var address=gps.split(',');GeoPoint=new YMaps.GeoPoint(address[1],address[0]);}
else{var address=document.getElementById('ymap_adr_'+id).innerHTML;var geocoder=new YMaps.Geocoder(address);YMaps.Events.observe(geocoder,geocoder.Events.Load,function(){if(this.length()){ymap_points.push(this.get(0).getGeoPoint());ymap_bounds=new YMaps.GeoCollectionBounds(ymap_points);map.setBounds(ymap_bounds);}});}}
