var middlepoint=null;
var count_point=0;
function SetPointOfAddress(map,geocoder,address,title,icontype,showinfotab)			
			{
  			geocoder.getLocations(address, 	geocoder.getLatLng(address,function(point){
				if (!point) 
						{
							adressarray=address.split(',');
							address=adressarray[0]+","+adressarray[1];
							zoom=11;
							SetPointOfAddress(map,geocoder,address,title,icontype,showinfotab);
							
						}
						else
						{
							var infoTabs = [new GInfoWindowTab("     ", "<b>"+title+"</b>"+'<DIV style="font-size:11px;">'+address+'</DIV>')];
							
							addMark(map,point,title,infoTabs,icontype,showinfotab);
							
						}
			
			}));
			}
			
function SetPointOfCor(map,geocoder,address,googlex,googley,title,icontype,showinfotab)			
			{
  			var point;
  			point=new GLatLng(googlex,googley)
				if (!point) 
						{
							zoom=11;
							SetPointOfAddress(map,geocoder,address,title,icontype,showinfotab);	
						}
						else
						{
							var infoTabs = [new GInfoWindowTab("     ", "<b>"+title+"</b>"+'<DIV style="font-size:11px;">'+address+'</DIV>')];
							
							addMark(map,point,title,infoTabs,icontype,showinfotab);
							
						}  			
			}
						
									function addMark(map,point,title,infoTabs,icontype,showinfotab)
									{
										
										if (icontype==4)   
										{
											var marker = CreateMarkerCenter(point,title);//new GMarker(point);
										}
										if (icontype==0)   
										{
											var marker = CreateMarkerShop(point,title);//new GMarker(point);
										}							
										if (icontype==1)   
										{
											var marker = CreateMarkerShop(point,title);//new GMarker(point);
										}							
										if (icontype==2)   
										{
											var marker = CreateMarkerShop(point,title);//new GMarker(point);
										}														
										if (icontype==3)   
										{
											var marker = CreateMarkerNetShop(point,title);//new GMarker(point);
										}	
										if (icontype==5)   
										{
											var marker = CreateMarker(point,title);//new GMarker(point);
										}
										GEvent.addListener(marker, "click", function() {marker.openInfoWindowTabsHtml(infoTabs);});
										map.addOverlay(marker);
											var points=ExtractPoint(point);
											var ext_middlepoint=ExtractPoint(middlepoint);
											if(ext_middlepoint[0]>0)
											{
												ext_middlepoint[0]=(ext_middlepoint[0]+points[0])/2;	
												count_point=count_point+1;
											}
											else
											{
												ext_middlepoint[0]=points[0];
											}
											if(ext_middlepoint[1]>0)
											{
												ext_middlepoint[1]=(ext_middlepoint[0]+points[1])/2;	
												count_point=count_point+1;
											}
											else
											{
												ext_middlepoint[1]=points[1];
											}
										middlepoint=new GLatLng(ext_middlepoint[0],ext_middlepoint[1]);
										if(showinfotab)
										{
											marker.openInfoWindowTabsHtml(infoTabs);
											
										}
									}
									function CreateMarkerShop(point, texts, ids) 
									{
												var myicon = new GIcon();
												myicon.image = "icon/icon_shop.png";
												myicon.shadow = "icon/icon_shop.png";
												myicon.iconSize = new GSize(18,15);
												myicon.shadowSize = new GSize(18,15);
												myicon.iconAnchor = new GPoint(18,15);
												myicon.infoWindowAnchor = new GPoint(10,7);
												var title = "";
												if(title)
												{ 
													title = texts; 
												}
												var marker = new GMarker(point,{"icon":myicon,"title":title});
												GEvent.addListener(marker, "click", function() 
												{
													//showAddressNoZoom(ids);
												});
												
												return marker;
									}
									function CreateMarker(point, texts, ids) 
									{
												var myicon = new GIcon();
												var title = "";
												if(title)
												{ 
													title = texts; 
												}
												var marker = new GMarker(point,{"title":title});
												GEvent.addListener(marker, "click", function() 
												{
													//showAddressNoZoom(ids);
												});
												
												return marker;
									}									
									function CreateMarkerManufacturer(point, texts, ids) 
									{
												var myicon = new GIcon();
												myicon.image = "icon/icon_manufact.png";
												myicon.shadow = "icon/icon_manufact.png";
												myicon.iconSize = new GSize(18,15);
												myicon.shadowSize = new GSize(18,15);
												myicon.iconAnchor = new GPoint(18,15);
												myicon.infoWindowAnchor = new GPoint(10,7);
												var title = "";
												if(title)
												{ 
													title = texts; 
												}
												var marker = new GMarker(point,{"icon":myicon,"title":title});
												GEvent.addListener(marker, "click", function() 
												{
													//showAddressNoZoom(ids);
												});
												
												return marker;
									}	
									function CreateMarkerNetShop(point, texts, ids) 
									{
												var myicon = new GIcon();
												myicon.image = "icon/icon_net_shop.png";
												myicon.shadow = "icon/icon_net_shop.png";
												myicon.iconSize = new GSize(18,15);
												myicon.shadowSize = new GSize(18,15);
												myicon.iconAnchor = new GPoint(18,15);
												myicon.infoWindowAnchor = new GPoint(10,7);
												var title = "";
												if(title)
												{ 
													title = texts; 
												}
												var marker = new GMarker(point,{"icon":myicon,"title":title});
												GEvent.addListener(marker, "click", function() 
												{
													//showAddressNoZoom(ids);
												});
												
												return marker;
									}
									function CreateMarkerCenter(point, texts, ids) 
									{
												var myicon = new GIcon();
												myicon.image = "icon/icon_center.png";
												myicon.shadow = "icon/icon_center.png";
												myicon.iconSize = new GSize(18,15);
												myicon.shadowSize = new GSize(18,15);
												myicon.iconAnchor = new GPoint(18,15);
												myicon.infoWindowAnchor = new GPoint(10,7);
												var title = "";
												if(title)
												{ 
													title = texts; 
												}
												var marker = new GMarker(point,{"icon":myicon,"title":title});
												GEvent.addListener(marker, "click", function() 
												{
													//showAddressNoZoom(ids);
												});
												
												return marker;
									}
									function CreateMap(div,center_x,center_y)
									{
										var map=null; 
										if (GBrowserIsCompatible()) 
      										{
      											        map = new GMap2(document.getElementById(div));
														map.setCenter(new GLatLng(center_x,center_y), zoom, G_NORMAL_MAP);
														map.addControl(new GLargeMapControl());
														map.addControl(new GMapTypeControl());
														map.addControl(new GScaleControl());
														map.enableDoubleClickZoom();
														var geocoder = new GClientGeocoder();
															var count=adress_list.length;
															for(i=1;i<count;i++)
															{
																if(count==2)
																{
																	var showinfotab=true;
																	zoom=13;
																}
																else
																{
																	var showinfotab=false;
																	zoom=10;
																}
																if(adress_list[i][0]!='')
																{
																 if(adress_list[i][4]==1)	
																 {
																	if(adress_list[i][5]>0&&adress_list[i][6]>0&&0)
																	{
																		SetPointOfCor(map,geocoder,adress_list[i][0],adress_list[i][5],adress_list[i][6],'<a href="/shop.php?id='+adress_list[i][3]+'" style="font-size:12px;font-weight:bold;color:blue;" target="_blank">'+adress_list[i][1]+'</a>',adress_list[i][2],showinfotab);								
																	}
																	else
																	{
																 		SetPointOfAddress(map,geocoder,adress_list[i][0],'<a href="/shop.php?id='+adress_list[i][3]+'" style="font-size:12px;font-weight:bold;color:blue;" target="_blank">'+adress_list[i][1]+'</a>',adress_list[i][2],showinfotab);
																	}	
																	
																 }
																 else
																 {
																 	//alert(adress_list[i][4]);
																 }
																} 
															}
															if(count==1)
															{
																//middlepoint=new GLatLng(ext_middlepoint[0],ext_middlepoint[1]);
																//map.setCenter(middlepoint, 9, G_NORMAL_MAP);
															}

														
      										}
      										return map;
									}

