// Js for search results 

var useAjax = 0;

// Javascript function called on change of propositions drop-down,
	// to populate profile-dependent destinations.
    function populateDestinationDropDown() {
        var profile = dwr.util.getValue("propositionSelect");
        AjaxSearchTools.populateDestinations(profile, updateDestinations);
        AjaxSearchTools.populateDefaultDestination(profile, updateDefaultDest);
        }


	// Refreshing destinations drop-down
    function updateDestinations(data) {
    	var profile = dwr.util.getValue("propositionSelect");
        dwr.util.removeAllOptions("destinationSelect");
        dwr.util.addOptions("destinationSelect", data);
        var destination = dwr.util.getValue("destinationSelect");
        AjaxSearchTools.populateResorts(destination, profile, updateResorts);
	AjaxSearchTools.populateDepartures(destination, profile, updateDepartures);     
		//AjaxSearchTools.populateDefaultDeparture(destination, updateDefaultDept);
    }
      // Setting default destination in drop-down
    function updateDefaultDest(data) {
       document.getElementById('destinationSelect').value = data;
     }
       // Setting default departure in drop-down
    function updateDefaultDept(data) {
       if (data == '') {
		dwr.util.addOptions("departureSelect", data);
		} else {
			document.getElementById('departureSelect').value = data;
		}
     }
       // Setting default inputnights in drop-down
    function updateDefaultNights(data) {
       document.getElementById('inputnights').value = data;
     }
    
	// Javascript function called on change of propositions drop-down,
	// to populate profile-dependent durations.
   function populateDurationDropDown() {
	    var profile = dwr.util.getValue("propositionSelect");
        AjaxSearchTools.populateDurations(profile, updateDurations);
        }

	//Refreshing durations drop-down
   function updateDurations(data) {
	    var profile = dwr.util.getValue("propositionSelect");
        dwr.util.removeAllOptions("inputnights");
        dwr.util.addOptions("inputnights", data);
        AjaxSearchTools.populateDefaultDuration(profile, updateDefaultNights);
        }

// Javascript function called on change of propositions drop-down,
  // to populate profile-dependent departure date.
	function populateDepartureDate(depDateID) {
		  var profile = dwr.util.getValue("propositionSelect");
		  var profile = dwr.util.getValue("propositionSelect");
		  var depDate = document.getElementById('departureDate').value;
		  var holidayType = document.getElementById('propositionSelect');
		  if(holidayType.options[holidayType.selectedIndex].text == "Snow holidays"){
			   populateSnowDepDate();
		  }else{
			  AjaxSearchTools.populateDepDate(profile,depDate, updateDepartureDate);
		  }
	   }

// setting departure date
   function updateDepartureDate(data){
	   arrDateTokens = data.split("-");
	   if(arrDateTokens.length > 0)
	       document.getElementById('defaultDay').innerHTML = arrDateTokens[1];
		   document.getElementById('departureDate').value = arrDateTokens[0];
   }
   
   function refresher(searchPanelType){
   	if(searchPanelType != 'extras'){
   		window.location.href = unescape(window.location.pathname) + "?passedSearchPanelTypeUrl="+searchPanelType;
   	} else {
   		parent.location.replace('http://tcs4agents.thomascook.com/ge')
   	}
   }


// For Budgets

 // Setting default budgets in drop-down
    function updateDefaultBudgets(data) {		
       document.getElementById('inputbudget').value = data;		
     }
    
	// Javascript function called on change of propositions drop-down,
	// to populate profile-dependent budgets.
   function populateBudgetDropDown(tourOpsName) {
        var profile = dwr.util.getValue("propositionSelect");
        AjaxSearchTools.populateBudgets(profile,tourOpsName, updateBudgets);
    }

	//Refreshing budgets drop-down
   function updateBudgets(data) {
	    var profile = dwr.util.getValue("propositionSelect");
        dwr.util.removeAllOptions("inputbudget");
        dwr.util.addOptions("inputbudget", data);
		//making another async call to server
		AjaxSearchTools.populateDefaultBudget(profile, updateDefaultBudgets);
   }


		//For Board basis
 // Setting default updateDefaultBoardBasis in drop-down
    function updateDefaultBoardBasis(data) {
       document.getElementById('inputboard').value = data;
     }
    
	// Javascript function called on change of propositions drop-down,
	// to populate profile-dependent updateBoardBasis.
   function populateBBDropDown() {
        var profile = dwr.util.getValue("propositionSelect");
        AjaxSearchTools.populateBoardBasis(profile, updateBoardBasis);
        }

	//Refreshing inputboard drop-down
   function updateBoardBasis(data) {
	   var profile = dwr.util.getValue("propositionSelect");
        dwr.util.removeAllOptions("inputboard");
        dwr.util.addOptions("inputboard", data);
        AjaxSearchTools.populateDefaultBB(profile, updateDefaultBoardBasis);
        }

