﻿	var currentField;

	function ToggleDiv(id)
	{
		var SDiv = document.getElementById("S" + id);
		var LDiv = document.getElementById("L" + id);
		var IObj = document.getElementById("I" + id);

		if (SDiv!=null && LDiv!=null)
		{	
			//Indien beide div's gevonden: zichtbaarheid beide div's omwisselen
			if (SDiv.style.display == 'none')
			{
				SDiv.style.display = 'block';
				LDiv.style.display = 'none';
				IObj.src = '_images/plus.gif';
				IObj.alt = 'uitklappen';
			}
			else
			{
				SDiv.style.display = 'none';
				LDiv.style.display = 'block';
				IObj.src = '_images/minus.gif';
				IObj.alt = 'inklappen';
			}
			
		}
		else
		{
			if (LDiv!=null)
			{	
				//Indien enkel LDiv gevonden: zichtbaarheid LDiv omwisselen
				if (LDiv.style.display == 'block')
				{
					LDiv.style.display = 'none';
					IObj.src = '_images/plus.gif';
					IObj.alt = 'uitklappen';
				}
				else
				{
					LDiv.style.display = 'block';
					IObj.src = '_images/minus.gif';
					IObj.alt = 'inklappen';
				}
			}
			if (SDiv!=null)
			{	
				//Indien enkel SDiv gevonden: zichtbaarheid LDiv omwisselen
				if (SDiv.style.display == 'block')
				{
					SDiv.style.display = 'none';
					IObj.src = '_images/plus.gif';
					IObj.alt = 'uitklappen';
				}
				else
				{
					SDiv.style.display = 'block';
					IObj.src = '_images/minus.gif';
					IObj.alt = 'inklappen';
				}
			}
		}
	}


	function ValidateProfile(veld)
	{
		var myForm = document.ProfileForm
		var ErrCount = 0

		if (veld == 'aanspreek' || veld == '')
		{
			if (myForm.aanspreek.selectedIndex == 0)
			{
				document.getElementById('I_aanspreek').style.visibility = 'visible';
				ErrCount++;
			}
			else
			{
				document.getElementById("I_aanspreek").style.visibility = 'hidden';
			}
		}
		if (veld == 'naam' || veld == '')
		{
			if (myForm.naam.value.length == 0)
			{
				document.getElementById("I_naam").style.visibility = 'visible';
				ErrCount++;
			}
			else
			{
				document.getElementById("I_naam").style.visibility = 'hidden';
			}
		}
		if (veld == 'voornaam' || veld == '')
		{
			if (myForm.voornaam.value.length == 0)
			{
				document.getElementById("I_voornaam").style.visibility = 'visible';
				ErrCount++;
			}
			else
			{
				document.getElementById("I_voornaam").style.visibility = 'hidden';
			}
		}
		if (veld == 'adres' || veld == '')
		{
//			if (myForm.adres1.value.length == 0 && myForm.adres2.value.length == 0)
//			{
//				document.getElementById("I_adres").style.visibility = 'visible';
//				ErrCount++;
//			}
//			else
//			{
				document.getElementById("I_adres").style.visibility = 'hidden';
//			}
		}
		if (veld == 'postcode' || veld == '')
		{
//			if (myForm.postcode.value.length == 0)
//			{
//				document.getElementById("I_postcode").style.visibility = 'visible';
//				ErrCount++;
//			}
//			else
//			{
				document.getElementById("I_postcode").style.visibility = 'hidden';
//			}
		}
		if (veld == 'woonplaats' || veld == '')
		{
//			if (myForm.woonplaats.value.length == 0)
//			{
//				document.getElementById("I_woonplaats").style.visibility = 'visible';
//				ErrCount++;
//			}
//			else
//			{
				document.getElementById("I_woonplaats").style.visibility = 'hidden';
//			}
		}
		if (veld == 'telefoon' || veld == '')
		{
//			if (myForm.telefoon1.value.length == 0 && myForm.telefoon2.value.length == 0)
//			{
//				document.getElementById("I_telefoon").style.visibility = 'visible';
//				ErrCount++;
//			}
//			else
//			{
				document.getElementById("I_telefoon").style.visibility = 'hidden';
//			}
		}
		if (veld == 'email' || veld == '')
		{
			if (myForm.email1.value.length == 0 && myForm.email2.value.length == 0 && myForm.email3.value.length == 0)
			{
				document.getElementById("I_email").alt = 'U moet een email adres opgeven';
				document.getElementById("I_email").style.visibility = 'visible';
				ErrCount++;
			}
			else
			{
				if ((myForm.email1.value.length > 0 && myForm.email1.value.indexOf('@') == -1) || 
				    (myForm.email2.value.length > 0 && myForm.email2.value.indexOf('@') == -1) || 
				    (myForm.email3.value.length > 0 && myForm.email3.value.indexOf('@') == -1) ||
				    (myForm.email1.value.indexOf(' ') > -1 || myForm.email2.value.indexOf(' ') > -1 || myForm.email3.value.indexOf(' ') > -1) || 
				    (myForm.email1.value.indexOf(';') > -1 || myForm.email2.value.indexOf(';') > -1 || myForm.email3.value.indexOf(';') > -1))
				{
					document.getElementById("I_email").alt = 'Een email adres is niet correct opgebouwd';
					document.getElementById("I_email").style.visibility = 'visible';
					ErrCount++;
				}
				else
				{
					if ((myForm.email1.value.length > 0 && (myForm.email1.value == myForm.email2.value || myForm.email1.value == myForm.email3.value)) ||
					    (myForm.email2.value.length > 0 && (myForm.email2.value == myForm.email1.value || myForm.email2.value == myForm.email3.value)) ||
					    (myForm.email3.value.length > 0 && (myForm.email3.value == myForm.email1.value || myForm.email3.value == myForm.email1.value)))
					{
						document.getElementById("I_email").alt = 'Gebruik een email adres maximaal 1 keer';
						document.getElementById("I_email").style.visibility = 'visible';
						ErrCount++;
					}
					else
					{
						document.getElementById("I_email").style.visibility = 'hidden';
					}
				}
			}
		}
		if (veld == 'paswoord' || veld == '')
		{
			if (myForm.paswoord1.value.length == 0)
			{
				document.getElementById("I_paswoord").alt = 'U moet een paswoord kiezen';
				document.getElementById("I_paswoord").style.visibility = 'visible';
				ErrCount++;
			}
			else
			{
				if (myForm.paswoord1.value.length < 6)
				{
					document.getElementById("I_paswoord").alt = 'Uw paswoord moet tussen 6 en 10 tekens lang zijn';
					document.getElementById("I_paswoord").style.visibility = 'visible';
					ErrCount++;
				}
				else
				{
					if (myForm.paswoord2.value != myForm.paswoord1.value)
					{
						document.getElementById("I_paswoord").alt = 'Controlepaswoord wijkt af van paswoord';
						document.getElementById("I_paswoord").style.visibility = 'visible';
						ErrCount++;
					}
					else
					{
						document.getElementById("I_paswoord").style.visibility = 'hidden';
					}
				}
			}
		}		
/*		if (veld == '')
		{
			var captcha = document.getElementByName("captcha");
			
			if (captcha != null)
			{
				if (captcha.value.length == 0)
				{
					alert('Vul de 8-cijferige code in om u te onderscheiden van een geautomatiseerd proces.');
					ErrCount++;
				}
			}
		}
*/
		return (ErrCount == 0);
	
	}

	function SubmitProfile()
	{
		if (ValidateProfile(''))
		{
			document.ProfileForm.submit();
		}
	}


	// function to allow adding text at current cursor position
	function insertAtCursor(myField, myValue) {

	    //IE support
	    if (document.selection) {
	        myField.focus();
	
	        //in effect we are creating a text range with zero
	        //length at the cursor location and replacing it
	        //with myValue
	        sel = document.selection.createRange();
	        sel.text = myValue;
	
	    //Mozilla/Firefox/Netscape 7+ support
	    } else if (myField.selectionStart || myField.selectionStart == '0') {
	
	        myField.focus();
	        //Here we get the start and end points of the
	        //selection. Then we create substrings up to the
	        //start of the selection and from the end point
	        //of the selection to the end of the field value.
	        //Then we concatenate the first substring, myValue,
	        //and the second substring to get the new value.
	        var startPos = myField.selectionStart;
	        var endPos = myField.selectionEnd;
	        myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos, myField.value.length);
	        myField.setSelectionRange(endPos+myValue.length, endPos+myValue.length);
	    } else {
	        myField.value += myValue;
	    }
	}

