var divToDisplay='';
function check_email(e) {
    ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";
    for(i=0; i < e.length ;i++){
        if(ok.indexOf(e.charAt(i))<0){ 
        return (false);
        }	
    } 
    if (document.images) {
        re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
        re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
        if (!e.match(re) && e.match(re_two)) {
            return (-1);		
        } 
    }
}

function circuitsNav(choice, pos){
	oNavProgramTop = document.getElementById('navProgramTop');
	oNavProgramTopOn = document.getElementById('navProgramTopOn');
	oNavCarteTop = document.getElementById('navCarteTop');
	oNavCarteTopOn = document.getElementById('navCarteTopOn');
	oNavTarifsTop = document.getElementById('navTarifsTop');
	oNavTarifsTopOn = document.getElementById('navTarifsTopOn');
	oNavProgramBottom = document.getElementById('navProgramBottom');
	oNavProgramBottomOn = document.getElementById('navProgramBottomOn');
	oNavCarteBottom = document.getElementById('navCarteBottom');
	oNavCarteBottomOn = document.getElementById('navCarteBottomOn');
	oNavTarifsBottom = document.getElementById('navTarifsBottom');
	oNavTarifsBottomOn = document.getElementById('navTarifsBottomOn');
	
	oDivProgram = document.getElementById('programme');
	oDivTarifs = document.getElementById('tarifs');
	
	switch(choice){
		case 'program':
			if ( oNavProgramTop != null ) oNavProgramTop.style.display = 'none';
			if ( oNavProgramTopOn != null ) oNavProgramTopOn.style.display = '';

			if ( oNavProgramBottom!= null ) oNavProgramBottom.style.display = 'none';
			if ( oNavProgramBottomOn!= null ) oNavProgramBottomOn.style.display = '';

			if ( oNavCarteTop != null ) oNavCarteTop.style.display = '';
			if ( oNavCarteTopOn != null ) oNavCarteTopOn.style.display = 'none';

			if ( oNavCarteBottom != null ) oNavCarteBottom.style.display = '';
			if ( oNavCarteBottomOn != null ) oNavCarteBottomOn.style.display = 'none';

			if ( oNavTarifsTop != null ) oNavTarifsTop.style.display = '';
			if ( oNavTarifsTopOn != null ) oNavTarifsTopOn.style.display = 'none';

			if ( oNavTarifsBottom != null ) oNavTarifsBottom.style.display = '';
			if ( oNavTarifsBottomOn != null ) oNavTarifsBottomOn.style.display = 'none';
			
			if ( oDivProgram != null ) oDivProgram.style.display = '';
			if ( oDivTarifs != null ) oDivTarifs.style.display = 'none';
			
			
		break;
		case 'carte':
			/*
			if ( oNavProgramTop != null ) oNavProgramTop.style.display = '';
			if ( oNavProgramTopOn != null ) oNavProgramTopOn.style.display = 'none';

			if ( oNavProgramBottom!= null ) oNavProgramBottom.style.display = '';
			if ( oNavProgramBottomOn!= null ) oNavProgramBottomOn.style.display = 'none';

			if ( oNavCarteTop != null ) oNavCarteTop.style.display = 'none';
			if ( oNavCarteTopOn != null ) oNavCarteTopOn.style.display = '';

			if ( oNavCarteBottom != null ) oNavCarteBottom.style.display = 'none';
			if ( oNavCarteBottomOn != null ) oNavCarteBottomOn.style.display = '';

			if ( oNavTarifsTop != null ) oNavTarifsTop.style.display = '';
			if ( oNavTarifsTopOn != null ) oNavTarifsTopOn.style.display = 'none';

			if ( oNavTarifsBottom != null ) oNavTarifsBottom.style.display = '';
			if ( oNavTarifsBottomOn != null ) oNavTarifsBottomOn.style.display = 'none';
			*/
			switch(pos){
			    case 'top':
			        showMap(oNavCarteTop);
			    break;
			    case 'bottom':
			        showMap(oNavCarteBottom);
			    break;
			}
			
		break;
		case 'tarifs':
			if ( oNavProgramTop != null ) oNavProgramTop.style.display = '';
			if ( oNavProgramTopOn != null ) oNavProgramTopOn.style.display = 'none';

			if ( oNavProgramBottom!= null ) oNavProgramBottom.style.display = '';
			if ( oNavProgramBottomOn!= null ) oNavProgramBottomOn.style.display = 'none';

			if ( oNavCarteTop != null ) oNavCarteTop.style.display = '';
			if ( oNavCarteTopOn != null ) oNavCarteTopOn.style.display = 'none';

			if ( oNavCarteBottom != null ) oNavCarteBottom.style.display = '';
			if ( oNavCarteBottomOn != null ) oNavCarteBottomOn.style.display = 'none';

			if ( oNavTarifsTop != null ) oNavTarifsTop.style.display = 'none';
			if ( oNavTarifsTopOn != null ) oNavTarifsTopOn.style.display = '';

			if ( oNavTarifsBottom != null ) oNavTarifsBottom.style.display = 'none';
			if ( oNavTarifsBottomOn != null ) oNavTarifsBottomOn.style.display = '';

			if ( oDivProgram != null ) oDivProgram.style.display = 'none';
			if ( oDivTarifs != null ) oDivTarifs.style.display = '';

		break;
	}
}


function docjslib_getRealLeft(oLink) {
	if (oLink == null) {
		xPos = 0;return;
	}
	xPos	= oLink.offsetLeft;
	tempEl	= oLink.offsetParent;
  	while (tempEl != null) {
  		xPos	+=	tempEl.offsetLeft;
  		tempEl	=	tempEl.offsetParent;
  	}
	return xPos;
}
			
function docjslib_getRealTop(oLink){
	if (oLink == null) {
		yPos = 0;return;
	}
	yPos	= oLink.offsetTop;
	tempEl	= oLink.offsetParent;
	
	while (tempEl != null) {
  		yPos	+=	tempEl.offsetTop;
  		tempEl	=	tempEl.offsetParent;
  	}
	return yPos;
}


function openSlow(idDiv, _height, step, stepAcc){
	var oDiv = document.getElementById(idDiv);
	if ( oDiv != null ) {
		intHeight = parseInt(oDiv.style.height.replace('px',''));
		if ( isNaN(intHeight) ) intHeight = 0;
		if ( intHeight < _height  ){
			//alert('_height ' + _height);
			//alert('intHeight ' + intHeight);
			intHeight+=step;
			if ( intHeight > _height ) intHeight = _height;
			oDiv.style.height = intHeight + 'px';
			if ( intHeight < _height  ) {
				step += stepAcc;
				setTimeout("openSlow('"+idDiv+"',"+ _height +", "+step+","+stepAcc+" )", 100);
			}
		}
	}
}



function closeSlow(idDiv, _height, step, stepAcc){
	var oDiv = document.getElementById(idDiv);
	if ( oDiv != null ) {
		intHeight = parseInt(oDiv.style.height.replace('px',''));
		if ( isNaN(intHeight) ) intHeight = _height;
		if ( intHeight > 0  ){
			//alert('_height ' + _height);
			//alert('intHeight ' + intHeight);
			intHeight-=step;
			//alert('intHeight ' + intHeight);
			if ( intHeight < 0 ) intHeight = 0;
			oDiv.style.height = intHeight + 'px';
			if ( intHeight >= 0  ) {
				step += stepAcc;
				setTimeout("closeSlow('"+idDiv+"',"+ _height +", "+step+", "+stepAcc+" )", 100);
			}
		}
	}
}

