                 
    
          
    
        
          
                                                 
	      
	        
		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();
	}
}; 
  	     
		var HomePage = (function() {
	var pickupLocPopup = null;
	var dropoffLocPopup = null;
	if(htz.homepage.jsflag.enableRightBannerAds) {
		var homePageAdsLoad = { cache: false, dataType: 'html', success: function(data) { $('#homePageBannerAdContainer').html(data); }};
		homePageAdsLoad.url = htz.config.rootContext + '/reservation/gaq/templates/home/reservationOnHomepageAds.jsp';
		LazyLoad.queueJS(homePageAdsLoad, 'high'); 
	}
	$(document).ready(function() {
		Clock.init(htz.clock.pickupHour, htz.clock.pickupMin, htz.clock.dropoffHour, htz.clock.dropoffMin, htz.clock.useMilitaryTime);
		
		var pickupCal = new Calendar(htz.calendar.flags.militaryClock, true);
		var dropoffCal = new Calendar(htz.calendar.flags.militaryClock, false);
		
		pickupCal.companionCalendar = dropoffCal;
		dropoffCal.companionCalendar = pickupCal;
		
		$("#oneWayTripCheckBox").change( function(){ dropoffCal.processOneWayClick($(this), dropoffCal); } );
		
		$("#pickupDay")
			.focus(function(){ $(this).blur(); })
			.click(function(){ pickupCal.showStart($(this),$("#dropoffDay")); });
			
		$("#dropoffDay")
			.focus(function(){ $(this).blur(); })
			.click(function(){ dropoffCal.showEnd($(this),$("#pickupDay")); });	
	
		if (htz.homepage.jsflag.ftsEnabled) {
			var pickupWordWheel = new WordWheel().init($("#pickupLocation"), pickupCal);
			var dropoffWordWheel = new WordWheel().init($("#dropoffLocation"), dropoffCal);
			
			$("#pickupLocation").change( function(){ pickupCal.processWordWheelFieldChange($(this).val(), pickupCal); } );
			$("#dropoffLocation").change( function(){ dropoffCal.processWordWheelFieldChange($(this).val(), dropoffCal); } );
		} else {
			$("#pickupLocation").change( function(){ pickupCal.processLocationDropdownChange($(this), pickupCal); } );
			$("#dropoffLocation").change( function(){ dropoffCal.processLocationDropdownChange($(this), dropoffCal); } );
			
			$("#pickupCountry").change( function(){ pickupCal.processLocationChange(null, pickupCal); } );
		}
		HomePage.overlayBox = new OverlayBox();
		
		$('#homePageAgeLink').click(function(){
			HomePage.showAgeText($(this));
		});	
		
		// To handle DnC
		if(htz.homepage.jsflag.isDnCAvailable){
			$("#pickupLocation").keydown(function(){HomePage.setDandCChangedValue('isDeliveryChanged',htz.homepage.jsdata.pkLocation,'Y',$("#pickupLocation")[0]);})
								.change(function(){HomePage.setDandCChangedValue('isDeliveryChanged',htz.homepage.jsdata.pkLocation,'Y',$("#pickupLocation")[0]);});
			
			$("#dropoffLocation").keydown(function(){HomePage.setDandCChangedValue('isCollectChanged',htz.homepage.jsdata.drLocation,'Y',$("#dropoffLocation")[0]);})
								.change(function(){HomePage.setDandCChangedValue('isCollectChanged',htz.homepage.jsdata.drLocation,'Y',$("#dropoffLocation")[0]);});
		}
		
		$("form[name='resModifyForm'] input[name='confirmationNumber']").focus();
		if($("#pickupCountry").length) {
			 $("#pickupCountry").focus();
	    } else {
			 $("#pickupLocation").focus(); 
	    }
		
		$('#cdpField').bind('blur',function(){
			HomePage.saveCDPInSession($(this).val());
		});
		
		$("#memberSelectedCdp").bind('change',function(){
			$("#profileCdpIndicator").trigger('click');
			HomePage.saveCDPInSession($(this).val(), $("#profileCdpIndicator").val());			
		});
		$("#memberOtherCdpField").bind('blur',function(){
			HomePage.saveCDPInSession($(this).val(), $("#otherCdpIndicator").val());
		});	
	});
	
	/* Copied the functions to submit home page , will refactor the code/functions after functionality is working. - KM */
	var validateResLocations = function(){
		if(htz.homepage.jsflag.isDropDownLocation)
			return validateDropDownLocations();
		
		return true;
	};
	var validateResDates = function(){
		with(document.resForm){
			if($.trim(pickupDay.value).length == 0){
				alert(htz.homepage.jscontent.choosePickDate);
				return false;
			}
			if($.trim(dropoffDay.value).length == 0){
				alert(htz.homepage.jscontent.chooseReturnDate);
				return false;
			}
		}
		return true;
	};
	var handleFTSSubmit = function(){
		with(document.resForm){
			if($.trim(wasFormSubmitted.value) == 'true'){
				continueButton.value = 'continue'; 
		 		submit();
			}
	    }
 	};
	var validateArrivalInformation = function(){
		var formVar = document.resForm;
		
		if(formVar.arrivingInfoRadioButton){
			if(!$.isArray(formVar.arrivingInfoRadioButton) || formVar.arrivingInfoRadioButton[2].checked){
				if($.trim(formVar.selectedAirline.value).length == 0){
					alert(htz.homepage.jscontent.arrivalOptionError);
					return false;
				}
				return true;
			}
		
			if(!formVar.arrivingInfoRadioButton[0].checked && !formVar.arrivingInfoRadioButton[1].checked && !formVar.arrivingInfoRadioButton[2].checked)
			{
				alert(htz.homepage.jscontent.arrivalInfoError);
				return false;
			}
		}
		return true;
	};
	
	determineOverallFormSubmission = function() {
		document.resForm.continueButton.value = 'continue';
		document.resForm.submit()	
	}	
	
	handlePopupMessages = function() {
		var self = this;
		self.returnType = 'Y';
		
		if($('#inpDropoffIsServedBy').val() == 'Y' && $('#pickupHiddenEOAG').val() != $('#dropoffHiddenEOAG').val()) {
			alert(htz.homepage.jscontent.cannotReturn);
			return false;
		}
		
		if(!htz.homepage.jsflag.isDropDownLocation && ($('#pickupHiddenEOAG').val() != '' || $('#dropoffHiddenEOAG').val() != '')){
			if($('#inpPickupIsServedBy').val() == 'Y' || $('#pickupHasSpecialInstruction').val() == 'true') {
				pickupLocPopup =  window.open(htz.config.rootContext+'/location/templates/locationsMessagePopupTile.jsp?oag=' + $('#pickupHiddenEOAG').val() + '&locType=pUp&origin=homepage','pickupLocPopup','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=350,height=400');
				pickupLocPopup.focus();
				self.returnType = 'N';
			}
			if(( $('#dropoffHasSpecialInstruction').val() == 'true') && $('#pickupHiddenEOAG').val() != $('#dropoffHiddenEOAG').val() && $("#oneWayTripCheckBox").attr("checked")) {
				dropoffLocPopup = window.open(htz.config.rootContext+'/location/templates/locationsMessagePopupTile.jsp?oag=' + $('#dropoffHiddenEOAG').val() + '&locType=dOff&origin=homepage','dropoffLocPopup','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=350,height=400');					
				self.returnType = 'N';
			}
		}
		if(self.returnType == 'Y') {
			return true;
		} else {
			return false;
		}
	};
	var populateLocation  = function (locationList){
		var pickCountry = $("#pickupCountry");
		var pickLocation = $("#pickupLocation");
		var dropLocation = $("#dropoffLocation");
		var pickUpOptions = pickLocation.attr('options');
		var dropOffOptions = dropLocation.attr('options');	
		
		pickCountry.attr("disabled", false);
		pickLocation.empty();
		dropLocation.empty();			
		if(locationList.nvplist.length <= 1){		
			locationList.nvplist[0].name = htz.homepage.jscontent.selectAnotherCountry;
		} else {
			locationList.nvplist[0].name = htz.homepage.jscontent.selectALocation;
		}
		
		for(i=0; i<locationList.nvplist.length; i++){
		    pickUpOptions[pickUpOptions.length] = new Option(locationList.nvplist[i].name, locationList.nvplist[i].value);
		    dropOffOptions[dropOffOptions.length] = new Option(locationList.nvplist[i].name, locationList.nvplist[i].value);
		}		
	};
	var resetSelections = function (){
		$("#pickupCountry").attr("disabled", false);
		$("#pickupLocation").empty().append($('<option>').text(htz.homepage.jscontent.selectCountry).val(""));
		$("#dropoffLocation").empty().append($('<option>').text(htz.homepage.jscontent.selectCountry).val(""));
	};
	var validateDropDownLocations = function(){
		var pickupCountry = $("#pickupCountry");
		var pickupLocation = $("#pickupLocation");
		var resCheckBox = $("#oneWayTripCheckBox");
		var dropoffLocation = $("#dropoffLocation");	
		
		if(($.trim(pickupCountry.val())).length == 0 || ($.trim(pickupLocation.val())).length == 0){
			if(($.trim(pickupCountry.val())).length == 0){
				alert(htz.homepage.jscontent.selectCountry);
				pickupCountry.focus();
			} else {
				alert(htz.homepage.jscontent.selectPickupLoc);			
				pickupLocation.focus();
			}
			return false;			
		}
		
		if(resCheckBox.attr("checked")){
			if(($.trim(dropoffLocation.val())).length == 0){
				alert(htz.homepage.jscontent.selectDropoffLoc);
				dropoffLocation.focus();
				return false;
			}
		}
	
		return true;
	};
	var handleDropDownSubmit = function(){
		with(document.resForm){ 
			pickupHiddenEOAG.value = pickupLocation.value;
			var index = pickupLocation.selectedIndex;
			pickupLocation.options[index].value = pickupLocation.options[index].text;
			
			if(returnAtDifferentLocationCheckbox.checked){
				dropoffHiddenEOAG.value = dropoffLocation.value;
                var index = dropoffLocation.selectedIndex;
				dropoffLocation.options[index].value = dropoffLocation.options[index].text;
			} else 
				dropoffHiddenEOAG.value = "";
		   
		   continueButton.value = 'continue';
		   submit();
	   }		
	};
	return {
		toggleTabs: function(cN) {
			$('#homeResFormTabs').removeClass().addClass(cN);				
		},
		openDandC : function (url,isLoginRequired){
			if(!isLoginRequired)
				window.open(url,'resWin','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=300,height=425').focus();
			else		
				document.location.href = url;			
		},
		setDandCChangedValue : function (id, originalLocationValue, flagValue, element){	
			if(element.value != originalLocationValue)
				$("#"+id).val(flagValue);
		    return true;
		},
		showOneWayTrip : function (){
			if($('#oneWayTripCheckBox').attr("checked"))
				$('#rtnLocationSec').show();
			else {
				$('#rtnLocationSec').hide();
				$('#inpDropoffIsServedBy').val('');
				$('#dropoffLocation').val('');
				$('#dropoffHiddenEOAG').val('');
			}
		},
		openLinkInPopup : function (url, width, height) {
			if(!width) width = 500;
			if(!height) height = 500;
			var left = (window.screen.width/2) - (width/2);
			window.open(url,'resWin','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=' + width + ',height=' + height +', left='+left).focus();
		},
		handleFormSubmit : function(){
			// pickup and dropoff location
			if(!validateResLocations()) return;
			// pickup and dropoff dates
			if(!validateResDates()) return;
			//arrival information
			if (!validateArrivalInformation()) return;
			// handle served by information and special instructions scenario
			if(!handlePopupMessages()) return;
			// submit form
			if(htz.homepage.jsflag.isDropDownLocation){
				handleDropDownSubmit();				
			} else {
				document.resForm.wasFormSubmitted.value = "true";
				handleFTSSubmit();
			}
		},
		// Multi CDP Widget - Release 11.10
		handleMultiCDPFormSubmit : function() {
			// pickup and dropoff location
			if(!validateResLocations()) return;
			// pickup and dropoff dates
			if(!validateResDates()) return;
			//arrival information
			if (!validateArrivalInformation()) return;
			// handle served by information and special instructions scenario
			if(!handlePopupMessages()) return;
			// submit form
			if(htz.homepage.jsflag.isDropDownLocation) {				
				widgetObj.cdpWidgetDropdownSubmit();				
			} else {
				document.resForm.wasFormSubmitted.value = "true";
				widgetObj.cdpWidgetFTSSubmit();
			}
		},
		handlePopupSubmit : function() {
			if(pickupLocPopup != null) { 
				pickupLocPopup.close();
			}
			if(dropoffLocPopup != null) {
				dropoffLocPopup.close();
			}
			with(document.resForm){ 
				 continueButton.value = 'continue';
		   		submit();
			}
		},
		handleDropDownSubmit : function() {
		},
		toggleAffiliations : function(obj){
			if(obj != null && obj.checked) $('#affiliationsSection').show();
			else $('#affiliationsSection').hide();
		},
		toggleCorpDependentFields : function (obj) {
			with(document.resForm){
				if(obj.checked) { 
					$('#RQCVITSection').hide(); 
					
					if(!htz.homepage.jsflag.showPCField)
					    $('#PCSection').hide();
					
					if($.trim(cdpField.value).length > 0 && $('#cdpOptions').length) {
						corporateRate.checked = true;
						officialTravel.checked = true;
						$('#cdpOptions').show();
					}
					corpCustomer.value = "Y";
				} else {
					$('#RQCVITSection').show(); 
					$('#PCSection').show();
					if($('#cdpOptions').length){
						$('#cdpOptions').hide();
						corporateRate.checked = false;
						officialTravel.checked = false;
					}
					corpCustomer.value = "N";
				}
			}
		},
		showCDPOptions : function (){ 
			with(document.resForm){
				var cdpOption = $('#cdpOptions').length ? $('#cdpOptions').get(0) : null;
				if(cdpOption == null) return;
				if($.trim(cdpField.value).length > 0){
					if(typeof corpCustCheckBoxFE != "undefined") {
						if(corpCustCheckBoxFE.checked){
							corporateRate.checked = true;
							officialTravel.checked = true;
							cdpOption.style.display = "block";
						}
					} else {
						cdpOption.style.display = "block";
					}
			    } else {
			    	cdpOption.style.display = "none";
			    	if(typeof corporateRate != "undefined")
						corporateRate.checked = false;
					if(typeof officialTravel != "undefined")
						officialTravel.checked = false;
				}
			}
		},
		highlightRow : function (element,trId) {
			if($.trim(element.value).length == 0) {
				$("#"+trId).removeClass('homeValidDisctountCode');
			} else {
				$("#"+trId).addClass('homeValidDisctountCode');
			}
		},
		
		showCdpRqWarning : function (){
			with (document.resForm){
				if(corporateRate.checked)
					if(typeInRateQuote.value != "" && !($('#corpCustCheckBoxFE').length && $('#corpCustCheckBoxFE').attr("checked")))
						alert(htz.homepage.jscontent.cdprqError);
			}
		},
		arrivalRadioButton : function () {
			$("#arrivalDropDownRadio").attr("checked", true);
		},
		determineOverallFormSubmission : function (){
			handleFTSSubmit();
		},
		findRes : function (x){
			if(typeof(x)=="object")	{ 
				$("#confirmationNumber").val(x.innerHTML)
				$("#confirmationNumber").css(	{ 'color' : 'white' } ) 
				}
	 		document.resModifyForm.submit();
	 	},		 
	 	handlePickCountrySelection : function(url){
			var pickCountry = $("#pickupCountry");
			if(pickCountry.attr("selectedIndex") > 0){
				pickCountry.attr("disabled", true);
				url+="?countrySelection="+pickCountry.val();
				$("#pickupLocation").empty().append($('<option>').text(htz.homepage.jscontent.loadingText).val(""));
				$.getJSON(url , function (data){ populateLocation(data);});
			} else 
			  resetSelections();
		},
		showAgeText : function(link){
			var self = this;
			self.overlayBox.reset(); 
		  	self.overlayBox.params.url = "homePageAgeText";
		  	self.overlayBox.params.width = 360;
		  	self.overlayBox.params.center = false;
		  	self.overlayBox.params.screen = 0;
		  	self.overlayBox.params.top = link.offset().top + 15;
		  	self.overlayBox.params.left = link.offset().left;
		  	self.overlayBox.params.scroll = false;
		  	self.overlayBox.init();
		  	self.overlayBox.showRequest();
		},	    
		reloadDropoffLocation : function(){
			var pickLocation = $("#pickupLocation");
			var dropLocation = $("#dropoffLocation");	
			
			dropLocation.empty();
			pickLocation = pickLocation[0];
			dropLocation = dropLocation[0]; 
			
			if(pickLocation.value != "" && pickLocation.value != null){
				for(i = 0; i < pickLocation.options.length ; i++){
					if(pickLocation.options[i].value != pickLocation.value){
						dropLocation.options[dropLocation.options.length] = new Option(pickLocation.options[i].text,pickLocation.options[i].value);
					}
				}
				if($("#oneWayTripCheckBox").attr("checked")) dropLocation.focus();		
			} else {
				for(i = 0 ; i < pickLocation.options.length ; i++){
					dropLocation.options[i] = new Option(pickLocation.options[i].text,pickLocation.options[i].value);
				}
			}
		},	
		loadDoubleClickBanners : function(obj){
			var eoag = $.trim(obj.value);
			if(eoag.length == 3 || eoag.length == 6){
				$.ajax({
					url: htz.config.rootContext +'/handlers/LocationChangeAJAXHandler',
					data : { 'eoag' : eoag, 'loadBanner' : 'true' },
					type: "GET",
					dataType: "json",
					cache: false,
					success: function(data, status, xhr){
						if ( data.DoubleClickBanner == true ){
							var cotainer = $("#homePageBannerAdContainer #homePageBannerAds").length > 0 ? "homePageBannerAds" : "homePageBannerAdContainer"; 
							$("#"+cotainer).load(htz.config.rootContext + '/reservation/gaq/templates/home/reservationOnHomepageAds.jsp?bannerOnly=Y');					
						}
					}
				});
			}
		},
		lookupLocation : function(loadBanner, oag, calendar) {
			if (oag.length > 0) {
				$.ajax({
					url: htz.config.rootContext + '/handlers/LocationChangeAJAXHandler',
					type: "GET",
					data : { 'eoag' : oag, 'loadBanner' : loadBanner},
					dataType: "json",
					cache: false,
					success: function(data, status, xhr){
						if ( loadBanner && data.DoubleClickBanner == true ){
							var cotainer = $("#homePageBannerAdContainer #homePageBannerAds").length > 0 ? "homePageBannerAds" : "homePageBannerAdContainer"; 
							$("#"+cotainer).load(htz.config.rootContext + '/reservation/gaq/templates/home/reservationOnHomepageAds.jsp?bannerOnly=Y');
						}
						if (calendar != null) {
							calendar.processLocationChange(data, calendar);
						}
					}
				});
			} else if (calendar != null) {
				calendar.processLocationChange(null, calendar);
			}
		},
		saveLocationInSession: function(location, origin){
			var $pickupAutofill = $('#inpPickupAutoFill').val();
			var $dropoffAutofill = $('#inpDropoffAutoFill').val();
			var $pickupHiddenEOAG = $('#pickupHiddenEOAG').val();
			var $dropoffHiddenEOAG = $('#dropoffHiddenEOAG').val();
			
			if(origin=='pickup' && typeof location=='object') {
				$.ajax({
					url: htz.config.rootContext + '/handlers/SaveSessionInformationHandler',
					data: {
						pickupLocation: location.locationTitle || location.displayText, 
						pickupStateCode: location.stateCode,
						pickupCountry: location.countryCode,
						pickupSearchType: location.searchType,
						pickupAutofill: $pickupAutofill,
						pickupEOAG: $pickupHiddenEOAG
					}
				});
			} 
			if($pickupHiddenEOAG == '' && origin=='pickup' && typeof location=='string') {
				$.ajax({
					url: htz.config.rootContext + '/handlers/SaveSessionInformationHandler',
					data: {
						pickupLocation: location
					}
				});
			} 
			if(origin=='dropoff' && typeof location=='object'){
				$.ajax({
					url: htz.config.rootContext + '/handlers/SaveSessionInformationHandler',
					data: {
						dropoffLocation: location.locationTitle || location.displayText, 
						dropoffStateCode: location.stateCode,
						dropoffCountry: location.countryCode,
						dropoffSearchType: location.searchType,
						dropoffAutofill: $dropoffAutofill,
						dropoffEOAG: $dropoffHiddenEOAG
					}
				});
			}
			if($dropoffHiddenEOAG == '' && origin=='dropoff' && typeof location=='string'){
				$.ajax({
					url: htz.config.rootContext + '/handlers/SaveSessionInformationHandler',
					data: {
						dropoffLocation: location
					}
				});
			}
						
		},
		saveCDPInSession: function(CDPText, selectedRadioName){
			$.ajax({
				url: htz.config.rootContext + '/handlers/SaveSessionInformationHandler',
				data: {cdp: CDPText, cdpRadioButton: selectedRadioName}
			});
		}
	}
})();
    
		var AppHomePage = (function() {
	$(document).ready(function() {
		AppHomePage.init();  
	});
	
	var preparePage = function() { 
		$("div.tmplPageContainer, div.tmplContainerMain, #homePageContainer").addClass("hpTransContainer");
		$("div.tmplPageContainer").addClass("hpRelContainer");
		$("div.tmplContainerMain").addClass("hpTmplContainer");
		$("table.homeAffiliationsTable").addClass("hpDiscount");
	}; 
	
	return {
		init : function() {
			preparePage();
		}
	};
})();

                
	   
	     
	
	
	
	
		
		
	 
	  
	 
	 
	
		
	
	
     



  
             
      
           
                                                                                 
                                
	            
	
	
		  
			
				
			
       
                                                                                                                  
/* EOF */                                                                                                                
                                                                              
/* EOF */                                                                                                                         
