function chkSaveItem() {
	if (document.formular.tage.value > 0 && document.formular.update.value == 0) {
	   if (!confirm("ACHTUNG! Datum liegt in der Zukunft.\nEintrag wird als Plan gespeichert!")) {
	       return false;
	   }
	 }
	
	if (document.formular.Distanz.value == 0 && document.formular.Dauer.value == 0) {
		alert("Bitte Distanz und/oder Dauer eingeben!");
		return false;
	}
	
	if (document.formular.Distanz.value > 150 && document.formular.Sportart.value == 10) 
	{
		alert("Distanz muss zwischen 0 und 150 sein!");
		return false;
	}
	if (document.formular.Distanz.value > 200 && document.formular.Sportart.value == 11) 
	{
		alert("Distanz muss zwischen 0 und 200 sein!");
		return false;
	}
	if (document.formular.Distanz.value > 20 && document.formular.Sportart.value == 12) 
	{
		alert("Distanz muss zwischen 0 und 20 sein!");
		return false;
	}
	if (document.formular.Dauer.value > 1000 ) 
	{
		alert("Dauer muss zwischen 0 und 1000 sein!");
		return false;
	}
	document.formular.action.value="save";
	document.formular.submit();
}

function chkPlanItem() {
	if (document.formular.fwoche.value == 0) {
		alert("Bitte Woche angeben")
		document.formular.fwoche.focus()
	    return false;
	 }
	 
	if (document.formular.ftag.value == 0) {
		alert("Bitte Tag angeben")
		document.formular.ftag.focus()
	    return false;
	 }
	 
	if (document.formular.sportart.value == 0) {
		alert("Bitte Sportart angeben")
		document.formular.sportart.focus()
	    return false;
	 }
	 
	 document.formular.posfunction.value='Speichern';
	 document.formular.submit()
}

function chgItemStrecke() 
{
	var array1 = document.formular.Distanzen.value.split(",")
	var array2 = document.formular.Hoehendifferenzen.value.split(",")
	if (document.formular.Laufstrecke.selectedIndex > 0) 
	{
		document.formular.Distanz.value = array1[document.formular.Laufstrecke.selectedIndex-1]
		document.formular.Hoehendiff.value = array2[document.formular.Laufstrecke.selectedIndex-1]
	}
}

function chkDeleteItem() 
{
	if (!confirm("ACHTUNG: Eintrag wird gelöscht!")) {
       return false;
    }
    document.formular.action.value="delete"
    document.formular.submit();
}

// Prüfen Formular
function chkPropForm (plannr, wochealt, aktwoche) 
{
	var t = document.formular.planwoche.value.split("/");
	jjw = t[1]+t[0];
	planneu = ""
	for (var i=0; i<document.formular.plan.length; i++) if (document.formular.plan[i].checked) planneu = document.formular.plan[i].value;
	if (planneu != plannr || document.formular.planwoche.value != wochealt) 
	{
		if (jjw <= aktwoche) 
		{
			alert("ACHTUNG! Startwoche für den Trainingsplan muss grösser\nals die aktuelle Woche sein!");
			return false;
		}
		if (document.formular.planwoche.value == "" && planneu != "") 
		{
	   		alert("ACHTUNG! Bitte ein Startwoche eingeben");
	   		return false;
	    }
	    if (!confirm("ACHTUNG! Alle geplanten Einheiten nach dem heutigen Datum\nwerden gelöscht!")) 
	    {
	       return false;
	    }
	}
	document.formular.action.value="Speichern";	
	document.formular.submit();
}

