function carbox_resident (value) {
  document.getElementById('rent_carbox_resident').style.display = (value ? 'inline': 'none');
}

function cyclebox_resident (value) {
  document.getElementById('rent_cyclebox_resident').style.display = (value ? 'inline': 'none');
}

function checkChildrenCount(which, children, chk) {
  if (which == 0) {
    if (chk.value == '') return;
    if (children.value == '') children.value = chk.value;

    if (parseInt(chk.value) > parseInt(children.value)) chk.value = children.value;
  } else {
    if (chk.value == '') return;
    if (children.value == '') children.value = chk.value;

    if (parseInt(children.value) < parseInt(chk.value)) children.value = chk.value;
  }
}

/**
 * Birthday selection has changed (month or year)
 * Validates the birthday on input.
 */
function changeBirthDays (days, months, years) {
  // Days of months (without leayears)
  var monthdays = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

  // Selected year
  var year = parseInt('19' + years.value);

  // Selected month
  var month = parseInt(months.options[months.selectedIndex].text);

  // Selected day
  var selday = parseInt(days.options[days.selectedIndex].text);

  // Leapyears
  //
  // One leapyear every 4 years, but not every 100 years, but ever
  // 400 years (the 100 and the 400 will not happen anymore, but we
  // take it in.
  if (!(year % 4) && ((year % 100) || !(year % 400)))
    monthdays[1] = 29;

  // Current length of days
  var currentlength = days.length;

  // New length of days
  var newlength = monthdays[month - 1];

  // Change the day length
  if (currentlength < newlength) {
    // If the new length is bigger than the current length, add some days
    for (var i=currentlength+1; i<=newlength; i++) {
      newEntry = new Option(i, i, false, false);
      days.options[days.length] = newEntry;
    }
  } else if (currentlength > newlength) {
    // Else if the new length is smaller than the current length, remove some days
    for (var i=currentlength; i>=newlength; i--) {
      days[i] = null;
    }

    // If there was a bigger days selected before, take the highest value now
    if (selday > newlength)
      days.options[days.length-1].selected = true;
  }
}

function numberInRange (theField, min, max) {
  checkForNumber(theField);

  var value = parseInt(theField.value);
  if (value > max) theField.value = max;
  if (value < min) theField.value = min;
}

function checkForNumber (theField) {
	var text = theField.value;
	result = text.search(/[^0-9]/);
  while (result != -1) {
    text = text.replace(/[^0-9]/, '');
    result = text.search(/[^0-9]/);
  }
  while (text.substring(0, 1) == '0') text = text.substring(1, text.length);
	if (text == '' || text == '0') text = '';
	theField.value = text;
}

function checkForNumberWidthZero (theField) {
	var text = theField.value;
	result = text.search(/[^0-9]/);
  while (result != -1) {
    text = text.replace(/[^0-9]/, '');
    result = text.search(/[^0-9]/);
  }
  while (text.substring(0, 1) == '0' && text.length > 1) text = text.substring(1, text.length);
	theField.value = text;
}

function checkForPhone (theField) {
	var text = theField.value;
	result = text.search(/[^0-9]/);
  while (result != -1) {
    text = text.replace(/[^0-9]/, '');
    result = text.search(/[^0-9]/);
  }
	theField.value = text;
}

function checkForZipcode (theField) {
	var text = theField.value;
	result = text.search(/[^0-9A-Za-z]/);
  while (result != -1) {
    text = text.replace(/[^0-9A-Za-z]/, '');
    result = text.search(/[^0-9A-Za-z]/);
  }
	theField.value = text;
}

function germanPrice (i) {
  i = '' + i;
  i = i.replace(/\./, ",");
  if (!i.match(/,/)) i += ',00';
  if (!i.match(/,[0-9][0-9]/)) i += '0';
  return i;
}

function englishPrice (i) {
  i = '' + i;
  i = i.replace(/,/, ".");
  return parseInt(i);
}

function div_ref (id) {
  if      (document.layers)         return document.layers[id];
  else if (document.all)            return document.all[id];
  else if (document.getElementById) return document.getElementById(id);
  else                              return null;
}

function div_ref_style (id) {
  if      (document.layers)         return document.layers[id];
  else if (document.all)            return document.all[id].style;
  else if (document.getElementById) return document.getElementById(id).style;
  else                              return null;
}

function writin (id, text) {
  result = text.search(/\n/);
  while (result != -1) {
    text = text.replace(/\n/, "<br>");
    result = text.search(/\n/);
  }

  if (document.getElementById) {
    x = document.getElementById(id);
    x.innerHTML = '';
    x.innerHTML = text;
  } else if (document.all) {
    x = document.all[id];
    x.innerHTML = text;
  }
}

function isEmail(str) {
  var supported = 0;
  if (window.RegExp) {
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;
  }

  if (!supported) return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);

  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$");
  return (!r1.test(str) && r2.test(str));
}

function testEmail (str) {
  if (!isEmail(str)) {
    alert(errorNoValidEmail);
    return false;
  } else {
    return true;
  }
}

function imgPopup (url, width, height) {
  F1 = open("img-popup.php?url=" + url, "f1window", "width=" + (width ? width: 200) + ", height=" + (height ? height: 200) + ", top=200, left=200, resizable=no, scrollbars=no, menubar=no, toolbar=no, status=no, location=no");
}

