﻿//FONCTION CALLBACK
/********************************************************Localisation*******************************************/
function couchetard_essenceHandleGetDataPartnersCaa(data) {
	managePartnerCaaDB('couchetard_essence', data);

}
function couchetard_tousHandleGetDataPartnersCaa(data) {

	managePartnerCaaDB('couchetard_tous', data);
}
function circle_kHandleGetDataPartnersCaa(data) {

	managePartnerCaaDB('circle_k', data);
}

function familiprixHandleGetDataPartnersCaa(data) {

	managePartnerCaaDB('familiprix', data);
}

function lodgingHandleGetDataFindNearPoi(data) {

	mangeDataHandleTdrPoi('lodging', data);
}

function aarHandleGetDataFindNearPoi(data) {

	mangeDataHandleTdrPoi('aar', data);
}
function attractionHandleGetDataFindNearPoi(data) {

	mangeDataHandleTdrPoi('attraction', data);
}
function hertzHandleGetDataFindNearPoi(data) {
	mangeDataHandleTdrPoi('hertz', data);
}

function restaurantHandleGetDataFindNearPoi(data) {
	mangeDataHandleTdrPoi('restaurant', data);
}
function campgroundHandleGetDataFindNearPoi(data) {
	mangeDataHandleTdrPoi('campground', data);
}
function eventHandleGetDataFindNearPoi(data) {
	mangeDataHandleTdrPoi('event', data);
}
function lmrchHandleGetDataFindNearPoi(data) {
	mangeDataHandleTdrPoi('lmrch', data);
}

function gasHandleGetDataFindNearPoi(data) {
	mangeDataHandleTdrPoi('gas', data);
}

function off_caaHandleGetDataFindNearPoi(data) {

	if (data != null && typeof data == 'object') {
		var isQuebec = new Boolean(false);
		var list = [];
		for ( var i = 0; i < data.TRAVEL_ITEM.length; i++) {
			if (data.TRAVEL_ITEM[i].GENS.GEN.PHYSICAL_STATE_PROVINCE_CODE.content != 'QC') {

				list.push(data.TRAVEL_ITEM[i]);
			}

		}

		if (data.TRAVEL_ITEM.length > 0) {
			poiInMapHashTable.set('off_caa', list);
		}

		manageTableHtmlPoiEventInMap(list, 'off_caa');
		userEventBubbleInMap();

	} else {
		alert(ressourceLang.get('error_message'));
	}
}
function mangeDataHandleTdrPoi(poiType, data) {

	if (data != null && typeof data == 'object') {

		if (data.TRAVEL_ITEM.length > 0) {			
			poiInMapHashTable.set(poiType, data.TRAVEL_ITEM);
		}

		manageTableHtmlPoiEventInMap(data.TRAVEL_ITEM, poiType);
		userEventBubbleInMap();

	} else {
		alert(ressourceLang.get('error_message'));
	}

} 
function managePartnerCaaDB(poiType, data) {
	if (data != null && typeof data == 'object') {

		if (data.length > 0) {
			poiInMapHashTable.set(poiType, data);
			 //changed: ici on doit ajouter les partenaire couchetard tous avec circle cas pour les afficher dans le meme boxhtml
			if(poiType=='couchetard_tous' && poiInMapHashTable.get('circle_k').length > 0){
	        	data=data.concat(poiInMapHashTable.get('circle_k'));	        	
	        }//fin de changement
		}else{
			if(poiType=='circle_k'){
				poiInMapHashTable.set('circle_k', []);
			}
		}
		
		if(poiType!='circle_k'){
		manageTableHtmlPoiPartnersCaaDB(data, poiType);
		}
		userEventBubbleInMap();
		

	} else {
		alert(ressourceLang.get('error_message'));
	}

}
function off_caaHandleGetDataCenterCaa(data) {

	if (data != null && typeof data == 'object') {		
		poiInMapHashTable.set('off_caa_qc', data);
		manageTableHtmlPoiCenterServiceCaaDB(data, 'off_caa_qc');		
	} else {
		alert(ressourceLang.get('error_message'));
	}
}
/**
 * fonction callback du AJAX pour la liste des POI 
 * @param  :un objet data contient la reponse Ajax.  
 * @return
 */
