function noSpam(user,domain) {
  locationstring = "mailto:" + user + "@" + domain;
  window.location = locationstring;
}

var validateForm = {
  init: function(whichForm)
  {
    form = whichForm;
    fields = $(form).getElements('input'); //get all input's and put in 'fields' array
    fields.extend($(form).getElements('textarea')); //get all textarea's and add to 'fields' array

    if (!$('required'))
    {
      return true;
    }
    reqFields = $('required').value.split(','); //moet eigenlijk nog (alleen) binnen het form kijken naar deze id

    errorheaderId = 'errorheader';
    errorMsgClass = 'errormsg';
    errorImg = '../images/arrowPointer.gif';
    errorImgAlt = 'Error';

    if ($('validateLanguage').value == 'nl')
    {
      //errorheaderMsg = '&mdash;Corrigeer a.u.b. de gemarkeerde velden, bedankt.';
      errorheaderMsg = '';
      errorMsgRequired = 'Dit veld is verplicht.';
      errorMsgEmail = 'Dit e-mailadres is onjuist.'
      errorImgTitle = 'Dit veld bevat een fout';
    } else
    {
      //errorheaderMsg = '&mdash;Please correct the marked fields. Thank you.';
      errorheaderMsg = '';
      errorMsgRequired = 'This field is required.';
      errorMsgEmail = 'This e-mail address is not correct.'
      errorImgTitle = 'This field has an error';
    }

    allFieldsValidate = false;
    validateForm.addValidation();
  },

  addValidation: function()
  {
    fields.each(function(elm)
    {
      elm.addEvent('blur', function()
      {
        if (this.hasClass('validate-blur'))
        {
          validateForm.field(this);
        }
      });
    });
  },

  allFields: function()
  {
    //clean up possible earlier checks
    if ($(errorheaderId))
    {
      $(errorheaderId).remove();
    }
    //start check
    allFieldsValidate = true;
    fields.each(function(elm)
    {
      if (elm.id != 'required')
      {
        validateForm.field(elm);
      }
    });
    allFieldsValidate = false;
    if (!$(errorheaderId))
    {
      return true;
    } else
    {
      //fix height div
			if ($('changingheightformcontainer'))
			{
      	divCorrectToNewHeight('changingheightformcontainer'); //divName should be selected dynamically (geeft nu errors bij andere forms met container divs etc.)
			}
			return false;
    }
  },

  field: function(elm)
  {
    validateForm.clearError(elm);
    if (elm.getTag() == 'textarea')
    {
      if (elm.value == '' && reqFields.contains(elm.id))
      {
        validateForm.addError(elm,'required');
      }
    } else
    {
      switch (elm.type.toLowerCase())
      {
        case 'text':
        case 'password':
        case 'textarea':
          if (elm.value == '' && reqFields.contains(elm.id) && !elm.id.contains('imeel'))
          {
            validateForm.addError(elm,'required');
          } else if (elm.id.contains('imeel') && !validateForm.isEmailAddress(elm.value))
          {
            validateForm.addError(elm,'emailaddress');
          }
          break;
        case 'checkbox':
          if (!elm.checked && reqFields.contains(elm.id))
          {
            validateForm.addError(elm);
          }
          break;
        case 'select-one':
          if (!elm.selectedIndex && elm.selectedIndex == 0)
          {
            validateForm.addError(elm);
          }
          break;
      }
    }
  },

  addError: function(elm,type)
  {
    if ((allFieldsValidate) && (!$(errorheaderId)))
    {
      //create error message and insert before submit button
      var header = new Element('div');
      $(header).setProperty('id', errorheaderId);
      $(header).setHTML(errorheaderMsg);
      if ($E('legend'))
      {
        $(header).injectAfter($E('legend'));
      } else
      {
        //there is no legend, use first block element
        $(header).addClass('alt');
        $(header).injectBefore($$('.block')[0]);
      }
    }

    //create error image
    var errorIndicatorImg = new Element('img');
    $(errorIndicatorImg).setProperties({
      src: errorImg,
      alt: errorImgAlt,
      title: errorImgTitle
    });
    $(errorIndicatorImg).addClass('left');

    //error container + text and image
    var errorIndicator = new Element('div');
    $(errorIndicator).addClass(errorMsgClass);
    $(errorIndicatorImg).injectInside(errorIndicator);
    if (type == 'emailaddress')
    {
      $(errorIndicator).appendText(errorMsgEmail);
    } else if (type == 'required')
    {
      $(errorIndicator).appendText(errorMsgRequired);
    }
    $(errorIndicator).injectAfter(elm);
  },

  clearError: function(elm)
  {
    if (elm.getNext() && elm.getNext().hasClass(errorMsgClass))
    {
      elm.getNext().remove();
    }
  },

  isEmailAddress: function(str)
  {
		return true;
		//Check disabled, seems to cause errors sometimes?
    //return str.match(/^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/);
  }
};