function showtandem (mode, id) {
  F3 = open("showtandem.popup.php?mode=" + mode + "&id=" + id, "f3window", "width=550, height=220, top=200, left=200, resizable=no, scrollbars=no, menubar=no, toolbar=no, status=no, location=no");
}

function printtandem (mode, id) {
  F6 = open("showtandem.popup.php?print=true&mode=" + mode + "&id=" + id, "f3window", "width=550, height=160, top=200, left=200, resizable=no, scrollbars=no, menubar=no, toolbar=no, status=no, location=no");
}

function openMustLogin (ref, xtra) {
  F4 = open("mustlogin.popup.php?ref=" + ref + "&xtra=" + xtra, "f4window", "width=400, height=160, top=200, left=200, resizable=no, scrollbars=no, menubar=no, toolbar=no, status=no, location=no");
}

function openPressmirrorPopup (id) {
  F5 = open("showpressespiegel.popup.php?id=" + id, "f5window", "width=1000, height=600, top=0, left=0, resizable=yes, scrollbars=yes, menubar=no, toolbar=no, status=no, location=no");
}

function openPressfolderPopup (id) {
  F6 = open("showpressemappe.popup.php?id=" + id, "f6window", "width=500, height=300, top=200, left=200, resizable=no, scrollbars=yes, menubar=no, toolbar=no, status=no, location=no");
}

function openaccoservicePopup (id) {
  F7 = open("zimmervermittlung.php?page=showoffer&id=" + id, "f7window", "width=550, height=400, top=200, left=200, resizable=no, scrollbars=yes, menubar=no, toolbar=no, status=no, location=no");
}

function openaccoservicePopup (id) {
  F7 = open("zimmervermittlung.php?page=showoffer&id=" + id, "f7window", "width=550, height=400, top=200, left=200, resizable=no, scrollbars=yes, menubar=no, toolbar=no, status=no, location=no");
}

function openDatePopup (id) {
  F8 = open("veranstaltungen.php?page=showevent&id=" + id, "f8window", "width=550, height=400, top=200, left=200, resizable=no, scrollbars=yes, menubar=no, toolbar=no, status=no, location=no");
}

function openFAQPopup (id) {
  F9 = open("faq.php?showid=" + id, "f9window", "width=550, height=400, top=200, left=200, resizable=no, scrollbars=yes, menubar=no, toolbar=no, status=no, location=no");
}

function openLearnGroupPopup (id) {
  F10 = open("lerngruppen.php?page=show&id=" + id, "f10window", "width=550, height=600, top=100, left=200, resizable=no, scrollbars=yes, menubar=no, toolbar=no, status=no, location=no");
}

function openEmailForm (name, email) {
  F11 = open("email_formular.popup.php?name=" + name + "&email=" + email, "f11window", "width=550, height=320, top=100, left=200, resizable=no, scrollbars=yes, menubar=no, toolbar=no, status=no, location=no");
}

function openAddCommentForm (id) {
  F12 = open("lerngruppen_kommentar.popup.php?id=" + id, "f12window", "width=550, height=300, top=100, left=200, resizable=no, scrollbars=yes, menubar=no, toolbar=no, status=no, location=no");
}

function openOptionsPopup (id) {
  F13 = open("zimmervermittlung_optionen.popup.php?id=" + id, "f13window", "width=550, height=300, top=100, left=200, resizable=no, scrollbars=yes, menubar=no, toolbar=no, status=no, location=no");
}

function openAccoInfoPopup () {
  F14 = open("zimmervermittlung.php?page=acooinfopopup", "f14window", "width=550, height=300, top=100, left=200, resizable=no, scrollbars=yes, menubar=no, toolbar=no, status=no, location=no");
}

function openPBSBuchtippsPopup (id) {
  F20 = open("pbs-buchtipps.popup.php?id=" + id, "f20window", "width=550, height=300, top=100, left=200, resizable=no, scrollbars=yes, menubar=no, toolbar=no, status=no, location=no");
}

function openPBSTextPopup (txtFile, title, isHtml, hidePrintBtn, width, height) {
	F21 = open("pbs-texte.popup.php?txt=" + txtFile + "&title=" + title + "&isHtml=" + (isHtml ? 1:0)  + "&hidePrintBtn=" + (hidePrintBtn ? 1:0), "f21window", "width=" + (width ? width: 600) + ", height=" + (height ? height: 450) + ", top=100, left=100, resizable=yes, scrollbars=yes, menubar=no, toolbar=no, status=no, location=no");
}

function showsponsorship (mode, id) {
  F22 = open("showsponsorship.popup.php?mode=" + mode + "&id=" + id, "f22window", "width=550, height=500, top=200, left=200, resizable=no, scrollbars=yes, menubar=no, toolbar=no, status=no, location=no");
}

function saveMemo (id, canteen, ref) {
  F55 = open("savememo.popup.php?id=" + id + "&canteen=" + canteen + "&goto=" + ref, "f55window", "width=550, height=450, top=200, left=200, resizable=no, scrollbars=yes, menubar=no, toolbar=no, status=no, location=no");
}

