

function ajax_google_Get_tabs(Map_lat,Map_lng){

	var tabs = _Ajax.syncPost('ajax_google_Get_tabs', {
		lat : Map_lat,
		lng : Map_lng,
		Project_name : _Project.name,
		Project_lang : _Project.lang
	});

	var	infotabs = new Array();
	infotabs.push(new GInfoWindowTab(tabs[0]['tabname'],tabs[0]['tabcontent'] ));
	if(tabs[1]['tabcontent'] != '')
	{
		infotabs.push(new GInfoWindowTab(tabs[1]['tabname'],tabs[1]['tabcontent'] ));
	}
	infotabs.push(new GInfoWindowTab(tabs[2]['tabname'],tabs[2]['tabcontent'] ));

	return infotabs;
}


function ajax_google_Get_point_mouseover(Map_lat,Map_lng){

	var tab = _Ajax.syncPost('ajax_google_Get_point_mouseover', {
		lat : Map_lat,
		lng : Map_lng,
		Project_name : _Project.name,
		Project_lang : _Project.lang
	});

	return tab;
}




function ajax_google_Get_NextPoint(Map_lat,Map_lng){

	var fi1 = 'false'; var fi2 = 'false'; var fi3 = 'false'; var fi4 = 'false'; var fi5 = 'false'; var fi6 = 'false'; var fi7 = 'false'; var fi8 = 'false';

	if(document.getElementById('service-fi1')){fi1 = document.getElementById('service-fi1').checked;};
	if(document.getElementById('service-fi2')){fi2 = document.getElementById('service-fi2').checked;};
	if(document.getElementById('service-fi3')){fi3 = document.getElementById('service-fi3').checked;};
	if(document.getElementById('service-fi4')){fi4 = document.getElementById('service-fi4').checked;};
	if(document.getElementById('service-fi5')){fi5 = document.getElementById('service-fi5').checked;};
	if(document.getElementById('service-fi6')){fi6 = document.getElementById('service-fi6').checked;};
	if(document.getElementById('service-fi7')){fi7 = document.getElementById('service-fi7').checked;};
	if(document.getElementById('service-fi8')){fi8 = document.getElementById('service-fi8').checked;};

	var tabs = _Ajax.syncPost('ajax_google_Get_NextPoint', {
		lat : Map_lat,
		lng : Map_lng,
		fi1 : fi1,
		fi2 : fi2,
		fi3 : fi3,
		fi4 : fi4,
		fi5 : fi5,
		fi6 : fi6,
		fi7 : fi7,
		fi8 : fi8,
		Project_name : _Project.name,
		Project_lang : _Project.lang
	});


	if (tabs)
	{
		if(document.getElementById('gmapInfo') && gmapInfo.getAttribute('distance'))
		{
			gmapInfo = document.getElementById('gmapInfo');
			distanceText = gmapInfo.getAttribute('distance');
			gmapInfo.innerHTML = distanceText+' '+Math.round((tabs[5]['distance']/1000))+' km Luftlinie';

		};

		var	infotabs = new Array();
		infotabs.push(new GInfoWindowTab(tabs[0]['tabname'],tabs[0]['tabcontent'] ));
		if(tabs[1]['tabcontent'] != '')
		{
			infotabs.push(new GInfoWindowTab(tabs[1]['tabname'],tabs[1]['tabcontent'] ));
		}
		infotabs.push(new GInfoWindowTab(tabs[2]['tabname'],tabs[2]['tabcontent'] ));

		var point =  new GLatLng(tabs[3]['lat'],tabs[3]['lng']);

		var ret = new Array();
		ret[0] = infotabs;
		ret[1] = point;
		ret[2] = tabs[4]['id'];

		return ret;
	} else {
		return false;
	}
}


function GmapOpenRoute(id,type)
{
	var startid = 'saddr_'+id;
	var zielid  = 'daddr_'+id;
	var start   = ', '+gmap_country;
	var ziel    = document.getElementById(zielid).value;
	
	if (document.getElementById(startid)){
		start = document.getElementById(startid).value+', '+gmap_country;
	}

	if(start ==', '+gmap_country){
		
		startid = 'route_input';
		if (document.getElementById(startid)){
			start = document.getElementById(startid).value;
		}
		if(start ==', '+gmap_country){
		alert('Bitte geben Sie eine Startadresse ein.');
		return false;
		}
	}
	// prüfen ob adresse existiert
	geocoder.getLatLng(
	start,
	function(point) {
		if (!point) {
			alert(start + " konnte nicht gefunden werden, bitte kontrollieren Sie Ihre Eingabe");

		}
		else {

			if(type == 1){
				window.open('http://maps.google.de/?saddr='+start+'&daddr='+ziel, 'googleMapsRoute');
			}
			else {
				map.clearOverlays()


				var _Route = _Ajax.syncPost('ajax_google_Get_Route', {
					pid : id,
					start : start,
					land : gmap_country,
					Project_name : _Project.name,
					Project_lang : _Project.lang
				});


				hs.htmlExpand(document.getElementById('Google_Map_show_route_div'),{ contentId: 'Google_Map_show_route' , align: 'center', width: 700 , height: 600, preserveContent:false} );
				document.getElementById('Route_Content').innerHTML = _Route[0];

				eval(_Route[1]);

			}
		}

	}
	);


}