function handleGetDataPoiList(data) {	
	if (data != null && typeof data == 'object') { 
				
		var response = data.RESPONSE;
		var listofErrors = response.ERROR;		
	 	if(listofErrors.length == 0){
 	  	  	var listFoundItems = response.FOUND_ITEMS;

 	  	 	if(listFoundItems.length > 0){
 	  	 		listofPOI = listFoundItems[0].POI; 	
 	  	 	 poiInMapHashTable.set(listofPOI[0].type,listofPOI);
 	  	 	 manageTableHtmlPoiInMap(listofPOI,listofPOI[0].type); 	  	 	 
 	  	 	 userEventBubbleInMap();		 	  	 
 	  	 	}
 	  	 	else{
	  	 		//alert('No found Item');
 	  	 	}
 		}else{
  	 		//alert('No data Found');
	 	}
		
		
	} else {
		alert(ressourceLang.get('error_message'));
	}	
}
function handleGetPhotos(data){	
	if(data!=null){				
		$('photosTdr').update("<img id='photosTdr' src='"+data+"'/>");		
	}
}
/**
 * fonction callback du AJAX pour la liste des POI dans les cas Pan et Zoom 
 * @param  :un objet data contient la reponse Ajax.  
 * @return
 */
function handleGetDataPanZoomPoiList(data) {
	
	if (data != null && typeof data == 'object') { 
				
		var response = data.RESPONSE;
		var listofErrors = response.ERROR;		
	 	if(listofErrors.length == 0){
 	  	  	var listFoundItems = response.FOUND_ITEMS;

 	  	 	if(listFoundItems.length > 0){
 	  	 		var listofPOI = listFoundItems[0].POI; 	  	
 	  	 	if(poiInMapHashTable.get('gas').length>0){
 	  	      poiInMapHashTable.get('gas').clear();
 	  	    } 
 	  	 
	  	 var xMin = map.scale.xScreen2Merc(map.view.left);
 	  	 var yMin = map.scale.yScreen2Merc(map.view.bottom);
 	  	 var xMax = map.scale.xScreen2Merc(map.view.right);
 	  	 var yMax = map.scale.yScreen2Merc(map.view.top);
 	  	 	
 	  	for(i=0; i<listofPOI.length;i++){
 	  	 	if(listofPOI[i].type=='gas'){ 	  	 	    
 	  		     if(parseFloat(listofPOI[i].long) >= parseFloat(xMin) && parseFloat(listofPOI[i].long) <= parseFloat(xMax) && parseFloat(listofPOI[i].lat) <= parseFloat(yMax) && parseFloat(listofPOI[i].lat) >= parseFloat(yMin)){ 	  	 			
 	  		    	     
 	  		    	 poiInMapHashTable.get(listofPOI[i].type).push(listofPOI[i]);
 	  	 		}
 	  	 	}else{
 	  	 	//mettre chaque POI dans sa liste de POI à l'aide d'une key de la hashtable	
 	  	 		poiInMapHashTable.get(listofPOI[i].type).push(listofPOI[i]);
 	  	 	}
 	  	 	  	 	 
 	  	 } 	  	 	  	 
			 	  	for(i=0; i<poiTypeList.length; i++){			 	  		
			 	  		if(poiTypeList[i]=='gas'){			 	  			
			 	  			manageTableHtmlPoiInMap(poiInMapHashTable.get(poiTypeList[i]),poiTypeList[i]);
			 	  			//userEventBubbleInMap();
			 	  		}else{
			 	  			if(poiInMapHashTable.get(poiTypeList[i]).length >0){			 	  			
				 	  			manageTableHtmlPoiInMap(poiInMapHashTable.get(poiTypeList[i]),poiTypeList[i]);
				 	  		}
			 	  		}
			 	  	}
			 	  	
			 	 userEventBubbleInMap();
 	  			 	  	 
 	  	 	}
 	  	 	else{
	  	 		//alert('No found Item');
 	  	 	}
 		}else{
  	 		//alert('No data Found');
	 	}
		
		
	} else {
		alert(ressourceLang.get('error_message'));
	}	
}
function handleGetDataFindNearPoi(data) {
	
	if (data != null && typeof data == 'object') { 		
		var response = data.RESPONSE;
		var listofErrors = response.ERROR;		
	 	if(listofErrors.length == 0){
 	  	  	var listFoundItems = response.FOUND_ITEMS;

 	  	 	if(listFoundItems.length > 0){
 	  	 		listofPOI = listFoundItems[0].POI; 
 	  	 	   	long =mercx2long(listofPOI[0].long);
 	  	 	   	lat =mercy2lat(listofPOI[0].lat);
 	  	 	   
 	  	 	   errorIsPresent='false';
 	  	 	}
 	  	 	else{
	  	 		//alert('No found Item');
 	  	 	errorIsPresent='true';
 	  	 	}
 		}else{
  	 		//alert('No data Found');
 			errorIsPresent='true';
	 	}
		
		
	} else {
		errorIsPresent='true';
		alert(ressourceLang.get('error_message'));
	}	
	isValid=true;
	
}
/**
 * fonction: pour recuperer le fichier pdf avec Ajax apartir du serveur. 
 * @param 
 * @return  
 */