function openOtherTextPopup (txtFile, title, isHtml, hidePrintBtn, width, height) {
  var F56 = open("other-texte.popup.php?txt=" + txtFile + "&title=" + title + "&isHtml=" + (isHtml ? 1:0)  + "&hidePrintBtn=" + (hidePrintBtn ? 1:0), "f21window", "width=" + (width ? width: 600) + ", height=" + (height ? height: 450) + ", top=100, left=100, resizable=yes, scrollbars=yes, menubar=no, toolbar=no, status=no, location=no");
}

var puloc;
var pudis;
function openSelectLocation (loc, dis) {
  puloc = loc;
  pudis = dis;
  F15 = window.open("zm_unterauswahl.php?select=location&loc=" + puloc + "&dis=" + pudis, "f15window", "width=500, height=600, top=100, left=200, resizable=no, scrollbars=yes, menubar=no, toolbar=no, status=no, location=no");
  //window.setTimeout("doOpenSelectLocation()", 5000);
}

function doOpenSelectLocation() {
  if (!blockAIP) {
    F15 = window.open("zm_unterauswahl.php?select=location&loc=" + puloc + "&dis=" + pudis, "f15window", "width=500, height=600, top=100, left=200, resizable=no, scrollbars=yes, menubar=no, toolbar=no, status=no, location=no");
  }
}

function takeZmChanges (loc, dis, zip) {
  theForm = document.inputForm2

  theForm.zipcode.value  = zip;
  theForm.location.value = loc;
  theForm.district.value = dis;

  return true;
}

var blockAIP = false;
function blockAccoInfoPopup (mode) {
  if (mode) {
    blockAIP = true;
    window.setTimeout("blockAccoInfoPopup(false)", 1000);
  } else {
    blockAIP = false;
  }
}

function changeRegformxtra (theObject) {
  if (navigator.appName == "Netscape" || window.opera) {
    var newModeOn  = (theObject.checked == true ? "table-row": "none");
  } else {
    var newModeOn  = (theObject.checked == true ? "block": "none");
  }
  var newModeOn2 = (theObject.checked == true ? "inline": "none");
  var newModeOff = (theObject.checked == true ? "none": "inline");

  div_ref_style('regformxtra0').display = newModeOff;
  div_ref_style('regformxtra1').display = newModeOn;
  div_ref_style('regformxtra2').display = newModeOn;
  div_ref_style('regformxtra3').display = newModeOn;
  div_ref_style('regformxtra4').display = newModeOn;
  div_ref_style('regformxtra5').display = newModeOn;
  div_ref_style('regformxtra6').display = newModeOn2;
  div_ref_style('regformxtra7').display = newModeOn2;

  if (theObject.checked == true) checkStudieDate();

  return true;
}

function changeRentTimeMode (theMode) {
  if (navigator.appName == "Netscape" || window.opera) {
    div_ref_style('renttimecustomrow').display = (theMode ? "table-row": "none");
  } else {
    div_ref_style('renttimecustomrow').display = (theMode ? "block": "none");
  }

  return true;
}

function tablerowDisplay (theMode) {
  if (theMode == 0) return 'none';
  if (navigator.appName == "Netscape" || window.opera) return 'table-row';
  return 'block';
}

var dontChangeMode = false;
function checkStudieDate () {
  if (typeof(document.inputForm) == 'undefined') {
	  return;
  }
  var year  = document.inputForm.year.options[document.inputForm.year.selectedIndex].value;
  var month = document.inputForm.month.options[document.inputForm.month.selectedIndex].value;

  var now       = new Date();
  var nowmonth  = String(now.getMonth() + 1);
  var nowyear   = String(now.getFullYear());

  var nowDate   = parseInt(nowyear + (nowmonth.length == 1 ? '0': '') + nowmonth);
  var checkDate = parseInt(year + (month.length == 1 ? '0': '') + month);

  if (!dontChangeMode) {
    if (navigator.appName == "Netscape" || window.opera) {
      div_ref_style('regformxtra1').display = (nowDate > checkDate ? 'table-row': 'none');
    } else {
      div_ref_style('regformxtra1').display = (nowDate > checkDate ? 'block': 'none');
    }
  }

  return(nowDate > checkDate);
}

function privacyCheck (set) {
  if (set == 'on') {
    div_ref('accepted1').checked = true;
    div_ref('accepted2').checked = true;
  } else if (set == 'off') {
    div_ref('accepted1').checked = false;
    div_ref('accepted2').checked = false;
  } else {
    F2 = open("privacy.popup.php", "f2window", "width=400, height=300, top=200, left=200, resizable=no, scrollbars=yes, menubar=no, toolbar=no, status=no, location=no");
  }
}

function privacyTandemCheck (set) {
  if (set == 'on') {
    div_ref('accepted1').checked = true;
    div_ref('accepted2').checked = true;
  } else if (set == 'off') {
    div_ref('accepted1').checked = false;
    div_ref('accepted2').checked = false;
  } else {
    F2 = open("privacy.tandem.popup.php", "f2window", "width=400, height=300, top=200, left=200, resizable=no, scrollbars=yes, menubar=no, toolbar=no, status=no, location=no");
  }
}