function showDiaporama(){
	oDiaporama = document.getElementById('diaporama');
	oBt = document.getElementById('lnk_diaporama');
	oBt_on = document.getElementById('lnk_diaporama_on');
    
	var _height = heightDiaporama;
	var step = 5;
	var stepAcc = 25;
	
	if ( oDiaporama == null ) return;
	docjslib_getRealTop(oBt);
	oDiaporama.style.top = (yPos  + 44 )+'px';; 
   // alert(oDiaporama.style.height);
	if ( oDiaporama.style.display == '' ){
		oDiaporama.style.display = 'none';
		oDiaporama.style.height = '0px';
		if ( oBt != null ) oBt.style.display = '';
		if ( oBt_on != null ) oBt_on.style.display = 'none';
	}else{
		oDiaporama.style.display = '';
		openSlow('diaporama', _height, step , stepAcc);
		if ( oBt != null ) oBt.style.display = 'none';
		if ( oBt_on != null ) oBt_on.style.display = '';
   }
}

function showHotel(id, idhotel){
	oHotel = document.getElementById('popup_hotel');
	oBt= document.getElementById('lnk_hotel_'+id);
	
	if ( oHotel == null ) return;
	docjslib_getRealTop(oBt);
	docjslib_getRealLeft(oBt);
	oHotel.style.top = (yPos  + 14 )+'px';; 
	oHotel.style.left = (xPos  -170 )+'px';; 
   // alert(oHotel.style.height);
    oHotel.style.display = '';
    divToDisplay ='hotel_content';
    ajax_postForm('pophotel.php', 'id='+idhotel, hotel_postChanged);
}
function closeHotel(){
	oHotel = document.getElementById('popup_hotel');
    oHotel.style.display = 'none';
}
/*GGMAP*/
var map;

function clearGGmap(){
	if (GBrowserIsCompatible()) {
		map.clearOverlays();
		bounds = null; 
		minLat = 3000;
		minLng = 3000;
		maxLat = -3000;
		maxLng = -3000;
	}
}




function displayMAP(_fileXML){
	var request = GXmlHttp.create();
	request.open("GET", _fileXML, true);
	request.onreadystatechange = function() {
	    if (request.readyState == 4) {
		   //alert(request.responseText);
		    var xmlDoc = GXml.parse(request.responseText);
		    // obtain the array of markers and loop through it
		    var markers = xmlDoc.documentElement.getElementsByTagName("marker");
		    for (var i = 0; i < markers.length; i++) {
			    // obtain the attribues of each marker
			    var lat = parseFloat(markers[i].getAttribute("lat"));
			    var lng = parseFloat(markers[i].getAttribute("lng"));
			    if ( !(markers[i].getAttribute("numjours")==null) ){
    			    var numjour = markers[i].getAttribute("numjours");
			    }else{
    			    var numjour = '';
			    }
			    if ( lat < minLat ) minLat = lat;
			    if ( lng < minLng ) minLng = lng;
			    if ( lat > maxLat ) maxLat = lat;
			    if ( lng > maxLng ) maxLng = lng;

			    //alert('lat: ' + lat +'\nlng ' + lng + '\n\n' + 'minLat: ' + minLat +'\nminLng  ' + minLng  + '\n\n'
			    //+ 'maxLat: ' + maxLat +'\nmaxLng  ' + maxLng  + '\n\n');

			    var point = new GLatLng(lat,lng);
			    var html = markers[i].getAttribute("html");
			    var label = markers[i].getAttribute("label");
			    // create the marker
			    var marker = createMarker(point,label,html, numjour);
			    map.addOverlay(marker);
		    }
		    //alert('bounds 1');
		    //alert(bounds);
          
		    //var bounds = new GLatLngBounds(new GLatLng(minLat, minLng), new GLatLng(maxLat, maxLng)); 
		    var bounds = new GLatLngBounds(new GLatLng(minLat-1, minLng-1), new GLatLng(maxLat+1, maxLng+1)); 
		    //alert(minLat+ ' ' +  minLng+ ' ' + maxLat+ ' ' + maxLng);
		    //alert(bounds);
		    map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds)); 
        
		    // ========= Now process the polylines ===========
		    var lines = xmlDoc.documentElement.getElementsByTagName("line");
		    // read each line
		    for (var a = 0; a < lines.length; a++) {
			    // get any line attributes
			    var colour = lines[a].getAttribute("colour");
			    var width  = parseFloat(lines[a].getAttribute("width"));
			    // read each point on that line
			    var points = lines[a].getElementsByTagName("point");
			    var pts = [];
			    for (var i = 0; i < points.length; i++) {
				    pts[i] = new GLatLng(parseFloat(points[i].getAttribute("lat")),
				    parseFloat(points[i].getAttribute("lng")));
			    }
			    map.addOverlay(new GPolyline(pts,colour,width));
		    }
	      // ================================================           
	    }
    }
    request.send(null);
}

function showMap(oLink){
	oMap = document.getElementById('map_large_cadre');
	if ( oMap == null ) return;
	docjslib_getRealTop(oLink);
	oMap.style.top = (yPos  - ( parseInt(oMap.style.height.replace('px','')) ) -20)+'px';; 
	oMap.style.display = '';
	
	if (GBrowserIsCompatible()) { 
		// Display the map, with some controls and set the initial location 
		if ( map == null ) {
			map = new GMap2(document.getElementById('map_large'));
			map.addControl(new GSmallMapControl());
			map.addControl(new GMenuMapTypeControl());
			map.setCenter(new GLatLng(37.09023980307208, -95.712890625), 3);
			var bounds = null; 
		}
		// assign this somewhere 
		bounds = new GLatLngBounds(); 
		var minLat = 3000;
		var minLng = 3000;
		var maxLat = -3000;
		var maxLng = -3000;
		clearGGmap();
		displayMAP("get_tour_map.php?id=" + _idtours);
	}
	// display a warning if the browser was not compatible
	else {
	  alert("Sorry, the Google Maps API is not compatible with this browser");
	}
}


// A function to create the marker and set up the event window
function createMarker(point,name,html,numjour) {
    if ( numjour.length > 0 ) {
 		var baseIcon = new GIcon(); 
 		baseIcon.iconSize=new GSize(20,34); 
 		baseIcon.iconAnchor=new GPoint(10,34); 
 		baseIcon.infoWindowAnchor=new GPoint(10,34); 
 		var jIcone = new GIcon(baseIcon, 'picts/gmap/iconr'+numjour+'.png', null, ''); 

	    var marker = new GMarker(point, jIcone);
    }else{
	    var marker = new GMarker(point);
	}
	GEvent.addListener(marker, "click", function() {
	  marker.openInfoWindowHtml(html);
	});

    //alert('picts/gmap/iconr'+numjour+'.png');


	return marker;
}


/*!GGMAP*/


/*RESERVATION*/
var xmlHttp;

function goTopCommand(){
    strLocation = document.location.href;
    if ( strLocation.indexOf('#top_command') < 0 ){
        strLocation += '#top_command';
    }
    document.location = strLocation;
}

function reserver(idtarif, tpvvge, idvge){
    btReservLoad('load');
    var strpost = "tab="+tpvvge+"&idtarifs="+idtarif+"&id="+idvge;
    //strpost = "id=142&tab=t&idtarifs=278"; // Tour
    //strpost = "idvehicules=26&idvilles=0&idstations=30&typeloc=car&tab=l&idtarifs="; //Test Loc Auto Type 1
    //strpost = "idvehicules=37&idvilles=0&idstations=31&typeloc=car&tab=l&idtarifs="; //Test Loc Auto Type 2
    //strpost = "idvehicules=9&idvilles=152&idstations=53&typeloc=bike&tab=l&idtarifs="; //Test Loc Moto
    //alert(strpost);
    var url="commander.php";
    ajax_postForm(url, strpost, commanderStateChanged);
}

