$(document).ready(function(){  


	//Examples of how to assign the ColorBox event to elements
	$("a[rel='example1']").colorbox();
	$("a[rel='example2']").colorbox({transition:"fade"});
	$("a[rel='example3']").colorbox({transition:"none", width:"75%", height:"75%"});
	$("a[rel='example4']").colorbox({slideshow:true});
	$(".example5").colorbox(); 
	$(".popup").colorbox({iframe:true, innerWidth:640, innerHeight:450});
	$(".diapo").colorbox({width:"840px", height:"630px", iframe:true});
	$(".video").colorbox({transition:"none" , width:"555px", height:"420px", iframe:true});
	$(".example8").colorbox({width:"50%", inline:true, href:"#inline_example1"});
	$(".example9").colorbox({
		onOpen:function(){ alert('onOpen: colorbox is about to open'); },
		onLoad:function(){ alert('onLoad: colorbox has started to load the targeted content'); },
		onComplete:function(){ alert('onComplete: colorbox has displayed the loaded content'); },
		onCleanup:function(){ alert('onCleanup: colorbox has begun the close process'); },
		onClosed:function(){ alert('onClosed: colorbox has completely closed'); }
	});
	
	//Example of preserving a JavaScript event for inline calls.
	$("#click").click(function(){ 
		$('#click').css({"background-color":"#f00", "color":"#fff", "cursor":"inherit"}).text("Open this window again and this message will still be here.");
		return false;
	});
});


 


function champsok(){
	
	if (document.AVIS.type2.value == 0)
	{
	alert("Merci d'indiquez si vous êtes un particulier, une entreprise, une association ou une collectivité");
	return false;
	}
	if (document.AVIS.nom2.value.length == 0)
	{
	alert("Veuillez indiquez vos nom et prénom, Merci");
	return false;
	}
	if (document.AVIS.adresse.value.length == 0)
	{
	alert("Veuillez indiquez votre adresse, Merci");
	return false;
	}
	if (document.AVIS.cp.value.length == 0)
	{
	alert("Veuillez indiquez votre code postal, Merci");
	return false;
	}
	if (document.AVIS.ville.value.length == 0)
	{
	alert("Veuillez indiquez votre ville, Merci");
	return false;
	}
	if (document.AVIS.telephone.value.length == 0)
	{
	alert("Veuillez indiquez votre n° de téléphone, Merci");
	return false;
	}
	if (document.AVIS.mail.value.length == 0)
	{
	alert("Veuillez indiquez votre E-mail, Merci");
	return false;
	}
	if (
	  document.AVIS.mail.value.indexOf(" ") != -1 || document.AVIS.mail.value.indexOf(";") != -1 ||
	  document.AVIS.mail.value.indexOf("?") != -1 || document.AVIS.mail.value.indexOf("!") != -1 ||
	  document.AVIS.mail.value.indexOf("#") != -1 || document.AVIS.mail.value.indexOf("'") != -1 ||
	  document.AVIS.mail.value.indexOf('"') != -1 || document.AVIS.mail.value.indexOf(",") != -1 ||
	  document.AVIS.mail.value.indexOf('$') != -1 || document.AVIS.mail.value.indexOf("*") != -1 ||
	  document.AVIS.mail.value.indexOf(':') != -1 || document.AVIS.mail.value.indexOf("/") != -1 ||
	  document.AVIS.mail.value.indexOf("@") == -1 || document.AVIS.mail.value.indexOf(".") == -1
		)
	{
	alert("Votre E-mail n'est pas valide");
	return false;
	}
	
	return true;


}


var countDep = 0;
var  timer = 0;

function dep(dir){

	if(countDep==0){
	
		if(dir==1){
	
			courrant++;
	
			if( courrant == nbre-1  ){ document.getElementById('f_bas').style.visibility='hidden'; }
			document.getElementById('f_haut').style.visibility='visible';
			
			timer=setInterval("gotoy(130)", 100);
	
	
		}else{
	
			courrant--;
	
			if( courrant == 1  ){ document.getElementById('f_haut').style.visibility='hidden'; }
			document.getElementById('f_bas').style.visibility='visible';
			
			timer=setInterval("gotoy(-130)", 100);
	
		}
	}
}

function gotoy(depY){

	countDep++;
	
	if( countDep<=5 ){
		
		document.getElementById('com').scrollTop+=depY/5;

	}else{
		clearInterval(timer);
		countDep = 0;
	}

}



