
window.onscroll = moveMenu;



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 moveMenu()
{

	if( document.body.scrollTop){ dist=document.body.scrollTop; }else{ dist=document.documentElement.scrollTop; }


	if (document.getElementById('menuleft')) {

		ref=283;

				
		if(dist>ref){
			
			hauteur=document.getElementById('menuleft').offsetHeight;
			dispo=document.getElementById('tablepage').offsetHeight;	
			position=dist-ref+15;
			
			if (document.getElementById('haut')) { document.getElementById('haut').style.visibility="visible"; }
			
			if(position+hauteur > dispo  ){
				position2=dispo-hauteur;
				document.getElementById('menuleft').style.top=position2+"px";
				
			}else{
				document.getElementById('menuleft').style.top=position+"px";
			}
		}else{
			
			document.getElementById('menuleft').style.top="15px";
			if (document.getElementById('haut')) { document.getElementById('haut').style.visibility="hidden"; }
		}
	}
}

function moveMenu2()
{

	if( document.body.scrollTop){ dist=document.body.scrollTop; }else{ dist=document.documentElement.scrollTop; }


	if (document.getElementById('menuleft')) {

		ref=470;

				
		if(dist>ref){
			
			hauteur=document.getElementById('menuleft').offsetHeight;
			dispo=document.getElementById('tablepage').offsetHeight;	
			position=dist-ref+15;
			
			if (document.getElementById('haut')) { document.getElementById('haut').style.visibility="visible"; }
			
			if(position+hauteur > dispo  ){
				position2=dispo-hauteur;
				document.getElementById('menuleft').style.top=position2+"px";
				
			}else{
				document.getElementById('menuleft').style.top=position+"px";
			}
		}else{
			
			document.getElementById('menuleft').style.top="15px";
			if (document.getElementById('haut')) { document.getElementById('haut').style.visibility="hidden"; }
		}
	}
}


function affich_image(sejour,pays)
{
window.open("http://www.vivatours.fr/test/image.php?sejour="+sejour+"&pays="+pays,"image","height=600,width=800,left=50,top=50,scrollbars=no,resizable=no,menubar=no,status=yes/no,toolbar=no,location=no") ;
}

function affich_hotel(hotel,pays)
{
window.open("http://www.vivatours.fr/new2/flash_hotel.php?hotel="+hotel+"&pays="+pays,"_blank","height=370,width=600,left=50,top=50,scrollbars=no,resizable=no,menubar=no,status=yes/no,toolbar=no,location=no") ;
}

function affich_bateau(bateau,pays)
{
window.open("http://www.vivatours.fr/new2/flash_bateau.php?bateau="+bateau+"&pays="+pays,"_blank","height=370,width=600,left=50,top=50,scrollbars=no,resizable=no,menubar=no,status=yes/no,toolbar=no,location=no") ;
}

function affich_excursion(excursion,pays)
{
window.open("http://www.vivatours.fr/new2/affich_excursion.php?excursion="+excursion+"&pays="+pays,"_blank","height=500,width=450,left=50,top=50,scrollbars=yes,resizable=no,menubar=no,status=no,toolbar=no,location=no") ;
}
function affich_extension(extension,pays)
{
window.open("http://www.vivatours.fr/new2/affich_extension.php?extension="+extension+"&pays="+pays,"_blank","height=500,width=450,left=50,top=50,scrollbars=yes,resizable=no,menubar=no,status=no,toolbar=no,location=no") ;
}

function carte(fichier) {
	ff=window.open("http://www.vivatours.fr/new2/"+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"
selectedItem=cid+"|"+document.getElementById(cid).style.display
}


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('tablepage').offsetHeight) {
		
		haut3=document.getElementById('tablepage').offsetHeight;

	}	
	
	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';}

	if (document.getElementById('tablepage').offsetHeight) {

		haut2=document.getElementById('tablepage').offsetHeight;

		if(haut2<haut3){

			document.getElementById('tablepage').style.height=haut3+"px";

		}

	}	

	
}

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" )
{
alert("Votre E-mail n'est pas valide");
return false;
}

return true;
}


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);

}