function annulerResa(){
    goTopCommand();
    var oDivTarifDetail = document.getElementById('tarifs_detail');
    var oDivResa = document.getElementById('resa_commander');
    if ( oDivTarifDetail != null ){
        oDivTarifDetail.style.display = '';
    }
    if ( oDivResa != null ){
        oDivResa.style.display = 'none';
        oDivResa.innerHTML = '';
    }
}
function annulerCoordonnees(){
    goTopCommand();
    var oDivCommander = document.getElementById('resa_commander');
    var oDivCoordonnes = document.getElementById('resa_coordonnees');
    if ( oDivCommander != null ){
        oDivCommander.style.display = '';
    }
    if ( oDivCoordonnes != null ){
        oDivCoordonnes.style.display = 'none';
        oDivCoordonnes.innerHTML = '';
    }
}

function btReservLoad(mode){
   var links=document.getElementsByTagName("A");

    for(var i=0; i< links.length; i++){
        if ( links[i].className.indexOf('resa') >= 0 || links[i].className==('ok')){
            if ( document.getElementById(links[i].id+'_load') != null ){
                if ( mode == 'load' ){
                    links[i].style.display = 'none';
                    document.getElementById(links[i].id+'_load').style.display = '';
                }else{
                    links[i].style.display = '';
                    document.getElementById(links[i].id+'_load').style.display = 'none';
                }
            }
            //alert(links[i].className);
            //links[i].style.
        }
    }
}


function commanderStateChanged(){ 
    var oDivTarifDetail = document.getElementById('tarifs_detail');
    var oDivResa = document.getElementById('resa_commander');
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
        //alert('ok 2');
        if ( xmlHttp.status != "200" ){
            alert("Une erreur est survenue, veuillez essayer ultérieurement ou nous contacter par téléphone.");
        }else{
            goTopCommand();
            if ( xmlHttp.responseText.length > 0 ){
                //alert('ok 3');
                if ( xmlHttp.responseText.indexOf('<<LOG_ERROR>>') >= 0 ){
                    alert('Une erreur est survenue, veuillez essayer ultérieurement ou nous contacter par téléphone.');
                }else{
                    if ( oDivResa != null ) {
                        oDivResa.style.display = '';
                        oDivTarifDetail.style.display = 'none';
                        oDivResa.innerHTML=xmlHttp.responseText;
                    }
                }
            }else{
                if ( oDivResa != null ) {
                    oDivResa.innerHTML='';
                    oDivResa.style.display = 'none';
                    oDivTarifDetail.style.display = '';
                }
            }
        }
        btReservLoad('');
    } 
}

function commander_valider(tpvvge, aDatesValides, strDatesValides, bIsLinkedVh, nbVehic){
    bIsOk = true;
    //////////////////////////////////////////////////////////////////////
    //Check Pour les TOURS
    if (tpvvge == "t" && bIsLinkedVh == 0){
        if ( document.form_commander.choixvehic1 != null ){
            if( document.form_commander.choixvehic1.selectedIndex == 0 ){
	            document.form_commander.choixvehic1.focus();
	            alert('Veuillez choisir un véhicule');
	            return false;
            }
        } 
        if ( document.form_commander.choixvehic2 != null ){
            if( document.form_commander.choixvehic2.selectedIndex == 0 ){
	            document.form_commander.choixvehic2.focus();
	            alert('Veuillez choisir un deuxième véhicule');
	            return false;
            }
            
            if ( document.form_commander.choixvehic1 != null ){
              if ( document.form_commander.choixvehic1.selectedIndex == document.form_commander.choixvehic2.selectedIndex ){
  	            document.form_commander.choixvehic2.focus();
  	            alert('Veuillez choisir des véhicules différents');
  	            return false;
              }
            }
            
        } 
        if ( document.form_commander.choixvehic3 != null ){
            if( document.form_commander.choixvehic3.selectedIndex == 0 ){
	            document.form_commander.choixvehic3.focus();
	            alert('Veuillez choisir un troisième véhicule');
	            return false;
            }


            if ( document.form_commander.choixvehic1 != null ){
              if ( document.form_commander.choixvehic1.selectedIndex == document.form_commander.choixvehic3.selectedIndex ){
  	            document.form_commander.choixvehic3.focus();
  	            alert('Veuillez choisir des véhicules différents');
  	            return false;
              }
            }

            if ( document.form_commander.choixvehic2 != null ){
              if ( document.form_commander.choixvehic2.selectedIndex == document.form_commander.choixvehic3.selectedIndex ){
  	            document.form_commander.choixvehic3.focus();
  	            alert('Veuillez choisir des véhicules différents');
  	            return false;
              }
            }


        } 
    }
    //! Check Pour les TOURS
    /////////////////////////////////////////////////////////////////////////////////////////////


    /////////////////////////////////////////////////////////////////////////////////////////////
    //+Check LOCATIONS
    if (tpvvge == "l"){

	    strDateDeb = document.form_commander.anneeD.options[document.form_commander.anneeD.selectedIndex].value + document.form_commander.moisD.options[document.form_commander.moisD.selectedIndex].value + document.form_commander.jourD.options[document.form_commander.jourD.selectedIndex].value;
	    intDateDeb = parseInt(strDateDeb);
	    intAnneeDeb = parseInt(document.form_commander.anneeD.options[document.form_commander.anneeD.selectedIndex].value);
	    intMoisDeb = document.form_commander.moisD.options[document.form_commander.moisD.selectedIndex].value.indexOf('0') == 0 ? parseInt(document.form_commander.moisD.options[document.form_commander.moisD.selectedIndex].value.substr(1,1)) : parseInt(document.form_commander.moisD.options[document.form_commander.moisD.selectedIndex].value);
	    intJourDeb = document.form_commander.jourD.options[document.form_commander.jourD.selectedIndex].value.indexOf('0') == 0 ? parseInt(document.form_commander.jourD.options[document.form_commander.jourD.selectedIndex].value.substr(1,1)) : parseInt(document.form_commander.jourD.options[document.form_commander.jourD.selectedIndex].value);

	    strDateFin = document.form_commander.anneeF.options[document.form_commander.anneeF.selectedIndex].value + document.form_commander.moisF.options[document.form_commander.moisF.selectedIndex].value + document.form_commander.jourF.options[document.form_commander.jourF.selectedIndex].value;
	    intDateFin = parseInt(strDateFin);
	    intAnneeFin = parseInt(document.form_commander.anneeF.options[document.form_commander.anneeF.selectedIndex].value);
	    intMoisFin = document.form_commander.moisF.options[document.form_commander.moisF.selectedIndex].value.indexOf('0') == 0 ? parseInt(document.form_commander.moisF.options[document.form_commander.moisF.selectedIndex].value.substr(1,1)) : parseInt(document.form_commander.moisF.options[document.form_commander.moisF.selectedIndex].value);
	    intJourFin = document.form_commander.jourF.options[document.form_commander.jourF.selectedIndex].value.indexOf('0') == 0 ? parseInt(document.form_commander.jourF.options[document.form_commander.jourF.selectedIndex].value.substr(1,1)) : parseInt(document.form_commander.jourF.options[document.form_commander.jourF.selectedIndex].value);
	    strDateDebNorm = strDateDeb.substr(6,2)+'/'+ strDateDeb.substr(4,2) + '/' + strDateDeb.substr(0,4);
	    strDateFinNorm = strDateFin.substr(6,2)+'/'+ strDateFin.substr(4,2) + '/' + strDateFin.substr(0,4);

	    if ( !CheckDate(strDateDebNorm) ){
    	    document.form_commander.jourD.focus();
    	    alert('La date de début de location n\'est pas valide.');
            return false;
	    }
	    if ( !CheckDate(strDateFinNorm) ){
    	    document.form_commander.jourF.focus();
    	    alert('La date de début de location n\'est pas valide.');
            return false;
	    }
        DateDeb  = new Date(intAnneeDeb, intMoisDeb -1, intJourDeb);
        DateFin  = new Date(intAnneeFin, intMoisFin -1, intJourFin);
        var one_day=1000*60*60*24
        DateDiff = Math.ceil((DateFin.getTime()-DateDeb.getTime())/(one_day)) + 1;

//Calculate difference btw the two dates, and convert to days
//document.write(Math.ceil((today.getTime()-startingdate.getTime())/(one_day))+
//" days has gone by since JavaScriptKit.com started!")

        if ( DateDiff < 3 ){
    	    document.form_commander.anneeD.focus();
    	    alert('La durée de la location doit être de 3 jours minimum.');
            return false;
        }

	    if ( ( intDateDeb >= intDateFin ) ){
    	    document.form_commander.anneeD.focus();
    	    alert('La date de fin de la location doit être supérieure à la date de début.');
            return false;
	    }


	    bIsPeriodOk = false;
	    for( i=0;i<aDatesValides.length;i++){
		    if ( intDateDeb >= aDatesValides[i][0] && intDateFin <= aDatesValides[i][1]){
			    bIsPeriodOk = true;
		    }
	    }
    	
	    if ( !bIsPeriodOk )	{
		    document.form_commander.anneeD.focus();
		    alert('Ce vehicule n\'est pas disponible pendant cette période\nVeuillez choisir d\'autres dates.\n' + strDatesValides);
		    return false;
	    }
    	
	    bIsOk = bIsOk & bIsPeriodOk;
					
	    if ( nbVehic > 1 ){
	        if ( bIsOk ){
		        var j=0;
            strVehicPreced = '-';
            for(i=0;i< document.form_commander.elements.length;i++){
			        if ( document.form_commander.elements[i].name == 'vehic_loc[]') {
                j++;
                strCurrentVehic = document.form_commander.elements[i].options[document.form_commander.elements[i].selectedIndex].value;
                if( strCurrentVehic == '' ){
  				        document.form_commander.elements[i].focus();
  				        alert('Veuillez choisir le véhicule ' + j);
  				        return false;
  			        }else{
  			          if (  strVehicPreced.indexOf(strCurrentVehic) >= 0 ){
    				        document.form_commander.elements[i].focus();
      	            alert('Veuillez choisir des véhicules différents');
      	            return false;
  			          }
  			          strVehicPreced += strCurrentVehic + '-';
  			        }
			        }
		        }
	        }
	    } //Fin if ( count($array_ListVehicLoc) > 1 )
    } //Fin if ( $tab == "l" )
    //!Check LOCATIONS
    /////////////////////////////////////////////////////////////////////////////////////////////



		
	//if ( bIsOk ) document.form_commander.submit();

    btReservLoad('load');
    strpost = getFormString(document.form_commander);
    var url="commander_coordonnees.php";
    ajax_postForm(url, strpost, commander_coordonneesChanged);
}

