﻿var channelID = 1;  
 var lat1 = 0;
 var lat2 = 0;
 var long1 = 0;
 var long2 = 0;
 var modeCarte = false;

// ---------------------- sélection des éléments à afficher -----------
function rechargeListResultT()
{
    mapSelectId = -1;  // -1 = ma recherche
    itineraryOnly = false;
    rechargeListResult();
}

function mapSelect(Type)
{
    // alert(Type);
    itineraryOnly = false;
    mapSelectId = Type;
    PushPinReInit = true;     //ADD BY FAB
    ListDetLAVList_i(map.GetCenter().Latitude, map.GetCenter().Longitude, map.GetZoomLevel(), channelID);
}

function viewHasChanged()
 {
    if (typeof(MWLavService) == 'function') {
            var zoomlevel = map.GetZoomLevel();
            if (modeCarte) { zoomlevel += 2; channelID = 100; }
            if (channelID > 0)
            ListDetLAVList_i(map.GetCenter().Latitude, map.GetCenter().Longitude, zoomlevel, channelID);
    }else{
            setTimeout("viewHasChanged()", 500);
    }
 }  
 
function initViewZone()
{
     var points = new Array();
     if (lat1 != 0 && long1 != 0)
     {
       points.push(new VELatLong(lat1.replace(",","."),long1.replace(",",".")));
       if (lat2 != 0 && long2 != 0) points.push(new VELatLong(lat2.replace(",","."),long2.replace(",",".")));
       map.SetMapView(points);
     }
} 
 
function firstdisplayFull() {

}

var curOnglet;

function initOnglets()
{

if ((document.getElementById("ctl00_ContentPlaceHolder1_onglet1Title").value.length > 0) &&
 (document.getElementById("ctl00_ContentPlaceHolder1_ongletSearch1").value.length > 0))
 {
    document.getElementById("onglet1TitleId").innerHTML = document.getElementById("ctl00_ContentPlaceHolder1_onglet1Title").value
    swapOngletV("onglet1");
 } 
if ((document.getElementById("ctl00_ContentPlaceHolder1_onglet2Title").value.length > 0) &&
 (document.getElementById("ctl00_ContentPlaceHolder1_ongletSearch2").value.length > 0))
 {
    document.getElementById("onglet2TitleId").innerHTML = document.getElementById("ctl00_ContentPlaceHolder1_onglet2Title").value
    swapOngletV("onglet2");
 } 
 if ((document.getElementById("ctl00_ContentPlaceHolder1_onglet3Title").value.length > 0) &&
 (document.getElementById("ctl00_ContentPlaceHolder1_ongletSearch3").value.length > 0))
 {
    document.getElementById("onglet3TitleId").innerHTML = document.getElementById("ctl00_ContentPlaceHolder1_onglet3Title").value
    swapOngletV("onglet3");
 } 
 if ((document.getElementById("ctl00_ContentPlaceHolder1_onglet4Title").value.length > 0) &&
 (document.getElementById("ctl00_ContentPlaceHolder1_ongletSearch4").value.length > 0))
 {
    document.getElementById("onglet4TitleId").innerHTML = document.getElementById("ctl00_ContentPlaceHolder1_onglet4Title").value
    swapOngletV("onglet4");
 } 
 curOnglet = document.getElementById("ctl00_ContentPlaceHolder1_startOnglet").value;
 pullOnglet("onglet" + curOnglet);
}

function displayOngletContent(ongletNb)
{
    itineraryOnly = false;
    pushpop(ongletNb);
    launchSearch(0);
 }

function pushpop(ongletNb)
{
   switch (ongletNb)
   {
   case (1):
        pullOnglet("onglet1");
        pushOnglet("onglet2");
        pushOnglet("onglet3");
        pushOnglet("onglet4");
        break;
   case (2):
        pushOnglet("onglet1");
        pullOnglet("onglet2");
        pushOnglet("onglet3");
        pushOnglet("onglet4");
        break;
   case (3):
        pushOnglet("onglet1");
        pushOnglet("onglet2");
        pullOnglet("onglet3");
        pushOnglet("onglet4");
        break;
   case (4):
        pushOnglet("onglet1");
        pushOnglet("onglet2");
        pushOnglet("onglet3");
        pullOnglet("onglet4");
        break;
   }
    curOnglet = ongletNb;
 }

function launchSearchPageCB(bool1,bool2,bool2,str1, PageNb)
{
    launchSearch(PageNb);
}
  
function launchSearch(PageNb)
{
    var searchStringParam = new Object();
    searchStringParam.searchForProductTO = true;
    searchStringParam.searchForMembersTrip = true;
    searchStringParam.searchForPlaces = true;
    searchStringParam.queryString = document.getElementById("ctl00_ContentPlaceHolder1_ongletSearch"+curOnglet).value; 
    searchStringParam.mode = 1;
    searchStringParam.pageNb = PageNb;       
   
    showWait();
    MWSearchService.getSearchResult(searchStringParam, displayResult,failedDisplayResult);
}

function displayResult(result)
{
    hideWait();
    document.getElementById("infoDecSpan").innerHTML = result;
//    initViewZone();
    PushPinReInit = true; 
    ListDetLAVList_i(map.GetCenter().Latitude, map.GetCenter().Longitude, map.GetZoomLevel(), channelID);
    document.getElementById("fondScroll").scrollTop = 0;
    // eval(result);
}

function failedDisplayResult()
{
    alert('searchResult plante');
}

function mediaHasbeenloaded()
{
}

function manageUserClick(lattitude,longitude,zoomlevel)
{
}

function handlePinclick(id)
{
    var Code = id.substring(0,36);
    var Type = id.substring(37);
    Type = Type.substring(0,Type.indexOf("_")); 
    rechargeInfoDecCBMd(Type, Code, 6);
}