// For star rating

 // Setting default updateDefaultBoardBasis in drop-down
    function updateDefaultStarRating(data) {
       document.getElementById('inputstarrating').value = data;
     }
    
	// Javascript function called on change of propositions drop-down,
	// to populate profile-dependent updateBoardBasis.
   function populateStarRatingDropDown() {
        var profile = dwr.util.getValue("propositionSelect");
        AjaxSearchTools.populateStarRating(profile, updateStarRating);
        }

	//Refreshing inputboard drop-down
   function updateStarRating(data) {
	   var profile = dwr.util.getValue("propositionSelect");
        dwr.util.removeAllOptions("inputstarrating");
        dwr.util.addOptions("inputstarrating", data);
		AjaxSearchTools.populateDefaultStarRating(profile, updateDefaultStarRating);
        }

	// Javascript function called on change of destinations drop-down,
	// to populate destination-dependent resorts.
    function onDestinationChange() {
    	var proposition = dwr.util.getValue("propositionSelect");
        var destination = dwr.util.getValue("destinationSelect");
       // alert("destination -"+destination);
        AjaxSearchTools.populateResorts(destination, proposition, updateResorts);
        AjaxSearchTools.populateDepartures(destination, proposition, updateDepartures);
       // AjaxSearchTools.populateDefaultDeparture(destination, updateDefaultDept);
        }

	// Refreshing resorts drop-down
    function updateResorts(data) {
        dwr.util.removeAllOptions("resortSelect");
        dwr.util.addOptions("resortSelect", data);
        }

	//Refreshing departures drop-down
     function updateDepartures(data) {  
		     dwr.util.removeAllOptions("departureSelect"); 
		     dwr.util.addOptions("departureSelect", data);
     }
     
     
      function onReviewDestinationChange() { 
        var destination = dwr.util.getValue("destinationSelect");
        AjaxSearchTools.populateReviewResorts(destination, updateReviewResorts);
      }
      
	function onMbcDeparturePointChange(filter, searchPanel) {
		var destination = dwr.util.getValue("destination");
			var departurePoint = dwr.util.getValue("departurePoint");

		if(useAjax == 2 || useAjax == 0){
			useAjax = 2;
			 AjaxSearchTools.mbcPointFilter(searchPanel, departurePoint, filter, 'childValues', mbcUpdateDestinations);
		}
	    }

	function onMbcDestinationChange(filter, searchPanel) { 
		var destination = dwr.util.getValue("destination");
		var departurePoint = dwr.util.getValue("departurePoint");

		if(useAjax == 1 ||  useAjax == 0){
			useAjax = 1;
			AjaxSearchTools.mbcPointFilter(searchPanel, destination, filter, 'parentValues', mbcUpdateDeparturePoints);
		}

	}
	
	function onMbcCountryChange(filter, searchPanel) { 
		var destination = dwr.util.getValue("region");
		if(useAjax == 1 ||  useAjax == 0){
			useAjax = 1;
			AjaxSearchTools.mbcPointFilter(searchPanel, destination, filter, 'childValues', mbcUpdateCountryPoints);
		}
	}
	
	function onMbcPfaCountryCookieChange(filter, searchPanel) {
		var destination = dwr.util.getValue("region");
		if(useAjax == 1 ||  useAjax == 0){
			useAjax = 1;
			AjaxSearchTools.mbcPointFilter(searchPanel, destination, filter, 'childValues', mbcUpdatePfaCountryPointsCookie);
		}
	}
	
	function onMbcAoCountryCookieChange(filter, searchPanel) {
		var destination = dwr.util.getValue("region");
		if(useAjax == 1 ||  useAjax == 0){
			useAjax = 1;
			AjaxSearchTools.mbcPointFilter(searchPanel, destination, filter, 'childValues', mbcUpdateAoCountryPointsCookie);
		}
	}
	
	function onMbcCrxCountryCookieChange(filter, searchPanel) {
		var destination = dwr.util.getValue("region");
		if(useAjax == 1 ||  useAjax == 0){
			useAjax = 1;
			AjaxSearchTools.mbcPointFilter(searchPanel, destination, filter, 'childValues', mbcUpdateCrxCountryPointsCookie);
		}
	}

	function onMbcDestinationPointChange(filter, searchPanel) { 
		var destination = dwr.util.getValue("country");
		if(useAjax == 1 ||  useAjax == 0){
			useAjax = 1;
			AjaxSearchTools.mbcPointFilter(searchPanel, destination, filter, 'childValues', mbcUpdateDestinationPoints);
		}
	}
	
	function onMbcDestinationPointCookieChange(filter, searchPanel) { 
		var destination = getCookie("flightAndHotelCountryDestination");
		if(useAjax == 1 ||  useAjax == 0){
			useAjax = 1;
			AjaxSearchTools.mbcPointFilter(searchPanel, destination, filter, 'childValues', mbcUpdateDestinationPointsCookie);
		}
	}
	
	function onMbcCityChange(filter, searchPanel) { 
		var destination = dwr.util.getValue("country");
		if(useAjax == 1 ||  useAjax == 0){
			useAjax = 1;
			AjaxSearchTools.mbcPointFilter(searchPanel, destination, filter, 'childValues', mbcUpdateCityPoints);
		}
	}
	
	function onMbcCityCookieChange(filter, searchPanel) { 
		var destination = getCookie("hotelOnlyCountryDestination");
		if(useAjax == 1 ||  useAjax == 0){
			useAjax = 1;
			AjaxSearchTools.mbcPointFilter(searchPanel, destination, filter, 'childValues', mbcUpdateCityCookiePoints);
		}
	}

	function onMbcPickupDropoffChange(filter, searchPanel) { 
		var destination = dwr.util.getValue("country");

		if(useAjax == 1 ||  useAjax == 0){
			useAjax = 1;
			AjaxSearchTools.mbcPointFilter(searchPanel, destination, filter, 'childValues', mbcUpdatePickupDropoff);
		}
	}
	
	function onMbcPickupDropoffCookieChange(filter, searchPanel) { 
		var destination = getCookie("carCountryDestination");

		if(useAjax == 1 ||  useAjax == 0){
			useAjax = 1;
			AjaxSearchTools.mbcPointFilter(searchPanel, destination, filter, 'childValues', mbcUpdatePickupDropoffCookie);
		}
	}

	function mbcUpdateDestinations(data){
		dwr.util.removeAllOptions("destination");
		dwr.util.addOptions("destination", data);
	}

	function mbcUpdateDeparturePoints(data){
		dwr.util.removeAllOptions("departurePoint");
		dwr.util.addOptions("departurePoint", data);
	}

	function mbcUpdateCountryPoints(data){
		dwr.util.removeAllOptions("country");
		dwr.util.addOptions("country", ["Pick country"]);
		dwr.util.addOptions("country", data);
	}
	
	function mbcUpdatePfaCountryPointsCookie(data){
		dwr.util.removeAllOptions("country");
		dwr.util.addOptions("country", ["Pick country"]);
		dwr.util.addOptions("country", data);
		var countryText = getCookie("flightAndHotelCountryDestination");
		if(countryText != null && countryText != ""){
			document.getElementById("country").value = countryText;
		}
	}
	
	function mbcUpdateAoCountryPointsCookie(data){
		dwr.util.removeAllOptions("country");
		dwr.util.addOptions("country", ["Pick country"]);
		dwr.util.addOptions("country", data);
		var countryText = getCookie("hotelOnlyCountryDestination");
		if(countryText != null && countryText != ""){
			document.getElementById("country").value = countryText;
		}
	}
	
	function mbcUpdateCrxCountryPointsCookie(data){
		dwr.util.removeAllOptions("country");
		dwr.util.addOptions("country", ["Pick country"]);
		dwr.util.addOptions("country", data);
		var countryText = getCookie("carCountryDestination");
		if(countryText != null && countryText != ""){
			document.getElementById("country").value = countryText;
		}
	}

	function mbcUpdateDestinationPoints(data){
		dwr.util.removeAllOptions("DESTINATION");
		dwr.util.addOptions("DESTINATION", ["Pick destination"]);
		dwr.util.addOptions("DESTINATION", data);
	}
	
	function mbcUpdateDestinationPointsCookie(data){
		dwr.util.removeAllOptions("DESTINATION");
		dwr.util.addOptions("DESTINATION", ["Pick destination"]);
		dwr.util.addOptions("DESTINATION", data);
		var destination = getCookie("flightAndHotelResortDestination");
		if(destination != null && destination != ""){
			setDropDownToCookieValueName("DESTINATION", getCookie("flightAndHotelResortDestination"));
		}
	}
	
	function mbcUpdateCityPoints(data){
		dwr.util.removeAllOptions("DESTINATION");
		dwr.util.addOptions("DESTINATION", ["Pick destination"]);
		dwr.util.addOptions("DESTINATION", data);
	}
	
	function mbcUpdateCityCookiePoints(data){
		dwr.util.removeAllOptions("DESTINATION");
		dwr.util.addOptions("DESTINATION", ["Pick destination"]);
		dwr.util.addOptions("DESTINATION", data);
		var destination = getCookie("hotelOnlyResortDestination");
		if(destination != null && destination != ""){
			setDropDownToCookieValueName("DESTINATION", getCookie("hotelOnlyResortDestination"));
		}
	}

	function mbcUpdatePickupDropoff(data){
		dwr.util.removeAllOptions("pickupLocation");
		dwr.util.removeAllOptions("dropoffLocation");
		dwr.util.addOptions("pickupLocation", ["Choose pickup"]);
		dwr.util.addOptions("dropoffLocation", ["Choose dropoff"]);
		dwr.util.addOptions("pickupLocation", data);
		dwr.util.addOptions("dropoffLocation", data);
	}
	
	function mbcUpdatePickupDropoffCookie(data){
		dwr.util.removeAllOptions("pickupLocation");
		dwr.util.removeAllOptions("dropoffLocation");
		dwr.util.addOptions("pickupLocation", ["Choose pickup"]);
		dwr.util.addOptions("dropoffLocation", ["Choose dropoff"]);
		dwr.util.addOptions("pickupLocation", data);
		dwr.util.addOptions("dropoffLocation", data);
		var pickup = getCookie("carPickup");
		if(pickup != null && pickup != ""){
			setDropDownToCookieValueName("pickupLocation", getCookie("carPickup"));
		}
		var dropoff = getCookie("carDropoff");
		if(dropoff != null && dropoff != ""){
			setDropDownToCookieValueName("dropoffLocation", getCookie("carDropoff"));
		}
	}
	

  	function checkform(searchPanel) {
  		
  		if (searchPanel == 'pfa') {
			// Child age error message
			for (i=1;i<=6;i++) {
				var childDisplay = "child"+i;
				var childCombo = "child"+i+"Combo";
				if (document.getElementById(childDisplay).style.display != 'none') {
					if (document.getElementById(childCombo).value == "") {
						document.getElementById("childAgeError").style.display = 'block';
						return false;
					}
				}
			}
			document.getElementById("childAgeError").style.display = 'none';
		}
		
		if (searchPanel != 'crx') {
			var dateValid = validateDate(document.getElementById("departureDate").value);
			if (dateValid != 'true') {
				document.getElementById("dateError").style.display = 'block';
				return false;
			}
		}
		
		
		
		if (document.getElementById("region").value == '-1') {
			document.getElementById("dateError").style.display = 'none';
			document.getElementById("regionError").style.display = 'block';
			return false;
		}
		else if (document.getElementById("country").value == 'Pick country') {
			document.getElementById("dateError").style.display = 'none';
			document.getElementById("regionError").style.display = 'none';
			document.getElementById("countryError").style.display = 'block';
			return false;
		}
		else if (searchPanel == 'crx') {
			if (document.getElementById("pickupLocation").value == 'Choose pickup') {
				document.getElementById("dateError").style.display = 'none';
				document.getElementById("regionError").style.display = 'none';
				document.getElementById("countryError").style.display = 'none';
				document.getElementById("pickupLocationError").style.display = 'block';
				return false;
			}
			else if (document.getElementById("dropoffLocation").value == 'Choose dropoff') {
				document.getElementById("dateError").style.display = 'none';
				document.getElementById("regionError").style.display = 'none';
				document.getElementById("countryError").style.display = 'none';
				document.getElementById("pickupLocationError").style.display = 'none';
				document.getElementById("dropoffLocationError").style.display = 'block';
				return false;
			}
		}
		else if (searchPanel != 'crx') {
			if (searchPanel == 'ao') {
				if (document.getElementById("DESTINATION").value == 'Pick destination') {
					document.getElementById("dateError").style.display = 'none';
					document.getElementById("regionError").style.display = 'none';
					document.getElementById("countryError").style.display = 'none';
					document.getElementById("destinationError").style.display = 'block';
					return false;
				}
			}
			
			if (searchPanel == 'pfa' || searchPanel == 'pra' || searchPanel == 'pfc') {
				if (document.getElementById("DESTINATION").value == 'Pick destination') {
					document.getElementById("dateError").style.display = 'none';
					document.getElementById("regionError").style.display = 'none';
					document.getElementById("countryError").style.display = 'none';
					document.getElementById("destinationError").style.display = 'block';
					return false;
				}
				if (document.getElementById("departurePoint").value == '-1') {
					document.getElementById("dateError").style.display = 'none';
					document.getElementById("regionError").style.display = 'none';
					document.getElementById("countryError").style.display = 'none';
					document.getElementById("destinationError").style.display = 'none';
					document.getElementById("departureError").style.display = 'block';
					return false;
				}
			}
		}
		else {
			return true;
		}
		
		if (searchPanel == 'pfa') {
			flightAndHotelSubmit();
		}
		if (searchPanel == 'ao') {
			hotelOnlySubmit();
		}
		if (searchPanel == 'crx') {
			if(validatePickupAndDropOffDates(document.getElementById("pickupDate"),document.getElementById("returnDate"),document.getElementById("fromDateTime_hour"),document.getElementById("toDateTime_hour"))){
				carSubmit();
				return true;
			}
			else
				return false;
		}
	  }

	  function validatePickupAndDropOffDates(pickUpDateObj,dropOffDateObj,pickUpTimeObj,dropOffTimeObj){
		  var canSubmit = true;
		 
		  if(!isValidDate(pickUpDateObj)){
			  document.getElementById('dateError').innerHTML = "Please choose a valid date";
			  canSubmit = false;
		  }if(!isValidDate(dropOffDateObj)){
			  document.getElementById('dateError').innerHTML = "Please choose a valid date";
			  canSubmit = false;
		  }if(canSubmit){
				var pickUpDate=new Date();
				var dropOffDate=new Date();
				var pickUpDateSplit = pickUpDateObj.value.split("/"); 
				var dropOffDateSplit = dropOffDateObj.value.split("/"); 
				pickUpDate.setFullYear(20+pickUpDateSplit[2],pickUpDateSplit[1]-1,pickUpDateSplit[0]);
				dropOffDate.setFullYear(20+dropOffDateSplit[2],dropOffDateSplit[1]-1,dropOffDateSplit[0]);
				if(pickUpTimeObj != null && dropOffTimeObj != null){
					pickUpDate.setHours(pickUpTimeObj.value);
					dropOffDate.setHours(dropOffTimeObj.value);
				}
				if(pickUpDate.getTime()>dropOffDate.getTime()){
					document.getElementById('dateError').innerHTML = "Dropoff date must be after the Pickup date";
					canSubmit = false;
				}else if(pickUpDate.getTime()==dropOffDate.getTime()){
					document.getElementById('dateError').innerHTML = "Pickup date and time, Dropoff date and time should not be same";
					canSubmit = false;
				}
		   }
		   if(!canSubmit)
			   document.getElementById('dateError').style.display = 'inline';
		   else
   			   document.getElementById('dateError').style.display = 'none';
		   return canSubmit;
	  }

	  function mbcSearchSwitch(url, productType){
	  	  AjaxSearchTools.getInclude(url, productType, changeSearch);  
	  }
	  
	  function changeSearch(data){
		 var currentSearchPanel = dwr.util.getValue("rightcont"); 
		 dwr.util.setValue("rightcont", data);
	  }
	  
      // Refreshing resorts drop-down
      function updateReviewResorts(data) {

        	dwr.util.removeAllOptions("resortSelect");
        	dwr.util.addOptions("resortSelect", data);
        	//calling this because on change of destination to default "select destination"
			//should also change the accommodation in addition to resorts.
			onReviewResortChange();
      }
      
      function onReviewResortChange() { 
        var resort = dwr.util.getValue("resortSelect");
        AjaxSearchTools.populateAccommodations(resort, updateReviewAccommodations);
      }

           // Refreshing Accommodation drop-down
      function updateReviewAccommodations(data) {
         dwr.util.removeAllOptions("accommodationSelect");
         dwr.util.addOptions("accommodationSelect", data);
       
      }   
        

	  function updateCompareList(action,selectedID,successURL,errorURL){
		  //selectedID is of the format 2x2_CurrentPackageID / 3x3_CurrentPackageID / CurrentPackageID -(for 1x1).
		  //So stripping of 2x2_ & 3x3_ if it exists.
		  if(selectedID.indexOf("_")!= -1){
               selectedID = selectedID.substring(selectedID.indexOf("_")+1);
		  }

		  //making an asynchronous java method call
		  AjaxSearchResultTools.reqUpdateComparisonList(action,selectedID,successURL,errorURL,updateCompareCount);
	  }

	  function updateCompareCount(data){
		  if(document.getElementById("holDetPopSpanID") || document.getElementById("holInfoPopSpanID")){
			  //pushing the d ata to the parent window.
			  if(window.opener.document.getElementById("compCountSpanID"))
			  {
                  window.opener.document.getElementById("compCountSpanID").innerHTML = data;
				  window.opener.globCompCount = data;
			  }
		  }else{
			 if(document.getElementById("compCountSpanID")){
				document.getElementById("compCountSpanID").innerHTML = data;
			 }
		  }
      }

	  function updateCompareList_AltFlight(action,selectedID,successURL,errorURL){
          AjaxSearchResultTools.reqUpdateComparisonListForAlternateFlightPackage(action,selectedID,successURL,errorURL,updateCompareCount)
	  }

	  function ajaxAddToShortList(action,selectedID,shortListURL,resultIndex)
	  {
		  //selectedID is of the format 2x2_CurrentPackageID / 3x3_CurrentPackageID / CurrentPackageID -(for 1x1).
		  //So stripping of 2x2_ & 3x3_ if it exists.
		  if(selectedID.indexOf("_")!= -1){
               selectedID = selectedID.substring(selectedID.indexOf("_")+1);
		  }

		  //making an asynchronous java method call
		  if(action == "Add"){
				AjaxSearchResultTools.reqAddToShortList(action,selectedID,shortListURL,updateShortListCount);
		  }else if(action == "Remove"){
                AjaxSearchResultTools.reqRemoveFromShortList(action,selectedID,shortListURL,updateShortListCount);
		  }

	  }


      /**
	   * This function updates the shortlist count on holidayplanner.jsp & correspondingly shows/hides save my 
	   * shortlist link.(checkUserStatus() & checkUserStatus_popup() does this).
	   */
      function updateShortListCount(data){

  		  if(document.getElementById("holDetPopSpanID") || document.getElementById("holInfoPopSpanID")){
        	  //calls a method that is defined in holidayInfoPopup.jsp/holidayDetailsPopup.jsp
			  checkUserStatus_popup(data);
		  }else{
			  if(document.getElementById("shortLstSpanID")){
				  document.getElementById("shortLstSpanID").innerHTML = data;
				  //calls a method that is defined in searchResults.jsp/myCompareList.jsp/myShortlist.jsp
				  checkUserStatus(data);
				  if(data > 0){
					   //fix for ACE issue # 850
						if(document.getElementById("errorBlock")){
								//document.getElementsByName("contentLeftDiv")[0].style.display ='block';
								 //document.getElementsByName("contentRightDiv")[0].style.display ='block';
								document.getElementById("errorBlock").style.display ='none';
						}
				  }else{
						//fix for ACE issue # 850
						if(document.getElementById("errorBlock")){
								document.getElementById("bodyLeft").style.display ='none';
								document.getElementById("bodyRight").style.display ='none';
								//document.getElementById("errorBlock").style.display ='block';
								document.getElementById("errorBlock").style.display ='block';
						}
				  }
			  }
		  }
	  }


     function ajaxAddToShortList_AltFlights(action,selectedID,shortListURL,resultIndex){
		  //alert("ajaxAddToShortList_AltFlights");
		  if(action == "Add"){
				AjaxSearchResultTools.reqAddAlternateFlightPackageToShortList(action,selectedID,shortListURL,updateShortListCount);
				
		  }else if(action == "Remove"){
                AjaxSearchResultTools.reqRemoveAlternateFlightPackageToShortList(action,selectedID,shortListURL,updateShortListCount);
		  }
	 }

     /* function updateShortListCount_AltFlights(data){
		  //document.getElementById("shortLstSpanID").innerHTML = "View My Shortlist ("+data+")";
		  document.getElementById("shortLstSpanID").innerHTML = data;
		  alert(data);
		  if(data > 0){
				document.getElementById("saveShrtLstSpanID").style.display = "block";
				//document.getElementById("currShrtLstSpanID").style.display = "none";

	      }else{
		        document.getElementById("saveShrtLstSpanID").style.display = "none";
	            //document.getElementById("currShrtLstSpanID").style.display = "block";
		  } 
	  } */

	 // This function will update the recently viewed list without refreshing the page.
      var selectedPackId = "";
	  var currency = "";
	  function updateRecentlyViewedList(selectedPackageId, currencyCode){
		    selectedPackId = selectedPackageId;
			currency = currencyCode;			
			AjaxSearchResultTools.reqUpdateRecentlyViewed(selectedPackageId,currencyCode,updateRVList);	
	  }
      
	  //This call back method takes a map as an input.
	  function updateRVList(data) {
		   var tmpInnerHTML = "";
		   var holidayDetailPopup ="/search/holiday/holidayDetailPopup.jsp";
		   var counter =0;
		  for (var property in data) {
				// Are there any elements with that id or name
				  //alertMe(property);
				  //alert(counter);
				  if (property != null) {
						var tmpArray = new Array();
						var tmpValue = data[property];
					 if(tmpValue.indexOf("#") > 0){
						 tmpArray = tmpValue.split("#");
					  }
					  if(tmpArray.length ==3){
						  tmpInnerHTML = tmpInnerHTML+ "<li><a href='javascript:openHolidayPopup('"+tmpArray[0]+"','"+holidayDetailPopup+"')' >"+tmpArray[1]+"</a> - "+tmpArray[2]+"</li>";
					  }
					  //else{
						//  tmpInnerHTML = tmpInnerHTML+ "<li><a href='#')' >"+tmpArray[0]+"</a> - £"+tmpArray[1]+"</li>";
					  //} 
					  
				}
			counter++;
		  }
		  selectedPackId = "";
		  if(document.getElementById("lastviewedul") != null){
		 document.getElementById("lastviewedul").innerHTML =tmpInnerHTML;
	  }
	  }
	  
	  function sendRedirect(){
		  if(window.self == window.top){
			var url = getQueryVariable("url");
			if(url != null && url != undefined){
				var point = url.lastIndexOf('&amp;_requestid');
				if(point != -1){		 	
					url = url.substring(0, point);
				}
			parent.location.replace(url);
			}
		  } else {
			 parent.location.replace(window.self.location)
		  }
	  }
	  
	  
	  function getQueryVariable(variable) {
  		var query = window.location.search.substring(1);
		var queryLength = query.length;
		var equalsPosition = query.search("=") + 1;
		return query.substring(equalsPosition, queryLength);
	   } 

	/*Fix for the issue INC700005974197  [P1 Critical priority ] & INC700005916972 [P3 Medium Priority]
	New Ajax methods created for population of all the drop downs on search
	panel specific to Clubbing Holiday Type. The new methods created are:
	populateClubbingDestinationDropDown(),populateClubbingDurationDropDown(),
	updateClubbingDurations(),populateClubbingBudgetDropDown() ,updateClubbingBudgets(),
	populateClubbingBBDropDown(),updateClubbingBoardBasis(),populateClubbingStarRatingDropDown(),
	updateClubbingStarRating(),populateClubbingDepartureDate(),updateClubbingDepartureDate()
	*/