var numCheck = function()
{
  if ($('aantal').value < 13)
  {
    if ($('aantal').value == 0)
    {
      $('aantal').value = 1;
    } else
    {
      return true;
    }
  } else
  {
    $('aantal').value = 12;
  }
}

Element.extend({
 
	resetValue: function(){
		switch(this.getTag()){
			case 'select':
				$each(this.options, function(option){ option.selected = option.defaultSelected });
				break;
			case 'input':
				if (['checkbox','radio'].contains(this.type) || ['hidden','submit','button'].contains(this.type)) {
					if (['checkbox','radio'].contains(this.type)) this.checked = this.defaultChecked;
					break;
				}
			case 'textarea': this.value = this.defaultValue;
		}
	},
 
	resetFormElements: function(){
		this.getFormElements().each(function(el){ el.resetValue() });
	}
 
});

var contactForm = {
  init: function(id)
  {
		currentForm = 'contactform';
    $(currentForm).addEvent('submit', function(e) {
    	new Event(e).stop();
      contactForm.send();
    });
		contactForm.addValidation();
  },

  send: function()
  {
    if (!validateForm.allFields())
    {
      return;
    }

    var response = $('response').empty().addClass('ajaxloading');

    new Ajax('functions/formmail.handler.php',
		{
      postBody: $(currentForm).toQueryString(),
      method: 'post',
      update: response,
      onComplete: contactForm.reset
    }).request();
  },

  reset: function()
  {
    $(currentForm).resetFormElements();
  },

  addValidation: function()
  {
    validateForm.init(currentForm);
  }
};

var spanjeSubscribeForm = {
  init: function()
  {
		currentForm = 'spanjesubscribeform';
    $(currentForm).addEvent('submit', function(e) {
    	new Event(e).stop();
      spanjeSubscribeForm.send();
    });
		spanjeSubscribeForm.addValidation();
  },

  send: function()
  {
    if (!validateForm.allFields())
    {
			window.location.href = '#formresponse';
			alert('Corrigeer aub de fouten in het formulier');
      return;
    }

    var response = $('response').empty().addClass('ajaxloading');

    new Ajax('functions/formmail.handler.php',
		{
      postBody: $(currentForm).toQueryString(),
      method: 'post',
      update: response,
      onComplete: spanjeSubscribeForm.reset
    }).request();
  },

  reset: function()
  {
		window.location.href = '#formresponse';
    $(currentForm).resetFormElements();
  },

  addValidation: function()
  {
    validateForm.init(currentForm);
  }
};




var subscribeForm = {
	init: function() {
		currentForm = 'forminschrijven-stap1';
		$(currentForm).addEvent('submit', function(e) {
			new Event(e).stop();
			subscribeForm.send();
		});
		$('aantal').addEvent('blur', numCheck);
		subscribeForm.addValidation();
	},

	send: function() {
		if(!validateForm.allFields()) return;  
		
		if(currentForm == 'forminschrijven-stap1') {
			var cookieQueryString = $(currentForm).toQueryString();
			var cookieQueryString2 = cookieQueryString.replace(/&/g, '|');
			Cookie.set(currentForm, cookieQueryString2);
			
			if($('aantal').value > 0) currentForm = 'forminschrijven-stap2';
				else currentForm = 'forminschrijven-finish';

			var response = $('inschrijfform').empty().addClass('ajaxloading');

			new Ajax('functions/formmail.multipage.handler.php', {
				postBody: cookieQueryString,
				method: 'post',
				update: response,
				onComplete: subscribeForm.finish
			}).request();
		} else {
			value = Cookie.get('forminschrijven-stap1')+'&'+$(currentForm).toQueryString();
			var intIndexOfMatch = value.indexOf('|');

			while (intIndexOfMatch != -1) {
				value = value.replace('|', '&');
				intIndexOfMatch = value.indexOf('|');
			}

			var response = $('inschrijfform').empty();

			new Fx.Scroll(window, {duration: 50}).scrollTo(0,(response.getTop() - 185));

			response.addClass('ajaxloading');

			new Ajax('functions/formmail.multipage.handler.php', {
				postBody: value,
				method: 'post',
				update: response
			}).request();
		}
	},

	finish: function() {
		$(currentForm).addEvent('submit', function(e) {
			new Event(e).stop();
			subscribeForm.send();
		});
		validateForm.init($(currentForm));
	},

	reset: function() {
		$(currentForm).resetFormElements();
	},

	addValidation: function() {
		validateForm.init(currentForm);
	}
}



var sendGuestbook = function()
{
  value = $('guestbookform').toQueryString();

			
  new Ajax('data/gastenboekcheck.php', {
            postBody: value,
            method: 'post',
            update: $('gastenboekform')
            }).request();		
}