                 
    
                 
     
         
          
                                                                   
	      
	   
	     
	  
		var WordWheel = function(){}
var objectClose;
WordWheel.prototype = { 
	input : {},
	calendar : null,
	searchValue : "", type : "", dialect : "",
	maxDisplay : 10,
	ie6 : $.browser.msie && $.browser.version=="6.0",
	cachedData : [],
	cachedSearchText : [],
	hiddenInputs : ["HiddenEOAG","AutoFill","searchType","stateCode","countryCode","isServedBy","HasSpecialInstruction"],
	query : function(location){
		var self = this;
		$.jsonp({
		    url: htz.wordWheel.url+"?callback=?",
		    data: {
				searchText: location,
				dialect: self.dialect,
				systemId: htz.config.systemId,
				subSystemId: htz.config.subSystemId,
				partnerId: htz.config.partnerId
			},
		    success: function(response) {
				if(response.locationList.length>0){
					self.draw(response.locationList,response.searchText);
					self.cachedData[self.input.val()]=response.locationList;
					self.cachedSearchText[self.input.val()]=self.input.val();
					self.searchValue = self.input.val();
				}
				else{
					self.close();
				}
		    },
		    error: function() {
				self.close();
		    }
		});		
	}
	,
	setTogglerTimer : function() {
		var self = this;
		if(self.currentTimer == 0) {
			self.currentTimer = null;
			clearTimeout(self.toggleTimeout);
			// Adding condition if length of search text > 3 or if the text box doesnt have an initial spaces
			if(self.input.val().length>=3 && self.input.val().substring(0,1) != ' '){
				self.query(self.input.val()); 
			}
		} else {
			self.currentTimer--;
			self.toggleTimeout = setTimeout(function(){
									self.setTogglerTimer();
								},1);
		}
	}, 
	
	handle : function(e){
		var self = this;
		//Fix for fire fox 2 by adding timer
		self.currentTimer = 10;
		clearTimeout(self.toggleTimeout);
		var key = (e.charCode) ? e.charCode : ((e.keyCode) ? e.keyCode : ((e.which) ? e.which : 0));
		if(key==13){ self.select(); return; }
		if(key!=37 && key!=38 && key!=39 && key!=40){

			// Adding condition if length of search text > 3 or if the text box doesnt have an initial spaces
			if(self.input.val().length>=3 && self.input.val().substring(0,1) != ' '){
				if(self.cachedData[self.input.val()]==undefined){
				self.handleTimeout = setTimeout(function(){
										self.setTogglerTimer();
									},1); 
				}
				else {
					self.draw(self.cachedData[self.input.val()],self.cachedSearchText[self.input.val()]); 
				}
			} else {
			    if(objectClose!= null)
		   			objectClose.hide();
				self.clear();
				self.prepare(null);
			}
		}
	},
	shift : function(e){
		var self = this;
		var key = (e.charCode) ? e.charCode : ((e.keyCode) ? e.keyCode : ((e.which) ? e.which : 0));
		if ($("#wordWheelResults").length && $("#wordWheelResults").css("visibility")=="visible")	{
			if (key==38) 
				self.move(0);				
			if (key==40) 
				self.move(1);
		}
	},
	prepare : function(location){
		var self = this;
		var prefix = "inp"+self.type.charAt(0).toUpperCase()+self.type.substr(1);
		if(location){
			for(var key in location){
				if(key=="preferredOag"){
					if(location[key]!="") 
						$("#"+self.type+"HiddenEOAG").val(location[key]);
					else 
						$("#"+self.type+"HiddenEOAG").val("");
				}
				if(key=="hasSpecialInstruction") {
					if(location[key]!="") 
						$("#"+self.type+"HasSpecialInstruction").val(location[key]);
					else 
						$("#"+self.type+"HasSpecialInstruction").val("");
				}
				if(location[key]!="") 
					$("#"+prefix+key.charAt(0).toUpperCase()+key.substr(1)).val(location[key]);
				else 
					$("#"+prefix+key.charAt(0).toUpperCase()+key.substr(1)).val("");
			}
			$("#"+prefix+"AutoFill").val("Y");

			if(location.locationTitle!="") self.input.val(location.locationTitle);
			else self.input.val(location.displayText);
		}
		else {
			for(var i=0; i<self.hiddenInputs.length;i++){
				if(self.hiddenInputs[i]=="HiddenEOAG") 
					$("#"+self.type+"HiddenEOAG").val("");
				else 
					$("#"+prefix+self.hiddenInputs[i].charAt(0).toUpperCase()+self.hiddenInputs[i].substr(1)).val("");
			}
		}
	},
	select : function(){
		var self = this;
		var selected = $("#wordWheelResults .wordWheelSelected");
		var location = null;
		if(selected.length && self.cachedData[self.input.val()]){
			for(var i=0;i<self.cachedData[self.input.val()].length;i++){
				var obj = self.cachedData[self.input.val()][i];
				if(obj.displayText == selected.text()) { 
					location = obj;
					
					if (typeof HomePage != 'undefined') {
						// Added the below condition to make sure that its not a locations page and also applied only to pickup location
						if($('#pickupHiddenEOAG').length != '0' && self.input[0].id != 'dropoffLocation') {
							HomePage.lookupLocation(true, obj.preferredOag, self.calendar);
						} else if($('#dropoffHiddenEOAG').length != '0' && self.input[0].id == 'dropoffLocation') {
							HomePage.lookupLocation(false, obj.preferredOag, self.calendar);
						}
					}
					
					break;
				}
			}
			self.prepare(location);
			if(typeof HomePage != 'undefined') HomePage.saveLocationInSession(location, self.type);
		} else {
			if(typeof HomePage != 'undefined' && self.input.val().length >= 3) HomePage.saveLocationInSession(self.input.val(), self.type);
		}
		self.input.unbind('keyup keydown keypress blur').blur();	
		self.clear();
		if(objectClose!= null)
		   objectClose.hide();
		setTimeout(function(){ self.set(); },1);
	},
	move : function(direction){
		var self = this;
		var results = $("#wordWheelResults");
		var selected = results.find(".wordWheelSelected");
		self.detach();
		
		if (direction==0){
			if(selected.length && selected.prev()!=null) 
				selected.removeClass("wordWheelSelected").prev().addClass("wordWheelSelected");
			else
				results.find("div:last-child").addClass("wordWheelSelected"); 
		}
		if (direction==1){
			if(selected.length && selected.next()!=null) 
				selected.removeClass("wordWheelSelected").next().addClass("wordWheelSelected");			
			else 
				results.find(":first").addClass("wordWheelSelected"); 
		}
        
		if (results.find(".wordWheelSelected").length){
			if (results.find(".wordWheelSelected").attr("id")=="wordWheelClose")
			  self.input.val('');
			else
			  self.input.val(results.find(".wordWheelSelected").attr("name"));
		} else
			self.input.val(self.cachedSearchText[self.input.val()]);
		
		self.reposition(direction);

		if (self.ie6) 
			setTimeout(function(){ self.attach(); },1);
		else 
			self.attach();
	},
	reposition : function(direction){
		var results = $("#wordWheelResults");
		var selected = results.find(".wordWheelSelected");
		
		if(!selected.length) results.attr("scrollTop",0);
		else {
			if (direction==0){
				if(selected.position().top>=results.height()) 
					results.attr("scrollTop",selected.position().top);
				else if(selected.position().top<0) 
					results.attr("scrollTop",results.attr("scrollTop")-selected.outerHeight()); 
			}
			if (direction==1){
				if (selected.position().top>=results.height()) 
					results.attr("scrollTop",selected.position().top-results.height()+selected.outerHeight()+results.attr("scrollTop"));
			}
		}
	},
	draw : function(list,searchText){ 
		var self = this;
		var results = $("#wordWheelResults");
		self.clear();

		var locationCountText='';
		var length;
		var suggestionStringToHighlight;
		var suggestionStringNotToHighlight;
		var index;
		var highlightedText;
		var nonHighlightedText;
		var locationCountInfo;
		var regularText;
		var displayText;
		var actualHeight;
		var outerHeight;
		var listLength;
		var topPosition;
		var topPosition;
		

		if(objectClose!= null)
		   objectClose.hide();	
		if (!results.length)
			results = $("<div>").attr("id","wordWheelResults").css("visibility","hidden").appendTo("body");

				
		for(var i=0; i<list.length;i++){
			var obj = list[i];
			index=0;
			displayText=obj.displayText;
			if (obj.displayText.indexOf('(') >0 && obj.searchType!=4 && obj.searchType!=6){
	    		locationCountText= obj.displayText.substring(obj.displayText.indexOf('('));
	    		displayText= obj.displayText.substring(0,obj.displayText.indexOf('('));
           	} else
         		locationCountText='';
         	        	
			var divWordWheel=$("<div>").attr("name", obj.locationTitle!="" ? obj.locationTitle : obj.displayText)
							.mouseover(function(){ $("#wordWheelResults .wordWheelSelected").removeClass(); $(this).addClass("wordWheelSelected"); })
							.click(function(){ self.select(); })
							.appendTo(results);
							
			while(index!=-1){
         		
         		  length=searchText.length;
         		  index=displayText.toLowerCase().indexOf(searchText.toLowerCase());
         		  if(index == 0)
         		     suggestionString=displayText.substring(0,length);
         		  else if(index == -1)
         		      suggestionString=displayText.substring(0);  
         		  else
         		      suggestionString=displayText.substring(0,index); 
         		        
         		  if(suggestionString.toLowerCase() == searchText.toLowerCase()){    
         		     $("<span>").attr("id","wordWheelHighlight").text(suggestionString).appendTo(divWordWheel);
         		     displayText=displayText.substring(index+length);   
         		  }   
         		  else{
         		     $("<span>").attr("id","nonHighlightedText").text(suggestionString).appendTo(divWordWheel);  
         		     displayText=displayText.substring(index);   
         		   }  
         	}
         	$("<span>").attr("id","wordWheelLocationCount").text(locationCountText).appendTo(divWordWheel);
       			
		}
		//var txtCloseButton = $("#closeButton").val();//modifyed by Animesh Singh
		var txtCloseButton = $("#closeButton").length > 0 ? $("#closeButton").val() : "";//Check for closeButton In the page
		var imgCloseButton = htz.config.protocol + '://images.hertz.com' + htz.config.fullContext + '/misc_refresh/popup_close.gif';
		var divClose=$("<div>").attr("id","wordWheelClose").click(function(){self.input.val('');$('#wordWheelResults').css('visibility')='hidden';divClose.hide(); }).css("visibility","hidden").appendTo("body");
		var spanCloseText=$("<span>").attr("id","wordWheelCloseText").click(function(){self.input.val('');divClose.hide(); }).text(txtCloseButton).appendTo(divClose);
		var spanCloseImg=$("<span>").attr("id","wordWheelCloseImg").click(function(){self.input.val('');divClose.hide(); }).appendTo(divClose);
		$("<img>").attr("src",imgCloseButton).appendTo(spanCloseImg);
		
		outerHeight=results.find(":first").outerHeight();
		listLength=list.length;
		if(listLength>self.maxDisplay)
		  actualHeight=outerHeight*10;
		else  
		  actualHeight=outerHeight*listLength;
		
		topPosition=self.input.offset().top+20;
		topPosition=topPosition+actualHeight;
		leftPosition=self.input.offset().left;
		divClose.css({"top":topPosition,"left":leftPosition,"visibility":"visible"});	
		objectClose=divClose;
	    objectResults=results;

		self.attach();
		
		if (list.length>=self.maxDisplay) 
			results.css("height",results.find(":first").outerHeight()*self.maxDisplay);
		results.css({"top":self.input.offset().top+20,"left":self.input.offset().left,"visibility":"visible"});		

		if(self.ie6){
			if (!$("#wordWheelResultsIFrame").length) 
				$("<iframe>").attr({"id":"wordWheelResultsIFrame","src":"javascript:false;"}).css("visibility","hidden").appendTo("body");
			$("#wordWheelResultsIFrame").css({"height":results.outerHeight()+outerHeight,"width":results.outerWidth(),"top":self.input.offset().top+self.input.outerHeight(),"left":self.input.offset().left,"visibility":"visible"});
		}
	},
	detach : function(){
		var results = $("#wordWheelResults");
		if(results.length) results.unbind().children().unbind();
	},
	attach : function(){
		var self = this;
		var results = $("#wordWheelResults");
		if(results.length){
			if(!$.browser.mozilla){
				results.mouseenter(function(){ self.input.unbind("blur").blur(function(){ self.input.focus(); }); })
					.mouseleave(function(){ self.input.unbind("blur").blur(function(){ self.select(); }); });
			}
			results.mousemove(function(){
				$(this).unbind('mousemove').children().unbind()
					.mouseover(function(){ $("#wordWheelResults .wordWheelSelected").removeClass(); $(this).addClass("wordWheelSelected"); })
					.click(function(){ self.select(); });	
			});	
			$(window).resize(function() {
				var results = $("[id=wordWheelResults]");
				var divClose = $("[id=wordWheelClose]");
				results.css({"top":self.input.offset().top+20,"left":self.input.offset().left});
				divClose.css({"top":self.input.offset().top+results.height()+20,"left":self.input.offset().left}); 
			});   
		}
	},
	clear : function(){
		var self = this;
 		if($("#wordWheelResults").length) $("#wordWheelResults").css({"height":"auto","visibility":"hidden"}).children().remove();
		if(self.ie6 && $("#wordWheelResultsIFrame").length) $("#wordWheelResultsIFrame").css("visibility","hidden");
	},
	set : function(){
		var self = this;
      	self.input.unbind('keyup keydown keypress blur')
      		.keyup(function(event){ self.handle(event); })
       		.keydown(function(event){ self.shift(event); })
       		.keypress(function(event){ return (event.keyCode != 13); })
			.blur(function(){ self.select(); });			   
	},
	close : function() {
		var self = this;
		if(objectClose!= null)
			objectClose.hide();
		self.clear();
		self.prepare(null);
	},	
	init : function(input, calendarPointer){
		var self = this;
		self.input = input;
		self.dialect = htz.config.dialect;
		self.calendar = calendarPointer;
		
		if(self.input.attr("id")=="pickupLocation") self.type = "pickup";
		if(self.input.attr("id")=="dropoffLocation") self.type = "dropoff";

		self.set();
	}
}; 
  	
		/* Location JS */