function getElementsBySelector(selector){
//Extracted from nifty.js
	var i,selid="",selclass="",tag=selector,f,s=[],objlist=[];
	if(selector.indexOf(" ")>0){  //descendant selector like "tag#id tag"
		s=selector.split(" ");
		var fs=s[0].split("#");
		if(fs.length==1) return(objlist);
		f=document.getElementById(fs[1]);
		if(f) return(f.getElementsByTagName(s[1]));
		return(objlist);
	}
	if(selector.indexOf("#")>0){ //id selector like "tag#id"
		s=selector.split("#");
		tag=s[0];
		selid=s[1];
    }
	if(selid!=""){
		f=document.getElementById(selid);
		if(f) objlist.push(f);
		return(objlist);
    }
	if(selector.indexOf(".")>0){  //class selector like "tag.class"
		s=selector.split(".");
		tag=s[0];
		selclass=s[1];
    }
	var v=document.getElementsByTagName(tag);  // tag selector like "tag"
	if(selclass=="")
		return(v);
	for(i=0;i<v.length;i++){
		if(v[i].className.indexOf(selclass)>=0)
			objlist.push(v[i]);
    }
	return(objlist);
}


function setTarif(id){
	
	var nodeClass = getElementsBySelector('div.tarif_select');

	for (I=0;I<nodeClass.length; I++) {
	
		 nodeClass[I].className='tarif';

	}

	document.getElementById('tarif'+id).className='tarif_select';


	var nodeClass = getElementsBySelector('input.tarif_check');

	for (I=0;I<nodeClass.length; I++) {
	
		 nodeClass[I].checked=false;

	}

	document.getElementById('check'+id).checked=true;


}

function unsetTarif(id){
	
	document.getElementById('tarif'+id).className='tarif';

}



function carte(fichier) {
	ff=window.open("./popup/"+fichier, "_blank","height=300,width=300,left=20,top=20,resizable=no,scrollbars=yes,menubar=no,status=yes/no,toolbar=no,location=no");
	}

function resize_carte(){ 
window.resizeTo(screen.availWidth,screen.availHeight);
window.moveTo(0,0);
}

function ouvre(fichier,larg,haut,px,py) {
	ff=window.open(fichier,"_blank","height="+haut+",width="+larg+",left="+px+",top="+py+",scrollbars=yes,resizable=no,menubar=no,status=yes/no,toolbar=no,location=no");

}


function switchcontent(cid){
	document.getElementById(cid).style.display=(document.getElementById(cid).style.display!="block")? "block" : "none"
}

var selectedItem = '0';

function switchonglet(cid){

	if(selectedItem != '0'){ if( document.getElementById(selectedItem).style.display == 'block' && selectedItem != cid ){ document.getElementById(selectedItem).style.display = 'none' } }

	document.getElementById(cid).style.display=(document.getElementById(cid).style.display!="block")? "block" : "none";

	selectedItem=cid;

}





function montre(id) {
	var d = document.getElementById(id);
		for (var i = 1; i<=10; i++) {
			if (document.getElementById('contenu'+i)) {document.getElementById('contenu'+i).style.display='none';}
		}
	if (d) {d.style.display='block';}
}

function montre_ss_cat(id,i,j,k) {
		
	//efface tout	
	if (document.getElementById('ss_cat'+i)) {document.getElementById('ss_cat'+i).style.display='none';}
	if (document.getElementById('per'+j)) {document.getElementById('per'+j).style.display='none';}
	if (document.getElementById('tablo'+k)) {document.getElementById('tablo'+k).style.display='none';}	
	if (document.getElementById('inclus'+i)) {document.getElementById('inclus'+i).style.display='none';}
	
	//focus select
	if (document.getElementById('opt'+i+'-0')) {document.getElementById('opt'+i+'-0').selected='selected';}
	if (document.getElementById('opt'+j+'-0')) {document.getElementById('opt'+j+'-0').selected='selected';}
	
	// affich
	if (document.getElementById('ss_cat'+id)) { document.getElementById('ss_cat'+id).style.display='block';}
	
	// tarif visible si pas de menu2	
	if(!document.getElementById('ss_cat'+id) ){ 
		montre_per(id+'-1',id,j,k);
	}
	
	

}

function montre_per(id,i,j,k) {
		
	//efface tout		
	if (document.getElementById('per'+j)) {document.getElementById('per'+j).style.display='none';}
	if (document.getElementById('tablo'+k)) {document.getElementById('tablo'+k).style.display='none';}
	if (document.getElementById('inclus'+i)) {document.getElementById('inclus'+i).style.display='none';}

	
	//focus select
	if (document.getElementById('opt'+j+'-0')) {document.getElementById('opt'+j+'-0').selected='selected';}
	
	//affich
	if (document.getElementById('per'+id)) { document.getElementById('per'+id).style.display='block'; }

	
	// tarif visible si pas de menu3	
	if( !document.getElementById('per'+id) ){ 
		montre_tablo(id+'-1',i,k);
	}
	
}