function handleGetDataPdfPartners(data) {
	if (data != null) {
		$('partnerPdf').href = data;
	} else {
		dwr.util.setValue('d2', dwr.util.toDescriptiveString(data, 1));
	}
}
/*********************************************common_feature***************************************************/
function handleGetDataCity(data) {

	if (data != null && typeof data == 'object') {

		if (data.RESPONSE.ERROR.length == 0) {
			// ici on vide le select qui contient les POIs
			$('response').innerHTML = ' ';
			var optionsHtml = '';
			var templateOptions = new Template(
					' <option value="">#{makeSelection}</option> ');
			optionsHtml += templateOptions.evaluate(form_lang);

			for (i = 0; i < data.RESPONSE.FOUND_ITEMSCount; i++) {

				for (j = 0; j < data.RESPONSE.FOUND_ITEMS[i].POICount; j++) {

					var poiName = data.RESPONSE.FOUND_ITEMS[i].POI[j].poiName;
					var poiId = (debugGisTdr != 'Y' ? '' : "G-"
							+ data.RESPONSE.FOUND_ITEMS[i].POI[j].poiID + " | ");
					// on commence à remplir le select avec les poi retourner
					// par le serveur
					optionsHtml += '<option value="' + poiName + '" >' + poiId
							+ unescape(poiName) + '</option>';
				}

			}

			$('response').update(optionsHtml);

			if ($('response').options.length > 0) {
				$('response').options[requestRows[currentIndex].RESPONSE_SELECTED_INDEX].selected = true;
			}

		} else {
			$('response')
					.update(
							'<option value="" >' + ressourceLang
									.get('no_results') + '</option>');
		}

	} else {
		$('response')
				.update(
						'<option value="" >' + ressourceLang.get('no_results') + '</option>');
	}
	// on garde les valeurs du data dans une varaible globale
	GlobalData = data;

}
/**
 * Fonction CALLBACK: retourne des resultats pour la reponse de l'ensemble des POIs TDR
 * @param 
 * @return
 */
function handleGetTDRData(data) {

	if (data != null && typeof data == 'object') {

		// ici on vide le select qui contient les POIs
		$('response').innerHTML = ' ';
		var optionsHtml = '';
		var templateOptions = new Template(
				' <option value="">#{makeSelection}</option> ');
		optionsHtml += templateOptions.evaluate(form_lang);
     if(data.TRAVEL_ITEM.length>0){
		for (i = 0; i < data.TRAVEL_ITEM.length; i++) {

			var poiName = data.TRAVEL_ITEM[i].TRAVEL_ITEM_DISPLAY_NAME.content;
			var poiId = (debugGisTdr != 'Y' ? '' : "T-"
					+ data.TRAVEL_ITEM[i].TRAVEL_ITEM_ID.content + " | ");

			// on commence à remplir le select avec les poi retourner par le
			// serveur
			optionsHtml += '<option value="' + poiName + '" >' + poiId
					+ unescape(poiName) + '</option>';

		}

		// ici selon le navigateur on procede pour affecter la variable qui
		// contient le code html de la select
        $('response').update(optionsHtml);

		if ($('response').options.length > 0) {

			$('response').options[requestRows[currentIndex].RESPONSE_SELECTED_INDEX].selected = true;
		}
     }else{
    	$('response')
			.update(
					'<option value="" >' + ressourceLang
							.get('no_results') + '</option>');
		}
     
	} else {
		alert(ressourceLang.get('error_message'));
	}
	// on garde les valeurs du data dans une varaible globale
	GlobalDataTDR = data;
}
/**
 * Fonction CALLBACK: pour valider une location
 * 
 * @param :data retouner depuis le serveur
 * @return
 */
