
var defaultDwrPath = "/dwr";

function getHotelDescription(autocompleter, supplierAccomCode, supplierCode) {
	HotelServiceFacade._path = defaultDwrPath;	
	HotelServiceFacade.getHotelDescriptionBySupplierAccomCode(supplierAccomCode, supplierCode, function(data) {
        autocompleter.setChoices(data)
    });
	
}

/*
 ***************************************************
 * Fonctions utilisées dans la page results-list.jsp
 ***************************************************
 */
function processTri(sortingMode, sortingDirection){
    var triForm = document.getElementById("triForm");
    var triFormSortingMode = document.getElementById("sortingMode");
    var triFormSortingDirection = document.getElementById("sortingDirection");
    triFormSortingMode.value = sortingMode;
    triFormSortingDirection.value = sortingDirection;
	
	var isListView = triForm.isListView;
	var mapViewStyleVisibility = document.getElementById("mapview").style.visibility;
	if (mapViewStyleVisibility == "visible") {
		isListView.value = false;
	} else {
		isListView.value = true;
	}
	
    triForm.submit();
}

function processFilterForm(){
	showWaitDisplay();
	var hotelsResultsForm = document.getElementById("hotelsResultsForm");
	var isListView = hotelsResultsForm.isListView;
	
	var mapView = document.getElementById("mapview");
	if (mapView!=null) {
    	var mapViewStyleVisibility = document.getElementById("mapview").style.visibility;
    	if (mapViewStyleVisibility == "visible") {
    		isListView.value = false;
    	} else {
    		isListView.value = true;
    	}
	}
	hotelsResultsForm.submit();
}

function processFilterActivation(filterActivated){
	showWaitDisplay();
	var filterActivationForm = document.getElementById("filterActivationForm");
    var filterActivationFormFilterActivated = document.getElementById("filterActive");
    if (filterActivated == "false") {
        filterActivationFormFilterActivated.value = false;
    } else {
        filterActivationFormFilterActivated.value = true;
    }
	
	var isListView = filterActivationForm.isListView;
	var mapView = document.getElementById("mapview");
	if (mapView!=null){
	    var mapViewStyleVisibility = document.getElementById("mapview").style.visibility;
    	if (mapViewStyleVisibility == "visible") {
    		isListView.value = false;
    	} else {
    		isListView.value = true;
    	}
	}
    filterActivationForm.submit();
}

function resetFilterForm(){
    var filterForm = document.getElementById("hotelsResultsForm");
    if (filterForm != null) {
        filterForm.elements.filterHotelName.value = '';
        if (filterForm.elements.filterOnRequest != null) {
            filterForm.elements.filterOnRequest.value = '';
        }
        if (filterForm.elements.filterSupplierCode != null) {
            filterForm.elements.filterSupplierCode.selectedIndex = 0;
        }
        filterForm.elements.filterCategory.selectedIndex = 0;
        filterForm.elements.filterSituation.selectedIndex = 0;
		if (filterForm.elements.filterDistance != null) {
			filterForm.elements.filterDistance.selectedIndex = 0;
		}
        filterForm.elements.filterBudget.selectedIndex = 0;
        filterForm.elements.filterMealPlan.selectedIndex = 0;
        for (var i = 0; i < filterForm.elements.length; i++) {
            if (filterForm.elements[i].id.indexOf("filterFacilities") > -1) {
                var chkBox = filterForm.elements[i];
                chkBox.checked = false;
            }
            if (filterForm.elements[i].id.indexOf("filterOnRequest") > -1) {
                var radioBox = filterForm.elements[i];
                if (radioBox.value == "true") {
                    radioBox.checked = false;
                }
                else {
                    radioBox.checked = true;
                }
            }
        }
        filterForm.razFilter.value = "true";
        filterForm.submit();
    }
}

function refreshResultList(pageId, nbOfResult) {
	var pageForm = document.getElementById("pageForm");
	pageForm.nbOfResultPerPage.value = nbOfResult;
	showWaitDisplay();
    pageForm.submit();
}

function displayPage(pageId) {
    var pageForm = document.getElementById("pageForm");
    pageForm.page.value = pageId;
	showWaitDisplay();
    pageForm.submit();
}

function switchToResult(accomId, newResultId, newSupplierAccomCode){
	
    // Retrouve le champ caché du conteneur contenant la valeur du result sélectionné
    var hiddenSelectedResult = document.getElementById("currentlySelectedResultId_" + accomId);
    
    if (hiddenSelectedResult != null) {
        hiddenSelectedResult.value = newResultId;
        newSupplierAccomCodeInput = document.getElementById("supplierAccomCodeInput_" + newResultId);
        
        if (newSupplierAccomCodeInput != null) {
            newSupplierAccomCodeInput.value = newSupplierAccomCode;
        }
    }
}

function showTableRowElement(elementObject){ 
	if (elementObject != null){
		elementObject.style.visibility="visible";
		var appname = window.navigator.appName;
		if (appname == "Microsoft Internet Explorer"){
			elementObject.style.display="block";
		}else{
			elementObject.style.display="table-row";  /* si on met un display-block, l'affichage n'est pas bon dans firefox*/
		}
	}				
}

function showViewTypeResultsTab(tabName){
	var form = document.getElementById("pageForm");
	if (form != null) {
		var isListView = form.isListView;
		if (tabName == "mapview"){
			//affichage / masquage
			showElement('mapview');
			hideElement('listview');
			showElement('displayableMap');
			
			showElement('aide');
			showElement('recentre');
			
			//mise à jour style
			changeElementCssName("mapviewtab", "resultstabactive");
			changeElementCssName("listviewtab", "resultstabdisabled");
			
			isListView.value="false";
			loadGoogleMap();
		} else if (tabName == "listview"){
		    
			//affichage / masquage
			hideElement('mapview');
			showElement('listview');
			hideElement('displayableMap');
			
			hideElement('aide');
			hideElement('recentre');
			
			//mise à jour style
			changeElementCssName("mapviewtab", "resultstabdisabled");
			changeElementCssName("listviewtab", "resultstabactive");
			
			isListView.value="true";
		}
	}
}

// Traitement du bouton "RESERVER"
function launchBooking(accomId){
	// Retrouve le champ caché du conteneur contenant la valeur du result sélectionné
    var hiddenSelectedResult = document.getElementById("currentlySelectedResultId_" + accomId);
    var resultId = hiddenSelectedResult.value;
    
    var supplierCodeInput = document.getElementById("supplierCodeInput_" + resultId);
    var supplierCode = supplierCodeInput.value.toUpperCase();
    
    var supplierAccomCodeInput = document.getElementById("supplierAccomCodeInput_" + resultId);
    var supplierAccomCode = supplierAccomCodeInput.value;
    
    var form = document.getElementById("bookingForm");
    form.accomId.value = accomId;
    form.supplierCode.value = supplierCode;
    form.resultId.value = resultId;
    form.supplierAccomCode.value = supplierAccomCode;
    
    //affichage du message d'attente
//    setTimeout("showWaitDisplay()"); 
  showWaitDisplay();
  
    form.submit();
}