function checkRegisterForm () {
  var theForm = document.inputForm;
  var allOK   = true;
  var error   = notallfilledout + ":\n";

  if (theForm.forename.value == "") {
    allOK  =  false;
    error  += "\n- " + forename;
  } else if (theForm.forename.value.length < 2) {
    allOK  =  false;
    error  += "\n- " + forename + "(" + toshort + ")";
  }
  if (theForm.surename.value == "") {
    allOK  =  false;
    error  += "\n- " + surename;
  } else if (theForm.surename.value.length < 2) {
    allOK  =  false;
    error  += "\n- " + surename + "(" + toshort + ")";
  }
  if (theForm.email.value == "") {
    allOK  =  false;
    error  += "\n- " + email;
  } else if (isEmail(theForm.email.value) == false) {
    allOK  =  false;
    error  += "\n- " + email + "(" + illegal + ")";
  }

  if (theForm.iamstudent.checked == true) {
    if (theForm.reformxtra1.value == "") {
      allOK  =  false;
      error  += "\n- " + college;
    }
    if (theForm.reformxtra2.value == "") {
      allOK  =  false;
      error  += "\n- " + studiepath;
    }
    if (checkStudieDate() == true) {
      if (theForm.reformxtra3.value == "") {
        allOK  =  false;
        error  += "\n- " + matrikelnr;
      }
    }
  }

  theForm.mobile.value = trim(theForm.mobile.value);
  var r = new RegExp("^([0-9]{4})[/ ]*?([0-9]*)$");

  if (!allOK) {
    alert(error);
    return false;
  } else if (smsmemo == true && !r.test(theForm.mobile.value)) {
    alert('Sie haben noch eine aktive SMS-Benachrichtigung. Bitte geben Sie eine gültige Handynummer an.');
    return false;
  } else if (theForm.accepted1.checked == false) {
    alert(mustacceptprivacy);
    return false;
  } else {
    return true;
  }
}

function checkNewPasswordForm () {
  var theForm = document.inputForm2;
  var allOK   = true;

  if (theForm.oldpassword.value == "" || theForm.newpassword.value == "" || theForm.conpassword.value == "") {
    var error   = notallfilledout + ":\n";

    if (theForm.oldpassword.value == "") {
      allOK  =  false;
      error  += "\n- " + oldpassword;
    }
    if (theForm.newpassword.value == "") {
      allOK  =  false;
      error  += "\n- " + newpassword;
    }
    if (theForm.conpassword.value == "") {
      allOK  =  false;
      error  += "\n- " + conpassword;
    }
  } else {
    if (hex_md5(theForm.oldpassword.value) != olduserpassword) {
      allOK  =  false;
      error  = invalidoldpassword;
    } else if (theForm.conpassword.value != theForm.newpassword.value) {
      allOK  =  false;
      error  = passwordsdontmatch;
    }
  }

  if (!allOK) {
    alert(error);
    return false;
  } else {
    return true;
  }
}

function checkLoginForm () {
  var theForm = document.inputForm;
  var allOK   = true;
  var error   = notallfilledout + ":\n";

  if (theForm.email.value == "") {
    allOK  =  false;
    error  += "\n- " + email;
  } else if (isEmail(theForm.email.value) == false) {
    allOK  =  false;
    error  += "\n- " + email + "(" + illegal + ")";
  }
  if (theForm.password.value == "") {
    allOK  =  false;
    error  += "\n- " + password;
  }

  if (!allOK) {
    alert(error);
    return false;
  } else {
    return true;
  }
}

function checkLoginFormRP () {
  var theForm = document.inputForm2;
  var allOK   = true;
  var error   = notallfilledout + ":\n";

 // if ( typeof(th) )
  if (theForm.email.value == "") {
    allOK  =  false;
    error  += "\n- " + email;
  } else if (isEmail(theForm.email.value) == false) {
    allOK  =  false;
    error  += "\n- " + email + "(" + illegal + ")";
  }

  if (!allOK) {
    alert(error);
    return false;
  } else {
    return true;
  }
}

function checkTandemForm () {
  var theForm = document.inputForm;
  var allOK   = true;
  var error   = notallfilledout + ":\n";

  if (theForm.email.value == "" && theForm.phone.vaue == "") {
    allOK  =  false;
    error  += "\n- " + emailorphone;
  }
  if (theForm.requestLang.value == "") {
    allOK  =  false;
    error  += "\n- " + requestLang;
  }
  if (theForm.offerLang.value == "") {
    allOK  =  false;
    error  += "\n- " + offerLang;
  }
  if (theForm.publish_inet.checked == false && theForm.publish_cali.checked == false && theForm.publish_ince.checked == false) {
    allOK  =  false;
    error  += "\n- " + publishat;
  }

  if (!allOK) {
    alert(error);
    return false;
  } else if (theForm.accepted1.checked == false) {
    alert(mustacceptprivacy);
    return false;
  } else {
    return true;
  }
}

function checkAccoServiceFormStep1 () {
  var theForm = document.inputForm2;
  var allOK   = true;
  var error   = notallfilledout + ":\n";

  if ((document.getElementById('roomtype0').checked && (theForm.rooms.value == '' || !isInt(theForm.rooms.value)))
  ||  (document.getElementById('roomtype1').checked && (theForm.wgs.value == '' || !isInt(theForm.wgs.value)))
  ||  (document.getElementById('roomtype2').checked && (theForm.roomcount.value == '' || !isHalfInt(theForm.roomcount.value)))) {
    allOK = false;
    error  += "\n- " + 'Zimmertyp (ungültige Zimmeranzahl)';
  }

  if (theForm.streetnr.value == "") {
    allOK = false;
    error  += "\n- " + streeno;
  }

  /*
  if (theForm.zipcode.value == "") {
    allOK  =  false;
    error  += "\n- " + zipcode;
  } else if (theForm.zipcode.value.length != 5 || !isInt(theForm.zipcode.value)) {
    allOK  =  false;
    error  += "\n- " + zipcode + " (" + illegal + ")";
  }
  */

  if (theForm.location.value == "") {
    allOK  =  false;
    error  += "\n- " + thelocation;
  }

  //if (theForm.district.value == "") {
  //  allOK = false;
  //  error  += "\n- " + detail_district;
  //}

  if (!allOK) {
    alert(error);
    return false;
  } else {
    return true;
  }
}

