﻿document.write("<script type='text/javascript' src='dwr/interface/GisPoiSearchService.js'></script>");
document.write("<script type='text/javascript' src='dwr/interface/GisQuickMapService.js'></script>");
document.write("<script type='text/javascript' src='dwr/interface/GisQuickRouteService.js'></script>");
document.write("<script type='text/javascript' src='dwr/interface/GisLocationValidationService.js'></script>");
document.write("<script type='text/javascript' src='dwr/interface/GisVicinitySearchService.js'></script>");
document.write("<script type='text/javascript' src='dwr/interface/TdrEventSearchService.js'></script>");
document.write("<script type='text/javascript' src='dwr/interface/CaaDbPartnersService.js'></script>");
document.write("<script type='text/javascript' src='dwr/interface/CaaDbPostalCodeService.js'></script>");
document.write("<script type='text/javascript' src='dwr/interface/CaaiprDbInfosService.js'></script>");
document.write("<script type='text/javascript' src='dwr/interface/CaaiprDbRegionsService.js'></script>");
document.write("<script type='text/javascript' src='dwr/interface/CaaTTpStatisticsService.js'></script>");
document.write("<script type='text/javascript' src='dwr/engine.js'></script>");
document.write("<script type='text/javascript' src='dwr/util.js'></script>");	
document.write("<script type='text/javascript' src='js/script_aculo_us/lib/prototype.js' ></script>");
document.write("<script type='text/javascript' src='js/script_aculo_us/scriptaculous.js' ></script>");
document.write("<script src='js/i18n_fr.js' type='text/javascript'></script>");
document.write("<script src='js/template.js' type='text/javascript'></script>");
document.write("<script src='js/states.js' type='text/javascript'></script>");
document.write("<script src='http://publishingwebservices.aaa.com/PublishingDynamicMap/ttp_userPOI.js?t=$TIMESTAMP$' type='text/javascript'></script>");



// global var
var suggestionsRows = [];
var requestRows = [];
var GlobalData = '';
var GlobalDataTDR = '';
var showPage = '';
var errorIsPresent = 'false';
var suggestionHtml = '';
var currentIndexLocationValidation = 0;
var currentIndex=0;
var newImage = null;
var isForm = new Boolean(false);
//cherche une liste de parametres dans l'url
var queryString =window.top.location.search.substring(1);
var debugGisTdr="N";
var isInfo =new Boolean(false);

/******************************************************Gestion des formulaires ******************************************/
/**
 * fonction pour cacher les champs de fomulaire
 * 
 * @param
 * @return
 */
function hideForm(){
	$('cityPostalCodePragraph','statCountryPragraph','adressPragraph','cityPragraph','poiResponseWaitPragraph','poiResponsePragraph','eventDatePragraph').invoke('hide');
}
/**
 * fonction pour montrer les champs du formulaires selon le type de destination
 * 
 * @param
 * @return
 */
function displayForm(){
	
	// cacher tous les champs du formulaire sauf le champ type de destination
	hideForm();
	// effacer toutes les resultats dans le select de la reponse
	// (initialisation)
	if ($('response').options.length > 0) {
		removeSelectOptions('response');
	}	
	if ($('city').options.length > 0) {
		removeSelectOptions('city');
	}
	$('poiResponseWaitLabel').innerHTML = destinationTypeHashTable.get($('destination_type').value);
	if ($('destination_type').value == 'Ville') {

		$('cityPostalCodePragraph').style.display = 'block';
		$('statCountryPragraph').style.display = 'block';

	} else if ($('destination_type').value == 'Address') {

		$('adressPragraph').style.display = 'block';
		$('cityPostalCodePragraph').style.display = 'block';
		$('statCountryPragraph').style.display = 'block';

	}
	// pour chaque type de destination montrer les champs necessaires et on
	// execute une fonction Ajax
	else if ($('destination_type').value == 'airport') {
		
		$('statCountryPragraph').style.display = 'block';
		$('poiResponsePragraph').style.display = 'block';			
		$('poiResponseLabel').innerHTML = destinationTypeHashTable
				.get($('destination_type').value);
		poiSearchSendRequest();
	} else if ($('destination_type').value == 'restaurant') {
		// chercher l'ensemble des villes pour chaque province
		$('statCountryPragraph').style.display = 'block';
		$('cityPragraph').style.display = 'block';
		$('poiResponsePragraph').style.display = 'block';
		$('poiResponseLabel').innerHTML = destinationTypeHashTable
				.get($('destination_type').value);
		cityPoiSearchSendRequest();
	} else if ($('destination_type').value == 'attraction') {
		$('statCountryPragraph').style.display = 'block';
		$('poiResponsePragraph').style.display = 'block';
		$('poiResponseLabel').innerHTML = destinationTypeHashTable.get($('destination_type').value);
		poiSearchSendRequest();
	} else if ($('destination_type').value == 'event') {
		$('statCountryPragraph').style.display = 'block';
		$('poiResponsePragraph').style.display = 'block';
		$('eventDatePragraph').style.display = 'block';
		Calendar.setup( {
			inputField : "eventDate", // id of the input field
			ifFormat : "%Y-%m-%d", // format of the input field
			button : "eventDateImg", // trigger for the calendar (button ID)
			align : "Bl", // alignment (defaults to "Bl")
			singleClick : true,
			onUpdate : catcalc
		});
		Calendar.setup( {
			inputField : "eventDateto", // id of the input field
			ifFormat : "%Y-%m-%d", // format of the input field
			button : "eventDateImgto", // trigger for the calendar (button ID)
			align : "Bl", // alignment (defaults to "Bl")
			singleClick : true,
			onUpdate : catcalc
		});
		
		$('poiResponseLabel').innerHTML = destinationTypeHashTable
				.get($('destination_type').value);
		$('response').update(
				'<option value="" > ' + ressourceLang
						.get('choose_date') + '</option>');
		poiTDRSearchSendRequest();
	} else if ($('destination_type').value == 'lodging') {
		// chercher l'ensemble des villes pour chaque province
		$('statCountryPragraph').style.display = 'block';
		$('cityPragraph').style.display = 'block';
		$('poiResponsePragraph').style.display = 'block';		
		$('poiResponseLabel').innerHTML = destinationTypeHashTable
				.get($('destination_type').value);
		cityPoiSearchSendRequest();
	} else if ($('destination_type').value == 'statepark') {
		$('statCountryPragraph').style.display = 'block';
		$('poiResponsePragraph').style.display = 'block';
		$('poiResponseLabel').innerHTML = destinationTypeHashTable
				.get($('destination_type').value);
		poiSearchSendRequest();
	} else if ($('destination_type').value == 'port') {
		$('statCountryPragraph').style.display = 'block';
		$('poiResponsePragraph').style.display = 'block';
		$('poiResponseLabel').innerHTML = destinationTypeHashTable
				.get($('destination_type').value);
		poiSearchSendRequest();
	} else if ($('destination_type').value == 'hospital') {
		$('statCountryPragraph').style.display = 'block';
		$('poiResponsePragraph').style.display = 'block';
		$('poiResponseLabel').innerHTML = destinationTypeHashTable
				.get($('destination_type').value);
		poiSearchSendRequest();
	} else if ($('destination_type').value == 'sports Venue') {
		$('statCountryPragraph').style.display = 'block';
		$('poiResponsePragraph').style.display = 'block';
		$('poiResponseLabel').innerHTML = destinationTypeHashTable.get($('destination_type').value);
		poiSearchSendRequest();
	} else if ($('destination_type').value == 'golf') {
		$('statCountryPragraph').style.display = 'block';
		$('poiResponsePragraph').style.display = 'block';
		$('poiResponseLabel').innerHTML = destinationTypeHashTable
				.get($('destination_type').value);
		poiSearchSendRequest();
	} else if ($('destination_type').value == 'ski') {
		$('statCountryPragraph').style.display = 'block';
		$('poiResponsePragraph').style.display = 'block';
		$('poiResponseLabel').innerHTML = destinationTypeHashTable
				.get($('destination_type').value);
		poiSearchSendRequest();
	} else if ($('destination_type').value == 'military') {
		$('statCountryPragraph').style.display = 'block';
		$('poiResponsePragraph').style.display = 'block';
		$('poiResponseLabel').innerHTML = destinationTypeHashTable
				.get($('destination_type').value);
		poiSearchSendRequest();
	} else if ($('destination_type').value == 'univ') {
		$('statCountryPragraph').style.display = 'block';
		$('poiResponsePragraph').style.display = 'block';
		$('poiResponseLabel').innerHTML = destinationTypeHashTable
				.get($('destination_type').value);
		poiSearchSendRequest();
	} else if ($('destination_type').value == 'nationalpark') {
		$('statCountryPragraph').style.display = 'block';
		$('poiResponsePragraph').style.display = 'block';
		$('poiResponseLabel').innerHTML = destinationTypeHashTable
				.get($('destination_type').value);
		poiSearchSendRequest();
	} else if ($('destination_type').value == 'lmrch') {
		$('statCountryPragraph').style.display = 'block';
		$('poiResponsePragraph').style.display = 'block';
		$('poiResponseLabel').innerHTML = ressourceLang.get('aaa_caa');
		$('poiResponseWaitLabel').innerHTML = ressourceLang.get('aaa_caa');
		poiTDRSearchSendRequest();
	}	
	if(requestRows[currentIndex].LOCATION_TYPE!=$('destination_type').value){
		requestRows[currentIndex].RESPONSE_SELECTED_INDEX=0;
		
	}
	
}
/**
 * Cette fonction passe la destination d'un champs simple aux champs détaillés
 * 
 * @param index
 * @return
 */