function handleGetDataLocationValidation(data) {

	if (suggestionsRows.length > 0) {
		suggestionsRows.clear();
	}
    
	if (data != null && typeof data == 'object') {
		errorIsPresent = 'false';		
		var error = data.RESPONSE.ERROR;
		
		if (data.RESPONSE.GEOPOINT != null && showPage == 'localisation') {
			long = data.RESPONSE.GEOPOINT.long;
			lat = data.RESPONSE.GEOPOINT.lat;
		}		
		suggestionHtml = '';
		//le cas ou la destination n'est pas valide
		if (error != null && typeof error == 'object') {

			requestRows[currentIndexLocationValidation].ERROORISPRESENT = 'true';

			if (error.LOCATION_CANDIDATES.length > 0) { // the response has a suggestion list
				var listOfSuggestion = new Array();
				var listOfAddress = error.LOCATION_CANDIDATES[0].LOCATION.ADDRESS;				
				if (listOfAddress != null && listOfAddress.length > 0) {//the candidates have address, we have to show, all info in the suggestion list	 	
					
					suggestionHtml = '<div class="errMsg"><button  class="close" onclick="hideErrMsg();" title="'
							+ ressourceLang.get('close')
							+ '" >'
							+ ressourceLang.get('close') + '</button><ul>'
					for ( var i = 0; i < listOfAddress.length; i++) {
						
						var address = listOfAddress[i];						
						var suggestionName = (address.location == '' ? ''
								: (address.location + ', '))
								+ (address.CITY[0].STATE.name == '' ? ''
										: (address.CITY[0].STATE.name + ', '))
								+ address.CITY[0].ZIPCODE.name;

						if (i <= 10) {
							var emptySuggestion = {
								CITY : '',
								STATE : '',
								RESPONSE : '',
								LOCATION_TYPE : '',
								ADDRESS : '',
								CITY_POSTALCODE : '',
								POI_ID : '',
								SHOW_DETAIL : 'false',
								ERROORISPRESENT : 'false'
							};
							emptySuggestion.CITY = address.CITY[0].name;
							emptySuggestion.STATE = statesByName
									.get(address.CITY[0].STATE.name)[0];
							emptySuggestion.CITY_POSTALCODE = address.CITY[0].ZIPCODE.name;
							emptySuggestion.ADDRESS = address.location;
							emptySuggestion.LOCATION_TYPE = $('destination_type').value;

							suggestionsRows.push(emptySuggestion);
							if (i == listOfAddress.length - 1 || i == 10) {
								suggestionHtml += '<li class="last"><a href="#" onclick="copySuggestionDestination('
										+ i
										+ ');">'
										+  unescape(suggestionName)
										+ '</a></li>';

							} else {
								suggestionHtml += '<li><a href="#" onclick="copySuggestionDestination('
										+ i
										+ ');">'
										+  unescape(suggestionName)
										+ '</a></li>';
							}
						}

					}
					suggestionHtml += '</ul></div>';

				} else {
					var listOfCities = error.LOCATION_CANDIDATES[0].LOCATION.CITY;

					suggestionHtml = '<div class="errMsg"><button  class="close" onclick="hideErrMsg();" title="'
							+ ressourceLang.get('close')
							+ '" >'
							+ ressourceLang.get('close') + '</button><ul>'

					for ( var i = 0; i < listOfCities.length; i++) {

						var city = listOfCities[i];
						var suggestionName = (city.name == '' ? ''
								: (city.name + ', '))
								+ city.STATE.name;
						if (i <= 10) {
							var emptySuggestion = {
								CITY : '',
								STATE : '',
								RESPONSE : '',
								LOCATION_TYPE : '',
								ADDRESS : '',
								CITY_POSTALCODE : '',
								POI_ID : '',
								SHOW_DETAIL : 'false',
								ERROORISPRESENT : 'false'
							};

							emptySuggestion.CITY = city.name;
							// le systeme retourne la clé de la hashtable (ex: Québec a la place de quebec).	
							emptySuggestion.STATE = statesByName
									.get(city.STATE.name)[0];
							emptySuggestion.CITY_POSTALCODE = city.name;
							emptySuggestion.LOCATION_TYPE = $('destination_type').value;
							suggestionsRows.push(emptySuggestion);
							if (i == listOfCities.length - 1 || i == 10) {
								suggestionHtml += '<li class="last"><a href="#" onclick="copySuggestionDestination('
										+ i
										+ ');">'
										+ suggestionName
										+ '</a></li>';

							} else {
								suggestionHtml += '<li><a href="#" onclick="copySuggestionDestination('
										+ i
										+ ');">'
										+ suggestionName
										+ '</a></li>';
							}
						}
					}
					suggestionHtml += '</ul></div>';

				}

			} else {
				requestRows[currentIndexLocationValidation].ERROORISPRESENT = 'true';
				suggestionHtml = '<div class="errMsg"><button  class="close" onclick="hideErrMsg();" title="'
						+ ressourceLang.get('close')
						+ '" >'
						+ ressourceLang.get('close')
						+ '</button>'
						+ getNoSuggestionHTML() + '</div>';

			}

			if (showPage == 'localisation') {
				requestRows[currentIndexLocationValidation].SHOW_DETAIL = 'false';
				var idError = 'errMsgItinerary' + currentIndexLocationValidation;
				generateLocalisationForm();
				$(idError).update(suggestionHtml);
				errorIsPresent = 'true';
			}

		} else {
			requestRows[currentIndexLocationValidation].ERROORISPRESENT = 'false';
			errorIsPresent = 'false';

		}

	} else {
		requestRows[currentIndexLocationValidation].ERROORISPRESENT = 'false';
		errorIsPresent = 'false';

	}

	if (showPage == 'localisation') {
		getMapLocPoi();
	} else {		
		requestRows[currentIndex].SHOW_DETAIL = 'false';
		getFormOrErrorShowDetail(currentIndex);
	}

}
/**
 * Fonction CALLBACK retourne des resultats pour chaque ville
 * 
 * @param
 * @return
 */

