
function MMOpnvToolWindow()
{	
	this.selectedRoute;	
	this.listener = null;
	//&#214;ffentlicher&nbsp;Nahverkehr
}
MMOpnvToolWindow.prototype = new MMToolWindow("VVS Stuttgart", 200,245, true);


/**
 * displays the Window with current route properties
 */
MMOpnvToolWindow.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.SetTransportation(
	    this.selectedRoute.GetRegionalbahn(),
	    this.selectedRoute.GetSbahn(),
	    this.selectedRoute.GetUbahn(),
	    this.selectedRoute.GetBus() );
	    
	this.SetTime(
	    this.selectedRoute.GetTime(),
	    this.selectedRoute.TimeIsDeparture() );
	    
	this.showWindow();
}


MMOpnvToolWindow.prototype.initializeContent = function(content)
{

	//content.style.font = "11px verdana";
	content.style.fontFamily = "arial, sans-serif";
	content.style.fontSize = "11px";	
	
	content.innerHTML = ''
		+'<form action="#">'
	
	+    '<table width="100%" border="0" cellspacing="0" cellpadding="0">'	
	+    '<tr>'
	+        '<td colspan="2"><label for="day">Tag</label>&nbsp;.&nbsp;<label for="month">Monat</label>&nbsp;.&nbsp;<label for="year">Jahr</label></td>'
	+    '</tr>'
	
	+    '<tr>'
	+        '<td colspan="2">'
	+            '<input type="text" style="width:20;" size="2" id="day" name="day" maxlength="2">&nbsp;.&nbsp;'
	+            '<input type="text" style="width:20;" size="2" id="month" name="month" maxlength="2">&nbsp;.&nbsp;'
	+            '<input type="text" style="width:40;" size="4" id="year" name="year" maxlength="4">'
	+        '</td>'
	+    '</tr>'
	
	+    '<tr>'
	+        '<td><label for="hour">Uhrzeit</label></td>'
	+        '<td rowspan="2">'
	+            '<input type="radio" id="departureTime" name="time"><label for="departureTime" title="Abfahrtszeit am Startpunkt der Teilstrecke">Abfahrtszeit</label><br/>'
	+            '<input type="radio" id="arrivalTime" name="time"><label for="arrivalTime" title="Ankunftszeit am Endpunkt der Teilstrecke">Ankunftszeit</label>'
	+        '</td>'
	+    '</tr>'
	
	+    '<tr>'
	+        '<td>'
	+            '<input type="text" style="width:20;" size="2" id="hour" name="hour" maxlength="2">&nbsp;:&nbsp;'
	+            '<input type="text" style="width:20;" size="2" id="minute" name="minute" maxlength="2">'
	+        '</td>'	
	+    '</tr>'
	+    '</table>'
		
	+'<fieldset>'
	+    '<legend>Verkehrsmittel</legend>'
	+    '<table width="100%" border="0" cellspacing="1" cellpadding="0">'
	
	+    '<tr>'
	+        '<td valign="middle">'	
	+            '<input type="checkbox" name="transp" id="rbahn" checked>'
	+        '</td>'
	+        '<td valign="middle">'
	+            '<img src="dateien/dockingWindow/rbahn.gif">'
    +        '</td>'
	+        '<td valign="middle">'
	+            '<label for="rbahn" title="Regionalbahn">Regionalbahn</label>'
	+        '</td>'
	+    '</tr>'
	
	+    '<tr>'
	+        '<td valign="middle">'	
	+            '<input type="checkbox" name="transp" id="sbahn" checked>'
	+        '</td>'
	+        '<td valign="middle">'
	+            '<img src="dateien/dockingWindow/sbahn.gif">'
    +        '</td>'
	+        '<td valign="middle">'
	+            '<label for="sbahn" title="S-Bahn">S-Bahn</label>'
	+        '</td>'
	+    '</tr>'
	
	+    '<tr>'
	+        '<td valign="middle">'	
	+            '<input type="checkbox" name="transp" id="stadtbahn" checked>'
	+        '</td>'
	+        '<td valign="middle">'
	+            '<img src="dateien/dockingWindow/stadtbahn.gif">'
    +        '</td>'
	+        '<td valign="middle">'
	+            '<label for="stadtbahn" title="Stadt-/Stra&szlig;enbahn">Stadt-/Stra&szlig;enbahn</label>'
	+        '</td>'
	+    '</tr>'
	
	+    '<tr>'
	+        '<td valign="middle">'	
	+            '<input type="checkbox" name="transp" id="bus" checked>'
	+        '</td>'
	+        '<td valign="middle">'
	+            '<img src="dateien/dockingWindow/bus.gif">'
    +        '</td>'
	+        '<td valign="middle">'
	+            '<label for="bus" title="Bus">Bus</label>'
	+        '</td>'
	+    '</tr>'
	
	+'</table>'
	+'</fieldset>'
	
	+'<br/>'
	+'<center style="position:absolute;top:195px;left:22px;"><input id="opnvSubmit" style="width:140px;" type="button" value="Route berechnen" /><center>'
	
	+'</form>';
		
	GEvent.bindDom(document.getElementById("opnvSubmit"), "click", this, this.onSubmitOpnvForm);
}



