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


function showAjaxFormDemonstration(event) {
	Event.stop(event);
	Lightview.show({
		href: 'form/quote.php',
		rel: 'ajax',
		options: {
			autosize: true,
			closeButton: 'small',
			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 text = $('ajaxForm').down('input').value.strip();
  if (!text) return;
	  
  Lightview.show({
    href: 'form/thanks.php',
    rel: 'ajax',
    options: {
      autosize: true,
	  title: 'results',
	  closeButton: 'small',
	  topclose: true,
      ajax: {
        parameters: Form.serialize('ajaxForm') // the parameters from the form
      }
    }
  });
}