function load(adress,title,icontype) 
{
 var map=CreateMap("map",55.699816,37.761709);
	/*if (GBrowserIsCompatible()) 
      {
        var map = new GMap2(document.getElementById("map"));
		map.setCenter(new GLatLng(55.753008661974164, 37.62062072753906), 10, G_NORMAL_MAP);
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		map.addControl(new GScaleControl());
		map.enableDoubleClickZoom();
		
		
		  	var geocoder = new GClientGeocoder();
  			address="Россия, "+adress;
  			
			function SetPoint(address,zoom)			
			{
  			geocoder.getLocations(address, 	geocoder.getLatLng(address,function(point){
				if (!point) 
						{
							adressarray=address.split(',');
							address=adressarray[0]+","+adressarray[1];
							SetPoint(address,10);
						}
						else
						{
							addMark(point,title,address,zoom);
						}
			
			}));
			}
			SetPoint(address,16);
      }*/
}

function ExtractPoint(point)
{
	var middle_points= new Array(null,null)
	if(point!=null)
	{
		var str_point=point.toString();
		str_point=str_point.replace('(','');
		str_point=str_point.replace(')','');
		middle_points=str_point.split(',');
		return middle_points;
	}
	else
	{
		return middle_points;	
	}
}

									function b()
									{
										return 0;
									}
function CreateHTMLListShops($list)
{
var count=$list.length;	
var table='';
	table='<TABLE width=100% align=left >';
	for(i=1;i<count;i++)
	{
		if($list[i][0]!='')
		{
			table=table+'<TR><TD><DIV style="margin-bottom:5px;font-size:10px;">'+i+': <a href="/shop.php?id='+$list[i][3]+'" style="font-size:12px;color:blue;" target="_blank">'+$list[i][1]+'</a></DIV><div style="font-size:11px;">'+$list[i][0]+'</DIV></TD></TR>';	
		}
	}
	table=table+'</TABLE>';
	return table;
}