function isPrice (str) {
  var supported = 0;
  if (window.RegExp) {
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;
  }

  if (!supported) return true;

  var r = new RegExp("^[0-9]+(\\.[0-9]{3,3})*(,[0-9]{2,2})*$");
  return (r.test(str));
}

function isInt (str) {
  var supported = 0;
  if (window.RegExp) {
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;
  }

  if (!supported) return true;

  var r = new RegExp("^[0-9]+$");
  return (r.test(str));
}

function isHalfInt (str) {
  var supported = 0;
  if (window.RegExp) {
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;
  }

  if (!supported) return true;

  var r = new RegExp("^[0-9]+(,5)?$");
  return (r.test(str) && parseInt(str) != 0 && str != '0,5');
}

function checkAccoServiceFormStep2 () {
  var theForm = document.inputForm2;
  var allOK   = true;
  var error   = notallfilledout + ":\n";

  if (theForm.space.value == "") {
    allOK  =  false;
    error  += "\n- " + space;
  } else if (!isInt(theForm.space.value)) {
    allOK  =  false;
    error  += "\n- " + space + "(" + illegal + ")";
  }
  if (theForm.rent.value == "") {
    allOK  =  false;
    error  += "\n- " + detail_rent;
  } else if (!isPrice(theForm.rent.value)) {
    allOK  =  false;
    error  += "\n- " + detail_rent + "(" + illegal + ")";
  }
  if (document.getElementById('rcmode2').checked != true) {
    if (theForm.relatedcosts.value == "") {
      allOK  =  false;
      error  += "\n- " + detail_relatedcosts;
    } else if (!isPrice(theForm.relatedcosts.value)) {
      allOK  =  false;
      error  += "\n- " + detail_relatedcosts + "(" + illegal + ")";
    }
  }
  /*
  if (theForm.caution.value == "") {
    allOK  =  false;
    error  += "\n- " + detail_caution;
  } else if (!isPrice(theForm.caution.value)) {
    allOK  =  false;
    error  += "\n- " + detail_caution + "(" + illegal + ")";
  }
  */

  if (!allOK) {
    alert(error);
    return false;
  } else {
    return true;
  }
}

function checkAccoServiceFormStep3 () {
  var theForm = document.inputForm2;
  var allOK   = true;
  var error   = notallfilledout + ":\n";

  if (!allOK) {
    alert(error);
    return false;
  } else {
    return true;
  }
}

function checkAccoServiceFormStep4 () {
  var theForm = document.inputForm2;
  var allOK   = true;
  var error   = notallfilledout + ":\n";

  if (!allOK) {
    alert(error);
    return false;
  } else {
    return true;
  }
}

function checkLearngroupForm () {
  var theForm = document.inputForm;
  var allOK   = true;
  var error   = notallfilledout + ":\n";

  if (theForm.subject.value == "") {
    allOK  =  false;
    error  += "\n- " + subject;
  }
  if (theForm.location.value == "") {
    allOK  =  false;
    error  += "\n- " + thelocation;
  }
  if (theForm.datetime.value == "") {
    allOK  =  false;
    error  += "\n- " + datetime;
  }
  if (theForm.description.value == "") {
    allOK  =  false;
    error  += "\n- " + description;
  }

  if (!allOK) {
    alert(error);
    return false;
  } else {
    return true;
  }
}

function checkEmailForm () {
  var theForm = document.inputForm;
  var allOK   = true;
  var error   = notallfilledout + ":\n";

  if (theForm.subject.value == "") {
    allOK  =  false;
    error  += "\n- " + subject2;
  }
  if (theForm.message.value == "") {
    allOK  =  false;
    error  += "\n- " + message;
  }

  if (!allOK) {
    alert(error);
    return false;
  } else {
    return true;
  }
}

function checkCommentFormLearngroups () {
  var theForm = document.inputForm2;
  var allOK   = true;
  var error   = notallfilledout + ":\n";

  if (theForm.comment.value == "") {
    allOK  =  false;
    error  += "\n- " + comment;
  }
  if (theForm.attachment.value != "") {
    var checkFile = theForm.attachment.value;
    var lastDot = checkFile.lastIndexOf('.');
    var ext = checkFile.substr(lastDot + 1);

    var aft = new Array('pdf', 'xls', 'doc', 'rtf', 'txt', 'jpg', 'gif', 'zip', 'rar');
    var wrongtype = true;
    for (i=0; i<aft.length; i++) if (aft[i] == ext) wrongtype = false;

    if (wrongtype) {
      allOK  =  false;
      error  += "\n- " + nofiletype;
    }
  }

  if (!allOK) {
    alert(error);
    return false;
  } else {
    return true;
  }
}