// Javascript function called  to populate Clubbing -dependent destinations.
	function populateClubbingDestinationDropDown() {
        var profile = dwr.util.getValue("propositionSelect"); /*Clubbing proposition ID */
        AjaxSearchTools.populateDestinations(profile, updateDestinations);
        AjaxSearchTools.populateDefaultDestination(profile, updateDefaultDest);
    }
// Javascript function called  to populate Clubbing -dependent durations.
   function populateClubbingDurationDropDown() {
	    var profile = dwr.util.getValue("propositionSelect"); /*Clubbing proposition ID */		
        AjaxSearchTools.populateDurations(profile, updateClubbingDurations);
        }

	//Refreshing durations drop-down
   function updateClubbingDurations(data) {
	    var profile = dwr.util.getValue("propositionSelect"); /*Clubbing proposition ID */
        dwr.util.removeAllOptions("inputnights");
        dwr.util.addOptions("inputnights", data);
        AjaxSearchTools.populateDefaultDuration(profile, updateDefaultNights);
        }

	// Javascript function called  to populate Clubbing -dependent budgets.
   function populateClubbingBudgetDropDown() {
        var profile = dwr.util.getValue("propositionSelect"); /*Clubbing proposition ID */
        AjaxSearchTools.populateBudgets(profile, "CLB", updateClubbingBudgets);
    }

	//Refreshing budgets drop-down
   function updateClubbingBudgets(data) {
	    var profile = dwr.util.getValue("propositionSelect"); /*Clubbing proposition ID */
        dwr.util.removeAllOptions("inputbudget");
        dwr.util.addOptions("inputbudget", data);
		//making another async call to server
		AjaxSearchTools.populateDefaultBudget(profile, updateDefaultBudgets);
   }

  