function showDetail(index) {
	currentIndex = index;
	var isAddress = new Boolean(false);
	for (i = 0; i < requestRows.length; i++) {
		if (requestRows[i].SHOW_DETAIL == 'true') {
			currentIndexLocationValidation = i;
			saveItinerary($('response').value, $('stat').value,
					$('city').value, $('destination_type').value,
					$('address').value, $('city_postalCode').value, 'false', i,
					'modifier', $('response').selectedIndex,
					$('city').selectedIndex, $('eventDate').value,$('eventDateto').value);

			if (($('destination_type').value == 'Address' || $('destination_type').value == 'Ville')
					&& ($('city_postalCode').value != '' || $('address').value != '')) {
				isAddress = true;				
				currentIndexLocationValidation = i;
				adressLocationValidationRequest(currentIndexLocationValidation);
			}
		}

		requestRows[i].SHOW_DETAIL = 'false';

		if (showPage == 'localisation'
				&& locationTypeHashTable.get(requestRows[i].LOCATION_TYPE) == 'Poi') {
			findNearPoiVicinitySearchSendRequest(15);

		}
	}
	if (isAddress == false) {
		getFormOrErrorShowDetail(index);
	}
}

/**
 * Cette fonction passe la destination des champs détaillés à un champs simple
 * 
 * @param
 * @return
 */
function hideDetail() {
	for (i = 0; i < requestRows.length; i++) {
		if (requestRows[i].SHOW_DETAIL == 'true') {
			if (requestRows[i].ERROORISPRESENT == 'false') {
				saveItinerary($('response').value, $('stat').value,
						$('city').value, $('destination_type').value,
						$('address').value, $('city_postalCode').value,
						'false', i, 'modifier', $('response').selectedIndex,
						$('city').selectedIndex, $('eventDate').value, $('eventDateto').value);
			}
		}
		requestRows[i].SHOW_DETAIL = 'false';
		requestRows[i].ERROORISPRESENT == 'false';
	}
}
/**
 * fonction: pour sauver la destination dans l'itinaraire.
 * 
 * @param :
 *            les champs de fomulaire choisie par l'utlisateur index : le numero
 *            de la ligne courante du tableau ResponseSelectedIndex: contient le
 *            numero de l'option select qui contient un POI (aide � chercher le
 *            poiID)
 * @return
 */
