// JavaScript Document
    function setasHome() {
        window.open('/sethomepage.php', 'sethomeapge', 'height=470,width=550,status=yes,toolbar=no,menubar=no,location=no');
    }
    function Tellafriend() {
        window.open('/tellafriend.php?referer='+document.location, 'tellafriend', 'height=460,width=400,status=yes,toolbar=no,menubar=no,location=no');
    }
    function favoris(url,desc) {
        if ( navigator.appName != 'Microsoft Internet Explorer' )
            window.sidebar.addPanel(desc,url,"");
        else
            window.external.AddFavorite(url,desc);
    }


$(document).ready(function(){
    // Action event on link to display iframe
    if ($('#a-hotel')) {
        $('#a-hotel').click(function () {
            // Tabs
            $("#li-hotel").addClass('on');
            $("#li-flight").removeClass('on');
            $("#li-car").removeClass('on');
            $("#li-cruise").removeClass('on');

            // iFrame
            $("#i017").show();
            $("#i015").hide();
            $("#i016").hide();
            $("#i018").hide();

            return false;
        });
    }

    if ($('#a-flight')) {
        $('#a-flight').click(function () {
            // Tabs
            $("#li-hotel").removeClass('on');
            $("#li-flight").addClass('on');
            $("#li-car").removeClass('on');
            $("#li-cruise").removeClass('on');

            // iFrame
            $("#i017").hide();
            $("#i015").show();
            $("#i016").hide();
            $("#i018").hide();
            return false;
        });
    }

    if ($('#a-car')) {
        $('#a-car').click(function () {
            // Tabs
            $("#li-hotel").removeClass('on');
            $("#li-flight").removeClass('on');
            $("#li-car").addClass('on');
            $("#li-cruise").removeClass('on');

            // iFrame
            $("#i017").hide();
            $("#i015").hide();
            $("#i016").show();
            $("#i018").hide();

            return false;
        });
    }

    if ($('#a-cruise')) {
        $('#a-cruise').click(function () {
            // Tabs
            $("#li-hotel").removeClass('on');
            $("#li-flight").removeClass('on');
            $("#li-car").removeClass('on');
            $("#li-cruise").addClass('on');

            // iFrame
            $("#i017").hide();
            $("#i015").hide();
            $("#i016").hide();
            $("#i018").show();

            return false;
        });
    }

// HOTELS

    // Calendar
    if ($('#rs_chk_in').length>0 && $('#rs_chk_out').length>0) {
        $("#rs_chk_in,#rs_chk_out").datepicker({
            beforeShow: customRangeHotel,
            showOn: "both",
            buttonImage: "/images/booking/calendar.gif",
            buttonImageOnly: true
        });
    }

// FLIGHTS
    // Calendar
    if ($('#rs_chk_in2').length>0 && $('#rs_chk_out2').length>0) {
        $("#rs_chk_in2,#rs_chk_out2").datepicker({
            beforeShow: customRangeFlight,
            showOn: "both",
            buttonImage: "/images/booking/calendar.gif",
            buttonImageOnly: true
        });
    }
    // City autocompletion
    if ($("#fl_city1").length>0) {
        $("#fl_city1").autocomplete('/scripts/airport-autocomplete.php', {onItemSelect:selectItemFlightFrom});
    }

// CARS
    // Calendar
    if ($('#rs_chk_in3').length>0 && $('#rs_chk_out3').length>0) {
        $("#rs_chk_in3,#rs_chk_out3").datepicker({
            beforeShow: customRangeCar,
            showOn: "both",
            buttonImage: "/images/booking/calendar.gif",
            buttonImageOnly: true
        });
    }

// CRUISES
    // Calendar
    if ($('#rs_chk_in4').length>0) {
        $("#rs_chk_in4").datepicker({
            beforeShow: customRangeCar,
            showOn: "both",
            buttonImage: "/images/booking/calendar.gif",
            buttonImageOnly: true
        });
    }

// EVENTS
    if ($('#dateFrom').length>0 && $('#dateTo').length>0) {
        $("#dateFrom,#dateTo").datepicker({
            showOn: "both",
            buttonImage: "/images/booking/calendar.gif",
            buttonImageOnly: true
        });
    }

// Quick Search
    if ($('#btn_go_there')) {
        $('#btn_go_there').click(function () {
            if ( $('#q-region').val()!='' ) {
		$.get("/scripts/record-js-click.php?type=city-finder", function(){
                	document.location.href= $('#q-region').val() ;
		});

            }
            else {
                alert('Please select a region and/or a town') ;
            }
            return false;
        });
    }

    if ($('#btn_display-now')) {
        $('#btn_display-now').click(function () {
            var message = '';

            if ($('#activity-list').val()=='')
                message += '\nPlease select a category' ;
            if ($('#location-list').val()=='')
                message += '\nPlease select a location' ;

            if (message=='') {
//                alert('load CAT:'+$('#activity-list').val()+' in LOC:'+$('#location-list').val()) ;

		$.get("/scripts/record-js-click.php?type=show-me", function(){
	                map.clearOverlays() ;
	
	                // Ajout des nouveaux elements
	                GDownloadUrl("/media/xml/ggmap/geocode-directory.php?cat="+$('#activity-list').val()+"&loc="+$('#location-list').val(), function(data) {
	                    if (data!='') {
	                        var xml = GXml.parse(data);
	                        var markers = xml.documentElement.getElementsByTagName("marker");
	
	                        for (var i = 0; i < markers.length; i++) {
	                            var latlng = new GLatLng(parseFloat(markers[i].getAttribute("lat")), parseFloat(markers[i].getAttribute("lng")));
	                            var sUrl = markers[i].getAttribute("url");
	
	                            if (i==0) {
	                                map.panTo(new GLatLng(parseFloat(markers[i].getAttribute("lat")), parseFloat(markers[i].getAttribute("lng"))));
	                            }
	
	                            map.addOverlay(createNewMarker(markerOptionsEstab, latlng, sUrl) );
	                        }
	                    }
	                    else {
	                        alert('Sorry, no listing meet your Criteria') ;
	                    }
	                });
		});
            }
            else {
                alert('Error: '+message) ;
            }
        });
    }
    $('a[@rel*=external]').attr('target', '_blank');
//    externalLink();
});

