function ClassCheckform(thisform) {
	this.errors = "";
	this.checkfield = checkfield;
	this.checkmail = checkmail;
	this.checkdate = checkdate;
	this.checkhttp = checkhttp;
	this.checkradio = checkradio;
	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 checkmail(fvalue, fname, required){
	var regexp = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/
	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 field = this.thisform[fvalue].value;
	var chkdate = true;
	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";
}