function saveItinerary(RESPONSE, STATE, CITY, LOCATIONTYPE, ADDRESS,
		POSTALCODE, add, index, showForm, responseSelectedIndex,
		citySelectedIndex, eventDate,eventDateto) {
  /* if(LOCATIONTYPE=='lmrch' && STATE=='quebec'){
    if (GlobalData.length >0){
	   for(var i=0;i< GlobalData.length; i++){
		  
		   if(GlobalData[i].servicecentername==RESPONSE){
			   
			   	requestRows[index].CITY = GlobalData[i].city ;			   
				requestRows[index].STATE = STATE;				
				requestRows[index].RESPONSE = RESPONSE;				
				requestRows[index].LOCATION_TYPE = LOCATIONTYPE;				
				requestRows[index].ADDRESS ='';//GlobalData[i].adressnumber+" "+GlobalData[i].street;				
				requestRows[index].CITY_POSTALCODE = GlobalData[i].postalcode.replace(
						/(\w\d\w)-*(\d\w\d)/, '$1 $2');
				requestRows[index].SHOW_DETAIL = 'true';
				requestRows[index].RESPONSE_SELECTED_INDEX = i+1;
				requestRows[index].CITY_SELECTED_INDEX = (citySelectedIndex == null ? 0
						: citySelectedIndex);
				alert(dwr.util.toDescriptiveString(requestRows[index],10));
		   }
	   }
	 }
   }else*/
	{
		requestRows[index].CITY = CITY;
		requestRows[index].STATE = STATE;
		requestRows[index].RESPONSE = RESPONSE;
		requestRows[index].LOCATION_TYPE = LOCATIONTYPE;
		requestRows[index].ADDRESS = ADDRESS;
		requestRows[index].CITY_POSTALCODE = POSTALCODE.replace(
				/(\w\d\w)-*(\d\w\d)/, '$1 $2');
		requestRows[index].SHOW_DETAIL = 'true';
		requestRows[index].RESPONSE_SELECTED_INDEX = responseSelectedIndex;
		requestRows[index].CITY_SELECTED_INDEX = (citySelectedIndex == null ? 0
				: citySelectedIndex);
   }
	
    
	if (responseSelectedIndex > '0') {
		if (TypeTdrOrGisHashTable.get(LOCATIONTYPE) == 'TDR'){
			if(LOCATIONTYPE=='lmrch' && STATE=='quebec'){
				if(GlobalData[(responseSelectedIndex - 1)]==null){
					responseSelectedIndex=2;
				}
					requestRows[index].LONG = (GlobalData[(responseSelectedIndex - 1)].longitude==null ? 0:GlobalData[(responseSelectedIndex - 1)].longitude);
					requestRows[index].LAT = (GlobalData[(responseSelectedIndex - 1)].latitude==null ? 0:GlobalData[(responseSelectedIndex - 1)].latitude);
				
			}else{
				requestRows[index].DATE = eventDate;
				requestRows[index].DATETO = eventDateto;
				/*if(GlobalDataTDR[(responseSelectedIndex - 1)]==null){
					//alert("back");
					responseSelectedIndex=1;
					
				}*/	
				if(LOCATIONTYPE=='event'){
					
				     requestRows[index].DATE_FROM = GlobalDataTDR.TRAVEL_ITEM[(responseSelectedIndex - 1)].OPERATING_DATES.OPERATING_DATE[0].FROM_DATE.content;
				     requestRows[index].DATE_TO = GlobalDataTDR.TRAVEL_ITEM[(responseSelectedIndex - 1)].OPERATING_DATES.OPERATING_DATE[0].TO_DATE.content;
				}
				
					requestRows[index].LONG = (GlobalDataTDR.TRAVEL_ITEM[(responseSelectedIndex - 1)].GENS.GEN.LONGITUDE==null ? 0:GlobalDataTDR.TRAVEL_ITEM[(responseSelectedIndex - 1)].GENS.GEN.LONGITUDE.content);
					requestRows[index].LAT = (GlobalDataTDR.TRAVEL_ITEM[(responseSelectedIndex - 1)].GENS.GEN.LATITUDE==null ? 0:GlobalDataTDR.TRAVEL_ITEM[(responseSelectedIndex - 1)].GENS.GEN.LATITUDE.content);
				
					
			}
		} else {
			
			requestRows[index].POI_ID = GlobalData.RESPONSE.FOUND_ITEMS[0].POI[(responseSelectedIndex - 1)].poiID;
			
		}

	}

}
/**
* Cette fonction retourne un fieldset du formulaire de l'index courant soit un fieldset ouvert ou fermé  
* @param : objet contient les informations pour la destination et l'index du fieldset courant
* @return fieldset du formulaire (templateFormfld)
*/
function getDestinationFieldset(requestRow,index){
	
	var colorPin;
	var depart;
	var data = '';
	var moveUp_dsbl = '';
	var moveDown = '';
	var dsblClassStyle = "dsbl";
	var permuteItineraryUp='';
	var permuteItineraryDown='';

	if (index == 0) {
		moveDownStyle='moveDown_dsbl';
		moveUpStyle='moveUp_dsbl';
		
		if (showPage == 'localisation') {
			colorPin = 'bleuPin';
			depart = '';
			if (requestRows[index].ERROORISPRESENT == 'false') {

				data = ressourceLang.get('click_enter_location');
				dsblClassStyle = "dsbl";
			} else {
				data = ressourceLang.get('location_not_found');
				dsblClassStyle = "errorFld";

			}
		} else {
			colorPin = 'greenPin';
			depart = ressourceLang.get('depart');	
			if (requestRows[index].ERROORISPRESENT == 'false') {

				data = ressourceLang.get('click_depart_location');
				dsblClassStyle = "dsbl";
			} else {
				data = ressourceLang.get('location_not_found');
				dsblClassStyle = "errorFld";

			}
		}

		

	} else if (index == requestRows.length - 1) {
		colorPin = 'redPin';
		depart = ressourceLang.get('end');
		moveDownStyle='moveDown_dsbl';
		moveUpStyle='moveUp_dsbl';
		
		if (requestRows[index].ERROORISPRESENT == 'false') {
			data = ressourceLang.get('click_for_location');
			dsblClassStyle = "dsbl";
		} else {
			data = ressourceLang.get('location_not_found');
			dsblClassStyle = "errorFld";
		}

	} else {
		moveDownStyle='moveDown_dsbl';
		moveUpStyle='moveUp_dsbl';
		if (showPage == 'localisation') {
			colorPin = 'bleuPin';
		}else{	
		colorPin = 'yellowPin';
		}
		depart = '';
		if (requestRows[index].ERROORISPRESENT == 'false') {
			data = ressourceLang.get('click_for_location');
			dsblClassStyle = "dsbl";
		} else {
			data = ressourceLang.get('location_not_found');
			dsblClassStyle = "errorFld";
		}

	}
	var isMoveDsbl='false';
	var messageAddress="";
	if(requestRows[index].RESPONSE != '' && locationTypeHashTable.get(requestRows[index].LOCATION_TYPE)=='Poi' && requestRows[index].ERROORISPRESENT=='false' ){
		
		data = (requestRows[index].RESPONSE == '' ? '' : unescape(requestRows[index].RESPONSE)) +			  
			   (requestRows[index].CITY == '' ? '' : ", " + requestRows[index].CITY) +
			   (requestRows[index].STATE == '' ? '' : ", " + states.get(requestRows[index].STATE)[0]);		
		isMoveDsbl='true';
		
	}else if(requestRows[index].CITY_POSTALCODE != '' && requestRows[index].ADDRESS =='' && locationTypeHashTable.get(requestRows[index].LOCATION_TYPE)=='Address' && requestRows[index].ERROORISPRESENT=='false'){ 	
		//le cas ou on a juste le code postal 
		//data = (requestRows[index].CITY_POSTALCODE == '' ? '' : requestRows[index].CITY_POSTALCODE.replace(/(\w\d\w) (\d\w\d)/, '$1'))+ 
		data = (requestRows[index].CITY_POSTALCODE == '' ? '' : requestRows[index].CITY_POSTALCODE)+
		   (requestRows[index].CITY == '' ? '' : ", " + requestRows[index].CITY) +
		   (requestRows[index].STATE == '' ? '' : ", " + states.get(requestRows[index].STATE)[0]);
		isMoveDsbl='true';
		messageAddress="<p align='center'>"+ressourceLang.get('message_address')+"</p>"
	}else if(requestRows[index].ADDRESS !='' && locationTypeHashTable.get(requestRows[index].LOCATION_TYPE)=='Address' && requestRows[index].ERROORISPRESENT=='false'){ 	
			  
		data = (requestRows[index].CITY_POSTALCODE == '' && requestRows[index].ADDRESS == '' ? '' : requestRows[index].ADDRESS)+
		   //(requestRows[index].CITY_POSTALCODE == '' ? '' : ", " +requestRows[index].CITY_POSTALCODE.replace(/(\w\d\w) (\d\w\d)/, '$1'))+
		   (requestRows[index].CITY_POSTALCODE == '' ? '' : ", " +requestRows[index].CITY_POSTALCODE)+
		   (requestRows[index].CITY == '' ? '' : ", " + requestRows[index].CITY) +
		   (requestRows[index].STATE == '' ? '' : ", " + states.get(requestRows[index].STATE)[0]);
		isMoveDsbl='true';
	}
	if(isMoveDsbl=='true'){
		
		if (index == 0) {
			moveDownStyle='moveDown';
			moveUpStyle='moveUp_dsbl';
			permuteItineraryDown='PermuteItineraryDown('+index+')';			
			
		} else if (index == requestRows.length - 1) {
			moveDownStyle='moveDown_dsbl';
			moveUpStyle='moveUp';
			permuteItineraryUp='PermuteItineraryUp('+index+')';
			
		} else {
			moveDownStyle='moveDown';
			moveUpStyle='moveUp';
			permuteItineraryUp='PermuteItineraryUp('+index+')';
			permuteItineraryDown='PermuteItineraryDown('+index+')';
		}
		
	}
	
	
	var templateFormfld;
	if (requestRow.SHOW_DETAIL=='false') {
		 templateFormfld = new Template(		
				'<fieldset id="Dest_'+index+'">'+
			    '<p><span class="'+colorPin+'">'+depart+'</span>'+
			    '<input type="text" id="dsbl_'+index+'"  class="'+dsblClassStyle+'" value="'+data+'" onclick="showDetail(\''+index+'\') "/>'+
			    '<button type="button" class="edit" onclick="showDetail(\''+index+'\');" title="#{modify}" >#{modify}</button>'+
			    '<button id="delete_'+index+'" type="button" class="delete"  onclick="deleteItinerary(\''+index+'\');" title="#{delete_case}" >#{delete_case}</button>'+
			    '<button id="moveUp_dsbl_'+index+'" type="button" class="'+moveUpStyle+'" onclick="'+permuteItineraryUp+'" title="#{move_up}" >#{move_up}</button>'+
			    '<button id="moveDown_'+index+'" type="button" class="'+moveDownStyle+'" onclick="'+permuteItineraryDown+'" title="#{move_down}">#{move_down}</button>'+
			    '</p>'+
			    '</fieldset><div id="errMsgItinerary'+index+'"></div>'+messageAddress);
		
		
		 
	} else {		
		
		 templateFormfld = new Template(
				 
					'<fieldset id="Dest_'+index+'">'+
					'<p id="Des_Type">'+
					'<label class="normal">'+
					'<span class="'+colorPin+'">'+depart+'</span>'+		             				
					'#{type}</label>'+
					'<select class="text" id="destination_type" onchange="javascript:displayForm();">'+					
					getDestinationTypeHtmlOptions()+
					'</select>'+
					'</p>'+
					'<p id="adressPragraph" style="display:none;">'+
					'<label class="normal">#{address}</label>'+
					'<input id="address" type="text" class="text"/> (optionnel)'+
					'</p>'+					
					'<p id="cityPostalCodePragraph" style="display:none;">'+
					'<label class="normal">#{postalCode}</label>'+				
					'<input id="city_postalCode" type="text" class="text" title="#{city_postalcode}" alt="#{city_postalcode}" value="" />'+
					'</p>'+					
					'<p id="statCountryPragraph" style="display:none;">'+					
			        '<label class="normal">#{state}</label>'+
					'<select class="text" name="stat" id="stat"  onchange="javascript:onChangeState();">'+					
					getStatesHtmlOptions()+
					'</select>'+
					'</p>'+
					'<p id="eventDatePragraph" style="display:none;">'+
					'<label class="normal">#{date_from}</label>'+				
					'<input id="eventDate" type="text" class="text"  value=""   onkeyup="onChangeDate($(\'eventDate\').value,'+index+');" />'+
					'<button id="eventDateImg" type="button" class="" title="#{select_date}">---</button>'+
					'<label class="normal">#{date_to}</label>'+				
					'<input id="eventDateto" type="text" class="text"  value=""   onkeyup="onChangeDateto($(\'eventDateto\').value,'+index+');" />'+
					'<button id="eventDateImgto" type="button" class="" title="#{select_date}">---</button>'+
					'</p>'+	
					'<p id="cityPragraph" style="display:none;">'+
			        '<label class="normal">#{city}</label>'+
					'<select class="text" id="city" onchange="javascript:adressPoiSearchSendRequest('+index+');">'+					
					'</select>'+
					'</p>'+				
					'<p id="poiResponsePragraph" >'+
			        '<label id="poiResponseLabel" class="normal"></label>'+				
					'<select class="text" id="response">'+					
					'</select>'+					
					'</p>'+	
					'<p id="poiResponseWaitPragraph" style="display:none;" >'+
			        '<label id="poiResponseWaitLabel" class="normal"></label>'+				
					'<select class="text" id="responseWait">'+	
					'<option value="" >#{wait_plz}</option>'+
					'</select>'+
					'</p>'+									
					'</fieldset>'							
				);		 
	}
	requestRows[index].ERROORISPRESENT='false';
	return  templateFormfld.evaluate(form_lang);
}