function commander_coordonneesChanged(){
    var oDivCommander = document.getElementById('resa_commander');
    var oDivCoordonnes = document.getElementById('resa_coordonnees');
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
        if ( xmlHttp.status != "200" ){
            alert("Une erreur est survenue, veuillez essayer ultérieurement ou nous contacter par téléphone.");
        }else{
            goTopCommand();
            if ( xmlHttp.responseText.length > 0 ){
                if ( xmlHttp.responseText.indexOf('<<LOG_ERROR>>') >= 0 ){
                    alert('Une erreur est survenue, veuillez essayer ultérieurement ou nous contacter par téléphone.');
                }else{
                    if ( oDivCoordonnes != null ) {
                        oDivCoordonnes.style.display = '';
                        oDivCommander.style.display = 'none';
                        oDivCoordonnes.innerHTML=xmlHttp.responseText;
                    }
                }
            }else{
                if ( oDivCoordonnes != null ) {
                    oDivCoordonnes.innerHTML='';
                    oDivCoordonnes.style.display = 'none';
                    oDivCommander.style.display = '';
                }
            }
        }
        btReservLoad('')
    } 
}


function commander_coord_valider(nbrepassMax){
	bIsOk = true;
    //+Check Passsagers
    //S il y a possibilite de saisir plus d 1 passager
    if ( parseInt(nbrepassMax) > 0 ){
	    for(i=0;i<document.getElementsByName('nom_passager[]').length;i++){
		    if ( ( document.getElementsByName('nom_passager[]')[i].value != '' && document.getElementsByName('prenom_passager[]')[i].value == '' ) || ( document.getElementsByName('nom_passager[]')[i].value == '' && document.getElementsByName('prenom_passager[]')[i].value != '' ) ){
                alert('Veuillez saisir le nom et le prénom du passager '+(i+1));
                return false;
                break;
		    }
	    } 
    }
    //!Check Passsagers
    
	with( document.form_commander_coord ){
		if (nom_pilote.value==""){
		     alert ("Veuillez saisir:\n le nom du conducteur");
		     nom_pilote.focus();
		     return false;
		}
		if (prenom_pilote.value==""){
			 alert ("Veuillez saisir:\n le prénom du conducteur");
			 prenom_pilote.focus();
			 return false;
		 }
		 
		if (adresse.value==""){
            alert ("Veuillez saisir:\nAdresse de la personne effectuant la réservation");
            adresse.focus();
            return false;
		}
		if (codepostal.value==""){
            alert ("Veuillez saisir:\nle code postal de la personne effectuant la réservation");
            codepostal.focus();
            return false;
        }
		if (ville.value==""){
            alert ("Veuillez saisir:\nla ville de la personne effectuant la réservation");
            ville.focus();
            return false;
        }
		// recherche du pays selectionné
		if ( pays.options[pays.selectedIndex].value == "" ){
			alert ("Veuillez sélectionner votre pays");
			pays.focus();
			return false;
		}
		if (tel_dom.value=="" && tel_trav.value=="" && tel_port.value==""){
			alert ("Veuillez saisir:\nun numéro de téléphone");
			tel_dom.focus();
			return false;
		}
		if (email.value==""){
			alert ("Veuillez saisir:\nune adresse E-mail");
			email.focus();
			return false;
		}
		if(!check_email(email.value)){
			alert ("Veuillez vérifier votre adresse E-mail");
			email.focus();
			return false;
		}
		//if ( bIsOk ) submit();
	}

    /*
    btReservLoad('load');
    strpost = getFormString(document.form_commander);
    var url="commander_coordonnees.php";
    ajax_postForm(url, strpost, commander_coordonneesChanged);
    */
    goTopCommand();
    btReservLoad('load')
    var oDivCoordonnees = document.getElementById('resa_coordonnees');
    var oDivPrestas = document.getElementById('resa_prestations');
    if ( oDivCoordonnees != null ) oDivCoordonnees.style.display = 'none';
    if ( oDivPrestas != null ) oDivPrestas.style.display = '';
    btReservLoad('')
   
}