function hideWait()
{
      // document.body.scrollTop = 0;
      // document.scrollTop = 0;    
       hideWaitNoScr();
} 
function hideWaitNoScr()
{
       document.getElementById("WaitBack").style.display = "none";   
       document.getElementById("Wait").style.display = "none";  
       // if(this.scrollTop) document.body.scrollTop = this.scrollTop;
}

function showWait()
{
       //document.body.scrollTop = 0;
       showWaitNoScr();  
}
function showWaitNoScr()
{
       document.getElementById("WaitBack").style.top = document.body.scrollTop;          
       document.getElementById("Wait").style.top = document.body.scrollTop;  
       document.getElementById("WaitBack").style.display = "block"; 
       document.getElementById("Wait").style.display = "block";
       setTimeout("hideWait();",60000);
}
function GoToLatLongDetCB(Lat, Long, Code, Type)
{
    rechargeInfoDecCB(Type, Code);
}

function rechargeInfoDecCB(Type, Query) 
{
    rechargeInfoDecCBMd(Type, Query, 6) ;
}

function GoToLatLongDetCBSEL(Lat, Long, Code, Type)
{
    rechargeInfoDecCBMd(Type, Code, 5) ;
}

function rechargeInfoDecCBMd(Type, Query, mode) 
{
    showWait();
    var searchParameters = new Object();
    searchParameters.LavType = Type;
    searchParameters.queryString = Query;
    searchParameters.mode = mode;
    MWInfoDecService.getObjectHTMLFullDescription(searchParameters, showPopupResized);
}

function insertElementInSelectionCB(Type,Lattitude, Longitude,Code,Name,Pays,Ville,codeElement) {
    showWait();
    var searchParametersGROUPE = new Object();
    searchParametersGROUPE.Type = Type;
    searchParametersGROUPE.Code = Code;
    searchParametersGROUPE.Name = Name;
    searchParametersGROUPE.Pays = Pays;
    searchParametersGROUPE.Ville = Ville;
    searchParametersGROUPE.Lattitude = Lattitude;
    searchParametersGROUPE.Longitude = Longitude;
    searchParametersGROUPE.Position = 0;
    if (codeElement != null)
        MWGroupeService.insertElementInSelection(searchParametersGROUPE, "CB", codeElement, displaySelectionCB);
    else
        MWGroupeService.insertElementInSelection(searchParametersGROUPE, "CB", Code, displaySelectionCB);
}

function insertElementInGuide(Type,Lattitude, Longitude,Code,Name,Pays,Ville,codeElement) {
    showWait();
    var searchParametersGROUPE = new Object();
    searchParametersGROUPE.Type = Type;
    searchParametersGROUPE.Code = Code;
    searchParametersGROUPE.Name = Name;
    searchParametersGROUPE.Pays = Pays;
    searchParametersGROUPE.Ville = Ville;
    searchParametersGROUPE.Lattitude = Lattitude;
    searchParametersGROUPE.Longitude = Longitude;
    searchParametersGROUPE.Position = 0;
    if (codeElement != null)
        MWGroupeService.insertElementInSelection(searchParametersGROUPE, "CB", codeElement, displaySelectionCB);
    else
        MWGroupeService.insertElementInSelection(searchParametersGROUPE, "CB", Code, displaySelectionCB);
}

function insertElementInBasket(codePOBooking) {
    showWait();
    //MWGroupeService.insertElementInBasket(codePOBooking, displayBasket);
    MWGroupeService.insertElementInBasket(codePOBooking, prestAddedToBasket);
}
function insertElementInBasketAndBook(codePOBooking) {
    showWait();
    MWGroupeService.insertElementInBasket(codePOBooking, prestGoToBook);
    //MWGroupeService.insertElementInBasket(codePOBooking, prestAddedToBasket);
}

function loadGuide()
{
	if (typeof(MWGroupeService) == 'function')
		MWGroupeService.getFormatedSelection("LCB", displayLeftSelectionCB);
	else
		setTimeout("loadGuide()", 500);
}


function loadBasket()
{
	if (typeof(MWGroupeService) == 'function') {
		MWGroupeService.getFormatedSelection("LCB", displayLeftSelectionCB);
		MWGroupeService.DisplayBasket(displayBasket);
	}else{
		setTimeout("loadBasket()", 500);
	}
}

function displayPopupAddTicketingToPanel()
{
    var divListTicketing = jQuery("#hiddenLAVListPopup");
    //divListTicketing.show();
    if (divListTicketing != null)
    {
        MW.Popup.show(divListTicketing);
    }
}

function AddTicketingToBasket()
{
    //On récupère la billeterie sélectionnée
    var selectedTicketing = jQuery("#radioSelected").val();
    var paramAddBasket = selectedTicketing.split('*');
    insertElementInSelectionCB(214,paramAddBasket[0],paramAddBasket[1],paramAddBasket[2], paramAddBasket[3], paramAddBasket[4], paramAddBasket[5]);
    //On rend la popup invisible
    hidePopup();
}

function radioButtonClicked(universalCode)
{
    jQuery('#radioSelected').val(universalCode);
}


function deleteElementFromSelectionCB(theValue) {
    MWGroupeService.deleteElementFromSelection(theValue, "CB", displaySelectionCB);
}
function moveUpETAPinListCB(theValue) {
    MWGroupeService.moveUpETAPinList(theValue, "CB", displaySelectionCB);
}

function moveDownETAPinListCB(theValue) {
    MWGroupeService.moveDownETAPinList(theValue, "CB", displaySelectionCB);
}
function prestHasBeenDroppedCB(x,y,theDraggedObject, receiverList)
{    
    showWait();
    theDraggedObject = theDraggedObject.replace("loc_Element","");
    receiverList = receiverList.replace("loc_Element","");
    moveElementInSelectionCB(theDraggedObject, receiverList);
}