function showProceedButton () {
  clearInterval(counter);
  div_ref_style("arrowRight").display = "block";
}

function changeGroupDisplay (theGroup, theMode) {
  var i = 0;
  while (true) {
    div_ref_style(theGroup + i).display = theMode;
    i++;
    if (div_ref(theGroup + i) == undefined) break;
  }
}

var oldTabID = 'info';
function activateTab (tabID) {
  if (oldTabID != undefined && oldTabID != "") {
    if (oldTabID == 'info') {
      div_ref_style('linetab_' + oldTabID).backgroundColor = '#FFFFFF';
      div_ref_style('linetab_' + oldTabID).borderBottomColor = '#CCCCCC';
      div_ref_style('linetab_' + oldTabID).color = '#999999';
      //div_ref_style('linetab_' + oldTabID).padding = '2px 6px 0px 6px;';
      div_ref_style('linetab_' + oldTabID).margin = '2px 0px 0px 0px;';
    } else {
      div_ref_style('linetab_' + oldTabID).backgroundColor = '#DDDDDD';
      div_ref_style('linetab_' + oldTabID).borderBottomColor = '#CCCCCC';
      div_ref_style('linetab_' + oldTabID).color = '#999999';
      if (tabID != 'info') changeGroupDisplay('linecol_' + oldTabID + '_', 'none');
      //div_ref_style('linetab_' + oldTabID).padding = '2px 6px 0px 6px;';
      div_ref_style('linetab_' + oldTabID).margin = '2px 0px 0px 0px;';
    }
  }

  if (tabID == 'info') {
    div_ref_style('linetab_' + tabID).backgroundColor = '#F9E866';
    div_ref_style('linetab_' + tabID).borderBottomColor = '#FFFFFF';
    div_ref_style('linetab_' + tabID).color = '#000000';
    window.location.href = "speiseplaene.php?page=" + linkToInfoPage + "&fbv=" + varsity;
  } else {
    div_ref_style('linetab_' + tabID).backgroundColor = '#FFFFFF';
    div_ref_style('linetab_' + tabID).borderBottomColor = '#FFFFFF';
    div_ref_style('linetab_' + tabID).color = '#000000';
    changeGroupDisplay('linecol_' + tabID + '_', 'block');
    //div_ref_style('linetab_' + tabID).padding = '2px 6px 2px 6px;';
    div_ref_style('linetab_' + tabID).margin = '0px 0px 0px 0px;';
  }

  oldTabID = tabID;
}

function overTab (tabID, mode) {
  if (mode == 0 && oldTabID != tabID) {
    if (tabID == 'info') {
      div_ref_style('linetab_' + tabID).backgroundColor = '#FFFFFF';
      div_ref_style('linetab_' + tabID).borderBottomColor = '#CCCCCC';
      div_ref_style('linetab_' + tabID).color = '#999999';
      //div_ref_style('linetab_' + tabID).padding = '2px 6px 0px 6px;';
      div_ref_style('linetab_' + tabID).margin = '2px 0px 0px 0px;';
      //div_ref_style('linetab_' + tabID).height = '14px';
    } else {
      div_ref_style('linetab_' + tabID).backgroundColor = '#DDDDDD';
      div_ref_style('linetab_' + tabID).borderBottomColor = '#CCCCCC';
      div_ref_style('linetab_' + tabID).color = '#999999';
      //div_ref_style('linetab_' + tabID).padding = '2px 6px 0px 6px;';
      div_ref_style('linetab_' + tabID).margin = '2px 0px 0px 0px;';
    }
  } else {
    if (tabID == 'info') {
      div_ref_style('linetab_' + tabID).backgroundColor = '#F9E866';
      div_ref_style('linetab_' + tabID).borderBottomColor = '#F9E866';
      div_ref_style('linetab_' + tabID).color = '#000000';
      //div_ref_style('linetab_' + tabID).padding = '2px 6px 2px 6px;'
      div_ref_style('linetab_' + tabID).margin = '2px 0px 0px 0px;';
      //div_ref_style('linetab_' + tabID).height = '14px';
    } else {
      div_ref_style('linetab_' + tabID).backgroundColor = '#FFFFFF';
      div_ref_style('linetab_' + tabID).borderBottomColor = '#FFFFFF';
      div_ref_style('linetab_' + tabID).color = '#000000';
      //div_ref_style('linetab_' + tabID).padding = '2px 6px 2px 6px;'
      div_ref_style('linetab_' + tabID).margin = '2px 0px 0px 0px;';
    }
  }
}

function info_activateTab (tabID) {
  if (tabID == 'info') {
    div_ref_style('linetab_' + tabID).backgroundColor = '#F9E866';
    div_ref_style('linetab_' + tabID).borderBottomColor = '#F9E866';
    div_ref_style('linetab_' + tabID).color = '#000000';
    //div_ref_style('linetab_' + tabID).padding = '2px 6px 2px 6px;';
    div_ref_style('linetab_' + tabID).margin = '0px 0px 0px 0px;';
  } else {
    div_ref_style('linetab_' + tabID).backgroundColor = '#FFFFFF';
    div_ref_style('linetab_' + tabID).borderBottomColor = '#F9E866';
    div_ref_style('linetab_' + tabID).color = '#000000';
    //div_ref_style('linetab_' + tabID).padding = '2px 6px 2px 6px;';
    div_ref_style('linetab_' + tabID).margin = '0px 0px 0px 0px;';
    window.location.href = "speiseplaene.php?varsity=" + fbv + "&datemode=0&startdate=___" + date_norm + "&firstID=" + tabID;
  }

  oldTabID = tabID;
}