function commander_presta_valider(){
    btReservLoad('load');
    strpost = getFormString(document.form_commander_coord);
    var url="commander_confirmation.php";
    ajax_postForm(url, strpost, commander_confirmationChanged);
}

function commander_confirmationChanged(){
    var oDivPrestas = document.getElementById('resa_prestations');
    var oDivConfirmation = document.getElementById('resa_confirmation');
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
        if ( xmlHttp.status != "200" ){
            alert("Une erreur est survenue, veuillez essayer ultérieurement ou nous contacter par téléphone.");
        }else{
            goTopCommand();
            if ( xmlHttp.responseText.length > 0 ){
                if ( xmlHttp.responseText.indexOf('<<LOG_ERROR>>') >= 0 ){
                    alert('Une erreur est survenue, veuillez essayer ultérieurement ou nous contacter par téléphone.');
                }else{
                    if ( oDivConfirmation != null ) {
                        oDivConfirmation.style.display = '';
                        oDivPrestas.style.display = 'none';
                        oDivConfirmation.innerHTML=xmlHttp.responseText;
                    }
                }
            }else{
                if ( oDivConfirmation != null ) {
                    oDivConfirmation.innerHTML='';
                    oDivConfirmation.style.display = 'none';
                    oDivPrestas.style.display = '';
                }
            }
        }
        btReservLoad('')
    } 
}

function commander_modifier_commande(){
    var oDivConfirmation = document.getElementById('resa_confirmation');
    var oDivCommander = document.getElementById('resa_commander');
    oDivConfirmation.innerHTML='';
    oDivConfirmation.style.display = 'none';
    oDivCommander.style.display = '';
}

function commander_modifier_coord(){
    var oDivConfirmation = document.getElementById('resa_confirmation');
    var oDivCoordonnees = document.getElementById('resa_coordonnees');
    oDivConfirmation.innerHTML='';
    oDivConfirmation.style.display = 'none';
    oDivCoordonnees.style.display = '';
}

function commander_confirm_valider(){
    if ( !document.form_commander_confirm.accord.checked ){
        alert("Vous devez certifier avoir pris connaissance des \nConditions Générales et Particulières de Vente de Voyages")
    }else{
        btReservLoad('load');
        strpost = getFormString(document.form_commander_confirm);
        var url="commander_reglement.php";
        ajax_postForm(url, strpost, commander_reglementChanged);
    }
}

function commander_reglementChanged(){
    var oDivConfirmation = document.getElementById('resa_confirmation');
    var oDivReglement = document.getElementById('resa_reglement');
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
        if ( xmlHttp.status != "200" ){
            alert("Une erreur est survenue, veuillez essayer ultérieurement ou nous contacter par téléphone.");
        }else{
            goTopCommand();
            if ( xmlHttp.responseText.length > 0 ){
                if ( xmlHttp.responseText.indexOf('<<LOG_ERROR>>') >= 0 ){
                    alert('Une erreur est survenue, veuillez essayer ultérieurement ou nous contacter par téléphone.');
                }else{
                    if ( oDivReglement != null ) {
                        oDivReglement.style.display = '';
                        oDivConfirmation.style.display = 'none';
                        oDivReglement.innerHTML=xmlHttp.responseText;
                    }
                }
            }else{
                if ( oDivReglement != null ) {
                    oDivReglement.innerHTML='';
                    oDivReglement.style.display = 'none';
                    oDivConfirmation.style.display = '';
                }
            }
        }
        btReservLoad('')
    } 
}


function getFormString(obj) {
    var getstr = "";
    for (i=0; i<obj.getElementsByTagName("input").length; i++) {
        if (obj.getElementsByTagName("input")[i].type == "text" || obj.getElementsByTagName("input")[i].type == "hidden") {
           getstr += escape(obj.getElementsByTagName("input")[i].name) + "=" + 
                   escape(obj.getElementsByTagName("input")[i].value) + "&";
        }
        if (obj.getElementsByTagName("input")[i].type == "checkbox") {
           if (obj.getElementsByTagName("input")[i].checked) {
              getstr += obj.getElementsByTagName("input")[i].name + "=" + 
                   escape(obj.getElementsByTagName("input")[i].value) + "&";
           }
        }
        if (obj.getElementsByTagName("input")[i].type == "radio") {
           if (obj.getElementsByTagName("input")[i].checked) {
              getstr += escape(obj.getElementsByTagName("input")[i].name) + "=" + 
                   escape(obj.getElementsByTagName("input")[i].value) + "&";
           }
        }  
        if (obj.getElementsByTagName("input")[i].tagName == "select") {
            var sel = obj.getElementsByTagName("input")[i];
            getstr += escape(sel.name) + "=" + escape(sel.options[sel.selectedIndex].value) + "&";
        }
    }
    for (i=0; i<obj.getElementsByTagName("select").length; i++) {
            var sel = obj.getElementsByTagName("select")[i];
            getstr += escape(sel.name) + "=" + escape(sel.options[sel.selectedIndex].value) + "&";
    }
    for (i=0; i<obj.getElementsByTagName("textArea").length; i++) {
        getstr += escape(obj.getElementsByTagName("textArea")[i].name) + "=" + 
        escape(obj.getElementsByTagName("textArea")[i].value) + "&";
    }
  return getstr;
}

