function FormRegistrieren_onsubmit(theForm) {
  
  if (theForm.matrikelnummer.value == "" || !isUnsignedInteger(theForm.matrikelnummer.value) || theForm.matrikelnummer.value.length != 7)
  {
    alert("Bitte geben Sie eine gültige 7-stellige \"Matrikelnummer\" ein.");
    theForm.matrikelnummer.focus();
    return (false);
  }

  if (theForm.uni.value == "")
  {
    alert("Bitte wählen Sie Ihre \"Uni\" aus.");
    theForm.telefon1.focus();
    return (false);
  }

  if (theForm.anrede.value == "")
  {
    alert("Bitte wählen Sie Ihre \"Anrede\" aus.");
    theForm.telefon1.focus();
    return (false);
  }

  if (theForm.vorname.value == "")
  {
    alert("Bitte geben Sie einen \"Vornamen\" ein.");
    theForm.vorname.focus();
    return (false);
  }

  if (theForm.nachname.value == "")
  {
    alert("Bitte geben Sie einen \"Namchnamen\" ein.");
    theForm.nachname.focus();
    return (false);
  }

  if (!isDate(theForm.geburtsdatum.value, 1920, 1994, "Geburtsdatum")) {
    theForm.geburtsdatum.focus();
    return (false);
  }
    
  if (theForm.telefon1.value == "")
  {
    alert("Bitte geben Sie ein Telfonnummer in \"Telefon-1\" ein.");
    theForm.telefon1.focus();
    return (false);
  }

  if (theForm.email.value == "")
  {
    alert("Bitte geben Sie eine \"E-Mail Adresse\" ein.");
    theForm.email.focus();
    return (false);
  }

  if (theForm.strasse.value == "")
  {
    alert("Bitte geben Sie eine \"Strasse\" ein.");
    theForm.strasse.focus();
    return (false);
  }

  if (theForm.postleitzahl.value == "")
  {
    alert("Bitte geben Sie eine \"Postleitzahl\" ein.");
    theForm.postleitzahl.focus();
    return (false);
  }

  if (theForm.postleitzahl.value.length < 4 || theForm.postleitzahl.value.length > 5)
  {
    alert("Bitte geben Sie eine 4- oder 5- stellige \"Postleitzahl\" ein.");
    theForm.postleitzahl.focus();
    return (false);
  }

  if (!isUnsignedInteger(theForm.postleitzahl.value))
  {
    alert("Bitte nur Ziffern für \"Postleitzahl\" eingeben.");
    theForm.postleitzahl.focus();
    return (false);
  }
  
  if (theForm.ort.value == "")
  {
    alert("Bitte geben Sie einen \"Ort\" ein.");
    theForm.ort.focus();
    return (false);
  }

  if (theForm.land.value == "")
  {
    alert("Bitte geben Sie ein \"Land\" ein.");
    theForm.land.focus();
    return (false);
  }
  
  if (theForm.bundesland.value == "") 
  {
    alert("Bitte ein \"Bundesland\" auswählen, oder \"---------\" falls sich Ihr Wohnsitz nicht in Österreich befindet.");
    theForm.bundesland.focus();
    return (false);
  }
  

  return (true);
}

function isUnsignedInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}

function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

var dtCh= ".";

function isDate(dtStr, minYear, maxYear, txt){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("Das " + txt + " bitte in folgendem Format angeben : TT.MM.JJJJ")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Das Monat bei " + txt + " ist ungültig.")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Der Tag bei " + txt + " ist ungültig.")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Bei " + txt + " bitte ein Jahr zwischen "+minYear+" and "+maxYear+" eingeben.")
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isUnsignedInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Bitte ein gültiges Datum für "+txt+" eingeben (TT.MM.JJJJ)")
		return false
	}
return true
}

	function registrierungStornoSindSieSicher() {
	  return confirm("Sind Sie sicher, dass Sie ihre Registrierung beenden wollen?");
	}
	
	function go2_onclick() {
	  if (!document.forms["FormRegistrierenBest"].akzeptiert[1].checked)
	  {
	    alert("Sie müssen die Nutzungsbestimmungen akzeptieren, bitte bestätigen Sie dies.");
	    return (false);
	  }
	  
	  return (confirm("Haben Sie ihre E-Mail Adresse auf Tippfehler geprüft, ist sie sicher korrekt?"));
	}	
