// JavaScript Document
document.observe('dom:loaded', function() {
	$$('a[rel]').each(function(element){
		element.observe('click', showAjaxFormDemonstration);
	});
});


function showAjaxFormDemonstration(event) {
	Event.stop(event);
	
	var idOffre = document.getElementById('choixOffre').value;
	var idActu = document.getElementById('choixActu').value;
	var idConsultant = document.getElementById('choixConsultant').value;
	
	if(idOffre != ''){
		Lightview.show({
			href: 'includes/tips/afficheOffre.php?idof='+idOffre,
			rel: 'ajax',
			options: {
				autosize:true,
				topclose: true
			}
		});
	}else if(idActu != ''){
		Lightview.show({
			href: 'includes/tips/afficheActu.php?idac='+idActu,
			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', submitAjaxForm);
					}
				}
			}
		});
	}else if(idConsultant != ''){
		Lightview.show({
			href: 'includes/tips/afficheConsultant.php?idco='+idConsultant,
			rel: 'ajax',
			options: {
				autosize:true,
				topclose: true
			}
		});
	}
}


function submitAjaxForm(event) {
  
  var idActu = document.getElementById('choixActu').value;
	
  // block default form submit
  Event.stop(event);
  Lightview.show({
    href: 'http://www.harmonc.com/LW_csq/LW_ajouteCommentaire.php',
    rel: 'ajax',
    options: {
      title: 'results',
	  menubar: false,
	  topclose: true,
	  autosize: true,
      ajax: {
        parameters: Form.serialize('ajaxForm')+"&idac="+idActu // the parameters from the form}
      }
    }
  });
}