function ajax_postForm(url, strpost, ofunction){
 	//alert(url);
 	//alert(strpost);
 	xmlHttp = GXmlHttp.create();
    if (xmlHttp==null){
        alert ("Une erreur est survenue, veuillez essayer ultérieurement ou nous contacter par téléphone.");
        return
    }
    xmlHttp.onreadystatechange=ofunction;
    xmlHttp.open("POST",url,true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    //xmlHttp.setRequestHeader("Content-Encoding", "utf-8");
    //alert(strpost);
    xmlHttp.send(strpost);
}

/*!RESERVATION*/

/*SUR MESURE*/
function CheckForm_sur_mesure_old(){
   
	bisOk = true;
	var isLocMoto = false;
	var isLocAuto = false;
	
	document.form_sur_mesure.isLocMoto.value = 0;
	if ( document.form_sur_mesure.motoAge.value != '' 
		|| document.form_sur_mesure.motoJours.value != '' 
		|| document.form_sur_mesure.motoDepart.value != '' 
		|| document.form_sur_mesure.motoRetour.value != '' 
		|| document.form_sur_mesure.typeMoto.value != ''  ){
		isLocMoto = true;
		document.form_sur_mesure.isLocMoto.value = 1;
	}

	document.form_sur_mesure.isLocAuto.value = 0;
	if ( document.form_sur_mesure.autoAge.value != '' 
		|| document.form_sur_mesure.autoJours.value != '' 
		|| document.form_sur_mesure.autoDepart.value != '' 
		|| document.form_sur_mesure.autoRetour.value != '' ){
		isLocAuto = true;
		document.form_sur_mesure.isLocAuto.value = 1;
	}

  if (document.form_sur_mesure.prenom.value=='' && bisOk )  { alert('Veuillez saisir votre prénom.'); bisOk = false;document.form_sur_mesure.prenom.focus();  }
  if (document.form_sur_mesure.nom.value=='' && bisOk )  { alert('Veuillez saisir votre nom.'); bisOk = false;document.form_sur_mesure.nom.focus();  }
  if (document.form_sur_mesure.adr1.value=='' && bisOk )  { alert('Veuillez saisir votre adresse.'); bisOk = false;document.form_sur_mesure.adr1.focus();  }
  if (document.form_sur_mesure.cpostal.value=='' && bisOk )  { alert('Veuillez saisir votre code postal.'); bisOk = false;document.form_sur_mesure.cpostal.focus();  }
  if (document.form_sur_mesure.ville.value=='' && bisOk )  { alert('Veuillez saisir votre ville.'); bisOk = false;document.form_sur_mesure.ville.focus();  }
  if (document.form_sur_mesure.email.value=='' && bisOk )  { alert('Veuillez saisir votre email.'); bisOk = false;document.form_sur_mesure.email.focus();  }
  if ( document.form_sur_mesure.search_engine.selectedIndex == 0  && bisOk  )  { alert('Veuillez saisir le nom du moteur de recherche.'); bisOk = false;document.form_sur_mesure.search_engine.focus();  }
  if ( document.form_sur_mesure.budget.selectedIndex == 0 && bisOk  )  { alert('Veuillez saisir le budget par personne pour ce voyage.'); bisOk = false;document.form_sur_mesure.budget.focus();  }
  if (!check_email(document.form_sur_mesure.email.value)  && bisOk )  { alert('Veuillez saisir correctement votre email.'); bisOk = false;document.form_sur_mesure.email.focus();  }
  if (( (document.form_sur_mesure.personnesAdultes.value == '' && document.form_sur_mesure.personnesEnfants.value == '') || (isNaN(document.form_sur_mesure.personnesAdultes.value) && document.form_sur_mesure.personnesEnfants.value == '') || (isNaN(document.form_sur_mesure.personnesEnfants.value) && document.form_sur_mesure.personnesAdultes.value == '') ) && bisOk )  { alert('Veuillez saisir correctement le nombre de personnes.'); bisOk = false;document.form_sur_mesure.personnesAdultes.focus();  }
  if (isLocMoto && document.form_sur_mesure.motoAge.value ==  '' && bisOk )  { alert('Veuillez saisir l âge du pilote de la moto.'); bisOk = false;document.form_sur_mesure.motoAge.focus();  }
  if (isLocMoto && document.form_sur_mesure.motoJours.value ==  '' && bisOk )  { alert('Veuillez saisir le nombre de jour de location moto..'); bisOk = false;document.form_sur_mesure.motoJours.focus();  }
  if (isLocMoto && document.form_sur_mesure.motoDepart.value ==  '' && bisOk )  { alert('Veuillez saisir la ville de départ de la location moto.'); bisOk = false;document.form_sur_mesure.motoDepart.focus();  }
  if (isLocMoto && document.form_sur_mesure.motoRetour.value ==  '' && bisOk )  { alert('Veuillez saisir la ville de retour de la location moto.'); bisOk = false;document.form_sur_mesure.motoRetour.focus();  }
  if (isLocAuto && document.form_sur_mesure.autoAge.value ==  '' && bisOk )  { alert('Veuillez saisir l âge du pilote de la auto.'); bisOk = false;document.form_sur_mesure.autoAge.focus();  }
  if (isLocAuto && document.form_sur_mesure.autoJours.value ==  '' && bisOk )  { alert('Veuillez saisir le nombre de jour de location auto..'); bisOk = false;document.form_sur_mesure.autoJours.focus();  }
  if (isLocAuto && document.form_sur_mesure.autoDepart.value ==  '' && bisOk )  { alert('Veuillez saisir la ville de départ de la location auto.'); bisOk = false;document.form_sur_mesure.autoDepart.focus();  }
  if (isLocAuto && document.form_sur_mesure.autoRetour.value ==  '' && bisOk )  { alert('Veuillez saisir la ville de retour de la location auto.'); bisOk = false;document.form_sur_mesure.autoRetour.focus();  }
  if (document.form_sur_mesure.transportDepart.value=='' && bisOk )  { alert('Veuillez saisir la ville de départ du transport aérien.'); bisOk = false;document.form_sur_mesure.transportDepart.focus();  }
  if (document.form_sur_mesure.transportRetour.value=='' && bisOk )  { alert('Veuillez saisir la ville de retour du transport aérien.'); bisOk = false;document.form_sur_mesure.transportRetour.focus();  }
  if (document.form_sur_mesure.hotelSingle.value == '' && document.form_sur_mesure.hotelDouble.value == '' && document.form_sur_mesure.hotelTriple.value == '' && document.form_sur_mesure.hotelQuadruple.value == ''  && bisOk )  { alert('Veuillez saisir le nbre de chambres.'); bisOk = false;document.form_sur_mesure.hotelSingle.focus();  }
  if (document.form_sur_mesure.hotelNuits.value=='' && bisOk )  { alert('Veuillez saisir le nombre de nuits d hôtel.'); bisOk = false;document.form_sur_mesure.hotelNuits.focus();  }
  
  
  return bisOk;
  
}


function CheckForm_sur_mesure(){
   
	bisOk = true;
	var isLoc = false;

  if ( 	document.form_sur_mesure.loc_nbjours.value || document.form_sur_mesure.loc_depart.value || document.form_sur_mesure.loc_retour.value )
  {
    isLoc = true;
  }

  if (document.form_sur_mesure.prenom.value=='' && bisOk )  { alert('Veuillez saisir votre prénom.'); bisOk = false;document.form_sur_mesure.prenom.focus();  }
  if (document.form_sur_mesure.nom.value=='' && bisOk )  { alert('Veuillez saisir votre nom.'); bisOk = false;document.form_sur_mesure.nom.focus();  }
  if (document.form_sur_mesure.adr1.value=='' && bisOk )  { alert('Veuillez saisir votre adresse.'); bisOk = false;document.form_sur_mesure.adr1.focus();  }
  if (document.form_sur_mesure.cpostal.value=='' && bisOk )  { alert('Veuillez saisir votre code postal.'); bisOk = false;document.form_sur_mesure.cpostal.focus();  }
  if (document.form_sur_mesure.ville.value=='' && bisOk )  { alert('Veuillez saisir votre ville.'); bisOk = false;document.form_sur_mesure.ville.focus();  }
  if (document.form_sur_mesure.email.value=='' && bisOk )  { alert('Veuillez saisir votre email.'); bisOk = false;document.form_sur_mesure.email.focus();  }
  if (!check_email(document.form_sur_mesure.email.value)  && bisOk )  { alert('Veuillez saisir correctement votre email.'); bisOk = false;document.form_sur_mesure.email.focus();  }
  if ( document.form_sur_mesure.search_engine.selectedIndex == 0  && bisOk  )  { alert('Veuillez saisir le nom du moteur de recherche.'); bisOk = false;document.form_sur_mesure.search_engine.focus();  }
  if ( document.form_sur_mesure.budget.selectedIndex == 0 && bisOk  )  { alert('Veuillez saisir le budget par personne pour ce voyage.'); bisOk = false;document.form_sur_mesure.budget.focus();  }
  if (( (document.form_sur_mesure.personnesAdultes.value == '' && document.form_sur_mesure.personnesEnfants.value == '') || (isNaN(document.form_sur_mesure.personnesAdultes.value) && document.form_sur_mesure.personnesEnfants.value == '') || (isNaN(document.form_sur_mesure.personnesEnfants.value) && document.form_sur_mesure.personnesAdultes.value == '') ) && bisOk )  { alert('Veuillez saisir correctement le nombre de personnes.'); bisOk = false;document.form_sur_mesure.personnesAdultes.focus();  }
  if (isLoc && document.form_sur_mesure.type_loc.selectedIndex ==  0 && bisOk )  { alert('Veuillez choisir une type de location.'); bisOk = false;document.form_sur_mesure.type_loc.focus();  }
  
  
  return bisOk;
  
}

function sur_mesure_valider_old(){
    if ( CheckForm_sur_mesure() ) {
      btReservLoad('load');
      strpost = getFormString(document.form_sur_mesure);
      var url="voyage_sur_mesure_confirmation.php";
      ajax_postForm(url, strpost, sur_mesure_confirmationChanged);
    }
}

function sur_mesure_valider(){
    if ( CheckForm_sur_mesure() ) {
      btReservLoad('load');
      strpost = getFormString(document.form_sur_mesure);
      var url="voyage_sur_mesure_confirmation.php";
      ajax_postForm(url, strpost, sur_mesure_confirmationChanged);
    }
}

function sur_mesure_confirmationChanged(){
    var oDiv = document.getElementById('div_formulaire_sur_mesure');
    var oDivValider = document.getElementById('div_valider');
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
        if ( xmlHttp.status != "200" ){
            alert("Une erreur est survenue, veuillez essayer ultérieurement ou nous contacter par téléphone.");
        }else{
            if ( xmlHttp.responseText.length > 0 ){
                if ( xmlHttp.responseText.indexOf('<<LOG_ERROR>>') >= 0 ){
                    alert('Une erreur est survenue, veuillez essayer ultérieurement ou nous contacter par téléphone.');
                }else if ( oDiv != null ) {
                  oDiv.innerHTML=xmlHttp.responseText;
                  oDivValider.style.display = 'none';
                }
            }
        }
        btReservLoad('')
    } 
}

