// JavaScript Document

var contactAccordion;
var contactScroll;

window.addEvent('load', function () {

	contactAccordion = new Accordion('#contact', '#contactformulier', {
									 opacity: false, 
									 alwaysHide:true, 
									 start: 'all-closed',
									 onComplete: function() {contactScroll.toElement('contactformulier');}
									 });

	$('contactformulier').setStyle('display', 'block');
});

function toonContact() {
	$('contact').fireEvent('click');
}

window.addEvent('domready', function(){
									 
	$('contactform').addEvent('submit', function(e) {
		new Event(e).stop();												 
		if (validate()) {												 
			contactAccordion.display(1);
			
			this.set('send', {
					 url: 'contact.php', 
					 method: 'post', 
					 update: $('contactbevestiging'),
					 onComplete: function(response) {
					 	$('contactbevestiging').set('html', response);
				 	 	contactAccordion.display(1);
						
					 	}
					 });
			
			this.send();
			}
	});
	
	$('opmerkingen').addEvent('focus', function(e) {
		e = new Event(e).stop();
		if ($('opmerkingen').value.substr(0,8) == 'Typ hier') $('opmerkingen').value = '';
		});

	contactScroll = new Fx.Scroll(window, {duration: 800});
});

function checkVerplicht() {
	var form = $('contactform');

	if (form.actie[0].checked) {
		$('xnaam').style.visibility='visible';
		$('xvoorletter').style.visibility='visible';
		$('xstraat').style.visibility='visible';
		$('xhuisnummer').style.visibility='visible';
		$('xpostcode').style.visibility='visible';
		$('xwoonplaats').style.visibility='visible';
		$('xtelefoon').style.visibility='visible';
		$('xemail').style.visibility='visible';
		$('xverplicht').style.visibility='visible';
		}
	else {
		$('xnaam').style.visibility='visible';
		$('xvoorletter').style.visibility='hidden';
		$('xstraat').style.visibility='hidden';
		$('xhuisnummer').style.visibility='hidden';
		$('xpostcode').style.visibility='hidden';
		$('xwoonplaats').style.visibility='hidden';
		$('xtelefoon').style.visibility='visible';
		$('xemail').style.visibility='visible';
		$('xverplicht').style.visibility='visible';
		}
}

function noenter() {
	return !(window.event && window.event.keyCode == 13); 
	}

function validate() 
	{
	var ok = false;
	var bestemming = false;
	var form = $('contactform');
	if (form.actie[0].checked) {
		bestemming = true;
		if ((form.naam.value!='')&&(form.voorletter.value!='')&&(form.straat.value!='')&&(form.huisnummer.value!='')&&(form.postcode.value!='')&&(form.woonplaats.value!='')&&(form.telefoon1.value!='')&&(form.email.value!='')) ok = true;
		}
	if (form.actie[1].checked) {
		bestemming = true;
		if ((form.naam.value!='')&&(form.telefoon1.value!='')&&(form.email.value!='')) ok = true;
		}
	if (!ok)
		{
		if (bestemming) alert('Vul alle verplichte gegevens in.'); 
		else alert ('Geef de bestemming van uw bericht aan.');
        return false;
    	}
    else
        return true;
	}
	


