
	function Form (sId) {
		
		this.id = sId || '';
		this.formField = [];
		
		OnLoadObject (this);
		
	}
	
	
	Form.prototype.init = function () {
		
		this.form = document.getElementById (this.id);
		this.message = new Melding ();
		
	}
	
	
	Form.prototype.checkAndSubmit = function () {
		
		this.preSubmit ();
		
		var sSubmitData = '';
		
		for (var i = 0; i < this.form.length; i++) {
			
			sSubmitData += this.form[i].name + ' = ' + this.form[i].value + '\n';
			
		}
		
		if (oPage.debug)
			alert (sSubmitData);
		
		if (this.valuesCheck ())
			return true;
		
		return false;
		
	}
	
	Form.prototype.getClassFromId = function(sId) {

		for (var i = 0; i<this.formField.length; i++) {
		
			if (sId == this.formField[i].getId()) {
				return this.formField[i];
			} 
		
		}
		
	}
	
	Form.prototype.onChangeFunctie = function (sBoolean) {
		var oRechtsgebiedTable = document.getElementById('rechtsgebiedtable');
		var oRechtsgebied = document.getElementById('rechtsgebied');
		
		if (sBoolean == 'true') {
			oRechtsgebiedTable.style.display = 'block';
			oRechtsgebied.style.display = 'block';
		} else if (sBoolean == 'false') {
			oRechtsgebiedTable.style.display = 'none';
			oRechtsgebied.style.display = 'none';
		}
	}
	
	
	Form.prototype.preSubmit = function () {
		
	}
	
	
	Form.prototype.addFormField = function (oFormField) {
		
		oFormField.init (this.id);
		
		this.formField.push (oFormField);
		
	}
	
	
	Form.prototype.showMessage = function (sMessage) {
		
		this.message.openDialog (sMessage);
		
	}
	
	
	Form.prototype.valuesCheck = function () {
		
		for (var i = 0; i < this.formField.length; i++) {
			
			if (!this.formField[i].isValid ()) {
				
//				this.formField[i].focus ();
//				this.showMessage (this.formField[i].errorMessage[0]);
				return false;
				
			}
			
		}
		
		this.form.submit ();
		
	}
	
	Form.prototype.addFileField = function (divId) {
		
		var oDiv = document.getElementById(divId);
		var oDivAttach = document.createElement('div');
		var nodesBefore = oDiv.childNodes.length;
		var nodesAfter = oDiv.childNodes.length + 1;
		//alert(oDiv.lastChild.firstChild.nodeName);
		if (oDiv.lastChild.firstChild.value != '') {
			oDivAttach.setAttribute('id', 'attach'+String(nodesAfter)+'Div');
			var self = this;
			oDivAttach.innerHTML = '<input class="inputText2" style="display: inline;" type="file" name="attach'+nodesAfter+'" id="'+nodesAfter+'"/><p class="pRemove" style="cursor: pointer; display: inline;"><a onclick="'+this.id+'.removeFileField(\''+divId+'\');">Verwijderen</a></p>';
		oDiv.appendChild(oDivAttach);
		} else
		{ 
			this.message.openDialog('Er is nog geen bestandsnaam ingevuld.'); 
		}
	}
	
	Form.prototype.removeFileField = function (divId) {
		
		var oDiv = document.getElementById(divId);
		
		//if (oDiv.lastChild.firstChild.value == '') {
			
			oDiv.removeChild(oDiv.lastChild);
		
		//} else
		//{ alert('er staat wat ingevuld.'); }
		//alert(oDiv.childNodes.length);
	}
	
	
	function FormField () 
	{
		
	}
	
	FormField.prototype.init = function (sFormId) 
	{
		this.inputElemForm = document.getElementById (sFormId)[this.id] || document.getElementById (sFormId)[this.id + '1'];
		this.inputElem = document.getElementById (this.id) || document.getElementById (this.id + '1');
		this.message = new Melding ();		
	}
	
	
	FormField.prototype.focus = function () 
	{	
		this.inputElem.focus ();
		this.inputElem.select ();
		
	}
	
	FormField.prototype.getId = function () 
	{
		return this.id;
	}
	
	FormField.prototype.isValid = function () 
	{
		if (this.compulsory && this.isEmpty () && !this.isHidden()) {
			
			this.focus ();
			this.message.openDialog (this.errorMessage[0]);
			return false;
			
		}
			
		return true;
		
	}

	FormField.prototype.isHidden = function () 
	{
		
		if (this.inputElemForm.nodeName == 'INPUT')
			return this.inputElemForm.style.display == 'none';
		else
			return false;

	}

	FormField.prototype.isEmpty = function () {
		
		var sValueTrimmed = this.inputElemForm.value.replace(/^\s*|\s*$/g, '');
		
		if (sValueTrimmed.length == 0)
			return true;
		else
			return false;
		
	}
	
	
	FormFieldText.prototype = new FormField;
	FormFieldSelect.prototype = new FormField;
	FormFieldChoice.prototype = new FormField;
	
	function FormFieldText (sId, sName, sType, errorMessage, bCompulsory) {
		
		this.id = sId;
		this.name = sName || '';
		this.errorMessage = errorMessage || [];
		this.type = sType;
		this.compulsory = bCompulsory || false;
		
	}
	
	function FormFieldSelect (sId, sName, sType, errorMessage, bCompulsory, iLength) {
		
		this.id = sId;
		this.name = sName || '';
		this.errorMessage = errorMessage || [];
		this.type = sType;
		this.compulsory = bCompulsory || false;
		this.length = iLength || 0;
		//this.inputElemForm = document.getElementById(this.id + '1') || null;
		//alert(this.inputElemForm.tagName);
		
	}
	
	function FormFieldChoice (sId, sName, value, errorMessage, bCompulsory) {
		
		this.id = sId;
		this.name = sName;
		this.value = value;
		this.errorMessage = errorMessage;
		this.compulsory = bCompulsory || false;
		
	}
	
	FormFieldChoice.prototype.focus = function () {
		
		if (browser == 'Internet Explorer') {
			this.inputElem.focus();
			//this.inputElem.select(); 'Veroorzaakt error in alle browsers
		}
		
	}
		
	FormFieldChoice.prototype.isEmpty = function () 
	{	
		var bChecked = false;
		
		for (var i = 0; i < this.inputElemForm.length; i++) 
		{	
			if (this.inputElemForm[i].checked)
			{
				bChecked = true;
			}
		}
		
		return !bChecked;
	}
	
	FormFieldSelect.prototype.isEmpty = function () 
	{	
		var bChecked = false;
	
		for (var i = 0; i < this.length; i++) 
		{
			if (document.getElementById(''+this.id+(i+1)).checked)
			{
				bChecked = true;
			}
		}
		return !bChecked;
		
	}

	// ========================================================================================
	// Extra classes for 'sollicitatieformulier'
	// ========================================================================================
	
	FormFieldFunction.prototype = new FormFieldChoice;
	
	function FormFieldFunction (sId, sName, value, errorMessage, bCompulsory) {
		
		this.id = sId;
		this.name = sName;
		this.value = value;
		this.errorMessage = errorMessage;
		this.compulsory = bCompulsory || false;
		
	}

	FormFieldFunction.prototype.isValid = function () {
		var inputElemFunction = document.getElementById ('functievan');
		
		if (this.compulsory) {
			
			if (this.isEmpty ()) {
				
				this.focus ();
				this.message.openDialog (this.errorMessage[0]);
				return false;
				
			}
			
			if (this.inputElemForm[5].checked && inputElemFunction.value.length == 0) {
				
				inputElemFunction.focus ();
				this.message.openDialog (this.errorMessage[1]);
				return false;
				
			}
			
		}
			
		return true;
		
	}

	function FormFieldFound (sId, sName, value, errorMessage, bCompulsory) {
		
		this.id = sId;
		this.name = sName;
		this.value = value;
		this.errorMessage = errorMessage;
		this.compulsory = bCompulsory || false;
		
	}

	FormFieldFound.prototype = new FormFieldChoice;
	
	FormFieldFound.prototype.isValid = function () {
		
		//inputElementFunction[0] = document.getElementById (this.id + 'text');
		
		if (this.compulsory) {
			
			if (this.isEmpty ()) {
				
				this.focus ();
				this.message.openDialog (this.errorMessage[0]);
				return false;
				
			}
			
			if (this.inputElemForm[0].checked && document.getElementById (this.id + '1' + 'text').value.length == 0) {
				
				document.getElementById (this.id + '1' + 'text').focus ();
				this.message.openDialog (this.errorMessage[0]);
				return false;
				
			}
			
			if (this.inputElemForm[1].checked && document.getElementById (this.id + '2' + 'text').value.length == 0) {
				
				document.getElementById (this.id + '2' + 'text').focus ();
				this.message.openDialog (this.errorMessage[0]);
				return false;
				
			}
			
			if (this.id != 'gevonden_masterclass')
			{
				if (this.inputElemForm[2].checked && document.getElementById (this.id + '3' + 'text').value.length == 0) 
				{
					document.getElementById (this.id + '3' + 'text').focus ();
					this.message.openDialog (this.errorMessage[0]);
					return false;					
				}
			}
			
			if (this.id != 'gevonden_masterclass')
			{
				if (this.inputElemForm[4].checked && document.getElementById (this.id + '5' + 'text').value.length == 0) 
				{
					document.getElementById (this.id + '5' + 'text').focus ();
					this.message.openDialog (this.errorMessage[0]);
					return false;
					
				}
			}
		}
			
		return true;
		
	}