/*LOCATIONS*/

function locations_choose_station(){
    var oDivStation = document.getElementById('div_locations_station');
    var oDivVehic = document.getElementById('div_locations_vehicule');
    with(document.formulaire_stations){
        if (listestations.options[listestations.selectedIndex].value != ''){
            //alert(listestations.options[listestations.selectedIndex].value)
            strValues2Open = listestations.options[listestations.selectedIndex].value;
            var arrayValues = strValues2Open.split('#');
            //alert(arrayValues[3]);
            strpost = 'typeid='+arrayValues[2]+'&idstation='+arrayValues[3];
            var url="locations_stations.php";
            ajax_postForm(url, strpost, locations_Changed_station);
        }else{
            if ( oDivVehic != null) oDivVehic.innerHTML = '';
            if ( oDivStation != null) oDivStation.innerHTML = '';
        }
    }
}
function locations_choose_vehicule(idstation, idvehicule){
    strpost = 'idstation='+idstation+'&idvehicule='+idvehicule;
    var url="locations_vehicule.php";
    ajax_postForm(url, strpost, locations_Changed_vehicule);
}

function locations_Changed_station(mode){
    locations_Changed('station');
}
function locations_Changed_vehicule(mode){
    locations_Changed('vehicule');
}
function locations_Changed(mode){
    switch(mode){
      case 'station':
        var oDivA = document.getElementById('div_locations_station');
        var oDivB = document.getElementById('div_locations_vehicule');
      break;
      case 'vehicule':
        var oDivA = document.getElementById('div_locations_vehicule');
        var oDivB = document.getElementById('div_locations_station');
      break;
    }
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
        if ( xmlHttp.status != "200" ){
            alert("Une erreur est survenue, veuillez essayer ultérieurement ou nous contacter par téléphone.");
        }else{
            if ( xmlHttp.responseText.length > 0 ){
                if ( xmlHttp.responseText.indexOf('<<LOG_ERROR>>') >= 0 ){
                    alert('Une erreur est survenue, veuillez essayer ultérieurement ou nous contacter par téléphone.');
                }else if ( oDivA != null && oDivB != null) {
                  oDivB.style.display = 'none';
                  oDivA.innerHTML=xmlHttp.responseText;
                  oDivA.style.display = '';
                }
            }
        }
    } 
}

function location_display(mode){
  var oDivVehicule = document.getElementById('div_locations_vehicule');
  var oDivStation = document.getElementById('div_locations_station');
  var oDivSpecs = document.getElementById('div_locations_specs');
  var oDivTarifs = document.getElementById('div_locations_tarifs');
  var oButtonSpec = document.getElementById('bt_loc_fichetech');
  var oButtonSpecOn = document.getElementById('bt_loc_fichetech_on');
  var oButtonTarif = document.getElementById('bt_loc_tarifsresa');
  var oButtonTarifOn = document.getElementById('bt_loc_tarifsresa_on');
  
  
  switch(mode){
    case 'station':
      oDivVehicule.style.display = 'none';
      oDivVehicule.innerHTML = '';
      oDivStation.style.display = '';
    break;
    case 'specs':
      oDivTarifs.style.display = 'none';
      oDivSpecs.style.display = '';
      oButtonSpec.style.display = 'none';
      oButtonSpecOn.style.display = '';
      oButtonTarif.style.display = '';
      oButtonTarifOn.style.display = 'none';
    break;
    case 'tarifs':
      oDivTarifs.style.display = '';
      oDivSpecs.style.display = 'none';
      oButtonSpec.style.display = '';
      oButtonSpecOn.style.display = 'none';
      oButtonTarif.style.display = 'none';
      oButtonTarifOn.style.display = '';
    break;
  }

}

function locations_reserver(typeloc, idstations, idvehicules){
 // $tab == 'l' && $typeloc != "" && intval($idstations) > 0 && intval($idvehicules) 
    btReservLoad('load');
    strpost = 'tab=l&typeloc='+typeloc+'&idstations='+idstations+'&idvehicules='+idvehicules;
    var url="commander.php";
    //alert(strpost);
    ajax_postForm(url, strpost, locations_reserverChanged);
}

function locations_reserverChanged(){ 
    var oDivLocation = document.getElementById('tarifs_detail');
    var oDivResa = document.getElementById('resa_commander');
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
        //alert('ok 2');
        if ( xmlHttp.status != "200" ){
            alert("Une erreur est survenue, veuillez essayer ultérieurement ou nous contacter par téléphone.");
        }else{
            goTopCommand();
            if ( xmlHttp.responseText.length > 0 ){
                //alert('ok 3');
                if ( xmlHttp.responseText.indexOf('<<LOG_ERROR>>') >= 0 ){
                    alert('Une erreur est survenue, veuillez essayer ultérieurement ou nous contacter par téléphone.');
                }else{
                    if ( oDivResa != null ) {
                        oDivResa.style.display = '';
                        oDivLocation.style.display = 'none';
                        oDivResa.innerHTML=xmlHttp.responseText;
                    }
                }
            }else{
                if ( oDivResa != null ) {
                    oDivResa.innerHTML='';
                    oDivResa.style.display = 'none';
                    oDivLocation.style.display = '';
                }
            }
        }
        btReservLoad('');
    } 
}

function showCondition(){
	oDiv = document.getElementById('div_cgv');
	if ( oDiv == null ) return;
	docjslib_getRealTop(oLink);
	oMap.style.top = (yPos  - ( parseInt(oDiv.style.height.replace('px','')) ) -20)+'px';; 
	oMap.style.display = '';


}