var locationObj = {
	init: function() {
		/* WordWheel Call */
		$(".wordWheelInput").each(function() {			
			new WordWheel().init($(this));
		});			
		
		/* Location 2nd Tab Airport Codes List */
		$('#locAirportListLink').click(function(){
			locationObj.airportList.query();
		});		
		
		/* Location Results JS */
		$('.locBoxLink li:first').css('padding-left','0px');
		$('.locBoxLink li:last').css('border-right','none');
		
		/* Location Airport Codes */
		$('.locListAlphabet li:last').css('border-right','none');
			
		/* Location all Tabs Click Event */		
		var locTabs = $('.tabsList td a');
		locTabs.click(function() {			
			$('.locationList').addClass('locationListNone');			
			$('.locTabContent').removeClass('show').addClass('hide');
			var currentContent = $('.locTabContent').eq(locTabs.index(this));
			currentContent.removeClass('hide').addClass('show');
			$('#locResults').hide();
			$('#locFullList').addClass('hide');
			
			/* Location 4th Tab Country */
			if ( locTabs.index(this) == locTabs.length -1 && (locTabs.length != 1) ) {
				$('#locFullList').removeClass('hide');			
				locationObj.CountriesListManager.countryList.query();
			}
			
			return false;
		});
		
		/* Location - Results Show on Home Page */
		$('.locResultShow:last').css('border-bottom','none');
		
		/* Location - Page Title */
		var titleId = $('#locationTitle').val();	
		var newTitle = titleId, pT = '', pageTitle;		
		pageTitle = (pT != '') ? 'Hertz - '+pT : 'Hertz';		
		document.title = ( newTitle == '' ) ? pageTitle : pageTitle+' - '+newTitle;
		
		/* Location Proximity Countries */
		locationObj.proximityCountryStates.init();		
	},
	airportList: {
		isLoaded: false,
		prevCountryName: '',
		currentCountryName: '',
		query: function() {
			var self = locationObj.airportList;
			if(!self.isLoaded) {
				$('#loadingMessage').addClass('show');
				$.getJSON(htz.config.rootContext + '/handlers/LocationAirportAJAXHandler?type=PU', self.renderHTML);	
			} else {
				$('#locResults').hide();
				$('.locationList').removeClass('locationListNone');
			}
		},
		renderHTML: function(response) {
			var self = locationObj.airportList;
			self.isLoaded = true;
			self.section = response.section;
			self.target = response.target;
			$('.locationList').removeClass('locationListNone');
			$('#locResults').hide();
			$('#loadingMessage').removeClass('show');
			if(response.list.length > 0) {
				var div = $('<div class="locAirportCodeList"/>');
				$(response.list).each(function(key, airport) {
					self.currentCountryName = airport.country_name;
					if(self.currentCountryName.substring(0,1) == self.prevCountryName.substring(0,1)) {
						if(airport.state != "") {	
							$('<ul class="locListHead"/>').append($('<li class="locListHeadLi fontSizeNine"/>').append(airport.country_name + ' - '  + airport.state  + ', ' + airport.city)).append($('<li class="locListHeadLi"/>').append($('<a  class="fontSizeNine" href="' + htz.config.rootContext + '/handlers/RememberLocationsHandler?oag_code=' + airport.OAGCode + '&from_section=' + self.section +  '&from_target=' + self.target + '"/>').append(airport.locationName))).append($('<li class="locListHeadLilast"/>').append($('<a class="fontSizeNine" href="' + htz.config.rootContext + '/handlers/RememberLocationsHandler?oag_code=' + airport.OAGCode + '&from_section=' + self.section +  '&from_target=' + self.target + '"/>').append(airport.OAGCode))).appendTo(div);
						} else {
							$('<ul class="locListHead"/>').append($('<li class="locListHeadLi fontSizeNine"/>').append(airport.country_name + ', ' + airport.city)).append($('<li class="locListHeadLi"/>').append($('<a  class="fontSizeNine" href="' + htz.config.rootContext + '/handlers/RememberLocationsHandler?oag_code=' + airport.OAGCode + '&from_section=' + self.section +  '&from_target=' + self.target + '"/>').append(airport.locationName))).append($('<li class="locListHeadLilast"/>').append($('<a class="fontSizeNine" href="' + htz.config.rootContext + '/handlers/RememberLocationsHandler?oag_code=' + airport.OAGCode + '&from_section=' + self.section +  '&from_target=' + self.target + '"/>').append(airport.OAGCode))).appendTo(div);
						}
					} else {
						$('<p class="locAlphabet"/>').append($('<a href="#" class="locAirportLinkLeft locLinkSmallfont"/>').attr('name',airport.country_name.substring(0,1)).append(airport.country_name.substring(0,1))).append($('<a href="#" class="locAirportLinkRight fontSizeEight">Back to Top</a>')).appendTo(div);
						$('<ul class="locListHead fontSizeNine"/>').append($('<li class="locListHeadLi fontSizeNine"/>').append(airport.country_name + ',' + airport.city)).append($('<li class="locListHeadLi"/>').append($('<a class="fontSizeNine" href="' + htz.config.rootContext + '/handlers/RememberLocationsHandler?oag_code=' + airport.OAGCode + '&from_section=' + self.section +  '&from_target=' + self.target + '"/>').append(airport.locationName))).append($('<li class="locListHeadLilast"/>').append($('<a class="fontSizeNine" href="' + htz.config.rootContext + '/handlers/RememberLocationsHandler?oag_code=' + airport.OAGCode + '&from_section=' + self.section +  '&from_target=' + self.target + '"/>').append(airport.OAGCode))).appendTo(div);
					}
					self.prevCountryName = airport.country_name;
				});
				$('#locAirportList').append(div);
			}
		}
	},	 
	proximityCountryStates: {
		init: function() {
			var self = locationObj.proximityCountryStates;
			$('#country').change(function() {
				self.getStates($('#country').val());
			});
			if(htz.config.targetPage == 'locationProximityView.jsp') {
				self.getStates($('#country').val());
			}
		},
		getStates: function(countryCode) {
			var self = locationObj.proximityCountryStates;
			$.getJSON(htz.config.rootContext + '/handlers/LocationStatesListAJAXHandler?countryCode=' + countryCode + '&addressType=PU',self.populateStates);			
		},
		populateStates: function(response) {
			var self = locationObj.proximityCountryStates;
			if(response.length == '0') {
				$('#locManualState').hide();
			} else {
				$('#locManualState').show();
				$('#state').children().remove();
				$(response.statesList).each(function(key, stateObj) {
					var states = $('<option></option>').val(stateObj.stateProvinceCode).html(stateObj.stateProvinceName);
					$('#state').append(states);
				});
			}
		}	
	},	
	ProximityMapFormSubmit: {
		submit: function(form) {
			with(document.manualSearch) {
					submit();	
			}
		}
	},	
	CountriesListManager: {	
		selectedCountryCode: '',
		selectedStateCode: '',
		
		/* Location Country List JS */
		countryList: {
			prevCountryName: 'A',
			currentCountryName: '',
			query: function() {
				var self = locationObj.CountriesListManager;				
				$.get(htz.config.rootContext + '/location/templates/countriesStatesListView.jsp', this.renderHTML);	
			},
			renderHTML: function(response) {							
				if(response != null) { 					
					$('#locFullList').html('');							
					$('#locFullList').append(response);								
				}
			}
		},	
		/* Location State List JS */
		stateList: {
			prevStateName:'A',
			currentStateName:'',
			query: function(countryCode, countryName) {
				var self = locationObj.CountriesListManager; 
				self.selectedCountryCode = countryCode;
				$.get(htz.config.rootContext + '/location/templates/countriesStatesListView.jsp?countryCode=' + countryCode + '&countryName=' + countryName +  '&addressType=PU', this.renderHTML);	
			},
			renderHTML: function(response) {
				var self = locationObj.CountriesListManager;
				$('#locFullList').html('');				
				$('#locFullList').append(response);
			}
		},	
		/* Location City List JS */
		cityList: {
			prevCityName: 'A',
			currentCityName: '',
			query: function(countryCode, countryName, stateCode, stateName, searchFrom) {
				var self = locationObj.CountriesListManager; 
				self.selectedStateCode=stateCode;
				$.get(htz.config.rootContext + '/location/templates/countriesStatesListView.jsp?countryCode='+countryCode+'&countryName='+countryName+ '&stateCode='+stateCode+'&stateName='+encodeURIComponent(stateName)+'&searchFrom='+searchFrom+'&rand='+Math.random(), this.renderHTML);				
			},
			renderHTML: function(response) {
				var self = locationObj.CountriesListManager;
				var div = $('<div class="locCountryList"/>');
				$('#locFullList').empty().append(response).show();
			},
			cityResultsQuery : function(countryCode, countryName, stateCode, stateName,  city, searchForm) {
				var self = locationObj.CountriesListManager;
				$('#loadingMessage').addClass('show');
				$.get(htz.config.rootContext + '/location/templates/locationResultsView.jsp?tab=4&country=' + countryCode + '&countryName=' + countryName  +((stateCode != null) ? '&state=' + stateCode : '' ) + ((stateCode != null) ? '&stateName=' + stateName : '' ) + '&city=' + encodeURIComponent($.trim(city)) + '&locType=' + document.locationsTab.locType.value,null , self.cityList.onResultsComplete);
			},
			onResultsComplete: function(response) {
				$('#locFullList').empty().append(response);
				$('#loadingMessage').removeClass('show');
				$('.locResultShow:last').css('border-bottom','none');
				$('.countriesShow:last').css('border-bottom','none');
				locationObj.results.urlParams = $('#locFullList #urlParams').first().val();
				locationObj.results.parentTab = $('#locFullList #tab').first().val();
			}
		}
	},	
	/* Location Tab 1 & Tab 2 Results JS */	
	results: { 
		query: function() {
			var self = locationObj.results;
			$('#loadingMessage').addClass('show');
			$('#locResults').hide();
			var queryURL = htz.config.rootContext + '/handlers/MapProviderHandler?'+ self.getQueryString();	
	    $.ajax({
				type: "POST",
				cache: false,
				url: queryURL,
				success: self.onAJAXComplete
			});
		},
		airportQuery: function() {
			var self = locationObj.results;
			$('#loadingMessage').addClass('show');
			$('.locationList').addClass('locationListNone');
			$.get(htz.config.rootContext + '/handlers/FTSSearchHandler?'+ 'tab=2&search=' + encodeURIComponent(document.locTabAirport.pickupLocation.value) + '&locType=' + document.locTabAirport.locType.value,null , self.onAJAXComplete);	
		},
		onAJAXComplete: function(response) {		
			$('#locResults').hide().html(response);
			locationObj.results.urlParams = $('#locResults #urlParams').first().val();
			locationObj.results.parentTab = $('#locResults #tab').first().val();			
			var ajaxResponse = $('#locResults #ajaxResponse').first();
			if(typeof(ajaxResponse) == 'object' && ajaxResponse.val() == 'countryStateList') {				
				$('.locTabContent').removeClass('show').addClass('hide');
				$('#locFullList').empty().append(response).removeClass("hide");
				
				/* Hide WordWheel when the control goes from 3rd tab to 4th tab */
				WordWheel.prototype.clear();
				objectClose.hide();
				$('#locResults').html('');
			} else {
				$('#locResults').show();
			}			
			$('#loadingMessage').removeClass('show');
			$('.locResultShow:last').css('border-bottom','none');
			$('.countriesShow:last').css('border-bottom','none');
			
			/* Location - Web Tracking */
			var urlParameter = locationObj.results.urlParams;
			var reqKey = "locationSearchResults"+urlParameter;
			var data = {"eVar23": urlParameter};			
			WebTracking.sendTrackingRequest(reqKey, data);			
		},
		getQueryString: function() {
			var self = locationObj.results;
			$('#loadingMessage').addClass('show');
			var queryString = 'address=' + document.locationsTab.address.value + '&city=' + document.locationsTab.city.value + '&state=' + document.locationsTab.state.value + '&country=' + document.locationsTab.country.value +'&zip=' + document.locationsTab.zip.value + '&locType=' + document.locationsTab.locType.value;
			if(document.locationsTab.majorAirport.checked) {
				queryString = queryString + '&majorAirport=y';
			}
			return queryString;
		},
		fullTextSearchQuery: function() {
			var self = locationObj.results;
			$('#loadingMessage').addClass('show');
			$("#locFullList").html("");
			$.get(htz.config.rootContext + '/handlers/FTSSearchHandler?'+ 'tab=3&search=' + encodeURIComponent(document.fullTextSearch.fullTextSearchBox.value) + '&locType=' + document.fullTextSearch.locType.value  + '&origin=' + document.fullTextSearch.origin.value + '&searchOrigin=locationsTab',null , self.onAJAXComplete);	
		},
		vehicleQuery: function() {
			var self = locationObj.results;
			$('#loadingMessage').addClass('show');
			var queryString = 'city='+ encodeURIComponent(document.locationsTab.city.value) +'&state='+ encodeURIComponent(document.locationsTab.state.value) +'&zip=' + document.locationsTab.zip.value + '&country=' + document.locationsTab.country.value + '&formaction=displayProximitySearchResults&searchOrigin=locationsTab';
			$.get(htz.config.rootContext + '/handlers/VehicleSearchHandler?'+ queryString ,null , self.onAJAXComplete);	
		},
		cityMatchesQuery: function(searchString) {
			var self = locationObj.results;
			/* Update FTS Search Textbox with most recent search value */
			document.fullTextSearch.pickupLocation.value = searchString;
			$.get(htz.config.rootContext + '/handlers/FTSSearchHandler?&locType=' + $('#locType').first().val() + '&origin=reservation&searchOrigin=locationsTab&search=' + searchString,null , self.onAJAXComplete);	
		},
		resultsSorting: {
			redirectURL: function(redirectType) {
				var self = locationObj.results.resultsSorting;
				if(typeof(self.urlParams) == 'undefined') {
					self.urlParams = locationObj.results.urlParams;
				}
				if(redirectType == 'ajax') {
					self.replaceURLParameter(locationObj.results.urlParams,'sortBy',$('#sortBy').val());
					self.replaceURLParameter(self.queryURL,'tab',locationObj.results.parentTab);					
					$.get(htz.config.rootContext + '/location/templates/locationResultsView.jsp?'+ self.queryURL, self.populateResults);			
				} else {
					window.location.href = 	self.replaceSortByParameter(window.location.href) + '&sortBy=' +  $('#sortBy').val();
				}
			},
			populateResults: function(response) {
				var self = locationObj.results.resultsSorting;
				var container = "";
				if(locationObj.results.parentTab == '3' || locationObj.results.parentTab == 'homepage') {
					container = "#locResults";
				} else {
					container = "#locFullList";
				}
				$(container).empty().append(response);
				$('#loadingMessage').removeClass('show');
				$('.locResultShow:last').css('border-bottom','none');
				$('.countriesShow:last').css('border-bottom','none');
				locationObj.results.urlParams = $('#urlParams',container)[0].value;
				locationObj.results.parentTab = $('#tab',container)[0].value;
			},
			replaceSortByParameter: function(URL) {
				var self = locationObj.results.resultsSorting;
				
				/* url Params value is set in the locationResultsView.jsp as we have to cover AJAX call and also page refresh */
				if(URL.indexOf('sortBy') != '-1') {
					self.queryURL = URL.substring(0,URL.indexOf('sortBy'));
				} else {
					self.queryURL = URL;
				}
				return self.queryURL;
			},
			replaceURLParameter: function(URL, param, value) {
				var self = locationObj.results.resultsSorting;
				var newURL = '';
				var vars = URL.split("&");
				if(URL.indexOf(param) != '-1') {
					for (var i=0;i<vars.length;i++) {
					    var pair = vars[i].split("=");
					    if(pair[0] != param) { 
					    	if(i == 0) {
						    	newURL = newURL + vars[i]; 
					    	} else {
						    	newURL = newURL + '&' + vars[i]; 
					    	}
							
			    		} else {
			    			vars[i] = pair[0] + '=' + value;
			    			if(i == 0) {
				    			newURL = newURL + vars[i]; 
			    			} else {
			    				newURL = newURL + '&' + vars[i];	
			    			}
			    		}
					}
				} else {
					newURL = URL + '&' + param + '=' + value;
				}
				self.queryURL = newURL;
				return newURL;
			}
		}
	},
	openPopUp: function(url, name, specs) {
		 window.open(url, name, specs);
	},
	didYouMeanFormSubmit : function(cityName,stateCode,countryCode){
		$('#city').val(cityName);
		$('#state').val(stateCode); 
		$('.locResultsContent').hide();
		var self=locationObj.results.query();
	}
};

$(document).ready(function() {
	locationObj.init();
});

/* Location - Web Tracking */
var sLazy = {};
sLazy.eVar23 = $('#locResSearch').val();  
	
	
	
	
		
		
	 
	  
	 
	 
	
		
	
	
     



  

       
              
                                                                                         
                                                           
	                                                  
	                    
	
		  
			
				
	
			
       
                                                                                                                  
/* EOF */                                                                                                                
                                                                              
/* EOF */                                                                                                                         
