
function addRow() {
	numRows ++;
	addRowById(numRows);
	document.getElementById('zeilen').value = numRows;
}

function addRowById(id) {
	
	var table = document.getElementById('table');
	var tblBody = table.getElementsByTagName("tbody")[0];
	var row = document.createElement("tr");

	var cell1 = document.createElement("td");
	var input1 = document.createElement("input");
	input1.type = "text";
	input1.name = "datum_" + id;
	input1.size = "7";
	input1.setAttribute("onblur", "if(this.value=='') this.value=getDateString();");
	cell1.appendChild(input1);
	row.appendChild(cell1);
	
	var cell2 = document.createElement("td");
	var input2 = document.createElement("input");
	input2.type = "text";
	input2.name = "von_" + id;
	input2.size = "6";
	input2.setAttribute("onblur", "if(this.value=='') this.value=getTimeString();");
	cell2.appendChild(input2);
	row.appendChild(cell2);
	
	var cell3 = document.createElement("td");
	var input3 = document.createElement("input");
	input3.type = "text";
	input3.name = "bis_" + id;
	input3.size = "6";
	input3.setAttribute("onblur", "if(this.value=='') this.value=getTimeString();");
	cell3.appendChild(input3);
	row.appendChild(cell3);
	
	var cell4 = document.createElement("td");
	var input4 = document.createElement("input");
	input4.type = "text";
	input4.name = "stn_" + id;
	input4.size = "12";
	input4.setAttribute("readonly", "readonly");
	cell4.appendChild(input4);
	row.appendChild(cell4);
	
	var cell5 = document.createElement("td");
	var input5 = document.createElement("input");
	input5.type = "text";
	input5.name = "kommentar_" + id;
	input5.size = "40";
	cell5.appendChild(input5);
	row.appendChild(cell5);
	
	var cell6 = document.createElement("td");
	var input6 = document.createElement("input");
	input6.type = "text";
	input6.name = "auftr_" + id;
	input6.size = "6";
	cell6.appendChild(input6);
	row.appendChild(cell6);
	
	tblBody.appendChild(row);
}

function activateExport() {
	
	checkbox = document.getElementById('export');
	checkbox.checked = true;
	
	setButtonExportLabel();
}

function updateButtonLabel() {
	
	checkbox = document.getElementById('export');
	
	if(checkbox.checked) {
		setButtonExportLabel();
	}
	else {
		setButtonCalcLabel();
	}
	
}

function setButtonCalcLabel() {
	
	var button = document.getElementById('submit');
	button.value = 'Ausrechnen'; 
	
}

function setButtonExportLabel() {
	
	var button = document.getElementById('submit');
	button.value = 'Exportieren'; 
	
}

function getDateString() {
	
	var now = new Date();
	
	var day = now.getDate();
	if(day < 10)
		day = '0' + day.toString();

	var month = now.getMonth() + 1;
	if(month < 10)
		month = '0' + month.toString();
		
	var year = now.getFullYear().toString().substr(2,2);
		
	return day + '.' + month + '.' + year;
}	

function getTimeString() {
	
	var now = new Date();
	
	var hours = now.getHours();
	if(hours < 10)
		hours = '0' + hours.toString();
		
	var minutes = now.getMinutes();
	minutes = Math.round(minutes / 5) * 5;
	if(minutes < 10)
		minutes = '0' + minutes.toString();
		
	if(minutes >= 60)
		minutes = '00';
	
	return hours + ':' + minutes;
}