function CheckDate(d) {
  // Cette fonction vérifie le format JJ/MM/AAAA saisi et la validité de la date.
  // Le séparateur est défini dans la variable separateur
  var amin=1900; // année mini
  var amax=2050; // année maxi
  var separateur="/"; // separateur entre jour/mois/annee
  var j=(d.substring(0,2));
  var m=(d.substring(3,5));
  var a=(d.substring(6));
  var ok=1;
  if ( ((isNaN(j))||(j<1)||(j>31)) && (ok==1) ) {
     ok=0;
  }
  if ( ((isNaN(m))||(m<1)||(m>12)) && (ok==1) ) {
     ok=0;
  }
  if ( ((isNaN(a))||(a<amin)||(a>amax)) && (ok==1) ) {
     ok=0;
  }
  if ( ((d.substring(2,3)!=separateur)||(d.substring(5,6)!=separateur)) && (ok==1) ) {
     ok=0;
  }
  if (ok==1) {
     var d2=new Date(a,m-1,j);
     j2=d2.getDate();
     m2=d2.getMonth()+1;
     a2=d2.getFullYear();
     if (a2<=100) {a2=1900+a2}
     if ( (j!=j2)||(m!=m2)||(a!=a2) ) {
        ok=0;
     }
  }
  return ok;
}


//Ouvre Un popup
function popup(url, w, h, sc) {
    (window.open(url, '', 'resizable=no,scrollbars=' + sc + ',menubar=no,width=' + w + ',height=' + h)).focus();
}

function popupname(url,name, w, h, sc){
    (window.open(url, name, 'resizable=no,scrollbars=' + sc + ',menubar=no,width=' + w + ',height=' + h)).focus();
}

var mapHotel;
var minLat = 3000;
var minLng = 3000;
var maxLat = -3000;
var maxLng = -3000;
var vZommStart = 8;

function hotel_postChanged(){ 
    var oDiv = document.getElementById(divToDisplay);
    //alert(divToDisplay);
    //alert(oDiv);
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
        //alert('ok 2');
        if ( xmlHttp.status != "200" ){
            alert("Une erreur est survenue, veuillez essayer ulterieurement.");
        }else{
            //alert('xmlHttp.readyState\n' + xmlHttp.readyState);
            ///alert('xmlHttp.status\n' + xmlHttp.status);
            if ( xmlHttp.responseText.length > 0 ){
                //alert('ok 3');
                if ( xmlHttp.responseText.indexOf('<<LOG_ERROR>>') >= 0 ){
                    //alert('Une erreur est survenue, veuillez essayer ulterieurement.');
                }else{
                    if ( oDiv != null ) {
                        //alert('ok 4');
                        //alert('xmlHttp.responseText\n' + xmlHttp.responseText);
                        oDiv.innerHTML=xmlHttp.responseText;
                        //mapHotel google
                        if (GBrowserIsCompatible()) { 
                            // Display the mapHotel, with some controls and set the initial location 
                            var oInputLat = document.getElementById('hotel_map_lat');
                            var oInputLng = document.getElementById('hotel_map_lng');
                            var nZoomLevel = 0; //0: point; 1: trajet
                            mapHotel = new GMap2(document.getElementById("map_hotel"));
                            mapHotel.addControl(new GSmallMapControl());
                            mapHotel.addControl(new GMapTypeControl());
                            /*
                            var panoCoords = new GLatLng(oInputLat.value,oInputLng.value);
                            panoramaOptions = { latlng:panoCoords };
                            myPano = new GStreetviewPanorama(document.getElementById("pano_hotel"), panoramaOptions);
                            GEvent.addListener(myPano, "error", handleNoFlash);
                            */
                            /*Centrage pays*/
                            var nompays = document.getElementById('hotel_nompays').value;
                    		if (nompays.length > 0 ){
                    		    var geocoder = new GClientGeocoder();
                    		    geocoder.getLocations(nompays, function addToMap(response){	
                    			    if (response.Placemark){	
                    				    place = response.Placemark[0];
                                        //mapHotel.setCenter(place.Point, 3);
                                        mapHotel.setCenter(new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]), 3);
                    			    }
                    			});
                    	    }else{
                                mapHotel.setCenter(new GLatLng(37.09023980307208, -95.712890625), 3);
                    	    }
                            
                            var bounds = null; 
                            // assign this somewhere 
                            bounds = new GLatLngBounds(); 
                            var minLat = 3000;
                            var minLng = 3000;
                            var maxLat = -3000;
                            var maxLng = -3000;
                            
                            var vZommStart = 8;
                       
                            GEvent.addListener(mapHotel, 'load', function() { 
                                displayMapPointHotel();
                            });
                            //displayMapPoint();
                        }
                        
                        // display a warning if the browser was not compatible
                        else {
                          alert("Sorry, the Google Maps API is not compatible with this browser");
                        }
                    }
                }
            }
        }
    } 
}

function displayMapPointHotel(){
    var oInputLat = document.getElementById('hotel_map_lat');
    var oInputLng = document.getElementById('hotel_map_lng');
    if ( oInputLat != null && oInputLng != null ){
        nZoomLevel = 0;
        mapHotel.clearOverlays();
        var vLat = oInputLat.value;
        var vLng = oInputLng.value;
        createMarkerHotel(new GLatLng(vLat, vLng), null, true);
    }
}

// A function to create the marker and set up the event window
function createMarkerHotel(point, iconeImage, isdraggable ) {
    vZoom = mapHotel.getZoom();
    if ( vZoom < vZommStart ) vZoom = vZommStart;
    var marker = new GMarker(point, {draggable: true});
    if ( isdraggable ) {
        GEvent.addListener(marker, 'dragend', function(point) { 
            if (point) {
                if ( oInputLat != null && oInputLng != null) { 
                    oInputLat.value = point.lat(); 
                    oInputLng.value = point.lng(); 
                }
                if ( nZoomLevel == 0 ) {
                    mapHotel.setCenter(point, vZoom);
                }else{
                  displayMapLarge();  
                }
            }
        });
    }
    mapHotel.addOverlay(marker);
    if ( iconeImage != null && iconeImage.length > 0 ) marker.setImage(iconeImage);
    var bounds = new GLatLngBounds(point, point); 
    mapHotel.setCenter(point, vZoom);
    //return marker;
}



function focusPass(strValue){
	odivPassA = document.getElementById('divPassA')
	odivPassB = document.getElementById('divPassB')
	if (strValue=='Mot de passe'){
		odivPassA.style.display='none';
		odivPassB.style.display='';
		document.frmLog.elements['pass'].focus();
	}
}

function logoff(){
	document.frmlogoff.submit();
}


function displayPanoHotel(){
    oDivPano = document.getElementById('pano_hotel');
    oGMap = document.getElementById('map_hotel');
    var oInputLat = document.getElementById('hotel_map_lat');
    var oInputLng = document.getElementById('hotel_map_lng');
    var svc = new GStreetviewClient();
    point1 = new GLatLng(oInputLat.value, oInputLng.value)
    svc.getNearestPanoramaLatLng(point1, function(point2) {
      if (point2) {
            var panoCoords = new GLatLng(oInputLat.value,oInputLng.value);
            panoramaOptions = { latlng:panoCoords };
            myPano = new GStreetviewPanorama(oDivPano, panoramaOptions);
            oDivPano.style.display = 'block';
            oGMap.style.display = 'none';
            document.getElementById('lnk_PanoHotel').style.display='none';
            document.getElementById('lnk_CarteHotel').style.display='block';
      } else {
        alert('Panorama non disponible à cette adresse');
        oDivPano.style.display = 'none';
        oGMap.style.display = 'block';
        document.getElementById('lnk_PanoHotel').style.display='block';
        document.getElementById('lnk_CarteHotel').style.display='none';
      }
    });
}

function displayCarteHotel(){
    document.getElementById('pano_hotel').style.display = 'none';
    document.getElementById('map_hotel').style.display = 'block';
    document.getElementById('lnk_PanoHotel').style.display='block';
    document.getElementById('lnk_CarteHotel').style.display='none';
    
}

