﻿    //****   Methods for showing detailed information about tripitems asynchronicly, after calling the modal popup.  ****//
    function ShowTripInfo(tripId)
    {
        var lang = GetCookie("Lang", "en");
        AddToTrip(tripId, lang);
    }
    
    function AddToTrip(tripId, language){
        var ActiveTripId = GetActiveTripIdFromCookie("MyTripId","0");
        if(ActiveTripId == 0){
            var Redirect = "/" + __market + "/" + __destination + "/MyTrip/AddTrip.aspx?TripItemId=" + tripId;
            window.location.href = Redirect;
            //__doPostBack(SearchWebControlGetID('')
        }else{
            ShowModalMessage(GetAddedMessage());
            TripplannerService.AddToMyTrip(tripId, language,ActiveTripId);
            setTimeout("__doPostBack(SearchWebControlGetID('upNavRightMyTrip'), '');", 500);
        }
    }
    
    
    //Use jQuery to complete the details popup
    function DisplayResult(trip)
    {
        if (trip != null)
        {
            var modal = FindModalPopupTripExtender();
            if (modal != null)
                modal.show();

            $("#popupDescription").text(trip.Description);
            $("#popupTripImage")[0].src = trip.Image;
        }
    }
    
    function CloseModalPopup()
    {
        var modal = FindModalPopupTripExtender();
        modal.hide();
        
        //Prevent the modal popup from displaying very briefly after requesting another webpage
        var PopupWebControl = SearchWebControlGetID("pnlTripDetail");
        if (PopupWebControl != null)
            $("#" + PopupWebControl).css({display:"none"});
    }
    
    //Retreives the instance of the ModalPopupExtender, either exists on the TripItem Index or Detail page.
    function FindModalPopupTripExtender()
    {
        var modal = $find('ctl00_cph_Body_Discover_GoogleMap_ModelPopupExtenderTrip'); 
        if (modal == null)
            modal = $find('ctl00_cph_Body_Details_GoogleMap_ModelPopupExtenderTrip');
        
        return modal;
    }
    
    //****   Modal popup for the forgot password link.  ****//
    function ShowModalPwd()
    {
        var modal = FindModalPopupPwdExtender();
        if (modal != null)
            modal.show();
    }
    
    function CloseModalPwd()
    {
        var modal = FindModalPopupPwdExtender();
        if (modal != null)
            modal.hide();
    }
    
    function FindModalPopupPwdExtender()
    {
        var modal = $find('ctl00_cph_Body_Menu_SignInThumb_ModelPopupExtenderPwd');
        return modal;
    }
    
    //****   Modal popup for various messages.  ****//
    function ShowModalMessage(message)
    {
        var modal = FindModalPopupMessage();
        modal.ModalPopupBehavior.show();
        
        $("#modalPopupMessageText").html(message);
    }
    
    function CloseModalPopupMessage()
    {
        var modal = FindModalPopupMessage();
        modal.ModalPopupBehavior.hide();
    }
    
    function FindModalPopupMessage() {
        return $get($('.modalPopup').attr('id'));
        //return $get(SearchWebControlGetID("pnlModalPopupMessage"));
    }
    