function moveElementInSelectionCB(src, dest) {
    MWGroupeService.moveElementInSelection(src,dest, "CB", displaySelectionCB);
}
function displayLeftSelectionCB(result)
{
    try 
    {
        var leftBasket = document.getElementById("leftGuideID");
        if (leftBasket != null)
        {
            leftBasket.innerHTML =  result.HTMLSelection;
        }
        else
        {
            alert("Votre session a expiré. ");
        }
    }
    catch (e)
    {
        alert("Votre session a expiré.");
    }
}
function displaySelectionCB(result)
{
    hideWait();
    try 
    {
        document.getElementById("ctl00_ContentPlaceHolder1_basketContentDiv").innerHTML =  result.HTMLSelection;
    }
    catch (e)
    {
        try {
            MWGroupeService.getFormatedSelection("LCB", displayLeftSelectionCB);
        }
        catch (e)
        {
            alert("Votre session a expiré.  ");
        }
    }    
}
function displayBasket(result)
{
    hideWait();
    jQuery("#leftBasketID").empty();
    jQuery("#leftBasketID").append(result);
}

function prestAddedToBasket()
{
	window.location = "addedToBasket.aspx";
}

function prestGoToBook()
{
	window.location = "ManageSelection.aspx";
}

function RemoveBookingFromBasket(bookingCode)
{
    MWGroupeService.RemoveBookingFromBasket(bookingCode,displayBasket);
}

