
function MMBikeToolWindow()
{	
	this.selectedRoute;
}
MMBikeToolWindow.prototype = new MMToolWindow("<center>Routen nach Wunsch Einstellungen</center>", 290, /*407*/380, true); //200, 250


/**
 * displays the Window with current route properties
 */
MMBikeToolWindow.prototype.show = function(route)
{
	this.selectedRoute = route;
	
	if(this.listener)GEvent.removeListener(this.listener);
	this.listener = GEvent.bind(this.selectedRoute, "remove", this, this.hideWindow);
	
	// Initialize State		
	this.SetDifficulty(this.selectedRoute.GetDifficulty());
	this.SetSurface(this.selectedRoute.GetSurface());
	this.SetUseElevation(this.selectedRoute.GetUseElevation());
	this.SetTraffic(this.selectedRoute.GetTraffic());
	this.showWindow();
}


MMBikeToolWindow.prototype.initializeContent = function(content)
{

	//content.style.font = "11px verdana";
	content.style.fontFamily = "arial, sans-serif";
	content.style.fontSize = "11px";
	
	content.innerHTML = ''
	+'<form action="#" name="form" id="form">'
	+''	
	+'<table style="padding-left:5px;padding-right:15px;" width="100%" border="0" cellspacing="0" cellpadding="0"><tr>'
	+'<td colspan="2"><strong>Charakter der Tour</strong></td></tr>'	
	+'<tr><td colspan="1" style="width:220px;"><select name="surfacecondition" id="surf" >'
	+'<option value="0" >keine Einschr&auml;nkung</option>'
	+'<option value="10">Rennradroute</option>'
	+'<option value="20">Tourenradroute</option>'
	+'<option value="30">Mountainbikeroute</option>'
	+'</select></td>'
	+'<td colspan="1"><a href="hilfe_attribute.php#1" target="_BLANK"><img src="dateien/grey_i.png" border="0" /></a></td>'
	+'</tr>'
	+'<tr><td colspan="2">'
	+'</td></tr><tr style="display:none"><td colspan="2"><table><tr><td valign="top"><input type="checkbox" id="fern"  name="fern"  disabled="disabled" /></td><td>Strecken auf Radfernwegen bevorzugen</td></tr></table>'
	+'</td></tr><tr style="display:none"><td colspan="2"><table><tr><td valign="top"><input type="checkbox" id="regio" name="regio" disabled="disabled" /></td><td>Strecken auf regionalen Touren bevorzugen</td></tr></table>'
	+'</td></tr><tr><td colspan="2"><table><tr><td             ><input type="checkbox" id="umweg" name="umweg" disabled="disabled" /></td><td>Zur Vermeidung von Umwegen auch schlechtere Oberfl&auml;chen zulassen</td></tr></table>'
	+'</td></tr>'
	+'</table>'
	
	+'<table style="padding-left:5px;padding-right:15px;" width="100%" border="0" cellspacing="0" cellpadding="0"><tr>'
	+'<td colspan="1" style="width:220px;"><strong>Maximaler Schwierigkeitsgrad</strong></td>'
	+'<td colspan="1"><a href="hilfe_attribute.php#3" target="_BLANK"><img src="dateien/grey_i.png" border="0" /></a></td></tr>'
	+'<tr><td colspan="2"><select name="difficulty" id="dif" >'
	+'<option value="0">keine Einschr&auml;nkung</option>'
	+'<option value="10">Leicht</option>'
	+'<option value="20">Mittel</option>'
	+'<option value="30">Schwer</option>'
	+'<option value="40">Sportlich</option>'
	+'</select></td>'
	+'</tr><tr><td colspan="2"><table><tr><td><input type="checkbox" id="elevation" name="elevation" /></td><td>Route mit m&ouml;glichst wenigen H&ouml;henmetern bergauf suchen</td></tr></table>'
	+'</td></tr></table>'
	
	+'<table style="padding-left:5px;padding-right:15px;" width="100%" border="0" cellspacing="0" cellpadding="0"><tr>'
	+'<td colspan="1" style="width:220px;"><strong>Verkehrsbelastung</strong></td>'
	+'<td colspan="1"><a href="hilfe_attribute.php#4" target="_BLANK"><img src="dateien/grey_i.png" border="0" /></a></td></tr>'
	+'<tr><td colspan="2">'
	+'</td></tr><tr><td colspan="2"><table><tr><td valign="top"><input type="radio" id="traf1" name="traf" checked /></td><td>Nur Strecken ohne bzw. mit geringer Verkehrsbelastung suchen</td></tr></table>'
	+'</td></tr><tr><td colspan="2"><table><tr><td valign="top"><input type="radio" id="traf2" name="traf" /></td><td>M&auml;&szlig;ig befahrene Stra&szlig;en zulassen, wenn damit Umwege vermieden werden</td></tr></table>'
	+'</td></tr><tr><td colspan="2"><table><tr><td valign="top"><input type="radio" id="traf3" name="traf" /></td><td>Stark und m&auml;&szlig;ig befahrene Stra&szlig;en zulassen, wenn damit Umwege vermieden werden</td></tr></table>'
	+'</td></tr>'
	+'</table>'
	+'<center><input id="bikeSubmit" style="width:142px;" type="button" value="Route neu berechnen" /><center>		'
	+'</form>'; 
		
	GEvent.bindDom(document.getElementById("surf"),       "change", this, this.onCharakterChange);
	GEvent.bindDom(document.getElementById("bikeSubmit"), "click", this, this.onSubmitBikeForm);	
		
}