MMOpnvToolWindow.prototype.onSubmitOpnvForm = function(){	
	
	this.selectedRoute.SetOpnv(true);
	this.selectedRoute.SetTime(this.GetTime(), this.TimeIsDeparture());
	this.selectedRoute.SetTransportation(this.GetRbahn(), this.GetSbahn(), this.GetUbahn(), this.GetBus());
	
	this.selectedRoute.load();
	return false;
}

/**
 * Sets Transportation to DockingWindow
 */
MMOpnvToolWindow.prototype.SetTransportation = function(rbahn, sbahn, ubahn, bus){
	var chkRbahn = document.getElementById("rbahn");
	var chkSbahn = document.getElementById("sbahn");
	var chkUbahn = document.getElementById("stadtbahn");
	var chkBus = document.getElementById("bus");
		
	if(rbahn) chkRbahn.checked = true; else chkRbahn.checked = false;
	if(sbahn) chkSbahn.checked = true; else chkSbahn.checked = false;
	if(ubahn) chkUbahn.checked = true; else chkUbahn.checked = false;
	if(bus) chkBus.checked = true; else chkBus.checked = false;
}

MMOpnvToolWindow.prototype.GetRbahn = function(){ return document.getElementById("rbahn").checked; } 
MMOpnvToolWindow.prototype.GetSbahn = function(){ return document.getElementById("sbahn").checked; } 
MMOpnvToolWindow.prototype.GetUbahn = function(){ return document.getElementById("stadtbahn").checked; } 
MMOpnvToolWindow.prototype.GetBus = function(){ return document.getElementById("bus").checked; } 


/**
 * Sets departure/arrival Time to DockingWindow
 */
MMOpnvToolWindow.prototype.SetTime = function(time, isDeparture){
	var year = document.getElementById("year");
	var month = document.getElementById("month");
	var day = document.getElementById("day");
	var hour = document.getElementById("hour");
	var minute = document.getElementById("minute");
	var chkIsDeparture = document.getElementById("departureTime");
	var chkIsArrival = document.getElementById("arrivalTime");
	
	if(isDeparture){
		chkIsArrival.checked = false;
		chkIsDeparture.checked = true;		
	} else {
		chkIsArrival.checked = true;
		chkIsDeparture.checked = false;		
	}

	year.value   = time.getFullYear();	
	month.value  = (time.getMonth()+1 < 10)? "0"+(time.getMonth()+1) : time.getMonth()+1;
	day.value    = (time.getDate()    < 10)? "0"+time.getDate()    : time.getDate();
	hour.value   = (time.getHours()   < 10)? "0"+time.getHours()   : time.getHours();
	minute.value = (time.getMinutes() < 10)? "0"+time.getMinutes() : time.getMinutes();
}

/**
 * Read departure/arrival Time from DockingWindow
 */
MMOpnvToolWindow.prototype.GetTime = function(){
	var year = document.getElementById("year");
	var month = document.getElementById("month");
	var day = document.getElementById("day");
	var hour = document.getElementById("hour");
	var minute = document.getElementById("minute");
	
	return new Date(year.value, month.value-1, day.value, hour.value, minute.value);

}
MMOpnvToolWindow.prototype.TimeIsDeparture = function(){
	var isDeparture = document.getElementById("departureTime");
	var isArrival = document.getElementById("arrivalTime");
	
	if(isDeparture.checked) return true;
	else return false;
}