function drawBasket()
{
    if (map == null) 
          window.location = "Ville_carte.aspx?basket=1"; 
    else
    { try { 
        LoadItinerary(19, "");
        }
      catch (e) {
      window.location = "Ville_carte.aspx?basket=1"; 
      }
    }
}


     MW.Euriage = {};

 MW.Euriage.Display_Class = function(){    
        //display a product booking page by its item Code (its code in the travel)   
        this.displayProductBookingPage = function(pItemCode, pTypeCode){
          MW.Waiter.show();
          if (typeof(MWResaService) == 'function')
                    MWResaService.DisplayProductBookingPage(pItemCode, this.onDisplayProductBookingPageComplete, this.onFailed, this.onFailed, this.onFailed, {caller:this, params:{typecode:pTypeCode}});        
          else
            setTimeout("displayProductBookingPage(pItemCode, pTypeCode)",500);  
        };
        
        //display a product booking page by its product infos
        this.displayProductBookingPageByProductInfo = function(pParams){
          MW.Waiter.show();
          MWResaService.DisplayProductBookingPageByProductInfo(pParams, this.onDisplayProductBookingPageByProductInfoComplete, this.onFailed, this.onFailed, this.onFailed, {caller:this, params:pParams});                
        };
        
        //display departure dates
        this.GetDepartureDays = function(pParams){
          MW.Waiter.show();
          MW.Euriage.openResultList();
          var departuredate;
          
          departuredate = jQuery('#ctbDepartureDateInput_Day_ID').val()+"/"+(new Number(jQuery('#ctbDepartureDateInput_Month_ID').val())+1)+"/"+jQuery('#ctbDepartureDateInput_Year_ID').val();
          
          var delta = 4;
          var duration = document.getElementById("ddDurationInput").value;
          MWResaService.GetDepartureDays(pParams, departuredate, delta, duration, this.onDisplayProductBookingPageByProductInfoComplete, this.onFailed , this.onFailed, this.onFailed, {caller:this});                
        };
        
        //display a product booking page by its LAV infos
        this.displayProductBookingPageByTipInfo = function(pParams){
          MW.Waiter.show();
          MW.Euriage.openResultList();
          MWResaService.DisplayProductBookingPageByTipInfo(pParams, this.onDisplayProductBookingPageByProductInfoComplete, this.onFailed, this.onFailed, this.onFailed, {caller:this});        
        };
        
		this.displayItemDescription = function(pItemCode, pType){
		    var searchParameters = new Object();
		    searchParameters.LavType = pType;
		    searchParameters.queryString = pItemCode;
		    searchParameters.mode = 5;
		    MWInfoDecService.getObjectHTMLFullDescription(searchParameters, this.onDisplayProductBookingPageComplete, this.onFailed, null, null, {caller:this});     
        };
		
        this.onDisplayProductBookingPageComplete = function(result, info, context){
            MW.Waiter.hide();
            document.getElementById("Mediawelcome_Choice_Panel").innerHTML = result;
            
            MW.Euriage.Display.arrangePage();  

        };    
        
        //TODO : à HARMONISER AVEC LA PRECEDENTE
        this.onDisplayProductBookingPageByProductInfoComplete = function(result, info, context){
            context.caller.onDisplayProductBookingPageComplete(result, info, context);
        };   
        
        this.arrangePage = function(){
            var suffix = jQuery('#itemCode').attr("value");
//            if(jQuery('#Mediawelcome_Working_Panel_Quote*'+suffix).length>0 && jQuery('#Mediawelcome_Working_Panel_Quote*'+suffix).html().length>10)
//	            jQuery('#Mediawelcome_Working*'+suffix).tabs( { fxSlide: true, fxFade: true, fxSpeed: 'normal',disabled: [2]  }).enableTab(1).triggerTab(3);
//        	else
//        		jQuery('#Mediawelcome_Working*'+suffix).tabs( { fxSlide: true, fxFade: true, fxSpeed: 'normal',disabled: [2,3]  }).enableTab(1).triggerTab(1);

            var isHotel = jQuery('#hdfIsHotel')[0].value;
            var isTicketing = jQuery('#hdfIsTicketing')[0].value;
        	
        	if (isHotel == 'true')
        	{
        	    MW.Booking.POBookingDisplay.launchScript('FirstHotelStep');
        	}
        	else if (isTicketing == 'true')
        	{
        	    MW.Booking.POBookingDisplay.launchScript('Ticketing');
        	}

		    jQuery("ul#gvUl").jqGalView({appendTo:"#jqGalViewHolder",items: 9});
	        
	        MW.VYDO.DatePicker.set(suffix);	  
	        MW.VYDO.DatePicker.linkDatePickers(jQuery('#DateDebut*'+suffix)[0], jQuery('#DateFin*'+suffix)[0],1);              
            
            //MW.VYDO.DatePicker.set(suffix);
          
            
             jQuery("#LastMonth").bind("click", function(){
                
                if (MWIndex>0){
                   if (Month==1){
                    Month=12;
                    Year=Year-1;
                   }else{
                    Month=Month-1;
                   }  
                  MWIndex--;
                  refreshPlanning();
                  if (MWIndex==0){
                    jQuery("#LastMonth").hide();
                  }else{
                    jQuery("#LastMonth").show();
                  }
               }
                   return false;
            
                });  
                    
            jQuery("#NextMonth").bind("click", function(){    
                   if (Month==12){
                    Month=1;
                    Year=(Year-1)+2;
                   }else{
                    Month=(Month-1)+2;
                   }      
                   
                   YearEnd=Year;
                   MonthEnd=Month;
                   if (MonthEnd==12){
                    MonthEnd=1;
                    YearEnd=(YearEnd-1)+2;
                   }else{
                    MonthEnd=(Month-1)+2;
                   }   
                   MWIndex++;
                  refreshPlanning();
                  if (MWIndex==NBM -1 ){
                    jQuery("#NextMonth").hide();
                  }else{
                    jQuery("#NextMonth").show();
                  }
                   return false;
                 });             
           
                var scripts = jQuery("#Mediawelcome_Choice_Panel script");
                for(var i=0; i<scripts.length; i++){
                    eval(scripts[i].innerHTML.split('\n').join(''));
                }                  
        };
        
        
        this.gotoBookPanel = function(){ 
            MWResaService.GetBookPage(this.onBookPageComplete, this.onBookPageFailed,this.onBookPageFailed, this.onBookPageFailed,{}, 100000);
        };
        
        this.gotoOrderPanel = function(pResult){  
               if(pResult){
                jQuery('#Mediawelcome_Choice_Panel').html(pResult.content);
               }
        };        
        
        this.onBookPageComplete = function(pResult){ 
            //On efface d'abord le fil d'ariane
            jQuery('#filAriane').hide();
           if(pResult){
               if(pResult.type > 0){
                   jQuery('#Mediawelcome_Choice_Panel').html(pResult.content);                  
               }
               else{
                   MW.Popup.openWithContent(pResult.message);
               }
           }
        };
        
        this.onFailed = function(){
            MW.Waiter.hide();
        };
        
        this.gotoChoicePanel = function(){
            jQuery('#Mediawelcome_Book_Panel').css('display','none'); 
            jQuery('#Mediawelcome_Order_Panel').css('display','none'); 
            jQuery('#Mediawelcome_Choice_Panel').css('display','block');            
        };          
        
        //Booking Form Panel
        this.getProductDescription = function( pPOBCode, pPanelCible){
             MW.Waiter.show();
             MWResaService.DisplayProductDescription(pPOBCode, this.onGetDescriptionComplete, null, null, null, pPanelCible, 100000);
        }
        
        this.onGetDescriptionComplete = function(result, obj, pPanelCible){        
              MW.Display.integrateContent(pPanelCible, result);
              MW.Waiter.hide();    
        }       
     }
     MW.Euriage.Display = new  MW.Euriage.Display_Class(); 

    
    function GoToFakeBookPage(fakePaymentPage,orderID)
    {
        var redirectPage = fakePaymentPage;
        redirectPage += "?LastName=" + document.getElementById('Customer_LastName').value;
        redirectPage += "&FirstName=" + document.getElementById('Customer_FirstName').value;
        redirectPage += "&Address=" + document.getElementById('Customer_Address').value;
        redirectPage += "&ZipCode=" + document.getElementById('Customer_ZipCode').value;
        redirectPage += "&City=" + document.getElementById('Customer_City').value;
        redirectPage += "&Country=" + document.getElementById('Customer_Country').value;
        redirectPage += "&Phone=" + document.getElementById('Customer_PhoneNumber').value;
        redirectPage += "&Mobile=" + document.getElementById('Customer_MobileNumber').value;
        redirectPage += "&Fax=" + document.getElementById('Customer_FaxNumber').value;
        redirectPage += "&Email=" + document.getElementById('Customer_Email').value;
        redirectPage += "&Note=" + document.getElementById('Customer_Note').value;
        redirectPage += "&OrderID=" + orderID;
        
        window.location.replace(redirectPage);
}

///COPY FROM RESASTAR
MW.ResaStar = {};

//HELPER PANEL
MW.ResaStar.helperMode= "";
MW.ResaStar.setHelperMode = function(pMode){
    MW.ResaStar.helperMode = pMode;
    var UIhelper = jQuery("#UIhelper");
    switch(pMode){
        case "CONSTRUCT" :
            UIhelper.find("a").eq(0).css("font-weight","bold");
            UIhelper.find("a").eq(1).css("font-weight","");            
        break;
        
        case "PRODUCT" :
            UIhelper.find("a").eq(1).css("font-weight","bold");
            UIhelper.find("a").eq(0).css("font-weight","");           
        break;
    }
};