/**
* Cette fonction retourne un objet destination initial  
* @param : 
* @return objet destination vide ou intial
*/

function getEmptyDestination() {
	var emptyDestination = {
		CITY : '',
		STATE : '',
		RESPONSE : '',
		LOCATION_TYPE : '',
		ADDRESS : '',
		CITY_POSTALCODE : '',
		POI_ID : '',
		RESPONSE_SELECTED_INDEX : 0,
		CITY_SELECTED_INDEX : 0,
		LONG : 0,
		LAT : 0,
		DATE : '',
		DATETO : '',
		DATE_FROM : '',
		DATE_TO: '',
		SHOW_DETAIL : 'false',
		ERROORISPRESENT : 'false'
	};
	return emptyDestination;
}
/**
* Cette fonction intitialise un formulaire   
* @param : 
* @return objet destination vide ou intial
*/

function initForm(index){
	
	requestRows[index].CITY = '';
	requestRows[index].STATE = '';
	requestRows[index].RESPONSE = '';
	requestRows[index].LOCATION_TYPE = '';
	requestRows[index].ADDRESS = '';
	requestRows[index].CITY_POSTALCODE = '';
	requestRows[index].POI_ID = '';
	requestRows[index].RESPONSE_SELECTED_INDEX = 0;
	requestRows[index].CITY_SELECTED_INDEX = 0;
	requestRows[index].LONG = 0;
	requestRows[index].LAT = 0;
	requestRows[index].DATE = '';
	requestRows[index].DATETO = '';
	requestRows[index].DATE_FROM = '';
	requestRows[index].DATE_TO = '';
	requestRows[index].SHOW_DETAIL = 'false';
	requestRows[index].ERROORISPRESENT = 'false';
	
}