MMBikeToolWindow.prototype.onCharakterChange = function(){
	var character;
	character = document.getElementById("surf");
	//alert(character.value);
	if(character.value== 0 || character.value== 20) document.getElementById("umweg").disabled=false;
	else document.getElementById("umweg").disabled=true;
	
	
}


MMBikeToolWindow.prototype.onSubmitBikeForm = function(){	
	
	// set routing properties
	this.selectedRoute.SetOpnv(false);
	this.selectedRoute.SetDifficulty(this.GetDifficulty());
	if(document.getElementById("umweg").checked)this.selectedRoute.SetSurface(25);
	else this.selectedRoute.SetSurface(this.GetSurface());
	this.selectedRoute.SetUseElevation(this.GetUseElevation());
	
	this.selectedRoute.SetTraffic(this.GetTraffic());
	
	// DEBUG
	// if(document.getElementById("umweg").checked)alert("dif:"+this.GetDifficulty()+" - surf:25 - elev:"+this.GetUseElevation()+" - traf:"+this.GetTraffic())
	// else alert("dif:"+this.GetDifficulty()+" - surf:"+this.GetSurface()+" - elev:"+this.GetUseElevation()+" - traf:"+this.GetTraffic())
	
	// refresh
	this.selectedRoute.load();
	return false;
}

/**
 * Gets UseElevation to DockingWindow
 */
MMBikeToolWindow.prototype.GetUseElevation = function(){	
	if(document.getElementById("elevation").checked) return true;
	else return false;
}


/**
 * Sets UseElevation to DockingWindow
 */
MMBikeToolWindow.prototype.SetUseElevation = function(bool){	
	var elevation = document.getElementById("elevation");	
	elevation.checked = bool;
}


/**
 * Sets Difficulty to DockingWindow
 */
MMBikeToolWindow.prototype.SetDifficulty = function(difficulty){		
	document.form.difficulty.value = difficulty;
	//alert(document.form.difficulty.value);
}


/**
 * Read Difficulty from DockingWindow
 */
MMBikeToolWindow.prototype.GetDifficulty = function(){
	return document.form.difficulty.value;
}



/**
 * Sets Surface to DockingWindow
 */
MMBikeToolWindow.prototype.SetSurface = function(surface){
	document.form.surfacecondition.value = surface;
	if(surface==0||surface==20)document.getElementById("umweg").disabled=false;
}


/**
 * Read Surface from DockingWindow
 */
MMBikeToolWindow.prototype.GetSurface = function(){
	return document.form.surfacecondition.value;
}


MMBikeToolWindow.prototype.SetTraffic = function(traffic){
	switch(traffic){
		case(1):	document.form.traf[0].checked = true;
					document.form.traf[1].checked = false;
					document.form.traf[2].checked = false; break;
		case(2):	document.form.traf[0].checked = false;
					document.form.traf[1].checked = true;
					document.form.traf[2].checked = false; break;
		case(3):	document.form.traf[0].checked = false;
					document.form.traf[1].checked = false;
					document.form.traf[2].checked = true;  break;
		default: 	document.form.traf[0].checked = true;
					document.form.traf[1].checked = false;
					document.form.traf[2].checked = false; break;
		break;
	}
}

MMBikeToolWindow.prototype.GetTraffic = function(){
	//alert(document.getElementById("traf3").value);
	if(document.form.traf[0].checked)return 1;
	if(document.form.traf[1].checked)return 2;
	if(document.form.traf[2].checked)return 3;
}

