function scrollbar() {
	var wndo = new dw_scrollObj('listingVideos', 'listing');
	wndo.setUpScrollbar("drag", "track", "v", 1, 1);
	wndo.setUpScrollControls('scrollbar');
}
function scrollbar2() {
	var wndo = new dw_scrollObj('scrollAll', 'contentScroll');
	wndo.setUpScrollbar("drag2", "track2", "v", 1, 1);
	wndo.setUpScrollControls('scrollbar2');
}
function openLightview(file, titre) {
		
	Lightview.show({
		href: file,
		rel: 'image',
		title: titre,
		options:{menubar:'bottom',closeButton:'small'}
	});

}
function showForm() {
	var params = Form.serialize(GLO_myForm); 
	var paramsVols = $('paramsVols').innerHTML;
	var langue = $('langue').innerHTML;
	
	Lightview.show({
		href: 'ajax/ajax.send.php',
		rel: 'ajax',
		options: {
			autosize: true,
			topclose: true,
			overlayClose: false,
			ajax: {
				method: 'post',
				parameters: params+'&total='+GLO_prix_total+'&transport='+GLO_transport+'&nbr='+GLO_nbrPersonnes+'&date='+GLO_date+'&paramsVol='+paramsVols+'&langue='+langue
			}
		}
	});
}

function extendsMenu(hide) {
	if(!$('showExtendsMenu')) {
		Event.observe($(hide+'_1'), 'mouseover', function() {
			if($(hide).visible != true)
				$(hide).show();
		});
		Event.observe($(hide), 'mouseout', function() {
			$(hide).hide();
		});
		Event.observe($(hide+'_1'), 'mouseout', function() {
			$(hide).hide();
		});
	}
	else {
		$(hide).show();
	}
}
var GLO_selectPersonne;
var GLO_eventPersonneChange = true;
var GLO_devise;
var GLO_daysDisp;

//FORMULAIRE
var GLO_myForm;
var GLO_prix_total;
var GLO_nbrPersonnes = 1;
var GLO_transport = 1;
var GLO_date;

