<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Original:  Torsten Frey (tf@tfrey.de) -->
<!-- Web Site:  http://www.tfrey.de -->

<!-- Modified and Complemented by Carsten Kreyser & Thorsten Kreutz -->
<!-- List of Modifications -->
<!-- check_date now correctly interpret days and months when noted in one char (TK)-->
<!-- check_Time now correctly interpret hours when noted in one char (TK)-->
<!-- check_Time now does not check empty fields which sometimes caused errors (TK)-->
<!-- List of New Functions -->
<!-- check_Number: is the field value a number? (CK) -->
<!-- check_Text: is the field value less or equal than max. amount of chars? (TK) -->
<!-- check_Integer: is the field value a positive integer? (TK) -->

<!-- Begin
function check_date(field){
  var checkstr = "0123456789";
  var DateField = field;
  var DateValue = "";
  var separator = ".";
  var separator1_pos;
  var separator2_pos;
  var day;
  var month;
  var year;
  var leap = 0;
  var err = 0;
  var i;
  var j = 0;

  DateValue = DateField.value;
  
  if (DateValue.length	> 0) {
    for (i = 0; i < DateValue.length; i++) {
      if ((isNaN(DateValue.substr(i,1)) == true) && (DateValue.substr(i,1) != separator)) {
        err = 19;
      }
    }
    if (err == 0) {
      for (i = 0; i < DateValue.length; i++) {
        if ((DateValue.substr(i,1)) == separator) {
          if (j == 0) {
            separator1_pos = i;
          }
          if (j == 1) {
            separator2_pos = i;
          }
          j++;
        }
      }
      if (j != 2) {
        err = 20;
      }
      day = DateValue.substr(0,separator1_pos);
      month = DateValue.substr(separator1_pos+1,separator2_pos-separator1_pos-1);
      year = DateValue.substr(separator2_pos+1,DateValue.length-1);
      // Validation of year
      if (year.length == 2) {
        if (year < 50) {
          year = 20 + year;
        }
        else {
          year = 19 + year;
        }
      }
      else if(year.length != 4) {
      	err = 26;
      }

	if(err == 0) {
	      // Validation of month
	      if (month.length == 1) {
	        month = 0 + month;
	      } 
	      if ((month < 1) || (month > 12)) {
	        err = 21;
	      }
	      //Validation of day
	      if (day.length == 1) {
	        day = 0 + day;
	      }
	      // Validation leap-year / february / day
	      if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) {
	        leap = 1;
	      }
	      if ((month == 2) && (leap == 1) && (day > 29)) {
	        err = 22;
	      }
	      if ((month == 2) && (leap != 1) && (day > 28)) {
	        err = 23;
	      }
	      // Validation of other months
	      if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) {
	        err = 24;
	      }
	      if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) {
	        err = 25;
	      }
	      // if 00 ist entered, no error, deleting the entry
	      if ((day == 0) && (month == 0) && (year == 00)) {
	        err = 0; day = ""; month = ""; year = ""; separator = "";
	      }
	    } 
	 }
    if (err != 0) {
      if (err == 19 || err == 20 || err == 26) {
        alert("Ungültiges Datum! Bitte im Format dd.mm.yyyy angeben!");
	  //return;
      }
      else {
        alert("Bitte ein gültiges Datum angeben!");
      }
      DateField.select();
  	  DateField.focus();
	  DateField.value = "";
    }
    else {
      DateField.value = day + separator + month + separator + year;
  	}
  }
}

function check_Time(field){
var checkstr = "0123456789";
var DateField = field;
var Datevalue = "";
var DateTemp = "";
var separator = ":";
var separator_pos = 0;
var hour;
var Minute;
var leap = 0;
var err = 0;
var i;
  err = 0;
  DateValue = DateField.value;
  /* Delete all chars except 0..9 */
  if (DateValue.length	> 0) {
    for (i = 0; i < DateValue.length; i++) {
      if ((DateValue.substr(i,1) == separator) && (separator_pos == 0)) {
        separator_pos = i;
      }
      if (checkstr.indexOf(DateValue.substr(i,1)) >= 0) {
        DateTemp = DateTemp + DateValue.substr(i,1);
      }
    }
    
    DateValue = DateTemp;
    if ((DateValue.length < 3) || (DateValue.length > 4)) {
      err = 19;}
    else {
      if (DateValue.length == 3) {
        if (separator_pos == 1) {
          hour = DateValue.substr(0,1);
          Minute= DateValue.substr(1,2);
        }
        else {
          hour = DateValue.substr(0,2);
          Minute= DateValue.substr(2,1) + "0";
        }
      }
      else {
        hour = DateValue.substr(0,2);
        Minute= DateValue.substr(2,2);
      }
      
      /* Validation of hour*/
      if ((hour < 0) || (hour > 24)) {
        err = 21;
      }
      /* Validation of Minute*/
      day = DateValue.substr(0,2);
      if ((Minute < 0) || (Minute > 59)) {
        err = 22;
      }
      if ((Minute > 0) && (hour == 24)) {
        err = 23;
      }
      /* if no error, write the completed time Input-Field (e.g. 17:00) */
      if (err == 0) {
        DateField.value = hour + separator + Minute;
      }
    }
  }
  /* Error-message if err != 0 */
  if (err != 0) {
    alert("Die Zeit ist Fehlerhaft! \nBitte geben Sie die Uhrzeit mit diesem Format ein:\nhh.mm (Beispiel 10.00)");
    DateField.value = "";
    DateField.select();
    DateField.focus();
  }
}

function checkamount(field){
var Anzahl= document.Order.Quantity.value;
var Preis = document.Order.Preis.value;
var Saldo = document.Order.Saldo.value;
var gPreis = 0;
var geht = 0;
gPreis= Anzahl * Preis;
geht= Saldo - gPreis;
if (geht < 0) {
	alert("Leider ist die Bestellung nicht durchführbar , da der Kontostand nicht ausreicht!!")
	document.Order.Quantity.value=1
	document.Order.Summe.value=Preis
	return true
   }
document.Order.Summe.value=gPreis;
}

function check_Number(field){
	
	if(isNaN(field.value)) {
		alert("Bitte geben sie als Wert eine Zahl an");
		field.select();
		field.focus();
	}
}

function check_Integer(field, dataValueLength){
  var DataValue = field.value;
  var i;
  var err = 0;
    
  if (DataValue.length	> 0) {
    for (i = 0; i < DataValue.length; i++) {
      if (isNaN(DataValue.substr(i,1)) == true) {
        err = 19;
      }
    }
  }
  
  if (DataValue > dataValueLength) {
    err = 20;
  }
  
  if (err != 0) {
    alert("Kein gültiger Zahlenwert!");
		field.select();
		field.focus();  
	}
}

function check_Text(field, textLength){
  var DataValue = field.value
  if (DataValue.length > textLength) {
    alert("Texteingabe ist zu lang. Bitte max. " + textLength + " Stellen verwenden!");
		field.select();
		field.focus();
	}
}