// Javascript function called  to populate Clubbing-dependent BoardBasis.
   function populateClubbingBBDropDown() {
        var profile = dwr.util.getValue("propositionSelect"); /*Clubbing proposition ID */
        AjaxSearchTools.populateBoardBasis(profile, updateClubbingBoardBasis);
        }

	//Refreshing inputboard drop-down
   function updateClubbingBoardBasis(data) {
	    var profile = dwr.util.getValue("propositionSelect"); /*Clubbing proposition ID */
        dwr.util.removeAllOptions("inputboard");
        dwr.util.addOptions("inputboard", data);
        AjaxSearchTools.populateDefaultBB(profile, updateDefaultBoardBasis);
        }
// Javascript function called  to populate Clubbing -dependent Star rating.
   function populateClubbingStarRatingDropDown() {
		var profile = dwr.util.getValue("propositionSelect"); /*Clubbing proposition ID */
        AjaxSearchTools.populateStarRating(profile, updateClubbingStarRating);
        }

	//Refreshing Star Rating drop-down
   function updateClubbingStarRating(data) {
		var profile = dwr.util.getValue("propositionSelect"); /*Clubbing proposition ID */
        dwr.util.removeAllOptions("inputstarrating");
        dwr.util.addOptions("inputstarrating", data);
		AjaxSearchTools.populateDefaultStarRating(profile, updateDefaultStarRating);
        }

