function ajax_form(form,site_url,link_id){
	var req = jQuery.post
	( 
		site_url, 
		jQuery('#' + form).serialize(), 
		function(html){
			
			var explode = html.split("\n");
			var shown = false;
			var msg = '<div class="error">Corrigeer onderstaande fouten en probeer het opnieuw</div>';
			for ( var i in explode)
			{
				if (i < 1000) {
					var explode_again_buffer = explode[i];
					var explode_again = explode_again_buffer.split("|");
					if (explode_again[0]=='error')
					{
						if ( ! shown ) {
							jQuery('#' + link_id).show();
						}
						shown = true;
						//add_remove_class('ok','error',explode_again[1]);
						jQuery('#err_' + explode_again[1]).html(explode_again[2]);
						jQuery('#err_' + explode_again[1]).show();
						//msg += "<li>" + explode_again[2] + "</li>";
					}
					else if (explode_again[0]=='ok') {
						//add_remove_class('error','ok',explode_again[1]);
						jQuery('#err_' + explode_again[1]).hide();
					}
			   }
			}
			if ( ! shown )
			{
				jQuery('#' + link_id).html('<div class="succes">We hebben uw reservering goed ontvangen</div>');
				//add_remove_class('error','success',link_id);
				jQuery('#' + link_id).show();

				document.getElementById("name").value = "";
				document.getElementById("email").value = "";
				document.getElementById("tel").value = "";
				document.getElementById("date").value = "";
				document.getElementById("aantal").value = "";
				document.getElementById("opmerkingen").value = "";
			}
			else {
				//add_remove_class('success','error',link_id);
				jQuery('#' + link_id).html(msg + "</ol>");
			}
			
			req = null;
		}
	);
}

function add_remove_class(search,replace,element_id)
{
	if (jQuery('#' + element_id).hasClass(search)){
		jQuery('#' + element_id).removeClass(search);
	}
	jQuery('#' + element_id).addClass(replace);
}

function clearForm(form) {
  // iterate over all of the inputs for the form
  // element that was passed in
  $(':input', form).each(function() {
	var type = this.type;
	var tag = this.tagName.toLowerCase(); // normalize case
	// it's ok to reset the value attr of text inputs,
	// password inputs, and textareas
	if (type == 'text' || type == 'password' || tag == 'textarea')
	  this.value = "";
	// checkboxes and radios need to have their checked state cleared
	// but should *not* have their 'value' changed
	else if (type == 'checkbox' || type == 'radio')
	  this.checked = false;
	// select elements need to have their 'selectedIndex' property set to -1
	// (this works for both single and multiple select elements)
	else if (tag == 'select')
	  this.selectedIndex = -1;
  });
};