function cityPoiSearchHandleGetData(data) {
	if (data != null && typeof data == 'object') {
		if (data.RESPONSE.ERROR.length == 0) {
			$('city').update();
			var optionsHtml = '';
			var templateOptions = new Template(
					' <option value="">#{makeSelection}</option> ');
			optionsHtml += templateOptions.evaluate(form_lang);
			for (i = 0; i < data.RESPONSE.FOUND_ITEMSCount; i++) {
				for (j = 0; j < data.RESPONSE.FOUND_ITEMS[i].POICount; j++) {

					var poiName = data.RESPONSE.FOUND_ITEMS[i].POI[j].poiName;
					optionsHtml += '<option value="' + poiName + '" >'
							+ poiName + '</option>';
				}
			}

			$('city').update(optionsHtml);

		} else {
			alert(ressourceLang.get('error_type_message')
					+ data.RESPONSE.ERROR[0].type);
		}

	} else {
		alert(ressourceLang.get('error_message'));
	}

}
/**
 * Fonction CALLBACK: retourne des resultats pour la reponse de l'ensemble des
 * POIs
 * 
 * @param
 * @return
 */
function handleGetData(data) {

	if (data != null && typeof data == 'object') {

		if (data.RESPONSE.ERROR.length == 0) {
			// ici on vide le select qui contient les POIs
			$('response').innerHTML = ' ';
			var optionsHtml = '';
			var templateOptions = new Template(
					' <option value="">#{makeSelection}</option> ');
			optionsHtml += templateOptions.evaluate(form_lang);

			for (i = 0; i < data.RESPONSE.FOUND_ITEMSCount; i++) {

				for (j = 0; j < data.RESPONSE.FOUND_ITEMS[i].POICount; j++) {

					var poiName = data.RESPONSE.FOUND_ITEMS[i].POI[j].poiName;
					var poiId = (debugGisTdr != 'Y' ? '' : "G-"
							+ data.RESPONSE.FOUND_ITEMS[i].POI[j].poiID + " | ");
					// on commence à remplir le select avec les poi retourner
					// par le serveur
					optionsHtml += '<option value="' + poiName + '" >' + poiId
							+ unescape(poiName) + '</option>';
				}

			}

			$('response').update(optionsHtml);

			if (locationTypeHashTable
					.get(requestRows[currentIndex].LOCATION_TYPE) == 'Poi') {
				if ($('response').options.length > 0) {
					$('response').options[requestRows[currentIndex].RESPONSE_SELECTED_INDEX].selected = true;
				}

			}

		} else {
			$('response')
					.update(
							'<option value="" >' + ressourceLang
									.get('no_results') + '</option>');
		}

	} else {
		$('response')
				.update(
						'<option value="" >' + ressourceLang.get('no_results') + '</option>');
	}
	// on garde les valeurs du data dans une varaible globale
	GlobalData = data;

}    
/**
 * Fonction CALLBACK: retourne des resultats pour la reponse de l'ensemble des
 * centres de services
 * 
 * @param
 * @return
 */