function montre_tablo(id,i,k) {
	
	if (document.getElementById('tablo'+k)) {document.getElementById('tablo'+k).style.display='none';}	
	
	if (document.getElementById('tablo'+id)) {document.getElementById('tablo'+id).style.display='block';}
	
	if (document.getElementById('inclus'+i)) {document.getElementById('inclus'+i).style.display='block';}
	
}

function montre_div(nomid,id,i,k) {
	
	if (document.getElementById(nomid+''+k)) {document.getElementById(nomid+''+k).style.display='none';}	
	
	if (document.getElementById(nomid+''+id)) {document.getElementById(nomid+''+id).style.display='block';}
	
	if (document.getElementById('inclus'+i)) {document.getElementById('inclus'+i).style.display='block';}
	
}


function nbParticipant(maxPax) {

	totalPax = 0;
	maxPax=Number(maxPax);

	td_adultes = document.getElementById('td_adultes');
	td_enfants = document.getElementById('td_enfants');

	if (td_adultes.selectedIndex != -1) { //record adult pax selection by user
			var selectedAdultPax = Number(td_adultes.options[td_adultes.selectedIndex].value);
			totalPax += selectedAdultPax;
	} else {
		var selectedAdultPax = "";
	}
	if (td_enfants.selectedIndex != -1) { //record child pax selection by user
			var selectedChildPax = Number(td_enfants.options[td_enfants.selectedIndex].value);
			totalPax += selectedChildPax;
	} else {
				var selectedChildPax = "";
	}
	
	if (selectedAdultPax == "" && selectedChildPax == "") totalPax = 1;


	var remainPax = maxPax - totalPax;

	// adult //

	if (selectedAdultPax == "")
			td_adultes.options.length = 1 + remainPax;
	else
		td_adultes.options.length = selectedAdultPax + remainPax;
	
	for (var i = 0; i < td_adultes.options.length; i++) {
			var theOption = td_adultes.options[i];
			theOption.text = theOption.value = i + 1;
			
			if (selectedAdultPax == theOption.value) {
					td_adultes.selectedIndex = theOption.index;
					selectedAdultPax = undefined;
			}
	}
		
	if (selectedAdultPax != undefined) {
			for (var i = 0; i < td_adultes.options.length; i++) {
					var theOption = td_adultes.options[i];
					if (selectedAdultPax == theOption.value) {
							td_adultes.selectedIndex = i;
							break;
					}
			}		
	}		
	if (td_adultes.selectedIndex == -1) {
		td_adultes.selectedIndex = 0;
	}
	
	selectedAdultPax = Number(td_adultes.options[td_adultes.selectedIndex].value);
	// child //
	td_enfants.options.length = 1 + parseInt(selectedChildPax + remainPax);
	td_enfants.options[0].text = td_enfants.options[0].value = 0;
	for (var i = 1; i < td_enfants.options.length; i++) {
		var theOption = td_enfants.options[i];
		theOption.text = theOption.value = i;
		if (selectedChildPax == theOption.value) {
				td_enfants.selectedIndex = theOption.index;
				selectedChildPax = undefined;
		}
	}
	if (selectedChildPax != undefined) {
		for (var i = 0; i < td_enfants.options.length; i++) {
			var theOption = td_enfants.options[i];
			if (selectedChildPax == theOption.value) {
				td_enfants.selectedIndex = i;
				break;
			}
		}
	}
	if (td_enfants.selectedIndex == -1) {
		td_enfants.selectedIndex = 0;
	}
	selectedChildPax = Number(td_enfants.options[td_enfants.selectedIndex].value);
	td_adultes.disabled = false;
	td_enfants.disabled = false;
	totalPax = selectedAdultPax + selectedChildPax;

	envoiTarif();
}

function envoiTarif() {

	if( 
		(!document.form2.vehicule || document.form2.vehicule.value!='0') 
		&& (!document.form2.hotel || document.form2.hotel.value!='0')
		&& (!document.form2.type_transfert || document.form2.type_transfert.value!='0')
		&& (!document.form2.chambre || document.form2.chambre.value!='0')
	)
	
	document.form2.submit();

	if(!document.form2.hotel) alert(document.form2.hotel.value);

}

function destination_DoFSCommand( ){
	  
	 montre('contenu3'); 	

}


