function Validation( oForm )
{
	this._form = oForm;
	this._errors = new Object();
}
Validation.prototype.validate = function( iPage )
{
	if( typeof iPage != 'number' )
		return false;
	
	this.removeErrors();
	
	switch( iPage )
	{
		case 0:
			return this.validateOne();
			break;
		case 1:
			return this.validateTwo();
			break;
		case 2:
			return this.validateThree();
			break;
		case 3:
			return this.validateFour();
			break;
		case 4:
			return this.validateFive();
			break;
		case 5:
			return this.validateSix();
			break;
		default:
			return true;
			break;
	}
}
Validation.prototype.validateOne = function()
{
	var bCorrect = true;
	if( this._form.roepnaam.value == '' )
	{
		if( this._errors.roepnaam == undefined )
			this._errors['roepnaam'] = this.addError( this._form.roepnaam );		
		bCorrect = false;
	}
	
	var oAge = this.checkDate( this._form.geboortedatum.value );
	if( this._form.geboortedatum.value == '' )
	{
		if( this._errors.geboortedatum == undefined )
			this._errors['geboortedatum'] = this.addError( this._form.geboortedatum );
		bCorrect = false;
	}
	else if( !oAge[ 0 ] )
	{
		if( this._errors.geboortedatum == undefined )
			this._errors['geboortedatum'] = this.addError( this._form.geboortedatum, "Vul een geldige datum in. Bijvoorbeeld 01-01-2010." );
		bCorrect = false;
	}
	else if( !oAge[ 1 ] )
	{
		if( this._errors.geboortedatum == undefined )
			this._errors['geboortedatum'] = this.addError( this._form.geboortedatum, "Vul een datum in het verleden in." );
		bCorrect = false;
	}
	
	oAge = this.checkDate( this._form.inbezitsinds.value );
	if( this._form.inbezitsinds.value == '' )
	{
		if( this._errors.inbezitsinds == undefined )
			this._errors['inbezitsinds'] = this.addError( this._form.inbezitsinds );
		bCorrect = false;
	}
	else if( !oAge[ 0 ] )
	{
		if( this._errors.inbezitsinds == undefined )
			this._errors['inbezitsinds'] = this.addError( this._form.inbezitsinds, "Vul een geldige datum in. Bijvoorbeeld 01-01-2010." );
		bCorrect = false;
	}
	else if( !oAge[ 1 ] )
	{
		if( this._errors.inbezitsinds == undefined )
			this._errors['inbezitsinds'] = this.addError( this._form.inbezitsinds, "Vul een datum in het verleden in." );
		bCorrect = false;
	}
	
	if( !this.validateRadio( this._form.soorthuisdier ) )
	{
		if( this._errors.soorthuisdier == undefined )
			this._errors['soorthuisdier'] = this.addError( this._form.soorthuisdier[ 0 ] );
		bCorrect = false;
	}
	
	if( !this.validateRadio( this._form.geslacht ) )
	{
		if( this._errors.geslacht == undefined )
			this._errors['geslacht'] = this.addError( this._form.geslacht[ 0 ] );
		bCorrect = false;
	}
	
	if( !this.validateRadio( this._form.castratie ) )
	{
		if( this._errors.castratie == undefined )
			this._errors['castratie'] = this.addError( this._form.castratie[ 0 ] );
		bCorrect = false;
	}
	
	if( !this.validateRadio( this._form.identificatiechip ) )
	{
		if( this._errors.identificatiechip == undefined )
			this._errors['identificatiechip'] = this.addError( this._form.identificatiechip[ 0 ] );
		bCorrect = false;
	}
	
	if( this.isVisible( this._form.chipnummer ) && this._form.chipnummer.value != '' && ( this._form.chipnummer.value.length < 15 || !this.isNumeric( this._form.chipnummer.value ) ) ) 
	{
		if( this._errors.chipnummer == undefined )
			this._errors['chipnummer'] = this.addError( this._form.chipnummer );
		bCorrect = false;
	}
	
	if( ( this._form.volgroeidgewicht.value == '' || !this.isNumeric( this._form.volgroeidgewicht.value ) || this._form.volgroeidgewicht.value > 99 ) && this.isVisible( this._form.volgroeidgewicht ) )
	{
		if( this._errors.volgroeidgewicht == undefined )
			this._errors['volgroeidgewicht'] = this.addError( this._form.volgroeidgewicht );
		bCorrect = false;
	}
	
	if( this._form.ras.value == '' )
	{
		if( this._errors.ras == undefined )
			this._errors['ras'] = this.addError( this._form.ras );
		bCorrect = false;
	}
	
	/*if( this._form.kruisingmet.value == '' )
	{
		if( this._errors.kruisingmet == undefined )
			this._errors['kruisingmet'] = this.addError( this._form.kruisingmet );
		bCorrect = false;
	}*/
	
	return bCorrect;
}
Validation.prototype.validateTwo = function()
{
	var bCorrect = true;
	
	if( !this.validateRadio( this._form.zorgpakket ) )
	{
		if( this._errors.zorgpakket == undefined )
			this._errors['zorgpakket'] = this.addError( this._form.zorgpakket[ 0 ] );
		bCorrect = false;
	}
	
	if( !this.validateRadio( this._form.eigenbijdrage ) )
	{
		if( this._errors.eigenbijdrage == undefined )
			this._errors['eigenbijdrage'] = this.addError( this._form.eigenbijdrage[ 0 ] );
		bCorrect = false;
	}
	
	if( !this.validateRadio( this._form.looptijdverz ) )
	{
		if( this._errors.looptijdverz == undefined )
			this._errors['looptijdverz'] = this.addError( this._form.looptijdverz[ 0 ] );
		bCorrect = false;
	}
	
	return bCorrect;
}
Validation.prototype.validateThree = function()
{
	var bCorrect = true;
	
	if( this._form.praktijknaam.value == '' )
	{
		if( this._errors.praktijknaam == undefined )
			this._errors['praktijknaam'] = this.addError( this._form.praktijknaam );
		bCorrect = false;
	}
	
	if( this._form.postcodeplaats.value == '' )
	{
		if( this._errors.postcodeplaats == undefined )
			this._errors['postcodeplaats'] = this.addError( this._form.postcodeplaats );
		bCorrect = false;
	}
	
	if( !this.validateRadio( this._form.controlearts ) )
	{
		if( this._errors.controlearts == undefined )
			this._errors['controlearts'] = this.addError( this._form.controlearts[ 0 ] );
		bCorrect = false;
	}
	
	if( !this.validateRadio( this._form.dierenarts ) )
	{
		if( this._errors.dierenarts == undefined )
			this._errors['dierenarts'] = this.addError( this._form.dierenarts[ 0 ] );
		bCorrect = false;
	}
	
	if( !this.validateRadio( this._form.verderebehandeling ) && this.isVisible( this._form.verderebehandeling[ 0 ] ) )
	{
		if( this._errors.verderebehandeling == undefined )
			this._errors['verderebehandeling'] = this.addError( this._form.verderebehandeling[ 0 ] );
		bCorrect = false;
	}
	
	if( this._form.verderebehandelinguitleg.value == '' && this.isVisible( this._form.verderebehandelinguitleg ) )
	{
		if( this._errors.verderebehandelinguitleg == undefined )
			this._errors['verderebehandelinguitleg'] = this.addError( this._form.verderebehandelinguitleg );
		bCorrect = false;
	}
	
	if( !this.validateRadio( this._form.medicijnen ) )
	{
		if( this._errors.medicijnen == undefined )
			this._errors['medicijnen'] = this.addError( this._form.medicijnen[ 0 ] );
		bCorrect = false;
	}
	
	if( this._form.medicijnenuitleg.value == '' && this.isVisible( this._form.medicijnenuitleg ) )
	{
		if( this._errors.medicijnenuitleg == undefined )
			this._errors['medicijnenuitleg'] = this.addError( this._form.medicijnenuitleg );
		bCorrect = false;
	}
	
	if( !this.validateRadio( this._form.vollediggezond ) )
	{
		if( this._errors.vollediggezond == undefined )
			this._errors['vollediggezond'] = this.addError( this._form.vollediggezond[ 0 ] );
		bCorrect = false;
	}
	
	if( this._form.vollediggezonduitleg.value == '' && this.isVisible( this._form.vollediggezonduitleg ) )
	{
		if( this._errors.vollediggezonduitleg == undefined )
			this._errors['vollediggezonduitleg'] = this.addError( this._form.vollediggezonduitleg );
		bCorrect = false;
	}
	
	if( !this.validateRadio( this._form.verdererisicos ) )
	{
		if( this._errors.verdererisicos == undefined )
			this._errors['verdererisicos'] = this.addError( this._form.verdererisicos[ 0 ] );
		bCorrect = false;
	}
	
	if( this._form.verdererisicosuitleg.value == '' && this.isVisible( this._form.verdererisicosuitleg ) )
	{
		if( this._errors.verdererisicosuitleg == undefined )
			this._errors['verdererisicosuitleg'] = this.addError( this._form.verdererisicosuitleg );
		bCorrect = false;
	}
	
	return bCorrect;
}
Validation.prototype.validateFour = function()
{
	var bCorrect = true;
	
	if( !this.validateRadio( this._form.betalingswijze ) )
	{
		if( this._errors.betalingswijze == undefined )
			this._errors['betalingswijze'] = this.addError( this._form.betalingswijze[ 0 ] );
		bCorrect = false;
	}
	
	if( this._form.banknummer.value == '' || !this.isBankaccount( this._form.banknummer.value ) )
	{
		if( this._errors.banknummer == undefined )
			this._errors['banknummer'] = this.addError( this._form.banknummer );
		bCorrect = false;
	}
	
	if( this._form.naamrekening.value == '' )
	{
		if( this._errors.naamrekening == undefined )
			this._errors['naamrekening'] = this.addError( this._form.naamrekening );
		bCorrect = false;
	}
	
	if( !this.validateRadio( this._form.ontvangstpolis ) )
	{
		if( this._errors.ontvangstpolis == undefined )
			this._errors['ontvangstpolis'] = this.addError( this._form.ontvangstpolis[ 0 ] );
		bCorrect = false;
	}
	
	return bCorrect;
}
Validation.prototype.validateFive = function()
{
	var bCorrect = true;
	
	if( this._form.clientnaam.value == '' )
	{
		if( this._errors.clientnaam == undefined )
			this._errors['clientnaam'] = this.addError( this._form.clientnaam );
		bCorrect = false;
	}
	
	if( !this.validateRadio( this._form.clientgeslacht ) && this.isVisible( this._form.clientgeslacht[ 0 ] ) )
	{
		if( this._errors.clientgeslacht == undefined )
			this._errors['clientgeslacht'] = this.addError( this._form.clientgeslacht[ 0 ] );
		bCorrect = false;
	}
	
	if( this._form.clientstraat.value == '' )
	{
		if( this._errors.clientstraat == undefined )
			this._errors['clientstraat'] = this.addError( this._form.clientstraat );
		bCorrect = false;
	}
	
	if(  this._form.clienthuisnummer.value == '' )
	{
		if( this._errors.clientstraat == undefined )
			this._errors['clientstraat'] = this.addError( this._form.clientstraat, "Vul uw huisnummer in." );
		bCorrect = false;
	}
	
	if( this._form.clientpostcode.value == '' || !this.isZipcode( this._form.clientpostcode.value ) )
	{
		if( this._errors.clientpostcode == undefined )
			this._errors['clientpostcode'] = this.addError( this._form.clientpostcode );
		bCorrect = false;
	}
	
	if( this._form.clientplaats.value == '' )
	{
		if( this._errors.clientpostcode == undefined )
			this._errors['clientpostcode'] = this.addError( this._form.clientpostcode, "Vul uw plaats in." );
		bCorrect = false;
	}
	
	var oAge = this.checkDate( this._form.clientgeboortedatum.value );
	if( this._form.clientgeboortedatum.value == '' )
	{
		if( this._errors.clientgeboortedatum == undefined )
			this._errors['clientgeboortedatum'] = this.addError( this._form.clientgeboortedatum );
		bCorrect = false;
	}
	else if( !oAge[ 0 ] )
	{
		if( this._errors.clientgeboortedatum == undefined )
			this._errors['clientgeboortedatum'] = this.addError( this._form.clientgeboortedatum, "Vul een geldige datum in. Bijvoorbeeld 01-01-1971" );
		bCorrect = false;
	}
	else if( !oAge[ 1 ] )
	{
		if( this._errors.clientgeboortedatum == undefined )
			this._errors['clientgeboortedatum'] = this.addError( this._form.clientgeboortedatum, "Vul een datum in het verleden in." );
		bCorrect = false;
	}
	
	if(  (this._form.clienttelefoon.value == '' || !this.checkPhone( this._form.clienttelefoon.value) ) && this.isVisible( this._form.clienttelefoon ) )
	{
		if( this._errors.clienttelefoon == undefined )
			this._errors['clienttelefoon'] = this.addError( this._form.clienttelefoon );
		bCorrect = false;
	}
	
	if( this._form.hoebekendmet.selectedIndex <= 0 )
	{
		if( this._errors.hoebekendmet == undefined )
			this._errors['hoebekendmet'] = this.addError( this._form.hoebekendmet );
		bCorrect = false;
	}
	
	return bCorrect;
}
Validation.prototype.validateSix = function()
{
		var bCorrect = true;
		
		if( !this.validateCheckbox( this._form.akkoord ) )
		{
			if( this._errors.akkoord == undefined )
				this._errors['akkoord'] = this.addError( this._form.akkoord );
			bCorrect = false;
		}
		
	if( this._form.looptijdverz[0].checked && this.isVisible( this._form.vijfjaarakkoord ) && !this.validateCheckbox( this._form.vijfjaarakkoord ) )
	{
		if( this._errors.vijfjaarakkoord == undefined )
			this._errors['vijfjaarakkoord'] = this.addError( this._form.vijfjaarakkoord );
		bCorrect = false;
	}
		return bCorrect;
}
Validation.prototype.addError = function( oNode, sError )
{
	oError = document.getElementById(oNode.name + 'error');
	if( oError )
	{
		if( typeof sError != 'undefined' )
		{
			var nError = document.getElementById(oNode.name + 'error2');
			if( !nError )
			{
				nError = oError.cloneNode(true);
				nError.id += '2';
				if( oError.nextSibling )
					oError.parentNode.insertBefore( nError, oError );
			}
			nError.innerHTML = sError;
			nError.className = 'error';
		}
		else
		{
			oError.className = 'error';
			return oError;
		}
	}
}
Validation.prototype.removeErrors = function()
{
	this._errors = new Object();
	var aDiv = this._form.getElementsByTagName( 'DIV' );
	for( var i = 0; i < aDiv.length; i++ )
	{
		if( aDiv[i].className == 'error' )
			aDiv[i].className = 'hidden';
	}
}
Validation.prototype.isVisible = function( oElement )
{
	if( !oElement.style )
		return true;
	
	if( oElement.style.display != 'none' && oElement.style.visibility != 'hidden' )
	{
		if( oElement.parentNode != 'undefined' )
			return this.isVisible( oElement.parentNode );
		else
			return true;
	}
	else
		return false;
}
Validation.prototype.validateCheckbox = function( oNode )
{
	return oNode.checked;
}
Validation.prototype.validateRadio = function( oNode )
{
	var bChecked = false;
	var i = 0;
	while (i < oNode.length)
	{
		if( oNode[ i ].checked )
		{
			bChecked = true;
			break;
		}
		i++;
	}
	
	return bChecked;
}
Validation.prototype.checkDate = function( sValue )
{
	var sTest = /([0-3]{1}[0-9]{1}-[0-1]{1}[0-9]{1}-[12]{1}[0-9]{3})/i;
	
	if( !sTest.test( sValue ) )
		return [ false, false ];
	
	year = parseInt( sValue.substring( 6, 10 ), 10 );
	month = parseInt( sValue.substring( 3, 5 ), 10 );
	day = parseInt( sValue.substring( 0, 2 ), 10 );
	month -= 1; // Month is zero-based
	var date = new Date( year, month, day );
	return [ true, date < new Date() ];
}
Validation.prototype.checkPhone = function( sValue )
{
	var sTest = /^((06((\s{0,1})|(\-{0,1}))[0-9]{8}$)|(^[0-9]{3}(\s{0,1}|\-{0,1})[0-9]{7}$)|(^[0-9]{4}(\s{0,1}|\-{0,1})[0-9]{6}$)|(^(\+{1}[0-9]{2}|[0]{2}[1-9]{2})(\s{0,1}|\-{0,1})[0-9]{2}(\s{0,1}|\-{0,1})[0-9]{7})$|(^(\+{1}[0-9]{2}|[0]{2}[1-9]{2})(\s{0,1}|\-{0,1})[0-9]{3}(\s{0,1}|\-{0,1})[0-9]{6}))$/i;
	return sTest.test( sValue );
}
Validation.prototype.checkEmail = function( sValue )
{
	var sTest = /^[_a-z0-9-]+([a-z0-9\.\+_-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3}|.info)$/i;
	return sTest.test( sValue );
}
Validation.prototype.isNumeric = function( sValue )
{
	return (sValue - 0) == sValue && sValue.length > 0;
}
Validation.prototype.isBankaccount = function( sValue )
{
	sValue = sValue.replace( /\D/g, '' );
	
	if( !this.isNumeric( sValue ) )
		return false;
	
	if( sValue.length <= 7 )
		return true; // Giro valt niet te checken
	else if( sValue.length == 8 )
		return false;
	else if( sValue.length > 10 )
		return false;
	
	if( sValue.length == 9 )
		sValue = '0' + sValue;
	
	var total = 0;
	for( var i = 1; i <= sValue.length; i++ )
		total += parseInt( sValue.charAt( i - 1 ), 10 ) * i;
	
	if( total == 0 )
		return false;
		
	return total % 11 == 0;
}
Validation.prototype.isZipcode = function( sValue )
{
	var sTest = /^[1-9]{1}[0-9]{3}[\s]*[a-zA-Z]{2}$/i
	return sTest.test( sValue );
}