// Prüfen Formular Profil
function chkProfilForm () 
{
	// Prüfen Geburtsdatum
	if (document.formular.geboren.value > 0) 
	{
		var d = document.formular.geboren.value.split(".");
		if (d[0] < 1 || d[0] > 31 || d[1] < 1 || d[1] > 12 || d[2] < 1900 || d[2] > 2020) 
		{
			alert("ACHTUNG! Geburtsdatum ungültig!\nFormat: TT.MM.JJJJ");
			document.formular.geboren.focus();
			return false;	
		}
	}
	//Prüfen Grösse
	if (document.formular.groesse.value > 0) 
	{
		if (document.formular.groesse.value > 2.20 || document.formular.groesse.value < 1.00) 
		{
			alert("ACHTUNG! Grösse ungültig!");
			document.formular.geboren.focus();
			return false;	
		}
	}
	//Prüfen Username
	if (document.formular.username.value.length < 6) 
	{
		alert("Username zu kurz (min. 5 Zeichen)!");
		document.formular.username.focus();
		return false;	
	}
	//Prüfen Passwort
	if (document.formular.passwort.value.length < 6) 
	{
		alert("Passwort zu kurz (min. 5 Zeichen)!");
		document.formular.passwort.focus();
		return false;	
	}
	document.formular.action.value="Speichern";	
	document.formular.submit();
}

//Radio-Button löschen
function Uncheck() {
	document.formular.planwoche.value = ""
	for (var i=0; i<document.formular.plan.length; i++) {
		document.formular.plan[i].checked = 0;
	}
}

// Prüfen Formular Tabellen
function chgTabStrecke() 
{
	var array1 = document.tabellen.Distanzen.value.split(",")
	if (document.tabellen.Strecken.selectedIndex > 0) 
	{
		document.tabellen.Distanz.value = array1[document.tabellen.Strecken.selectedIndex-1]
	}
}
// Steuern Button wenn Distanz eingegeben
function chgTabDistanz() 
{
	if (document.tabellen.Art_ST.selectedIndex) 
	{
		document.tabellen.Function_ST[2].disabled=false;
	    document.tabellen.Function_ST[3].disabled=true;
	}
}

function chkDeleteTab() 
{
	if (!confirm("ACHTUNG: Tabelleneintrag wird gelöscht!")) 
	{
       return false;
    }
}

// Wenn Tabelleintrag geändert, dann Button AENDERN an, Button LOESCHEN aus
function chgTabText() 
{
	if (document.tabellen.Tageszeit_Neu.value !== document.tabellen.Art_TZ.options[document.tabellen.Art_TZ.selectedIndex].text) 
	{
		document.tabellen.Function_TZ[1].disabled=false;
		document.tabellen.Function_TZ[2].disabled=false;
        document.tabellen.Function_TZ[3].disabled=true;
	}
	if (document.tabellen.Trainingsart_Neu.value !== document.tabellen.Art_TA.options[document.tabellen.Art_TA.selectedIndex].text) 
	{
		document.tabellen.Function_TA[1].disabled=false;
		document.tabellen.Function_TA[2].disabled=false;
        document.tabellen.Function_TA[3].disabled=true;
	}
	if (document.tabellen.Untergrund_Neu.value !== document.tabellen.Art_UG.options[document.tabellen.Art_UG.selectedIndex].text) 
	{
		document.tabellen.Function_UG[1].disabled=false;
		document.tabellen.Function_UG[2].disabled=false;
        document.tabellen.Function_UG[3].disabled=true;
	}
	if (document.tabellen.Wetter_Neu.value !== document.tabellen.Art_WR.options[document.tabellen.Art_WR.selectedIndex].text) 
	{
		document.tabellen.Function_WR[1].disabled=false;
		document.tabellen.Function_WR[2].disabled=false;
        document.tabellen.Function_WR[3].disabled=true;
	}
	if (document.tabellen.Fitness_Neu.value !== document.tabellen.Art_FS.options[document.tabellen.Art_FS.selectedIndex].text) 
	{
		document.tabellen.Function_FS[1].disabled=false;
		document.tabellen.Function_FS[2].disabled=false;
        document.tabellen.Function_FS[3].disabled=true;
	}
	if (document.tabellen.Laufschuh_Neu.value !== document.tabellen.Art_LS.options[document.tabellen.Art_LS.selectedIndex].text) 
	{
		document.tabellen.Function_LS[1].disabled=false;
		document.tabellen.Function_LS[2].disabled=false;
        document.tabellen.Function_LS[3].disabled=true;
	}
	if (document.tabellen.Laufstrecke_Neu.value !== document.tabellen.Art_ST.options[document.tabellen.Art_ST.selectedIndex].text) 
	{
		document.tabellen.Function_ST[1].disabled=false;
		document.tabellen.Function_ST[2].disabled=false;
        document.tabellen.Function_ST[3].disabled=true;
	}
}