/**
 * Cette fonction ajoute un objet destination initial dans la liste des
 * itineraires
 * 
 * @param :
 * @return :
 */
function addEmptyDestination() {
	requestRows.push(getEmptyDestination());
	hideDetail();
	if (showPage == 'localisation'){
		generateLocalisationForm();
	} else {
		generateItineraryForm();
	}
}

/**
 * fonction quand on change le province on doit savoir si la destination va
 * executer une fonction ajax ou non
 * 
 * @param
 * @return
 */
function onChangeState() {
	// ici juste dans le cas de POI on fait appel pour raffrichir le fomulaire
	if (locationTypeHashTable.get($('destination_type').value) == 'Poi') {
		displayForm();
	}

}
/**
 * fonction quand on change la date dans le cas d'un evenement on doit savoir si la destination va executer une fonction ajax ou non  
 * @param 
 * @return
 */
function onChangeDate(value, index) {

	if ((value).match(/^[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}$/)
			&& requestRows[index].DATE != value) {
		requestRows[index].DATE = value;
		poiTDRSearchSendRequest();
	} else {
		return false;
	}

}
/**
 * fonction quand on change la date dans le cas d'un evenement on doit savoir si la destination va executer une fonction ajax ou non  
 * @param 
 * @return
 */
function onChangeDateto(value, index) {

	if ((value).match(/^[0-9]{4}[-]{1}[0-9]{2}[-]{1}[0-9]{2}$/)
			&& requestRows[index].DATETO != value) {
		requestRows[index].DATETO = value;
		poiTDRSearchSendRequest();
	} else {
		return false;
	}

}

/**
 * fonction appeler automatiquement par le calendar quand on change la date.    
 * @param 
 * @return
 */
function catcalc(cal) {
	poiTDRSearchSendRequest();
}


/**
 * intilaisation des selects 
 * @param :le ID html de la select concernée
 * @return
 */

function removeSelectOptions(selectName) {
	var i;
	for (i = $(selectName).length - 1; i >=0; i--) {
		$(selectName).remove(i);
	}
}
/**
 * Cette fonction construit les options de la select du html qui concerne les
 * provinces
 * 
 * @param :
 * @return :
 */
function getStatesHtmlOptions() {
	var optionsHtml = '';
	var i = 0;
	states.each(function(pair) {
		optionsHtml += '<option value="' + pair.key + '" ';

		optionsHtml += '>' + pair.value[0];

		optionsHtml += '</option>';
		i++;
	});

	return optionsHtml;

}

/**
* Cette fonction construit les options de la select du html qui concerne les provinces     
* @param :  
* @return :
*/
function getDestinationTypeHtmlOptions() {

	var optionsHtml = '';

	destinationTypeHashTable.each(function(pair) {
		
		var value= pair.key;
		//value= value.replace("_"," ");		
		optionsHtml += '<option value="'+value+'" ';

		optionsHtml += '>' + pair.value;

		optionsHtml += '</option>';
	});

	return optionsHtml;
}

/**
* Cette fonction copier les infomations de la liste des suggestions vers les champs du fomulaire pour le fieldset concerné     
* @param :  index du fieldset
* @return :
*/
function copySuggestionDestination(index) {

	requestRows[currentIndexLocationValidation].CITY = suggestionsRows[index].CITY;
	requestRows[currentIndexLocationValidation].STATE = suggestionsRows[index].STATE;
	requestRows[currentIndexLocationValidation].ADDRESS = suggestionsRows[index].ADDRESS;
	requestRows[currentIndexLocationValidation].CITY_POSTALCODE = suggestionsRows[index].CITY_POSTALCODE;
	requestRows[currentIndexLocationValidation].SHOW_DETAIL = suggestionsRows[index].SHOW_DETAIL;
	requestRows[currentIndexLocationValidation].LOCATION_TYPE = suggestionsRows[index].LOCATION_TYPE;
	showDetail(currentIndexLocationValidation);
}
/**
 * Cette fonction cache la liste des suggestion dans le cas ou la localisation
 * n'est pas valide
 * 
 * @param :
 * @return :
 */
function hideErrMsg() {
	var idError = 'errMsgItinerary' + currentIndexLocationValidation;
	$(idError).remove();
}

function getNoSuggestionHTML() {
	var templateSUGGESTION = new Template(
			'<ul>' + '<li><a >#{li1}</a></li>' + '<li class="last"><a>#{li2}</a></li>' + '</ul>');
	return templateSUGGESTION.evaluate(suggestion_lang);
}


/****************************************************** Fin gestion des formulaires ******************************************/
/****************************************************** Initialisation  ******************************************/

/**
 * fonction: pour temporiser le temps pour executer une requete AJAX. 
 * @param 
 * @return  
 */
function init(){ 
	useLoadingImage("/caa-ttp/css/images/ajax-loader.gif");
 }

/**
* Cette fonction est appeler la premiere fois au demarrage de l'application
* elle vide la liste itinéraire  et elle ajoute le nombre des objets passer en parametre  
* @param : numberSimplecase le nombre de case ou de fieldset dans le formulaire
* @return :
*/
function initApp(numberSimplecase) {
			for (i = 0; i < numberSimplecase; i++) {
			if(requestRows.length< 2){
			requestRows.push(getEmptyDestination());
			}
		}
}
/**
* Cette fonction montre soit la localisation soit l'itinéraire  
* @param : show :le nom de la page à afficher, hide: la page à cacher 
* @return :
*/
function showHide(show, hide) {

	showPage = show;
	$(hide).style.display = 'none';
	$(show).style.display = 'block';
	hideDetail();
	
	if(show == 'localisation'){	
		
		$('dMapContainer').style.display='block';
		//$('transparency').style.display='block';
		$('dDNCStuff').style.display='block';
		$('dMapContainer1').style.display='block';
		$('mapHandleStuff').style.display='block';
		$('dTipArm').style.display='block';						
		var i=0;		
		map.show();		
		initApp(1);
		generateLocalisationForm();
	} else if (hide == 'localisation'){
		
		$('dMapContainer').style.display='none';
		//$('transparency').style.display='none';
		$('dDNCStuff').style.display='none';
		$('dMapContainer1').style.display='none';
		$('mapHandleStuff').style.display='none';
		$('dTipArm').style.display='none';
		map.hide();
		$('mapCtn').className='mapItineraire';
		$('mapCtn').style.display = 'block';
		initApp(2);
		generateItineraryForm();
	}

}
/**
* Cette fonction montre la liste de checkbox qui conteints tous les POIs  
* @param : show :le nom de la section html à afficher, hide: le html à cacher 
* @return :
*/
function showHidePoi(show, hide) {

	$(hide).style.display = 'none';
	$(show).style.display = 'block';
}

