// JavaScript Document

document.observe('dom:loaded', function() {
	//$('ajaxform').observe('click', showAjaxFormDemonstration);
});


function showAjaxFormDemonstration(param) {
	//alert(param+' x');
	//Event.stop(event);
	Lightview.show({
		href: 'content/newsletter_fullform.php?'+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 inputName = $('ajaxForm').email.value.strip();
  	if (!inputName) { checkFields = false; };
	var inputEmail = $('ajaxForm').zip.value.strip();
 	 if (!inputEmail) { checkFields = false; };
	var inputText = $('ajaxForm').captcha.value.strip();
  	if (!inputText) { checkFields = false; };
	
  
	if (!checkFields) { showDiv('message_red'); return; };
	// return;
	
	
	 
	
	
  Lightview.show({
    href: 'content/newsletter_fullform.php',
    rel: 'ajax',
    options: {
      title: 'results',
	  menubar: false,
	  topclose: true,
	  autosize: true,
      ajax: {
        parameters: Form.serialize('ajaxForm') // the parameters from the form
      }
    }
  });
}
