// JavaScript Document

document.observe('dom:loaded', function() {
	//$('ajaxform').observe('click', showAjaxFormDemonstration);
});


function showAjaxFormDemonstration(param) {
	//alert(param+' x');
	//Event.stop(event);
	Lightview.show({
		href: 'content/ajax_contactform.php?op='+param,
		rel: 'ajax',
		options: {
			autosize: true,
			topclose: true,
			ajax: {
				onComplete: function(){
				// once the request is complete we observe the form for a submit
				$('ajaxForm').observe('submit', submitAjaxFormDemonstration);
				}
			}
		}
	});
}

function submitAjaxFormDemonstration(event) {
  // block default form submit
  Event.stop(event);
  
 	// if there's no text in the box, don't do anything
  	var checkFields = true;
	var checkFields2 = true;
	
  	var inputName = $('ajaxForm').name.value.strip();
  	if (!inputName) { checkFields = false; };
 	var inputVille = $('ajaxForm').prenom.value.strip();
  	if (!inputVille) { checkFields = false; };
  	var inputText = $('ajaxForm').commentaire.value.strip();
  	if (!inputText) { checkFields = false; };
	var inputText = $('ajaxForm').captcha.value.strip();
  	if (!inputText) { checkFields = false; };
	
	var inputEmail = $('ajaxForm').mail.value.strip();
 	if (!inputEmail) { 
		checkFields = false; 
	} else {
		var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if (inputEmail.search(filter)) {
			checkFields2 = false;
		}
	};
  
  


	hideDiv('message_red_empty'); 
	hideDiv('message_red_badmail');
	
	if (!checkFields) { showDiv('message_red_empty'); return; };
	if (!checkFields2) { showDiv('message_red_badmail'); return; };
	// return;
	
	
	 
	
	
  Lightview.show({
    href: 'content/ajax_contactform.php',
    rel: 'ajax',
    options: {
      title: 'results',
	  menubar: false,
	  topclose: true,
	  autosize: true,
      ajax: {
        parameters: Form.serialize('ajaxForm') // the parameters from the form
      }
    }
  });
}