function handleGetDataserviceCenters(data) {

	if (data != null && typeof data == 'object') {

		if (data.length > 0) {

			// ici on vide le select qui contient les POIs
			$('response').update();
			var optionsHtml = '';
			var templateOptions = new Template(
					' <option value="">#{makeSelection}</option> ');
			optionsHtml += templateOptions.evaluate(form_lang);

			for (i = 0; i < data.length; i++) {

				var poiName = data[i].servicecentername;
				// on commence à remplir le select avec les poi retourner
				// par le serveur
				optionsHtml += '<option value="' + poiName + '" >'
						+ unescape(poiName) + '</option>';
			}

			$('response').update(optionsHtml);

			if (locationTypeHashTable
					.get(requestRows[currentIndex].LOCATION_TYPE) == 'Poi') {
				if ($('response').options.length > 0) {
					$('response').options[requestRows[currentIndex].RESPONSE_SELECTED_INDEX].selected = true;
				}
			}

		}

	} else {
		alert(ressourceLang.get('error_message'));
	}
	GlobalData = data;
}

/**
 * Fonction CALLBACK: retourne des resultats pour la reponse de postalCode
 * 
 * @param  codepostal 
 * @return object postalcode
 */
function handleGetDataPostalCode(data) {      
	if (data != null && typeof data == 'object'){		
		//alert(dwr.util.toDescriptiveString(data,10));
		if(data.latitude==0 && data.longitude==0){
			currentIndexLocationValidation=currentIndex;
			adressLocationValidationRequest(currentIndex);
		}else{
			 long=data.longitude;
			 lat= data.latitude;					
			 errorIsPresent='false'	;
			 getMapLocPoi();
	   }
	} else {		
		alert(ressourceLang.get('error_message'));		
		
	}
	
}

/***********************************************Itineraire**********************************************************/
/**
 * fonction: pour recuperer le tracé routier avec Ajax apartir du serveur. 
 * @param 
 * @return  
 */
function handleGetDataDirections(data) {
	
	if (data != null && typeof data == 'object') {
		
		if (data.RESPONSE.ERROR.length == 0){		
			requestRows[currentIndex].SHOW_DETAIL='false';
			 generateItineraryForm();
				for (i = 0; i < data.RESPONSE.DIRECTIONSCount; i++) {
					
					var patt=new RegExp("\\|\\d+\\|\\d+\\.\\d+\\|");	
					directions=  data.RESPONSE.DIRECTIONS[i].text;					
					var j=0;
					var distance = directions.replace(/\|\d+\|(\d+\.\d+)\|.*/,"$1");
					directions=directions
						.replace(/\| \| \|/g, "")
						.replace(/\|\d+\|\d+\.\d+\|/,getSegment(j,distance)+"<ol>");
					while(patt.test(directions)){
						j++;						
						var distance = directions.replace(/.*?\|\d+\|(\d+\.\d+)\|.*/,"$1");		
						directions=directions
							.replace(/\|\d+\|\d+\.\d+\|/,"</li></ol>"+getSegment(j,distance)+"<ol>");				    
					 
					}
					directions=directions
					.replace(/\d+\|/, "<li>")
				    .replace(/\d+\|/g, "</li><li>")
				    .replace(/\|/g, "</li></ol>")
				    .replace(/%27/g,"'");				     
					$('directionsDiv').innerHTML=  directions ;					
					var time =  new Date(0,0,0,0,0,data.RESPONSE.TOTALTIME[i].text) ;					
					var jour=time.getDay();
					var hour = time.getHours()+ (jour*24) ;
					var minute =time.getMinutes();
					

					newImage = 'url('+data.RESPONSE.MAP_IMAGE[i].url+') center top no-repeat';
					$('mapCtn').style.background = newImage;  
					$('indicationsRoute').innerHTML='<ul><li><strong>'+
					ressourceLang.get('quickroute_totaltime')+'</strong>: ' +
					hour+
					ressourceLang.get('quickroute_hours')+
					minute+ressourceLang.get('quickroute_minutes')+
					'</li>'+
		            '<li><strong>'+ressourceLang.get('quickroute_totalmiles')+'</strong>: '+
		            roundNumber(data.RESPONSE.TOTALMILES[i].text,2)+
		            ressourceLang.get('quickroute_km')+' (' +
		            roundNumber(data.RESPONSE.TOTALMILES[i].text/1.61,2) + 
		            ressourceLang.get('quickroute_miles')+')</li>'+		            
		            '</ul>';
					showHidePoi('fullTopBoxItineraire','minTopBoxItineraire');
				}
		}else{
			//alert(dwr.util.toDescriptiveString(data.RESPONSE.ERROR,10));
			requestRows[currentIndex].SHOW_DETAIL='true';
			alert(ressourceLang.get('error_message'));			
		}

	} else {
		alert(ressourceLang.get('error_message'));
	}
}
/**
 * fonction: pour recuperer le fichier pdf avec Ajax apartir du serveur. 
 * @param 
 * @return  
 */