function getFormOrErrorShowDetail(index) {

	if (requestRows[index].ERROORISPRESENT == 'false'&& requestRows[currentIndexLocationValidation].ERROORISPRESENT == 'false') {

		requestRows[index].SHOW_DETAIL = 'true';

		if (showPage == 'localisation') {

			generateLocalisationForm();

		} else {

			generateItineraryForm();
		}

		if (requestRows[index].LOCATION_TYPE == '') {
			$('destination_type').value = 'Address';
		} else {
			$('destination_type').value = requestRows[index].LOCATION_TYPE;
		}
		if (requestRows[index].STATE == '') {
			$('stat').value = 'quebec';
		} else {
			$('stat').value = requestRows[index].STATE;
		}

		if (requestRows[index].CITY_POSTALCODE != '') {
			$('city_postalCode').value = requestRows[index].CITY_POSTALCODE;
		}

		$('address').value = requestRows[index].ADDRESS;
		$('eventDate').value = requestRows[index].DATE;
		$('eventDateto').value = requestRows[index].DATETO;
		displayForm();
		$('city').value = requestRows[index].CITY;
		if (locationTypeHashTable.get(requestRows[index].LOCATION_TYPE) == 'Poi') {
			if ($('city') != null && $('city').options.length > 0
					&& $('city').value != '') {

				adressPoiSearchSendRequest(index);
				$('city').options[requestRows[index].CITY_SELECTED_INDEX].selected = true;
			}

		}

	} else {
		var idError = 'errMsgItinerary' + currentIndexLocationValidation;

		if (showPage == 'localisation') {
			generateLocalisationForm();

		} else {
			generateItineraryForm();

		}
		$(idError).update(suggestionHtml);

	}

}
function errh(msg){	  
	
	  return true;
}
function onloadApp(){	
	isInfo=false;
	init();		
	createMap(-108.02305883154294,50.212289472855015,13);	
	getPosition();
	showHide('localisation','itineraire');
	getAjaxPub();		
	showHidePoi('minTopBox','fullTopBox');
	dwr.engine.setErrorHandler(errh);	
	dwr.engine.setOrdered(true);
	requestRows[0].CITY_POSTALCODE =(getParameter(queryString,"city_postalcode" )=='null'|| getParameter(queryString,"city_postalcode" )==undefined ? '':getParameter(queryString,"city_postalcode"));
	var couchetard_tous =(getParameter(queryString,"couchetard" )=='null'|| getParameter(queryString,"couchetard" )==undefined ? 'N':getParameter(queryString,"couchetard"));
	var couchetard_essence =(getParameter(queryString,"couchetardessence" )=='null'|| getParameter(queryString,"couchetardessence" )==undefined ? 'N':getParameter(queryString,"couchetardessence"));
	var familiprix =(getParameter(queryString,"familiprix" )=='null'|| getParameter(queryString,"familiprix" )==undefined ? 'N':getParameter(queryString,"familiprix"));
	var partenairespriv =(getParameter(queryString,"partenairespriv" )=='null'|| getParameter(queryString,"partenairespriv" )==undefined ? 'N':getParameter(queryString,"partenairespriv"));
	var garagesrecommandes =(getParameter(queryString,"garagesrecommandes" )=='null'|| getParameter(queryString,"garagesrecommandes" )==undefined ? 'N':getParameter(queryString,"garagesrecommandes"));
	if(requestRows[0].CITY_POSTALCODE !=''){
		
		if(couchetard_essence.toUpperCase()=='Y'){
			$('couchetard_essenceCheckbox').checked = true;
			setCheckedPartners('couchetard_essence');
			getPoiPartnerInCard('couchetard_essence');
		}else{
			$('couchetard_essenceCheckbox').checked = false;
		}
		if(couchetard_tous.toUpperCase()=='Y'){
			$('couchetard_tousCheckbox').checked = true;
			setCheckedPartners('couchetard_tous');			
			getPoiPartnerInCard('couchetard_tous');
		
			
			
		}else{
			$('couchetard_tousCheckbox').checked = false;
		}
		if(familiprix.toUpperCase()=='Y'){
			$('familiprixCheckbox').checked = true;
			getPoiPartnerInCard('familiprix');			
		}else{
			$('familiprixCheckbox').checked =false;
		}
		
		if(familiprix.toUpperCase()!='Y' && couchetard_tous.toUpperCase()!='Y' && couchetard_essence.toUpperCase()!='Y' ){			
			$('Partners').checked =false;	
			$('filtrepartenaire').style.display ='none';	
			
		}
		
		
		if(partenairespriv.toUpperCase()=='Y'){
			$('lmrchCheckbox').checked = true;
			poiTypeList.push('lmrch');
		}
		if(garagesrecommandes.toUpperCase()=='Y'){
			$('aarCheckbox').checked = true;
			poiTypeList.push('aar');
		}
		
		
	}else{		
		getPoiPartnerInCard('couchetard_tous');		
		getPoiPartnerInCard('familiprix');	
	}	
	poiTypeList.push('off_caa_qc');
	poiTypeList.push('off_caa');

	//pour montrer les IDS en mode debugs
	debugGisTdr=(getParameter(queryString,"debug" )=='null'|| getParameter(queryString,"debug" )==undefined ? '':getParameter(queryString,"debug"));	
		
	if(requestRows[0].CITY_POSTALCODE !=''){
		$('Partners').checked =false;	
		$('filtrepartenaire').style.display ='none';
		showHidePartners();
		//couchetard=Y&couchetardessence=Y&familiprix=Y&partenairespriv=Y&garagesrecommandes=Y
		requestRows[0].CITY_POSTALCODE=requestRows[0].CITY_POSTALCODE.replace(/(\w\d\w)-*(\d\w\d)/, '$1 $2');
		requestRows[0].ADDRESS=(getParameter( queryString,"address")=='null' || getParameter(queryString,"address")==undefined ? '':getParameter( queryString, "address" ));
		requestRows[0].STATE=(getParameter( queryString,"state")=='null' || getParameter(queryString,"state")==undefined ? 'quebec':getParameter( queryString, "state" ).toLowerCase());	
		requestRows[0].LOCATION_TYPE=(getParameter( queryString,"ville")=='Y' ? 'Ville':'Address');	
		
		controllevel=(getParameter( queryString,"zoom")=='null' || getParameter(queryString,"zoom")==undefined ? '3':getParameter( queryString, "zoom" ));
		getCardLocalisation();		
	}
	
	var longRequest=(getParameter( queryString,"long")=='null' || getParameter(queryString,"long")==undefined ? '':getParameter( queryString, "long" ));
	var latRequest=(getParameter( queryString,"lat")=='null' || getParameter(queryString,"lat")==undefined ? '':getParameter( queryString, "lat" ));
	
	if(longRequest !='' && latRequest !=''){		
		$('Partners').checked =false;	
		$('filtrepartenaire').style.display ='none';
		showHidePartners();
		lat=latRequest;
		long=longRequest;
		onloadMap = 'N'; 
		errorIsPresent='false'	;	
		getMapLocPoi();
	}
	
	var info_id=(getParameter( queryString,"info_id")=='null' || getParameter(queryString,"info_id")==undefined ? '':getParameter( queryString, "info_id" ).toLowerCase());
	if(info_id !=''){	
		    isInfo=true;
			$('Partners').checked =false;	
			$('filtrepartenaire').style.display ='none';
			showHidePartners();
			isForm = false;
			CaaiprDbInfosService.getInfoById(info_id,{
						callback : caaiprHandlerInfoById,
						async : false
			});
		
	}
	var region_id=(getParameter( queryString,"region_id")=='null' || getParameter(queryString,"region_id")==undefined ? '':getParameter( queryString, "region_id" ).toLowerCase());
	if(region_id !=''){		
		    poiTypeList.push('info');
			isForm = false;
			CaaiprDbRegionsService.getRegionById(region_id,{
						callback : caaiprHandlerRegionById,
						async : false
			});
	}
	
}
function getParameter(queryString, parameterName) {
	// Add "=" to the parameter name (i.e. parameterName=value)
	var parameterName = parameterName + "=";
	if (queryString.length > 0) {
		// Find the beginning of the string
		begin = queryString.indexOf(parameterName);
		// If the parameter name is not found, skip it, otherwise return the
		// value
		if (begin != -1) {
			// Add the length (integer) to the beginning
			begin += parameterName.length;
			// Multiple parameters are separated by the "&" sign
			end = queryString.indexOf("&", begin);
			if (end == -1) {
				end = queryString.length
			}
			// Return the string
			return unescape(queryString.substring(begin, end));
		}
		// Return "null" if no parameter has been found
		return "null";
	}
} 