// Button ein-/auschalten wenn Farbe geändert
function chgTabColor() 
{
		if (document.tabellen.Art_TZ.selectedIndex && document.tabellen.Farbe_TZ.selectedIndex) 
		{
	        document.tabellen.Function_TZ[0].disabled=false;
	        document.tabellen.Function_TZ[0].focus();
	    }
	    if (document.tabellen.Art_TA.selectedIndex && document.tabellen.Farbe_TA.selectedIndex) 
	    {
	        document.tabellen.Function_TA[0].disabled=false;
	        document.tabellen.Function_TA[0].focus();
	    }
	    if (document.tabellen.Art_UG.selectedIndex && document.tabellen.Farbe_UG.selectedIndex) 
	    {
	        document.tabellen.Function_UG[0].disabled=false;
	        document.tabellen.Function_UG[0].focus();
	    }
	    if (document.tabellen.Art_WR.selectedIndex && document.tabellen.Farbe_WR.selectedIndex) 
	    {
	        document.tabellen.Function_WR[0].disabled=false;
	        document.tabellen.Function_WR[0].focus();
	    }
	    if (document.tabellen.Art_FS.selectedIndex && document.tabellen.Farbe_FS.selectedIndex) 
	    {
	        document.tabellen.Function_FS[0].disabled=false;
	        document.tabellen.Function_FS[0].focus();
	    }
	    if (document.tabellen.Art_LS.selectedIndex && document.tabellen.Farbe_LS.selectedIndex) 
	    {
	        document.tabellen.Function_LS[0].disabled=false;
	        document.tabellen.Function_LS[0].focus();
	    }
	    if (document.tabellen.Art_ST.selectedIndex && document.tabellen.Farbe_ST.selectedIndex) 
	    {
	        document.tabellen.Function_ST[0].disabled=false;
	        document.tabellen.Function_ST[0].focus();
	    }
}
// Link aufrufen
function click(filename) 
{
	window.open("http://www.gpsies.com/map.do?url=http://www.laufportal.ch/upload/"+filename)
}

// Link aufrufen
function doku(link) 
{
	docWin = window.open(link,'win2','status=no,toolbar=no,menubar=no,scrollbars=yes,resizable=yes,left=0,top=0,width=600,height=300,directories=no,location=no,titlebar=no')
	docWin.focus();
}

// Scripts für Liste/Export
// Submit Anzeigen
function viewSubmit() 
{
	if (!document.auswahl.ansicht[1].checked) 
	{
		document.auswahl.ansicht.value='Liste';
	} else {
		document.auswahl.ansicht.value='Wochenplan';
	}
	if (document.auswahl.isteintrag.checked) 
	{
		document.auswahl.isteintrag.value='0';
		
	}  else {
		document.auswahl.isteintrag.value='1';
	}
	if (document.auswahl.planeintrag.checked) 
	{
		document.auswahl.planeintrag.value='1';	
	} else {
		document.auswahl.planeintrag.value='0';
	}
 window.open('viewlist.php?vondatum='+document.auswahl.vondatum.value+'&bisdatum='+document.auswahl.bisdatum.value+'&ansicht='+document.auswahl.ansicht.value+'&planeintrag='+document.auswahl.planeintrag.value+'&isteintrag='+document.auswahl.isteintrag.value
,'win2','status=yes,location=yes,toolbar=yes,menubar=yes,scrollbars=yes,resizable=yes,width=980,height=600,directories=no,location=no');
document.auswahl.submit();
}