//MAP PANEL
MW.ResaStar.openMap = function(){
    jQuery("#myMap").show();    
    jQuery("#myFlashMapContainer").css("height",MW.Map.visibleHeight+"px");    

    jQuery("#myFlashMap")[0].height = MW.Map.visibleHeight;
    if(jQuery("#myFlashMap embed")[0])jQuery("#myFlashMap embed")[0].height = MW.Map.visibleHeight;
   
    jQuery("#mapPanelTitle .openLink").hide();
    jQuery("#mapPanelTitle .closeLink").show();    
    
    //show the sumup result List
    if(MW.ResaStar.helperMode == "PRODUCT") jQuery("#SumUpResultList").show();  
       
};
MW.ResaStar.closeMap = function(){
    jQuery("#myMap").hide();
    jQuery("#myFlashMapContainer").css("height","0px");   
    jQuery("#myFlashMap")[0].height = 0;
    if(jQuery("#myFlashMap embed")[0])jQuery("#myFlashMap embed")[0].height = 0;
    jQuery("#mapPanelTitle .openLink").show();
    jQuery("#mapPanelTitle .closeLink").hide();    
    
    //hide the sumup result List
    jQuery("#SumUpResultList").hide();     
};

//RESULT PANEL
MW.ResaStar.openResultList = function(){
    jQuery("#resultList").show();
    jQuery("#resultListPanelTitle .openLink").hide();
    jQuery("#resultListPanelTitle .closeLink").show();    
};
MW.ResaStar.closeResultList = function(){
    jQuery("#resultList").hide();
    jQuery("#resultListPanelTitle .openLink").show();
    jQuery("#resultListPanelTitle .closeLink").hide();           
};

MW.ResaStar.disableResultList = function(){
    this.closeResultList();  
    jQuery("#resultListPanelTitle .closeLink").hide();       
    jQuery("#resultListPanelTitle .openLink").hide();
    jQuery("#resultListPanelTitle").removeClass("BigPanelTitleBar").addClass("BigPanelTitleBar_Disable");    
};
MW.ResaStar.enableResultList = function(){
    jQuery("#resultListPanelTitle").removeClass("BigPanelTitleBar_Disable").addClass("BigPanelTitleBar");
    this.openResultList();   
};


//CURRENT SELECTION PANEL
MW.ResaStar.openSelection = function(){
    this.openPopupProduct();
};
MW.ResaStar.closeSelection = function(){
    this.closePopupProduct();       
};

MW.ResaStar.closePopupProduct = function(){
       //Montre les scrollbars
       MW.ScrollBar.show();  

       if(jQuery.browser.msie){
           jQuery('select').show();
       }
       document.getElementById("PopupProduct").style.display = "none";          
       document.getElementById("PopupProduct_Back").style.display = "none";         
};

MW.ResaStar.openPopupProduct = function(typeCode){
       if(jQuery.browser.msie){
           jQuery('select').hide();
           jQuery('# PopupProduct select').show();
       }
       document.getElementById("PopupProduct").style.display = "block";   
       document.getElementById("PopupProduct").style.top = (10+window.document.body.scrollTop)+'px';              
       document.getElementById("PopupProduct_Back").style.display = "block";  
       document.getElementById("PopupProduct_Back").style.height =  window.document.body.scrollHeight+'px';
       if(typeCode){
        jQuery('#PopupProduct').find('.PopupProductBorder_R1C2').css('background-image',"url('images/popupProduct/PopupProductBorder_R1C2_"+typeCode+".png')");
       }else{
       
       }
       
       //Cache les scrollbars
       MW.ScrollBar.hide();  
};

MW.ResaStar.closePopupCity = function(){
       if(jQuery.browser.msie){
           jQuery('select').show();
       }
       document.getElementById("PopupCity").style.display = "none";          
       document.getElementById("PopupProduct_Back").style.display = "none";         
};

MW.ResaStar.openPopupCity = function(){
       if(jQuery.browser.msie){
           jQuery('select').hide();
           jQuery('# PopupProduct select').show();
       }
       document.getElementById("PopupCity").style.display = "block";   
       document.getElementById("PopupCity").style.top = (10+window.document.body.scrollTop)+'px';              
       document.getElementById("PopupProduct_Back").style.display = "block";  
       document.getElementById("PopupProduct_Back").style.height =  window.document.body.scrollHeight+'px';
};

MW.ResaStar.closePopupProductInfo = function(){
    if(jQuery.browser.msie){
       jQuery('select').show();
    }
    var popup = document.getElementById("PopupProductInfo");
    popup.style.display = "none";   
};

MW.ResaStar.openPopupProductInfo = function(event, pCode){
       if(jQuery.browser.msie){
           jQuery('select').hide();
           jQuery('# PopupProduct select').show();
       }

    var popup = document.getElementById("PopupProductInfo");
    popup.style.display = "block";     
    if(event.pageX>550){
        popup.style.left = event.pageX-350;
        popup.style.top = event.pageY; 
    }else{
        popup.style.left = event.pageX;
        popup.style.top = event.pageY; 
    }

    jQuery('#PopupProductInfoContent').html(jQuery("#ProductPopupInfo_"+pCode).html());    
};

MW.ResaStar.openPopupCityInfo = function(event, pItem){
    var params = {};
    params.CityName = pItem.name;

    showPopup(jQuery("#PopupMapCityContent"),params);
};


MW.ResaStar.closeSearch = function(){
    CPT_searchProductComponent.hide();
};

MW.ResaStar.disableSelectionPanel = function(){
    jQuery("#selectionPanelTitle").removeClass("BigPanelTitleBar").addClass("BigPanelTitleBar_Disable");
    jQuery("#Mediawelcome_Working_Travel").hide();  
};
MW.ResaStar.enableSelectionPanel = function(){
    jQuery("#selectionPanelTitle").removeClass("BigPanelTitleBar_Disable").addClass("BigPanelTitleBar"); 
     jQuery("#Mediawelcome_Working_Travel").show()   
};


