// 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});
    }
    // City autocompletion for Flights Combined with Hotels
    if ($("#fl2_city1").length>0) {
        $("#fl2_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 ($('#eventFrom').length>0 && $('#eventTo').length>0) {
        $("#eventFrom,#eventTo").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" ? null : null)};
}

function customRangeFlight(input) {
    return {minDate: (input.id == "rs_chk_out2" ? $("#rs_chk_in2").datepicker("getDate") : null),
        maxDate: (input.id == "rs_chk_in2" ? null : null)};
}

function customRangeCar(input) {
    return {minDate: (input.id == "rs_chk_out3" ? $("#rs_chk_in3").datepicker("getDate") : null),
        maxDate: (input.id == "rs_chk_in3" ? null : 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];
    }
}

/* Similar to function below, this hides/display any element you send it - CJ 20111020 */
		function showField(field) {
        		document.getElementById(field).style.visibility = 'visible';
        		document.getElementById(field).style.display = 'inline';
		}
		function hideField(field) {
        		document.getElementById(field).style.visibility = 'hidden';
        		document.getElementById(field).style.display = 'none';
		}

// USE THIS FUNCTION TO CLEAR A FIELD IN FORM
		function clearField(form, field) {
			oFormObject = document.forms[form];
			oFormObject.elements[field].value = '';
		}

// USE THIS FUNCTION TO UPDATE A FIELD VALUE IN FORM
		function updateField(form, field, newValue) {
			oFormObject = document.forms[form];
			oFormObject.elements[field].value = newValue;
		}
		
// THIS FUNCTION COPIES VALUE FROM DROPDOWN FOR HOTEL CITY TO THE DROPDOWN OF FLIGHTS CITY IF A USER CLICKS "include flights" ON THE HOTELS & FLIGHTS COMBINED SLUG
		/*function populateCity() {
	        if ( document.getElementById('ht_city').value!='' ) {
		        alert (document.getElementById('fl_city2').value=document.getElementById('ht_city').value;
			}
		}*/

/*
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='';
    }
    if (ps_type=='show') {
        document.getElementById('fl2_return').style.display='block' ;
        document.getElementById('rs_chk_out').value='';
    } else {
        document.getElementById('fl2_return').style.display='none' ;
        document.getElementById('rs_chk_out').value='';
    }
}

function sendHotel() {
    var ErrorMessage = '' ;

	if ( document.getElementById('incFlightsTrue').checked==true ) {
		if (document.getElementById('fl2_city1').value=='') {
			ErrorMessage += '\n- Please select a Departing city' ;
		}
	
		if (document.getElementById('fl2_city2').value=='' ) {
			ErrorMessage += '\n- Please select a Destination city' ;
		}
	
		if (document.getElementById('rs_chk_in').value=='' || document.getElementById('rs_chk_in').value=='mm/dd/yyyy') {
			ErrorMessage += '\n- Please select a Departing Date' ;
		}
	
		if (document.getElementById('flight_return').checked) {
			if (document.getElementById('rs_chk_out').value=='' || document.getElementById('rs_chk_out').value=='mm/dd/yyyy') {
				ErrorMessage += '\n- Please select a Return Date' ;
			}
		}
	} else {
	
		if (document.getElementById('ht_city').value=='') {
			ErrorMessage += '\n- Please select a Destination city' ;
		}
	
		if (document.getElementById('rs_chk_in').value=='' || document.getElementById('rs_chk_in').value=='mm/dd/yyyy') {
			ErrorMessage += '\n- Please select a Check-In date' ;
		}
		if (document.getElementById('rs_chk_out').value=='' || document.getElementById('rs_chk_out').value=='mm/dd/yyyy') {
			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=='' || document.getElementById('rs_chk_in2').value=='mm/dd/yyyy') {
        ErrorMessage += '\n- Please select a Departing Date' ;
    }

    if (document.getElementById('flight_return').checked) {
        if (document.getElementById('rs_chk_out2').value=='' || document.getElementById('rs_chk_out2').value=='mm/dd/yyyy') {
            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=='' || document.getElementById('rs_chk_in3').value=='mm/dd/yyyy') {
        ErrorMessage += '\n- Please select a Pick-Up Date' ;
    }
    if (document.getElementById('rs_chk_out3').value=='' || document.getElementById('rs_chk_out3').value=='mm/dd/yyyy') {
        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;
}

// MOVE ELEMENTS FROM SOURCE DIV TO TARGET DIV - CJ
function moveElements(elementToMove,targetDiv) {
$(elementToMove).appendTo(targetDiv);
}

// FUNCTIONS FOR LOGIN/JOIN/NEWSLETTER TAB BOX - CJ
                function changeClass(fieldName,className) {
                        var e = document.getElementById(fieldName);
                        e.setAttribute("class", className);
                        return;
                }

                function switchTab(tab) {
                        if ( tab == 'login' ) {
                                showField('loginBox');
                                hideField('joinBox');
                                hideField('newsletterBox');
                                changeClass('li-join','off');
                                changeClass('li-newsletter','off');
                                changeClass('li-login','on');
                                return;
                        } else if ( tab == 'join' ) {
                                hideField('loginBox');
                                showField('joinBox');
                                hideField('newsletterBox');
                                changeClass('li-login','off');
                                changeClass('li-newsletter','off');
                                changeClass('li-join','on');
                                return;
                        } else if ( tab == 'newsletter' ) {
                                hideField('loginBox');
                                hideField('joinBox');
                                showField('newsletterBox');
                                changeClass('li-login','off');
                                changeClass('li-join','off');
                                changeClass('li-newsletter','on');
                                return;
                        }
                }