function info_overTab (tabID, mode) {
  if (mode == 0 && oldTabID != tabID) {
    div_ref_style('linetab_' + tabID).backgroundColor = '#DDDDDD';
    div_ref_style('linetab_' + tabID).borderBottomColor = '#CCCCCC';
    div_ref_style('linetab_' + tabID).color = '#999999';
    div_ref_style('linetab_' + tabID).padding = '2px 6px 0px 6px;';
    div_ref_style('linetab_' + tabID).margin = '2px 0px 0px 0px;';
  } else if (tabID != 'info') {
    div_ref_style('linetab_' + tabID).backgroundColor = '#FFFFFF';
    div_ref_style('linetab_' + tabID).borderBottomColor = '#F9E866';
    div_ref_style('linetab_' + tabID).color = '#000000';
    div_ref_style('linetab_' + tabID).padding = '2px 6px 2px 6px;'
    div_ref_style('linetab_' + tabID).margin = '0px 0px 0px 0px;';
  }
}

months = [];
months[1]  = "Jan";
months[2]  = "Feb";
months[3]  = "Mar";
months[4]  = "Apr";
months[5]  = "May";
months[6]  = "Jun";
months[7]  = "Jul";
months[8]  = "Aug";
months[9]  = "Sep";
months[10] = "Oct";
months[11] = "Nov";
months[12] = "Dec";

var weekdays = new Array("So","Mo","Di","Mi","Do","Fr","Sa");
var calenderField;

function setUpZero (string, length) {
  string = string + "";
  while (string.length < length) string = "0" + string;
  return string;
}

function setDate (fieldName, value) {
  checkDate(calenderField, value);
}

function getDate (value) {
  var match = /(\d*)\.(\d*)\.(\d*)/;
  if (match.test(value) == false) value = date_dmy;
  match.exec(value);

  var vf = new Array(RegExp.$1 * 1, RegExp.$2 * 1 - 1, RegExp.$3);

  if (vf[0] < 1 || vf[0] > 31) vf[0] = date_d;
  if (vf[1] < 0 || vf[1] > 11) vf[1] = date_m;
  if (vf[2].length > 2) vf[2] = vf[2].substring(vf[2].length-2, vf[2].length);
  if (vf[2].length < 2) vf[2] = setUpZero(vf[2], 2);

  var selfDateO = new Date("20" + vf[2], vf[1], vf[0]);

  return selfDateO.getTime();
}

function getDateObject (value) {
  var match = /(\d*)\.(\d*)\.(\d*)/;
  if (match.test(value) == false) value = date_dmy;
  match.exec(value);

  var vf = new Array(RegExp.$1 * 1, RegExp.$2 * 1 - 1, RegExp.$3);


  if (vf[0] < 1 || vf[0] > 31) vf[0] = date_d;
  if (vf[1] < 0 || vf[1] > 11) vf[1] = date_m;
  if (vf[2].length > 2) vf[2] = vf[2].substring(vf[2].length-2, vf[2].length);
  if (vf[2].length < 2) vf[2] = setUpZero(vf[2], 2);

  var selfDateO = new Date("20" + vf[2], vf[1], vf[0]);

  return selfDateO;
}