function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function getAjaxPub(){	
	var url ='/caa-ttp/media/photo_pub_gauche/index.html';
	new Ajax.Request(url, {
	  method: 'post',
	  onSuccess: function(response) {
	    var pubImageLoc = $('pubImageLoc');
	    var pubImageIti = $('pubImageIti');	        
	    	pubImageLoc.update(response.responseText);
	    	pubImageIti.update(response.responseText);	    
	  }
	});
	
	
}
function createTemplate(){
	temp = document.createElement('div');
	temp.setAttribute('id', 'temp');
	temp.update('<form action=" "><div id="wrap"></div></form>');
	document.body.appendChild(temp);
	setTemplate('header',templateHEADER.evaluate(header_lang));
	setTemplate('content',templateCONTENT.evaluate(content_lang));
	setTemplate('footer',templateFOOTER.evaluate(footer_lang));
}
function setTemplate(templateName,templateContent){
	
	template = document.createElement('div');
	template.setAttribute('id', templateName);
	template.update(templateContent);
	$('wrap').appendChild(template);
}

/**
 * **************************************************** Fin Initialisation *******************************************/
/********************* Les appels AJAX commune pour l'application avec ses fonctions CALLBACK ******************************************/
//FONCTION AJAX

/**
 * Fonction Ajax pour chercher la reponse finale.
 * 
 * @param
 * @return
 */
function poiSearchSendRequest() {
	
	var code = states.get($('stat').value)[1];
	var poisearch_request = new poisearchREQUEST();
	poisearch_request = {
		type : 'POI Search',
		LOCATION : {
			type : 'state',
			STATE : {
				abbr : $('stat').value,
				COUNTRY : {
					code : code
				}
			}
		},
		POI : {
			type : $('destination_type').value
		}
	};
	isForm = true;
	GisPoiSearchService.doRequest(poisearch_request, {
		callback : handleGetData,
		ordered : false
	});
	
	
}

/**
 * Fonction Ajax pour chercher les villes pour chaque province
 * 
 * @param
 * @return
 */
function cityPoiSearchSendRequest() {

	var code = states.get($('stat').value)[1];
	var Citypoisearch_request = new poisearchREQUEST();
	Citypoisearch_request = {
		type : 'POI Search',
		LOCATION : {
			type : 'city',
			STATE : {
				abbr : $('stat').value,
				COUNTRY : {
					code : code
				}
			}
		},
		POI : {
			type : $('destination_type').value
		}
	};
	isForm = true;
	GisPoiSearchService.doRequest(Citypoisearch_request, {
		callback : cityPoiSearchHandleGetData,
		async : false
	});

}
/**
 * Fonction Ajax pour les adresses des villes specifiques (ex: toutes les noms
 * des restaurants de la ville de Alma )
 * 
 * @param
 * @return
 */

function adressPoiSearchSendRequest(i) {

	if (requestRows[currentIndex].CITY != $('city').value) {
		requestRows[currentIndex].RESPONSE_SELECTED_INDEX = 0;
	}

	var code = states.get($('stat').value)[1];
	var Adresspoisearch_request = new poisearchREQUEST();
	Adresspoisearch_request = {
		type : 'POI Search',
		LOCATION : {
			type : 'city',
			ADDRESS : {
				location : "-",

				CITY : {
					name : $('city').value,
					STATE : {
						abbr : $('stat').value,
						COUNTRY : {
							code : code
						}
					}
				}
			}
		},
		POI : {
			type : $('destination_type').value
		}
	};
	isForm = true;
	GisPoiSearchService.doRequest(Adresspoisearch_request, {
		callback : handleGetDataCity
	});
}
/**
 * Fonction Ajax pour valider une location
 * 
 * @param :
 *            index
 * @return : un callback async pour retourner un objet data
 */
function adressLocationValidationRequest(index) {

	var code = states.get(requestRows[index].STATE)[1];
	var locationvalidation_request = new locationvalidationREQUEST();
	locationvalidation_request = {
		type : 'location validation',
		LOCATION : {
			ADDRESS : {
				location : (requestRows[index].LOCATION_TYPE == 'Ville' ? '-' : requestRows[index].ADDRESS),
				CITY : {
					name : (requestRows[index].CITY_POSTALCODE == '' ? '-'	: requestRows[index].CITY_POSTALCODE.replace(/(\w\d\w)-*(\d\w\d)/, '$1 $2')),
					STATE : {
						abbr : requestRows[index].STATE,
						COUNTRY : {
							name : code
						}
					}
				}
			}
		}
	};
	isForm = true;
	GisLocationValidationService.doRequest(locationvalidation_request, {
		callback : handleGetDataLocationValidation
	});
}
/**
 * Fonction AJAX: pour chercher la reponse finale dans le TDR.
 * 
 * @param
 * @return
 */