// Javascript function called  to populate Clubbing -dependent departure date
	function populateClubbingDepartureDate(depDateID) {
		var profile = dwr.util.getValue("propositionSelect"); /*Clubbing proposition ID */
		  var depDate = document.getElementById('departureDate').value;
		  AjaxSearchTools.populateDepDate(profile,depDate, updateClubbingDepartureDate);
	   }

// setting departure date
   function updateClubbingDepartureDate(data){
	   arrDateTokens = data.split("-");
	   if(arrDateTokens.length > 0)
	       document.getElementById('defaultDay').innerHTML = arrDateTokens[1];
		   document.getElementById('departureDate').value = arrDateTokens[0];
   }/*FF9159 Bin Range Recognition */
/* This method is used to disable the all fields on tcBinRangePaymentDetails.jsp
 * 
 * 
 */
   function creditCardDisable()
	{
		document.getElementById("nameoncard").disabled=true;
		document.getElementById("fromDateMonth").disabled=true;
		document.getElementById("fromDateYear").disabled=true;
		document.getElementById("ccv").disabled=true;
		document.getElementById("cardissue").disabled=true;
		document.getElementById("ExpiryDateMonth").disabled=true;
		document.getElementById("ExpiryDateYear").disabled=true;
		document.getElementById("nameOnCardLabel").disabled=true;
		document.getElementById("validFromLabel").disabled=true;
		document.getElementById("expiryDateLabel").disabled=true;
		document.getElementById("ccvLabel").disabled=true;
		document.getElementById("cardIssueLabel").disabled=true;
		document.getElementById("frmDtMnthOption").disabled=true;
		document.getElementById("frmDtYrOption").disabled=true;
		document.getElementById("expDtMnthOption").disabled=true;
		document.getElementById("expDtYrOption").disabled=true;
		
	}