function eventTour() {
	initMyForm();
	Event.observe('transports','change', function() {
		if(this.value != false)
			$('t_'+this.value).appear();
			
		var tab = $$('select[name=tarifs]');
		for(var i=0; i<tab.length; i++) {
			if(this.value == "") {
				$(tab[i]).hide();
				$('prix').hide();
				hideFonctionCal();
				GLO_selectPersonne = "";
			}
			else if(tab[i].id != 't_'+this.value) {
				$(tab[i]).hide();
				$('prix').hide();
				Event.stopObserving();
			}
			else {
				GLO_transport = this.value;
				
				GLO_selectPersonne = tab[i].id;
				$(GLO_selectPersonne).options[0].selected = true;
				
				var firstOpt = $$('#'+tab[i].id+' :first-child');
				firstOpt = firstOpt[0].value;
				
				$('prix').appear();
				$('prixTotal').update(firstOpt);
				GLO_prix_total = firstOpt;
				
				//if(GLO_eventPersonneChange)
					eventPersonneChange();
			}
		}
		showCalendar();
	});
}
function eventPersonneChange() {
	Event.observe(GLO_selectPersonne, 'change', function() {
		var tabNbrPersonnes = $(GLO_selectPersonne).options;
		for(var i=0; i<tabNbrPersonnes.length;i++) {
			if(tabNbrPersonnes[i].selected == true) {
				$('prixTotal').update(tabNbrPersonnes[i].value);
				GLO_prix_total = tabNbrPersonnes[i].value;
				GLO_nbrPersonnes = (i+1);
			}
		}
	});
	GLO_eventPersonneChange = false;
}
var GLO_currentDate = "";
function showCalendar() {
	new Ajax.Request('ajax/ajax.calendrier.php?idEvent='+GLO_selectPersonne,
		{
		asynchronous:true, method: 'get',
		onSuccess: function(t) {
			eval(t.responseText);
			
			GLO_currentDate = currentDate;			
			GLO_daysDisp = daysDisp;		
			
			$('showCalendar').update(showCalendar);
			eventLinkCalendar();
			
			if(GLO_selectPersonne != "")
				showActivedDays(activedDays);
			else
				hideFonctionCal();
		}
	});
	eventPrevNext();
}
function showActivedDays(activedDays) {
	var tabLinkCalendar = $$('.ligne a');
	var tab = activedDays.split("##");
	
	for(var i=0; tabLinkCalendar.length > i; i++) {			
		if(GLO_daysDisp == 0) {
			$(tabLinkCalendar[i]).addClassName('bgLinkActivedCalendarDisp');
			$(tabLinkCalendar[i]).style.opacity = 0.7;
		}
		for (var j=0; j < tab.length; j++) {
			if(tabLinkCalendar[i].id == 'id_'+tab[j]) {
				if(GLO_daysDisp == 0) 
					$(tabLinkCalendar[i]).removeClassName('bgLinkActivedCalendarDisp');
				else
					$(tabLinkCalendar[i]).addClassName('bgLinkActivedCalendarDisp');
				
				$(tabLinkCalendar[i]).style.opacity = 0.7;
			}
		}
	}
}
var GLO_prevNext = true;
function eventPrevNext() {

	initFonctionCal();
	
	if(GLO_prevNext) {
		//PREV
		Event.observe('prevCalendar', 'click', function() {
			new Ajax.Request('ajax/ajax.calendrier.php?act=prevCalendar&idEvent='+GLO_selectPersonne+'&currentDate='+GLO_currentDate,
				{
				asynchronous:true, method: 'get',
				onSuccess: function(t) {
					eval(t.responseText);
					
					GLO_currentDate = currentDate;
					
					$('showCalendar').update(showCalendar);
					eventLinkCalendar();
					showActivedDays(activedDays);
				}
			});
		});
		//NEXT
		Event.observe('nextCalendar', 'click', function() {
			new Ajax.Request('ajax/ajax.calendrier.php?act=nextCalendar&idEvent='+GLO_selectPersonne+'&currentDate='+GLO_currentDate,
				{
				asynchronous:true, method: 'get',
				onSuccess: function(t) {
					eval(t.responseText);
					
					GLO_currentDate = currentDate;
					
					$('showCalendar').update(showCalendar);
					eventLinkCalendar();
					showActivedDays(activedDays);
				}
			});
		});
		GLO_prevNext = false;
	}
}
function initFonctionCal() {
	$('prevCalendar').style.cssText = 'cursor:pointer;display:block;';
	$('nextCalendar').style.cssText = 'cursor:pointer;display:block;';
}
function hideFonctionCal() {
	$('prevCalendar').style.cssText = 'display:none;';
	$('nextCalendar').style.cssText = 'display:none;';
}
function eventLinkCalendar() {
	initMyForm();
	var tabLinkCalendar = $$('.ligne a');
	for(var i=0; tabLinkCalendar.length > i; i++) {
		Event.observe(tabLinkCalendar[i], 'click', function() {
			var linkId = this.id;
			if($(linkId).hasClassName('bgLinkActivedCalendarDisp'))
				activeMyForm(linkId);
			else
				initMyForm();
		});
	}
}
//FORMULAIRE
function initMyForm() {
	GLO_myForm = $('myForm');
	Form.disable(GLO_myForm);
	$('recapitulatif').update('&nbsp;');
}
var GLO_validate = true;
var GLO_cgv = false;
function activeMyForm(linkId) {
	recapitulatif(linkId);
	new Effect.Appear('mySubmit', {duration:0.5});
	
	if(GLO_validate) {
		Event.observe('mySubmit', 'click', function() {
			verirMyAjaxForm();
		});
		GLO_validate = false;
	}
	
	Form.enable(GLO_myForm);	
	var myFields = Form.getElements(GLO_myForm);
	for(var i=0; i<myFields.length; i++) {
		Event.observe(myFields[i].id, 'blur', function() {
			if($F(this.id) == "" && this.id != "cgv")
				errorField(this.id);
			else {
				if(this.id == "cgv") {
					if(this.checked == true)
						GLO_cgv = true;
					else GLO_cgv = false;
				}
				else if($(this.id).id == "email") {
					var reg = new RegExp('^[a-z0-9]+([_|\.|-]?[a-z0-9]+)*@[a-z0-9]+([_|\.|-]{1}[a-z0-9]+)*[\.]{1}[a-z]{2,6}$', 'i');
					if(!reg.test($F('email')))
						errorField('email');
					else
						restoreField('email');
				}
				else
					restoreField(this.id);	
			}
				
			verifMyForm();
		});
	}
}
var GLO_post = true;
var GLO_setError;
function verifMyForm() {
	GLO_setError = false;
	var myFields = Form.getElements(GLO_myForm);
	for(var i=0; i<myFields.length; i++) {
		if($(myFields[i]).id != "mySubmit") {
			if($F(myFields[i].id) == "")
				GLO_setError = true;
		}
	}
	if(!GLO_setError && GLO_cgv == true) {
		if(GLO_post) {
			Event.observe('mySubmit', 'click', function() {
				SendForm();
			});
			GLO_post = false;
		}
	}
}
function verirMyAjaxForm() {
	var myFields = Form.getElements(GLO_myForm);
	for(var i=0; i<myFields.length; i++) {
		if($F(myFields[i]) == "" && $(myFields[i]).id != "cgv")
			errorField(myFields[i]);
		else {
			if($(myFields[i]).id == "cgv") {
				if($(myFields[i]).checked == true)
					GLO_cgv = true;
				else GLO_cgv = false;
			}
			else if($(myFields[i]).id == "email") {
				var reg = new RegExp('^[a-z0-9]+([_|\.|-]?[a-z0-9]+)*@[a-z0-9]+([_|\.|-]{1}[a-z0-9]+)*[\.]{1}[a-z]{2,6}$', 'i');
				if(!reg.test($F('email')))
					errorField('email');
				else
					restoreField('email');
			}
			else
				restoreField(myFields[i]);
		}
	}
}
function SendForm() {
	if(!GLO_setError && GLO_cgv == true) {
		var tabError = new Array();
		var params = Form.serialize(GLO_myForm);
		new Ajax.Request('ajax/ajax.post.php',{
			method: 'post',
			asynchronous: true,
			contentType: 'application/x-www-form-urlencoded',
			encoding: 'UTF-8',
			parameters: params,
			onSuccess: function(t){
				eval(t.responseText);
				for(var i=0; i<tabError.length;i++) {
					errorField(tabError[i]);
				}
				if(tabError.length == 0) {
					//OPEN LIGHTVIEW
					showForm();
				}
			},
			onFailure: function() {
				alert("nogood");
			},
			onLoading: function() {
				
			}
		});
	}
} 
function errorField(field) {
	var id = $(field).id;
	var bg = $(id).getStyle('background-color');
	if(bg == "rgb(255, 255, 255)" || bg == "#ffffff") {
		new Effect.Highlight(field, 
		{
			startcolor: "#FFFFFF",
			endcolor: "#FF0000",
			restorecolor: "#DF0000",
			duration: 0.5,
			afterFinish: function() {
				$(field).style.cssText = 'color:#ffffff; background:#DF0000;';
			}
		});
		$(field).style.color = '#ffffff';
	}
}
function restoreField(field) {
	var id = $(field).id;
	var bg = $(id).getStyle('background-color');
	if(bg != "rgb(255, 255, 255)" && bg != "#ffffff") {
		new Effect.Highlight(field, 
		{
			startcolor: "#DF0000",
			endcolor: "#FFFFFF",
			restorecolor: "#FFFFFF",
			duration: 0.5,
			afterFinish: function() {
				$(field).style.cssText = 'color:#000000; background:#FFFFFF;';
			}
		});
		$(field).style.color = '#000000';
	}
}
function recapitulatif(linkId) {
	var date = linkId.substring(3);
	date = date.split("-");
	
	var jour = date[2];
	var mois = convertMonth(date[1]);
	var annee = date[0];
	
	$('recapitulatif').update('Commande du '+jour+' '+mois+' '+annee);
	GLO_date = jour+' '+mois+' '+annee;
}
function convertMonth(numMonth) {
	var month = "";
	
	if(numMonth == 1) month = "janvier";
	if(numMonth == 2) month = "février";
	if(numMonth == 3) month = "mars";
	if(numMonth == 4) month = "avril";
	if(numMonth == 5) month = "mai";
	if(numMonth == 6) month = "juin";
	if(numMonth == 7) month = "juillet";
	if(numMonth == 8) month = "aôut";
	if(numMonth == 9) month = "septembre";
	if(numMonth == 10) month = "octobre";
	if(numMonth == 11) month = "novembre";
	if(numMonth == 12) month = "décembre";
	
	return month;
}
