﻿	// Submits form
	function OnLinieChanged() 
	{
		tm = document.getElementById("editTime");
		if ( document.getElementById("radioTime").checked && !isValidTime(tm.value) )
		{
			alert("Bitte geben Sie ein gültiges Datumformat ein (HH:MM), oder selektieren sie Option Jetzt !");
			return false;
		}
		
		if ( tm != null ) 
		{
			var tm4 = tm.value.substr(0,2) + tm.value.substr(3,2);
			tm.value = tm4;
		}
		
		var theform = document.frmDFI;
		theform.submit();
		return true;
	}
	

	// Function set "Now" radio button checked
	function OnAbfahrtsZeitFocus() 
	{
		document.getElementById("radioTime").checked = true;
	}

	// Function set focus to "Time" control
	function OnZeitClick() 
	{
		document.getElementById("editTime").focus();
	}

	// Shows full-screen window
	function fullscreen() {
		var idx = document.frmDFI.stopId.selectedIndex;
		if ( idx < 0 || document.frmDFI.stopId.options[idx].value < 0 ) 
		{
			alert("Fullscreen view is available if route and stop is selected!");
			return;
		}
		window.open('fullscreen.jsp' + document.location.search,'fs','left=0,top=0,width=' + screen.width + ',height=' + screen.height + ',fullscreen=yes, scrollbars=no');
		return true;
	}

	// Shows autorefresh window
	function auto_refresh() 
	{
  		var idx = document.frmDFI.stopId.selectedIndex;
  		if ( idx < 0 || document.frmDFI.stopId.options[idx].value < 0 ) 
  		{
    			alert("Autorefreshing view is available if route and stop is selected!");
    			return;
  		}
  		var aux = document.location.search;
  		var start = aux.indexOf("autorefresh", 0);
  		var end = aux.indexOf("&", start);
  		if ( -1 != start && -1 != end )
  		{
    			aux = aux.substring(0,start) + "autorefresh=" + document.frmDFI.default_autorefresh.value + aux.substring(end, aux.length);
  		}
  		else
  		{
    			aux = aux + "&autorefresh=" + document.frmDFI.default_autorefresh.value;
  		}

  		window.open('main.jsp' + aux );
  		return true;
	}


	// Shows route diagram window
	function showNetzplan() {
		n = window.open('../html/diagram.html','netzplan','width=820,height=600');
		n.focus();
		return true;
	}

	// Function called when stop is choosen from route diagram.
	function hsSelected(idx) 
	{
		url = document.URL
		paramsIdx = url.indexOf('?')
		paramsIdx = paramsIdx > 0 ? paramsIdx : url.length - 1
		
		params = document.location.search;
		rowParamIdx = params.search("nRows");
		nRows = 4;
		if ( rowParamIdx > 0 )
		{
			endValIdx = params.indexOf('&',rowParamIdx+6) > rowParamIdx+6 ? params.indexOf('&',rowParamIdx+6) : params.length;
			nr = params.substring(rowParamIdx+6,endValIdx);
			if ( isDigit(nr.charAt(0)) ) 
			{
				nRows = nr.charAt(0);
				if ( nr.length > 1 && isDigit(nr.charAt(1)) ) nRows += nr.charAt(1);
			}
		}
		
		window.location.href = url.substring(0, paramsIdx) + '?stName=' + idx + '&allLines=y' + '&nRows=' + nRows;
	}
	
	// Function returns true if given character is digit
	function isDigit(ch,vmax)
	{
		if ( ch < '0' || ch > '9' ) return false;
		 else return true;
	}
	
	// Checks if time entered by user has correct format
	function isValidTime(tm)
	{
		if ( tm.length != 5 ) return false;
		if ( tm.charAt(2) != ':' || !(isDigit(tm.charAt(0)))  || !(isDigit(tm.charAt(1))) || !(isDigit(tm.charAt(3))) || !(isDigit(tm.charAt(4))) ) return false;
		if ( tm.charAt(0) > 2 || (tm.charAt(0) == 2 && tm.charAt(1) > 3 ) || tm.charAt(3) >= 6 ) return false;
		return true
	}

	// Checks if time entered by user in time control has correct format
	function checkTimeFormat()
	{
		var tm = document.getElementById("editTime").value;

		if ( document.getElementById("radioTime").checked && !isValidTime(tm) )
		{
			alert("Bitte geben Sie ein gültiges Datumformat ein (HH:MM), oder selektieren sie Option Jetzt !");
			return;
		}
		
		var tm4 = tm.substr(0,2) + tm.substr(3,2);
		document.getElementById("editTime").value = tm4;
		var theform = document.frmDFI;
		//kpa@otp / 02.08.2006 - form fields must be always enabled before submitting
		var ar = document.getElementById("allLines");
		ar.disabled = false;
		theform.submit();
	}

	// Function called when user checks "All routes" checkbox
	function OnCheckAllRoutes()
	{
	  cb = document.getElementById("allLines");
		if ( cb != null && cb.checked == false)
		{
			//document.getElementById("routeId").selectedIndex = 0;
			//document.getElementById("stopId").selectedIndex = -1;
		}
		OnLinieChanged();
	}

	// Function called when user click "Now" button
	function OnNowClick()
	{
		document.getElementById("editTime").value = "";
		OnLinieChanged();
	}