// Auswahl Anzeige
function chgView() 
{
	// Wenn Ansicht Wochenplan, dann Button Excel ausblenden
	if (!document.auswahl.ansicht[1].checked) 
	{
		document.auswahl.Function[1].disabled=false;
		
	} else {
		document.auswahl.Function[1].disabled=true;
	}
}

// Scripts für verwalten Wettkämpfe
function chgUserRef() 
{
		document.formular.referenz.value = document.formular.reftext.value;
}


function ChangeEvent(nr)
{
	document.formular.item.value = nr;
	document.formular.action.value = "change";
	document.formular.submit(); 
}

function DeleteItem(nr)
{
	if (!confirm("Eintrag wirklich löschen!")) 
	{
       	return false;
    } else {
		document.formular.item.value = nr;
		document.formular.action.value = "delete";
		document.formular.submit(); 
	}
}

function LockItem(nr,status)
{
	document.formular.item.value = nr;
	document.formular.action.value = status;
	document.formular.submit(); 
}

function ChangeItem(nr,pos)
{
	document.formular.item.value = nr;
	document.formular.maxpos.value = pos;
	document.formular.action.value = "change";
	document.formular.submit(); 
}

function DeletePosItem(nr)
{
	if (!confirm("Eintrag wirklich löschen!")) 
	{
       	return false;
    } else {
		document.formular.positem.value =nr;
		document.formular.posaction.value = "delete";
		document.formular.submit(); 
	}
}
function ChangePosItem(nr)
{
	document.formular.positem.value = nr;
	document.formular.posaction.value = "change";
	document.formular.submit(); 
}

//Tabellen sortieren
function SortTable(sort,p)
{	
	if (document.formular.sort.value == sort)
	{
		if (document.formular.folge.value == 'ASC')
		{
			document.formular.folge.value = 'DESC'
		} else {
			document.formular.folge.value = 'ASC'
		}
	} else {
		document.formular.sort.value = sort
		document.formular.folge.value = 'ASC'
	}
	if (p)
	{
		document.formular.view.value = '';
	}
	document.formular.submit()
}	

function chgViewItem()
{
	document.formular.view.value = '';
	document.formular.submit();
}

function chgLock()
{
	document.formular.aflag.value = 1;
	document.formular.submit();
}
	
function enableButton(button) 
{
	if (button == 3) {
		if(document.getElementById) {
			document.getElementById("UpButton").innerHTML="<a href='#'><img src='img/24/hot/up.png' name='up' onclick=\"document.formular.action.value='up';document.formular.submit()\" alt='Oben' title='Nach oben verschieben'></a>";
			document.getElementById("DownButton").innerHTML="<a href='#'><img src='img/24/hot/down.png' name='up' onclick=\"document.formular.action.value='down';document.formular.submit()\" alt='Unten' title='Nach unten verschieben'></a>";
			document.getElementById("BackButton").innerHTML="<a href='#'><img src='img/24/hot/back.png' name='up' onclick=\"document.formular.action.value='back';document.formular.submit()\" alt='Entfernen' title='Ansicht aus Bericht erntfernen'></a>";
		}
	}
	if (button == 4) {
		if(document.getElementById) {
			document.getElementById("ForwardButton").innerHTML="<a href='#'><img src='img/24/hot/forward.png' name='up' onclick=\"document.formular.action.value='forward';document.formular.submit()\" alt='Hinzufügen' title='Ansicht zu Bericht hinzufügen'></a>";
		}
	}
}

function Export()
{
	document.formular.exp.value = 'excel';
	document.formular.submit();
}

function chkEventTime() {
	if (document.formular.min.value > 59 || document.formular.sek.value > 59 || document.formular.zsek.value > 9) 
	{
			alert("Ungültiges Zeitformat!");
			return false;
	}
}

function DivSaveButton() {
	if(document.getElementById) {
		document.getElementById("SaveButton").innerHTML="<a href='#'><img src='img/32/hot/ok.png' name='save' onclick=\"document.formular.action.value='Speichern';document.formular.submit()\" alt='Speichern' title='Änderungen speichern'></a>";
	}
}
