function RequestForm()
{
	this.init();
	
	window[ ( this._self = "$_ImageListObject" ) ] = this;
}
RequestForm.prototype.init = function()
{
	this._heightfixor = new HeightFixor();
	this._container = document.getElementById('form');
	this._progressbar = document.getElementById('progressbar');
	this._form = Array();
	this._currentPage = 0;
	this._endSubmit = false;
	
	// start the validation
	this._validation = new Validation(this._container);
	
	this._buttons = document.getElementById('buttons').getElementsByTagName( 'input' );
	for( var i = 0; i < this._buttons.length; i++ )
	{
		this._buttons[ i ].onmouseover = function()
		{
			this.className += " over";
		}
		this._buttons[ i ].onmouseout = function()
		{
			this.className = this.className.replace(/ over/gi, "");;
		}
		this._buttons[ i ].onmousedown = function()
		{
			this.className += " click";
		}
		this._buttons[ i ].onmouseup = function()
		{
			this.className = this.className.replace(/ click/gi, "");;
		}
	}
	
	this._backbutton = document.getElementById('backbutton');
	this._backbutton._parent = this;
	this._backbutton.onclick = function()
	{
		this._parent.previouspage();
	}
	
	this._resetbutton = document.getElementById('resetbutton');
	this._resetbutton._parent = this;
	this._resetbutton.onclick = function()
	{
		this._parent.resetform();
	}
	
	this._endbutton = document.getElementById('endbutton');
	this._endbutton._parent = this;
	this._endbutton.onclick = function()
	{
		this._parent._endSubmit = true;
		this._parent.nextpage();
		if( document.getElementById( 'closingname' ) && this._parent._container.clientnaam.value != '' )
		{
			if( this._parent._container.clientgeslacht[ 0 ].checked )
				document.getElementById( 'closingname' ).innerHTML = 'Geachte heer ';
			else if( this._parent._container.clientgeslacht[ 1 ].checked )
				document.getElementById( 'closingname' ).innerHTML = 'Geachte mevrouw ';
			else
				document.getElementById( 'closingname' ).innerHTML = 'Geachte heer/mevrouw ';
			document.getElementById( 'closingname' ).innerHTML += this._parent._container.clientnaam.value + ",";
		}
	}
	
	this._submitbutton = document.getElementById('submitbutton');
	this._submitbutton._parent = this;
	this._submitbutton.onclick = function()
	{
		this._parent.nextpage();
	}
	
	if( this._container )
	{
		var n = 0;
		for( var j = 0; j < this._container.childNodes.length; j++ )
		{
			if( this._container.childNodes[ j ].nodeName.toLowerCase() == "div" && this._container.childNodes[ j ].className.match( "page" ) )
			{
				var oNode = this._container.childNodes[ j ];
				this.hide( oNode );
				this._form[ n++ ] = oNode;
			}
		}
	}
}
RequestForm.prototype.start = function( iPage )
{
	if( typeof iPage != 'number' )
		iPage = 0;
	this.hide( this._endbutton );
	this.hide( this._resetbutton );
	this._currentPage = iPage;
	this.showPage();
}
RequestForm.prototype.showPage = function()
{
	this._progressbar.className = "page" + this._currentPage;
	for ( var i = 0; i < this._form.length; i++ )
	{
		if ( i != this._currentPage )
			this.hide( this._form[ i ] );
		else
		{
			this.display( this._form[ i ] );
			this._heightfixor.fix( this._form[ i ] );
			this._loadPageTracker( i );
		}
	}
	
	if( this._currentPage == this._form.length - 2 )
	{
		this.hide( this._submitbutton );
		this.hide( this._backbutton );
		this.display( this._endbutton, 'inline' );
		this.hide( this._resetbutton, 'inline' );
		if( document.getElementById( 'fiveyearcheck' ) )
		{
			if( this._container.looptijdverz[0].checked )
				this.display( document.getElementById( 'fiveyearcheck' ), 'inline-block' );
			else
				this.hide( document.getElementById( 'fiveyearcheck' ) );
		}
		this.summarize();
	}
	else if( this._currentPage == this._form.length - 1 )
       {
		this.addTrackcode();
		this.addTradeDoubler();
		this.hide( this._submitbutton );
		this.hide( this._endbutton );
		this.hide( this._resetbutton );
		this.hide( this._backbutton );
		this.hide( document.getElementById( 'horizontalline' ) );
       }
       else if( this._currentPage == 0 )
       {
       this.display( this._submitbutton, 'inline' );
       this.hide( this._backbutton );
       this.hide( this._endbutton );
       this.hide( this._resetbutton );
       }
	else
	{
		this.display( this._submitbutton, 'inline' );
		this.display( this._backbutton, 'inline' );
		this.hide( this._endbutton );
		this.hide( this._resetbutton );
	}
	
	this.setButtonText();
	// update the sidebar
	if( oCalc != undefined )
		oCalc.update();
}
RequestForm.prototype.setButtonText = function()
{
	var sText = '';
	switch( this._currentPage )
	{
		case 0:
			sText = 'Kies uw zorgpakket';
			break;
		case 1:
			sText = 'Ga naar extra gegevens';
			break;
		case 2:
			sText = 'Ga naar betalingsmogelijkheden';
			break;
		case 3:
			sText = 'Vul uw gegevens in';
			break;
		case 4:
			sText = 'Controleer uw aanvraag';
			break;
		default:
			sText = 'verder';
			break;
	}
	
	this._submitbutton.value = sText;
}
RequestForm.prototype.nextpage = function()
{
	if( this._validation.validate( this._currentPage ) )
	{
		if( this._currentPage < this._form.length - 1 )
			++this._currentPage;
		
		// Special for Cremation Insurance
		this.setCremationStatus();
		this.setSterilisationStatus();
		this.setChemoStatus();
		this.setTravelStatus();
		
		this.storeData();
		
		this.showPage();
	}
	else
		this._heightfixor.fixit();
}
RequestForm.prototype.previouspage = function()
{
	if( this._currentPage > 0 )
		--this._currentPage;
	this.showPage();
}
RequestForm.prototype.resetform = function( mPage )
{
	if( typeof mPage == "number" && mPage >= 0 && mPage < 5 )
		this._currentPage = mPage;
	else
		this._currentPage = 0;
	this.showPage();
}
RequestForm.prototype.hide = function(mElement, bEmpty)
{
	if ( typeof mElement == "string" && document.getElementById )
		oElement = document.getElementById( mElement );
	else if ( typeof mElement == "object" )
		oElement = mElement;
	else
		return false;
		
	oElement.style.display = "none";
	
	if( typeof bEmpty == "undefined " )
		bEmpty = false;
	
	if( bEmpty )
		this.emptyElement( oElement );
	
	this._heightfixor.fixit();
}
RequestForm.prototype.disable = function(mElement, bEmpty)
{
	if ( typeof mElement == "string" && document.getElementById )
		oElement = document.getElementById( mElement );
	else if ( typeof mElement == "object" )
		oElement = mElement;
	else
		return false;
	
	var aList = Array( 'INPUT', 'TEXTAREA', 'SELECT' );
	
	for( var i = 0; i < aList.length; i++ )
	{
		aElements = oElement.getElementsByTagName( aList[ i ] );
		for( var j = 0; j < aElements.length; j++ )
		{
			aElements[ j ].disabled = true;
		}
	}	
	
	if( typeof bEmpty == "undefined " )
		bEmpty = false;
	
	if( bEmpty )
		this.emptyElement( oElement );
	
	this._heightfixor.fixit();
}
RequestForm.prototype.enable = function(mElement)
{
	if ( typeof mElement == "string" && document.getElementById )
		oElement = document.getElementById( mElement );
	else if ( typeof mElement == "object" )
		oElement = mElement;
	else
		return false;
	
	var aList = Array( 'INPUT', 'TEXTAREA', 'SELECT' );
	
	for( var i = 0; i < aList.length; i++ )
	{
		aElements = oElement.getElementsByTagName( aList[ i ] );
		for( var j = 0; j < aElements.length; j++ )
		{
			aElements[ j ].disabled = false;
		}
	}
	
	this._heightfixor.fixit();
}
RequestForm.prototype.display = function(mElement, sValue)
{
	if ( typeof mElement == "string" && document.getElementById )
		oElement = document.getElementById( mElement );
	else if ( typeof mElement == "object" )
		oElement = mElement;
	else
		return false;
		
	if( typeof sValue == "undefined" )
		sValue = "block";
	oElement.style.display = sValue;
	
	this._heightfixor.fixit();
}
RequestForm.prototype.emptyElement = function( oElement )
{
	aElements = oElement.getElementsByTagName( 'INPUT' );
	for( var i = 0; i < aElements.length; i++ )
	{
		if( aElements[ i ].checked )
			aElements[ i ].checked = false;
		else if( aElements[ i ].value != '' )
			aElements[ i ].value = '';
	}
	
	aElements = oElement.getElementsByTagName( 'TEXTAREA' );
	for( var i = 0; i < aElements.length; i++ )
	{
		if( aElements[ i ].value != '' )
			aElements[ i ].value = '';
	}
	
	aElements = oElement.getElementsByTagName( 'SELECT' );
	for( var i = 0; i < aElements.length; i++ )
	{
		if( aElements[ i ].selectedIndex >= 0 )
			aElements[ i ].selectedIndex = -1;
	}
}
RequestForm.prototype.summarize = function()
{
	var elements = this._container.getElementsByTagName( 'TD' );
	for( i = 0; i < elements.length; i++ )
	{
		if( elements[ i ].id && elements[ i ].id.indexOf( 'summary' ) >= 0 )
			this.fillSummary( elements[ i ] );
	}
	
	this._heightfixor.fixit();
}
RequestForm.prototype.fillSummary = function( oElement )
{
	switch( oElement.id )
	{
		case 'summarypolis':
			if( this._container.zorgpakket[ 0 ].checked )
				oElement.innerHTML = 'Basis Pakket';
			else if( this._container.zorgpakket[ 1 ].checked )
				oElement.innerHTML = 'Plus Pakket';
			else if( this._container.zorgpakket[ 2 ].checked )
				oElement.innerHTML = 'Totaal Pakket';
			break;
		case 'summarylooptijd':
			if( this._container.looptijdverz[ 0 ].checked )
				oElement.innerHTML = '5 jaar';
			else if( this._container.looptijdverz[ 1 ].checked )
				oElement.innerHTML = '1 jaar';
			break;
		case 'summaryextra':
			var i = 0;
			var aInfo = Array();
			if( this._container.stercas.checked )
				aInfo[ i++ ] = 'Sterilisatie en Castratie Verzekering';
			if( this._container.chemrad.checked )
				aInfo[ i++ ] = 'Chemo en Radiotherapie Verzekering';
			if( this._container.crem.checked )
				aInfo[ i++ ] = 'Crematie Verzekering';
			if( this._container.reisverz.checked )
				aInfo[ i++ ] = 'Doorlopende Reisverzekering Wereld';
			oElement.innerHTML = aInfo.join( ', ' );
			break;
		case 'summaryeigenbijdrage':
			if( this._container.eigenbijdrage[ 0 ].checked )
				oElement.innerHTML = '&euro; 35,-';
			else if( this._container.eigenbijdrage[ 1 ].checked )
				oElement.innerHTML = '&euro; 25,-';
			else if( this._container.eigenbijdrage[ 2 ].checked )
				oElement.innerHTML = '&euro; 15,-';
			break;
		
		case 'summarynaamdier':
			oElement.innerHTML = this._container.roepnaam.value;
			break;
		case 'summarygeboortedatumdier':
			oElement.innerHTML = this._container.geboortedatum.value;
			break;
		case 'summarydatumdierinbezit':
			oElement.innerHTML = this._container.inbezitsinds.value;
			break;
		case 'summarysoortdier':
			if( this._container.soorthuisdier[ 0 ].checked )
				oElement.innerHTML = 'Hond';
			else if( this._container.soorthuisdier[ 1 ].checked )
				oElement.innerHTML = 'Kat';
			else if( this._container.soorthuisdier[ 2 ].checked )
				oElement.innerHTML = 'Konijn';
			else if( this._container.soorthuisdier[ 3 ].checked )
				oElement.innerHTML = 'Papegaai';
			break;
		case 'summarygeslachtdier':
			if( this._container.geslacht[ 0 ].checked )
				oElement.innerHTML = 'M';
			else if( this._container.geslacht[ 1 ].checked )
				oElement.innerHTML = 'V';
			break;
		case 'summarygesteriliseerd':
			if( this._container.castratie[ 0 ].checked )
				oElement.innerHTML = 'Ja';
			else if( this._container.castratie[ 1 ].checked )
				oElement.innerHTML = 'Nee';
			break;
		case 'summarychip':
			this.display( oElement.parentNode, '' );
			if( this._container.identificatiechip[ 0 ].checked )
			{
				oElement.innerHTML =  'Ja';
				if( this._container.chipnummer.value != '' )
					oElement.innerHTML += ' (' + this._container.chipnummer.value + ')';
			}
			else
				this.hide( oElement.parentNode );
			break;
		case 'summarygewicht':
			this.display( oElement.parentNode, '' );
			if( this._container.volgroeidgewicht.value != '' )
				oElement.innerHTML = this._container.volgroeidgewicht.value;
			else
				this.hide( oElement.parentNode );
			break;
		case 'summaryras':
			oElement.innerHTML = this._container.ras.value;
			break;
		case 'summarykruising':
			this.display( oElement.parentNode, '' );
			if( this._container.kruisingmet.value != '' )
				oElement.innerHTML = this._container.kruisingmet.value;
			else
				this.hide( oElement.parentNode );
			break;
		case 'summaryvastevoetring':
			this.display( oElement.parentNode, '' );
			if( this._container.vastevoetring.value != '' )
				oElement.innerHTML = this._container.vastevoetring.value;
			else
				this.hide( oElement.parentNode );
			break;
		
		case 'summaryclientnaam':
			oElement.innerHTML = this._container.clientnaam.value;
			break;
		case 'summaryclientgeslacht':
			this.display( oElement.parentNode, '' );
			if( this._container.clientgeslacht[ 0 ].checked )
				oElement.innerHTML = 'Man';
			else if( this._container.clientgeslacht[ 1 ].checked )
				oElement.innerHTML = 'Vrouw';
			else
				this.hide( oElement.parentNode );
			break;
		case 'summaryclientadres':
			this.display( oElement.parentNode, '' );
			if( this._container.clientstraat.value != '' )
				oElement.innerHTML = this._container.clientstraat.value + ' ' + this._container.clienthuisnummer.value + ', ' + this._container.clientpostcode.value + ' ' + this._container.clientplaats.value;
			else
				this.hide( oElement.parentNode );
			break;
		case 'summaryclientgeboortedatum':
			this.display( oElement.parentNode, '' );
			if( this._container.clientgeboortedatum.value != '' )
				oElement.innerHTML = this._container.clientgeboortedatum.value;
			else
				this.hide( oElement.parentNode );
			break;
		case 'summaryclienttelefoon':
			this.display( oElement.parentNode, '' );
			if( this._container.clienttelefoon.value != '' )
				oElement.innerHTML = this._container.clienttelefoon.value;
			else
				this.hide( oElement.parentNode );
			break;
		case 'summaryclientemail':
			this.display( oElement.parentNode, '' );
			if( this._container.clientemail.value != '' )
				oElement.innerHTML = this._container.clientemail.value;
			else
				this.hide( oElement.parentNode );
			break;
		
		case 'summaryperiode':
			if( this._container.betalingswijze[ 0 ].checked )
				oElement.innerHTML = 'Jaarlijks via automatische incasso';
			else if( this._container.betalingswijze[ 1 ].checked )
				oElement.innerHTML = 'Jaarlijks via acceptgiro';
			else if( this._container.betalingswijze[ 2 ].checked )
				oElement.innerHTML = 'Maandelijks via automatische (verplichte) incasso';
			break;
		case 'summarybanknummer':
			oElement.innerHTML = this._container.banknummer.value + ' t.n.v. ' + this._container.naamrekening.value;
			break;
		case 'summaryontvangstpolis':
			if( this._container.ontvangstpolis[ 0 ].checked )
				oElement.innerHTML = 'Per post';
			else if( this._container.ontvangstpolis[ 1 ].checked )
				oElement.innerHTML = 'Via e-mail';
			break;
		
		default:
			return;
			break;
	}
}
RequestForm.prototype.storeData = function()
{
	var oVariable = new Object();
	var aInput    = this._container.getElementsByTagName( "input" );
	var aSelect   = this._container.getElementsByTagName( "select" );
	var aTextarea = this._container.getElementsByTagName( "textarea" );

	if ( aInput )
		for ( var i = 0;i < aInput.length; ++i )
			if ( aInput[ i ].name != "" )
				switch( aInput[ i ].type )
				{
					case "checkbox":
					case "radio":
						if ( aInput[ i ].checked )
							oVariable[ aInput[ i ].name ] = aInput[ i ].value || "on";
						break;
					case "submit":
					case "button":
					case "image":
						break;
					default:
						oVariable[ aInput[ i ].name ] = aInput[ i ].value;
						break;
				}

	if ( aSelect )
		for ( var i = 0;i < aSelect.length; ++i )
			if ( aSelect[ i ].name != "" )
				oVariable[ aSelect[ i ].name ] = aSelect[ i ][ aSelect[ i ].selectedIndex ].value;

	if ( aTextarea )
		for ( var i = 0;i < aTextarea.length; ++i )
			if ( aTextarea[ i ].name != "" )
				oVariable[ aTextarea[ i ].name ] = aTextarea[ i ].value;
	
	oVariable.emaildata = this._endSubmit;
	
	oVariable.command = 'storedata';
	oVariable._format = 'xml';
	
	var oXML = new klib3.xml();
	oXML.form = this._container;
	oXML.parent = this;
	if ( typeof this.onload == "function" )
	{
		oXML.onload = this.onload;
	}
	else
	{
		oXML.onload  = function()
		{
			var oStatus = new Status( this );
			if( !oStatus.success )
			{
				alert( oStatus.message );
			}
			if( oStatus.content && oStatus.content.userid && oStatus.content.userid != '' )
				this.form.userid.value = oStatus.content.userid;
		}
	}
	
	oXML.post( "interface.php", true, oVariable );
}
RequestForm.prototype.setSterilisationStatus = function()
	{
		if( oCalc && ( oCalc.getAge( this._container.geboortedatum.value ) > 9 || ( this._container.soorthuisdier[ 2 ].checked && oCalc.getAge( this._container.geboortedatum.value ) > 2 ) ) && !this._container.soorthuisdier[ 3 ].checked )
			this.disable( "stercasquestion" );
		else
			this.enable( "stercasquestion" );
	}
	RequestForm.prototype.setChemoStatus = function()
	{
		if( oCalc && (oCalc.getAge( this._container.geboortedatum.value ) > 3 || this._container.soorthuisdier[ 2 ].checked) && !this._container.soorthuisdier[ 3 ].checked )
			this.disable( "chemradquestion" );
		else
			this.enable( "chemradquestion" );
	}
	RequestForm.prototype.setCremationStatus = function()
	{
		if( oCalc && ( oCalc.getAge( this._container.geboortedatum.value ) > 6 || ( this._container.soorthuisdier[ 2 ].checked && oCalc.getAge( this._container.geboortedatum.value ) > 2 ) ) && !this._container.soorthuisdier[ 3 ].checked )
			this.disable( "cremquestion" );
		else
			this.enable( "cremquestion" );
	}
	RequestForm.prototype.setTravelStatus = function()
	{
		if( oCalc && ( oCalc.getAge( this._container.geboortedatum.value ) > 12 || ( this._container.soorthuisdier[ 0 ].checked && oCalc.getAge( this._container.geboortedatum.value ) > 9 ) ) && !this._container.soorthuisdier[ 3 ].checked )
			this.disable( "reisquestion" );
		else
			this.enable( "reisquestion" );
	}