function checkDate (field, newValue, noerror) {
  if (newValue != undefined) {
    value = newValue;
  } else {
    value = field.value;
  }

  //add for stw\\
  if (field.name == "enddateRange" && value == "") div_ref_style('dayrange').display = 'block';
  //\\

  if (value == "") return true;

  //add for stw\\
  if (field.name == "enddateRange") div_ref_style('dayrange').display = 'none';
  //\\

  var match = /(\d*)\.(\d*)\.(\d*)/;
  if (match.test(value) == false) value = date_dmy;
  match.exec(value);

  var vf = new Array(RegExp.$1 * 1, RegExp.$2 * 1 - 1, RegExp.$3);

  if (vf[0] < 1 || vf[0] > 31) vf[0] = date_d;
  if (vf[1] < 0 || vf[1] > 11) vf[1] = date_m;
  if (vf[2].length > 2) vf[2] = vf[2].substring(vf[2].length-2, vf[2].length);
  if (vf[2].length < 2) vf[2] = setUpZero(vf[2], 2);

  dateO = new Date("20" + vf[2], vf[1], vf[0]);

  if (max6months != undefined && max6months != null) {
    if (max6months[field.id] != undefined) {
      if (dateO.getTime() > getDate(max6months[field.id])) {
        var sd = getDateObject(max6months[field.id]);
        checkDate(field, weekdays[sd.getDay()] + ", " + setUpZero(sd.getDate(), 2) + "." + setUpZero(sd.getMonth()+1, 2) + "." + (sd.getFullYear() + "").substring(2, 4));
        window.alert('Gewünschter Einzugstermin muss innerhalb der nächsten 6 Monate liegen.');
      }
    }
  }

  if (max5years != undefined && max5years != null) {
    if (max5years[field.id] != undefined) {
      if (dateO.getTime() > getDate(max5years[field.id])) {
        var sd = getDateObject(max5years[field.id]);
        checkDate(field, weekdays[sd.getDay()] + ", " + setUpZero(sd.getDate(), 2) + "." + setUpZero(sd.getMonth()+1, 2) + "." + (sd.getFullYear() + "").substring(2, 4));
        window.alert('Gewünschte Wohndauer darf maximal 5 Jahre im vorraus liegen.');
      }
    }
  }

  if (conditions != undefined && conditions != null) {
    if (conditions[field.id] != undefined) {
      tC = conditions[field.id];

      if (tC[0] == "goet") {
        if (dateO.getTime() < getDate(tC[1])) {
          checkDate(field, date_dmy);
          if (noerror != 'noerror') window.alert('Datumseingabe ungültig.');
          return false;
        }
      }

      if (tC[0] == "goec") {
        if (dateO.getTime() < getDate(tC[1].value)) {
          if (noerror != 'noerror') window.alert('Datumseingabe ungültig.');
          var sd = getDateObject(tC[1].value);
          checkDate(field, weekdays[sd.getDay()] + ", " + setUpZero(sd.getDate(), 2) + "." + setUpZero(sd.getMonth()+1, 2) + "." + (sd.getFullYear() + "").substring(2, 4));
          return false;
        }
      }
    }
  }

  oldValue = field.value;
  field.value = weekdays[dateO.getDay()] + ", " + setUpZero(dateO.getDate(), 2) + "." + setUpZero(dateO.getMonth()+1, 2) + "." + (dateO.getFullYear() + "").substring(2, 4);

  for (i in conditions) {
    if (conditions[i][0] == 'goec' && div_ref(i) != field) {
      tC = conditions[i];
      if (getDate(div_ref(i).value) < getDate(tC[1].value) && div_ref(i).value != "") {
        field.value = oldValue;
        window.alert('Datumseingabe ungültig.');
        return false;
        var sd = getDateObject(tC[1].value);
        div_ref(i).value = weekdays[dateO.getDay()] + ", " + setUpZero(dateO.getDate(), 2) + "." + setUpZero(dateO.getMonth()+1, 2) + "." + (dateO.getFullYear() + "").substring(2, 4);
      }
    }
  }

  if (field.name == 'entering_date') {
    var now = new Date();
    var now_string = weekdays[now.getDay()] + ", " + setUpZero(now.getDate(), 2) + "." + setUpZero(now.getMonth()+1, 2) + "." + (now.getFullYear() + "").substring(2, 4);

    if (field.value == now_string) {
      document.inputForm2['other_entering[1]'].disabled = true;
      document.inputForm2['other_entering[1]'].checked = false;
    } else {
      document.inputForm2['other_entering[1]'].disabled = false;
    }
  }
}

function setUpDate (field, mode) {
  emptyValue = false;
  value = field.value;
  var match = /(\d*)\.(\d*)\.(\d*)/;
  if (match.test(value) == false) emptyValue = true;
  if (emptyValue) value = date_dmy;
  match.exec(value);

  var vf = new Array(RegExp.$1 * 1, RegExp.$2 * 1 - 1, RegExp.$3);

  if (vf[0] < 1 || vf[0] > 31) vf[0] = date_d;
  if (vf[1] < 0 || vf[1] > 11) vf[1] = date_m;
  if (vf[2].length > 2) vf[2] = vf[2].substring(vf[2].length-2, vf[2].length);
  if (vf[2].length < 2) vf[2] = setUpZero(vf[2], 2);

  dateO = new Date("20" + vf[2], vf[1], vf[0]);

  if (mode == "up") {
    tsn = dateO.getTime() + 24*60*60*1000;
  } else if (emptyValue) {
    tsn = dateO.getTime();
  } else {
    tsn = dateO.getTime() - 24*60*60*1000;
  }

  dateO.setTime(tsn);

  newValue = weekdays[dateO.getDay()] + ", " + setUpZero(dateO.getDate(), 2) + "." + setUpZero(dateO.getMonth()+1, 2) + "." + (dateO.getFullYear() + "").substring(2, 4);
  checkDate(field, newValue);

  //add for stw\\
  if (field.name == "enddateRange") div_ref_style('dayrange').display = 'none';
  //\\
}

function openCalender (field) {
  calenderField = field;
  F1 = open("calender.php?field=" + field, "f1window", "width=225, height=190, top=400, left=300, resizable=no, scrollbars=no, menubar=no, toolbar=no, status=no, location=no");
}

function printIt () {
  if (!window.print && document.all) {
    var OLECMDID_PRINT = 6;
    var OLECMDEXECOPT_DONTPROMPTUSER = 2;
    var OLECMDEXECOPT_PROMPTUSER = 1;
    var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH="0" HEIGHT="0" CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
    document.body.insertAdjacentHTML('beforeEnd',WebBrowser);
    WebBrowser1.ExecWB(OLECMDID_PRINT,OLECMDEXECOPT_DONTPROMPTUSER);
    WebBrowser1.outerHTML = '';
  } else {
    print();
  }
}

function trim (s) {
  while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r')) s = s.substring(1,s.length);
  while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r')) s = s.substring(0,s.length-1);
  return s;
}

function empty (s) {
  s = trim(s);
  if (s == '') {
    return true;
  }

  return false;
}