var companyLinks = new Class(
{
	initialize:	function()
	{	
		this.setEvents();
	},
	
	setEvents: function()
	{
		$$('img.company_link').each(function(img)
		{
			img.addEvent('mouseenter', function()
			{
				this.fadein = img.effect('opacity',
				{
					duration: 100
				}).start(0.5,1)
			}.bind(this));
				img.addEvent('mouseleave', function()
			{
				this.fadeout = img.effect('opacity',
				{
					duration: 200
				}).start(1,0.5)				
			}.bind(this));			
		});	
	}
});
companyLinks.implement(new Options, new Events);

var imageLabels = new Class(
{
	initialize:	function()
	{	
		this.setEvents();
	},
	
	setEvents: function()
	{
		$$('img.button').each(function(img)
		{
			img.addEvent('mouseenter', function()
			{
				var currentButton = img.id.substring(7);
				this.fadein = $(currentButton).effect('opacity',
				{
					duration: 100
				}).start(0,1)
			}.bind(this));

			img.addEvent('mouseleave', function()
			{
				var currentButton = img.id.substring(7);
				this.fadeout = $(currentButton).effect('opacity',
				{
					duration: 100
				}).start(1,0)	
			}.bind(this));
		});		
	}
});
imageLabels.implement(new Options, new Events);

var processVraagbaak = new Class(
{
	valid: Boolean = true,
	html: "",
	
	initialize:	function()
	{
		if ($('vraagbaakButton'))
		{
			$('vraagbaakButton').addEvent('click', function()
			{
				this.validateForm();
				this.processForm();
			}.bind(this));
		}
	},
	
	validateForm: function()
	{
		var elements = $ES('input', 'form_div');
		elements.each(function(item)
		{
			if (item.value == "")
			{
				this.valid = false;
			}
		});

		if (($('email').getProperty('value').indexOf("@") == -1) || ($('email').getProperty('value').indexOf(".") == -1))
		{
			this.valid = false;
		}

		if ($('vraag').getProperty('value') == "")
		{
			this.valid = false;	
		}
	},
	
	processForm: function()
	{
		if (this.valid)
		{
			var request = new Ajax("http://www.jongejan-accountants.nl/jongejan/index.php?rt=ajax/vraagbaak",
			{
				method: 'get',
				onComplete: function(response)
				{
					if (eval(response.toString()))
					{
						this.html = $('vraagbaak_div').innerHTML;
						$('vraagbaak_div').empty();
						$('vraagbaak_div').setHTML('<br><b>Hartelijk dank voor uw reactie. We nemen zo spoedig mogelijk contact met u op via de mail om uw vraag te beantwoorden!</b>');
						this.resetForm.delay(10000, this);
					}
					else
					{
						alert("Het formulier kon niet verzonden worden. Probeert u het later nog eens!");
					}
				}.bind(this)
			}).request("n=" + $('naam').getProperty('value') + "&w=" + $('woonplaats').getProperty('value') + "&b=" + $('bedrijf').getProperty('value') + "&e=" + $('email').getProperty('value') + "&v=" + $('vraag').getProperty('value'));
		}
		else
		{
			alert("U hebt niet alle velden ingevuld of geen geldig e-mailadres opgegeven!");
			this.valid = true;
		}
	},
	
	resetForm: function()
	{
		$('vraagbaak_div').empty();
		$('vraagbaak_div').innerHTML = this.html;
		var elements = $ES('input', 'vraagbaak_div');
		elements.each(function(element)
		{
			element.value = "";
		});
		$('vraagbaakButton').value = "Versturen";
	}
});
processVraagbaak.implement(new Options, new Events);


var workshops = new Class(
{
	valid: Boolean = true,
	
	initialize:	function()
	{	
		this.setEvents();	
	},
	
	setEvents: function()
	{
		var radios = $ES('input[type=radio]', 'workshop_div');
		radios.each(function(radio)
		{
			radio.addEvent('click', function()
			{
				$('workshop_type').setProperty('value', radio.getProperty('value'));
			}.bind(this));
		});
		
		if ($('aanmelden_workshop'))
		{
			$('aanmelden_workshop').addEvent('click', function()
			{
				this.validate();
			}.bind(this));
		}
	},
	
	validate: function()
	{
		this.valid = true;
		var elements = $ES('input[type=text]', 'workshop_div');
		elements.each(function(element)
		{
			if (element.getProperty('value') == "")
			{
				this.valid = false;
			}
		}.bind(this));
		
		if (($('emailadres').getProperty('value').indexOf("@") == -1) || ($('emailadres').getProperty('value').toString().indexOf(".") == -1))
		{
			this.valid = false;
		}
		
		if ($('workshop_type').getProperty('value') == "")
		{
			this.valid = false;	
		}
		
		this.processForm();
	},
	
	processForm: function()
	{
		if (this.valid)
		{
			var request = new Ajax("http://www.jongejan-accountants.nl/jongejan/index.php?rt=ajax/workshops",
			{
				method: 'get',
				onComplete: function(response)
				{
					if (eval(response.toString()))
					{
						$('workshop_div').empty();
						$('workshop_div').setHTML('<br><b>Hartelijk dank voor uw opgave. We hopen u te mogen begroeten tijdens de workshop!</b>');
					}
					else
					{
						alert("Het formulier kon niet verzonden worden. Probeert u het later nog eens!");
					}
				}
			}).request("ws=" + $('workshopChoice').getProperty('value') + "&wt=" + $('workshop_type').getProperty('value') + "&p=" + $('aantal').getProperty('value') + "&n=" + $('naam').getProperty('value') + "&a=" + $('adres').getProperty('value') + "&w=" + $('woonplaats').getProperty('value') + "&b=" + $('bedrijf').getProperty('value') + "&t=" + $('telefoon').getProperty('value') + "&e=" + $('emailadres').getProperty('value'));
		}
		else
		{
			alert("U hebt niet alle velden ingevuld of geen geldig e-mailadres opgegeven!");
			this.valid = true;
		}		
	}
});
workshops.implement(new Options, new Events);