function handleGetDataPdfIndications(data) {     
	if (data != null){		
		window.open(data, "caattp");
	} else {
		alert(ressourceLang.get('error_message'));
	}
}	

function handlePrintMapLocalisation(data){	
		
	if (data != null){
		
		
		window.open(data, "Carte");
			
		
	} else {
		alert(ressourceLang.get('error_message'));
	}
}

function caaiprHandlerInfoById(data){	
	if (data != null && typeof data == 'object') {
				if(data.longitude!=0 && data.latitude!=0 ){
					requestRows[0].CITY =data.city;
					requestRows[0].STATE ='quebec';//poiInMapHashTable.get(poiType)[index].STATE;
					requestRows[0].RESPONSE ='';
					requestRows[0].LOCATION_TYPE='Address';
					var address=(data.addressstreet!='' ? data.addressnumber+' '+ data.addressstreet:data.inaddressstreet);
					requestRows[0].ADDRESS =address;
					requestRows[0].CITY_POSTALCODE =(data.zipcode!='' && data.zipcode!=null ? data.zipcode:'');
					requestRows[0].POI_ID ='';
					requestRows[0].RESPONSE_SELECTED_INDEX = 0;
					requestRows[0].CITY_SELECTED_INDEX = 0;
					requestRows[0].LONG =data.longitude;
					requestRows[0].LAT = data.latitude;
					requestRows[0].DATE = '';
					requestRows[0].SHOW_DETAIL = 'false';
					requestRows[0].ERROORISPRESENT = 'false';	
					long=requestRows[0].LONG;
					lat= requestRows[0].LAT;
					onloadMap = 'N'; 
					errorIsPresent='false'	;	
					getMapLocPoi();
					
			}else {
				alert(ressourceLang.get('error_message'));
			}
		
	}else {
		alert(ressourceLang.get('error_message'));
	}
}

function caaiprHandlerRegionById(data){	
	if (data != null && typeof data == 'object') {
		if(data.longitude!=0 && data.latitude!=0 ){
			long=data.longitude;
			lat= data.latitude;
			errorIsPresent='false';	
			getMapLocPoi();
			var xMin = map.scale.xScreen2Merc(map.view.left);
			var yMin = map.scale.yScreen2Merc(map.view.bottom);
			var xMax = map.scale.xScreen2Merc(map.view.right);
			var yMax = map.scale.yScreen2Merc(map.view.top);		
			RegionVincitySearchInMap(mercx2long(xMin),mercy2lat(yMin),mercx2long(xMax),mercy2lat(yMax));
		}else {
			alert(ressourceLang.get('error_message'));
		}
	}else {
		alert(ressourceLang.get('error_message'));
	}
}


function caaiprHandlegetIprVincitySearch(data){	
	if (data != null && typeof data == 'object') {
	   //alert(dwr.util.toDescriptiveString(data,10));		
	   poiInMapHashTable.set('info',data);
	   userEventBubbleInMap();
	}else {
		alert(ressourceLang.get('error_message'));
	}
}

function RegionVincitySearchInMap(longMin, latMin, longMax, latMax){	
	isForm = false;
	CaaiprDbRegionsService.getIprVincitySearch(longMin, latMin, longMax,
			latMax, {
				callback : caaiprHandlegetIprVincitySearch,
				async : false
			});	
}


	

