	function personchange(){
		for (i=1; i <= document.getElementById('persons').value; i++) {
			document.getElementById('person'+i).appear();
		};
		
		if (document.getElementById('persons').value < 10){
			// hide others
			for (j = Number(document.getElementById('persons').value); j<=10; j++) {
				var elementId = 'person'+String(j);
				document.getElementById(elementId).hide();
			};
		}
		
		personsField =document.getElementById('persons');
		companyTypeField =document.getElementById('company_type');

		if ((personsField.value > 4 && companyTypeField.value == 'retail') || companyTypeField.value=='leverancier'){
			document.getElementById('invoice').show();
        }else{
        	document.getElementById('invoice').hide();
        }
        
	}
	
	function validate_tre_form(){
		var valid = true;
		var errorMessage = '';

	    if ( document.treForm.name.value == "" )
	    { valid = false; errorMessage += ' - Bedrijfsnaam is niet ingevuld \n';}
	    
	    if ( document.treForm.kvk.value == "" )
	    { valid = false; errorMessage += ' - KVK nummer is niet ingevuld \n';}
	    
	    if ( document.treForm.street.value == "" )
	    { valid = false; errorMessage += ' - Straat is niet ingevuld \n';}
	    
	    if ( document.treForm.housenumber.value == "" )
	    { valid = false; errorMessage += ' - Huisnummer is niet ingevuld \n';}
	    
	    if ( document.treForm.postalcode.value == "" )
	    { valid = false; errorMessage += ' - Postcode is niet ingevuld \n';}
	    
	    if ( document.treForm.city.value == "" )
	    { valid = false; errorMessage += ' - Plaats is niet ingevuld \n';}
	    
	    if ( document.treForm.initials.value == "" )
	    { valid = false; errorMessage += ' - Contactpersoon voorletters zijn niet ingevuld \n';}
	    
	    if ( document.treForm.lastname.value == "" )
	    { valid = false; errorMessage += ' - Contactpersoon achternaam is niet ingevuld \n';}
 	    
	    if ( document.treForm.telephone.value == "" )
	    { valid = false; errorMessage += ' - Contactpersoon telefonnummer is niet ingevuld \n';}
	    
	    if ( document.treForm.email.value == "" )
	    { valid = false; errorMessage += ' - Contactpersoon email is niet ingevuld \n';}

		var persons = document.treForm.persons.value;
		var arrInitials = document.getElementsByName("personinitials[]");
		var arrName = document.getElementsByName("personname[]");
		var arrEmail = document.getElementsByName("personemail[]");
		var arr_length = arrInitials.length;
		
		
		for(var i=0; i < arr_length; i++)
		{
			if (i<persons){
				if ( arrInitials[i].value == "" )
	    		{ valid = false; errorMessage += ' - Bezoeker '+(i+1)+' voorletters zijn niet ingevuld \n';}
	    		if (arrName[i].value == "" )
	    	    { valid = false; errorMessage += ' - Bezoeker '+(i+1)+' achternaam is niet ingevuld \n';}
	    	    if ( arrEmail[i].value == "" )
	    	    { valid = false; errorMessage += ' - Bezoeker '+(i+1)+' email is niet ingevuld \n';}
			}	
		}
		
		 
	    
	    
	    if(!valid){
	    	if (errorMessage.length > 250){
		    	alert ( "U heeft meerdere velden niet goed ingevuld, controleert u uw invoer alstublieft." );
		    }else{
	   			alert ( "Een aantal velden zijn niet of niet goed ingevuld: \n " + errorMessage );
	  		}
	    }
	
	    return valid;
	}
			
	Event.observe(window, 'load', function(){
		if($('persons')) {
			// run on load and change
			personchange();
			obj = $('persons');
			Event.observe(obj,'change',function(){
				for (i=1; i <= obj.value; i++) {
					document.getElementById('person'+String(i)).appear();
				};
				
				if (obj.value < 10){
					// hide others
					for (j = Number(obj.value); j<=10; j++) {
						document.getElementById('person'+String(j)).hide();
					};
				}
				
				personsField =document.getElementById('persons');
				companyTypeField =document.getElementById('company_type');
		
				if ((personsField.value > 4 && companyTypeField.value == 'retail') || companyTypeField.value=='leverancier'){
					document.getElementById('invoice').show();
		        }else{
		        	document.getElementById('invoice').hide();
		        }
		        
			});
			
			obj2 = document.getElementById("other_invoice");
			Event.observe(obj2,'change',function(){
				if (obj2.value == 'Ja'){
					document.getElementById('invoice2').show();
		        }else{
		        	document.getElementById('invoice2').hide();
		        }
			});
			
		}
		
		// search initial
		if($$('#searchfield input[type=text]')){
			$$('#searchfield input[type=text]')[0].initial('zoekopdracht');
		}
		
		
		
		// forms
		$$('form.cmxform label').each(function(label){
			var span = document.createElement('span');
			Element.extend(span);
			label.setStyle({
				display: '-moz-inline-box'
			});
			span.setStyle({
				display: 'block',
				width: '220px'
			});
			span.innerHTML = label.innerHTML;
			label.innerHTML = '';
			label.appendChild(span);
		});	
	
		if ($('clickbutton')) {
			$('clickbutton').observe('click', function(){
				$('overview-start').fade({
					afterFinish: function(){
						$('overview-next').appear();
					}
				});
			})
		}
		

		if ($$('.image-side')[0]) {
			new Ajax.PeriodicalUpdater($$('.image-side')[0], '/json.php', {
				frequency: 20,
				parameters: {
					action: 'get_banner',
					page_id: site.page.id
				}
			});
		}
	});
	
	Element.addMethods({
		initial: function(element,value){
			if(element.value == '')
				element.addClassName('initial');
			element.observe('focus',function(){
				if(element.value == value){
					element.removeClassName('initial');
					element.value = '';
				}
			});
			element.observe('blur',function(){
				if(element.value == ''){
					element.addClassName('initial');
					element.value = value;
				}
			});			
			element.value = value;
			
			return element;
		}
	});
	
	function d(m){console.log(m)}
	
	
	
	