//MODE
MW.ResaStar.mode = "";
MW.ResaStar.setMode = function(pMode){
    if(pMode && this.mode == pMode) return;
    if(pMode) this.mode = pMode;
    MW.ResaStar.setHelperMode(this.mode);

    OLD_LatMin = 0;
    OLD_LatMax = 0;
    OLD_LongMin = 0;
    OLD_LongMax = 0;  

    switch(this.mode){
        case "CONSTRUCT" :
            MW.Map.visibleWidth = 722;	
            MW.Map.visibleHeight = 500;	
          //  CPT_searchProductComponent.setMode("PLACE");
             
			MW.ResaStar.openMap(); 
			MW.Map.loadTravelItems();		
            MW.ResaStar.disableResultList();  
            MW.ResaStar.disableSelectionPanel();
					           
			if(MW_FLASH.map && MW_FLASH.map.flashMap.setMode){
				MW_FLASH.map.flashMap.setMode("MODE_EDIT_SCENARIO");			  
				MW_FLASH.map.flashMap.setMapPositionSize(0,0,MW.Map.visibleWidth,MW.Map.visibleHeight);
				
				jQuery('#myFlashMap')[0].width = MW.Map.visibleWidth;
				if(jQuery("#myFlashMap embed")[0])jQuery('#myFlashMap embed')[0].width = MW.Map.visibleWidth;	
				jQuery('#myMap').css('width',[0].width = MW.Map.visibleWidth+'px');
				jQuery('#myFlashMapContainer').css('width',[0].width = MW.Map.visibleWidth+'px');
							
				jQuery('#myFlashMap')[0].height = MW.Map.visibleHeight;
				if(jQuery("#myFlashMap embed")[0])jQuery('#myFlashMap embed')[0].height = MW.Map.visibleHeight;	
				jQuery('#myMap').css('height',[0].height = MW.Map.visibleHeight+'px');				
				jQuery('#myMapWaiter').css('height',[0].height = MW.Map.visibleHeight+'px');
				jQuery('#myFlashMapContainer').css('height',[0].height = MW.Map.visibleHeight+'px');
			}
			
			jQuery("#SumUpResultList").hide(); 
            break;

        case "PRODUCT" :
            MW.Map.visibleWidth = 522;	
            MW.Map.visibleHeight = 320;
            CPT_searchProductComponent.setMode("PRODUCT");
            MW.ResaStar.enableResultList();
            MW.ResaStar.enableSelectionPanel(); 
			
			if(MW_FLASH.map && MW_FLASH.map.flashMap.setMode){
				MW_FLASH.map.flashMap.setMode("MODE_DEFAULT");	
				MW_FLASH.map.flashMap.setMapPositionSize(0,0,MW.Map.visibleWidth,MW.Map.visibleHeight);
				
				jQuery('#myFlashMap')[0].width = MW.Map.visibleWidth;
				if(jQuery("#myFlashMap embed")[0])jQuery('#myFlashMap embed')[0].width = MW.Map.visibleWidth;	
				jQuery('#myMap').css('width',[0].width = MW.Map.visibleWidth+'px');
				jQuery('#myFlashMapContainer').css('width',[0].width = MW.Map.visibleWidth+'px');
				
				jQuery('#myFlashMap')[0].height = MW.Map.visibleHeight;
				if(jQuery("#myFlashMap embed")[0])jQuery('#myFlashMap embed')[0].height = MW.Map.visibleHeight;	
				jQuery('#myMap').css('height',[0].height = MW.Map.visibleHeight+'px');
				jQuery('#myMapWaiter').css('height',[0].height = MW.Map.visibleHeight+'px');				
				jQuery('#myFlashMapContainer').css('height',[0].height = MW.Map.visibleHeight+'px');
				
			}
			jQuery("#SumUpResultList").show(); 
            break;    
    }
}


    MW.ResaStar.searchProductFromParams = function(pParams){
       
       var timePeriodText = "";
       if(pParams.startDate)
		    timePeriodText = " à partir du " + pParams.startDate;
       if(pParams.duration)
	    if(pParams.duration > 0)
		    timePeriodText += " pendant " + pParams.duration + " jours";
       CPT_searchProductComponent.searchProduct("hotel à " + pParams.cityName.split('-').join(' ') + timePeriodText, 1, "1|3|6|4|10", " à " + pParams.cityName.split('-').join(' ') + timePeriodText);      
    };


 MW.ResaStar.Display_Class = function(){    
        //display a product booking page by its item Code (its code in the travel)   
        this.displayProductBookingPage = function(pItemCode, pTypeCode){
          MW.Waiter.show();
          //MW.ResaStar.openResultList();
          MWResaService.DisplayProductBookingPage(pItemCode, this.onDisplayProductBookingPageComplete, this.onFailed, this.onFailed, this.onFailed, {caller:this, params:{typecode:pTypeCode}});        
        };
        
        //display a product booking page by its product infos
        this.displayProductBookingPageByProductInfo = function(pParams){
          MW.Waiter.show();
          //MW.ResaStar.openResultList();
          MWResaService.DisplayProductBookingPageByProductInfo(pParams, this.onDisplayProductBookingPageByProductInfoComplete, this.onFailed, this.onFailed, this.onFailed, {caller:this, params:pParams});                
        };
        
        //display departure dates
        this.GetDepartureDays = function(pParams){
          MW.Waiter.show();
          MW.ResaStar.openResultList();
          var departuredate;
         // if(document.getElementById("ctbDepartureDateInput").style.display != 'hidden') = document.getElementById("ctbDepartureDateInput").value;
          
          departuredate = jQuery('#ProductCircuitDisplay_StartDate').val();
          
          var delta = 4;
          var duration = document.getElementById("ddDurationInput").value;
          MWResaService.GetDepartureDays(pParams, departuredate, delta, duration, this.onDisplayProductBookingPageByProductInfoComplete, this.onFailed , this.onFailed, this.onFailed, {caller:this});                
        };
        
        //display a product booking page by its LAV infos
        this.displayProductBookingPageByTipInfo = function(pParams){
          MW.Waiter.show();
          MW.ResaStar.openResultList();
          MWResaService.DisplayProductBookingPageByTipInfo(pParams, this.onDisplayProductBookingPageByProductInfoComplete, this.onFailed, this.onFailed, this.onFailed, {caller:this});        
        };
        
		this.displayItemDescription = function(pItemCode, pType){
		    var searchParameters = new Object();
		    searchParameters.LavType = pType;
		    searchParameters.queryString = pItemCode;
		    searchParameters.mode = 5;
		    MWInfoDecService.getObjectHTMLFullDescription(searchParameters, this.onDisplayProductBookingPageComplete, this.onFailed, null, null, {caller:this});     
        };
		
        this.onDisplayProductBookingPageComplete = function(result, info, context){
            MW.Waiter.hide();
            /*var func = function(){
                MW.ResaStar.Display.gotoBookPanel();
            }*/
            document.getElementById("Mediawelcome_Choice_Panel").innerHTML = result;
            
            MW.ResaStar.Display.arrangePage();     
            MW.ResaStar.openPopupProduct(context.params.typecode);     
            MW.ResaStar.closePopupProductInfo();

        };    
        
        //TODO : à HARMONISER AVEC LA PRECEDENTE
        this.onDisplayProductBookingPageByProductInfoComplete = function(result, info, context){
            context.caller.onDisplayProductBookingPageComplete(result, info, context);
            //MW.ResaStar.closeMap();
        };   
        
        this.arrangePage = function(){
            var suffix = jQuery('#itemCode').attr("value");
            if(jQuery('#Mediawelcome_Working_Panel_Quote*'+suffix).length>0 && jQuery('#Mediawelcome_Working_Panel_Quote*'+suffix).html().length>10)
	            jQuery('#Mediawelcome_Working*'+suffix).tabs( { fxSlide: true, fxFade: true, fxSpeed: 'normal',disabled: [2]  }).enableTab(1).triggerTab(3);
        	else
        		jQuery('#Mediawelcome_Working*'+suffix).tabs( { fxSlide: true, fxFade: true, fxSpeed: 'normal',disabled: [2,3]  }).enableTab(1).triggerTab(1);
        		
	        /*jQuery(".tabs-nav li a").one("click", function(){
		          if(jQuery(this).attr( 'href').indexOf('Mediawelcome_Working_Panel_Description')>-1){
			         MW.ResaStar.Display.getProductDescription('<xsl:value-of select="$suffix"/>', document.getElementById('Mediawelcome_Working_Panel_Description*<xsl:value-of select="$suffix"/>'));
		        }
            });*/

		    jQuery("ul#gvUl").jqGalView({appendTo:"#jqGalViewHolder",items: 9});
		  	/*jQuery('#DateDebut*'+suffix).bind(
		        'dpClosed',
		        function(e, selectedDates)
		        {
			        var d = selectedDates[0];
			        if (d) {
				        jQuery('#DateFin*'+suffix).dpSetStartDate(d.addDays(1).asString());
			        }
		        }
	        );
	        jQuery('#DateFin*'+suffix).bind(
		        'dpClosed',
		        function(e, selectedDates)
		        {
			        var d = selectedDates[0];
			        if (d) {
				        jQuery('#DateDebut*'+suffix).dpSetEndDate(d.addDays(-1).asString());
			        }
		        }
	        );  */  
	        
            MW.VYDO.DatePicker.set(suffix);	        
	        MW.VYDO.DatePicker.linkDatePickers(jQuery('#DateDebut*'+suffix)[0], jQuery('#DateFin*'+suffix)[0]);              
            

          
            
             jQuery("#LastMonth").bind("click", function(){
                
                if (MWIndex>0){
                   if (Month==1){
                    Month=12;
                    Year=Year-1;
                   }else{
                    Month=Month-1;
                   }  
                  MWIndex--;
                  refreshPlanning();
                  if (MWIndex==0){
                    jQuery("#LastMonth").hide();
                  }else{
                    jQuery("#LastMonth").show();
                  }
               }
                   return false;
            
                });  
                    
            jQuery("#NextMonth").bind("click", function(){    
                   if (Month==12){
                    Month=1;
                    Year=(Year-1)+2;
                   }else{
                    Month=(Month-1)+2;
                   }      
                   
                   YearEnd=Year;
                   MonthEnd=Month;
                   if (MonthEnd==12){
                    MonthEnd=1;
                    YearEnd=(YearEnd-1)+2;
                   }else{
                    MonthEnd=(Month-1)+2;
                   }   
                   MWIndex++;
                  refreshPlanning();
                  if (MWIndex==NBM -1 ){
                    jQuery("#NextMonth").hide();
                  }else{
                    jQuery("#NextMonth").show();
                  }
                   return false;
                 });  
                 
           // eval(jQuery("#PlanningScript").text());             
           // eval(jQuery('#script_departuredate').text());            
           
                var scripts = jQuery("#Mediawelcome_Choice_Panel script");
                for(var i=0; i<scripts.length; i++){
                    eval(scripts[i].innerHTML.split('\n').join(''));
                }                  
        };
        
        
        this.gotoBookPanel = function(){  
            MWResaService.GetBookPage(this.onBookPageComplete, this.onBookPageFailed,this.onBookPageFailed, this.onBookPageFailed,{}, 100000);
        };
        
        this.gotoOrderPanel = function(pResult){  
               /*jQuery('#Mediawelcome_Choice_Panel').css('display','none');
               jQuery('#Mediawelcome_Order_Panel').css('display','block'); 
               jQuery('#Mediawelcome_Book_Panel').css('display','none');*/
               if(pResult){
                jQuery('#Mediawelcome_Choice_Panel').html(pResult.content);
               }
        };        
        
        this.onBookPageComplete = function(pResult){
            // alert('MW.ResaStar.Display - onBookPageComplete - result : '+result);
           if(pResult){
               if(pResult.type > 0){
                   /*jQuery('#Mediawelcome_Choice_Panel').css('display','none');
                   jQuery('#Mediawelcome_Order_Panel').css('display','none'); 
                   jQuery('#Mediawelcome_Book_Panel').css('display','block');*/
                   MW.ResaStar.openPopupProduct("Book");
                   jQuery('#Mediawelcome_Choice_Panel').html(pResult.content);                  
               }
               else{
                   MW.Popup.openWithContent(pResult.message);
               }
           }
        };
        
        this.onFailed = function(){
            MW.Waiter.hide();
        };
        
        this.gotoChoicePanel = function(){
            jQuery('#Mediawelcome_Book_Panel').css('display','none'); 
            jQuery('#Mediawelcome_Order_Panel').css('display','none'); 
            jQuery('#Mediawelcome_Choice_Panel').css('display','block');            
        };          
        
        //Booking Form Panel
        this.getProductDescription = function( pPOBCode, pPanelCible){
             MW.Waiter.show();
             MWResaService.DisplayProductDescription(pPOBCode, this.onGetDescriptionComplete, null, null, null, pPanelCible, 100000);
        }
        
        this.onGetDescriptionComplete = function(result, obj, pPanelCible){        
              MW.Display.integrateContent(pPanelCible, result);
             /* MW.Popup.openWithContent(result);*/
              MW.Waiter.hide();    
        }       
     }
     MW.ResaStar.Display = new  MW.ResaStar.Display_Class();    
     
     MW.ResaStar.Booking_Class = function(){
     
        this.addProductToTravel = function(pItem){
            MWResaService.AddProductToTravel(pItem,this.onAddProductToTravel);
        }
        
        this.onAddProductToTravel = function(pResult){        
            jQuery("#ctl00_ContentPlaceHolder1_diagram").html(pResult.content);
            jQuery("#infoDecSpan").html(jQuery("#infoDecSpan").html());
        }
        
        this.setCustomerInfo = function(){
            MWResaService.SetCustomerInfo( getParameters("Mediawelcome_Booking_CustomerInfo") , MW.ResaStar.Display.onBookPageComplete, this.onBookPageFailed,this.onBookPageFailed, this.onBookPageFailed,{}, 100000);
        };
        
        this.onSetCustomerInfoComplete = function(result){
// alert('MW.ResaStar.Display - onBookPageComplete - result : '+result);
            jQuery('#Mediawelcome_Book_Panel').html(result);
        };
        
        this.onSetCustomerInfoFailed = function(){
        
        };
        
        this.setToBook = function(pPOBCodeList){
             MWResaService.SetToBook(pPOBCodeList,  MW.ResaStar.Display.onBookPageComplete);
        };
        
        this.switchToBook = function(pPOBCode, pValue){
            MWResaService.SwitchToBook(pPOBCode, pValue,   MW.ResaStar.Booking.onSwitchToBookComplete);
            jQuery("#ProductToBook_CB*"+pPOBCode).attr("checked",pValue);
            jQuery("#ProductToBook_CB2*"+pPOBCode).attr("checked",pValue);
        };
        
        this.onSwitchToBookComplete = function(pResult){
            if(pResult.type < 0) alert("ERROR");
        };
        
        this.cancelToBook = function(pPOBCodeList){
             MWResaService.CancelToBook(pPOBCodeList,  MW.ResaStar.Display.onBookPageComplete);
        };
        
        this.book = function(pPOBCodeList){
             MWResaService.Book(pPOBCodeList,  MW.ResaStar.Display.onBookPageComplete);
        };
        
        this.bookSelected = function(){
             MWResaService.BookSelected(MW.ResaStar.Display.onBookPageComplete);
        };
        
        this.bookAll = function(){
            MW.Waiter.show();  
            MWResaService.BookAll(getParameters("Mediawelcome_Booking_CustomerInfo"), MW.ResaStar.Booking.onBookPageComplete);
        };        
        
        this.onBookPageComplete = function(pResult){
            if(pResult.type > 0){
                MW.ResaStar.Display.gotoOrderPanel(pResult);
            }else{
                alert("onBookPageComplete - Une erreur a eu lieu");
            }
            MW.Waiter.hide(); 
        };
        
        this.save = function(pPOBCodeList){
             MWResaService.SaveTravel();
        };       
        
        this.getWebPlanning = function(pPOBCode){
             MWResaService.GetWebPlanning(pPOBCode,MW.ResaStar.Booking.onGetWebPlanning);        
        };
        
        this.onGetWebPlanning = function(pWebPlanningHTML){
            //open popup with web planning
            /*jQuery('#Availabities').empty();
            jQuery('#Availabities').append(pWebPlanningHTML).show();    */  
            
            jQuery('#webPlanningContent').empty().append(pWebPlanningHTML).show(); 
            //xPopupV2('Périodes disponibles','Périodes disponibles',160,220,null,jQuery('#Availabities'),jQuery('#GetWebPlanning')[0]);     
        };  
        this.GetTicketingStep = function(){
            MWResaService.GetTicketingStep(MW.ResaStar.Booking.onGetTicketingStep);
        };   
        this.onGetTicketingStep = function(pTicketingHTML){ 
            document.getElementById("MediaWelcome_Ticketing_Choice_Panel").innerHTML = pTicketingHTML;
            MW.Booking.POBookingDisplay.launchScript('Ticketing');
        };  
     }
     MW.ResaStar.Booking = new  MW.ResaStar.Booking_Class();     