RequestForm.prototype.changeRuntime = function(oCheck)
{
	if( oCheck.checked )
	{
		this._container.looptijdverz1.disabled='disabled';
		this._container.looptijdverz5.checked='checked';
	}
	else
	{
		this._container.looptijdverz1.disabled='';
		this._container.looptijdverz5.checked='';
	}
}
RequestForm.prototype._loadPageTracker = function( iPage )
    {
        var sPage = '';
        switch( iPage )
        {
            case 0:
                sPage = '1_gegevens_huisdier';
                break;
            case 1:
                sPage = '2_gegevens_zorgpakket';
                break;
            case 2:
                sPage = '3_extra_gegevens';
                break;
            case 3:
                sPage = '4_betalingsmogelijkheden';
                break;
            case 4:
                sPage = '5_uw_gegevens';
                break;
            case 5:
                sPage = '6_aanvraag_verzenden';
                break;
            case 6:
                sPage = '7_aanvraag_verzonden';
                break;
            default:
                sPage = 'unknown';
                break;
        }
        
        if( pageTracker )
            pageTracker._trackPageview( '/aanvraagformulier/' + sPage );
    }
    RequestForm.prototype.addTrackcode = function()
		{
			var oImg = document.createElement( "IMG" );
			oImg.style.border = "0";
			oImg.style.height = "1px";
			oImg.style.width = "1px";
			transactieId = this._container.userid.value;
			land = 'nl';
			postcode = this._container.clientpostcode.value;
			geslacht = 'o';
			if( this._container.clientgeslacht[ 0 ].checked )
				geslacht = 'm';
			else if( this._container.clientgeslacht[ 1 ].checked )
				geslacht = 'v';
			geboorteDatum = this._container.clientgeboortedatum.value;
			year = parseInt( geboorteDatum.substring( 6, 10 ), 10 );
			month = parseInt( geboorteDatum.substring( 3, 5 ), 10 );
			day = parseInt( geboorteDatum.substring( 0, 2 ), 10 );
			geboorteDatum = year + '-' + ( month < 10 ? '0' : '' ) + month + '-' + ( day < 10 ? '0' : '' ) + day;
			
			oImg.src = "http://ds1.nl/t/?si=982&ti=" + transactieId + "&oa=polisaanvraag&om=polisaanvraag&ai=11895&ln=" + land + "&pc=" + postcode + "&gs=" + geslacht + "&gb=" + geboorteDatum;

			this._container.appendChild( oImg );
		}
		RequestForm.prototype.addTradeDoubler = function()
	{
		var tduid = getCookie("TRADEDOUBLER");
		
		if( tduid )
		{
			var organization=1474642;
			var event=193121;
			var leadNumber = Math.round((new Date().getTime() * Math.random()));
			//Build reportInfo, f1 = product ID, f2 = product name, f3 = product price, f4 =quantity ordered.
			var reportInfo = "";
			//reportInfo = "f1="+ProductName+"&f2="+ProductID+"&f3="+NumberOfProduct+"&f4="+ProductPrice+"|f1="+ProductName+"&f2="+ProductID+"&f3="+NumberOfProduct+"&f4="+ProductPrice;
			//reportInfo = escape(reportInfo);
			
			var oImg = document.createElement( "IMG" );
			oImg.style.border = "0";
			oImg.style.height = "1px";
			oImg.style.width = "1px";
			
			oImg.src = "http://tbl.tradedoubler.com/report?organization="+organization+"&event="+event+"&leadNumber="+leadNumber+"&orderValue=1&tduid="+tduid+"&reportInfo="+reportInfo;
			
			this._container.appendChild( oImg );
		}
	}

