function ClassCheckform(thisform) {

	this.errors = "";
	this.checkfield = checkfield;
	this.checkmail = checkmail;
	this.checkdate = checkdate;
	this.checktime = checktime;
	this.checkhttp = checkhttp;
	this.checkradio = checkradio;
	this.checknumeric = checknumeric;
	this.checkcurrency = checkcurrency;
	this.showerrors = showerrors;
	this.thisform = thisform;
	this.errortext = "Folgende Felder müssen korrekt ausgefüllt werden:";
}

function showerrors(){
	if (this.errors != ""){
		alert(this.errortext + "\n\n" + this.errors);
		return false;
	}else{
		return true;
	}
}

function checkcurrency(fvalue,fname) {
	var args = checkcurrency.arguments;
	var field = this.thisform[fvalue].value;
	var required = (args[2] == true) ? true : false;
	var nlower = args[3];
	var nupper = args[4];
	var valid = true;
	var curr = field.replace(/,/,".");

	if (required || (field != '' && !required)) {
		if (isNaN(curr)) valid = false;
		if (!isNaN(nlower)) if (nlower > curr)	valid = false;
		if (!isNaN(nupper)) if (curr > nupper) valid = false;
	}

	if (!valid) {
		this.errors += "- " + fname + "\n";
	}else{
		this.thisform[fvalue].value = curr.replace(/\./,",");
	}
}

function checknumeric(fvalue,fname) {
	var args = checknumeric.arguments;
	var field = this.thisform[fvalue].value;
	var required = (args[2] == true) ? true : false;
	var nlower = args[3];
	var nupper = args[4];
	var valid = true;

	if (required || (field != '' && !required)) {
		if (isNaN(field)) valid = false;
		if (!isNaN(nlower)) if (nlower > field)	valid = false;
		if (!isNaN(nupper)) if (field > nupper) valid = false;
	}
	
	if (!valid) this.errors += "- " + fname + "\n";

}

function checkmail(fvalue, fname, required) {
	//var regexp = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/
	var regexp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
	if (required){
		if (!regexp.test(this.thisform[fvalue].value)){
			this.errors += "- " + fname + "\n";
		}
	} else if (required == 0 && this.thisform[fvalue].value != ""){
		if (!regexp.test(this.thisform[fvalue].value)){
			this.errors += "- " + fname + "\n";
		}
	}
}

function checkfield(fvalue,fname){
	if (this.thisform[fvalue].value == "" || this.thisform[fvalue].value == null){
		this.errors += "- " + fname + "\n";
	}
}

function checkradio(fvalue, fname) {
	var btmp = false;
	for (i = 0; i < this.thisform[fvalue].length; i++) {
		if (this.thisform[fvalue][i].checked) {
			btmp = true;
			break;
		}
	}
	if (!btmp) this.errors += "- " + fname + "\n";
}
	
function checkhttp(fvalue){
	if (this.thisform[fvalue].value != ""){
		if (this.thisform[fvalue].value.substr(0,4) != "http"){
			url = this.thisform[fvalue].value;
			this.thisform[fvalue].value = "http://" + url;
		}
	}
}

function checkdate(fvalue,fname) {
	var args = checkdate.arguments
	var required = (args[2] == false) ? false : true;
	var field = this.thisform[fvalue].value;
	var chkdate = true;
	
	if (required || (field != '' && !required)) {
		var dd = Number(field.substr(0,2));
		var mm = Number(field.substr(3,2));
		var yy = Number(field.substr(6,4));

		var dot1 = field.substr(2,1);
		var dot2 = field.substr(5,1);
		var dom = 0;
	
		if (field.length != 10 || isNaN(dd) || dd > 31 || isNaN(mm) || mm > 12 || isNaN(yy) || yy < 1900){
			chkdate=false;			
		}else{
			if (yy<1900) yy+=2000;
			var leap = ((yy == (parseInt(yy/4) * 4)) && !(yy == (parseInt(yy/100) * 100)));
			if (mm < 1 || mm > 12) chkdate=false;
			if ((mm == 2) && (leap)) dom = 29;
			if ((mm == 2) && !(leap)) dom = 28;
			if ((mm == 1) || (mm == 3) || (mm == 5) || (mm == 7) || (mm == 8) || (mm == 10) || (mm == 12)) dom = 31;
			if ((mm == 4) || (mm == 6) || (mm == 9) || (mm == 11)) dom = 30;
			if (dd > dom) chkdate=false;
		}
	}

	if (!chkdate) this.errors += "- " + fname + "\n";
}

function checktime(fvalue,fname) {
	var args = checktime.arguments
	var required = (args[2] == false) ? false : true;
	var field = this.thisform[fvalue].value;
	var chktime = true;
	
	if (required || (field != '' && !required)) {
		var hh = Number(field.substr(0,2));
		var mm = Number(field.substr(3,2));

		var colon = field.substr(2,1);
		var dom = 0;
	
		if (field.length != 5 || isNaN(hh) || hh > 23 || isNaN(mm) || mm > 59){
			chktime=false;			
		}
	}

	if (!chktime) this.errors += "- " + fname + "\n";
}