/*FF9159 Bin Range Recognition */
/*
* 
* 
*/
function creditCardEnable()
	{

		document.getElementById("nameoncard").disabled=false;
		document.getElementById("fromDateMonth").disabled=false;
		document.getElementById("fromDateYear").disabled=false;
		document.getElementById("ccv").disabled=false;
		document.getElementById("cardissue").disabled=false;
		document.getElementById("ExpiryDateMonth").disabled=false;
		document.getElementById("ExpiryDateYear").disabled=false;
		document.getElementById("nameOnCardLabel").disabled=false;
		document.getElementById("validFromLabel").disabled=false;
		document.getElementById("expiryDateLabel").disabled=false;
		document.getElementById("ccvLabel").disabled=false;
		document.getElementById("cardIssueLabel").disabled=false;
		document.getElementById("frmDtMnthOption").disabled=false;
		document.getElementById("frmDtYrOption").disabled=false;
		document.getElementById("expDtMnthOption").disabled=false;
		document.getElementById("expDtYrOption").disabled=false;
		
	}

/*FF9159 Bin Range Recognition */
/*This method has been called from binRanngePaymentDetails.jsp.
* When the user has entered 8 digits, in the creditcardnumber input box.
* On keypress of 9th digit, the following function is called
*/
function getCreditCardNumberLength()
{ 
			var inputCCNoValue = document.getElementById("numberoncard").value;
			var inputCCNoLength = document.getElementById("numberoncard").value.length;
			
			if (inputCCNoLength == '8')
			{
				findCreditCardType(inputCCNoValue);
			}
			
}
	