function poiTDRSearchSendRequest() {
	// dans le cas ou le state est composé de plusieurs mot il faut le mettre en
	// un seul mot
	var state = ($('stat').value).toUpperCase().replace(/\s/g, '');
	var urlTdrEvent = new urlTdrHttpRequest();
	urlTdrEvent = {
		host : '',
		profile : '',
		dateFormat : '',
		user : '',
		database : '',
		style : '',
		var0 : '',
		type0 : '',
		val0 : '',
		var1 : '',
		type1 : '',
		val1 : '',
		var2 : '',
		type2 : '',
		val2 : '',
		var3 : '',
		type3 : '',
		val3 : '',
		var4 : '',
		type4 : '',
		val4 : '',
		var5 : '',
		type5 : '',
		val5 : '',
		var6 : '',
		type6 : '',
		val6 : '',
		var7 : '',
		type7 : '',
		val7 : '',
		var8 : '',
		type8 : '',
		val8 : '',
		var9 : '',
		type9 : '',
		val9 : ''

	};
	if ($('destination_type').value == 'event') {		
		if ($('eventDate').value =='' || $('eventDateto').value=='') {			
			return false;
		} else{						
			urlTdrEvent.profile = 'EVENTS_IN_MAP';
			urlTdrEvent.var0 = 'MINDATE';
			urlTdrEvent.type0 = 'STRING';
			urlTdrEvent.val0 = $('eventDate').value;
			urlTdrEvent.var1 = 'MAXDATE';
			urlTdrEvent.type1 = 'STRING';
			urlTdrEvent.val1 = $('eventDateto').value;
			urlTdrEvent.var2 = 'POINAME';
			urlTdrEvent.type2 = 'STRING';
			urlTdrEvent.val2 = ($('destination_type').value).toUpperCase();
			urlTdrEvent.var3 = 'VARSTATENAME';
			urlTdrEvent.type3 = 'STRING';
			urlTdrEvent.val3 = state;
		}
	} else if ($('destination_type').value == 'lmrch') {
		if ($('stat').value == 'quebec') {
			isForm = true;
			CaaDbPartnersService.doRequestServiceCenters( {
				callback : handleGetDataserviceCenters
			});
			return false;
		}
		urlTdrEvent.profile = 'POI_IN_MAP';
		urlTdrEvent.var0 = 'POINAME';
		urlTdrEvent.type0 = 'STRING';
		urlTdrEvent.val0 = ($('destination_type').value == 'lmrch' ? 'CLUB%20OFFICE'
				: ($('destination_type').value).toUpperCase());
		urlTdrEvent.var1 = 'VARSTATENAME';
		urlTdrEvent.type1 = 'STRING';
		urlTdrEvent.val1 = state;

	}
	isForm = true;	
	TdrEventSearchService.doRequest(urlTdrEvent, {
		callback : handleGetTDRData
	});
}
function useLoadingImage(imageSrc) {
	var loadingImage;
	var imageSrcForm = imageSrc;
	if (imageSrc)
		loadingImage = imageSrc;
	else
		loadingImage = "/caa-ttp/css/images/ajax-loader.gif";
	dwr.engine.setPreHook(function() {
		var disabledImageZone = $('disabledImageZone');
		var disabledImageZoneForm = $('disabledImageZoneForm');		
		if (isForm == false) {
			if (!disabledImageZone) {
				disabledImageZone = document.createElement('div');
				disabledImageZone.setAttribute('id', 'disabledImageZone');
				disabledImageZone.style.position = "absolute";
				disabledImageZone.style.zIndex = "1000";
				disabledImageZone.style.right = "30%";
				disabledImageZone.style.bottom = "50%";
				disabledImageZone.style.width = "100px";
				disabledImageZone.style.height = "100px";
				var imageZone = document.createElement('img');
				imageZone.setAttribute('id', 'imageZone');
				imageZone.setAttribute('src', imageSrc);
				imageZone.style.position = "absolute";
				imageZone.style.bottom = "0px";
				imageZone.style.right = "0px";
				disabledImageZone.appendChild(imageZone);
				document.body.appendChild(disabledImageZone);		

			} else {

				$('imageZone').src = imageSrc;
				disabledImageZone.style.display = 'block';
				if ($('response') != null
						&& locationTypeHashTable
								.get($('destination_type').value) == 'Poi') {					
					$('poiResponsePragraph').hide();
					$('poiResponseWaitPragraph').show();
					
				}

			}
		} else {

			if (!disabledImageZoneForm) {
				disabledImageZoneForm = document.createElement('div');
				disabledImageZoneForm.setAttribute('id',
						'disabledImageZoneForm');
				disabledImageZoneForm.style.position = "absolute";
				disabledImageZoneForm.style.zIndex = "1000";
				disabledImageZoneForm.style.right = "0px";
				disabledImageZoneForm.style.top = "0px";
				disabledImageZoneForm.style.width = "100%";
				disabledImageZoneForm.style.height = "100%";
				var imageZoneForm = document.createElement('img');
				imageZoneForm.setAttribute('id', 'imageZoneForm');
				imageZoneForm.setAttribute('src', imageSrcForm);
				imageZoneForm.style.position = "absolute";
				imageZoneForm.style.top = "120px";
				imageZoneForm.style.left = "160px";
				disabledImageZoneForm.appendChild(imageZoneForm);
				document.body.appendChild(disabledImageZoneForm);
				if ($('response') != null && locationTypeHashTable.get($('destination_type').value) == 'Poi') {					
					$('poiResponsePragraph').hide();
					$('poiResponseWaitPragraph').show();
					
				}
				
			} else {
				$('imageZoneForm').src = imageSrcForm;
				disabledImageZoneForm.style.display = 'block';
				if ($('response') != null && locationTypeHashTable.get($('destination_type').value) == 'Poi') {					
					$('poiResponsePragraph').hide();
					$('poiResponseWaitPragraph').show();
					
				}
			}

		}

	});
	dwr.engine.setPostHook(function() {
		if (isForm == false) {
			if ($('disabledImageZone') != null) {
				$('disabledImageZone').style.display = 'none';
			}
			if ($('disabledImageZoneForm') != null) {
				$('disabledImageZoneForm').style.display = 'none';
			}
			if ($('response') != null && locationTypeHashTable.get($('destination_type').value) == 'Poi') {				
				$('poiResponseWaitPragraph').hide();
				$('poiResponsePragraph').show();
			}
			
		}else{
			
			if ($('disabledImageZone') != null) {
				$('disabledImageZone').style.display = 'none';
			}
			if ($('disabledImageZoneForm') != null) {
				$('disabledImageZoneForm').style.display = 'none';
			}
			if ($('response') != null && locationTypeHashTable.get($('destination_type').value) == 'Poi') {					
					$('poiResponseWaitPragraph').hide();
					$('poiResponsePragraph').show();
					if ($('city') != null && $('destination_type').value!='event' && $('response').value == '') {
						if ($('city').value == '')
							$('response').update(
									'<option value="" > ' + ressourceLang
											.get('choose_city') + '</option>');
					}	
	
				}
			
		}
		
		});
	
}