function CopyGmap(old_id,new_id)
{

	var old_map = document.getElementById(old_id).innerHTML;
	document.getElementById(new_id).innerHTML = old_map;
};



function ajax_google_Get_all_Points(){

	var points = _Ajax.syncPost('ajax_google_Get_all_Points', {
		Project_name : _Project.name,
		Project_lang : _Project.lang

	});
	eval(points);

	PMapPoints.showCategory('');
	map.savePosition();

	return true;
}

function Get_GMapPoints(){

	var cats = [];

	if(_Filter.length > 0){
		for(var i = 0, len = _Filter.length; i < len; i++)
		{
			if(document.getElementById('service-'+_Filter[i]).checked == true){cats.push(_Filter[i]);}
		}
	}

	map.clearOverlays();

	PMapPoints.showCategory(cats);

	if(gmap_show_dropdownfilter == true)
	{
		document.getElementById('selectstandort_div').innerHTML = Locater_selectstandort_html;
		var parent = document.getElementById('Locater-selectstandort');

		var sel = parent.options;
		var check = true;
		var del = new Array();
		for(var i = 0, len = sel.length; i < len; i++)
		{
			check = true;
			for(var c = 0, len2 = cats.length; c < len2; c++)
			{
				if(sel[i].getAttribute(cats[c]) == 1 && check == true)
				{
					check = true;
				} else
				{
					check = false;
				};
			}

			if(!check)
			{
				del.push(sel[i])
			};
		}

		for(var i = 0, len = del.length; i < len; i++)
		{
			parent.removeChild(del[i]);
		}
	}

	return true;
}


function GMapPoints( settings )
{
	this.points = new Array();
	var map = null;


	if(settings.image)
	{
		image = settings.image;
	}

	if(settings.map)
	{
		map = settings.map;
	}

	// Punkt hinzufügen
	this.appendChild = function( Point, Cat, Title )
	{

		this.points.push( {p:Point, c: Cat , t:Title} );
	}

	this.showCategory = function( cats )
	{


		var check = true;

		var p = this.points;

		for(var i = 0, len = p.length; i < len; i++)
		{
			if(cats.length != 0)
			{
				check = true;

				for(var c = 0, len2 = cats.length; c < len2; c++)
				{
					if(p[i].c[ cats[c] ] == true && check == true)
					{

						check = true;
					} else
					{
						check = false;
					}
				}
			}

			if(check)
			{

				map.addOverlay( createTabsMarker(p[i].p, image, p[i].t) );
				bounds.extend(p[i].p);
			}
		}
		//alert(bounds.getCenter());
		map.setCenter(new GLatLng(google_def_lat,google_def_lng),  6)
	}
}



function GmapPrint(mapid){

	var pw = window.open("about:blank", "karte_drucken", "width=700, height=700");
	pw.document.open();
	pw.document.write(GmapGetMapHtml(mapid));
	pw.document.close();
	return false;
};

function GmapGetMapHtml(mapid)
{

	map.hideControls(mapid);
	var body = document.getElementById(mapid).innerHTML;
	map.showControls();


	return "<html>\n" +
	"<head>\n" +
	"<title>Route Drucken</title>\n" +
	"<script>\n" +"function step1() {\n" +
	"  setTimeout(\'step2()\', 10);\n" +
	"}\n" +
	"function step2() {\n" +
	"  window.print();\n" +
	"  window.close();\n" +
	"}\n" +
	"</scr" + "ipt>\n" +
	"</head>\n" +
	"<body onLoad=\'step1()\'>\n" +
	"<div id ='"+mapid+"' style='width: 680px; height: 680px; position: relative; background-color: rgb(229, 227, 223);' >"+
	body+
	"</div>"+
	"</body>\n" +
	"</html>\n";
};