function updateQuickSearch() {
    // on supprime les elements existants
    if ($("#q-city").lenght>0) {
        $("#q-city").removeOption(/./);

        // On appelle un php pour recuperer les villes
        // du pays selectionne par l'utilisateur
        $.get("/scripts/quick-search.php?region="+$('#q-region').val(), function(data){
            $("#q-city").html(data);
        });
    }
}

function customRangeHotel(input) {
    return {minDate: (input.id == "rs_chk_out" ? $("#rs_chk_in").datepicker("getDate") : null),
        maxDate: (input.id == "rs_chk_in" ? $("#rs_chk_out").datepicker("getDate") : null)};
}

function customRangeFlight(input) {
    return {minDate: (input.id == "rs_chk_out2" ? $("#rs_chk_in2").datepicker("getDate") : null),
        maxDate: (input.id == "rs_chk_in2" ? $("#rs_chk_out2").datepicker("getDate") : null)};
}

function customRangeCar(input) {
    return {minDate: (input.id == "rs_chk_out3" ? $("#rs_chk_in3").datepicker("getDate") : null),
        maxDate: (input.id == "rs_chk_in3" ? $("#rs_chk_out3").datepicker("getDate") : null)};
}

// Call back function for hotel
function selectItemHotel(li) {
    if (li.extra) {
        document.getElementById('ht_origincode').value=li.extra[0];
    }
}

// Call back function for flight from
function selectItemFlightFrom(li) {
    if (li.extra) {
        document.getElementById('fl_origincode').value=li.extra[0];
    }
}

// Call back function for flight to
function selectItemFlightTo(li) {
    if (li.extra) {
        document.getElementById('fl_destinationcode').value=li.extra[0];
    }
}

// Call back function for car
function selectItemCar(li) {
    if (li.extra) {
        document.getElementById('ca_origincode').value=li.extra[0];
    }
}

/*
Function to show/hide return date regarding flight type
Empty return date in all case */
function returnDate(ps_type) {
    if (ps_type=='show') {
        document.getElementById('fl_return').style.display='block' ;
        document.getElementById('rs_chk_out2').value='';
    }
    else {
        document.getElementById('fl_return').style.display='none' ;
        document.getElementById('rs_chk_out2').value='';
    }
}

function sendHotel() {
    var ErrorMessage = '' ;

    if (document.getElementById('ht_city').value=='') {
        ErrorMessage += '\n- Please select a city' ;
    }

    if (document.getElementById('rs_chk_in').value=='') {
        ErrorMessage += '\n- Please select a Check-In date' ;
    }
    if (document.getElementById('rs_chk_out').value=='') {
        ErrorMessage += '\n- Please select a Check-Out date' ;
    }

    if (ErrorMessage!='') {
        alert(ErrorMessage) ;
        return false;
    }

    return true;
}


function sendFlight() {
    var ErrorMessage = '' ;

    if (document.getElementById('fl_city1').value=='') {
        ErrorMessage += '\n- Please select a Departing city' ;
    }

    if (document.getElementById('fl_city2').value=='' ) {
        ErrorMessage += '\n- Please select a Traveling city' ;
    }

    if (document.getElementById('rs_chk_in2').value=='') {
        ErrorMessage += '\n- Please select a Departing Date' ;
    }

    if (document.getElementById('flight_return').checked) {
        if (document.getElementById('rs_chk_out2').value=='') {
            ErrorMessage += '\n- Please select a Return Date' ;
        }
    }

    if (ErrorMessage!='') {
        alert(ErrorMessage) ;
        return false;
    }

    return true;
}

function sendCar() {
    var ErrorMessage = '' ;

    if (document.getElementById('ca_city1').value=='') {
        ErrorMessage += '\n- Please select a Pick-Up City' ;
    }

    if (document.getElementById('rs_chk_in3').value=='') {
        ErrorMessage += '\n- Please select a Pick-Up Date' ;
    }
    if (document.getElementById('rs_chk_out3').value=='') {
        ErrorMessage += '\n- Please select a Drop-Off Date' ;
    }

    if (ErrorMessage!='') {
        alert(ErrorMessage) ;
        return false;
    }

    return true;
}

function sendCruise() {
    var ErrorMessage = '' ;

    if (document.getElementById('cr_city1').value=='') {
        ErrorMessage += '\n- Please select a Destination' ;
    }

    if (document.getElementById('rs_chk_in4').value=='') {
        ErrorMessage += '\n- Please select a Depature Date' ;
    }

    if (ErrorMessage!='') {
        alert(ErrorMessage) ;
        return false;
    }

    return true;
}

