﻿
//*********************************************************************
//My Favourites Add/Remove Items
//*********************************************************************
var accommodationCode;
function addItemInMyFav(txt) {
  var vals = new Array();
  vals = txt.split('_');
  accommodationCode = vals[0];

  PageMethods.AddMyFavItem(vals[0], vals[1], vals[2], 325, onAddMyFavItemComplete);
}

function addItemInMyFavFromLastViewedItem(txt) {
  var vals = new Array();
  vals = txt.split('_');
  accommodationCode = vals[0];

  PageMethods.AddMyFavItemFromLastViewed(vals[0], 325, onAddMyFavItemComplete);
}

function onAddMyFavItemComplete(result) {

  var btnAdd = document.getElementById("spanAddRVBtn" + accommodationCode);
  var btnRemove = document.getElementById("spanRemoveRVBtn" + accommodationCode);
  var refresh = document.getElementById(hdnADDRemoveFavClientID);

  if (result) {
    refresh.value = "true";
  
    btnAdd.style.display = "none";
    btnRemove.style.display = "inline";
    PageMethods.MyFavouriteTotalItems(325, displayMyFavTotalItems);
  }
}

function removeItemFromMyFav(txt) {
  var vals = new Array();
  vals = txt.split('_');

  accommodationCode = vals[0];
  PageMethods.RemoveMyFavItem(vals[0], vals[1], vals[2], 325, onRemoveMyFavItemComplete);
}

function removeItemFromLastViewedItem(txt) {
  var vals = new Array();
  vals = txt.split('_');

  accommodationCode = vals[0];
  PageMethods.RemoveMyFavItemFromLastViewed(vals[0], 325, onRemoveMyFavItemComplete);
}

function onRemoveMyFavItemComplete(result) {
  var btnAdd = document.getElementById("spanAddRVBtn" + accommodationCode);
  var btnRemove = document.getElementById("spanRemoveRVBtn" + accommodationCode);
  var refresh = document.getElementById(hdnADDRemoveFavClientID);

  if (result) {
    refresh.value = "true";
    btnAdd.style.display = "inline";
    btnRemove.style.display = "none";
    PageMethods.MyFavouriteTotalItems(325, displayMyFavTotalItems);
  }
}

function displayMyFavTotalItems(result) {

  var count = document.getElementById(ltrMyFavTotalItemsClientID);
  count.value = result;

  //Store count in cookie

  var expdate = new Date();
  expdate.setTime(expdate.getTime() + 1 * 24 * 60 * 60 * 1000); //Set expiry to 1 day
  document.cookie = 'MyFavCount=' + escape(result) + '; expires=' + expdate.toGMTString() + ";path=/";

  // Display favourite items count in MyBowhills and MyHoseaosons toolbar at the top

  var myhoseasonsFavCount = document.getElementById("ctl00_linkShortlist");
  if (myhoseasonsFavCount)
  { myhoseasonsFavCount.innerHTML = result }
}

function loadMyFavourites() {
  var refresh = document.getElementById(hdnADDRemoveFavClientID);

  if (refresh.value == "true") {
    var btn = document.getElementById(hiddennMyFavBtnClientID);
    btn.click();
  }
  refresh.value = "";
}

$(document).ready(function () {
  
  if ($('#datepicker').val() != null && $('#datepicker').val() != '(Optional)') { $('#divOptional').html('Clear'); $('#divOptional').show(); }

  $('#divOptional').click(function () { $('#datepicker').val('(Optional)'); $('#divOptional').hide(); })

});

//*********************************************************************