/*FF9159 Bin Range Recognition */ 	
/*
*The above method passes the 
* It passes the control to java class and the method
* @ params = first 8 digits of card number user has entered
* This is the Ajax method
*/
function findCreditCardType(userBinRange)
{
	BinRangeValidatorTool.getCreditCardType(userBinRange,updateCreditCardType);
}
/*FF9159 Bin Range Recognition */
/*Whatever return is received from Java method ,
 * the following method is used to set the output 
 * to the jsp.
 */
	function updateCreditCardType(data)
	{    
	      var counter = 1;
	      var tmpArray = new Array();
		     for (var property in data){
			     if (property != null) {			
					var tmpValue = data[property];
					tmpArray[counter]= tmpValue;
					counter++;
				}  
			     if (property == 'displayName')
			     {  /*showing the display name*/
			         document.getElementById('ccName').innerHTML=data[property]; 
			       
			     }
			     if (property == 'fees' )
			     {
			       calculateFees(data[property]);
			       document.getElementById('feesCalculated').value= data[property]; 
			    	
			     }
			     if (property == 'imagePath')
			     {
			    	var cardImagePath = "\'"+data[property]+"\'";	
					/*setting the image*/
			        document.getElementById('ccImage').innerHTML="<img src="+cardImagePath+"/>";
			        
			     }
			     if (property == 'issueNumberExists')
			     {  
			    	 var issueNumExists=data[property];
			    	    
			    	    if (issueNumExists == 1)
			    	 	{  /*showing issue number div in case of Solo and maestro cards*/
							
			    	 		document.getElementById("issueNumber").style.display = "block";
			    	 	}			    	 	
			    	 	else if (issueNumExists == 0)
			    	 	{
			    	 		document.getElementById("issueNumber").style.display = "none";
			    	 	}
			     }
			     if (property == 'cardType')
			     {
			    	 var ccTypeVal = data[property];
			    	 /*passing this value as hidden field to jsp.It will be set to Bean*/
			    	 document.getElementById("creditCardTypeId").value = ccTypeVal;
			     }
		 }
		
		 if (tmpArray != '')
		 { 
			 /*if due to the card number we find any matching matching bin range 
			  * hence credit card type information we enable the other credit card fields */
			 //alert("tmpArray");
			 creditCardEnable();
			 if (document.getElementById("invalidBinError").style.display == "block")
			  {
			     document.getElementById("invalidBinError").style.display = "none";
		 }	    
			  	document.getElementById("ccName").style.display = "block";
	    	 	document.getElementById("ccfees").style.display = "block";
	    	    document.getElementById("ccImage").style.display = "block";
		 }else{  
	    	 //alert("INVALID CARD ERROR");
	    	 
	    	 if (document.getElementById("invalidBinError").style.display == "none")
	     {   
	    	 document.getElementById("invalidBinError").style.display = "block";
		 }
	    	 
			    document.getElementById("ccName").style.display = "none";
	    	 	document.getElementById("ccfees").style.display = "none";
	    	    document.getElementById("ccImage").style.display = "none";			  	
	    	 
	    	 creditCardDisable();
		 }
	} 

	function populateSnowDepDate(){
		var curDate = new Date;
		var snowDate = new Date;
		snowDate.setDate(curDate.getDate()+3);
			var month = snowDate.getMonth();
			if(month == 11 || month == 0 || month == 1 || month == 2 || month == 3) {
				if(month < 4)
					month = "0"+(month+1);
				var dateNum = snowDate.getDate();
				//dateNum=dateNum+3;
				if(dateNum<10)
					dateNum = "0"+dateNum;

				document.getElementById('departureDate').value = dateNum+"/"+month+"/"+(snowDate.getFullYear()-2000);
			}else{
				document.getElementById('departureDate').value = "01/12/"+(snowDate.getFullYear()-2000);
			}
	}
	
	
	
	
	
	
	
