/************************************************************\
*
\************************************************************/

function addParticipant() {
	var participants = document.getElementById("participants");
	num_participants++;
	if ( num_participants <= maxp ) {
		var html = "span".t([
				"label".t("Teilnehmer "+num_participants+":"),
				"input".a("name","participants1[]").a("type","text").a("size","20").t(),
				"input".a("name","participants2[]").a("type","text").a("size","20").t(),
				"br".t()
			]);
		"participants".id(html);
		document.getElementById("nump").value = num_participants;
	} else {
		alert("Es können keine weiteren Teilnehmer hinzugefügt werden.");
	}
	
}

function switchdisplay(el) {
	var element = document.getElementById(el);
	if ( element.style.display == 'block' ) {
		element.style.display = 'none';
	} else {
		element.style.display = 'block';
	}

	
}


var tinyMCEmode = true;
function toogleEditorMode(sEditorID) {
    try {
        if(tinyMCEmode) {
            tinyMCE.removeMCEControl(tinyMCE.getEditorId(sEditorID));
            tinyMCEmode = false;
        } else {
            tinyMCE.addMCEControl(document.getElementById('pagecontent'), sEditorID);
            tinyMCEmode = true;
        }
    } catch(e) {
        //error handling
    }
}


function chkFormular() {
    return false;
 }
 
 
function showAddress(address,map,html,zoom) {

	if (geocoder) {
	
	geocoder.getLatLng(
	  address,
	  function(point) {
	    if (!point) {
	      
	      showAddress(location_str + ', ' + location_city + ', Germany',map,1,13);
	    } else {
	      map.setCenter(point, zoom);
	      var marker = new GMarker(point);
	      map.addOverlay(marker);
	      if ( html ) { 
	      	marker.openInfoWindowHtml('<span class="style3" style="font-size: 10pt;"><b>' + location_name + '</b><br />' + location_str + ', ' + location_plz + ' ' + location_city + '</span>');
	      }
	    }
	  }
	);
	}
}
    

var map;
var map1;
var map2;
var map3;
var gdir;
var gdir1;
var gdir2;
var gdir3;
var geocoder = null;
var addressMarker;
var fromAddress;
var toAddress;
var locale = "de";

function initialize() {
	map = new google.maps.Map2(document.getElementById("map"));
	map.addControl(new GSmallMapControl());
	map.addControl(new GMapTypeControl());
	map.setCenter(new GLatLng(49, 9), 8);
        gdir = new GDirections(map, document.getElementById("directions"));
        GEvent.addListener(gdir, "load", onGDirectionsLoad);
        GEvent.addListener(gdir, "error", handleErrors);
	geocoder = new GClientGeocoder();
}


function initializeS() {
	map = new google.maps.Map2(document.getElementById("map"));
	map.addControl(new GSmallMapControl());
	map.addControl(new GMapTypeControl());
	map.setCenter(new GLatLng(49, 9), 8);
        gdir = new GDirections(map, document.getElementById("directions"));
        GEvent.addListener(gdir, "load", onGDirectionsLoad);
        GEvent.addListener(gdir, "error", handleErrors);
	geocoder = new GClientGeocoder();
	showMap(); showAddress(address,map,1,13);
}


function initializePrint() {
	map1 = new google.maps.Map2(document.getElementById("map1"));
	map1.addControl(new GSmallMapControl());
	map1.addControl(new GMapTypeControl());
	map1.setCenter(new GLatLng(49, 9), 8);
	gdir = new GDirections(map1, document.getElementById("directions"));

	map2 = new google.maps.Map2(document.getElementById("map2"));
	map2.addControl(new GSmallMapControl());
	map2.addControl(new GMapTypeControl());
	map2.setCenter(new GLatLng(49, 9), 8);
	
	map3 = new google.maps.Map2(document.getElementById("map3"));
	map3.addControl(new GSmallMapControl());
	map3.addControl(new GMapTypeControl());
	map3.setCenter(new GLatLng(49, 9), 8);	
        
        GEvent.addListener(gdir, "load", onGDirectionsLoad);
        GEvent.addListener(gdir, "error", handleErrors);
	geocoder = new GClientGeocoder();
	
	showAddress(address,map3,0,15); 
	showAddress(fromAddress,map2,0,15); 
	setDirections(fromAddress,map1)
}

function saveAdress(fromAddress){
	if ( document.getElementById('saveAddress').checked == true ) {
		fromAddress = document.getElementById('fromAddress').value;	
		Delete_Cookie('fromaddress','/', '');
		Set_Cookie('fromaddress', fromAddress, 30, '/', '', '' );
	}
}



function setDirections(fromAddress, map) {
	fromAddress = document.getElementById('fromAddress').value;
	showAddress(address,map,1,13);
	gdir.load("from: " + fromAddress + " to: " + address,
		{ "locale": locale });
}

    function handleErrors(){
	   if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
	     alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + gdir.getStatus().code);
	   else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
	     alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code);
	   
	   else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
	     alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);

	//   else if (gdir.getStatus().code == G_UNAVAILABLE_ADDRESS)  <--- Doc bug... this is either not defined, or Doc is wrong
	//     alert("The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual reasons.\n Error code: " + gdir.getStatus().code);
	     
	   else if (gdir.getStatus().code == G_GEO_BAD_KEY)
	     alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);

	   else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
	     alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);
	    
	   else alert("An unknown error occurred.");
	   
	}
	
	function onGDirectionsLoad(){ 
      // Use this function to access information about the latest load()
      // results.

      // e.g.
      // document.getElementById("getStatus").innerHTML = gdir.getStatus().code;
	  // and yada yada yada...
	}
	
var maphidden = true;	
function showMap() {
	if ( maphidden ) {
		maphidden = false;
		mapDIV.className="show";
	}
}

function hideMap() {
	if ( !maphidden ) {
		maphidden = true;
		mapDIV.className= "hiddenA";
	}
}


function openPrintWindow(url) {
	var printwindow = window.open(url,'printwindow','menubar=yes,scrollbars=yes,resizable=yes,width=900,height=650');
	printwindow.focus();
}



function Set_Cookie( name, value, expires, path, domain, secure ) 
{
var today = new Date();
today.setTime( today.getTime() );

if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
( ( path ) ? ";path=" + path : "" ) + 
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}

function Delete_Cookie( name, path, domain ) {
if ( Get_Cookie( name ) ) document.cookie = name + "=" +
( ( path ) ? ";path=" + path : "") +
( ( domain ) ? ";domain=" + domain : "" ) +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

function Get_Cookie( name ) {
	
var start = document.cookie.indexOf( name + "=" );
var len = start + name.length + 1;
if ( ( !start ) &&
( name != document.cookie.substring( 0, name.length ) ) )
{
return null;
}
if ( start == -1 ) return null;
var end = document.cookie.indexOf( ";", len );
if ( end == -1 ) end = document.cookie.length;
return unescape( document.cookie.substring( len, end ) );
}
